/******************************************************************************
 * QSkinny - Copyright (C) 2016 Uwe Rathmann
 * This file may be used under the terms of the QSkinny License, Version 1.0
 *****************************************************************************/

#ifndef QSK_SUB_WINDOW_H
#define QSK_SUB_WINDOW_H 1

#include "QskGlobal.h"
#include "QskPopup.h"

class QSK_EXPORT QskSubWindow : public QskPopup
{
    Q_OBJECT

    Q_PROPERTY( bool decorated READ isDecorated
        WRITE setDecorated NOTIFY decoratedChanged )

    Q_PROPERTY( QString title READ title WRITE setTitle NOTIFY titleChanged )
    Q_PROPERTY( WindowButtons windowButtons READ windowButtons
        WRITE setWindowButtons NOTIFY windowButtonsChanged )

    using Inherited = QskPopup;

public:
    enum WindowButton
    {
        MinimizeButton = 0x1,
        MaximizeButton = 0x2,
        CloseButton = 0x4
    };

    Q_ENUM( WindowButton )
    Q_DECLARE_FLAGS( WindowButtons, WindowButton )

    QSK_SUBCONTROLS( Panel, TitleBar )

    QskSubWindow( QQuickItem* parent = nullptr );
    virtual ~QskSubWindow();

    Q_INVOKABLE void setTitle( const QString& );
    Q_INVOKABLE QString title() const;

    Q_INVOKABLE void setDecorated( bool );
    Q_INVOKABLE bool isDecorated() const;

    Q_INVOKABLE void setWindowButtons( WindowButtons );
    Q_INVOKABLE WindowButtons windowButtons() const;

    Q_INVOKABLE void setWindowButton( WindowButton, bool on = true );
    Q_INVOKABLE bool testWindowButton( WindowButton ) const;

    QRectF titleBarRect() const;

    virtual QSizeF contentsSizeHint() const override;
    virtual QRectF layoutRect() const override;

Q_SIGNALS:
    void titleChanged();
    void decoratedChanged();
    void windowButtonsChanged();

protected:
    virtual bool event( QEvent* ) override;

    virtual void itemChange( QQuickItem::ItemChange,
        const QQuickItem::ItemChangeData& ) override;

private:
    class PrivateData;
    std::unique_ptr< PrivateData > m_data;
};

#endif
