From 6e66907957653ef4a2b9becd5948878b934a7f82 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Fri, 13 Mar 2020 12:33:40 +0200 Subject: [PATCH] update settings Layout name delegate --- app/settings/delegates/checkboxdelegate.cpp | 10 +++-- app/settings/delegates/checkboxdelegate.h | 8 ++-- app/settings/delegates/layoutnamedelegate.cpp | 37 +++++++++++++++++-- app/settings/delegates/layoutnamedelegate.h | 11 ++++-- app/settings/settingsdialog.cpp | 6 +-- 5 files changed, 56 insertions(+), 16 deletions(-) diff --git a/app/settings/delegates/checkboxdelegate.cpp b/app/settings/delegates/checkboxdelegate.cpp index 5df4f77ab..d27b3f536 100644 --- a/app/settings/delegates/checkboxdelegate.cpp +++ b/app/settings/delegates/checkboxdelegate.cpp @@ -35,9 +35,10 @@ namespace Latte { namespace Settings { -namespace View { +namespace Layouts { +namespace Delegates { -CheckBoxDelegate::CheckBoxDelegate(QObject *parent) +CheckBox::CheckBox(QObject *parent) : QStyledItemDelegate(parent) { auto *settingsDialog = qobject_cast(parent); @@ -47,7 +48,7 @@ CheckBoxDelegate::CheckBoxDelegate(QObject *parent) } } -void CheckBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +void CheckBox::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem adjustedOption = option; //! Remove the focus dotted lines @@ -109,7 +110,7 @@ void CheckBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti } } -bool CheckBoxDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, +bool CheckBox::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { Q_ASSERT(event); @@ -145,3 +146,4 @@ bool CheckBoxDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, con } } } +} diff --git a/app/settings/delegates/checkboxdelegate.h b/app/settings/delegates/checkboxdelegate.h index b9f98f203..111608f5f 100644 --- a/app/settings/delegates/checkboxdelegate.h +++ b/app/settings/delegates/checkboxdelegate.h @@ -29,12 +29,13 @@ class SettingsDialog; namespace Latte { namespace Settings { -namespace View { +namespace Layouts { +namespace Delegates { -class CheckBoxDelegate : public QStyledItemDelegate +class CheckBox : public QStyledItemDelegate { public: - CheckBoxDelegate(QObject *parent = 0); + CheckBox(QObject *parent = 0); void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; virtual bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override; @@ -46,5 +47,6 @@ private: } } } +} #endif diff --git a/app/settings/delegates/layoutnamedelegate.cpp b/app/settings/delegates/layoutnamedelegate.cpp index 649f01484..d7f591e57 100644 --- a/app/settings/delegates/layoutnamedelegate.cpp +++ b/app/settings/delegates/layoutnamedelegate.cpp @@ -29,15 +29,17 @@ #include #include #include +#include #include #include #include namespace Latte { namespace Settings { -namespace View { +namespace Layouts { +namespace Delegates { -LayoutNameDelegate::LayoutNameDelegate(QObject *parent) +LayoutName::LayoutName(QObject *parent) : QStyledItemDelegate(parent) { auto *settingsDialog = qobject_cast(parent); @@ -47,7 +49,35 @@ LayoutNameDelegate::LayoutNameDelegate(QObject *parent) } } -void LayoutNameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +QWidget *LayoutName::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + Q_UNUSED(option); + Q_UNUSED(index); + + QLineEdit *editor = new QLineEdit(parent); + return editor; +} + +void LayoutName::setEditorData(QWidget *editor, const QModelIndex &index) const +{ + QLineEdit *lineEditor = qobject_cast(editor); + + if (lineEditor) { + QString name = index.data(Qt::DisplayRole).toString(); + lineEditor->setText(name); + } +} + +void LayoutName::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const +{ + QLineEdit *lineEditor = qobject_cast(editor); + + if (lineEditor) { + model->setData(index, lineEditor->text(), Qt::DisplayRole); + } +} + +void LayoutName::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { bool isLocked = index.data(Model::Layouts::LAYOUTISLOCKEDROLE).toBool(); bool isShared = index.data(Model::Layouts::LAYOUTISSHAREDROLE).toBool() && index.data(Model::Layouts::INMULTIPLELAYOUTSMODE).toBool(); @@ -128,3 +158,4 @@ void LayoutNameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op } } } +} diff --git a/app/settings/delegates/layoutnamedelegate.h b/app/settings/delegates/layoutnamedelegate.h index 4583343a5..ecf7f5754 100644 --- a/app/settings/delegates/layoutnamedelegate.h +++ b/app/settings/delegates/layoutnamedelegate.h @@ -29,13 +29,17 @@ class SettingsDialog; namespace Latte { namespace Settings { -namespace View { +namespace Layouts { +namespace Delegates { -class LayoutNameDelegate : public QStyledItemDelegate +class LayoutName : public QStyledItemDelegate { public: - LayoutNameDelegate(QObject *parent = 0); + LayoutName(QObject *parent = 0); + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + void setEditorData(QWidget *editor, const QModelIndex &index) const override; + void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; private: @@ -45,4 +49,5 @@ private: } } } +} #endif diff --git a/app/settings/settingsdialog.cpp b/app/settings/settingsdialog.cpp index a913ef208..853a9eba4 100644 --- a/app/settings/settingsdialog.cpp +++ b/app/settings/settingsdialog.cpp @@ -128,10 +128,10 @@ SettingsDialog::SettingsDialog(QWidget *parent, Latte::Corona *corona) colors.append(color); } - ui->layoutsView->setItemDelegateForColumn(NAMECOLUMN, new Settings::View::LayoutNameDelegate(this)); + ui->layoutsView->setItemDelegateForColumn(NAMECOLUMN, new Settings::Layouts::Delegates::LayoutName(this)); ui->layoutsView->setItemDelegateForColumn(COLORCOLUMN, new ColorCmbBoxDelegate(this, iconsPath, colors)); - ui->layoutsView->setItemDelegateForColumn(MENUCOLUMN, new Settings::View::CheckBoxDelegate(this)); - ui->layoutsView->setItemDelegateForColumn(BORDERSCOLUMN, new Settings::View::CheckBoxDelegate(this)); + ui->layoutsView->setItemDelegateForColumn(MENUCOLUMN, new Settings::Layouts::Delegates::CheckBox(this)); + ui->layoutsView->setItemDelegateForColumn(BORDERSCOLUMN, new Settings::Layouts::Delegates::CheckBox(this)); ui->layoutsView->setItemDelegateForColumn(ACTIVITYCOLUMN, new ActivitiesDelegate(this)); ui->layoutsView->setItemDelegateForColumn(SHAREDCOLUMN, new SharedDelegate(this));