Commit 14f91cf1 authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud

Beautifying menu bar button.

parent 97a8e1b2
...@@ -33,6 +33,7 @@ int main(int argc, char **argv) ...@@ -33,6 +33,7 @@ int main(int argc, char **argv)
{ {
dtk::core::registerParameters(); dtk::core::registerParameters();
dtk::widgets::initialize(""); dtk::widgets::initialize("");
dtkThemesEngine::instance()->apply(); // TODO
dtkApplication *application = dtkApplication::create(argc, argv); dtkApplication *application = dtkApplication::create(argc, argv);
application->setApplicationName("dtkWidgetsMenu"); application->setApplicationName("dtkWidgetsMenu");
......
...@@ -104,7 +104,8 @@ class dtkWidgetsMenuBarButtonCollapse : public QLabel ...@@ -104,7 +104,8 @@ class dtkWidgetsMenuBarButtonCollapse : public QLabel
Q_OBJECT Q_OBJECT
public: public:
dtkWidgetsMenuBarButtonCollapse(QWidget *parent = nullptr); dtkWidgetsMenuBarButtonCollapse(QWidget *parent = nullptr);
~dtkWidgetsMenuBarButtonCollapse(void);
signals: signals:
void clicked(void); void clicked(void);
...@@ -120,13 +121,26 @@ public: ...@@ -120,13 +121,26 @@ public:
public: public:
bool collapsed = true; bool collapsed = true;
QMetaObject::Connection m_connection;
}; };
dtkWidgetsMenuBarButtonCollapse::dtkWidgetsMenuBarButtonCollapse(QWidget *parent) : QLabel(parent) dtkWidgetsMenuBarButtonCollapse::dtkWidgetsMenuBarButtonCollapse(QWidget *parent) : QLabel(parent)
{ {
this->setAlignment(Qt::AlignCenter);
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
this->setMouseTracking(true);
this->touch(); this->touch();
m_connection = connect(dtkThemesEngine::instance(), &dtkThemesEngine::changed, [=]()
{
this->touch();
});
}
dtkWidgetsMenuBarButtonCollapse::~dtkWidgetsMenuBarButtonCollapse(void)
{
disconnect(m_connection);
} }
QSize dtkWidgetsMenuBarButtonCollapse::sizeHint(void) const QSize dtkWidgetsMenuBarButtonCollapse::sizeHint(void) const
...@@ -137,13 +151,12 @@ QSize dtkWidgetsMenuBarButtonCollapse::sizeHint(void) const ...@@ -137,13 +151,12 @@ QSize dtkWidgetsMenuBarButtonCollapse::sizeHint(void) const
void dtkWidgetsMenuBarButtonCollapse::touch(void) void dtkWidgetsMenuBarButtonCollapse::touch(void)
{ {
dtkFontAwesome::instance()->initFontAwesome(); dtkFontAwesome::instance()->initFontAwesome();
dtkFontAwesome::instance()->setDefaultOption("color", QColor("#999999")); dtkFontAwesome::instance()->setDefaultOption("color", dtkThemesEngine::instance()->color("@base7"));
this->setPixmap(dtkFontAwesome::instance()->icon(this->collapsed ? fa::chevronright : fa::chevronleft).pixmap(QSize(::size * 3 / 4, ::size * 3 / 4)));
this->setAlignment(Qt::AlignCenter);
this->setToolTip(this->collapsed ? "Expand" : "Collapse"); this->setToolTip(this->collapsed ? "Expand" : "Collapse");
this->setPixmap(dtkFontAwesome::instance()->icon(this->collapsed ? fa::chevronright : fa::chevronleft).pixmap(QSize(::size * 3 / 4, ::size * 3 / 4)));
this->setStyleSheet(this->styleSheet()); // This is no bug! dtkThemesEngine::instance()->polish(this);
} }
void dtkWidgetsMenuBarButtonCollapse::mousePressEvent(QMouseEvent *event) void dtkWidgetsMenuBarButtonCollapse::mousePressEvent(QMouseEvent *event)
...@@ -163,20 +176,17 @@ void dtkWidgetsMenuBarButtonCollapse::mousePressEvent(QMouseEvent *event) ...@@ -163,20 +176,17 @@ void dtkWidgetsMenuBarButtonCollapse::mousePressEvent(QMouseEvent *event)
dtkWidgetsMenuBarButton::dtkWidgetsMenuBarButton(int id, const QString &title, QWidget *parent) : QLabel(parent) dtkWidgetsMenuBarButton::dtkWidgetsMenuBarButton(int id, const QString &title, QWidget *parent) : QLabel(parent)
{ {
dtkFontAwesome::instance()->initFontAwesome();
dtkFontAwesome::instance()->setDefaultOption("color", QColor("#999999"));
this->icon_id = id; this->icon_id = id;
this->setPixmap(dtkFontAwesome::instance()->icon(this->icon_id).pixmap(QSize(::size * 3 / 4, ::size * 3 / 4)));
this->setAlignment(Qt::AlignCenter); this->setAlignment(Qt::AlignCenter);
this->setToolTip(title); this->setToolTip(title);
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
this->setMouseTracking(true); this->setMouseTracking(true);
this->touch(false);
m_connection = connect(dtkThemesEngine::instance(), &dtkThemesEngine::changed, [=]() m_connection = connect(dtkThemesEngine::instance(), &dtkThemesEngine::changed, [=]()
{ {
dtkThemesEngine::instance()->polish(this); this->touch(this->selected);
}); });
} }
...@@ -185,23 +195,20 @@ dtkWidgetsMenuBarButton::~dtkWidgetsMenuBarButton(void) ...@@ -185,23 +195,20 @@ dtkWidgetsMenuBarButton::~dtkWidgetsMenuBarButton(void)
disconnect(m_connection); disconnect(m_connection);
} }
void dtkWidgetsMenuBarButton::darken(void) void dtkWidgetsMenuBarButton::touch(bool selected)
{ {
dtkFontAwesome::instance()->setDefaultOption("color", QColor("#999999")); this->selected = selected;
this->setPixmap(dtkFontAwesome::instance()->icon(this->icon_id).pixmap(QSize(::size * 3 / 4, ::size * 3 / 4))); if (!selected) {
dtkFontAwesome::instance()->setDefaultOption("color", dtkThemesEngine::instance()->color("@base7"));
this->setProperty("state", "default");
this->setProperty("state", ""); } else {
dtkThemesEngine::instance()->polish(this); dtkFontAwesome::instance()->setDefaultOption("color", dtkThemesEngine::instance()->color("@fg"));
} this->setProperty("state", "current");
}
void dtkWidgetsMenuBarButton::lighten(void)
{
dtkFontAwesome::instance()->setDefaultOption("color", QColor("#ffffff"));
this->setPixmap(dtkFontAwesome::instance()->icon(this->icon_id).pixmap(QSize(::size * 3 / 4, ::size * 3 / 4))); this->setPixmap(dtkFontAwesome::instance()->icon(this->icon_id).pixmap(QSize(::size * 3 / 4, ::size * 3 / 4)));
this->setProperty("state", "current");
dtkThemesEngine::instance()->polish(this); dtkThemesEngine::instance()->polish(this);
} }
...@@ -217,6 +224,21 @@ void dtkWidgetsMenuBarButton::mousePressEvent(QMouseEvent *event) ...@@ -217,6 +224,21 @@ void dtkWidgetsMenuBarButton::mousePressEvent(QMouseEvent *event)
event->accept(); event->accept();
} }
void dtkWidgetsMenuBarButton::enterEvent(QEvent *)
{
dtkFontAwesome::instance()->setDefaultOption("color", dtkThemesEngine::instance()->color("@fg"));
this->setPixmap(dtkFontAwesome::instance()->icon(this->icon_id).pixmap(QSize(::size * 3 / 4, ::size * 3 / 4)));
}
void dtkWidgetsMenuBarButton::leaveEvent(QEvent *)
{
if (!this->selected) {
dtkFontAwesome::instance()->setDefaultOption("color", dtkThemesEngine::instance()->color("@base7"));
this->setPixmap(dtkFontAwesome::instance()->icon(this->icon_id).pixmap(QSize(::size * 3 / 4, ::size * 3 / 4)));
}
}
// ///////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
// //
// ///////////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////////
...@@ -451,14 +473,13 @@ void dtkWidgetsMenuBarPrivate::touch(void) ...@@ -451,14 +473,13 @@ void dtkWidgetsMenuBarPrivate::touch(void)
for (int i = 0; i < this->layout->count(); ++i) { for (int i = 0; i < this->layout->count(); ++i) {
if (dtkWidgetsMenuBarButton *button = dynamic_cast<dtkWidgetsMenuBarButton *>(this->layout->itemAt(i)->widget())) { if (dtkWidgetsMenuBarButton *button = dynamic_cast<dtkWidgetsMenuBarButton *>(this->layout->itemAt(i)->widget())) {
button->darken();
if (button == b) { if (button == b) {
button->lighten(); button->touch(true);
target = index; target = index;
} else {
button->touch(false);
} }
++index;
index++;
} }
} }
...@@ -717,16 +738,11 @@ dtkWidgetsParameter *dtkWidgetsMenuBar::parameterWidget(const QString& id) ...@@ -717,16 +738,11 @@ dtkWidgetsParameter *dtkWidgetsMenuBar::parameterWidget(const QString& id)
void dtkWidgetsMenuBar::setCurrentIndex(int index) void dtkWidgetsMenuBar::setCurrentIndex(int index)
{ {
int n = 0; int n = 0;
for (int i = 0; i < d->layout->count(); ++i) {
for (int i = 0; i < d->layout->count(); i++) {
if (dtkWidgetsMenuBarButton *button = dynamic_cast<dtkWidgetsMenuBarButton *>(d->layout->itemAt(i)->widget())) { if (dtkWidgetsMenuBarButton *button = dynamic_cast<dtkWidgetsMenuBarButton *>(d->layout->itemAt(i)->widget())) {
button->touch(n == index);
(n == index) ? button->lighten() : button->darken();
(n == index) ? d->scroll->ensureWidgetVisible(button) : (void)index; (n == index) ? d->scroll->ensureWidgetVisible(button) : (void)index;
++n;
n++;
} }
} }
} }
......
...@@ -46,8 +46,7 @@ signals: ...@@ -46,8 +46,7 @@ signals:
void clicked(void); void clicked(void);
public slots: public slots:
void darken(void); void touch(bool);
void lighten(void);
public: public:
QSize sizeHint(void) const override; QSize sizeHint(void) const override;
...@@ -55,10 +54,14 @@ public: ...@@ -55,10 +54,14 @@ public:
protected: protected:
void mousePressEvent(QMouseEvent *) override; void mousePressEvent(QMouseEvent *) override;
void enterEvent(QEvent *) override;
void leaveEvent(QEvent *) override;
public: public:
dtkWidgetsMenu *menu = nullptr; dtkWidgetsMenu *menu = nullptr;
private: private:
bool selected = false;
int icon_id = 0; int icon_id = 0;
QMetaObject::Connection m_connection; QMetaObject::Connection m_connection;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment