libyui-qt
QY2ListView.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: QY2ListView.h
20 
21  Author: Stefan Hundhammer <shundhammer@suse.de>
22 
23  This is a pure Qt widget - it can be used independently of YaST2.
24 
25 /-*/
26 
27 
28 #ifndef QY2ListView_h
29 #define QY2ListView_h
30 
31 #include <QTreeWidget>
32 #include <qtooltip.h>
33 #include <qpoint.h>
34 #include <qcolor.h>
35 #include <vector>
36 
37 #define FIXME_TOOLTIP 0
38 
39 
40 class QY2ListViewItem;
41 class QY2ListViewToolTip;
42 
43 
47 class QY2ListView : public QTreeWidget
48 {
49  Q_OBJECT
50 
51 public:
52 
56  QY2ListView( QWidget * parent );
57 
61  virtual ~QY2ListView();
62 
63 
64 public slots:
65 
71  virtual void selectSomething();
72 
77  virtual void clear();
78 
84  void updateItemStates();
85 
91  void updateItemData();
92 
96  void saveColumnWidths();
97 
102  void restoreColumnWidths();
103 
104 
105 signals:
106 
110  void columnClicked ( int button,
111  QTreeWidgetItem * item,
112  int col,
113  const QPoint & pos );
114 
118  void columnDoubleClicked ( int button,
119  QTreeWidgetItem * item,
120  int col,
121  const QPoint & pos );
122 
123 
124 public:
125 
137  virtual QString toolTip( QTreeWidgetItem * item, int column );
138 
144  bool sortByInsertionSequence() const { return _sortByInsertionSequence; }
145 
151 
156  int nextSerial() { return _nextSerial++; }
157 
162  virtual QSize minimumSizeHint() const;
163 
167  virtual bool eventFilter( QObject * obj, QEvent * event );
168 
169 
170 protected slots:
171 
177  void columnWidthChanged( int col, int oldSize, int newSize );
178 
182  void treeExpanded( QTreeWidgetItem * listViewItem );
183 
187  void treeCollapsed( QTreeWidgetItem * listViewItem );
188 
189 
190 protected:
191 
196  virtual void mousePressEvent( QMouseEvent * e );
197 
202  virtual void mouseReleaseEvent( QMouseEvent * );
203 
208  virtual void mouseDoubleClickEvent( QMouseEvent * );
209 
210 
211  //
212  // Data members
213  //
214 
215  QTreeWidgetItem * _mousePressedItem;
216  int _mousePressedCol;
217  Qt::MouseButton _mousePressedButton;
218 
219  std::vector<int> _savedColumnWidth;
220  bool _sortByInsertionSequence;
221  int _nextSerial;
222 
223  QY2ListViewToolTip * _toolTip;
224  bool _mouseButton1PressedInHeader;
225  bool _finalSizeChangeExpected;
226 };
227 
228 
229 
233 class QY2ListViewItem : public QTreeWidgetItem
234 {
235 public:
236 
240  QY2ListViewItem( QY2ListView * parentListView,
241  const QString & text = QString() );
242 
243 
247  QY2ListViewItem( QTreeWidgetItem * parentItem,
248  const QString & text = QString() );
249 
253  virtual ~QY2ListViewItem();
254 
261  virtual void updateStatus() {}
262 
269  virtual void updateData() {}
270 
275  virtual bool operator< ( const QTreeWidgetItem & other ) const;
276 
282  bool sortByInsertionSequence() const;
283 
288  int serial() const { return _serial; }
289 
294  bool compare(const QString& text1, const QString& text2) const;
295 
299  virtual QString smartSortKey(int column) const;
300 
307  virtual QString toolTip( int column ) { return QString(); }
308 
309 
310 protected:
311 
312  //
313  // Data members
314  //
315 
316  int _serial;
317 
318  QColor _textColor;
319  QColor _backgroundColor;
320 };
321 
322 
323 
328 {
329 public:
330 
334  QY2CheckListItem( QY2ListView * parentListView,
335  const QString & text );
336 
337 
341  QY2CheckListItem( QTreeWidgetItem * parentItem,
342  const QString & text );
343 
347  virtual ~QY2CheckListItem();
348 
355  virtual void updateStatus() {}
356 
363  virtual void updateData() {}
364 
369  int serial() const { return _serial; }
370 
375  void setTextColor( const QColor & col )
376  { _textColor = col; }
377 
382  void setBackgroundColor( const QColor & col )
383  { _backgroundColor = col; }
384 
391  virtual QString toolTip( int column ) { return QString(); }
392 
393 
394 protected:
395 
396  //
397  // Data members
398  //
399 
400  int _serial;
401 };
402 
403 
404 #if FIXME_TOOLTIP
405 
410 class QY2ListViewToolTip : public QToolTip
411 {
412 public:
413 
417  QY2ListViewToolTip( QY2ListView * parent )
418  : QToolTip( parent->viewport() )
419  , _listView( parent ) {}
420 
424  virtual ~QY2ListViewToolTip() {}
425 
426 
427 protected:
428 
434  virtual void maybeTip( const QPoint & p );
435 
436 
437  //
438  // Data members
439  //
440 
441  QY2ListView * _listView;
442 };
443 #endif
444 
445 #endif // ifndef QY2ListView_h
int serial() const
Definition: QY2ListView.h:288
QY2ListViewItem(QY2ListView *parentListView, const QString &text=QString())
Definition: QY2ListView.cc:368
bool sortByInsertionSequence() const
Definition: QY2ListView.h:144
virtual void setSortByInsertionSequence(bool sortByInsertionSequence)
Definition: QY2ListView.cc:355
virtual bool operator<(const QTreeWidgetItem &other) const
Definition: QY2ListView.cc:396
virtual QSize minimumSizeHint() const
Definition: QY2ListView.cc:348
void saveColumnWidths()
Definition: QY2ListView.cc:170
void setTextColor(const QColor &col)
Definition: QY2ListView.h:375
void columnWidthChanged(int col, int oldSize, int newSize)
Definition: QY2ListView.cc:289
void setBackgroundColor(const QColor &col)
Definition: QY2ListView.h:382
virtual QString smartSortKey(int column) const
Definition: QY2ListView.cc:461
QY2ListView(QWidget *parent)
Definition: QY2ListView.cc:37
virtual void clear()
Definition: QY2ListView.cc:102
void columnClicked(int button, QTreeWidgetItem *item, int col, const QPoint &pos)
bool compare(const QString &text1, const QString &text2) const
Definition: QY2ListView.cc:441
virtual void updateData()
Definition: QY2ListView.h:363
virtual void mouseDoubleClickEvent(QMouseEvent *)
Definition: QY2ListView.cc:267
virtual void updateStatus()
Definition: QY2ListView.h:355
virtual void updateData()
Definition: QY2ListView.h:269
virtual QString toolTip(QTreeWidgetItem *item, int column)
Definition: QY2ListView.cc:144
virtual bool eventFilter(QObject *obj, QEvent *event)
Definition: QY2ListView.cc:317
void updateItemStates()
Definition: QY2ListView.cc:110
virtual ~QY2CheckListItem()
Definition: QY2ListView.cc:491
virtual QString toolTip(int column)
Definition: QY2ListView.h:391
bool sortByInsertionSequence() const
Definition: QY2ListView.cc:429
void treeCollapsed(QTreeWidgetItem *listViewItem)
Definition: QY2ListView.cc:554
void columnDoubleClicked(int button, QTreeWidgetItem *item, int col, const QPoint &pos)
Definition: QY2ListView.h:327
Enhanced QTreeWidget.
Definition: QY2ListView.h:47
virtual QString toolTip(int column)
Definition: QY2ListView.h:307
QY2CheckListItem(QY2ListView *parentListView, const QString &text)
Definition: QY2ListView.cc:467
void treeExpanded(QTreeWidgetItem *listViewItem)
Definition: QY2ListView.cc:547
int serial() const
Definition: QY2ListView.h:369
Definition: QY2ListView.h:233
virtual ~QY2ListViewItem()
Definition: QY2ListView.cc:389
virtual ~QY2ListView()
Definition: QY2ListView.cc:72
void updateItemData()
Definition: QY2ListView.cc:127
virtual void mouseReleaseEvent(QMouseEvent *)
Definition: QY2ListView.cc:237
virtual void selectSomething()
Definition: QY2ListView.cc:82
int nextSerial()
Definition: QY2ListView.h:156
virtual void mousePressEvent(QMouseEvent *e)
Definition: QY2ListView.cc:212
void restoreColumnWidths()
Definition: QY2ListView.cc:185
virtual void updateStatus()
Definition: QY2ListView.h:261