|
| 1 | +/**************************************************************************** |
| 2 | +** $Id: qt/qheader.h 3.0.5 edited May 3 19:39 $ |
| 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 [email protected] 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 [email protected] 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 | + |
| 49 | +class QShowEvent; |
| 50 | +class QHeaderData; |
| 51 | +class QTable; |
| 52 | + |
| 53 | +class Q_EXPORT QHeader : public QWidget |
| 54 | +{ |
| 55 | + friend class QTable; |
| 56 | + friend class QTableHeader; |
| 57 | + |
| 58 | + Q_OBJECT |
| 59 | + Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation ) |
| 60 | + Q_PROPERTY( bool tracking READ tracking WRITE setTracking ) |
| 61 | + Q_PROPERTY( int count READ count ) |
| 62 | + Q_PROPERTY( int offset READ offset WRITE setOffset ) |
| 63 | + Q_PROPERTY( bool moving READ isMovingEnabled WRITE setMovingEnabled ) |
| 64 | + Q_PROPERTY( bool stretching READ isStretchEnabled WRITE setStretchEnabled ) |
| 65 | + |
| 66 | +public: |
| 67 | + QHeader( QWidget* parent=0, const char* name=0 ); |
| 68 | + QHeader( int, QWidget* parent=0, const char* name=0 ); |
| 69 | + ~QHeader(); |
| 70 | + |
| 71 | + int addLabel( const QString &, int size = -1 ); |
| 72 | + int addLabel( const QIconSet&, const QString &, int size = -1 ); |
| 73 | + void removeLabel( int section ); |
| 74 | + virtual void setLabel( int, const QString &, int size = -1 ); |
| 75 | + virtual void setLabel( int, const QIconSet&, const QString &, int size = -1 ); |
| 76 | + QString label( int section ) const; |
| 77 | + QIconSet* iconSet( int section ) const; |
| 78 | + |
| 79 | + virtual void setOrientation( Orientation ); |
| 80 | + Orientation orientation() const; |
| 81 | + virtual void setTracking( bool enable ); |
| 82 | + bool tracking() const; |
| 83 | + |
| 84 | + virtual void setClickEnabled( bool, int section = -1 ); |
| 85 | + virtual void setResizeEnabled( bool, int section = -1 ); |
| 86 | + virtual void setMovingEnabled( bool ); |
| 87 | + virtual void setStretchEnabled( bool b, int section ); |
| 88 | + void setStretchEnabled( bool b ) { setStretchEnabled( b, -1 ); } |
| 89 | + bool isClickEnabled( int section = -1 ) const; |
| 90 | + bool isResizeEnabled( int section = -1 ) const; |
| 91 | + bool isMovingEnabled() const; |
| 92 | + bool isStretchEnabled() const; |
| 93 | + bool isStretchEnabled( int section ) const; |
| 94 | + |
| 95 | + void resizeSection( int section, int s ); |
| 96 | + int sectionSize( int section ) const; |
| 97 | + int sectionPos( int section ) const; |
| 98 | + int sectionAt( int pos ) const; |
| 99 | + int count() const; |
| 100 | + int headerWidth() const; |
| 101 | + QRect sectionRect( int section ) const; |
| 102 | + |
| 103 | + virtual void setCellSize( int , int ); // obsolete, do not use |
| 104 | + int cellSize( int i ) const { return sectionSize( mapToSection(i) ); } // obsolete, do not use |
| 105 | + int cellPos( int ) const; // obsolete, do not use |
| 106 | + int cellAt( int pos ) const { return mapToIndex( sectionAt(pos + offset()) ); } // obsolete, do not use |
| 107 | + |
| 108 | + int offset() const; |
| 109 | + |
| 110 | + QSize sizeHint() const; |
| 111 | + |
| 112 | + int mapToSection( int index ) const; |
| 113 | + int mapToIndex( int section ) const; |
| 114 | + int mapToLogical( int ) const; // obsolete, do not use |
| 115 | + int mapToActual( int ) const; // obsolete, do not use |
| 116 | + |
| 117 | + void moveSection( int section, int toIndex ); |
| 118 | + virtual void moveCell( int, int); // obsolete, do not use |
| 119 | + |
| 120 | + void setSortIndicator( int section, bool increasing = TRUE ); |
| 121 | + void adjustHeaderSize() { adjustHeaderSize( -1 ); } |
| 122 | + |
| 123 | +public slots: |
| 124 | + void setUpdatesEnabled( bool enable ); |
| 125 | + virtual void setOffset( int pos ); |
| 126 | + |
| 127 | +signals: |
| 128 | + void clicked( int section ); |
| 129 | + void pressed( int section ); |
| 130 | + void released( int section ); |
| 131 | + void sizeChange( int section, int oldSize, int newSize ); |
| 132 | + void indexChange( int section, int fromIndex, int toIndex ); |
| 133 | + void sectionClicked( int ); // obsolete, do not use |
| 134 | + void moved( int, int ); // obsolete, do not use |
| 135 | + |
| 136 | +protected: |
| 137 | + void paintEvent( QPaintEvent * ); |
| 138 | + void showEvent( QShowEvent *e ); |
| 139 | + void resizeEvent( QResizeEvent *e ); |
| 140 | + QRect sRect( int index ); |
| 141 | + |
| 142 | + virtual void paintSection( QPainter *p, int index, const QRect& fr); |
| 143 | + virtual void paintSectionLabel( QPainter* p, int index, const QRect& fr ); |
| 144 | + |
| 145 | + void mousePressEvent( QMouseEvent * ); |
| 146 | + void mouseReleaseEvent( QMouseEvent * ); |
| 147 | + void mouseMoveEvent( QMouseEvent * ); |
| 148 | + |
| 149 | +private: |
| 150 | + void adjustHeaderSize( int diff ); |
| 151 | + void init( int ); |
| 152 | + |
| 153 | + void paintRect( int p, int s ); |
| 154 | + void markLine( int idx ); |
| 155 | + void unMarkLine( int idx ); |
| 156 | + int pPos( int i ) const; |
| 157 | + int pSize( int i ) const; |
| 158 | + int findLine( int ); |
| 159 | + bool reverse() const; |
| 160 | + void calculatePositions( bool onlyVisible = FALSE, int start = 0 ); |
| 161 | + void handleColumnResize(int, int, bool, bool = TRUE ); |
| 162 | + QSize sectionSizeHint( int section, const QFontMetrics& fm ) const; |
| 163 | + void setSectionSizeAndHeight( int section, int size ); |
| 164 | + |
| 165 | + void resizeArrays( int size ); |
| 166 | + void setIsATableHeader( bool b ); |
| 167 | + int offs; |
| 168 | + int handleIdx; |
| 169 | + int oldHIdxSize; |
| 170 | + int moveToIdx; |
| 171 | + enum State { Idle, Sliding, Pressed, Moving, Blocked }; |
| 172 | + State state; |
| 173 | + QCOORD clickPos; |
| 174 | + bool trackingIsOn; |
| 175 | + int cachedIdx; // not used |
| 176 | + int cachedPos; // not used |
| 177 | + Orientation orient; |
| 178 | + |
| 179 | + QHeaderData *d; |
| 180 | + |
| 181 | +private: // Disabled copy constructor and operator= |
| 182 | +#if defined(Q_DISABLE_COPY) |
| 183 | + QHeader( const QHeader & ); |
| 184 | + QHeader &operator=( const QHeader & ); |
| 185 | +#endif |
| 186 | +}; |
| 187 | + |
| 188 | + |
| 189 | +inline QHeader::Orientation QHeader::orientation() const |
| 190 | +{ |
| 191 | + return orient; |
| 192 | +} |
| 193 | + |
| 194 | +inline void QHeader::setTracking( bool enable ) { trackingIsOn = enable; } |
| 195 | +inline bool QHeader::tracking() const { return trackingIsOn; } |
| 196 | + |
| 197 | +#endif // QT_NO_HEADER |
| 198 | + |
| 199 | +#endif // QHEADER_H |
0 commit comments