Messagelib

themeeditor.h
1/******************************************************************************
2 *
3 * SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
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
21class QCheckBox;
22
23class QComboBox;
24class QSpinBox;
25class QLineEdit;
26
27namespace MessageList
28{
29namespace Core
30{
31class Item;
32class GroupHeaderItem;
33class MessageItem;
34class FakeItem;
35class ModelInvariantRowMapper;
36} // namespace Core
37
38namespace Utils
39{
40class ThemeColumnPropertiesDialog : public QDialog
41{
43public:
44 explicit ThemeColumnPropertiesDialog(QWidget *parent, Core::Theme::Column *column, const QString &title);
45
46protected:
47 Core::Theme::Column *const mColumn;
48 QLineEdit *mNameEdit = nullptr;
49 QCheckBox *mVisibleByDefaultCheck = nullptr;
50 QCheckBox *mIsSenderOrReceiverCheck = nullptr;
51 QComboBox *mMessageSortingCombo = nullptr;
52
53protected Q_SLOTS:
54 void slotOkButtonClicked();
55};
56
57class ThemePreviewDelegate : public Core::ThemeDelegate
58{
60public:
61 explicit ThemePreviewDelegate(QAbstractItemView *parent);
62 ~ThemePreviewDelegate() override;
63
64private:
65 Core::GroupHeaderItem *mSampleGroupHeaderItem = nullptr;
66 Core::FakeItem *mSampleMessageItem = nullptr;
67 Core::ModelInvariantRowMapper *mRowMapper = nullptr; // needed for the MessageItem above to be valid
68public:
69 Core::Item *itemFromIndex(const QModelIndex &index) const override;
70};
71
72class ThemePreviewWidget : public QTreeWidget
73{
75public:
76 explicit ThemePreviewWidget(QWidget *parent);
77 ~ThemePreviewWidget() override;
78 void setReadOnly(bool readOnly);
79
80private:
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
104private:
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
119public:
120 QSize sizeHint() const override;
121 void setTheme(Core::Theme *theme);
122
123protected:
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
133private:
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
147protected 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
162class ThemeContentItemSourceLabel : public QLabel
163{
165public:
166 ThemeContentItemSourceLabel(QWidget *parent, Core::Theme::ContentItem::Type type);
167 ~ThemeContentItemSourceLabel() override;
168
169public:
171 void startDrag();
172
173protected:
174 void mousePressEvent(QMouseEvent *e) override;
175 void mouseMoveEvent(QMouseEvent *e) override;
176
177private:
178 QPoint mMousePressPoint;
180};
181
182class ThemeEditor : public OptionSetEditor
183{
185public:
186 explicit ThemeEditor(QWidget *parent);
187 ~ThemeEditor() override;
188
189public:
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();
201 void themeNameChanged();
202
203private:
204 void fillViewHeaderPolicyCombo();
205
206protected Q_SLOTS:
207 void slotNameEditTextEdited(const QString &newName) override;
208 void slotIconSizeSpinBoxValueChanged(int val);
209
210private:
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 QSpinBox *mIconSizeSpinBox = nullptr;
221};
222} // namespace Utils
223} // namespace MessageList
Type
The available ContentItem types.
Definition theme.h:106
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
virtual bool event(QEvent *e) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:08:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.