1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** 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 are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QCOLUMNVIEW_P_H
|
---|
43 | #define QCOLUMNVIEW_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists for the convenience
|
---|
50 | // of other Qt classes. This header file may change from version to
|
---|
51 | // version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include "qcolumnview.h"
|
---|
57 |
|
---|
58 | #ifndef QT_NO_QCOlUMNVIEW
|
---|
59 |
|
---|
60 | #include <private/qabstractitemview_p.h>
|
---|
61 |
|
---|
62 | #include <QtCore/qabstractitemmodel.h>
|
---|
63 | #include <QtCore/qtimeline.h>
|
---|
64 | #include <QtGui/qabstractitemdelegate.h>
|
---|
65 | #include <QtGui/qabstractitemview.h>
|
---|
66 | #include <QtGui/qitemdelegate.h>
|
---|
67 | #include <qlistview.h>
|
---|
68 | #include <qevent.h>
|
---|
69 | #include <qscrollbar.h>
|
---|
70 |
|
---|
71 | QT_BEGIN_NAMESPACE
|
---|
72 |
|
---|
73 | class QColumnViewPreviewColumn : public QAbstractItemView {
|
---|
74 |
|
---|
75 | public:
|
---|
76 | QColumnViewPreviewColumn(QWidget *parent) : QAbstractItemView(parent), previewWidget(0) {
|
---|
77 | }
|
---|
78 |
|
---|
79 | void setPreviewWidget(QWidget *widget) {
|
---|
80 | previewWidget = widget;
|
---|
81 | setMinimumWidth(previewWidget->minimumWidth());
|
---|
82 | }
|
---|
83 |
|
---|
84 | void resizeEvent(QResizeEvent * event){
|
---|
85 | if (!previewWidget)
|
---|
86 | return;
|
---|
87 | previewWidget->resize(
|
---|
88 | qMax(previewWidget->minimumWidth(), event->size().width()),
|
---|
89 | previewWidget->height());
|
---|
90 | QSize p = viewport()->size();
|
---|
91 | QSize v = previewWidget->size();
|
---|
92 | horizontalScrollBar()->setRange(0, v.width() - p.width());
|
---|
93 | horizontalScrollBar()->setPageStep(p.width());
|
---|
94 | verticalScrollBar()->setRange(0, v.height() - p.height());
|
---|
95 | verticalScrollBar()->setPageStep(p.height());
|
---|
96 |
|
---|
97 | QAbstractScrollArea::resizeEvent(event);
|
---|
98 | }
|
---|
99 |
|
---|
100 | QRect visualRect(const QModelIndex &) const
|
---|
101 | {
|
---|
102 | return QRect();
|
---|
103 | }
|
---|
104 | void scrollTo(const QModelIndex &, ScrollHint)
|
---|
105 | {
|
---|
106 | }
|
---|
107 | QModelIndex indexAt(const QPoint &) const
|
---|
108 | {
|
---|
109 | return QModelIndex();
|
---|
110 | }
|
---|
111 | QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers)
|
---|
112 | {
|
---|
113 | return QModelIndex();
|
---|
114 | }
|
---|
115 | int horizontalOffset () const {
|
---|
116 | return 0;
|
---|
117 | }
|
---|
118 | int verticalOffset () const {
|
---|
119 | return 0;
|
---|
120 | }
|
---|
121 | QRegion visualRegionForSelection(const QItemSelection &) const
|
---|
122 | {
|
---|
123 | return QRegion();
|
---|
124 | }
|
---|
125 | bool isIndexHidden(const QModelIndex &) const
|
---|
126 | {
|
---|
127 | return false;
|
---|
128 | }
|
---|
129 | void setSelection(const QRect &, QItemSelectionModel::SelectionFlags)
|
---|
130 | {
|
---|
131 | }
|
---|
132 | private:
|
---|
133 | QWidget *previewWidget;
|
---|
134 | };
|
---|
135 |
|
---|
136 | class Q_AUTOTEST_EXPORT QColumnViewPrivate : public QAbstractItemViewPrivate
|
---|
137 | {
|
---|
138 | Q_DECLARE_PUBLIC(QColumnView)
|
---|
139 |
|
---|
140 | public:
|
---|
141 | QColumnViewPrivate();
|
---|
142 | ~QColumnViewPrivate();
|
---|
143 | void initialize();
|
---|
144 |
|
---|
145 | QAbstractItemView *createColumn(const QModelIndex &index, bool show);
|
---|
146 |
|
---|
147 | void updateScrollbars();
|
---|
148 | void closeColumns(const QModelIndex &parent = QModelIndex(), bool build = false);
|
---|
149 | void doLayout();
|
---|
150 | void setPreviewWidget(QWidget *widget);
|
---|
151 |
|
---|
152 | void _q_gripMoved(int offset);
|
---|
153 | void _q_changeCurrentColumn();
|
---|
154 | void _q_clicked(const QModelIndex &index);
|
---|
155 |
|
---|
156 | QList<QAbstractItemView*> columns;
|
---|
157 | QVector<int> columnSizes; // used during init and corner moving
|
---|
158 | bool showResizeGrips;
|
---|
159 | int offset;
|
---|
160 | QTimeLine currentAnimation;
|
---|
161 | QWidget *previewWidget;
|
---|
162 | QAbstractItemView *previewColumn;
|
---|
163 | };
|
---|
164 |
|
---|
165 | /*!
|
---|
166 | * This is a delegate that will paint the triangle
|
---|
167 | */
|
---|
168 | class QColumnViewDelegate : public QItemDelegate
|
---|
169 | {
|
---|
170 |
|
---|
171 | public:
|
---|
172 | explicit QColumnViewDelegate(QObject *parent = 0) : QItemDelegate(parent) {};
|
---|
173 | ~QColumnViewDelegate() {};
|
---|
174 |
|
---|
175 | void paint(QPainter *painter,
|
---|
176 | const QStyleOptionViewItem &option,
|
---|
177 | const QModelIndex &index) const;
|
---|
178 | };
|
---|
179 | #endif // QT_NO_QCOLUMNVIEW
|
---|
180 |
|
---|
181 |
|
---|
182 | QT_END_NAMESPACE
|
---|
183 | #endif //QCOLUMNVIEW_P_H
|
---|
184 |
|
---|