45 #include <QMouseEvent>
49 #include <QDockWidget>
53 handleMouseClickEvent(event);
58 handleMouseClickEvent(event);
61 void CanvasView::handleMouseClickEvent(QMouseEvent* event)
81 moving->
moveBy(p.x() - moving_start.x(), p.y() - moving_start.y());
92 QMenu* editMenu = menuBar()->addMenu(tr(
"Edit"));
93 QMenu* newObjectMenu = editMenu->addMenu(tr(
"New Object"));
95 QAction* newRectangleAction =
new QAction(tr(
"Rectangle"),
this);
96 connect(newRectangleAction, SIGNAL(triggered(
bool)),
this, SLOT(newRectangle()));
97 newObjectMenu->addAction(newRectangleAction);
99 QAction* newLineAction =
new QAction(tr(
"Line"),
this);
100 connect(newLineAction, SIGNAL(triggered(
bool)),
this, SLOT(newLine()));
101 newObjectMenu->addAction(newLineAction);
103 QAction* newEllipseAction =
new QAction(tr(
"Ellipse"),
this);
104 connect(newEllipseAction, SIGNAL(triggered(
bool)),
this, SLOT(newEllipse()));
105 newObjectMenu->addAction(newEllipseAction);
107 QAction* newTextAction =
new QAction(tr(
"Text"),
this);
108 connect(newTextAction, SIGNAL(triggered(
bool)),
this, SLOT(newText()));
109 newObjectMenu->addAction(newTextAction);
111 deleteAction =
new QAction(tr(
"Delete Object"),
this);
112 connect(deleteAction, SIGNAL(triggered(
bool)),
this, SLOT(deleteObject()));
113 editMenu->addAction(deleteAction);
115 QAction* clearAction =
new QAction(tr(
"Clear All"),
this);
116 connect(clearAction, SIGNAL(triggered(
bool)),
this, SLOT(clearAll()));
117 editMenu->addAction(clearAction);
119 QAction* fillAction =
new QAction(tr(
"Fill View"),
this);
120 connect(fillAction, SIGNAL(triggered(
bool)),
this, SLOT(fillView()));
121 editMenu->addAction(fillAction);
125 connect(variantManager, SIGNAL(valueChanged(
QtProperty*,
const QVariant&)),
126 this, SLOT(valueChanged(
QtProperty*,
const QVariant&)));
132 setCentralWidget(canvasView);
134 QDockWidget* dock =
new QDockWidget(
this);
135 addDockWidget(Qt::RightDockWidgetArea, dock);
139 dock->setWidget(propertyEditor);
152 void MainWindow::newRectangle()
159 void MainWindow::newEllipse()
166 void MainWindow::newLine()
173 void MainWindow::newText()
180 void MainWindow::deleteObject()
192 void MainWindow::clearAll()
200 void MainWindow::fillView()
202 for (
int i = 0; i < 10; i++)
216 rand() % canvas->
height(), 50, 50, canvas);
217 int z = rand() % 256;
218 item->
setBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
219 item->
setPen(QPen(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8), 4));
228 item->
setBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
230 item->
setZ(rand() % 256);
241 item->
setPen(QPen(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8), 6));
242 item->
setZ(rand() % 256);
251 item->
setColor(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
253 item->
setZ(rand() % 256);
260 if (item != currentItem)
265 variantManager->
setValue(idToProperty[QLatin1String(
"xpos")], item->
x());
266 variantManager->
setValue(idToProperty[QLatin1String(
"ypos")], item->
y());
267 variantManager->
setValue(idToProperty[QLatin1String(
"zpos")], item->
z());
270 void MainWindow::updateExpandState()
273 QListIterator<QtBrowserItem*> it(
list);
279 idToExpanded[propertyToId[prop]] = propertyEditor->
isExpanded(item);
287 QMap<QtProperty*, QString>::ConstIterator itProp = propertyToId.constBegin();
289 while (itProp != propertyToId.constEnd())
295 propertyToId.clear();
296 idToProperty.clear();
302 deleteAction->setEnabled(
false);
306 deleteAction->setEnabled(
true);
312 property->setAttribute(QLatin1String(
"maximum"), canvas->
width());
313 property->setValue(item->
x());
314 addProperty(property, QLatin1String(
"xpos"));
318 property->setAttribute(QLatin1String(
"maximum"), canvas->
height());
319 property->setValue(item->
y());
320 addProperty(property, QLatin1String(
"ypos"));
324 property->setAttribute(QLatin1String(
"maximum"), 256);
325 property->setValue(item->
z());
326 addProperty(property, QLatin1String(
"zpos"));
334 addProperty(property, QLatin1String(
"brush"));
338 addProperty(property, QLatin1String(
"pen"));
340 property = variantManager->
addProperty(QVariant::Size, tr(
"Size"));
342 addProperty(property, QLatin1String(
"size"));
350 addProperty(property, QLatin1String(
"pen"));
354 addProperty(property, QLatin1String(
"endpoint"));
362 addProperty(property, QLatin1String(
"brush"));
364 property = variantManager->
addProperty(QVariant::Size, tr(
"Size"));
366 addProperty(property, QLatin1String(
"size"));
374 addProperty(property, QLatin1String(
"color"));
378 addProperty(property, QLatin1String(
"text"));
380 property = variantManager->
addProperty(QVariant::Font, tr(
"Font"));
382 addProperty(property, QLatin1String(
"font"));
388 propertyToId[property] = id;
389 idToProperty[id] = property;
392 if (idToExpanded.contains(
id))
394 propertyEditor->
setExpanded(item, idToExpanded[
id]);
398 void MainWindow::valueChanged(
QtProperty* property,
const QVariant&
value)
400 if (!propertyToId.contains(property))
410 QString
id = propertyToId[property];
412 if (
id == QLatin1String(
"xpos"))
416 else if (
id == QLatin1String(
"ypos"))
420 else if (
id == QLatin1String(
"zpos"))
424 else if (
id == QLatin1String(
"text"))
432 else if (
id == QLatin1String(
"color"))
440 else if (
id == QLatin1String(
"brush"))
446 QBrush b = i->
brush();
447 b.setColor(
value.value<QColor>());
451 else if (
id == QLatin1String(
"pen"))
458 p.setColor(
value.value<QColor>());
462 else if (
id == QLatin1String(
"font"))
470 else if (
id == QLatin1String(
"endpoint"))
475 QPoint p =
value.value<QPoint>();
479 else if (
id == QLatin1String(
"size"))
484 QSize
s =
value.value<QSize>();
490 QSize
s =
value.value<QSize>();