Messagelib

customtemplates.h
1 /*
2  * SPDX-FileCopyrightText: 2006 Dmitry Morozhnikov <[email protected]>
3  * SPDX-FileCopyrightText: 2011-2023 Laurent Montel <[email protected]>
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 
16 class KActionCollection;
17 
18 class Ui_CustomTemplatesBase;
19 
20 namespace TemplateParser
21 {
22 class CustomTemplateItem;
23 /**
24  * @brief The CustomTemplates class
25  */
26 class TEMPLATEPARSER_EXPORT CustomTemplates : public QWidget
27 {
28  Q_OBJECT
29 public:
30  enum Type {
31  TUniversal,
32  TReply,
33  TReplyAll,
34  TForward,
35  };
36 
37 public:
38  explicit CustomTemplates(const QList<KActionCollection *> &actionCollection, QWidget *parent = nullptr);
39  ~CustomTemplates() override;
40 
41  void load();
42  void save();
43 
44 Q_SIGNALS:
45  void changed();
46  void templatesUpdated();
47 
48 private Q_SLOTS:
49  void slotInsertCommand(const QString &cmd, int adjustCursor = 0);
50  void slotTextChanged();
51  void slotAddClicked();
52  void slotRemoveClicked();
53  void slotListSelectionChanged();
54  void slotTypeActivated(int index);
55  void slotShortcutChanged(const QKeySequence &newSeq);
56  void slotItemChanged(QTreeWidgetItem *item, int column);
57  void slotHelpLinkClicked(const QString &);
58  void slotNameChanged(const QString &text);
59  void slotDuplicateClicked();
60 
61 private:
62  Q_REQUIRED_RESULT bool nameAlreadyExists(const QString &str, QTreeWidgetItem *item = nullptr);
63  Q_REQUIRED_RESULT QString indexToType(int index);
64  Q_REQUIRED_RESULT QString createUniqueName(const QString &name) const;
65  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 
81 class CustomTemplateItem : public QTreeWidgetItem
82 {
83 public:
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  CustomTemplates::Type customType() const;
94 
95  Q_REQUIRED_RESULT QString to() const;
96  Q_REQUIRED_RESULT QString cc() const;
97 
98  void setTo(const QString &);
99  void setCc(const QString &);
100 
101  Q_REQUIRED_RESULT QString content() const;
102  void setContent(const QString &);
103 
104  Q_REQUIRED_RESULT QKeySequence shortcut() const;
105  void setShortcut(const QKeySequence &);
106 
107  Q_REQUIRED_RESULT QString oldName() const;
108  void setOldName(const QString &);
109 
110 private:
111  QString mName, mContent;
112  QKeySequence mShortcut;
113  CustomTemplates::Type mType;
114  QString mTo, mCC;
115 };
116 
117 class CustomTemplateItemDelegate : public QStyledItemDelegate
118 {
119  Q_OBJECT
120 public:
121  explicit CustomTemplateItemDelegate(QObject *parent = nullptr);
122  ~CustomTemplateItemDelegate() override;
123  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.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Mar 26 2023 04:08:10 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.