File indexing completed on 2024-12-08 11:06:56
0001 /*************************************************************************** 0002 * Copyright (C) 2003-2006 by David Saxton * 0003 * david@bluehaze.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ***************************************************************************/ 0010 0011 #ifndef ITEMSELECTOR_H 0012 #define ITEMSELECTOR_H 0013 0014 // #include <q3listview.h> // gone in kde4.. 0015 0016 #include <QPixmap> 0017 #include <QString> 0018 #include <QTreeWidget> 0019 // #include <q3listview.h> 0020 0021 // #include <k3listview.h> 0022 0023 class ProjectItem; 0024 // class Q3StoredDrag; // 2018.08.12 - move to QTreeWidget 0025 class QMimeData; 0026 0027 namespace KateMDI 0028 { 0029 class ToolView; 0030 } 0031 0032 /** 0033 @short Contains info about item for ItemSelector 0034 @author David Saxton 0035 */ 0036 class ILVItem : public QObject, public QTreeWidgetItem /* K3ListViewItem */ 0037 { 0038 public: 0039 enum { 0040 DataRole_ID = Qt::UserRole, 0041 // note: add here isRemovable, projectItem 0042 } ILVItemRole; 0043 0044 ILVItem(QTreeWidget *parent, const QString &id); 0045 ILVItem(QTreeWidgetItem *parent, const QString &id); 0046 0047 void setProjectItem(ProjectItem *projectItem) 0048 { 0049 m_pProjectItem = projectItem; 0050 } 0051 ProjectItem *projectItem() const 0052 { 0053 return m_pProjectItem; 0054 } 0055 0056 // QString id() const { return m_id; } // 2018.08.12 - use value() 0057 0058 // QString key( int, bool ) const { return m_id; } // 2018.08.12 - use value() 0059 /** 0060 * Set whether the item can be removed from the listview by the user 0061 */ 0062 void setRemovable(bool isRemovable) 0063 { 0064 b_isRemovable = isRemovable; 0065 } 0066 /** 0067 * Whether the item can be removed from the listview by the user 0068 */ 0069 bool isRemovable() const 0070 { 0071 return b_isRemovable; 0072 } 0073 0074 protected: 0075 // QString m_id; // 2018.08.12 - use value() 0076 bool b_isRemovable; 0077 ProjectItem *m_pProjectItem; 0078 }; 0079 0080 /** 0081 @short Allows selection of generic items for dragging / clicking 0082 @author David Saxton 0083 */ 0084 class ItemSelector : public QTreeWidget /* K3ListView */ 0085 { 0086 Q_OBJECT 0087 public: 0088 ItemSelector(QWidget *parent); 0089 ~ItemSelector() override; 0090 /** 0091 * Adds a listview item to the ListView 0092 * @param caption The displayed text 0093 * @param id A unique identification for when it is dragged or activated 0094 * @param category The category it is in, eg "Integrated Circuits 0095 * @param icon The icon to be displayed to the left of the text 0096 * @param removable Whether the user can right-click on the item and select Remove 0097 */ 0098 void addItem(const QString &caption, const QString &id, const QString &category, const QIcon &icon = QIcon(), bool removable = false); 0099 0100 public slots: 0101 virtual void slotContextMenuRequested(const QPoint &pos); 0102 virtual void clear(); 0103 void slotRemoveSelectedItem(); 0104 0105 signals: 0106 /** 0107 * Emitted when a user selects an item and removes it 0108 */ 0109 void itemRemoved(const QString &id); 0110 void itemDoubleClicked(const QString &id); 0111 void itemClicked(const QString &id); 0112 void itemSelected(const QString &id); 0113 0114 protected: 0115 /** 0116 * Sets the caption of the ListView (eg 'Components' or 'Files') 0117 */ 0118 void setListCaption(const QString &caption); 0119 /** 0120 * Writes the open status (folded or unfolded) of "parent" items in the view 0121 * to the config file. 0122 */ 0123 void writeOpenStates(); 0124 /** 0125 * Reads the open status (folded or unfolded) of the given item. The default 0126 * status for non-existant items is true. 0127 */ 0128 bool readOpenState(const QString &id); 0129 0130 QTreeWidgetItem *selectedItem() const; 0131 0132 QMimeData *mimeData(const QList<QTreeWidgetItem *> items) const override; 0133 0134 private slots: 0135 void slotItemSelected(); 0136 void slotItemClicked(QTreeWidgetItem *item, int); 0137 void slotItemDoubleClicked(QTreeWidgetItem *, int); 0138 0139 private: 0140 /** 0141 * @return a dragobject encoding the currently selected component item. 0142 */ 0143 // Q3DragObject * dragObject(); 0144 0145 QStringList m_categories; 0146 }; 0147 0148 /** 0149 @short Allows selection of electrical components 0150 @author David Saxton 0151 */ 0152 class ComponentSelector : public ItemSelector 0153 { 0154 Q_OBJECT 0155 public: 0156 static ComponentSelector *self(KateMDI::ToolView *parent = nullptr); 0157 static QString toolViewIdentifier() 0158 { 0159 return "ComponentSelector"; 0160 } 0161 0162 private: 0163 ComponentSelector(KateMDI::ToolView *parent); 0164 static ComponentSelector *m_pSelf; 0165 }; 0166 0167 /** 0168 @short Allows selection of PIC parts (eg 'Pause') 0169 @author David Saxton 0170 */ 0171 class FlowPartSelector : public ItemSelector 0172 { 0173 Q_OBJECT 0174 public: 0175 static FlowPartSelector *self(KateMDI::ToolView *parent = nullptr); 0176 static QString toolViewIdentifier() 0177 { 0178 return "FlowPartSelector"; 0179 } 0180 0181 private: 0182 FlowPartSelector(KateMDI::ToolView *parent); 0183 static FlowPartSelector *m_pSelf; 0184 }; 0185 0186 /** 0187 @author David Saxton 0188 */ 0189 class MechanicsSelector : public ItemSelector 0190 { 0191 Q_OBJECT 0192 public: 0193 static MechanicsSelector *self(KateMDI::ToolView *parent = nullptr); 0194 static QString toolViewIdentifier() 0195 { 0196 return "MechanicsSelector"; 0197 } 0198 0199 private: 0200 MechanicsSelector(QWidget *parent = nullptr); 0201 static MechanicsSelector *m_pSelf; 0202 }; 0203 0204 #endif