tycho: move drawView to IProjectModel

master
an 2019-07-18 00:38:48 -04:00
Parent 9625eb1618
révision 98ba7309ce
9 fichiers modifiés avec 50 ajouts et 87 suppressions

Voir le fichier

@ -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

Voir le fichier

@ -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"]]}
}
}
}

17
tycho/cc/interface.cc Normal file
Voir le fichier

@ -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<void *>(&paint));
}
// EOF

Voir le fichier

@ -6,6 +6,8 @@
#include <QPainter>
#include <QWidget>
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<void *>(&paint));
}
void paintEvent(QPaintEvent *event) override;
private:
IProjectModel const *const m_model;
};
// EOF

Voir le fichier

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

Voir le fichier

@ -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,

Voir le fichier

@ -1,10 +1,8 @@
//! GUI implementation.
mod mapmodel;
mod mapview;
mod qobj;
pub use self::mapmodel::IMapModel;
pub use self::mapview::IMapView;
// EOF

Voir le fichier

@ -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

Voir le fichier

@ -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