Messagelib

customtemplates.h
1/*
2 * SPDX-FileCopyrightText: 2006 Dmitry Morozhnikov <dmiceman@mail.ru>
3 * SPDX-FileCopyrightText: 2011-2024 Laurent Montel <montel@kde.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8#pragma once
9
10#include "templateparser_export.h"
11
12#include <QStyledItemDelegate>
13#include <QTreeWidgetItem>
14#include <QWidget>
15
17
18class Ui_CustomTemplatesBase;
19
20namespace TemplateParser
21{
22class CustomTemplateItem;
23/**
24 * @brief The CustomTemplates class
25 */
26class TEMPLATEPARSER_EXPORT CustomTemplates : public QWidget
27{
28 Q_OBJECT
29public:
30 enum Type {
31 TUniversal,
32 TReply,
33 TReplyAll,
34 TForward,
35 };
36
37public:
38 explicit CustomTemplates(const QList<KActionCollection *> &actionCollection, QWidget *parent = nullptr);
39 ~CustomTemplates() override;
40
41 void load();
42 void save();
43
44Q_SIGNALS:
45 void changed();
46 void templatesUpdated();
47
48private Q_SLOTS:
49 TEMPLATEPARSER_NO_EXPORT void slotInsertCommand(const QString &cmd, int adjustCursor = 0);
50 TEMPLATEPARSER_NO_EXPORT void slotTextChanged();
51 TEMPLATEPARSER_NO_EXPORT void slotAddClicked();
52 TEMPLATEPARSER_NO_EXPORT void slotRemoveClicked();
53 TEMPLATEPARSER_NO_EXPORT void slotListSelectionChanged();
54 TEMPLATEPARSER_NO_EXPORT void slotTypeActivated(int index);
55 TEMPLATEPARSER_NO_EXPORT void slotShortcutChanged(const QKeySequence &newSeq);
56 TEMPLATEPARSER_NO_EXPORT void slotItemChanged(QTreeWidgetItem *item, int column);
57 TEMPLATEPARSER_NO_EXPORT void slotHelpLinkClicked(const QString &);
58 TEMPLATEPARSER_NO_EXPORT void slotNameChanged(const QString &text);
59 TEMPLATEPARSER_NO_EXPORT void slotDuplicateClicked();
60
61private:
62 [[nodiscard]] TEMPLATEPARSER_NO_EXPORT bool nameAlreadyExists(const QString &str, QTreeWidgetItem *item = nullptr);
63 [[nodiscard]] TEMPLATEPARSER_NO_EXPORT QString indexToType(int index);
64 [[nodiscard]] TEMPLATEPARSER_NO_EXPORT QString createUniqueName(const QString &name) const;
65 TEMPLATEPARSER_NO_EXPORT void iconFromType(CustomTemplates::Type type, CustomTemplateItem *item);
66
67 /// These templates will be deleted when we're saving.
68 QStringList mItemsToDelete;
69
70 QIcon mReplyPix;
71 QIcon mReplyAllPix;
72 QIcon mForwardPix;
73
74 /// Whether or not to Q_EMIT the changed() signal. This is useful to disable when loading
75 /// templates, which changes the UI without user action
76 bool mBlockChangeSignal = false;
77
78 Ui_CustomTemplatesBase *const mUi;
79};
80
81class CustomTemplateItem : public QTreeWidgetItem
82{
83public:
84 explicit CustomTemplateItem(QTreeWidget *parent,
85 const QString &name,
86 const QString &content,
87 const QKeySequence &shortcut,
88 CustomTemplates::Type type,
89 const QString &to,
90 const QString &cc);
91 ~CustomTemplateItem() override;
92 void setCustomType(CustomTemplates::Type type);
93 [[nodiscard]] CustomTemplates::Type customType() const;
94
95 [[nodiscard]] QString to() const;
96 [[nodiscard]] QString cc() const;
97
98 void setTo(const QString &);
99 void setCc(const QString &);
100
101 [[nodiscard]] QString content() const;
102 void setContent(const QString &);
103
104 [[nodiscard]] QKeySequence shortcut() const;
105 void setShortcut(const QKeySequence &);
106
107 [[nodiscard]] QString oldName() const;
108 void setOldName(const QString &);
109
110private:
111 QString mName, mContent;
112 QKeySequence mShortcut;
113 CustomTemplates::Type mType;
114 QString mTo, mCC;
115};
116
117class CustomTemplateItemDelegate : public QStyledItemDelegate
118{
120public:
121 explicit CustomTemplateItemDelegate(QObject *parent = nullptr);
122 ~CustomTemplateItemDelegate() override;
123 [[nodiscard]] QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
124
125 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
126};
127}
The CustomTemplates class.
Q_OBJECTQ_OBJECT
QObject * parent() const const
QTreeWidgetItem * parent() const const
int type() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.