57 handleMouseClickEvent(event);
63 handleMouseClickEvent(event);
67CanvasView::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);
174 propertyEditor->setFactoryForManager(doubleManager, doubleSpinBoxFactory);
175 propertyEditor->setFactoryForManager(stringManager, lineEditFactory);
176 propertyEditor->setFactoryForManager(colorManager->subIntPropertyManager(), spinBoxFactory);
177 propertyEditor->setFactoryForManager(fontManager->subIntPropertyManager(), spinBoxFactory);
178 propertyEditor->setFactoryForManager(fontManager->subBoolPropertyManager(), checkBoxFactory);
179 propertyEditor->setFactoryForManager(fontManager->subEnumPropertyManager(), comboBoxFactory);
180 propertyEditor->setFactoryForManager(pointManager->subIntPropertyManager(), spinBoxFactory);
181 propertyEditor->setFactoryForManager(sizeManager->subIntPropertyManager(), spinBoxFactory);
182 dock->setWidget(propertyEditor);
194MainWindow::newRectangle()
202MainWindow::newEllipse()
204 QtCanvasItem* item = addEllipse();
212 QtCanvasItem* item = addLine();
220 QtCanvasItem* item = addText();
226MainWindow::deleteObject()
239MainWindow::clearAll()
248MainWindow::fillView()
250 for (
int i = 0; i < 10; i++)
262MainWindow::addRectangle()
264 QtCanvasPolygonalItem* item =
265 new QtCanvasRectangle(rand() % canvas->width(), rand() % canvas->height(), 50, 50, canvas);
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));
275MainWindow::addEllipse()
277 QtCanvasPolygonalItem* item =
new QtCanvasEllipse(50, 50, canvas);
278 item->
setBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
279 item->
move(rand() % canvas->width(), rand() % canvas->height());
280 item->
setZ(rand() % 256);
288 QtCanvasLine* item =
new QtCanvasLine(canvas);
291 rand() % canvas->width() - canvas->width() / 2,
292 rand() % canvas->height() - canvas->height() / 2);
293 item->
move(rand() % canvas->width(), rand() % canvas->height());
294 item->
setPen(QPen(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8), 6));
295 item->
setZ(rand() % 256);
303 QtCanvasText* item =
new QtCanvasText(canvas);
305 item->
setColor(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
306 item->
move(rand() % canvas->width(), rand() % canvas->height());
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());
326MainWindow::updateExpandState()
328 QList<QtBrowserItem*> list = propertyEditor->topLevelItems();
329 QListIterator<QtBrowserItem*> it(list);
333 QtBrowserItem* item = it.next();
334 QtProperty* prop = item->
property();
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);
365 QtProperty* property;
367 property = doubleManager->addProperty(tr(
"Position X"));
368 doubleManager->setRange(property, 0, canvas->width());
369 doubleManager->setValue(property, item->
x());
370 addProperty(property, QLatin1String(
"xpos"));
372 property = doubleManager->addProperty(tr(
"Position Y"));
373 doubleManager->setRange(property, 0, canvas->height());
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"));
384 QtCanvasRectangle* i = (QtCanvasRectangle*)item;
386 property = colorManager->addProperty(tr(
"Brush Color"));
387 colorManager->setValue(property, i->
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"));
394 property = sizeManager->addProperty(tr(
"Size"));
395 sizeManager->setValue(property, i->
size());
396 addProperty(property, QLatin1String(
"size"));
400 QtCanvasLine* i = (QtCanvasLine*)item;
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"));
407 pointManager->setValue(property, i->
endPoint());
408 addProperty(property, QLatin1String(
"endpoint"));
412 QtCanvasEllipse* i = (QtCanvasEllipse*)item;
414 property = colorManager->addProperty(tr(
"Brush Color"));
415 colorManager->setValue(property, i->
brush().color());
416 addProperty(property, QLatin1String(
"brush"));
418 property = sizeManager->addProperty(tr(
"Size"));
419 sizeManager->setValue(property, QSize(i->
width(), i->
height()));
420 sizeManager->setRange(property, QSize(0, 0), QSize(1000, 1000));
421 addProperty(property, QLatin1String(
"size"));
425 QtCanvasText* i = (QtCanvasText*)item;
427 property = colorManager->addProperty(tr(
"Color"));
428 colorManager->setValue(property, i->
color());
429 addProperty(property, QLatin1String(
"color"));
431 property = stringManager->addProperty(tr(
"Text"));
432 stringManager->setValue(property, i->
text());
433 addProperty(property, QLatin1String(
"text"));
435 property = fontManager->addProperty(tr(
"Font"));
436 fontManager->setValue(property, i->
font());
437 addProperty(property, QLatin1String(
"font"));
442MainWindow::addProperty(
QtProperty* property,
const QString&
id)
444 propertyToId[property] = id;
445 idToProperty[id] = property;
446 QtBrowserItem* item = propertyEditor->addProperty(property);
448 if (idToExpanded.contains(
id))
450 propertyEditor->setExpanded(item, idToExpanded[
id]);
455MainWindow::valueChanged(
QtProperty* property,
double value)
457 if (!propertyToId.contains(property))
467 QString
id = propertyToId[property];
469 if (
id == QLatin1String(
"xpos"))
471 currentItem->setX(value);
473 else if (
id == QLatin1String(
"ypos"))
475 currentItem->setY(value);
477 else if (
id == QLatin1String(
"zpos"))
479 currentItem->setZ(value);
486MainWindow::valueChanged(
QtProperty* property,
const QString& value)
488 if (!propertyToId.contains(property))
498 QString
id = propertyToId[property];
500 if (
id == QLatin1String(
"text"))
504 QtCanvasText* i = (QtCanvasText*)currentItem;
513MainWindow::valueChanged(
QtProperty* property,
const QColor& value)
515 if (!propertyToId.contains(property))
525 QString
id = propertyToId[property];
527 if (
id == QLatin1String(
"color"))
531 QtCanvasText* i = (QtCanvasText*)currentItem;
535 else if (
id == QLatin1String(
"brush"))
540 QtCanvasPolygonalItem* i = (QtCanvasPolygonalItem*)currentItem;
541 QBrush b = i->
brush();
546 else if (
id == QLatin1String(
"pen"))
551 QtCanvasPolygonalItem* i = (QtCanvasPolygonalItem*)currentItem;
562MainWindow::valueChanged(
QtProperty* property,
const QFont& value)
564 if (!propertyToId.contains(property))
574 QString
id = propertyToId[property];
576 if (
id == QLatin1String(
"font"))
580 QtCanvasText* i = (QtCanvasText*)currentItem;
589MainWindow::valueChanged(
QtProperty* property,
const QPoint& value)
591 if (!propertyToId.contains(property))
601 QString
id = propertyToId[property];
605 QtCanvasLine* i = (QtCanvasLine*)currentItem;
607 if (
id == QLatin1String(
"endpoint"))
617MainWindow::valueChanged(
QtProperty* property,
const QSize& value)
619 if (!propertyToId.contains(property))
629 QString
id = propertyToId[property];
631 if (
id == QLatin1String(
"size"))
635 QtCanvasRectangle* i = (QtCanvasRectangle*)currentItem;
640 QtCanvasEllipse* i = (QtCanvasEllipse*)currentItem;
QList< QtCanvasItem * > QtCanvasItemList
void contentsMouseMoveEvent(QMouseEvent *event)
void itemClicked(QtCanvasItem *item)
void itemMoved(QtCanvasItem *item)
void contentsMouseDoubleClickEvent(QMouseEvent *event)
void contentsMousePressEvent(QMouseEvent *event)
MainWindow(QWidget *parent=0)
QtProperty * property() const
void setSize(int w, int h)
virtual void setEnabled(bool yes)
void move(double x, double y)
void setPoints(int x1, int y1, int x2, int y2)
QPoint startPoint() const
virtual void setBrush(QBrush b)
virtual void setPen(QPen p)
void setSize(int w, int h)
void setText(const QString &)
void setFont(const QFont &)
void setColor(const QColor &)
QtCanvas * canvas() const
const QMatrix & inverseWorldMatrix() const
QtCanvasItemList collisions(const QPoint &) const
The QtCheckBoxFactory class provides QCheckBox widgets for properties created by QtBoolPropertyManage...
The QtColorPropertyManager provides and manages QColor properties.
The QtDoublePropertyManager provides and manages double properties.
The QtDoubleSpinBoxFactory class provides QDoubleSpinBox widgets for properties created by QtDoublePr...
The QtEnumEditorFactory class provides QComboBox widgets for properties created by QtEnumPropertyMana...
The QtFontPropertyManager provides and manages QFont properties.
The QtLineEditFactory class provides QLineEdit widgets for properties created by QtStringPropertyMana...
The QtPointPropertyManager provides and manages QPoint properties.
The QtProperty class encapsulates an instance of a property.
The QtSizePropertyManager provides and manages QSize properties.
The QtSpinBoxFactory class provides QSpinBox widgets for properties created by QtIntPropertyManager o...
The QtStringPropertyManager provides and manages QString properties.
The QtTreePropertyBrowser class provides QTreeWidget based property browser.
std::shared_ptr< Value > value()