source: trunk/include/qheader.h@ 136

Last change on this file since 136 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 7.5 KB
Line 
1/****************************************************************************
2** $Id: qheader.h 2 2005-11-16 15:49:26Z dmik $
3**
4** Definition of QHeader widget class (table header)
5**
6** Created : 961105
7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the widgets module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#ifndef QHEADER_H
39#define QHEADER_H
40
41#ifndef QT_H
42#include "qwidget.h"
43#include "qstring.h"
44#include "qiconset.h" // conversion QPixmap->QIconset
45#endif // QT_H
46
47#ifndef QT_NO_HEADER
48
49class QShowEvent;
50class QHeaderData;
51class QTable;
52
53class Q_EXPORT QHeader : public QWidget
54{
55 friend class QTable;
56 friend class QTableHeader;
57 friend class QListView;
58
59 Q_OBJECT
60 Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation )
61 Q_PROPERTY( bool tracking READ tracking WRITE setTracking )
62 Q_PROPERTY( int count READ count )
63 Q_PROPERTY( int offset READ offset WRITE setOffset )
64 Q_PROPERTY( bool moving READ isMovingEnabled WRITE setMovingEnabled )
65 Q_PROPERTY( bool stretching READ isStretchEnabled WRITE setStretchEnabled )
66
67public:
68 QHeader( QWidget* parent=0, const char* name=0 );
69 QHeader( int, QWidget* parent=0, const char* name=0 );
70 ~QHeader();
71
72 int addLabel( const QString &, int size = -1 );
73 int addLabel( const QIconSet&, const QString &, int size = -1 );
74 void removeLabel( int section );
75 virtual void setLabel( int, const QString &, int size = -1 );
76 virtual void setLabel( int, const QIconSet&, const QString &, int size = -1 );
77 QString label( int section ) const;
78 QIconSet* iconSet( int section ) const;
79
80 virtual void setOrientation( Orientation );
81 Orientation orientation() const;
82 virtual void setTracking( bool enable );
83 bool tracking() const;
84
85 virtual void setClickEnabled( bool, int section = -1 );
86 virtual void setResizeEnabled( bool, int section = -1 );
87 virtual void setMovingEnabled( bool );
88 virtual void setStretchEnabled( bool b, int section );
89 void setStretchEnabled( bool b ) { setStretchEnabled( b, -1 ); }
90 bool isClickEnabled( int section = -1 ) const;
91 bool isResizeEnabled( int section = -1 ) const;
92 bool isMovingEnabled() const;
93 bool isStretchEnabled() const;
94 bool isStretchEnabled( int section ) const;
95
96 void resizeSection( int section, int s );
97 int sectionSize( int section ) const;
98 int sectionPos( int section ) const;
99 int sectionAt( int pos ) const;
100 int count() const;
101 int headerWidth() const;
102 QRect sectionRect( int section ) const;
103
104 virtual void setCellSize( int , int ); // obsolete, do not use
105 int cellSize( int i ) const { return sectionSize( mapToSection(i) ); } // obsolete, do not use
106 int cellPos( int ) const; // obsolete, do not use
107 int cellAt( int pos ) const { return mapToIndex( sectionAt(pos + offset()) ); } // obsolete, do not use
108
109 int offset() const;
110
111 QSize sizeHint() const;
112
113 int mapToSection( int index ) const;
114 int mapToIndex( int section ) const;
115 int mapToLogical( int ) const; // obsolete, do not use
116 int mapToActual( int ) const; // obsolete, do not use
117
118 void moveSection( int section, int toIndex );
119 virtual void moveCell( int, int); // obsolete, do not use
120
121 void setSortIndicator( int section, bool ascending = TRUE ); // obsolete, do not use
122 inline void setSortIndicator( int section, SortOrder order )
123 { setSortIndicator( section, (order == Ascending) ); }
124 int sortIndicatorSection() const;
125 SortOrder sortIndicatorOrder() const;
126
127 void adjustHeaderSize() { adjustHeaderSize( -1 ); }
128
129public slots:
130 void setUpdatesEnabled( bool enable );
131 virtual void setOffset( int pos );
132
133signals:
134 void clicked( int section );
135 void pressed( int section );
136 void released( int section );
137 void sizeChange( int section, int oldSize, int newSize );
138 void indexChange( int section, int fromIndex, int toIndex );
139 void sectionClicked( int ); // obsolete, do not use
140 void moved( int, int ); // obsolete, do not use
141 void sectionHandleDoubleClicked( int section );
142
143protected:
144 void paintEvent( QPaintEvent * );
145 void showEvent( QShowEvent *e );
146 void resizeEvent( QResizeEvent *e );
147 QRect sRect( int index );
148
149 virtual void paintSection( QPainter *p, int index, const QRect& fr);
150 virtual void paintSectionLabel( QPainter* p, int index, const QRect& fr );
151
152 void fontChange( const QFont & );
153
154 void mousePressEvent( QMouseEvent * );
155 void mouseReleaseEvent( QMouseEvent * );
156 void mouseMoveEvent( QMouseEvent * );
157 void mouseDoubleClickEvent( QMouseEvent * );
158
159 void keyPressEvent( QKeyEvent * );
160 void keyReleaseEvent( QKeyEvent * );
161
162private:
163 void handleColumnMove( int fromIdx, int toIdx );
164 void adjustHeaderSize( int diff );
165 void init( int );
166
167 void paintRect( int p, int s );
168 void markLine( int idx );
169 void unMarkLine( int idx );
170 int pPos( int i ) const;
171 int pSize( int i ) const;
172 int findLine( int );
173 int handleAt( int p );
174 bool reverse() const;
175 void calculatePositions( bool onlyVisible = FALSE, int start = 0 );
176 void handleColumnResize(int, int, bool, bool = TRUE );
177 QSize sectionSizeHint( int section, const QFontMetrics& fm ) const;
178 void setSectionSizeAndHeight( int section, int size );
179
180 void resizeArrays( int size );
181 void setIsATableHeader( bool b );
182 int offs;
183 int handleIdx;
184 int oldHIdxSize;
185 int moveToIdx;
186 enum State { Idle, Sliding, Pressed, Moving, Blocked };
187 State state;
188 QCOORD clickPos;
189 bool trackingIsOn;
190 int oldHandleIdx;
191 int cachedPos; // not used
192 Orientation orient;
193
194 QHeaderData *d;
195
196private: // Disabled copy constructor and operator=
197#if defined(Q_DISABLE_COPY)
198 QHeader( const QHeader & );
199 QHeader &operator=( const QHeader & );
200#endif
201};
202
203
204inline QHeader::Orientation QHeader::orientation() const
205{
206 return orient;
207}
208
209inline void QHeader::setTracking( bool enable ) { trackingIsOn = enable; }
210inline bool QHeader::tracking() const { return trackingIsOn; }
211
212extern Q_EXPORT bool qt_qheader_label_return_null_strings; // needed for professional edition
213
214#endif // QT_NO_HEADER
215
216#endif // QHEADER_H
Note: See TracBrowser for help on using the repository browser.