| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at qt-info@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QHEADERVIEW_H
|
|---|
| 43 | #define QHEADERVIEW_H
|
|---|
| 44 |
|
|---|
| 45 | #include <QtGui/qabstractitemview.h>
|
|---|
| 46 |
|
|---|
| 47 | QT_BEGIN_HEADER
|
|---|
| 48 |
|
|---|
| 49 | QT_BEGIN_NAMESPACE
|
|---|
| 50 |
|
|---|
| 51 | QT_MODULE(Gui)
|
|---|
| 52 |
|
|---|
| 53 | #ifndef QT_NO_ITEMVIEWS
|
|---|
| 54 |
|
|---|
| 55 | class QHeaderViewPrivate;
|
|---|
| 56 | class QStyleOptionHeader;
|
|---|
| 57 |
|
|---|
| 58 | class Q_GUI_EXPORT QHeaderView : public QAbstractItemView
|
|---|
| 59 | {
|
|---|
| 60 | Q_OBJECT
|
|---|
| 61 | Q_PROPERTY(bool showSortIndicator READ isSortIndicatorShown WRITE setSortIndicatorShown)
|
|---|
| 62 | Q_PROPERTY(bool highlightSections READ highlightSections WRITE setHighlightSections)
|
|---|
| 63 | Q_PROPERTY(bool stretchLastSection READ stretchLastSection WRITE setStretchLastSection)
|
|---|
| 64 | Q_PROPERTY(bool cascadingSectionResizes READ cascadingSectionResizes WRITE setCascadingSectionResizes)
|
|---|
| 65 | Q_PROPERTY(int defaultSectionSize READ defaultSectionSize WRITE setDefaultSectionSize)
|
|---|
| 66 | Q_PROPERTY(int minimumSectionSize READ minimumSectionSize WRITE setMinimumSectionSize)
|
|---|
| 67 | Q_PROPERTY(Qt::Alignment defaultAlignment READ defaultAlignment WRITE setDefaultAlignment)
|
|---|
| 68 | Q_ENUMS(ResizeMode)
|
|---|
| 69 |
|
|---|
| 70 | public:
|
|---|
| 71 |
|
|---|
| 72 | enum ResizeMode
|
|---|
| 73 | {
|
|---|
| 74 | Interactive,
|
|---|
| 75 | Stretch,
|
|---|
| 76 | Fixed,
|
|---|
| 77 | ResizeToContents,
|
|---|
| 78 | Custom = Fixed
|
|---|
| 79 | };
|
|---|
| 80 |
|
|---|
| 81 | explicit QHeaderView(Qt::Orientation orientation, QWidget *parent = 0);
|
|---|
| 82 | virtual ~QHeaderView();
|
|---|
| 83 |
|
|---|
| 84 | void setModel(QAbstractItemModel *model);
|
|---|
| 85 |
|
|---|
| 86 | Qt::Orientation orientation() const;
|
|---|
| 87 | int offset() const;
|
|---|
| 88 | int length() const;
|
|---|
| 89 | QSize sizeHint() const;
|
|---|
| 90 | int sectionSizeHint(int logicalIndex) const;
|
|---|
| 91 |
|
|---|
| 92 | int visualIndexAt(int position) const;
|
|---|
| 93 | int logicalIndexAt(int position) const;
|
|---|
| 94 |
|
|---|
| 95 | inline int logicalIndexAt(int x, int y) const;
|
|---|
| 96 | inline int logicalIndexAt(const QPoint &pos) const;
|
|---|
| 97 |
|
|---|
| 98 | int sectionSize(int logicalIndex) const;
|
|---|
| 99 | int sectionPosition(int logicalIndex) const;
|
|---|
| 100 | int sectionViewportPosition(int logicalIndex) const;
|
|---|
| 101 |
|
|---|
| 102 | void moveSection(int from, int to);
|
|---|
| 103 | void swapSections(int first, int second);
|
|---|
| 104 | void resizeSection(int logicalIndex, int size);
|
|---|
| 105 | void resizeSections(QHeaderView::ResizeMode mode);
|
|---|
| 106 |
|
|---|
| 107 | bool isSectionHidden(int logicalIndex) const;
|
|---|
| 108 | void setSectionHidden(int logicalIndex, bool hide);
|
|---|
| 109 | int hiddenSectionCount() const;
|
|---|
| 110 |
|
|---|
| 111 | inline void hideSection(int logicalIndex);
|
|---|
| 112 | inline void showSection(int logicalIndex);
|
|---|
| 113 |
|
|---|
| 114 | int count() const;
|
|---|
| 115 | int visualIndex(int logicalIndex) const;
|
|---|
| 116 | int logicalIndex(int visualIndex) const;
|
|---|
| 117 |
|
|---|
| 118 | void setMovable(bool movable);
|
|---|
| 119 | bool isMovable() const;
|
|---|
| 120 |
|
|---|
| 121 | void setClickable(bool clickable);
|
|---|
| 122 | bool isClickable() const;
|
|---|
| 123 |
|
|---|
| 124 | void setHighlightSections(bool highlight);
|
|---|
| 125 | bool highlightSections() const;
|
|---|
| 126 |
|
|---|
| 127 | void setResizeMode(ResizeMode mode);
|
|---|
| 128 | void setResizeMode(int logicalIndex, ResizeMode mode);
|
|---|
| 129 | ResizeMode resizeMode(int logicalIndex) const;
|
|---|
| 130 | int stretchSectionCount() const;
|
|---|
| 131 |
|
|---|
| 132 | void setSortIndicatorShown(bool show);
|
|---|
| 133 | bool isSortIndicatorShown() const;
|
|---|
| 134 |
|
|---|
| 135 | void setSortIndicator(int logicalIndex, Qt::SortOrder order);
|
|---|
| 136 | int sortIndicatorSection() const;
|
|---|
| 137 | Qt::SortOrder sortIndicatorOrder() const;
|
|---|
| 138 |
|
|---|
| 139 | bool stretchLastSection() const;
|
|---|
| 140 | void setStretchLastSection(bool stretch);
|
|---|
| 141 |
|
|---|
| 142 | bool cascadingSectionResizes() const;
|
|---|
| 143 | void setCascadingSectionResizes(bool enable);
|
|---|
| 144 |
|
|---|
| 145 | int defaultSectionSize() const;
|
|---|
| 146 | void setDefaultSectionSize(int size);
|
|---|
| 147 |
|
|---|
| 148 | int minimumSectionSize() const;
|
|---|
| 149 | void setMinimumSectionSize(int size);
|
|---|
| 150 |
|
|---|
| 151 | Qt::Alignment defaultAlignment() const;
|
|---|
| 152 | void setDefaultAlignment(Qt::Alignment alignment);
|
|---|
| 153 |
|
|---|
| 154 | void doItemsLayout();
|
|---|
| 155 | bool sectionsMoved() const;
|
|---|
| 156 | bool sectionsHidden() const;
|
|---|
| 157 |
|
|---|
| 158 | #ifndef QT_NO_DATASTREAM
|
|---|
| 159 | QByteArray saveState() const;
|
|---|
| 160 | bool restoreState(const QByteArray &state);
|
|---|
| 161 | #endif
|
|---|
| 162 |
|
|---|
| 163 | void reset();
|
|---|
| 164 |
|
|---|
| 165 | public Q_SLOTS:
|
|---|
| 166 | void setOffset(int offset);
|
|---|
| 167 | void setOffsetToSectionPosition(int visualIndex);
|
|---|
| 168 | void setOffsetToLastSection();
|
|---|
| 169 | void headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast);
|
|---|
| 170 |
|
|---|
| 171 | Q_SIGNALS:
|
|---|
| 172 | void sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex);
|
|---|
| 173 | void sectionResized(int logicalIndex, int oldSize, int newSize);
|
|---|
| 174 | void sectionPressed(int logicalIndex);
|
|---|
| 175 | void sectionClicked(int logicalIndex);
|
|---|
| 176 | void sectionEntered(int logicalIndex);
|
|---|
| 177 | void sectionDoubleClicked(int logicalIndex);
|
|---|
| 178 | void sectionCountChanged(int oldCount, int newCount);
|
|---|
| 179 | void sectionHandleDoubleClicked(int logicalIndex);
|
|---|
| 180 | void sectionAutoResize(int logicalIndex, QHeaderView::ResizeMode mode);
|
|---|
| 181 | void geometriesChanged();
|
|---|
| 182 | void sortIndicatorChanged(int logicalIndex, Qt::SortOrder order);
|
|---|
| 183 |
|
|---|
| 184 | protected Q_SLOTS:
|
|---|
| 185 | void updateSection(int logicalIndex);
|
|---|
| 186 | void resizeSections();
|
|---|
| 187 | void sectionsInserted(const QModelIndex &parent, int logicalFirst, int logicalLast);
|
|---|
| 188 | void sectionsAboutToBeRemoved(const QModelIndex &parent, int logicalFirst, int logicalLast);
|
|---|
| 189 |
|
|---|
| 190 | protected:
|
|---|
| 191 | QHeaderView(QHeaderViewPrivate &dd, Qt::Orientation orientation, QWidget *parent = 0);
|
|---|
| 192 | void initialize();
|
|---|
| 193 |
|
|---|
| 194 | void initializeSections();
|
|---|
| 195 | void initializeSections(int start, int end);
|
|---|
| 196 | void currentChanged(const QModelIndex ¤t, const QModelIndex &old);
|
|---|
| 197 |
|
|---|
| 198 | bool event(QEvent *e);
|
|---|
| 199 | void paintEvent(QPaintEvent *e);
|
|---|
| 200 | void mousePressEvent(QMouseEvent *e);
|
|---|
| 201 | void mouseMoveEvent(QMouseEvent *e);
|
|---|
| 202 | void mouseReleaseEvent(QMouseEvent *e);
|
|---|
| 203 | void mouseDoubleClickEvent(QMouseEvent *e);
|
|---|
| 204 | bool viewportEvent(QEvent *e);
|
|---|
| 205 |
|
|---|
| 206 | virtual void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
|
|---|
| 207 | virtual QSize sectionSizeFromContents(int logicalIndex) const;
|
|---|
| 208 |
|
|---|
| 209 | int horizontalOffset() const;
|
|---|
| 210 | int verticalOffset() const;
|
|---|
| 211 | void updateGeometries();
|
|---|
| 212 | void scrollContentsBy(int dx, int dy);
|
|---|
| 213 |
|
|---|
| 214 | void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
|---|
| 215 | void rowsInserted(const QModelIndex &parent, int start, int end);
|
|---|
| 216 |
|
|---|
| 217 | QRect visualRect(const QModelIndex &index) const;
|
|---|
| 218 | void scrollTo(const QModelIndex &index, ScrollHint hint);
|
|---|
| 219 |
|
|---|
| 220 | QModelIndex indexAt(const QPoint &p) const;
|
|---|
| 221 | bool isIndexHidden(const QModelIndex &index) const;
|
|---|
| 222 |
|
|---|
| 223 | QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers);
|
|---|
| 224 | void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags);
|
|---|
| 225 | QRegion visualRegionForSelection(const QItemSelection &selection) const;
|
|---|
| 226 | void initStyleOption(QStyleOptionHeader *option) const;
|
|---|
| 227 |
|
|---|
| 228 | private:
|
|---|
| 229 | Q_PRIVATE_SLOT(d_func(), void _q_sectionsRemoved(const QModelIndex &parent, int logicalFirst, int logicalLast))
|
|---|
| 230 | Q_PRIVATE_SLOT(d_func(), void _q_layoutAboutToBeChanged())
|
|---|
| 231 | Q_DECLARE_PRIVATE(QHeaderView)
|
|---|
| 232 | Q_DISABLE_COPY(QHeaderView)
|
|---|
| 233 | };
|
|---|
| 234 |
|
|---|
| 235 | inline int QHeaderView::logicalIndexAt(int ax, int ay) const
|
|---|
| 236 | { return orientation() == Qt::Horizontal ? logicalIndexAt(ax) : logicalIndexAt(ay); }
|
|---|
| 237 | inline int QHeaderView::logicalIndexAt(const QPoint &apos) const
|
|---|
| 238 | { return logicalIndexAt(apos.x(), apos.y()); }
|
|---|
| 239 | inline void QHeaderView::hideSection(int alogicalIndex)
|
|---|
| 240 | { setSectionHidden(alogicalIndex, true); }
|
|---|
| 241 | inline void QHeaderView::showSection(int alogicalIndex)
|
|---|
| 242 | { setSectionHidden(alogicalIndex, false); }
|
|---|
| 243 |
|
|---|
| 244 | #endif // QT_NO_ITEMVIEWS
|
|---|
| 245 |
|
|---|
| 246 | QT_END_NAMESPACE
|
|---|
| 247 |
|
|---|
| 248 | QT_END_HEADER
|
|---|
| 249 |
|
|---|
| 250 | #endif // QHEADERVIEW_H
|
|---|