Messagelib

themeeditor.h
1 /******************************************************************************
2  *
3  * SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <[email protected]>
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  *
7  *******************************************************************************/
8 
9 #pragma once
10 
11 #include "core/theme.h"
12 #include "core/themedelegate.h"
13 #include "utils/optionseteditor.h"
14 
15 #include <QLabel>
16 #include <QRect>
17 #include <QTreeWidget>
18 
19 #include <QDialog>
20 
21 class QCheckBox;
22 
23 class QComboBox;
25 class QLineEdit;
26 
27 namespace MessageList
28 {
29 namespace Core
30 {
31 class Item;
32 class GroupHeaderItem;
33 class MessageItem;
34 class FakeItem;
35 class ModelInvariantRowMapper;
36 } // namespace Core
37 
38 namespace Utils
39 {
40 class ThemeColumnPropertiesDialog : public QDialog
41 {
42  Q_OBJECT
43 public:
44  explicit ThemeColumnPropertiesDialog(QWidget *parent, Core::Theme::Column *column, const QString &title);
45 
46 protected:
47  Core::Theme::Column *const mColumn;
48  QLineEdit *mNameEdit = nullptr;
49  QCheckBox *mVisibleByDefaultCheck = nullptr;
50  QCheckBox *mIsSenderOrReceiverCheck = nullptr;
51  QComboBox *mMessageSortingCombo = nullptr;
52 
53 protected Q_SLOTS:
54  void slotOkButtonClicked();
55 };
56 
57 class ThemePreviewDelegate : public Core::ThemeDelegate
58 {
59  Q_OBJECT
60 public:
61  explicit ThemePreviewDelegate(QAbstractItemView *parent);
62  ~ThemePreviewDelegate() override;
63 
64 private:
65  Core::GroupHeaderItem *mSampleGroupHeaderItem = nullptr;
66  Core::FakeItem *mSampleMessageItem = nullptr;
67  Core::ModelInvariantRowMapper *mRowMapper = nullptr; // needed for the MessageItem above to be valid
68 public:
69  Core::Item *itemFromIndex(const QModelIndex &index) const override;
70 };
71 
72 class ThemePreviewWidget : public QTreeWidget
73 {
74  Q_OBJECT
75 public:
76  explicit ThemePreviewWidget(QWidget *parent);
77  ~ThemePreviewWidget() override;
78  void setReadOnly(bool readOnly);
79 
80 private:
81  // DnD insert position stuff
82 
83  /**
84  * The row we'll be inserting the dragged item into
85  */
86  enum RowInsertPosition {
87  AboveRow, ///< We'll insert above the currently hit row in mDelegate
88  InsideRow, ///< We'll insert inside the currently hit row in mDelegate
89  BelowRow ///< We'll insert below the currently hit row in mDelegate
90  };
91 
92  /**
93  * The position in row that we'll be inserting the dragged item
94  */
95  enum ItemInsertPosition {
96  OnLeftOfItem, ///< We'll insert on the left of the selected item
97  OnRightOfItem, ///< We'll insert on the right of the selected item
98  AsLastLeftItem, ///< We'll insert as last left item of the row (rightmost left item)
99  AsLastRightItem, ///< We'll insert as last right item of the row (leftmost right item)
100  AsFirstLeftItem, ///< We'll insert as first left item of the row (leftmost)
101  AsFirstRightItem ///< We'll insert as first right item of the row (rightmost)
102  };
103 
104 private:
105  ThemePreviewDelegate *mDelegate = nullptr;
106  QTreeWidgetItem *mGroupHeaderSampleItem = nullptr;
107  QRect mThemeSelectedContentItemRect;
108  Core::Theme::ContentItem *mSelectedThemeContentItem = nullptr;
109  Core::Theme::Column *mSelectedThemeColumn = nullptr;
110  QPoint mMouseDownPoint;
111  Core::Theme *mTheme = nullptr;
112  RowInsertPosition mRowInsertPosition;
113  ItemInsertPosition mItemInsertPosition;
114  QPoint mDropIndicatorPoint1;
115  QPoint mDropIndicatorPoint2;
116  bool mFirstShow;
117  bool mReadOnly;
118 
119 public:
120  QSize sizeHint() const override;
121  void setTheme(Core::Theme *theme);
122 
123 protected:
124  void dragMoveEvent(QDragMoveEvent *e) override;
125  void dragEnterEvent(QDragEnterEvent *e) override;
126  void dropEvent(QDropEvent *e) override;
127  void mouseMoveEvent(QMouseEvent *e) override;
128  void mousePressEvent(QMouseEvent *e) override;
129  void paintEvent(QPaintEvent *e) override;
130  void showEvent(QShowEvent *e) override;
131  void changeEvent(QEvent *event) override;
132 
133 private:
134  void internalHandleDragMoveEvent(QDragMoveEvent *e);
135  void internalHandleDragEnterEvent(QDragEnterEvent *e);
136 
137  /**
138  * Computes the drop insert position for the dragged item at position pos.
139  * Returns true if the dragged item can be inserted somewhere and
140  * false otherwise. Sets mRowInsertPosition, mItemInsertPosition,
141  * mDropIndicatorPoint1 ,mDropIndicatorPoint2.
142  */
143  bool computeContentItemInsertPosition(const QPoint &pos, Core::Theme::ContentItem::Type type);
144 
145  void applyThemeColumnWidths();
146 
147 protected Q_SLOTS:
148  void slotHeaderContextMenuRequested(const QPoint &pos);
149  void slotAddColumn();
150  void slotColumnProperties();
151  void slotDeleteColumn();
152  void slotDisabledFlagsMenuTriggered(QAction *act);
153  void slotForegroundColorMenuTriggered(QAction *act);
154  void slotFontMenuTriggered(QAction *act);
155  void slotSoftenActionTriggered(bool);
156  void slotGroupHeaderBackgroundModeMenuTriggered(QAction *act);
157  void slotGroupHeaderBackgroundStyleMenuTriggered(QAction *act);
158  void slotMoveColumnToLeft();
159  void slotMoveColumnToRight();
160 };
161 
162 class ThemeContentItemSourceLabel : public QLabel
163 {
164  Q_OBJECT
165 public:
166  ThemeContentItemSourceLabel(QWidget *parent, Core::Theme::ContentItem::Type type);
167  ~ThemeContentItemSourceLabel() override;
168 
169 public:
170  Core::Theme::ContentItem::Type type() const;
171  void startDrag();
172 
173 protected:
174  void mousePressEvent(QMouseEvent *e) override;
175  void mouseMoveEvent(QMouseEvent *e) override;
176 
177 private:
178  QPoint mMousePressPoint;
180 };
181 
182 class ThemeEditor : public OptionSetEditor
183 {
184  Q_OBJECT
185 public:
186  explicit ThemeEditor(QWidget *parent);
187  ~ThemeEditor() override;
188 
189 public:
190  /**
191  * Sets the option set to be edited.
192  * Saves and forgets any previously option set that was being edited.
193  * The set parameter may be 0: in this case the editor is simply disabled.
194  */
195  void editTheme(Core::Theme *set);
196 
197  Core::Theme *editedTheme() const;
198 
199  void commit();
200 Q_SIGNALS:
201  void themeNameChanged();
202 
203 private:
204  void fillViewHeaderPolicyCombo();
205 
206 protected Q_SLOTS:
207  void slotNameEditTextEdited(const QString &newName) override;
208  void slotIconSizeSpinBoxValueChanged(int val);
209 
210 private:
211  void setReadOnly(bool readOnly);
212 
213  Core::Theme *mCurrentTheme = nullptr; // shallow, may be null!
214 
215  // Appearance tab
216  ThemePreviewWidget *mPreviewWidget = nullptr;
217 
218  // Advanced tab
219  QComboBox *mViewHeaderPolicyCombo = nullptr;
220  KPluralHandlingSpinBox *mIconSizeSpinBox = nullptr;
221 };
222 } // namespace Utils
223 } // namespace MessageList
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
Q_SIGNALSQ_SIGNALS
Type
The available ContentItem types.
Definition: theme.h:107
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Mar 24 2023 04:08:32 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.