44 #include <QDockWidget>
48 #include <QMouseEvent>
57 handleMouseClickEvent(event);
63 handleMouseClickEvent(event);
67 CanvasView::handleMouseClickEvent(QMouseEvent* event)
88 moving->
moveBy(p.x() - moving_start.x(), p.y() - moving_start.y());
97 QMenu* editMenu = menuBar()->addMenu(tr(
"Edit"));
98 QMenu* newObjectMenu = editMenu->addMenu(tr(
"New Object"));
100 QAction* newRectangleAction =
new QAction(tr(
"Rectangle"),
this);
101 connect(newRectangleAction, SIGNAL(triggered(
bool)),
this, SLOT(newRectangle()));
102 newObjectMenu->addAction(newRectangleAction);
104 QAction* newLineAction =
new QAction(tr(
"Line"),
this);
105 connect(newLineAction, SIGNAL(triggered(
bool)),
this, SLOT(newLine()));
106 newObjectMenu->addAction(newLineAction);
108 QAction* newEllipseAction =
new QAction(tr(
"Ellipse"),
this);
109 connect(newEllipseAction, SIGNAL(triggered(
bool)),
this, SLOT(newEllipse()));
110 newObjectMenu->addAction(newEllipseAction);
112 QAction* newTextAction =
new QAction(tr(
"Text"),
this);
113 connect(newTextAction, SIGNAL(triggered(
bool)),
this, SLOT(newText()));
114 newObjectMenu->addAction(newTextAction);
116 deleteAction =
new QAction(tr(
"Delete Object"),
this);
117 connect(deleteAction, SIGNAL(triggered(
bool)),
this, SLOT(deleteObject()));
118 editMenu->addAction(deleteAction);
120 QAction* clearAction =
new QAction(tr(
"Clear All"),
this);
121 connect(clearAction, SIGNAL(triggered(
bool)),
this, SLOT(clearAll()));
122 editMenu->addAction(clearAction);
124 QAction* fillAction =
new QAction(tr(
"Fill View"),
this);
125 connect(fillAction, SIGNAL(triggered(
bool)),
this, SLOT(fillView()));
126 editMenu->addAction(fillAction);
135 connect(doubleManager,
139 connect(stringManager,
140 SIGNAL(valueChanged(
QtProperty*,
const QString&)),
142 SLOT(valueChanged(
QtProperty*,
const QString&)));
143 connect(colorManager,
144 SIGNAL(valueChanged(
QtProperty*,
const QColor&)),
146 SLOT(valueChanged(
QtProperty*,
const QColor&)));
148 SIGNAL(valueChanged(
QtProperty*,
const QFont&)),
150 SLOT(valueChanged(
QtProperty*,
const QFont&)));
151 connect(pointManager,
152 SIGNAL(valueChanged(
QtProperty*,
const QPoint&)),
154 SLOT(valueChanged(
QtProperty*,
const QPoint&)));
156 SIGNAL(valueChanged(
QtProperty*,
const QSize&)),
158 SLOT(valueChanged(
QtProperty*,
const QSize&)));
168 setCentralWidget(canvasView);
170 QDockWidget* dock =
new QDockWidget(
this);
171 addDockWidget(Qt::RightDockWidgetArea, dock);
182 dock->setWidget(propertyEditor);
194 MainWindow::newRectangle()
202 MainWindow::newEllipse()
210 MainWindow::newLine()
218 MainWindow::newText()
226 MainWindow::deleteObject()
239 MainWindow::clearAll()
248 MainWindow::fillView()
250 for (
int i = 0; i < 10; i++)
262 MainWindow::addRectangle()
266 int z = rand() % 256;
267 item->
setBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
268 item->
setPen(QPen(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8), 4));
275 MainWindow::addEllipse()
278 item->
setBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
280 item->
setZ(rand() % 256);
286 MainWindow::addLine()
291 rand() % canvas->
width() - canvas->
width() / 2,
294 item->
setPen(QPen(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8), 6));
295 item->
setZ(rand() % 256);
301 MainWindow::addText()
305 item->
setColor(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
307 item->
setZ(rand() % 256);
315 if (item != currentItem)
320 doubleManager->
setValue(idToProperty[QLatin1String(
"xpos")], item->
x());
321 doubleManager->
setValue(idToProperty[QLatin1String(
"ypos")], item->
y());
322 doubleManager->
setValue(idToProperty[QLatin1String(
"zpos")], item->
z());
326 MainWindow::updateExpandState()
329 QListIterator<QtBrowserItem*> it(
list);
335 idToExpanded[propertyToId[prop]] = propertyEditor->
isExpanded(item);
344 QMap<QtProperty*, QString>::ConstIterator itProp = propertyToId.constBegin();
346 while (itProp != propertyToId.constEnd())
352 propertyToId.clear();
353 idToProperty.clear();
359 deleteAction->setEnabled(
false);
363 deleteAction->setEnabled(
true);
367 property = doubleManager->
addProperty(tr(
"Position X"));
369 doubleManager->
setValue(property, item->
x());
370 addProperty(property, QLatin1String(
"xpos"));
372 property = doubleManager->
addProperty(tr(
"Position Y"));
374 doubleManager->
setValue(property, item->
y());
375 addProperty(property, QLatin1String(
"ypos"));
377 property = doubleManager->
addProperty(tr(
"Position Z"));
378 doubleManager->
setRange(property, 0, 256);
379 doubleManager->
setValue(property, item->
z());
380 addProperty(property, QLatin1String(
"zpos"));
386 property = colorManager->
addProperty(tr(
"Brush Color"));
388 addProperty(property, QLatin1String(
"brush"));
390 property = colorManager->
addProperty(tr(
"Pen Color"));
391 colorManager->
setValue(property, i->
pen().color());
392 addProperty(property, QLatin1String(
"pen"));
396 addProperty(property, QLatin1String(
"size"));
402 property = colorManager->
addProperty(tr(
"Pen Color"));
403 colorManager->
setValue(property, i->
pen().color());
404 addProperty(property, QLatin1String(
"pen"));
406 property = pointManager->
addProperty(tr(
"Vector"));
408 addProperty(property, QLatin1String(
"endpoint"));
414 property = colorManager->
addProperty(tr(
"Brush Color"));
416 addProperty(property, QLatin1String(
"brush"));
420 sizeManager->
setRange(property, QSize(0, 0), QSize(1000, 1000));
421 addProperty(property, QLatin1String(
"size"));
429 addProperty(property, QLatin1String(
"color"));
433 addProperty(property, QLatin1String(
"text"));
437 addProperty(property, QLatin1String(
"font"));
442 MainWindow::addProperty(
QtProperty* property,
const QString&
id)
444 propertyToId[property] = id;
445 idToProperty[id] = property;
448 if (idToExpanded.contains(
id))
450 propertyEditor->
setExpanded(item, idToExpanded[
id]);
457 if (!propertyToId.contains(property))
467 QString
id = propertyToId[property];
469 if (
id == QLatin1String(
"xpos"))
473 else if (
id == QLatin1String(
"ypos"))
477 else if (
id == QLatin1String(
"zpos"))
488 if (!propertyToId.contains(property))
498 QString
id = propertyToId[property];
500 if (
id == QLatin1String(
"text"))
515 if (!propertyToId.contains(property))
525 QString
id = propertyToId[property];
527 if (
id == QLatin1String(
"color"))
535 else if (
id == QLatin1String(
"brush"))
541 QBrush b = i->
brush();
546 else if (
id == QLatin1String(
"pen"))
564 if (!propertyToId.contains(property))
574 QString
id = propertyToId[property];
576 if (
id == QLatin1String(
"font"))
591 if (!propertyToId.contains(property))
601 QString
id = propertyToId[property];
607 if (
id == QLatin1String(
"endpoint"))
619 if (!propertyToId.contains(property))
629 QString
id = propertyToId[property];
631 if (
id == QLatin1String(
"size"))