44 #include <QDockWidget>
48 #include <QMouseEvent>
56 handleMouseClickEvent(event);
62 handleMouseClickEvent(event);
66 CanvasView::handleMouseClickEvent(QMouseEvent* event)
87 moving->
moveBy(p.x() - moving_start.x(), p.y() - moving_start.y());
96 QMenu* editMenu = menuBar()->addMenu(tr(
"Edit"));
97 QMenu* newObjectMenu = editMenu->addMenu(tr(
"New Object"));
99 QAction* newRectangleAction =
new QAction(tr(
"Rectangle"),
this);
100 connect(newRectangleAction, SIGNAL(triggered(
bool)),
this, SLOT(newRectangle()));
101 newObjectMenu->addAction(newRectangleAction);
103 QAction* newLineAction =
new QAction(tr(
"Line"),
this);
104 connect(newLineAction, SIGNAL(triggered(
bool)),
this, SLOT(newLine()));
105 newObjectMenu->addAction(newLineAction);
107 QAction* newEllipseAction =
new QAction(tr(
"Ellipse"),
this);
108 connect(newEllipseAction, SIGNAL(triggered(
bool)),
this, SLOT(newEllipse()));
109 newObjectMenu->addAction(newEllipseAction);
111 QAction* newTextAction =
new QAction(tr(
"Text"),
this);
112 connect(newTextAction, SIGNAL(triggered(
bool)),
this, SLOT(newText()));
113 newObjectMenu->addAction(newTextAction);
115 deleteAction =
new QAction(tr(
"Delete Object"),
this);
116 connect(deleteAction, SIGNAL(triggered(
bool)),
this, SLOT(deleteObject()));
117 editMenu->addAction(deleteAction);
119 QAction* clearAction =
new QAction(tr(
"Clear All"),
this);
120 connect(clearAction, SIGNAL(triggered(
bool)),
this, SLOT(clearAll()));
121 editMenu->addAction(clearAction);
123 QAction* fillAction =
new QAction(tr(
"Fill View"),
this);
124 connect(fillAction, SIGNAL(triggered(
bool)),
this, SLOT(fillView()));
125 editMenu->addAction(fillAction);
129 connect(variantManager,
130 SIGNAL(valueChanged(
QtProperty*,
const QVariant&)),
132 SLOT(valueChanged(
QtProperty*,
const QVariant&)));
138 setCentralWidget(canvasView);
140 QDockWidget* dock =
new QDockWidget(
this);
141 addDockWidget(Qt::RightDockWidgetArea, dock);
145 dock->setWidget(propertyEditor);
157 MainWindow::newRectangle()
165 MainWindow::newEllipse()
173 MainWindow::newLine()
181 MainWindow::newText()
189 MainWindow::deleteObject()
202 MainWindow::clearAll()
211 MainWindow::fillView()
213 for (
int i = 0; i < 10; i++)
225 MainWindow::addRectangle()
229 int z = rand() % 256;
230 item->
setBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
231 item->
setPen(QPen(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8), 4));
238 MainWindow::addEllipse()
241 item->
setBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
243 item->
setZ(rand() % 256);
249 MainWindow::addLine()
254 rand() % canvas->
width() - canvas->
width() / 2,
257 item->
setPen(QPen(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8), 6));
258 item->
setZ(rand() % 256);
264 MainWindow::addText()
268 item->
setColor(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
270 item->
setZ(rand() % 256);
278 if (item != currentItem)
283 variantManager->
setValue(idToProperty[QLatin1String(
"xpos")], item->
x());
284 variantManager->
setValue(idToProperty[QLatin1String(
"ypos")], item->
y());
285 variantManager->
setValue(idToProperty[QLatin1String(
"zpos")], item->
z());
289 MainWindow::updateExpandState()
292 QListIterator<QtBrowserItem*> it(
list);
298 idToExpanded[propertyToId[prop]] = propertyEditor->
isExpanded(item);
307 QMap<QtProperty*, QString>::ConstIterator itProp = propertyToId.constBegin();
309 while (itProp != propertyToId.constEnd())
315 propertyToId.clear();
316 idToProperty.clear();
322 deleteAction->setEnabled(
false);
326 deleteAction->setEnabled(
true);
332 property->setAttribute(QLatin1String(
"maximum"), canvas->
width());
333 property->setValue(item->
x());
334 addProperty(property, QLatin1String(
"xpos"));
338 property->setAttribute(QLatin1String(
"maximum"), canvas->
height());
339 property->setValue(item->
y());
340 addProperty(property, QLatin1String(
"ypos"));
344 property->setAttribute(QLatin1String(
"maximum"), 256);
345 property->setValue(item->
z());
346 addProperty(property, QLatin1String(
"zpos"));
354 addProperty(property, QLatin1String(
"brush"));
358 addProperty(property, QLatin1String(
"pen"));
360 property = variantManager->
addProperty(QVariant::Size, tr(
"Size"));
362 addProperty(property, QLatin1String(
"size"));
370 addProperty(property, QLatin1String(
"pen"));
374 addProperty(property, QLatin1String(
"endpoint"));
382 addProperty(property, QLatin1String(
"brush"));
384 property = variantManager->
addProperty(QVariant::Size, tr(
"Size"));
386 addProperty(property, QLatin1String(
"size"));
394 addProperty(property, QLatin1String(
"color"));
398 addProperty(property, QLatin1String(
"text"));
400 property = variantManager->
addProperty(QVariant::Font, tr(
"Font"));
402 addProperty(property, QLatin1String(
"font"));
409 propertyToId[property] = id;
410 idToProperty[id] = property;
413 if (idToExpanded.contains(
id))
415 propertyEditor->
setExpanded(item, idToExpanded[
id]);
422 if (!propertyToId.contains(property))
432 QString
id = propertyToId[property];
434 if (
id == QLatin1String(
"xpos"))
438 else if (
id == QLatin1String(
"ypos"))
442 else if (
id == QLatin1String(
"zpos"))
446 else if (
id == QLatin1String(
"text"))
454 else if (
id == QLatin1String(
"color"))
462 else if (
id == QLatin1String(
"brush"))
468 QBrush b = i->
brush();
469 b.setColor(
value.value<QColor>());
473 else if (
id == QLatin1String(
"pen"))
480 p.setColor(
value.value<QColor>());
484 else if (
id == QLatin1String(
"font"))
492 else if (
id == QLatin1String(
"endpoint"))
497 QPoint p =
value.value<QPoint>();
501 else if (
id == QLatin1String(
"size"))
506 QSize
s =
value.value<QSize>();
512 QSize
s =
value.value<QSize>();