File indexing completed on 2024-04-28 04:20:49
0001 // SPDX-FileCopyrightText: 2014 - 2022 Tobias Leupold <tl at stonemx dot de> 0002 // SPDX-FileCopyrightText: 2023 Johannes Zarl-Zierl <johannes@zarl-zierl.at> 0003 // 0004 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 0006 #ifndef DESCRIPTIONEDIT_H 0007 #define DESCRIPTIONEDIT_H 0008 0009 #include <KTextEdit> 0010 0011 class QKeyEvent; 0012 0013 namespace AnnotationDialog 0014 { 0015 0016 /** 0017 * @brief The DescriptionEdit class improves upon the KTextEdit, adding a changed() method and an intuitive API to the case 0018 * when several images have a conflicting description. 0019 * 0020 * \note Don't use the base class methods like QTextEdit::setPlainText() and QTextEdit::setPlaceholderText() to manipulate the 0021 * DescriptionEdit. We can't override these methods since they are not virtual, and private inheritance won't work here because 0022 * DescriptionEdit needs to be a QWidget. 0023 * 0024 */ 0025 class DescriptionEdit : public KTextEdit 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 explicit DescriptionEdit(QWidget *parent = nullptr); 0031 ~DescriptionEdit() override; 0032 0033 /** 0034 * @brief description 0035 * @return QTextEdit::toPlainText() 0036 */ 0037 QString description() const; 0038 0039 /** 0040 * @brief setDescription sets the text editor's contents as plain text and sets the comparison QString for changed(). 0041 * This action also removes the ConflictWarning text if set. 0042 * @param text 0043 */ 0044 void setDescription(const QString &text); 0045 0046 /** 0047 * @brief changed 0048 * @return \c true, if the text that was set with setDescription was changed. \c false otherwise. 0049 */ 0050 bool changed() const; 0051 0052 /** 0053 * @brief isEmpty is shorthand for description().isEmpty() 0054 * @return 0055 */ 0056 bool isEmpty() const; 0057 0058 /** 0059 * @brief setConflictWarning sets the text editor's placeholder text to the given QString and marks the editor to have a placeholder state. 0060 * This action also clears the editor's content. 0061 * @param placeholderText 0062 */ 0063 void setConflictWarning(const QString &placeholderText); 0064 0065 /** 0066 * @brief hasConflictWarning 0067 * @return \true, if there is currently a ConflictWarning text set for the DescriptionEdit 0068 */ 0069 bool hasConflictWarning() const; 0070 0071 Q_SIGNALS: 0072 void pageUpDownPressed(QKeyEvent *event); 0073 0074 private: 0075 void keyPressEvent(QKeyEvent *event) override; 0076 0077 QString m_originalText; 0078 }; 0079 0080 } 0081 0082 #endif // DESCRIPTIONEDIT_H 0083 0084 // vi:expandtab:tabstop=4 shiftwidth=4: