From 2b1464fb1b8c74465eba9b7ac0945e6d70ee010f Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sun, 4 Apr 2021 11:07:45 +0300 Subject: [PATCH] provide genericbasictable through meta system --- app/CMakeLists.txt | 1 + app/data/CMakeLists.txt | 1 + app/data/genericbasictable.cpp | 42 +++++++++++ app/data/genericbasictable.h | 48 +++++++++++++ app/data/genericdata.cpp | 4 -- app/data/genericdata.h | 9 ++- app/data/generictable.h | 2 +- app/data/screendata.h | 1 + .../viewsdialog/delegates/CMakeLists.txt | 6 ++ .../delegates/singleoptiondelegate.cpp | 70 +++++++++++++++++++ .../delegates/singleoptiondelegate.h | 59 ++++++++++++++++ app/settings/viewsdialog/viewsmodel.h | 4 +- 12 files changed, 237 insertions(+), 10 deletions(-) create mode 100644 app/data/genericbasictable.cpp create mode 100644 app/data/genericbasictable.h create mode 100644 app/settings/viewsdialog/delegates/CMakeLists.txt create mode 100644 app/settings/viewsdialog/delegates/singleoptiondelegate.cpp create mode 100644 app/settings/viewsdialog/delegates/singleoptiondelegate.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 5a0f9ef47..f1b591803 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -24,6 +24,7 @@ add_subdirectory(settings/exporttemplatedialog/delegates) add_subdirectory(settings/settingsdialog) add_subdirectory(settings/settingsdialog/delegates) add_subdirectory(settings/viewsdialog) +add_subdirectory(settings/viewsdialog/delegates) add_subdirectory(shortcuts) add_subdirectory(templates) add_subdirectory(tools) diff --git a/app/data/CMakeLists.txt b/app/data/CMakeLists.txt index 2e7235527..f56a66e30 100644 --- a/app/data/CMakeLists.txt +++ b/app/data/CMakeLists.txt @@ -2,6 +2,7 @@ set(lattedock-app_SRCS ${lattedock-app_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/activitydata.cpp ${CMAKE_CURRENT_SOURCE_DIR}/appletdata.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/genericbasictable.cpp ${CMAKE_CURRENT_SOURCE_DIR}/genericdata.cpp ${CMAKE_CURRENT_SOURCE_DIR}/generictable.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layoutdata.cpp diff --git a/app/data/genericbasictable.cpp b/app/data/genericbasictable.cpp new file mode 100644 index 000000000..28a416ced --- /dev/null +++ b/app/data/genericbasictable.cpp @@ -0,0 +1,42 @@ +/* + * Copyright 2021 Michail Vourlakos + * + * This file is part of Latte-Dock + * + * Latte-Dock is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * Latte-Dock is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "genericbasictable.h" + +namespace Latte { +namespace Data { + +GenericBasicTable::GenericBasicTable() + : GenericTable() +{ +} + +GenericBasicTable::GenericBasicTable(GenericBasicTable &&o) + : GenericTable(o) +{ +} + +GenericBasicTable::GenericBasicTable(const GenericBasicTable &o) + : GenericTable(o) +{ +} + +} +} diff --git a/app/data/genericbasictable.h b/app/data/genericbasictable.h new file mode 100644 index 000000000..02a1855ce --- /dev/null +++ b/app/data/genericbasictable.h @@ -0,0 +1,48 @@ +/* + * Copyright 2021 Michail Vourlakos + * + * This file is part of Latte-Dock + * + * Latte-Dock is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * Latte-Dock is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef GENERICBASICTABLE_H +#define GENERICBASICTABLE_H + +// local +#include "genericdata.h" +#include "generictable.h" + +// Qt +#include + +namespace Latte { +namespace Data { + +class GenericBasicTable : public GenericTable +{ +public: + GenericBasicTable(); + GenericBasicTable(GenericBasicTable &&o); + GenericBasicTable(const GenericBasicTable &o); +}; + +} +} + +Q_DECLARE_METATYPE(Latte::Data::Generic) +Q_DECLARE_METATYPE(Latte::Data::GenericBasicTable) + +#endif diff --git a/app/data/genericdata.cpp b/app/data/genericdata.cpp index 21e1fa56d..4232ae4c5 100644 --- a/app/data/genericdata.cpp +++ b/app/data/genericdata.cpp @@ -23,10 +23,6 @@ namespace Latte { namespace Data { -Generic::Generic() -{ -} - Generic::Generic(Generic &&o) : id(o.id), name(o.name) diff --git a/app/data/genericdata.h b/app/data/genericdata.h index bdd4c5f70..e802e6273 100644 --- a/app/data/genericdata.h +++ b/app/data/genericdata.h @@ -21,7 +21,10 @@ #ifndef GENERICDATA_H #define GENERICDATA_H -//! Qt +// local +#include "generictable.h" + +// Qt #include namespace Latte { @@ -30,7 +33,7 @@ namespace Data { class Generic { public: - Generic(); + Generic() = default; Generic(Generic &&o); Generic(const Generic &o); @@ -48,4 +51,6 @@ public: } } + + #endif diff --git a/app/data/generictable.h b/app/data/generictable.h index e92456df5..c421de118 100644 --- a/app/data/generictable.h +++ b/app/data/generictable.h @@ -30,7 +30,7 @@ namespace Latte { namespace Data { -template +template class GenericTable { diff --git a/app/data/screendata.h b/app/data/screendata.h index 01bc3f1cf..bb76e8892 100644 --- a/app/data/screendata.h +++ b/app/data/screendata.h @@ -64,5 +64,6 @@ typedef GenericTable ScreensTable; } Q_DECLARE_METATYPE(Latte::Data::Screen) +Q_DECLARE_METATYPE(Latte::Data::ScreensTable) #endif diff --git a/app/settings/viewsdialog/delegates/CMakeLists.txt b/app/settings/viewsdialog/delegates/CMakeLists.txt new file mode 100644 index 000000000..c2dcf696e --- /dev/null +++ b/app/settings/viewsdialog/delegates/CMakeLists.txt @@ -0,0 +1,6 @@ +set(lattedock-app_SRCS + ${lattedock-app_SRCS} + ${CMAKE_CURRENT_SOURCE_DIR}/singleoptiondelegate.cpp + PARENT_SCOPE +) + diff --git a/app/settings/viewsdialog/delegates/singleoptiondelegate.cpp b/app/settings/viewsdialog/delegates/singleoptiondelegate.cpp new file mode 100644 index 000000000..ef8f2d6b7 --- /dev/null +++ b/app/settings/viewsdialog/delegates/singleoptiondelegate.cpp @@ -0,0 +1,70 @@ +/* +* Copyright 2021 Michail Vourlakos +* +* This file is part of Latte-Dock +* +* Latte-Dock is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* Latte-Dock is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#include "singleoptiondelegate.h" + +// local +#include "../viewsmodel.h" +#include "../../../data/genericbasictable.h" + +// Qt +#include +#include + +namespace Latte { +namespace Settings { +namespace View { +namespace Delegate { + +SingleOption::SingleOption(QObject *parent) + : QStyledItemDelegate(parent) +{ +} + +QWidget *SingleOption::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QPushButton *button = new QPushButton(parent); + + QMenu *menu = new QMenu(button); + button->setMenu(menu); + menu->setMinimumWidth(option.rect.width()); + + bool isViewActive = index.data(Model::Views::ISACTIVEROLE).toBool(); + + QString currentChoice = index.data(Qt::UserRole).toString(); + Latte::Data::GenericBasicTable choices = index.data(Model::Views::CHOICESROLE).value(); + + for (int i=0; isetData(choices[i].id); + + if (choices[i].id == currentChoice) { + action->setIcon(QIcon::fromTheme("dialog-yes")); + } + + menu->addAction(action); + } + + return button; +} + +} +} +} +} diff --git a/app/settings/viewsdialog/delegates/singleoptiondelegate.h b/app/settings/viewsdialog/delegates/singleoptiondelegate.h new file mode 100644 index 000000000..62cf163b8 --- /dev/null +++ b/app/settings/viewsdialog/delegates/singleoptiondelegate.h @@ -0,0 +1,59 @@ +/* +* Copyright 2021 Michail Vourlakos +* +* This file is part of Latte-Dock +* +* Latte-Dock is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* Latte-Dock is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +#ifndef SINGLEOPTIONDELEGATE_H +#define SINGLEOPTIONDELEGATE_H + +// local +#include "../../../data/genericdata.h" + +// Qt +#include +#include + +class QModelIndex; +class QWidget; +class QVariant; + +namespace Latte { +namespace Settings { +namespace View { +namespace Delegate { + +class SingleOption : public QStyledItemDelegate +{ + Q_OBJECT +public: + SingleOption(QObject *parent); + + 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 updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + //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; + +}; + +} +} +} +} + +#endif diff --git a/app/settings/viewsdialog/viewsmodel.h b/app/settings/viewsdialog/viewsmodel.h index 945034a93..2bbd7562c 100644 --- a/app/settings/viewsdialog/viewsmodel.h +++ b/app/settings/viewsdialog/viewsmodel.h @@ -55,9 +55,7 @@ public: IDROLE = Qt::UserRole + 1, NAMEROLE, ISACTIVEROLE, - SCREENSLISTROLE, - EDGESLISTROLE, - SUBCONTAINMENTSIDSROLE, + CHOICESROLE, SORTINGROLE };