Browse Source

tycho: move drawView to IProjectModel

Alison Watson 4 months ago
parent
commit
98ba7309ce

+ 1
- 0
tycho/CMakeLists.txt View File

@@ -27,6 +27,7 @@ add_library(
27 27
 	STATIC
28 28
 		$ENV{OUT_DIR}/bindings.cc
29 29
 		$ENV{OUT_DIR}/bindings.h
30
+		cc/interface.cc
30 31
 		cc/interface.h
31 32
 		cc/main.cc
32 33
 		cc/mapmodel.cc

+ 3
- 13
tycho/bindings.json View File

@@ -46,19 +46,7 @@
46 46
 					"arguments": [
47 47
 						{"name": "index", "type": "quint16"}
48 48
 					]
49
-				}
50
-			},
51
-			"properties": {
52
-				"dirty": {"type": "bool", "write": true}
53
-			},
54
-			"itemProperties": {
55
-				"propIndex": {"type": "quint64", "roles": [["display"]]}
56
-			}
57
-		},
58
-		"IMapView": {
59
-			"type": "Widget",
60
-			"baseClass": "IProjectView",
61
-			"functions": {
49
+				},
62 50
 				"drawView": {
63 51
 					"return": "void",
64 52
 					"mut": false,
@@ -68,8 +56,10 @@
68 56
 				}
69 57
 			},
70 58
 			"properties": {
59
+				"dirty": {"type": "bool", "write": true}
71 60
 			},
72 61
 			"itemProperties": {
62
+				"propIndex": {"type": "quint64", "roles": [["display"]]}
73 63
 			}
74 64
 		}
75 65
 	}

+ 17
- 0
tycho/cc/interface.cc View File

@@ -0,0 +1,17 @@
1
+#include "tycho.h"
2
+
3
+IProjectView::IProjectView(Project *parent) :
4
+	QWidget(parent),
5
+	m_model(parent->model())
6
+{
7
+	setMinimumSize(320, 240);
8
+}
9
+
10
+void IProjectView::paintEvent(QPaintEvent *event)
11
+{
12
+	QPainter paint{this};
13
+	paint.fillRect(QRectF(0, 0, width(), height()), QColor(0, 0, 0, 255));
14
+	m_model->drawView(static_cast<void *>(&paint));
15
+}
16
+
17
+// EOF

+ 9
- 10
tycho/cc/interface.h View File

@@ -6,6 +6,8 @@
6 6
 #include <QPainter>
7 7
 #include <QWidget>
8 8
 
9
+class Project;
10
+
9 11
 class IProjectModel : public QAbstractItemModel
10 12
 {
11 13
 	Q_OBJECT
@@ -23,6 +25,8 @@ public:
23 25
 	virtual bool save() const = 0;
24 26
 	virtual bool saveAs(QString const &path) const = 0;
25 27
 
28
+	virtual void drawView(void *paint) const = 0;
29
+
26 30
 public slots:
27 31
 	virtual void deselect() = 0;
28 32
 	virtual void select(QModelIndex const &index) = 0;
@@ -38,19 +42,14 @@ class IProjectView : public QWidget
38 42
 	Q_OBJECT
39 43
 
40 44
 public:
41
-	using QWidget::QWidget;
42
-
45
+	explicit IProjectView(Project *parent);
43 46
 	virtual ~IProjectView() {}
44 47
 
45
-	virtual void drawView(void *paint) const = 0;
46
-
47 48
 protected:
48
-	void paintEvent(QPaintEvent *event) override
49
-	{
50
-		QPainter paint{this};
51
-		paint.fillRect(QRectF(0, 0, width(), height()), QColor(0, 0, 0, 255));
52
-		drawView(static_cast<void *>(&paint));
53
-	}
49
+	void paintEvent(QPaintEvent *event) override;
50
+
51
+private:
52
+	IProjectModel const *const m_model;
54 53
 };
55 54
 
56 55
 // EOF

+ 1
- 4
tycho/cc/mapview.cc View File

@@ -1,11 +1,8 @@
1 1
 #include "tycho.h"
2 2
 
3 3
 MapView::MapView(Project *parent) :
4
-	IMapView(parent),
5
-	m_mapModel(parent->mapModel())
4
+	IProjectView(parent)
6 5
 {
7
-	setMinimumSize(320, 240);
8
-
9 6
 	dbgPrintFunc();
10 7
 }
11 8
 

+ 2
- 5
tycho/cc/tycho.h View File

@@ -46,16 +46,13 @@ private:
46 46
 	QVariant data(const QModelIndex &index, int role) const override;
