-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitormodel.cpp
More file actions
135 lines (115 loc) · 2.7 KB
/
Copy pathmonitormodel.cpp
File metadata and controls
135 lines (115 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// SPDX-License-Identifier: LGPL-3.0-or-later
#include <scratchcpp/monitor.h>
#include <scratchcpp/sprite.h>
#include <scratchcpp/iextension.h>
#include "monitormodel.h"
using namespace scratchcpprender;
MonitorModel::MonitorModel(QObject *parent) :
MonitorModel(nullptr, parent)
{
}
MonitorModel::MonitorModel(libscratchcpp::IExtension *extension, QObject *parent) :
QObject(parent)
{
if (!extension)
return;
// TODO: Get the color from the extension
std::string name = extension->name();
if (name == "Motion")
m_color = QColor::fromString("#4C97FF");
else if (name == "Looks")
m_color = QColor::fromString("#9966FF");
else if (name == "Sound")
m_color = QColor::fromString("#CF63CF");
else if (name == "Sensing")
m_color = QColor::fromString("#5CB1D6");
else if (name == "Variables")
m_color = QColor::fromString("#FF8C1A");
else if (name == "Lists")
m_color = QColor::fromString("#FF661A");
}
QString MonitorModel::name() const
{
if (m_monitor) {
if (libscratchcpp::Sprite *sprite = m_monitor->sprite())
return QString::fromStdString(sprite->name() + ": " + m_monitor->name());
else
return QString::fromStdString(m_monitor->name());
} else
return "";
}
bool MonitorModel::visible() const
{
if (m_monitor)
return m_monitor->visible() && !m_monitor->needsAutoPosition();
else
return false;
}
const QColor &MonitorModel::color() const
{
return m_color;
}
void MonitorModel::init(libscratchcpp::Monitor *monitor)
{
m_monitor = monitor;
}
void MonitorModel::onVisibleChanged(bool visible)
{
emit visibleChanged();
}
void MonitorModel::onXChanged(int x)
{
emit xChanged();
emit visibleChanged();
}
void MonitorModel::onYChanged(int y)
{
emit yChanged();
emit visibleChanged();
}
libscratchcpp::Monitor *MonitorModel::monitor() const
{
return m_monitor;
}
int MonitorModel::x() const
{
if (m_monitor)
return m_monitor->x();
else
return 0;
}
int MonitorModel::y() const
{
if (m_monitor)
return m_monitor->y();
else
return 0;
}
unsigned int MonitorModel::width() const
{
if (m_monitor)
return m_monitor->width();
else
return 0;
}
void MonitorModel::setWidth(unsigned int newWidth)
{
if (m_monitor) {
m_monitor->setWidth(newWidth);
emit widthChanged();
}
}
unsigned int MonitorModel::height() const
{
if (m_monitor)
return m_monitor->height();
else
return 0;
}
void MonitorModel::setHeight(unsigned int newHeight)
{
if (m_monitor) {
m_monitor->setHeight(newHeight);
emit heightChanged();
}
}