-
Notifications
You must be signed in to change notification settings - Fork 1
/
PaintGui.cpp
239 lines (203 loc) · 7.13 KB
/
PaintGui.cpp
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
* PaintGui.cpp
*
* (c) 2014 Sofian Audry -- info(@)sofianaudry(.)com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <PaintGui.h>
namespace mmp {
PaintGui::PaintGui(Paint::ptr paint)
: _paint(paint)
{
// Create editor.
_propertyBrowser = new QtTreePropertyBrowser;
_variantManager = new VariantManager;
_variantFactory = new VariantFactory;
_topItem = _variantManager->addProperty(QtVariantPropertyManager::groupTypeId(),
QObject::tr("Paint"));
_propertyBrowser->setFactoryForManager(_variantManager, _variantFactory);
connect(_variantManager, SIGNAL(valueChanged(QtProperty*, const QVariant&)),
this, SLOT(setValue(QtProperty*, const QVariant&)));
_propertyBrowser->addProperty(_topItem);
// Paint basic properties.
_opacityItem = _variantManager->addProperty(QVariant::Double, QObject::tr("Opacity (%)"));
_opacityItem->setAttribute("minimum", 0.0);
_opacityItem->setAttribute("maximum", 100.0);
_opacityItem->setAttribute("decimals", 1);
_opacityItem->setValue(_paint->getOpacity()*100.0);
_topItem->addSubProperty(_opacityItem);
}
PaintGui::~PaintGui()
{
delete _propertyBrowser;
}
QWidget* PaintGui::getPropertiesEditor()
{
return _propertyBrowser;
}
void PaintGui::setValue(QtProperty* property, const QVariant& value)
{
if (property == _opacityItem)
{
double opacity = qBound(value.toDouble() / 100.0, 0.0, 1.0);
if (opacity != _paint->getOpacity())
{
_paint->setOpacity(opacity);
emit valueChanged(_paint);
}
}
}
void PaintGui::setValue(QString propertyName, QVariant value)
{
if (propertyName == "opacity")
_opacityItem->setValue(value.toDouble() * 100);
}
ColorGui::ColorGui(Paint::ptr paint)
: PaintGui(paint)
{
color = qSharedPointerCast<Color>(paint);
Q_CHECK_PTR(color);
_colorItem = _variantManager->addProperty(QVariant::Color,
QObject::tr("Color"));
_colorItem->setValue(color->getColor());
_topItem->addSubProperty(_colorItem);
}
void ColorGui::setValue(QtProperty* property, const QVariant& value) {
if (property == _colorItem) {
color->setColor(value.value<QColor>());
emit valueChanged(_paint);
}
else
PaintGui::setValue(property, value);
}
void ColorGui::setValue(QString propertyName, QVariant value)
{
if (propertyName == "color")
setValue(_colorItem, value);
else
PaintGui::setValue(propertyName, value);
}
TextureGui::TextureGui(Paint::ptr paint) : PaintGui(paint) {
}
ImageGui::ImageGui(Paint::ptr paint)
: TextureGui(paint)
{
image = qSharedPointerCast<Image>(paint);
Q_CHECK_PTR(image);
_imageFileItem = _variantManager->addProperty(VariantManager::filePathTypeId(),
tr("Image file"));
_imageFileItem->setAttribute("filter", tr("Image files (%1);;All files (*)").arg(MM::IMAGE_FILES_FILTER));
_imageFileItem->setValue(image->getUri());
_imageRateItem = _variantManager->addProperty(QVariant::Double,
tr("Speed (%)"));
// we need to save it because the call to setAttribute will set it to minimum
double rate = image->getRate()*100;
_imageRateItem->setAttribute("decimals", 1);
_imageRateItem->setValue(rate);
_topItem->addSubProperty(_imageFileItem);
_topItem->addSubProperty(_imageRateItem);
}
void ImageGui::setValue(QtProperty* property, const QVariant& value) {
if (property == _imageFileItem) {
image->setUri(value.toString());
emit valueChanged(_paint);
}
else if (property == _imageRateItem)
{
//double rateSign = (media->getRate() <= 0 ? -1 : +1);
image->setRate(value.toDouble()/100.0);
emit valueChanged(_paint);
}
else
TextureGui::setValue(property, value);
}
void ImageGui::setValue(QString propertyName, QVariant value)
{
if (propertyName == "uri")
_imageFileItem->setValue(value);
else if (propertyName == "rate")
_imageRateItem->setValue(value.toDouble()*100);
else
TextureGui::setValue(propertyName, value);
}
VideoGui::VideoGui(Paint::ptr paint)
: TextureGui(paint)
{
media = qSharedPointerCast<Video>(paint);
Q_CHECK_PTR(media);
_mediaFileItem = _variantManager->addProperty(VariantManager::filePathTypeId(),
tr("Video file"));
_mediaFileItem->setAttribute("filter", tr("Video files (%1);;All files (*)").arg(MM::VIDEO_FILES_FILTER));
_mediaFileItem->setValue(media->getUri());
_mediaRateItem = _variantManager->addProperty(QVariant::Double,
tr("Speed (%)"));
// we need to save it because the call to setAttribute will set it to minimum
double rate = media->getRate()*100;
_mediaRateItem->setAttribute("decimals", 1);
_mediaRateItem->setValue(rate);
_mediaVolumeItem = _variantManager->addProperty(QVariant::Double,
tr("Volume (%)"));
double volume = media->getVolume()*100;
_mediaVolumeItem->setAttribute("minimum", 0.0);
_mediaVolumeItem->setAttribute("maximum", 100.0);
_mediaVolumeItem->setAttribute("decimals", 1);
_mediaVolumeItem->setValue(volume);
// _mediaReverseItem = _variantManager->addProperty(QVariant::Bool,
// tr("Reverse"));
// _mediaReverseItem->setValue(false);
_topItem->addSubProperty(_mediaFileItem);
_topItem->addSubProperty(_mediaRateItem);
_topItem->addSubProperty(_mediaVolumeItem);
// _topItem->addSubProperty(_mediaReverseItem);
}
void VideoGui::setValue(QtProperty* property, const QVariant& value)
{
if (property == _mediaFileItem)
{
media->setUri(value.toString());
emit valueChanged(_paint);
}
else if (property == _mediaRateItem)
{
//double rateSign = (media->getRate() <= 0 ? -1 : +1);
media->setRate(value.toDouble()/100.0);
emit valueChanged(_paint);
}
// else if (property == _mediaReverseItem)
// {
// double absoluteRate = abs( media->getRate() );
// media->setRate( (value.toBool() ? -1 : +1) * absoluteRate );
// emit valueChanged(_paint);
// }
else if (property == _mediaVolumeItem)
{
media->setVolume(value.toDouble()/100.0);
emit valueChanged(_paint);
}
else
TextureGui::setValue(property, value);
}
void VideoGui::setValue(QString propertyName, QVariant value)
{
if (propertyName == "uri")
_mediaFileItem->setValue(value);
if (propertyName == "rate")
_mediaRateItem->setValue(value.toDouble()*100);
if (propertyName == "volume")
_mediaVolumeItem->setValue(value.toDouble()*100);
else
TextureGui::setValue(propertyName, value);
}
}