diff --git a/tycho/CMakeLists.txt b/tycho/CMakeLists.txt index 9de0ada..e973cc6 100644 --- a/tycho/CMakeLists.txt +++ b/tycho/CMakeLists.txt @@ -27,6 +27,7 @@ add_library( STATIC $ENV{OUT_DIR}/bindings.cc $ENV{OUT_DIR}/bindings.h + cc/interface.cc cc/interface.h cc/main.cc cc/mapmodel.cc diff --git a/tycho/bindings.json b/tycho/bindings.json index a957c79..6af0c05 100644 --- a/tycho/bindings.json +++ b/tycho/bindings.json @@ -46,19 +46,7 @@ "arguments": [ {"name": "index", "type": "quint16"} ] - } - }, - "properties": { - "dirty": {"type": "bool", "write": true} - }, - "itemProperties": { - "propIndex": {"type": "quint64", "roles": [["display"]]} - } - }, - "IMapView": { - "type": "Widget", - "baseClass": "IProjectView", - "functions": { + }, "drawView": { "return": "void", "mut": false, @@ -68,8 +56,10 @@ } }, "properties": { + "dirty": {"type": "bool", "write": true} }, "itemProperties": { + "propIndex": {"type": "quint64", "roles": [["display"]]} } } } diff --git a/tycho/cc/interface.cc b/tycho/cc/interface.cc new file mode 100644 index 0000000..f4eb049 --- /dev/null +++ b/tycho/cc/interface.cc @@ -0,0 +1,17 @@ +#include "tycho.h" + +IProjectView::IProjectView(Project *parent) : + QWidget(parent), + m_model(parent->model()) +{ + setMinimumSize(320, 240); +} + +void IProjectView::paintEvent(QPaintEvent *event) +{ + QPainter paint{this}; + paint.fillRect(QRectF(0, 0, width(), height()), QColor(0, 0, 0, 255)); + m_model->drawView(static_cast(&paint)); +} + +// EOF diff --git a/tycho/cc/interface.h b/tycho/cc/interface.h index 892428b..ba48188 100644 --- a/tycho/cc/interface.h +++ b/tycho/cc/interface.h @@ -6,6 +6,8 @@ #include #include +class Project; + class IProjectModel : public QAbstractItemModel { Q_OBJECT @@ -23,6 +25,8 @@ public: virtual bool save() const = 0; virtual bool saveAs(QString const &path) const = 0; + virtual void drawView(void *paint) const = 0; + public slots: virtual void deselect() = 0; virtual void select(QModelIndex const &index) = 0; @@ -38,19 +42,14 @@ class IProjectView : public QWidget Q_OBJECT public: - using QWidget::QWidget; - + explicit IProjectView(Project *parent); virtual ~IProjectView() {} - virtual void drawView(void *paint) const = 0; - protected: - void paintEvent(QPaintEvent *event) override - { - QPainter paint{this}; - paint.fillRect(QRectF(0, 0, width(), height()), QColor(0, 0, 0, 255)); - drawView(static_cast(&paint)); - } + void paintEvent(QPaintEvent *event) override; + +private: + IProjectModel const *const m_model; }; // EOF diff --git a/tycho/cc/mapview.cc b/tycho/cc/mapview.cc index c2e6e82..8dd7ef4 100644 --- a/tycho/cc/mapview.cc +++ b/tycho/cc/mapview.cc @@ -1,11 +1,8 @@ #include "tycho.h" MapView::MapView(Project *parent) : - IMapView(parent), - m_mapModel(parent->mapModel()) + IProjectView(parent) { - setMinimumSize(320, 240); - dbgPrintFunc(); } diff --git a/tycho/cc/tycho.h b/tycho/cc/tycho.h index 3762132..3f840f4 100644 --- a/tycho/cc/tycho.h +++ b/tycho/cc/tycho.h @@ -46,16 +46,13 @@ private: QVariant data(const QModelIndex &index, int role) const override; }; -class MapView final : public IMapView +class MapView : public IProjectView { Q_OBJECT public: explicit MapView(Project *parent); - ~MapView(); - -private: - MapModel *const m_mapModel; + ~MapView() override; }; class MapProps final : public QDialog, diff --git a/tycho/source/gui.rs b/tycho/source/gui.rs index 3a0fef2..2c5078c 100644 --- a/tycho/source/gui.rs +++ b/tycho/source/gui.rs @@ -1,10 +1,8 @@ //! GUI implementation. mod mapmodel; -mod mapview; mod qobj; pub use self::mapmodel::IMapModel; -pub use self::mapview::IMapView; // EOF diff --git a/tycho/source/gui/mapmodel.rs b/tycho/source/gui/mapmodel.rs index 60a08ef..e209320 100644 --- a/tycho/source/gui/mapmodel.rs +++ b/tycho/source/gui/mapmodel.rs @@ -113,6 +113,23 @@ impl IMapModelTrait for IMapModel self.selected = Some(index); } + + fn draw_view(&self, paint: *mut cc::QPainter) + { + cc::paint_fg(paint, 0, 255, 0, 255); + cc::paint_arc(paint, 30, 30, 100, 100, 77, 440); + cc::paint_chord(paint, 50, 50, 100, 100, 77, 440); + cc::paint_ellipse(paint, 80, 80, 30, 30); + cc::paint_image(paint, 200, 10, ":/tycho/images/tycho1.png"); + cc::paint_line(paint, 100, 60, 140, 100); + cc::paint_point(paint, 20, 20); + cc::paint_polygon(paint, &[cc::Int2{x: 250, y: 170}, + cc::Int2{x: 270, y: 190}, + cc::Int2{x: 230, y: 190}]); + cc::paint_rect(paint, 150, 170, 20, 20); + cc::paint_squircle(paint, 90, 170, 30, 30, 7, 9); + cc::paint_text(paint, 50, 50, "hello, world"); + } } impl Drop for IMapModel diff --git a/tycho/source/gui/mapview.rs b/tycho/source/gui/mapview.rs deleted file mode 100644 index a26cdef..0000000 --- a/tycho/source/gui/mapview.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! Map view. - -use super::qobj::*; -use crate::cc; - -impl IMapViewTrait for IMapView -{ - /// Returns a new `IMapView` instance. - fn new(emit: IMapViewEmitter) -> Self - { - if cfg!(debug_assertions) { - eprintln!("new IMapView"); - } - - Self{emit} - } - - /// Returns the emitter of `self`. - fn emit(&mut self) -> &mut IMapViewEmitter {&mut self.emit} - - fn draw_view(&self, paint: *mut cc::QPainter) - { - cc::paint_fg(paint, 0, 255, 0, 255); - cc::paint_arc(paint, 30, 30, 100, 100, 77, 440); - cc::paint_chord(paint, 50, 50, 100, 100, 77, 440); - cc::paint_ellipse(paint, 80, 80, 30, 30); - cc::paint_image(paint, 200, 10, ":/tycho/images/tycho1.png"); - cc::paint_line(paint, 100, 60, 140, 100); - cc::paint_point(paint, 20, 20); - cc::paint_polygon(paint, &[cc::Int2{x: 250, y: 170}, - cc::Int2{x: 270, y: 190}, - cc::Int2{x: 230, y: 190}]); - cc::paint_rect(paint, 150, 170, 20, 20); - cc::paint_squircle(paint, 90, 170, 30, 30, 7, 9); - cc::paint_text(paint, 50, 50, "hello, world"); - } -} - -impl Drop for IMapView -{ - fn drop(&mut self) - { - if cfg!(debug_assertions) { - eprintln!("drop IMapView"); - } - } -} - -pub struct IMapView { - emit: IMapViewEmitter, -} - -// EOF