1 /* 2 3 Firewall Builder 4 5 Copyright (C) 2003 NetCitadel, LLC 6 7 Author: Vadim Kurland vadim@fwbuilder.org 8 9 This program is free software which we release under the GNU General Public 10 License. You may redistribute and/or modify this program under the terms 11 of that license as published by the Free Software Foundation; either 12 version 2 of the License, or (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 To get a copy of the GNU General Public License, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 22 */ 23 24 25 #ifndef __OBJECTTREEVIEW_H_ 26 #define __OBJECTTREEVIEW_H_ 27 28 #include <QTreeWidget> 29 #include <QTreeWidgetItem> 30 #include <QMimeData> 31 #include <qtimer.h> 32 #include <QDragEnterEvent> 33 #include <QDropEvent> 34 #include <QMouseEvent> 35 #include <QDragMoveEvent> 36 #include <QKeyEvent> 37 #include <QFocusEvent> 38 #include <QDragLeaveEvent> 39 40 #include <vector> 41 #include <set> 42 43 namespace libfwbuilder { 44 class FWObject; 45 }; 46 47 class ProjectPanel; 48 class ObjectTreeViewItem; 49 50 class ObjectTreeView : public QTreeWidget 51 { 52 53 Q_OBJECT; 54 55 QTreeWidgetItem *item_before_drag_started; 56 QTreeWidgetItem *lastSelected; 57 QItemSelection lastSelection; 58 bool second_click; 59 bool selectionFrozen; 60 bool expandOrCollapse; 61 bool Lockable; 62 bool Unlockable; 63 bool startingDrag; 64 bool visible; 65 bool process_mouse_release_event; 66 std::set<int> expanded_objects; 67 std::vector<libfwbuilder::FWObject*> selectedObjects; 68 ProjectPanel* m_project; 69 70 QSet<QTreeWidgetItem*> resolveChildren(QTreeWidgetItem*); 71 72 QSet<QTreeWidgetItem*> resolveParents(QTreeWidgetItem*); 73 74 QString filter; 75 QSet<QStringList> expandedState; 76 void doExpandedState(bool save, QStringList &list, QTreeWidgetItem *item); 77 78 protected: 79 80 bool event( QEvent *event ); 81 82 virtual void dragEnterEvent( QDragEnterEvent *ev); 83 virtual void dragMoveEvent( QDragMoveEvent *ev); 84 virtual void dropEvent(QDropEvent *ev); 85 virtual void dragLeaveEvent( QDragLeaveEvent *ev); 86 87 virtual void keyPressEvent( QKeyEvent* ev ); 88 virtual void mousePressEvent( QMouseEvent *e ); 89 virtual void mouseReleaseEvent( QMouseEvent *e ); 90 //virtual void mouseDoubleClickEvent( QMouseEvent *e ); 91 virtual void mouseMoveEvent( QMouseEvent *e ); 92 93 virtual void keyReleaseEvent( QKeyEvent* ev ); 94 95 virtual void focusInEvent(QFocusEvent*); 96 virtual void focusOutEvent(QFocusEvent*); 97 98 virtual bool edit(const QModelIndex &index, 99 EditTrigger trigger, QEvent *event); 100 101 void startDrag(Qt::DropActions supportedActions); 102 103 virtual void paintEvent(QPaintEvent *ev); 104 105 void drawRow(QPainter *painter, const QStyleOptionViewItem &option, 106 const QModelIndex &index ) const; 107 108 public: 109 110 ObjectTreeView(ProjectPanel* project, 111 QWidget* parent = 0, 112 const char * name = 0, 113 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) 114 Qt::WFlags f = 0); 115 #else 116 Qt::WindowFlags f = 0); 117 #endif 118 freezeSelection(bool f)119 void freezeSelection(bool f) { selectionFrozen = f; } 120 getSelectedObjects()121 std::vector<libfwbuilder::FWObject*>& getSelectedObjects() 122 { return selectedObjects; } 123 124 bool isSelected(libfwbuilder::FWObject* obj); 125 int getNumSelected(); 126 127 libfwbuilder::FWObject* getCurrentObject(); 128 129 void editCurrentObject(); 130 131 void clearLastSelected(); 132 becomingVisible()133 void becomingVisible() { visible=true; } becomingHidden()134 void becomingHidden() { visible=false; } 135 void updateAfterPrefEdit(); 136 /* Under some circumstances, user may select several host or fw 137 * objects so that their children objects are selected as well 138 * (e.g. when shift-click is used). "Delete objects" or "group 139 * objects" operations will work on all children objects, which leads 140 * to unexpected results since it is not obvious to the user that 141 * children objects were selected (since they are invisible). We need 142 * to remove them from the list before we delete or perform other 143 * actions. 144 */ 145 std::vector<libfwbuilder::FWObject*> getSimplifiedSelection(); 146 ignoreNextMouseReleaseEvent()147 void ignoreNextMouseReleaseEvent() { process_mouse_release_event = false; } 148 149 void ExpandTreeItems(const std::set<int> &ids); getListOfExpandedObjectIds()150 const std::set<int>& getListOfExpandedObjectIds() { return expanded_objects; } 151 152 void showOrHideAttributesColumn(); 153 154 public slots: 155 156 void itemSelectionChanged(); 157 void resetSelection(); 158 void currentItemChanged(QTreeWidgetItem *cur); 159 void itemCollapsed(QTreeWidgetItem *itm); 160 void itemExpanded(QTreeWidgetItem *itm); 161 void itemOpened (); 162 virtual void updateTreeIcons(); 163 void setFilter(QString); 164 void updateFilter(); 165 166 signals: 167 168 // void showObjectInfo_sign(libfwbuilder::FWObject *); 169 void editCurrentObject_sign(); 170 void switchObjectInEditor_sign(libfwbuilder::FWObject*); 171 void objectDropped_sign(libfwbuilder::FWObject *); 172 void deleteObject_sign(libfwbuilder::FWObject *); 173 void contextMenuRequested_sign(const QPoint&); 174 void moveItems_sign(ObjectTreeViewItem *dest, 175 const std::list<libfwbuilder::FWObject *> &items); 176 }; 177 178 179 #endif 180 181