itemviews/qcolumnviewgrip.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 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 -
51QT_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*/ -
71QColumnViewGrip::QColumnViewGrip(QWidget *parent) -
72: QWidget(*new QColumnViewGripPrivate, parent, 0) -
73{ -
74#ifndef QT_NO_CURSOR -
75 setCursor(Qt::SplitHCursor);
never executed (the execution status of this line is deduced): setCursor(Qt::SplitHCursor);
-
76#endif -
77}
never executed: }
0
78 -
79/*! -
80 \internal -
81*/ -
82QColumnViewGrip::QColumnViewGrip(QColumnViewGripPrivate & dd, QWidget *parent, Qt::WindowFlags f) -
83: QWidget(dd, parent, f) -
84{ -
85}
never executed: }
0
86 -
87/*! -
88 Destroys the view. -
89*/ -
90QColumnViewGrip::~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*/ -
98int QColumnViewGrip::moveGrip(int offset) -
99{ -
100 QWidget *parentWidget = (QWidget*)parent();
never executed (the execution status of this line is deduced): QWidget *parentWidget = (QWidget*)parent();
-
101 -
102 // first resize the parent -
103 int oldWidth = parentWidget->width();
never executed (the execution status of this line is deduced): int oldWidth = parentWidget->width();
-
104 int newWidth = oldWidth;
never executed (the execution status of this line is deduced): int newWidth = oldWidth;
-
105 if (isRightToLeft())
never evaluated: isRightToLeft()
0
106 newWidth -= offset;
never executed: newWidth -= offset;
0
107 else -
108 newWidth += offset;
never executed: newWidth += offset;
0
109 newWidth = qMax(parentWidget->minimumWidth(), newWidth);
never executed (the execution status of this line is deduced): newWidth = qMax(parentWidget->minimumWidth(), newWidth);
-
110 parentWidget->resize(newWidth, parentWidget->height());
never executed (the execution status of this line is deduced): parentWidget->resize(newWidth, parentWidget->height());
-
111 -
112 // Then have the view move the widget -
113 int realOffset = parentWidget->width() - oldWidth;
never executed (the execution status of this line is deduced): int realOffset = parentWidget->width() - oldWidth;
-
114 int oldX = parentWidget->x();
never executed (the execution status of this line is deduced): int oldX = parentWidget->x();
-
115 if (realOffset != 0)
never evaluated: realOffset != 0
0
116 emit gripMoved(realOffset);
never executed: gripMoved(realOffset);
0
117 if (isRightToLeft())
never evaluated: isRightToLeft()
0
118 realOffset = -1 * (oldX - parentWidget->x());
never executed: realOffset = -1 * (oldX - parentWidget->x());
0
119 return realOffset;
never executed: return realOffset;
0
120} -
121 -
122/*! -
123 \reimp -
124*/ -
125void QColumnViewGrip::paintEvent(QPaintEvent *event) -
126{ -
127 QPainter painter(this);
never executed (the execution status of this line is deduced): QPainter painter(this);
-
128 QStyleOption opt;
never executed (the execution status of this line is deduced): QStyleOption opt;
-
129 opt.initFrom(this);
never executed (the execution status of this line is deduced): opt.initFrom(this);
-
130 style()->drawControl(QStyle::CE_ColumnViewGrip, &opt, &painter, this);
never executed (the execution status of this line is deduced): style()->drawControl(QStyle::CE_ColumnViewGrip, &opt, &painter, this);
-
131 event->accept();
never executed (the execution status of this line is deduced): event->accept();
-
132}
never executed: }
0
133 -
134/*! -
135 \reimp -
136 Resize the parent window to the sizeHint -
137*/ -
138void QColumnViewGrip::mouseDoubleClickEvent(QMouseEvent *event) -
139{ -
140 Q_UNUSED(event);
never executed (the execution status of this line is deduced): (void)event;;
-
141 QWidget *parentWidget = (QWidget*)parent();
never executed (the execution status of this line is deduced): QWidget *parentWidget = (QWidget*)parent();
-
142 int offset = parentWidget->sizeHint().width() - parentWidget->width();
never executed (the execution status of this line is deduced): int offset = parentWidget->sizeHint().width() - parentWidget->width();
-
143 if (isRightToLeft())
never evaluated: isRightToLeft()
0
144 offset *= -1;
never executed: offset *= -1;
0
145 moveGrip(offset);
never executed (the execution status of this line is deduced): moveGrip(offset);
-
146 event->accept();
never executed (the execution status of this line is deduced): event->accept();
-
147}
never executed: }
0
148 -
149/*! -
150 \reimp -
151 Begin watching for mouse movements -
152*/ -
153void QColumnViewGrip::mousePressEvent(QMouseEvent *event) -
154{ -
155 Q_D(QColumnViewGrip);
never executed (the execution status of this line is deduced): QColumnViewGripPrivate * const d = d_func();
-
156 d->originalXLocation = event->globalX();
never executed (the execution status of this line is deduced): d->originalXLocation = event->globalX();
-
157 event->accept();
never executed (the execution status of this line is deduced): event->accept();
-
158}
never executed: }
0
159 -
160/*! -
161 \reimp -
162 Calculate the movement of the grip and moveGrip() and emit gripMoved -
163*/ -
164void QColumnViewGrip::mouseMoveEvent(QMouseEvent *event) -
165{ -
166 Q_D(QColumnViewGrip);
never executed (the execution status of this line is deduced): QColumnViewGripPrivate * const d = d_func();
-
167 int offset = event->globalX() - d->originalXLocation;
never executed (the execution status of this line is deduced): int offset = event->globalX() - d->originalXLocation;
-
168 d->originalXLocation = moveGrip(offset) + d->originalXLocation;
never executed (the execution status of this line is deduced): d->originalXLocation = moveGrip(offset) + d->originalXLocation;
-
169 event->accept();
never executed (the execution status of this line is deduced): event->accept();
-
170}
never executed: }
0
171 -
172/*! -
173 \reimp -
174 Stop watching for mouse movements -
175*/ -
176void QColumnViewGrip::mouseReleaseEvent(QMouseEvent *event) -
177{ -
178 Q_D(QColumnViewGrip);
never executed (the execution status of this line is deduced): QColumnViewGripPrivate * const d = d_func();
-
179 d->originalXLocation = -1;
never executed (the execution status of this line is deduced): d->originalXLocation = -1;
-
180 event->accept();
never executed (the execution status of this line is deduced): event->accept();
-
181}
never executed: }
0
182 -
183/* -
184 * private object implementation -
185 */ -
186QColumnViewGripPrivate::QColumnViewGripPrivate() -
187: QWidgetPrivate(), -
188originalXLocation(-1) -
189{ -
190}
never executed: }
0
191 -
192QT_END_NAMESPACE -
193 -
194#endif // QT_NO_QCOLUMNVIEW -
195 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial