update settings Layout name delegate

pull/11/head
Michail Vourlakos 5 years ago
parent e5baecfb9f
commit 6e66907957

@ -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<Latte::SettingsDialog *>(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
}
}
}
}

@ -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

@ -29,15 +29,17 @@
#include <QDebug>
#include <QEvent>
#include <QKeyEvent>
#include <QLineEdit>
#include <QMouseEvent>
#include <QPainter>
#include <QStandardItemModel>
namespace Latte {
namespace Settings {
namespace View {
namespace Layouts {
namespace Delegates {
LayoutNameDelegate::LayoutNameDelegate(QObject *parent)
LayoutName::LayoutName(QObject *parent)
: QStyledItemDelegate(parent)
{
auto *settingsDialog = qobject_cast<Latte::SettingsDialog *>(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<QLineEdit *>(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<QLineEdit *>(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
}
}
}
}

@ -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

@ -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));

Loading…
Cancel
Save