layouteditor:improve activity/shares edit behavior

--situation has improved vastly for users for activities
and shares when trying to change their values. The menus
that appear now contain Ok/Cancel buttons in order to
accept or ignore the changes. If the user just hides
the menu without clicking Ok button then the changes
are ignored.
pull/19/head
Michail Vourlakos 5 years ago
parent 3f1e788885
commit 105b14de38

@ -29,14 +29,17 @@
// Qt
#include <QApplication>
#include <QDebug>
#include <QWidget>
#include <QDialogButtonBox>
#include <QMenu>
#include <QModelIndex>
#include <QPainter>
#include <QPushButton>
#include <QString>
#include <QTextDocument>
#include <QWidget>
#include <QWidgetAction>
#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<QPushButton *>(editor);
if (button->property(OKPRESSED).isNull() || !button->property(OKPRESSED).toBool()) {
return;
}
QStringList assignedActivities;
foreach (QAction *action, button->menu()->actions()) {
if (action->isChecked()) {

@ -30,14 +30,16 @@
#include <QApplication>
#include <QComboBox>
#include <QDebug>
#include <QDialogButtonBox>
#include <QMenu>
#include <QWidget>
#include <QModelIndex>
#include <QPainter>
#include <QPushButton>
#include <QString>
#include <QTextDocument>
#include <QWidgetAction>
#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<QPushButton *>(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);
}

Loading…
Cancel
Save