/****************************************************************************
 * NOTES:
 *  1) the mainWidget is host-widget, FramelessTitleBar is used as its event filter
 *  2) the titleWidget is the title bar area of mainWidget, used to guide the
 *     mouse event operation of FramelessTitleBar.
 *
 *  -------------------------------------,
 *  |           titleWidget             | \
 *  |------------------------------------  \
 *  |                                   |    mainWindget
 *  |                                   |  /
 *  |                                   | /
 *  -------------------------------------'
 *
 *  3) systemToolBar contains min, max, close Buttons
 *
 *   --------------------------,--------,     ,--- systemToolBar
 *   |          titleWidget    | - [] x | <--'
 *   --------------------------'--------'
 *
 *****************************************************************************
 */
#ifndef FRAMELESSTITLEBAR_H
#define FRAMELESSTITLEBAR_H

#include "frameless_define.h"
#include <QObject>

class QEvent;
class QLabel;
class QToolButton;
class QAction;


    class FramelessTitleBarPrivate;

/* FramelessTitleBar */
class FramelessTitleBar : public QObject
{
    Q_OBJECT

public:
    enum ButtonRole {
        MinButton, MaxButton, NormalButton, CloseButton,
    };

public:
    explicit FramelessTitleBar(QWidget *mainWidget);
    virtual ~FramelessTitleBar();

    void setTitleWidget(QWidget *widget);

    QToolButton *logoButton() const;
    QLabel  *titleLabel() const;
    QWidget *systemToolBar() const;
    QWidget *mainWidget() const;

    QAction *addAction(const QIcon &icon, const QString &text);
    void     addAction(QAction *action);
    void     insertAction(QAction *before, QAction *action);
    QAction *addSeparator();
    QAction *insertSeparator(QAction *before);
    QAction *addWidget(QWidget *widget);
    QAction *insertWidget(QAction *before, QWidget *widget);

    void setButtonIcon(ButtonRole role, const QIcon &icon);
    void setButtonTip(ButtonRole role, const QString &tip);

    void setWidgetResizable(bool resizable);
    void setWidgetMovable(bool movable);
    void setWidgetMaximizable(bool maximizable);

    void setDisabled(bool disable);
    void updateWidgetFlags();

    void addCaptionClassName(const QString &name);

    void setCloseBySystemButton(bool state);

signals:
    void windowResizable(bool resizable);
    void windowMovable(bool movable);
    void windowIconChanged(QIcon &icon);
    void signalClose();

public:
    void setIconSize(const QSize &size);
    void setSystemButtonBgColor(const QColor& normalColor, const QColor& hoverColor, const QColor& pressColor);


protected:
    virtual bool eventFilter(QObject* object, QEvent* event);

private:
    FramelessTitleBarPrivate *d;
};



#endif // FRAMELESSTITLEBAR_H
