|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
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/qpropertyanimation.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 void checkColumnCreation(const QModelIndex &parent); |
|
152 |
|
153 |
|
154 void _q_gripMoved(int offset); |
|
155 void _q_changeCurrentColumn(); |
|
156 void _q_clicked(const QModelIndex &index); |
|
157 void _q_columnsInserted(const QModelIndex &parent, int start, int end); |
|
158 |
|
159 QList<QAbstractItemView*> columns; |
|
160 QVector<int> columnSizes; // used during init and corner moving |
|
161 bool showResizeGrips; |
|
162 int offset; |
|
163 #ifndef QT_NO_ANIMATION |
|
164 QPropertyAnimation currentAnimation; |
|
165 #endif |
|
166 QWidget *previewWidget; |
|
167 QAbstractItemView *previewColumn; |
|
168 }; |
|
169 |
|
170 /*! |
|
171 * This is a delegate that will paint the triangle |
|
172 */ |
|
173 class QColumnViewDelegate : public QItemDelegate |
|
174 { |
|
175 |
|
176 public: |
|
177 explicit QColumnViewDelegate(QObject *parent = 0) : QItemDelegate(parent) {} |
|
178 ~QColumnViewDelegate() {} |
|
179 |
|
180 void paint(QPainter *painter, |
|
181 const QStyleOptionViewItem &option, |
|
182 const QModelIndex &index) const; |
|
183 }; |
|
184 #endif // QT_NO_QCOLUMNVIEW |
|
185 |
|
186 |
|
187 QT_END_NAMESPACE |
|
188 #endif //QCOLUMNVIEW_P_H |
|
189 |