CustusX  18.04-rc1
An IGT application
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 /*
14  * sscMousePadWidget.cpp
15  *
16  * Created on: Jul 25, 2011
17  * Author: christiana
18  */
19 
20 #include "cxMousePadWidget.h"
21 #include <QtWidgets>
22 #include "cxVector3D.h"
23 
24 namespace cx
25 {
26 
27 MousePadWidgetInternal::MousePadWidgetInternal(QWidget* parent, QSize minimumSize) :
28  QFrame(parent), mFixPosX(false), mFixPosY(false), mMinSize(minimumSize)
29 {
30 }
31 
33 {
34 }
35 
37 {
38  mFixPosX = on;
39  this->fixPos();
40 }
42 {
43  mFixPosY = on;
44  this->fixPos();
45 }
46 
47 void MousePadWidgetInternal::fixPos()
48 {
49  if (mFixPosX)
50  {
51  mLastPos.rx() = this->width() / 2;
52  }
53  if (mFixPosY)
54  {
55  mLastPos.ry() = this->height() / 2;
56  }
57 }
58 
59 void MousePadWidgetInternal::showEvent(QShowEvent* event)
60 {
61  mLastPos = QPoint(this->width() / 2, this->height() / 2);
62  this->fixPos();
63  this->update();
64 }
65 
67 {
68  mLastPos = event->pos();
69  this->fixPos();
70  this->update();
71 }
72 
74 {
75  QPoint delta = event->pos() - mLastPos;
76 
77  double padSize = (this->size().width() + this->size().height()) / 2.0; // pixel size of trackpad
78  QPointF deltaN(double(delta.x()) / padSize, double(delta.y()) / padSize);
79  emit
80  mouseMoved(deltaN);
81 
82  mLastPos = event->pos();
83  this->fixPos();
84  this->update();
85 }
86 
88 {
89  mLastPos = QPoint(this->width() / 2, this->height() / 2);
90  this->fixPos();
91  this->update();
92 }
93 
94 void MousePadWidgetInternal::resizeEvent(QResizeEvent* event)
95 {
96  mLastPos = QPoint(this->width() / 2, this->height() / 2);
97  this->fixPos();
98  this->update();
99 }
100 
102 {
103  QPainter p(this);
104 
105  Vector3D center(this->width() / 2, this->height() / 2, 0);
106  double radius = center.length();
107  QPoint qcenter(this->width() / 2, this->height() / 2);
108 
109  QRadialGradient radialGrad(qcenter, radius, mLastPos);
110  radialGrad.setColorAt(0.0, QColor("khaki"));
111  radialGrad.setColorAt(0.4, QColor("lightgrey"));
112  radialGrad.setColorAt(1, QColor("dimgrey"));
113 
114  QColor color(146, 0, 146);
115  QBrush brush(radialGrad);
116 
117  p.setPen(QColor(146, 0, 146));
118  p.setBrush(QColor(146, 0, 146));
119  p.fillRect(0, 0, width() - 1, height() - 1, brush);
120 }
121 
125 
126 
127 MousePadWidget::MousePadWidget(QWidget* parent, QSize minimumSize) :
128  QFrame(parent)
129 {
130  mInternal = new MousePadWidgetInternal(this, minimumSize);
131  connect(mInternal, SIGNAL(mouseMoved(QPointF)), this, SIGNAL(mouseMoved(QPointF)));
132 
133  this->setFrameStyle(QFrame::Panel | QFrame::Raised);
134  this->setLineWidth(3);
135  QVBoxLayout* fLayout = new QVBoxLayout;
136  fLayout->setMargin(0);
137  this->setLayout(fLayout);
138 
139  // MousePadWidget* pad = new MousePadWidget(this, minimumSize);
140  // pad->setFixedYPos(true);
141  // pad->setFrameStyle(QFrame::Panel | QFrame::Sunken);
142  // pad->setLineWidth(3);
143  fLayout->addWidget(mInternal);
144 }
146 {
147 }
149 {
150  mInternal->setFixedXPos(on);
151 }
153 {
154  mInternal->setFixedYPos(on);
155 }
156 
157 }
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:42
void mouseMoved(QPointF deltaN)
virtual void showEvent(QShowEvent *event)
void paintEvent(QPaintEvent *event)
virtual void mouseMoveEvent(QMouseEvent *event)
MousePadWidget(QWidget *parent, QSize minimumSize)
Namespace for all CustusX production code.