diff --git a/app/settings/delegates/activitiesdelegate.cpp b/app/settings/delegates/activitiesdelegate.cpp index 09babf110..ab1f5d5b8 100644 --- a/app/settings/delegates/activitiesdelegate.cpp +++ b/app/settings/delegates/activitiesdelegate.cpp @@ -29,14 +29,17 @@ // Qt #include #include -#include +#include #include #include #include #include #include #include +#include +#include +#define OKPRESSED "OKPRESSED" namespace Latte { namespace Settings { @@ -141,6 +144,25 @@ QWidget *Activities::createEditor(QWidget *parent, const QStyleOptionViewItem &o updateButton(button, allActivitiesData); }); + //! Ok, Apply Buttons behavior + menu->addSeparator(); + + QDialogButtonBox *menuDialogButtons = new QDialogButtonBox(menu); + menuDialogButtons->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + + QWidgetAction* menuDialogButtonsWidgetAction = new QWidgetAction(menu); + menuDialogButtonsWidgetAction->setDefaultWidget(menuDialogButtons); + + menu->addAction(menuDialogButtonsWidgetAction); + + connect(menuDialogButtons->button(QDialogButtonBox::Ok), &QPushButton::clicked, [this, menu, button]() { + button->setProperty(OKPRESSED, true); + menu->hide(); + }); + + connect(menuDialogButtons->button(QDialogButtonBox::Cancel), &QPushButton::clicked, menu, &QMenu::hide); + connect(menu, &QMenu::aboutToHide, button, &QWidget::clearFocus); + return button; } @@ -155,6 +177,10 @@ void Activities::setModelData(QWidget *editor, QAbstractItemModel *model, const { QPushButton *button = static_cast(editor); + if (button->property(OKPRESSED).isNull() || !button->property(OKPRESSED).toBool()) { + return; + } + QStringList assignedActivities; foreach (QAction *action, button->menu()->actions()) { if (action->isChecked()) { diff --git a/app/settings/delegates/shareddelegate.cpp b/app/settings/delegates/shareddelegate.cpp index ec18bdf5f..cc08d46d2 100644 --- a/app/settings/delegates/shareddelegate.cpp +++ b/app/settings/delegates/shareddelegate.cpp @@ -30,14 +30,16 @@ #include #include #include +#include #include -#include #include #include #include #include #include +#include +#define OKPRESSED "OKPRESSED" namespace Latte { namespace Settings { @@ -92,6 +94,25 @@ QWidget *Shared::createEditor(QWidget *parent, const QStyleOptionViewItem &optio m_controller->on_sharedToInEditChanged(layoutId, true); + //! Ok, Apply Buttons behavior + menu->addSeparator(); + + QDialogButtonBox *menuDialogButtons = new QDialogButtonBox(menu); + menuDialogButtons->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + + QWidgetAction* menuDialogButtonsWidgetAction = new QWidgetAction(menu); + menuDialogButtonsWidgetAction->setDefaultWidget(menuDialogButtons); + + menu->addAction(menuDialogButtonsWidgetAction); + + connect(menuDialogButtons->button(QDialogButtonBox::Ok), &QPushButton::clicked, [this, menu, button]() { + button->setProperty(OKPRESSED, true); + menu->hide(); + }); + + connect(menuDialogButtons->button(QDialogButtonBox::Cancel), &QPushButton::clicked, menu, &QMenu::hide); + connect(menu, &QMenu::aboutToHide, button, &QWidget::clearFocus); + return button; } @@ -105,6 +126,13 @@ void Shared::setModelData(QWidget *editor, QAbstractItemModel *model, const QMod { QPushButton *button = static_cast(editor); + QString layoutId = index.data(Model::Layouts::IDROLE).toString(); + + if (button->property(OKPRESSED).isNull() || !button->property(OKPRESSED).toBool()) { + m_controller->on_sharedToInEditChanged(layoutId, false); + return; + } + QStringList assignedLayouts; foreach (QAction *action, button->menu()->actions()) { if (action->isChecked()) { @@ -114,7 +142,6 @@ void Shared::setModelData(QWidget *editor, QAbstractItemModel *model, const QMod model->setData(index, assignedLayouts, Qt::UserRole); - QString layoutId = index.data(Model::Layouts::IDROLE).toString(); m_controller->on_sharedToInEditChanged(layoutId, false); }