tycho: move drawView to IProjectModel
parent
9625eb1618
commit
98ba7309ce
|
@ -27,6 +27,7 @@ add_library(
|
||||||
STATIC
|
STATIC
|
||||||
$ENV{OUT_DIR}/bindings.cc
|
$ENV{OUT_DIR}/bindings.cc
|
||||||
$ENV{OUT_DIR}/bindings.h
|
$ENV{OUT_DIR}/bindings.h
|
||||||
|
cc/interface.cc
|
||||||
cc/interface.h
|
cc/interface.h
|
||||||
cc/main.cc
|
cc/main.cc
|
||||||
cc/mapmodel.cc
|
cc/mapmodel.cc
|
||||||
|
|
|
@ -46,19 +46,7 @@
|
||||||
"arguments": [
|
"arguments": [
|
||||||
{"name": "index", "type": "quint16"}
|
{"name": "index", "type": "quint16"}
|
||||||
]
|
]
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"properties": {
|
|
||||||
"dirty": {"type": "bool", "write": true}
|
|
||||||
},
|
|
||||||
"itemProperties": {
|
|
||||||
"propIndex": {"type": "quint64", "roles": [["display"]]}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"IMapView": {
|
|
||||||
"type": "Widget",
|
|
||||||
"baseClass": "IProjectView",
|
|
||||||
"functions": {
|
|
||||||
"drawView": {
|
"drawView": {
|
||||||
"return": "void",
|
"return": "void",
|
||||||
"mut": false,
|
"mut": false,
|
||||||
|
@ -68,8 +56,10 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"dirty": {"type": "bool", "write": true}
|
||||||
},
|
},
|
||||||
"itemProperties": {
|
"itemProperties": {
|
||||||
|
"propIndex": {"type": "quint64", "roles": [["display"]]}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
|
@ -6,6 +6,8 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
class Project;
|
||||||
|
|
||||||
class IProjectModel : public QAbstractItemModel
|
class IProjectModel : public QAbstractItemModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -23,6 +25,8 @@ public:
|
||||||
virtual bool save() const = 0;
|
virtual bool save() const = 0;
|
||||||
virtual bool saveAs(QString const &path) const = 0;
|
virtual bool saveAs(QString const &path) const = 0;
|
||||||
|
|
||||||
|
virtual void drawView(void *paint) const = 0;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void deselect() = 0;
|
virtual void deselect() = 0;
|
||||||
virtual void select(QModelIndex const &index) = 0;
|
virtual void select(QModelIndex const &index) = 0;
|
||||||
|
@ -38,19 +42,14 @@ class IProjectView : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using QWidget::QWidget;
|
explicit IProjectView(Project *parent);
|
||||||
|
|
||||||
virtual ~IProjectView() {}
|
virtual ~IProjectView() {}
|
||||||
|
|
||||||
virtual void drawView(void *paint) const = 0;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override
|
void paintEvent(QPaintEvent *event) override;
|
||||||
{
|
|
||||||
QPainter paint{this};
|
private:
|
||||||
paint.fillRect(QRectF(0, 0, width(), height()), QColor(0, 0, 0, 255));
|
IProjectModel const *const m_model;
|
||||||
drawView(static_cast<void *>(&paint));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
#include "tycho.h"
|
#include "tycho.h"
|
||||||
|
|
||||||
MapView::MapView(Project *parent) :
|
MapView::MapView(Project *parent) :
|
||||||
IMapView(parent),
|
IProjectView(parent)
|
||||||
m_mapModel(parent->mapModel())
|
|
||||||
{
|
{
|
||||||
setMinimumSize(320, 240);
|
|
||||||
|
|
||||||
dbgPrintFunc();
|
dbgPrintFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,16 +46,13 @@ private:
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MapView final : public IMapView
|
class MapView : public IProjectView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MapView(Project *parent);
|
explicit MapView(Project *parent);
|
||||||
~MapView();
|
~MapView() override;
|
||||||
|
|
||||||
private:
|
|
||||||
MapModel *const m_mapModel;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class MapProps final : public QDialog,
|
class MapProps final : public QDialog,
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
//! GUI implementation.
|
//! GUI implementation.
|
||||||
|
|
||||||
mod mapmodel;
|
mod mapmodel;
|
||||||
mod mapview;
|
|
||||||
mod qobj;
|
mod qobj;
|
||||||
|
|
||||||
pub use self::mapmodel::IMapModel;
|
pub use self::mapmodel::IMapModel;
|
||||||
pub use self::mapview::IMapView;
|
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
|
|
|
@ -113,6 +113,23 @@ impl IMapModelTrait for IMapModel
|
||||||
|
|
||||||
self.selected = Some(index);
|
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
|
impl Drop for IMapModel
|
||||||
|
|
|
@ -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
|
|
Loading…
Reference in New Issue