47 47
 };
48 48
 
49
-class MapView final : public IMapView
49
+class MapView : public IProjectView
50 50
 {
51 51
 	Q_OBJECT
52 52
 
53 53
 public:
54 54
 	explicit MapView(Project *parent);
55
-	~MapView();
56
-
57
-private:
58
-	MapModel *const m_mapModel;
55
+	~MapView() override;
59 56
 };
60 57
 
61 58
 class MapProps final : public  QDialog,

+ 0
- 2
tycho/source/gui.rs View File

@@ -1,10 +1,8 @@
1 1
 //! GUI implementation.
2 2
 
3 3
 mod mapmodel;
4
-mod mapview;
5 4
 mod qobj;
6 5
 
7 6
 pub use self::mapmodel::IMapModel;
8
-pub use self::mapview::IMapView;
9 7
 
10 8
 // EOF

+ 17
- 0
tycho/source/gui/mapmodel.rs View File

@@ -113,6 +113,23 @@ impl IMapModelTrait for IMapModel
113 113
 
114 114
 		self.selected = Some(index);
115 115
 	}
116
+
117
+	fn draw_view(&self, paint: *mut cc::QPainter)
118
+	{
119
+		cc::paint_fg(paint, 0, 255, 0, 255);
120
+		cc::paint_arc(paint, 30, 30, 100, 100, 77, 440);
121
+		cc::paint_chord(paint, 50, 50, 100, 100, 77, 440);
122
+		cc::paint_ellipse(paint, 80, 80, 30, 30);
123
+		cc::paint_image(paint, 200, 10, ":/tycho/images/tycho1.png");
124
+		cc::paint_line(paint, 100, 60, 140, 100);
125
+		cc::paint_point(paint, 20, 20);
126
+		cc::paint_polygon(paint, &[cc::Int2{x: 250, y: 170},
127
+		                           cc::Int2{x: 270, y: 190},
128
+		                           cc::Int2{x: 230, y: 190}]);
129
+		cc::paint_rect(paint, 150, 170, 20, 20);
130
+		cc::paint_squircle(paint, 90, 170, 30, 30, 7, 9);
131
+		cc::paint_text(paint, 50, 50, "hello, world");
132
+	}
116 133
 }
117 134
 
118 135
 impl Drop for IMapModel

+ 0
- 53
tycho/source/gui/mapview.rs View File

@@ -1,53 +0,0 @@
1
-//! Map view.
2
-
3
-use super::qobj::*;
4
-use crate::cc;
5
-
6
-impl IMapViewTrait for IMapView
7
-{
8
-	/// Returns a new `IMapView` instance.
9
-	fn new(emit: IMapViewEmitter) -> Self
10
-	{
11
-		if cfg!(debug_assertions) {
12
-			eprintln!("new IMapView");
13
-		}
14
-
15
-		Self{emit}
16
-	}
17
-
18
-	/// Returns the emitter of `self`.
19
-	fn emit(&mut self) -> &mut IMapViewEmitter {&mut self.emit}
20
-
21
-	fn draw_view(&self, paint: *mut cc::QPainter)
22
-	{
23
-		cc::paint_fg(paint, 0, 255, 0, 255);
24
-		cc::paint_arc(paint, 30, 30, 100, 100, 77, 440);
25
-		cc::paint_chord(paint, 50, 50, 100, 100, 77, 440);
26
-		cc::paint_ellipse(paint, 80, 80, 30, 30);
27
-		cc::paint_image(paint, 200, 10, ":/tycho/images/tycho1.png");
28
-		cc::paint_line(paint, 100, 60, 140, 100);
29
-		cc::paint_point(paint, 20, 20);
30
-		cc::paint_polygon(paint, &[cc::Int2{x: 250, y: 170},
31
-		                           cc::Int2{x: 270, y: 190},
32
-		                           cc::Int2{x: 230, y: 190}]);
33
-		cc::paint_rect(paint, 150, 170, 20, 20);
34
-		cc::paint_squircle(paint, 90, 170, 30, 30, 7, 9);
35
-		cc::paint_text(paint, 50, 50, "hello, world");
36
-	}
37
-}
38
-
39
-impl Drop for IMapView
40
-{
41
-	fn drop(&mut self)
42
-	{
43
-		if cfg!(debug_assertions) {
44
-			eprintln!("drop IMapView");
45
-		}
46
-	}
47
-}
48
-
49
-pub struct IMapView {
50
-	emit: IMapViewEmitter,
51
-}
52
-
53
-// EOF

Loading…
Cancel
Save