File indexing completed on 2024-12-01 11:10:36
0001 /* 0002 SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef VIEWSCONTROLLER_H 0007 #define VIEWSCONTROLLER_H 0008 0009 // local 0010 #include <coretypes.h> 0011 #include "viewsmodel.h" 0012 #include "../../lattecorona.h" 0013 #include "../../data/viewdata.h" 0014 #include "../../data/viewstable.h" 0015 0016 // Qt 0017 #include <QAbstractItemModel> 0018 #include <QHash> 0019 #include <QItemSelection> 0020 #include <QList> 0021 #include <QMetaObject> 0022 #include <QSortFilterProxyModel> 0023 #include <QTableView> 0024 0025 // KDE 0026 #include <KMessageWidget> 0027 0028 namespace Latte { 0029 class CentralLayout; 0030 class Corona; 0031 class ViewsDialog; 0032 0033 namespace Settings { 0034 namespace Handler { 0035 class ViewsHandler; 0036 } 0037 namespace View { 0038 class ViewsTableView; 0039 } 0040 } 0041 } 0042 0043 namespace Latte { 0044 namespace Settings { 0045 namespace Controller { 0046 0047 class Views : public QObject 0048 { 0049 Q_OBJECT 0050 0051 public: 0052 explicit Views(Settings::Handler::ViewsHandler *parent); 0053 ~Views(); 0054 0055 QAbstractItemModel *proxyModel() const; 0056 QAbstractItemModel *baseModel() const; 0057 QTableView *view() const; 0058 0059 bool hasChangedData() const; 0060 0061 int viewsForRemovalCount() const; 0062 0063 void sortByColumn(int column, Qt::SortOrder order); 0064 0065 bool hasSelectedView() const; 0066 int selectedViewsCount() const; 0067 const Latte::Data::View currentData(const QString &id); 0068 const Data::ViewsTable selectedViewsCurrentData() const; 0069 0070 const Latte::Data::View appendViewFromViewTemplate(const Data::View &view); 0071 0072 void selectRow(const QString &id); 0073 0074 //! actions 0075 void reset(); 0076 void save(); 0077 0078 public slots: 0079 void copySelectedViews(); 0080 void cutSelectedViews(); 0081 void duplicateSelectedViews(); 0082 void pasteSelectedViews(); 0083 void removeSelectedViews(); 0084 0085 signals: 0086 void dataChanged(); 0087 0088 private: 0089 void init(); 0090 0091 bool hasValidOriginView(const Data::View &view); 0092 CentralLayout *originLayout(const Data::View &view); 0093 0094 int rowForId(QString id) const; 0095 QString uniqueViewName(QString name); 0096 QString visibleViewName(const QString &id) const; 0097 0098 Data::ViewsTable selectedViewsForClipboard(); 0099 0100 //! errors/warnings 0101 void messagesForErrorsWarnings(const Latte::CentralLayout *centralLayout, const bool &showNoErrorsMessage = false); 0102 void messageForErrorAppletsWithSameId(const Data::Error &error); 0103 void messageForErrorOrphanedParentAppletOfSubContainment(const Data::Error &error); 0104 void messageForWarningOrphanedSubContainments(const Data::Warning &warning); 0105 void messageForWarningAppletAndContainmentWithSameId(const Data::Warning &warning); 0106 0107 void showDefaultInlineMessageValidator(); 0108 void showDefaultPersistentErrorWarningInlineMessage(const QString &messageText, 0109 const KMessageWidget::MessageType &messageType, 0110 QList<QAction *> extraActions = QList<QAction *>(), 0111 const bool &showOpenLayoutAction = true); 0112 0113 0114 private slots: 0115 void loadConfig(); 0116 void saveConfig(); 0117 void storeColumnWidths(); 0118 void applyColumnWidths(); 0119 0120 void onCurrentLayoutChanged(); 0121 void onSelectionsChanged(); 0122 0123 void updateDoubledMoveDestinationRows(); 0124 0125 private: 0126 Settings::Handler::ViewsHandler *m_handler{nullptr}; 0127 0128 Settings::View::ViewsTableView *m_view{nullptr}; 0129 0130 int m_debugSaveCall{0}; 0131 0132 //! current active layout signals/slots 0133 QList<QMetaObject::Connection> m_currentLayoutConnections; 0134 0135 //! layoutsView ui settings 0136 int m_viewSortColumn{Model::Views::SCREENCOLUMN}; 0137 Qt::SortOrder m_viewSortOrder; 0138 QStringList m_viewColumnWidths; 0139 0140 KConfigGroup m_storage; 0141 0142 //! context menu actions for docks panels 0143 QAction *m_cutAction; 0144 QAction *m_copyAction; 0145 QAction *m_duplicateAction; 0146 QAction *m_pasteAction; 0147 0148 //! current data 0149 Model::Views *m_model{nullptr}; 0150 QSortFilterProxyModel *m_proxyModel{nullptr}; 0151 }; 0152 0153 } 0154 } 0155 } 0156 0157 #endif 0158