comparison Applications/Qt/QCairoWidget.h @ 385:6cc3ce74dc05

using message broker in widgets
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 07 Nov 2018 20:49:41 +0100
parents 87376a645ee1
children b70e9be013e4
comparison
equal deleted inserted replaced
384:d20d75f20c5d 385:6cc3ce74dc05
1 /** 1 /**
2 * Stone of Orthanc 2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium 4 4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium 5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
6 * 6 *
7 * This program is free software: you can redistribute it and/or 7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License 8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of 9 * as published by the Free Software Foundation, either version 3 of
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/ 19 **/
20 20
21 #pragma once 21 #pragma once
22 22
23 #include "../../Framework/Widgets/CairoWidget.h"
24 #include "../../Applications/Generic/NativeStoneApplicationContext.h" 23 #include "../../Applications/Generic/NativeStoneApplicationContext.h"
25 #include "../../Framework/Viewport/CairoSurface.h" 24 #include "../../Framework/Viewport/CairoSurface.h"
25 #include "../../Framework/Widgets/IWidget.h"
26 26
27 #include <QWidget> 27 #include <QWidget>
28 #include <QGestureEvent>
29 #include <memory> 28 #include <memory>
30 #include <cassert> 29 #include <cassert>
31 30
32 class QCairoWidget : public QWidget, public OrthancStone::IViewport::IObserver 31 class QCairoWidget : public QWidget
33 { 32 {
34 Q_OBJECT 33 Q_OBJECT
35 34
36 private: 35 private:
36 class StoneObserver : public OrthancStone::IObserver
37 {
38 private:
39 QCairoWidget& that_;
40
41 public:
42 StoneObserver(QCairoWidget& that,
43 OrthancStone::IViewport& viewport,
44 OrthancStone::MessageBroker& broker);
45
46 void OnViewportChanged(const OrthancStone::IViewport::ViewportChangedMessage& message)
47 {
48 that_.OnViewportChanged();
49 }
50 };
51
37 std::auto_ptr<QImage> image_; 52 std::auto_ptr<QImage> image_;
38 OrthancStone::CairoSurface surface_; 53 OrthancStone::CairoSurface surface_;
39 OrthancStone::NativeStoneApplicationContext* context_; 54 OrthancStone::NativeStoneApplicationContext* context_;
55 std::auto_ptr<StoneObserver> observer_;
40 56
41 protected: 57 protected:
42 virtual void paintEvent(QPaintEvent *event); 58 virtual void paintEvent(QPaintEvent *event);
43 59
44 virtual void resizeEvent(QResizeEvent *event); 60 virtual void resizeEvent(QResizeEvent *event);
54 virtual void keyPressEvent(QKeyEvent *event); 70 virtual void keyPressEvent(QKeyEvent *event);
55 71
56 public: 72 public:
57 explicit QCairoWidget(QWidget *parent); 73 explicit QCairoWidget(QWidget *parent);
58 74
59 virtual ~QCairoWidget();
60
61 void SetContext(OrthancStone::NativeStoneApplicationContext& context); 75 void SetContext(OrthancStone::NativeStoneApplicationContext& context);
62 76
63 virtual void OnViewportContentChanged(const OrthancStone::IViewport& /*sceneNotUsed*/) 77 void OnViewportChanged()
64 { 78 {
65 update(); // schedule a repaint (handled by Qt) 79 update(); // schedule a repaint (handled by Qt)
66 emit ContentChanged(); 80 emit ContentChanged();
67 } 81 }
68 82
69 signals: 83 signals:
70
71 void ContentChanged(); 84 void ContentChanged();
72 85
73 public slots: 86 public slots:
74 87
75 }; 88 };