libyui-qt
2.43.5
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: YQTree.h 00020 00021 Author: Stefan Hundhammer <sh@suse.de> 00022 00023 /-*/ 00024 00025 #ifndef YQTree_h 00026 #define YQTree_h 00027 00028 #include <QFrame> 00029 #include <QTreeWidget> 00030 00031 #include <yui/YTree.h> 00032 00033 00034 class YQWidgetCaption; 00035 class YQTreeItem; 00036 00037 00038 class YQTree : public QFrame, public YTree 00039 { 00040 Q_OBJECT 00041 00042 public: 00043 00044 /** 00045 * Constructor. 00046 **/ 00047 YQTree( YWidget * parent, const std::string & label, bool multiSelection, bool recursiveSelection ); 00048 00049 /** 00050 * Destructor. 00051 **/ 00052 virtual ~YQTree(); 00053 00054 /** 00055 * Change the label text. 00056 * 00057 * Reimplemented from YSelectionWidget. 00058 **/ 00059 virtual void setLabel( const std::string & label ); 00060 00061 /** 00062 * Rebuild the displayed tree from the internally stored YTreeItems. 00063 * 00064 * The application should call this (once) after all items have been added 00065 * with addItem(). YTree::addItems() calls this automatically. 00066 * 00067 * Implemented from YTree. 00068 **/ 00069 virtual void rebuildTree(); 00070 00071 /** 00072 * Select or deselect an item. 00073 * 00074 * Reimplemented from YSelectionWidget. 00075 **/ 00076 virtual void selectItem( YItem * item, bool selected = true ); 00077 00078 /** 00079 * Deselect all items. 00080 * 00081 * Reimplemented from YSelectionWidget. 00082 **/ 00083 virtual void deselectAllItems(); 00084 00085 /** 00086 * Delete all items. 00087 * 00088 * Reimplemented from YSelectionWidget. 00089 **/ 00090 virtual void deleteAllItems(); 00091 00092 00093 /** 00094 * Set enabled/disbled state. 00095 * 00096 * Reimplemented from YWidget. 00097 **/ 00098 virtual void setEnabled( bool enabled ); 00099 00100 /** 00101 * Preferred width of the widget. 00102 * 00103 * Reimplemented from YWidget. 00104 **/ 00105 virtual int preferredWidth(); 00106 00107 /** 00108 * Preferred height of the widget. 00109 * 00110 * Reimplemented from YWidget. 00111 **/ 00112 virtual int preferredHeight(); 00113 00114 /** 00115 * Set the new size of the widget. 00116 * 00117 * Reimplemented from YWidget. 00118 **/ 00119 virtual void setSize( int newWidth, int newHeight ); 00120 00121 /** 00122 * Accept the keyboard focus. 00123 **/ 00124 virtual bool setKeyboardFocus(); 00125 00126 00127 /** 00128 * Return the the item that currently has the keyboard focus 00129 * or 0 if no item currently has the keyboard focus. 00130 * 00131 * Reimplemented from YMultiSelectionBox. 00132 **/ 00133 virtual YTreeItem * currentItem(); 00134 00135 00136 00137 protected slots: 00138 00139 00140 00141 /** 00142 * Propagate a tree item selection. 00143 * 00144 * This will trigger a 'SelectionChanged' event if 'notify' is set. 00145 **/ 00146 void slotSelectionChanged(); 00147 00148 /** 00149 * Propagate a tree item change. 00150 * 00151 * This will trigger a 'ValueChanged' event if 'notify' is set. 00152 **/ 00153 void slotItemChanged( QTreeWidgetItem * item); 00154 void slotItemClicked( QTreeWidgetItem * item, int column ); 00155 00156 00157 00158 00159 /** 00160 * Propagate a double click or pressing the space key on a tree item. 00161 * 00162 * This will trigger an 'Activated' event if 'notify' is set. 00163 **/ 00164 void slotActivated( QTreeWidgetItem * item); 00165 00166 /** 00167 * Propagate an "item expanded" event to the underlying YTreeItem. 00168 **/ 00169 void slotItemExpanded( QTreeWidgetItem * item ); 00170 00171 /** 00172 * Propagate an "item collapsed" event to the underlying YTreeItem. 00173 **/ 00174 void slotItemCollapsed( QTreeWidgetItem * item ); 00175 00176 /** 00177 * Propagate a context menu selection 00178 * 00179 * This will trigger an 'ContextMenuActivated' event if 'notifyContextMenu' is set. 00180 **/ 00181 void slotContextMenu ( const QPoint & pos ); 00182 00183 00184 protected: 00185 00186 /** 00187 * Select an item via the corresponding YQTreItem. 00188 **/ 00189 void selectItem( YQTreeItem * item ); 00190 00191 /** 00192 * Select or deselect an item, recursively 00193 **/ 00194 void selectItem(QTreeWidgetItem * item, bool selected, bool recursive); 00195 00196 /** 00197 * Open the branch of 'item' recursively to its toplevel item. 00198 **/ 00199 void openBranch( YQTreeItem * item ); 00200 00201 /** 00202 * Build a tree of items that will be displayed (YQTreeItems) from the 00203 * original items between iterators 'begin' and 'end' as child items of 00204 * 'parentItem' (or as toplevel items if 'parentItem' is 0). 00205 **/ 00206 void buildDisplayTree( YQTreeItem * parentItem, 00207 YItemIterator begin, 00208 YItemIterator end ); 00209 00210 // 00211 // Data members 00212 // 00213 00214 YQWidgetCaption * _caption; 00215 QTreeWidget * _qt_treeWidget; 00216 int _nextSerialNo; 00217 }; 00218 00219 00220 class YQTreeItem: public QTreeWidgetItem 00221 { 00222 public: 00223 00224 /** 00225 * Constructor for a top level item. 00226 **/ 00227 YQTreeItem( YQTree * tree, 00228 QTreeWidget * parent, 00229 YTreeItem * origItem, 00230 int serial ); 00231 00232 /** 00233 * Constructor for a non-top level item. 00234 **/ 00235 YQTreeItem( YQTree * tree, 00236 YQTreeItem * parent, 00237 YTreeItem * origItem, 00238 int serial ); 00239 00240 /** 00241 * Returns the original YTreeItem of which this item is a clone. 00242 **/ 00243 YTreeItem * origItem() { return _origItem; } 00244 00245 /** 00246 * Open this item. 00247 * 00248 * Reimplemented from QTreeWidgetItem. 00249 **/ 00250 virtual void setOpen( bool open ); 00251 00252 00253 private: 00254 00255 /** 00256 * Init function. All constructors end up here. 00257 **/ 00258 void init( YQTree * tree, 00259 YTreeItem * yTreeItem, 00260 int serial ); 00261 00262 00263 protected: 00264 00265 /** 00266 * Sort key of this item. 00267 * 00268 * Reimplemented from QTreeWidgetItem. 00269 **/ 00270 QString key( int column, bool ascending ) const; 00271 00272 00273 // 00274 // Data members 00275 // 00276 00277 YQTree * _tree; 00278 YTreeItem * _origItem; 00279 int _serialNo; 00280 00281 }; 00282 00283 00284 #endif // ifndef YQTree_h