summaryrefslogtreecommitdiffabout
path: root/qtcompat/qcombotableitem.h
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /qtcompat/qcombotableitem.h
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'qtcompat/qcombotableitem.h') (more/less context) (ignore whitespace changes)
-rw-r--r--qtcompat/qcombotableitem.h571
1 files changed, 571 insertions, 0 deletions
diff --git a/qtcompat/qcombotableitem.h b/qtcompat/qcombotableitem.h
new file mode 100644
index 0000000..5688c1c
--- a/dev/null
+++ b/qtcompat/qcombotableitem.h
@@ -0,0 +1,571 @@
1/****************************************************************************
2**
3** Definition of QTable widget class
4**
5** Created : 000607
6**
7** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
8**
9** This file is part of the table module of the Qt GUI Toolkit.
10**
11** This file may be distributed under the terms of the Q Public License
12** as defined by Trolltech AS of Norway and appearing in the file
13** LICENSE.QPL included in the packaging of this file.
14**
15** This file may be distributed and/or modified under the terms of the
16** GNU General Public License version 2 as published by the Free Software
17** Foundation and appearing in the file LICENSE.GPL included in the
18** packaging of this file.
19**
20** Licensees holding valid Qt Enterprise Edition licenses may use this
21** file in accordance with the Qt Commercial License Agreement provided
22** with the Software.
23**
24** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26**
27** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
28** information about Qt Commercial License Agreements.
29** See http://www.trolltech.com/qpl/ for QPL licensing information.
30** See http://www.trolltech.com/gpl/ for GPL licensing information.
31**
32** Contact info@trolltech.com if any conditions of this licensing are
33** not clear to you.
34**
35**********************************************************************/
36
37#ifndef QTCOMPAT_QCOMBOTABLEITEM_H
38#define QTCOMPAT_QCOMBOTABLEITEM_H
39
40#include "qtable.h"
41#include "qstringlist.h"
42
43class QComboBox;
44class QWidget;
45class QPainter;
46
47#define QM_EXPORT_TABLE Q_EXPORT
48
49/*US
50
51#ifndef QT_H
52#include "qscrollview.h"
53#include "qpixmap.h"
54#include "qptrvector.h"
55#include "qheader.h"
56#include "qmemarray.h"
57#include "qptrlist.h"
58#include "qguardedptr.h"
59#include "qshared.h"
60#include "qintdict.h"
61#include "qstringlist.h"
62#endif // QT_H
63
64#ifndef QT_NO_TABLE
65
66#if !defined( QT_MODULE_TABLE ) || defined( QT_LICENSE_PROFESSIONAL ) || defined( QT_INTERNAL_TABLE )
67#define QM_EXPORT_TABLE
68#ifndef QM_TEMPLATE_EXTERN_TABLE
69# define QM_TEMPLATE_EXTERN_TABLE
70#endif
71#else
72#define QM_EXPORT_TABLE Q_EXPORT
73#define QM_TEMPLATE_EXTERN_TABLE Q_TEMPLATE_EXTERN
74#endif
75
76class QTableHeader;
77class QValidator;
78class QTable;
79class QPaintEvent;
80class QTimer;
81class QResizeEvent;
82class QComboBox;
83class QCheckBox;
84class QDragObject;
85
86struct QTablePrivate;
87struct QTableHeaderPrivate;
88
89
90class QM_EXPORT_TABLE QTableSelection
91{
92public:
93 QTableSelection();
94 QTableSelection( int start_row, int start_col, int end_row, int end_col );
95 void init( int row, int col );
96 void expandTo( int row, int col );
97 bool operator==( const QTableSelection &s ) const;
98 bool operator!=( const QTableSelection &s ) const { return !(operator==(s)); }
99
100 int topRow() const { return tRow; }
101 int bottomRow() const { return bRow; }
102 int leftCol() const { return lCol; }
103 int rightCol() const { return rCol; }
104 int anchorRow() const { return aRow; }
105 int anchorCol() const { return aCol; }
106 int numRows() const;
107 int numCols() const;
108
109 bool isActive() const { return active; }
110 bool isEmpty() const { return numRows() == 0; }
111
112private:
113 uint active : 1;
114 uint inited : 1;
115 int tRow, lCol, bRow, rCol;
116 int aRow, aCol;
117};
118
119#define Q_DEFINED_QTABLE_SELECTION
120#include "qwinexport.h"
121
122
123class QM_EXPORT_TABLE QTableItem : public Qt
124{
125 friend class QTable;
126
127public:
128 enum EditType { Never, OnTyping, WhenCurrent, Always };
129
130 QTableItem( QTable *table, EditType et );
131 QTableItem( QTable *table, EditType et, const QString &text );
132 QTableItem( QTable *table, EditType et, const QString &text,
133 const QPixmap &p );
134 virtual ~QTableItem();
135
136 virtual QPixmap pixmap() const;
137 virtual QString text() const;
138 virtual void setPixmap( const QPixmap &p );
139 virtual void setText( const QString &t );
140 QTable *table() const { return t; }
141
142 virtual int alignment() const;
143 virtual void setWordWrap( bool b );
144 bool wordWrap() const;
145
146 EditType editType() const;
147 virtual QWidget *createEditor() const;
148 virtual void setContentFromEditor( QWidget *w );
149 virtual void setReplaceable( bool );
150 bool isReplaceable() const;
151
152 virtual QString key() const;
153 virtual QSize sizeHint() const;
154
155 virtual void setSpan( int rs, int cs );
156 int rowSpan() const;
157 int colSpan() const;
158
159 virtual void setRow( int r );
160 virtual void setCol( int c );
161 int row() const;
162 int col() const;
163
164 virtual void paint( QPainter *p, const QColorGroup &cg,
165 const QRect &cr, bool selected );
166
167 void updateEditor( int oldRow, int oldCol );
168
169 virtual void setEnabled( bool b );
170 bool isEnabled() const;
171
172 virtual int rtti() const;
173 static int RTTI;
174
175private:
176 QString txt;
177 QPixmap pix;
178 QTable *t;
179 EditType edType;
180 uint wordwrap : 1;
181 uint tcha : 1;
182 uint enabled : 1;
183 int rw, cl;
184 int rowspan, colspan;
185#if (QT_VERSION >= 0x040000)
186#error "Add a setAlignment() function in 4.0 (but no d pointer)"
187#endif
188};
189
190#define Q_DEFINED_QTABLE_ITEM
191#include "qwinexport.h"
192*/
193class QM_EXPORT_TABLE QComboTableItem : public QTableItem
194{
195public:
196 QComboTableItem( QTable *table, const QStringList &list, bool editable = FALSE );
197 virtual QWidget *createEditor() const;
198 virtual void setContentFromEditor( QWidget *w );
199 virtual void paint( QPainter *p, const QColorGroup &cg,
200 const QRect &cr, bool selected );
201 virtual void setCurrentItem( int i );
202 virtual void setCurrentItem( const QString &i );
203 int currentItem() const;
204 QString currentText() const;
205 int count() const;
206#if !defined(Q_NO_USING_KEYWORD)
207 //using QTableItem::text;
208#endif
209
210
211 QString text( int i ) const;
212 virtual void setEditable( bool b );
213 bool isEditable() const;
214 virtual void setStringList( const QStringList &l );
215
216 int rtti() const;
217 static int RTTI;
218
219 QSize sizeHint() const;
220
221private:
222 QComboBox *cb;
223 QStringList entries;
224 int current;
225 bool edit;
226 static QComboBox *fakeCombo;
227
228};
229/*US
230
231class QM_EXPORT_TABLE QCheckTableItem : public QTableItem
232{
233public:
234 QCheckTableItem( QTable *table, const QString &txt );
235 void setText( const QString &t );
236 virtual QWidget *createEditor() const;
237 virtual void setContentFromEditor( QWidget *w );
238 virtual void paint( QPainter *p, const QColorGroup &cg,
239 const QRect &cr, bool selected );
240 virtual void setChecked( bool b );
241 bool isChecked() const;
242
243 int rtti() const;
244 static int RTTI;
245
246 QSize sizeHint() const;
247
248private:
249 QCheckBox *cb;
250 bool checked;
251
252};
253
254class QM_EXPORT_TABLE QTable : public QScrollView
255{
256 Q_OBJECT
257 Q_ENUMS( SelectionMode FocusStyle )
258 Q_PROPERTY( int numRows READ numRows WRITE setNumRows )
259 Q_PROPERTY( int numCols READ numCols WRITE setNumCols )
260 Q_PROPERTY( bool showGrid READ showGrid WRITE setShowGrid )
261 Q_PROPERTY( bool rowMovingEnabled READ rowMovingEnabled WRITE setRowMovingEnabled )
262 Q_PROPERTY( bool columnMovingEnabled READ columnMovingEnabled WRITE setColumnMovingEnabled )
263 Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly )
264 Q_PROPERTY( bool sorting READ sorting WRITE setSorting )
265 Q_PROPERTY( SelectionMode selectionMode READ selectionMode WRITE setSelectionMode )
266 Q_PROPERTY( FocusStyle focusStyle READ focusStyle WRITE setFocusStyle )
267 Q_PROPERTY( int numSelections READ numSelections )
268
269 friend class QTableHeader;
270 friend class QComboTableItem;
271 friend class QCheckTableItem;
272 friend class QTableItem;
273
274public:
275 QTable( QWidget* parent=0, const char* name=0 );
276 QTable( int numRows, int numCols,
277 QWidget* parent=0, const char* name=0 );
278 ~QTable();
279
280 QHeader *horizontalHeader() const;
281 QHeader *verticalHeader() const;
282
283 enum SelectionMode { Single, Multi, SingleRow, MultiRow, NoSelection };
284 virtual void setSelectionMode( SelectionMode mode );
285 SelectionMode selectionMode() const;
286
287 virtual void setItem( int row, int col, QTableItem *item );
288 virtual void setText( int row, int col, const QString &text );
289 virtual void setPixmap( int row, int col, const QPixmap &pix );
290 virtual QTableItem *item( int row, int col ) const;
291 virtual QString text( int row, int col ) const;
292 virtual QPixmap pixmap( int row, int col ) const;
293 virtual void clearCell( int row, int col );
294
295 virtual QRect cellGeometry( int row, int col ) const;
296 virtual int columnWidth( int col ) const;
297 virtual int rowHeight( int row ) const;
298 virtual int columnPos( int col ) const;
299 virtual int rowPos( int row ) const;
300 virtual int columnAt( int x ) const;
301 virtual int rowAt( int y ) const;
302
303 virtual int numRows() const;
304 virtual int numCols() const;
305
306 void updateCell( int row, int col );
307
308 bool eventFilter( QObject * o, QEvent * );
309
310 int currentRow() const { return curRow; }
311 int currentColumn() const { return curCol; }
312 void ensureCellVisible( int row, int col );
313
314 bool isSelected( int row, int col ) const;
315 bool isRowSelected( int row, bool full = FALSE ) const;
316 bool isColumnSelected( int col, bool full = FALSE ) const;
317 int numSelections() const;
318 QTableSelection selection( int num ) const;
319 virtual int addSelection( const QTableSelection &s );
320 virtual void removeSelection( const QTableSelection &s );
321 virtual void removeSelection( int num );
322 virtual int currentSelection() const;
323
324 void selectCells( int start_row, int start_col, int end_row, int end_col );
325 void selectRow( int row );
326 void selectColumn( int col );
327
328 bool showGrid() const;
329
330 bool columnMovingEnabled() const;
331 bool rowMovingEnabled() const;
332
333 virtual void sortColumn( int col, bool ascending = TRUE,
334 bool wholeRows = FALSE );
335 bool sorting() const;
336
337 virtual void takeItem( QTableItem *i );
338
339 virtual void setCellWidget( int row, int col, QWidget *e );
340 virtual QWidget *cellWidget( int row, int col ) const;
341 virtual void clearCellWidget( int row, int col );
342
343 virtual QRect cellRect( int row, int col ) const;
344
345 virtual void paintCell( QPainter *p, int row, int col,
346 const QRect &cr, bool selected );
347 virtual void paintCell( QPainter *p, int row, int col,
348 const QRect &cr, bool selected, const QColorGroup &cg );
349 virtual void paintFocus( QPainter *p, const QRect &r );
350 QSize sizeHint() const;
351
352 bool isReadOnly() const;
353 bool isRowReadOnly( int row ) const;
354 bool isColumnReadOnly( int col ) const;
355
356 void setEnabled( bool b );
357
358 void repaintSelections();
359
360 enum FocusStyle { FollowStyle, SpreadSheet };
361 virtual void setFocusStyle( FocusStyle fs );
362 FocusStyle focusStyle() const;
363
364 void updateHeaderStates();
365
366public slots:
367 virtual void setNumRows( int r );
368 virtual void setNumCols( int r );
369 virtual void setShowGrid( bool b );
370 virtual void hideRow( int row );
371 virtual void hideColumn( int col );
372 virtual void showRow( int row );
373 virtual void showColumn( int col );
374
375 virtual void setColumnWidth( int col, int w );
376 virtual void setRowHeight( int row, int h );
377
378 virtual void adjustColumn( int col );
379 virtual void adjustRow( int row );
380
381 virtual void setColumnStretchable( int col, bool stretch );
382 virtual void setRowStretchable( int row, bool stretch );
383 bool isColumnStretchable( int col ) const;
384 bool isRowStretchable( int row ) const;
385 virtual void setSorting( bool b );
386 virtual void swapRows( int row1, int row2, bool swapHeader = FALSE );
387 virtual void swapColumns( int col1, int col2, bool swapHeader = FALSE );
388 virtual void swapCells( int row1, int col1, int row2, int col2 );
389
390 virtual void setLeftMargin( int m );
391 virtual void setTopMargin( int m );
392 virtual void setCurrentCell( int row, int col );
393 void clearSelection( bool repaint = TRUE );
394 virtual void setColumnMovingEnabled( bool b );
395 virtual void setRowMovingEnabled( bool b );
396
397 virtual void setReadOnly( bool b );
398 virtual void setRowReadOnly( int row, bool ro );
399 virtual void setColumnReadOnly( int col, bool ro );
400
401 virtual void setDragEnabled( bool b );
402 bool dragEnabled() const;
403
404 virtual void insertRows( int row, int count = 1 );
405 virtual void insertColumns( int col, int count = 1 );
406 virtual void removeRow( int row );
407 virtual void removeRows( const QMemArray<int> &rows );
408 virtual void removeColumn( int col );
409 virtual void removeColumns( const QMemArray<int> &cols );
410
411 virtual void editCell( int row, int col, bool replace = FALSE );
412
413 void setRowLabels( const QStringList &labels );
414 void setColumnLabels( const QStringList &labels );
415
416protected:
417 enum EditMode { NotEditing, Editing, Replacing };
418 void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
419 void contentsMousePressEvent( QMouseEvent* );
420 void contentsMouseMoveEvent( QMouseEvent* );
421 void contentsMouseDoubleClickEvent( QMouseEvent* );
422 void contentsMouseReleaseEvent( QMouseEvent* );
423 void contentsContextMenuEvent( QContextMenuEvent * e );
424 void keyPressEvent( QKeyEvent* );
425 void focusInEvent( QFocusEvent* );
426 void focusOutEvent( QFocusEvent* );
427 void viewportResizeEvent( QResizeEvent * );
428 void showEvent( QShowEvent *e );
429 void paintEvent( QPaintEvent *e );
430 void setEditMode( EditMode mode, int row, int col );
431#ifndef QT_NO_DRAGANDDROP
432 virtual void contentsDragEnterEvent( QDragEnterEvent *e );
433 virtual void contentsDragMoveEvent( QDragMoveEvent *e );
434 virtual void contentsDragLeaveEvent( QDragLeaveEvent *e );
435 virtual void contentsDropEvent( QDropEvent *e );
436 virtual QDragObject *dragObject();
437 virtual void startDrag();
438#endif
439
440 virtual void paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch );
441 virtual void activateNextCell();
442 virtual QWidget *createEditor( int row, int col, bool initFromCell ) const;
443 virtual void setCellContentFromEditor( int row, int col );
444 virtual QWidget *beginEdit( int row, int col, bool replace );
445 virtual void endEdit( int row, int col, bool accept, bool replace );
446
447 virtual void resizeData( int len );
448 virtual void insertWidget( int row, int col, QWidget *w );
449 int indexOf( int row, int col ) const;
450
451 void windowActivationChange( bool );
452 bool isEditing() const;
453 EditMode editMode() const;
454 int currEditRow() const;
455 int currEditCol() const;
456
457protected slots:
458 virtual void columnWidthChanged( int col );
459 virtual void rowHeightChanged( int row );
460 virtual void columnIndexChanged( int section, int fromIndex, int toIndex );
461 virtual void rowIndexChanged( int section, int fromIndex, int toIndex );
462 virtual void columnClicked( int col );
463
464signals:
465 void currentChanged( int row, int col );
466 void clicked( int row, int col, int button, const QPoint &mousePos );
467 void doubleClicked( int row, int col, int button, const QPoint &mousePos );
468 void pressed( int row, int col, int button, const QPoint &mousePos );
469 void selectionChanged();
470 void valueChanged( int row, int col );
471 void contextMenuRequested( int row, int col, const QPoint &pos );
472#ifndef QT_NO_DRAGANDDROP
473 void dropped( QDropEvent *e );
474#endif
475
476private slots:
477 void doAutoScroll();
478 void doValueChanged();
479 void updateGeometriesSlot();
480
481private:
482 void contentsMousePressEventEx( QMouseEvent* );
483 void drawContents( QPainter* );
484 void updateGeometries();
485 void repaintSelections( QTableSelection *oldSelection,
486 QTableSelection *newSelection,
487 bool updateVertical = TRUE,
488 bool updateHorizontal = TRUE );
489 QRect rangeGeometry( int topRow, int leftCol,
490 int bottomRow, int rightCol, bool &optimize );
491 void fixRow( int &row, int y );
492 void fixCol( int &col, int x );
493
494 void init( int numRows, int numCols );
495 QSize tableSize() const;
496 void repaintCell( int row, int col );
497 void contentsToViewport2( int x, int y, int& vx, int& vy );
498 QPoint contentsToViewport2( const QPoint &p );
499 void viewportToContents2( int vx, int vy, int& x, int& y );
500 QPoint viewportToContents2( const QPoint &p );
501
502 void updateRowWidgets( int row );
503 void updateColWidgets( int col );
504 bool isSelected( int row, int col, bool includeCurrent ) const;
505 void setCurrentCell( int row, int col, bool updateSelections );
506 void fixCell( int &row, int &col, int key );
507 void delayedUpdateGeometries();
508 struct TableWidget
509 {
510 TableWidget( QWidget *w, int r, int c ) : wid( w ), row( r ), col ( c ) {}
511 QWidget *wid;
512 int row, col;
513 };
514 void saveContents( QPtrVector<QTableItem> &tmp,
515 QPtrVector<TableWidget> &tmp2 );
516 void updateHeaderAndResizeContents( QTableHeader *header,
517 int num, int colRow,
518 int width, bool &updateBefore );
519 void restoreContents( QPtrVector<QTableItem> &tmp,
520 QPtrVector<TableWidget> &tmp2 );
521 void finishContentsResze( bool updateBefore );
522
523private:
524 QPtrVector<QTableItem> contents;
525 QPtrVector<QWidget> widgets;
526 int curRow;
527 int curCol;
528 QTableHeader *leftHeader, *topHeader;
529 EditMode edMode;
530 int editCol, editRow;
531 QPtrList<QTableSelection> selections;
532 QTableSelection *currentSel;
533 QTimer *autoScrollTimer;
534 int lastSortCol;
535 bool sGrid : 1;
536 bool mRows : 1;
537 bool mCols : 1;
538 bool asc : 1;
539 bool doSort : 1;
540 bool mousePressed : 1;
541 bool readOnly : 1;
542 bool shouldClearSelection : 1;
543 bool dEnabled : 1;
544 bool context_menu : 1;
545 bool drawActiveSelection : 1;
546 bool was_visible : 1;
547 SelectionMode selMode;
548 int pressedRow, pressedCol;
549 QTablePrivate *d;
550 QIntDict<int> roRows;
551 QIntDict<int> roCols;
552 int startDragRow;
553 int startDragCol;
554 QPoint dragStartPos;
555 int oldCurrentRow, oldCurrentCol;
556 QWidget *unused_topLeftCorner; //### remove in 4.0
557 FocusStyle focusStl;
558 QSize unused_cachedSizeHint; // ### remove in 4.0
559
560#if defined(Q_DISABLE_COPY)
561 QTable( const QTable & );
562 QTable &operator=( const QTable & );
563#endif
564};
565
566#define Q_DEFINED_QTABLE
567#include "qwinexport.h"
568#endif // QT_NO_TABLE
569
570*/
571#endif // QTCOMPAT_QCOMBOTABLEITEM_H