NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxMousePadWidget.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 
34 /*
35  * sscMousePadWidget.cpp
36  *
37  * Created on: Jul 25, 2011
38  * Author: christiana
39  */
40 
41 #include "cxMousePadWidget.h"
42 #include <QtWidgets>
43 #include "cxVector3D.h"
44 
45 namespace cx
46 {
47 
48 MousePadWidgetInternal::MousePadWidgetInternal(QWidget* parent, QSize minimumSize) :
49  QFrame(parent), mFixPosX(false), mFixPosY(false), mMinSize(minimumSize)
50 {
51 }
52 
54 {
55 }
56 
58 {
59  mFixPosX = on;
60  this->fixPos();
61 }
63 {
64  mFixPosY = on;
65  this->fixPos();
66 }
67 
68 void MousePadWidgetInternal::fixPos()
69 {
70  if (mFixPosX)
71  {
72  mLastPos.rx() = this->width() / 2;
73  }
74  if (mFixPosY)
75  {
76  mLastPos.ry() = this->height() / 2;
77  }
78 }
79 
80 void MousePadWidgetInternal::showEvent(QShowEvent* event)
81 {
82  mLastPos = QPoint(this->width() / 2, this->height() / 2);
83  this->fixPos();
84  this->update();
85 }
86 
88 {
89  mLastPos = event->pos();
90  this->fixPos();
91  this->update();
92 }
93 
95 {
96  QPoint delta = event->pos() - mLastPos;
97 
98  double padSize = (this->size().width() + this->size().height()) / 2.0; // pixel size of trackpad
99  QPointF deltaN(double(delta.x()) / padSize, double(delta.y()) / padSize);
100  emit
101  mouseMoved(deltaN);
102 
103  mLastPos = event->pos();
104  this->fixPos();
105  this->update();
106 }
107 
109 {
110  mLastPos = QPoint(this->width() / 2, this->height() / 2);
111  this->fixPos();
112  this->update();
113 }
114 
115 void MousePadWidgetInternal::resizeEvent(QResizeEvent* event)
116 {
117  mLastPos = QPoint(this->width() / 2, this->height() / 2);
118  this->fixPos();
119  this->update();
120 }
121 
123 {
124  QPainter p(this);
125 
126  Vector3D center(this->width() / 2, this->height() / 2, 0);
127  double radius = center.length();
128  QPoint qcenter(this->width() / 2, this->height() / 2);
129 
130  QRadialGradient radialGrad(qcenter, radius, mLastPos);
131  radialGrad.setColorAt(0.0, QColor("khaki"));
132  radialGrad.setColorAt(0.4, QColor("lightgrey"));
133  radialGrad.setColorAt(1, QColor("dimgrey"));
134 
135  QColor color(146, 0, 146);
136  QBrush brush(radialGrad);
137 
138  p.setPen(QColor(146, 0, 146));
139  p.setBrush(QColor(146, 0, 146));
140  p.fillRect(0, 0, width() - 1, height() - 1, brush);
141 }
142 
146 
147 
148 MousePadWidget::MousePadWidget(QWidget* parent, QSize minimumSize) :
149  QFrame(parent)
150 {
151  mInternal = new MousePadWidgetInternal(this, minimumSize);
152  connect(mInternal, SIGNAL(mouseMoved(QPointF)), this, SIGNAL(mouseMoved(QPointF)));
153 
154  this->setFrameStyle(QFrame::Panel | QFrame::Raised);
155  this->setLineWidth(3);
156  QVBoxLayout* fLayout = new QVBoxLayout;
157  fLayout->setMargin(0);
158  this->setLayout(fLayout);
159 
160  // MousePadWidget* pad = new MousePadWidget(this, minimumSize);
161  // pad->setFixedYPos(true);
162  // pad->setFrameStyle(QFrame::Panel | QFrame::Sunken);
163  // pad->setLineWidth(3);
164  fLayout->addWidget(mInternal);
165 }
167 {
168 }
170 {
171  mInternal->setFixedXPos(on);
172 }
174 {
175  mInternal->setFixedYPos(on);
176 }
177 
178 }
virtual void mousePressEvent(QMouseEvent *event)
void setFixedXPos(bool on)
void mouseMoved(QPointF deltaN)
virtual void resizeEvent(QResizeEvent *event)
MousePadWidgetInternal(QWidget *parent, QSize minimumSize)
virtual void mouseReleaseEvent(QMouseEvent *event)
void setFixedYPos(bool on)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
void mouseMoved(QPointF deltaN)
virtual void showEvent(QShowEvent *event)
void paintEvent(QPaintEvent *event)
virtual void mouseMoveEvent(QMouseEvent *event)
MousePadWidget(QWidget *parent, QSize minimumSize)