Commit eeb67417 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

collapse menu if click on already selected button

parent 85705ca1
......@@ -186,7 +186,7 @@ dtkWidgetsMenuBarButton::dtkWidgetsMenuBarButton(int id, const QString &title, Q
m_connection = connect(dtkThemesEngine::instance(), &dtkThemesEngine::changed, [=]()
{
this->touch(this->selected);
this->touch(this->m_selected);
});
}
......@@ -195,9 +195,14 @@ dtkWidgetsMenuBarButton::~dtkWidgetsMenuBarButton(void)
disconnect(m_connection);
}
bool dtkWidgetsMenuBarButton::selected(void) const
{
return this->m_selected;
}
void dtkWidgetsMenuBarButton::touch(bool selected)
{
this->selected = selected;
this->m_selected = selected;
if (!selected) {
dtkFontAwesome::instance()->setDefaultOption("color", dtkThemesEngine::instance()->color("@base7"));
......@@ -233,7 +238,7 @@ void dtkWidgetsMenuBarButton::enterEvent(QEvent *)
void dtkWidgetsMenuBarButton::leaveEvent(QEvent *)
{
if (!this->selected) {
if (!this->m_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)));
}
......@@ -469,6 +474,7 @@ void dtkWidgetsMenuBarPrivate::touch(void)
int index = 0;
int target = 0;
bool selected = b->selected();
for (int i = 0; i < this->layout->count(); ++i) {
......@@ -489,7 +495,7 @@ void dtkWidgetsMenuBarPrivate::touch(void)
q->emit clicked(target);
};
if(!this->c->width()) {
if(!this->c->width() || selected) {
this->toggle->collapsed = !this->toggle->collapsed;
this->toggle->touch();
this->c->slider->blockSignals(true);
......
......@@ -48,6 +48,9 @@ signals:
public slots:
void touch(bool);
public:
bool selected(void) const;
public:
QSize sizeHint(void) const override;
......@@ -61,7 +64,7 @@ public:
dtkWidgetsMenu *menu = nullptr;
private:
bool selected = false;
bool m_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