Qt 4.8
qcolumnviewgrip.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
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 
72 : QWidget(*new QColumnViewGripPrivate, parent, 0)
73 {
74 #ifndef QT_NO_CURSOR
76 #endif
77 }
78 
83 : QWidget(dd, parent, f)
84 {
85 }
86 
91 {
92 }
93 
99 {
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 
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 
139 {
140  Q_UNUSED(event);
142  int offset = parentWidget->sizeHint().width() - parentWidget->width();
143  if (isRightToLeft())
144  offset *= -1;
145  moveGrip(offset);
146  event->accept();
147 }
148 
154 {
156  d->originalXLocation = event->globalX();
157  event->accept();
158 }
159 
165 {
167  int offset = event->globalX() - d->originalXLocation;
168  d->originalXLocation = moveGrip(offset) + d->originalXLocation;
169  event->accept();
170 }
171 
177 {
179  d->originalXLocation = -1;
180  event->accept();
181 }
182 
183 /*
184  * private object implementation
185  */
187 : QWidgetPrivate(),
188 originalXLocation(-1)
189 {
190 }
191 
193 
194 #endif // QT_NO_QCOLUMNVIEW
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_D(Class)
Definition: qglobal.h:2482
int x
the x coordinate of the widget relative to its parent including any window frame
Definition: qwidget.h:161
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QStyle * style() const
Definition: qwidget.cpp:2742
void mouseMoveEvent(QMouseEvent *event)
Reimplemented Function Calculate the movement of the grip and moveGrip() and emit gripMoved ...
void mouseDoubleClickEvent(QMouseEvent *event)
Reimplemented Function Resize the parent window to the sizeHint
int width() const
Returns the width.
Definition: qsize.h:126
WindowFlags WFlags
Definition: qnamespace.h:1681
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void paintEvent(QPaintEvent *event)
Reimplemented Function
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
QColumnViewGrip(QWidget *parent=0)
Creates a new QColumnViewGrip with the given parent to view a model.
#define emit
Definition: qobjectdefs.h:76
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
int moveGrip(int offset)
Attempt to resize the parent object by offset returns the amount of offset that it was actually able ...
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
~QColumnViewGrip()
Destroys the view.
int minimumWidth
the widget&#39;s minimum width in pixels
Definition: qwidget.h:174
void resize(int w, int h)
This corresponds to resize(QSize(w, h)).
Definition: qwidget.h:1014
void mouseReleaseEvent(QMouseEvent *event)
Reimplemented Function Stop watching for mouse movements
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given element with the provided painter with the style options specified by option...
void mousePressEvent(QMouseEvent *event)
Reimplemented Function Begin watching for mouse movements
QSize sizeHint
the recommended size for the widget
Definition: qwidget.h:195
bool isRightToLeft() const
Definition: qwidget.h:428
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
void gripMoved(int offset)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729