annotate Applications/Qt/QCairoWidget.cpp @ 1279:7ec8fea061b9 broker

integration mainline->broker
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 Feb 2020 15:20:08 +0100
parents 0ca50d275b9a 2d8ab34c8c91
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
280
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
1 /**
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
2 * Stone of Orthanc
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
4 * Department, University Hospital of Liege, Belgium
1270
2d8ab34c8c91 upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1256
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
280
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
6 *
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
7 * This program is free software: you can redistribute it and/or
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
10 * the License, or (at your option) any later version.
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
11 *
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
12 * This program is distributed in the hope that it will be useful, but
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
15 * Affero General Public License for more details.
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
16 *
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
19 **/
829163c6efc1 split MainWindow into a generic one and one specific to these samples
am@osimis.io
parents: 277
diff changeset
20
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
21 #include "QCairoWidget.h"
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
22
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
23 #include <QPainter>
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
24 #include <QPaintEvent>
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
25
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
26 #include <stdexcept>
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
27
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
28
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
29 QCairoWidget::StoneObserver::StoneObserver(QCairoWidget& that,
730
fe938bddb932 fix after namespace rename to Deprecated
Alain Mazy <alain@mazy.be>
parents: 570
diff changeset
30 Deprecated::IViewport& viewport,
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
31 OrthancStone::MessageBroker& broker) :
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
32 OrthancStone::IObserver(broker),
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
33 that_(that)
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
34 {
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
35 // get notified each time the content of the central viewport changes
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
36 viewport.RegisterObserverCallback(
730
fe938bddb932 fix after namespace rename to Deprecated
Alain Mazy <alain@mazy.be>
parents: 570
diff changeset
37 new OrthancStone::Callable<StoneObserver, Deprecated::IViewport::ViewportChangedMessage>
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
38 (*this, &StoneObserver::OnViewportChanged));
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
39 }
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
40
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
41
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
42 QCairoWidget::QCairoWidget(QWidget *parent) :
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
43 QWidget(parent),
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
44 context_(NULL)
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
45 {
284
38b0ac8055b9 Qt: catch and forward keyboard events
am@osimis.io
parents: 280
diff changeset
46 setFocusPolicy(Qt::StrongFocus); // catch keyPressEvents
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
47 }
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
48
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
49
291
87376a645ee1 renaming
am@osimis.io
parents: 284
diff changeset
50 void QCairoWidget::SetContext(OrthancStone::NativeStoneApplicationContext& context)
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
51 {
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
52 context_ = &context;
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
53
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
54 {
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
55 OrthancStone::NativeStoneApplicationContext::GlobalMutexLocker locker(*context_);
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
56 observer_.reset(new StoneObserver(*this,
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
57 locker.GetCentralViewport(),
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
58 locker.GetMessageBroker()));
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
59 }
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
60 }
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
61
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
62
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
63 void QCairoWidget::paintEvent(QPaintEvent* /*event*/)
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
64 {
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
65 QPainter painter(this);
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
66
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
67 if (image_.get() != NULL &&
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
68 context_ != NULL)
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
69 {
291
87376a645ee1 renaming
am@osimis.io
parents: 284
diff changeset
70 OrthancStone::NativeStoneApplicationContext::GlobalMutexLocker locker(*context_);
730
fe938bddb932 fix after namespace rename to Deprecated
Alain Mazy <alain@mazy.be>
parents: 570
diff changeset
71 Deprecated::IViewport& viewport = locker.GetCentralViewport();
318
3a4ca166fafa ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents: 291
diff changeset
72 Orthanc::ImageAccessor a;
369
557c8ff1db5c integration mainline->am-2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 327
diff changeset
73 surface_.GetWriteableAccessor(a);
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
74 viewport.Render(a);
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
75 painter.drawImage(0, 0, *image_);
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
76 }
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
77 else
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
78 {
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
79 painter.fillRect(rect(), Qt::red);
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
80 }
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
81 }
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
82
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
83 OrthancStone::KeyboardModifiers GetKeyboardModifiers(QInputEvent* event)
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
84 {
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
85 Qt::KeyboardModifiers qtModifiers = event->modifiers();
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
86 int stoneModifiers = static_cast<int>(OrthancStone::KeyboardModifiers_None);
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
87 if ((qtModifiers & Qt::AltModifier) != 0)
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
88 {
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
89 stoneModifiers |= static_cast<int>(OrthancStone::KeyboardModifiers_Alt);
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
90 }
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
91 if ((qtModifiers & Qt::ControlModifier) != 0)
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
92 {
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
93 stoneModifiers |= static_cast<int>(OrthancStone::KeyboardModifiers_Control);
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
94 }
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
95 if ((qtModifiers & Qt::ShiftModifier) != 0)
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
96 {
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
97 stoneModifiers |= static_cast<int>(OrthancStone::KeyboardModifiers_Shift);
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
98 }
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
99 return static_cast<OrthancStone::KeyboardModifiers>(stoneModifiers);
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
100 }
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
101
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
102 void QCairoWidget::mousePressEvent(QMouseEvent* event)
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
103 {
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
104 OrthancStone::KeyboardModifiers stoneModifiers = GetKeyboardModifiers(event);
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
105
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
106 OrthancStone::MouseButton button;
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
107
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
108 switch (event->button())
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
109 {
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
110 case Qt::LeftButton:
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
111 button = OrthancStone::MouseButton_Left;
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
112 break;
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
113
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
114 case Qt::RightButton:
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
115 button = OrthancStone::MouseButton_Right;
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
116 break;
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
117
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
118 case Qt::MiddleButton:
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
119 button = OrthancStone::MouseButton_Middle;
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
120 break;
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
121
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
122 default:
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
123 return; // Unsupported button
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
124 }
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
125
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
126 {
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
127 OrthancStone::NativeStoneApplicationContext::GlobalMutexLocker locker(*context_);
730
fe938bddb932 fix after namespace rename to Deprecated
Alain Mazy <alain@mazy.be>
parents: 570
diff changeset
128 locker.GetCentralViewport().MouseDown(button, event->pos().x(), event->pos().y(), stoneModifiers, std::vector<Deprecated::Touch>());
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
129 }
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
130 }
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
131
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
132
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
133 void QCairoWidget::mouseReleaseEvent(QMouseEvent* /*eventNotUsed*/)
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
134 {
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
135 OrthancStone::NativeStoneApplicationContext::GlobalMutexLocker locker(*context_);
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
136 locker.GetCentralViewport().MouseLeave();
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
137 }
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
138
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
139
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
140 void QCairoWidget::mouseMoveEvent(QMouseEvent* event)
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
141 {
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
142 OrthancStone::NativeStoneApplicationContext::GlobalMutexLocker locker(*context_);
730
fe938bddb932 fix after namespace rename to Deprecated
Alain Mazy <alain@mazy.be>
parents: 570
diff changeset
143 locker.GetCentralViewport().MouseMove(event->pos().x(), event->pos().y(), std::vector<Deprecated::Touch>());
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
144 }
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
145
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
146
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
147 void QCairoWidget::wheelEvent(QWheelEvent * event)
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
148 {
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
149 OrthancStone::NativeStoneApplicationContext::GlobalMutexLocker locker(*context_);
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
150
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
151 OrthancStone::KeyboardModifiers stoneModifiers = GetKeyboardModifiers(event);
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
152
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
153 if (event->orientation() == Qt::Vertical)
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
154 {
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
155 if (event->delta() < 0) // TODO: compare direction with SDL and make sure we send the same directions
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
156 {
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
157 locker.GetCentralViewport().MouseWheel(OrthancStone::MouseWheelDirection_Up, event->pos().x(), event->pos().y(), stoneModifiers);
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
158 }
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
159 else
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
160 {
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
161 locker.GetCentralViewport().MouseWheel(OrthancStone::MouseWheelDirection_Down, event->pos().x(), event->pos().y(), stoneModifiers);
277
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
162 }
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
163 }
a38465cc909f Qt: refresh ok + mouse interaction ok
am@osimis.io
parents: 276
diff changeset
164 }
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
165
284
38b0ac8055b9 Qt: catch and forward keyboard events
am@osimis.io
parents: 280
diff changeset
166 void QCairoWidget::keyPressEvent(QKeyEvent *event)
38b0ac8055b9 Qt: catch and forward keyboard events
am@osimis.io
parents: 280
diff changeset
167 {
327
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
168 using namespace OrthancStone;
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
169
284
38b0ac8055b9 Qt: catch and forward keyboard events
am@osimis.io
parents: 280
diff changeset
170 OrthancStone::KeyboardModifiers stoneModifiers = GetKeyboardModifiers(event);
38b0ac8055b9 Qt: catch and forward keyboard events
am@osimis.io
parents: 280
diff changeset
171
327
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
172 OrthancStone::KeyboardKeys keyType = OrthancStone::KeyboardKeys_Generic;
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
173 char keyChar = event->text()[0].toLatin1();
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
174
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
175 #define CASE_QT_KEY_TO_ORTHANC(qt, o) case qt: keyType = o; break;
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
176 if (keyChar == 0)
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
177 {
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
178 switch (event->key())
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
179 {
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
180 CASE_QT_KEY_TO_ORTHANC(Qt::Key_Up, KeyboardKeys_Up);
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
181 CASE_QT_KEY_TO_ORTHANC(Qt::Key_Down, KeyboardKeys_Down);
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
182 CASE_QT_KEY_TO_ORTHANC(Qt::Key_Left, KeyboardKeys_Left);
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
183 CASE_QT_KEY_TO_ORTHANC(Qt::Key_Right, KeyboardKeys_Right);
1256
771913258728 more keyboard key mappings
Alain Mazy <alain@mazy.be>
parents: 1199
diff changeset
184 CASE_QT_KEY_TO_ORTHANC(Qt::Key_F1, KeyboardKeys_F1);
771913258728 more keyboard key mappings
Alain Mazy <alain@mazy.be>
parents: 1199
diff changeset
185 CASE_QT_KEY_TO_ORTHANC(Qt::Key_F2, KeyboardKeys_F2);
771913258728 more keyboard key mappings
Alain Mazy <alain@mazy.be>
parents: 1199
diff changeset
186 CASE_QT_KEY_TO_ORTHANC(Qt::Key_F3, KeyboardKeys_F3);
771913258728 more keyboard key mappings
Alain Mazy <alain@mazy.be>
parents: 1199
diff changeset
187 CASE_QT_KEY_TO_ORTHANC(Qt::Key_F4, KeyboardKeys_F4);
771913258728 more keyboard key mappings
Alain Mazy <alain@mazy.be>
parents: 1199
diff changeset
188 CASE_QT_KEY_TO_ORTHANC(Qt::Key_F5, KeyboardKeys_F5);
771913258728 more keyboard key mappings
Alain Mazy <alain@mazy.be>
parents: 1199
diff changeset
189 CASE_QT_KEY_TO_ORTHANC(Qt::Key_F6, KeyboardKeys_F6);
771913258728 more keyboard key mappings
Alain Mazy <alain@mazy.be>
parents: 1199
diff changeset
190 CASE_QT_KEY_TO_ORTHANC(Qt::Key_F7, KeyboardKeys_F7);
771913258728 more keyboard key mappings
Alain Mazy <alain@mazy.be>
parents: 1199
diff changeset
191 CASE_QT_KEY_TO_ORTHANC(Qt::Key_F8, KeyboardKeys_F8);
771913258728 more keyboard key mappings
Alain Mazy <alain@mazy.be>
parents: 1199
diff changeset
192 CASE_QT_KEY_TO_ORTHANC(Qt::Key_F9, KeyboardKeys_F9);
771913258728 more keyboard key mappings
Alain Mazy <alain@mazy.be>
parents: 1199
diff changeset
193 CASE_QT_KEY_TO_ORTHANC(Qt::Key_F10, KeyboardKeys_F10);
771913258728 more keyboard key mappings
Alain Mazy <alain@mazy.be>
parents: 1199
diff changeset
194 CASE_QT_KEY_TO_ORTHANC(Qt::Key_F11, KeyboardKeys_F11);
771913258728 more keyboard key mappings
Alain Mazy <alain@mazy.be>
parents: 1199
diff changeset
195 CASE_QT_KEY_TO_ORTHANC(Qt::Key_F12, KeyboardKeys_F12);
327
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
196 default:
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
197 break;
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
198 }
8716176ff7f0 added support for arrow keys
am@osimis.io
parents: 318
diff changeset
199 }
1199
922d2e61aa5d RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents: 730
diff changeset
200 else if (keyChar == 127)
922d2e61aa5d RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents: 730
diff changeset
201 {
922d2e61aa5d RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents: 730
diff changeset
202 switch (event->key())
922d2e61aa5d RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents: 730
diff changeset
203 {
922d2e61aa5d RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents: 730
diff changeset
204 CASE_QT_KEY_TO_ORTHANC(Qt::Key_Delete, KeyboardKeys_Delete);
922d2e61aa5d RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents: 730
diff changeset
205 CASE_QT_KEY_TO_ORTHANC(Qt::Key_Backspace, KeyboardKeys_Backspace);
922d2e61aa5d RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents: 730
diff changeset
206 default:
922d2e61aa5d RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents: 730
diff changeset
207 break;
922d2e61aa5d RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents: 730
diff changeset
208 }
922d2e61aa5d RadiograpyScene: can now remove any layer + new key wrappers for Delete/Backspace
Alain Mazy <alain@mazy.be>
parents: 730
diff changeset
209 }
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
210
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
211 {
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
212 OrthancStone::NativeStoneApplicationContext::GlobalMutexLocker locker(*context_);
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
213 locker.GetCentralViewport().KeyPressed(keyType, keyChar, stoneModifiers);
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
214 }
284
38b0ac8055b9 Qt: catch and forward keyboard events
am@osimis.io
parents: 280
diff changeset
215 }
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
216
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
217
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
218 void QCairoWidget::resizeEvent(QResizeEvent* event)
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
219 {
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
220 grabGesture(Qt::PanGesture);
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
221 QWidget::resizeEvent(event);
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
222
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
223 if (event)
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
224 {
570
e77cbe4bb4c8 fix + access to DicomFrameConverter members to allow serialization
Alain Mazy <alain@mazy.be>
parents: 457
diff changeset
225 surface_.SetSize(event->size().width(), event->size().height(), true);
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
226
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
227 image_.reset(new QImage(reinterpret_cast<uchar*>(surface_.GetBuffer()),
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
228 event->size().width(),
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
229 event->size().height(),
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
230 surface_.GetPitch(),
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
231 QImage::Format_RGB32));
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
232
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
233 {
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
234 OrthancStone::NativeStoneApplicationContext::GlobalMutexLocker locker(*context_);
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
235 locker.GetCentralViewport().SetSize(event->size().width(), event->size().height());
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
236 }
276
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
237 }
5de5699ad570 first display in QCairoWidget; no mouse interaction yet
am@osimis.io
parents:
diff changeset
238 }