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)
{
dtk::core::registerParameters();
dtk::widgets::initialize("");
dtkThemesEngine::instance()->apply(); // TODO
dtkApplication *application = dtkApplication::create(argc, argv);
application->setApplicationName("dtkWidgetsMenu");
......
......@@ -105,6 +105,7 @@ class dtkWidgetsMenuBarButtonCollapse : public QLabel
public:
dtkWidgetsMenuBarButtonCollapse(QWidget *parent = nullptr);
~dtkWidgetsMenuBarButtonCollapse(void);
signals:
void clicked(void);
......@@ -120,13 +121,26 @@ public:
public:
bool collapsed = true;
QMetaObject::Connection m_connection;
};
dtkWidgetsMenuBarButtonCollapse::dtkWidgetsMenuBarButtonCollapse(QWidget *parent) : QLabel(parent)
{
this->setAlignment(Qt::AlignCenter);
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
this->setMouseTracking(true);
this->touch();
m_connection = connect(dtkThemesEngine::instance(), &dtkThemesEngine::changed, [=]()
{
this->touch();
});
}
dtkWidgetsMenuBarButtonCollapse::~dtkWidgetsMenuBarButtonCollapse(void)
{
disconnect(m_connection);
}
QSize dtkWidgetsMenuBarButtonCollapse::sizeHint(void) const
......@@ -137,13 +151,12 @@ QSize dtkWidgetsMenuBarButtonCollapse::sizeHint(void) const
void dtkWidgetsMenuBarButtonCollapse::touch(void)
{
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->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)
......@@ -163,20 +176,17 @@ void dtkWidgetsMenuBarButtonCollapse::mousePressEvent(QMouseEvent *event)
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->setPixmap(dtkFontAwesome::instance()->icon(this->icon_id).pixmap(QSize(::size * 3 / 4, ::size * 3 / 4)));
this->setAlignment(Qt::AlignCenter);
this->setToolTip(title);
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
this->setMouseTracking(true);
this->touch(false);
m_connection = connect(dtkThemesEngine::instance(), &dtkThemesEngine::changed, [=]()
{
dtkThemesEngine::instance()->polish(this);
this->touch(this->selected);
});
}
......@@ -185,23 +195,20 @@ dtkWidgetsMenuBarButton::~dtkWidgetsMenuBarButton(void)
disconnect(m_connection);
}
void dtkWidgetsMenuBarButton::darken(void)
void dtkWidgetsMenuBarButton::touch(bool selected)
{
dtkFontAwesome::instance()->setDefaultOption("color", QColor("#999999"));
this->setPixmap(dtkFontAwesome::instance()->icon(this->icon_id).pixmap(QSize(::size * 3 / 4, ::size * 3 / 4)));
this->selected = selected;
this->setProperty("state", "");
dtkThemesEngine::instance()->polish(this);
}
if (!selected) {
dtkFontAwesome::instance()->setDefaultOption("color", dtkThemesEngine::instance()->color("@base7"));
this->setProperty("state", "default");
void dtkWidgetsMenuBarButton::lighten(void)
{
dtkFontAwesome::instance()->setDefaultOption("color", QColor("#ffffff"));
} else {
dtkFontAwesome::instance()->setDefaultOption("color", dtkThemesEngine::instance()->color("@fg"));
this->setProperty("state", "current");
}
this->setPixmap(dtkFontAwesome::instance()->icon(this->icon_id).pixmap(QSize(::size * 3 / 4, ::size * 3 / 4)));
this->setProperty("state", "current");
dtkThemesEngine::instance()->polish(this);
}
......@@ -217,6 +224,21 @@ void dtkWidgetsMenuBarButton::mousePressEvent(QMouseEvent *event)
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)
for (int i = 0; i < this->layout->count(); ++i) {
if (dtkWidgetsMenuBarButton *button = dynamic_cast<dtkWidgetsMenuBarButton *>(this->layout->itemAt(i)->widget())) {
button->darken();
if (button == b) {
button->lighten();
button->touch(true);
target = index;
} else {
button->touch(false);
}
index++;
++index;
}
}
......@@ -717,16 +738,11 @@ dtkWidgetsParameter *dtkWidgetsMenuBar::parameterWidget(const QString& id)
void dtkWidgetsMenuBar::setCurrentIndex(int index)
{
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())) {
(n == index) ? button->lighten() : button->darken();
button->touch(n == index);
(n == index) ? d->scroll->ensureWidgetVisible(button) : (void)index;
n++;
++n;
}
}
}
......
......@@ -46,8 +46,7 @@ signals:
void clicked(void);
public slots:
void darken(void);
void lighten(void);
void touch(bool);
public:
QSize sizeHint(void) const override;
......@@ -55,10 +54,14 @@ public:
protected:
void mousePressEvent(QMouseEvent *) override;
void enterEvent(QEvent *) override;
void leaveEvent(QEvent *) override;
public:
dtkWidgetsMenu *menu = nullptr;
private:
bool selected = false;
int icon_id = 0;
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