File indexing completed on 2024-04-21 16:32:03
0001 /** 0002 * SPDX-FileCopyrightText: (C) 2005 Sébastien Laoût <slaout@linux62.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef TAGEDIT_H 0008 #define TAGEDIT_H 0009 0010 #include <QDialog> 0011 #include <QItemDelegate> 0012 #include <QTreeWidgetItem> 0013 #include <QtCore/QList> 0014 0015 #include "tag.h" 0016 0017 class QCheckBox; 0018 class QFontComboBox; 0019 class QGroupBox; 0020 class QHBoxLayout; 0021 class QLabel; 0022 class QLineEdit; 0023 class QTreeWidget; 0024 0025 class QKeyEvent; 0026 class QMouseEvent; 0027 0028 class KIconButton; 0029 class QPushButton; 0030 class QKeySequence; 0031 class KShortcutWidget; 0032 0033 class FontSizeCombo; 0034 class KColorCombo2; 0035 0036 class StateCopy 0037 { 0038 public: 0039 typedef QList<StateCopy *> List; 0040 explicit StateCopy(State *old = nullptr); 0041 ~StateCopy(); 0042 State *oldState; 0043 State *newState; 0044 void copyBack(); 0045 }; 0046 0047 class TagCopy 0048 { 0049 public: 0050 typedef QList<TagCopy *> List; 0051 explicit TagCopy(Tag *old = nullptr); 0052 ~TagCopy(); 0053 Tag *oldTag; 0054 Tag *newTag; 0055 StateCopy::List stateCopies; 0056 void copyBack(); 0057 bool isMultiState(); 0058 }; 0059 0060 class TagListViewItem : public QTreeWidgetItem 0061 { 0062 friend class TagListDelegate; 0063 0064 public: 0065 TagListViewItem(QTreeWidget *parent, TagCopy *tagCopy); 0066 TagListViewItem(QTreeWidgetItem *parent, TagCopy *tagCopy); 0067 TagListViewItem(QTreeWidget *parent, QTreeWidgetItem *after, TagCopy *tagCopy); 0068 TagListViewItem(QTreeWidgetItem *parent, QTreeWidgetItem *after, TagCopy *tagCopy); 0069 TagListViewItem(QTreeWidget *parent, StateCopy *stateCopy); 0070 TagListViewItem(QTreeWidgetItem *parent, StateCopy *stateCopy); 0071 TagListViewItem(QTreeWidget *parent, QTreeWidgetItem *after, StateCopy *stateCopy); 0072 TagListViewItem(QTreeWidgetItem *parent, QTreeWidgetItem *after, StateCopy *stateCopy); 0073 ~TagListViewItem() override; 0074 TagCopy *tagCopy() 0075 { 0076 return m_tagCopy; 0077 } 0078 StateCopy *stateCopy() 0079 { 0080 return m_stateCopy; 0081 } 0082 bool isEmblemObligatory(); 0083 TagListViewItem *lastChild(); 0084 TagListViewItem *prevSibling(); 0085 TagListViewItem *nextSibling(); 0086 TagListViewItem *parent() const; // Reimplemented to cast the return value 0087 int width(const QFontMetrics &fontMetrics, const QTreeWidget *listView, int column) const; 0088 void setup(); 0089 0090 private: 0091 TagCopy *m_tagCopy; 0092 StateCopy *m_stateCopy; 0093 }; 0094 0095 Q_DECLARE_METATYPE(TagListViewItem *); 0096 0097 class TagListView : public QTreeWidget 0098 { 0099 Q_OBJECT 0100 public: 0101 explicit TagListView(QWidget *parent = nullptr); 0102 ~TagListView() override; 0103 void keyPressEvent(QKeyEvent *event) override; 0104 void mouseDoubleClickEvent(QMouseEvent *event) override; 0105 void mousePressEvent(QMouseEvent *event) override; 0106 void mouseReleaseEvent(QMouseEvent *event) override; 0107 TagListViewItem *currentItem() const; // Reimplemented to cast the return value 0108 TagListViewItem *firstChild() const; // Reimplemented to cast the return value 0109 TagListViewItem *lastItem() const; // Reimplemented to cast the return value 0110 Q_SIGNALS: 0111 void deletePressed(); 0112 void doubleClickedItem(); 0113 }; 0114 0115 /** 0116 * @author Sébastien Laoût 0117 */ 0118 class TagsEditDialog : public QDialog 0119 { 0120 Q_OBJECT 0121 public: 0122 explicit TagsEditDialog(QWidget *parent = nullptr, State *stateToEdit = nullptr, bool addNewTag = false); 0123 ~TagsEditDialog() override; 0124 State::List deletedStates() 0125 { 0126 return m_deletedStates; 0127 } 0128 State::List addedStates() 0129 { 0130 return m_addedStates; 0131 } 0132 TagListViewItem *itemForState(State *state); 0133 0134 void accept() override; 0135 void reject() override; 0136 0137 private Q_SLOTS: 0138 void newTag(); 0139 void newState(); 0140 void moveUp(); 0141 void moveDown(); 0142 void deleteTag(); 0143 void renameIt(); 0144 void capturedShortcut(const QKeySequence &shortcut); 0145 void removeShortcut(); 0146 void removeEmblem(); 0147 void modified(); 0148 void currentItemChanged(QTreeWidgetItem *item, QTreeWidgetItem *next = nullptr); 0149 void selectUp(); 0150 void selectDown(); 0151 void selectLeft(); 0152 void selectRight(); 0153 void resetTreeSizeHint(); 0154 0155 private: 0156 void loadBlankState(); 0157 void loadStateFrom(State *state); 0158 void loadTagFrom(Tag *tag); 0159 void saveStateTo(State *state); 0160 void saveTagTo(Tag *tag); 0161 void ensureCurrentItemVisible(); 0162 TagListView *m_tags; 0163 QPushButton *m_moveUp; 0164 QPushButton *m_moveDown; 0165 QPushButton *m_deleteTag; 0166 QLineEdit *m_tagName; 0167 KShortcutWidget *m_shortcut; 0168 QPushButton *m_removeShortcut; 0169 QCheckBox *m_inherit; 0170 QGroupBox *m_tagBox; 0171 QHBoxLayout *m_tagBoxLayout; 0172 QGroupBox *m_stateBox; 0173 QHBoxLayout *m_stateBoxLayout; 0174 QLabel *m_stateNameLabel; 0175 QLineEdit *m_stateName; 0176 KIconButton *m_emblem; 0177 QPushButton *m_removeEmblem; 0178 QPushButton *m_bold; 0179 QPushButton *m_underline; 0180 QPushButton *m_italic; 0181 QPushButton *m_strike; 0182 KColorCombo2 *m_textColor; 0183 QFontComboBox *m_font; 0184 FontSizeCombo *m_fontSize; 0185 KColorCombo2 *m_backgroundColor; 0186 QLineEdit *m_textEquivalent; 0187 QCheckBox *m_onEveryLines; 0188 QCheckBox *m_allowCrossRefernce; 0189 0190 TagCopy::List m_tagCopies; 0191 State::List m_deletedStates; 0192 State::List m_addedStates; 0193 0194 bool m_loading; 0195 }; 0196 0197 class TagListDelegate : public QItemDelegate 0198 { 0199 Q_OBJECT 0200 0201 public: 0202 explicit TagListDelegate(QWidget *parent = nullptr) 0203 : QItemDelegate(parent) 0204 { 0205 } 0206 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; 0207 }; 0208 0209 #endif // TAGEDIT_H