46 #include <QMouseEvent>
50 #include <QDockWidget>
54 handleMouseClickEvent(event);
59 handleMouseClickEvent(event);
62 void CanvasView::handleMouseClickEvent(QMouseEvent* event)
82 moving->
moveBy(p.x() - moving_start.x(), p.y() - moving_start.y());
93 QMenu* editMenu = menuBar()->addMenu(tr(
"Edit"));
94 QMenu* newObjectMenu = editMenu->addMenu(tr(
"New Object"));
96 QAction* newRectangleAction =
new QAction(tr(
"Rectangle"),
this);
97 connect(newRectangleAction, SIGNAL(triggered(
bool)),
this, SLOT(newRectangle()));
98 newObjectMenu->addAction(newRectangleAction);
100 QAction* newLineAction =
new QAction(tr(
"Line"),
this);
101 connect(newLineAction, SIGNAL(triggered(
bool)),
this, SLOT(newLine()));
102 newObjectMenu->addAction(newLineAction);
104 QAction* newEllipseAction =
new QAction(tr(
"Ellipse"),
this);
105 connect(newEllipseAction, SIGNAL(triggered(
bool)),
this, SLOT(newEllipse()));
106 newObjectMenu->addAction(newEllipseAction);
108 QAction* newTextAction =
new QAction(tr(
"Text"),
this);
109 connect(newTextAction, SIGNAL(triggered(
bool)),
this, SLOT(newText()));
110 newObjectMenu->addAction(newTextAction);
112 deleteAction =
new QAction(tr(
"Delete Object"),
this);
113 connect(deleteAction, SIGNAL(triggered(
bool)),
this, SLOT(deleteObject()));
114 editMenu->addAction(deleteAction);
116 QAction* clearAction =
new QAction(tr(
"Clear All"),
this);
117 connect(clearAction, SIGNAL(triggered(
bool)),
this, SLOT(clearAll()));
118 editMenu->addAction(clearAction);
120 QAction* fillAction =
new QAction(tr(
"Fill View"),
this);
121 connect(fillAction, SIGNAL(triggered(
bool)),
this, SLOT(fillView()));
122 editMenu->addAction(fillAction);
131 connect(doubleManager, SIGNAL(valueChanged(
QtProperty*,
double)),
132 this, SLOT(valueChanged(
QtProperty*,
double)));
133 connect(stringManager, SIGNAL(valueChanged(
QtProperty*,
const QString&)),
134 this, SLOT(valueChanged(
QtProperty*,
const QString&)));
135 connect(colorManager, SIGNAL(valueChanged(
QtProperty*,
const QColor&)),
136 this, SLOT(valueChanged(
QtProperty*,
const QColor&)));
137 connect(fontManager, SIGNAL(valueChanged(
QtProperty*,
const QFont&)),
138 this, SLOT(valueChanged(
QtProperty*,
const QFont&)));
139 connect(pointManager, SIGNAL(valueChanged(
QtProperty*,
const QPoint&)),
140 this, SLOT(valueChanged(
QtProperty*,
const QPoint&)));
141 connect(sizeManager, SIGNAL(valueChanged(
QtProperty*,
const QSize&)),
142 this, SLOT(valueChanged(
QtProperty*,
const QSize&)));
152 setCentralWidget(canvasView);
154 QDockWidget* dock =
new QDockWidget(
this);
155 addDockWidget(Qt::RightDockWidgetArea, dock);
166 dock->setWidget(propertyEditor);
179 void MainWindow::newRectangle()
186 void MainWindow::newEllipse()
193 void MainWindow::newLine()
200 void MainWindow::newText()
207 void MainWindow::deleteObject()
219 void MainWindow::clearAll()
227 void MainWindow::fillView()
229 for (
int i = 0; i < 10; i++)
243 rand() % canvas->
height(), 50, 50, canvas);
244 int z = rand() % 256;
245 item->
setBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
246 item->
setPen(QPen(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8), 4));
255 item->
setBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
257 item->
setZ(rand() % 256);
268 item->
setPen(QPen(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8), 6));
269 item->
setZ(rand() % 256);
278 item->
setColor(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
280 item->
setZ(rand() % 256);
287 if (item != currentItem)
292 doubleManager->
setValue(idToProperty[QLatin1String(
"xpos")], item->
x());
293 doubleManager->
setValue(idToProperty[QLatin1String(
"ypos")], item->
y());
294 doubleManager->
setValue(idToProperty[QLatin1String(
"zpos")], item->
z());
297 void MainWindow::updateExpandState()
300 QListIterator<QtBrowserItem*> it(
list);
306 idToExpanded[propertyToId[prop]] = propertyEditor->
isExpanded(item);
314 QMap<QtProperty*, QString>::ConstIterator itProp = propertyToId.constBegin();
316 while (itProp != propertyToId.constEnd())
322 propertyToId.clear();
323 idToProperty.clear();
329 deleteAction->setEnabled(
false);
333 deleteAction->setEnabled(
true);
337 property = doubleManager->
addProperty(tr(
"Position X"));
339 doubleManager->
setValue(property, item->
x());
340 addProperty(property, QLatin1String(
"xpos"));
342 property = doubleManager->
addProperty(tr(
"Position Y"));
344 doubleManager->
setValue(property, item->
y());
345 addProperty(property, QLatin1String(
"ypos"));
347 property = doubleManager->
addProperty(tr(
"Position Z"));
348 doubleManager->
setRange(property, 0, 256);
349 doubleManager->
setValue(property, item->
z());
350 addProperty(property, QLatin1String(
"zpos"));
356 property = colorManager->
addProperty(tr(
"Brush Color"));
358 addProperty(property, QLatin1String(
"brush"));
360 property = colorManager->
addProperty(tr(
"Pen Color"));
361 colorManager->
setValue(property, i->
pen().color());
362 addProperty(property, QLatin1String(
"pen"));
366 addProperty(property, QLatin1String(
"size"));
372 property = colorManager->
addProperty(tr(
"Pen Color"));
373 colorManager->
setValue(property, i->
pen().color());
374 addProperty(property, QLatin1String(
"pen"));
376 property = pointManager->
addProperty(tr(
"Vector"));
378 addProperty(property, QLatin1String(
"endpoint"));
384 property = colorManager->
addProperty(tr(
"Brush Color"));
386 addProperty(property, QLatin1String(
"brush"));
390 sizeManager->
setRange(property, QSize(0, 0), QSize(1000, 1000));
391 addProperty(property, QLatin1String(
"size"));
399 addProperty(property, QLatin1String(
"color"));
403 addProperty(property, QLatin1String(
"text"));
407 addProperty(property, QLatin1String(
"font"));
411 void MainWindow::addProperty(
QtProperty* property,
const QString&
id)
413 propertyToId[property] = id;
414 idToProperty[id] = property;
417 if (idToExpanded.contains(
id))
419 propertyEditor->
setExpanded(item, idToExpanded[
id]);
425 if (!propertyToId.contains(property))
435 QString
id = propertyToId[property];
437 if (
id == QLatin1String(
"xpos"))
441 else if (
id == QLatin1String(
"ypos"))
445 else if (
id == QLatin1String(
"zpos"))
453 void MainWindow::valueChanged(
QtProperty* property,
const QString&
value)
455 if (!propertyToId.contains(property))
465 QString
id = propertyToId[property];
467 if (
id == QLatin1String(
"text"))
479 void MainWindow::valueChanged(
QtProperty* property,
const QColor&
value)
481 if (!propertyToId.contains(property))
491 QString
id = propertyToId[property];
493 if (
id == QLatin1String(
"color"))
501 else if (
id == QLatin1String(
"brush"))
507 QBrush b = i->
brush();
512 else if (
id == QLatin1String(
"pen"))
527 void MainWindow::valueChanged(
QtProperty* property,
const QFont&
value)
529 if (!propertyToId.contains(property))
539 QString
id = propertyToId[property];
541 if (
id == QLatin1String(
"font"))
553 void MainWindow::valueChanged(
QtProperty* property,
const QPoint&
value)
555 if (!propertyToId.contains(property))
565 QString
id = propertyToId[property];
571 if (
id == QLatin1String(
"endpoint"))
580 void MainWindow::valueChanged(
QtProperty* property,
const QSize&
value)
582 if (!propertyToId.contains(property))
592 QString
id = propertyToId[property];
594 if (
id == QLatin1String(
"size"))