|
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 QT_NO_QCOLUMNVIEW |
|
43 |
|
44 #include "qcolumnviewgrip_p.h" |
|
45 #include <qstyleoption.h> |
|
46 #include <qpainter.h> |
|
47 #include <qbrush.h> |
|
48 #include <qevent.h> |
|
49 #include <qdebug.h> |
|
50 |
|
51 QT_BEGIN_NAMESPACE |
|
52 |
|
53 /* |
|
54 \internal |
|
55 class QColumnViewGrip |
|
56 |
|
57 QColumnViewGrip is created to go inside QAbstractScrollArea's corner. |
|
58 When the mouse it moved it will resize the scroll area and emit's a signal. |
|
59 */ |
|
60 |
|
61 /* |
|
62 \internal |
|
63 \fn void QColumnViewGrip::gripMoved() |
|
64 Signal that is emitted when the grip moves the parent widget. |
|
65 */ |
|
66 |
|
67 /*! |
|
68 Creates a new QColumnViewGrip with the given \a parent to view a model. |
|
69 Use setModel() to set the model. |
|
70 */ |
|
71 QColumnViewGrip::QColumnViewGrip(QWidget *parent) |
|
72 : QWidget(*new QColumnViewGripPrivate, parent, 0) |
|
73 { |
|
74 #ifndef QT_NO_CURSOR |
|
75 setCursor(Qt::SplitHCursor); |
|
76 #endif |
|
77 } |
|
78 |
|
79 /*! |
|
80 \internal |
|
81 */ |
|
82 QColumnViewGrip::QColumnViewGrip(QColumnViewGripPrivate & dd, QWidget *parent, Qt::WFlags f) |
|
83 : QWidget(dd, parent, f) |
|
84 { |
|
85 } |
|
86 |
|
87 /*! |
|
88 Destroys the view. |
|
89 */ |
|
90 QColumnViewGrip::~QColumnViewGrip() |
|
91 { |
|
92 } |
|
93 |
|
94 /*! |
|
95 Attempt to resize the parent object by \a offset |
|
96 returns the amount of offset that it was actually able to resized |
|
97 */ |
|
98 int QColumnViewGrip::moveGrip(int offset) |
|
99 { |
|
100 QWidget *parentWidget = (QWidget*)parent(); |
|
101 |
|
102 // first resize the parent |
|
103 int oldWidth = parentWidget->width(); |
|
104 int newWidth = oldWidth; |
|
105 if (isRightToLeft()) |
|
106 newWidth -= offset; |
|
107 else |
|
108 newWidth += offset; |
|
109 newWidth = qMax(parentWidget->minimumWidth(), newWidth); |
|
110 parentWidget->resize(newWidth, parentWidget->height()); |
|
111 |
|
112 // Then have the view move the widget |
|
113 int realOffset = parentWidget->width() - oldWidth; |
|
114 int oldX = parentWidget->x(); |
|
115 if (realOffset != 0) |
|
116 emit gripMoved(realOffset); |
|
117 if (isRightToLeft()) |
|
118 realOffset = -1 * (oldX - parentWidget->x()); |
|
119 return realOffset; |
|
120 } |
|
121 |
|
122 /*! |
|
123 \reimp |
|
124 */ |
|
125 void QColumnViewGrip::paintEvent(QPaintEvent *event) |
|
126 { |
|
127 QPainter painter(this); |
|
128 QStyleOption opt; |
|
129 opt.initFrom(this); |
|
130 style()->drawControl(QStyle::CE_ColumnViewGrip, &opt, &painter, this); |
|
131 event->accept(); |
|
132 } |
|
133 |
|
134 /*! |
|
135 \reimp |
|
136 Resize the parent window to the sizeHint |
|
137 */ |
|
138 void QColumnViewGrip::mouseDoubleClickEvent(QMouseEvent *event) |
|
139 { |
|
140 Q_UNUSED(event); |
|
141 QWidget *parentWidget = (QWidget*)parent(); |
|
142 int offset = parentWidget->sizeHint().width() - parentWidget->width(); |
|
143 if (isRightToLeft()) |
|
144 offset *= -1; |
|
145 moveGrip(offset); |
|
146 event->accept(); |
|
147 } |
|
148 |
|
149 /*! |
|
150 \reimp |
|
151 Begin watching for mouse movements |
|
152 */ |
|
153 void QColumnViewGrip::mousePressEvent(QMouseEvent *event) |
|
154 { |
|
155 Q_D(QColumnViewGrip); |
|
156 d->originalXLocation = event->globalX(); |
|
157 event->accept(); |
|
158 } |
|
159 |
|
160 /*! |
|
161 \reimp |
|
162 Calculate the movement of the grip and moveGrip() and emit gripMoved |
|
163 */ |
|
164 void QColumnViewGrip::mouseMoveEvent(QMouseEvent *event) |
|
165 { |
|
166 Q_D(QColumnViewGrip); |
|
167 int offset = event->globalX() - d->originalXLocation; |
|
168 d->originalXLocation = moveGrip(offset) + d->originalXLocation; |
|
169 event->accept(); |
|
170 } |
|
171 |
|
172 /*! |
|
173 \reimp |
|
174 Stop watching for mouse movements |
|
175 */ |
|
176 void QColumnViewGrip::mouseReleaseEvent(QMouseEvent *event) |
|
177 { |
|
178 Q_D(QColumnViewGrip); |
|
179 d->originalXLocation = -1; |
|
180 event->accept(); |
|
181 } |
|
182 |
|
183 /* |
|
184 * private object implementation |
|
185 */ |
|
186 QColumnViewGripPrivate::QColumnViewGripPrivate() |
|
187 : QWidgetPrivate(), |
|
188 originalXLocation(-1) |
|
189 { |
|
190 } |
|
191 |
|
192 QT_END_NAMESPACE |
|
193 |
|
194 #endif // QT_NO_QCOLUMNVIEW |