FloatEdit::FloatEdit(float initialValue, int id) : m_value(initialValue), m_id(id) { QHBoxLayout *layout = new QHBoxLayout; setLayout(layout); layout->setContentsMargins(0, 0, 0, 0); m_lineEdit = new QLineEdit(QString::number(m_value)); layout->addWidget(m_lineEdit); connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(editDone())); }
void NewItemInteractor::mouseReleaseEvent ( QMouseEvent* ) { if (theItem) { #if 0 KollageGraphicsScene* theScene = dynamic_cast<KollageGraphicsScene*>(theView->scene()); QUndoCommand* undo = new NewItemCommand(theScene, theFrame); theScene->getUndoStack()->push(undo); theFrame->setSelected(true); #endif theItem = 0; emit editDone(); } }
ColorEdit::ColorEdit(QRgb initialColor, int id) : m_color(initialColor), m_id(id) { QHBoxLayout *layout = new QHBoxLayout; setLayout(layout); layout->setContentsMargins(0, 0, 0, 0); m_lineEdit = new QLineEdit(QString::number(m_color, 16)); layout->addWidget(m_lineEdit); m_button = new QFrame; QPalette palette = m_button->palette(); palette.setColor(QPalette::Window, QColor(m_color)); m_button->setPalette(palette); m_button->setAutoFillBackground(true); m_button->setMinimumSize(32, 0); m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); m_button->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); layout->addWidget(m_button); connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(editDone())); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), selectInteractor(0), newLineItemInteractor(0), newRectItemInteractor(0), newTextItemInteractor(0) { setObjectName(QStringLiteral("MainWindow")); resize(1024, 768); graphicsSheet = new GraphicsSheet(this); QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect(graphicsSheet); shadow->setBlurRadius(20); shadow->setColor(QColor(0xa0, 0xa0, 0xa0)); graphicsSheet->setGraphicsEffect(shadow); graphicsSheet->setScaleBackground(QColor(0xFF, 0xFF, 0xF8)); QLayout* layout = new ScrollAreaLayout(); layout->addWidget(graphicsSheet); QWidget *centralwidget = new QWidget(this); centralwidget->setLayout(layout); setCentralWidget(centralwidget); /*****************************************************************************/ menubar = new QMenuBar(this); menubar->setObjectName(QStringLiteral("menubar")); menubar->setGeometry(QRect(0, 0, 401, 21)); setMenuBar(menubar); statusbar = new QStatusBar(this); statusbar->setObjectName(QStringLiteral("statusbar")); setStatusBar(statusbar); toolBar = new QToolBar(this); toolBar->setObjectName(QStringLiteral("toolBar")); addToolBar(Qt::TopToolBarArea, toolBar); /*****************************************************************************/ /* Initialize zoom, scale, and paper formats */ graphicsSheet->addScale("1:10", 0.1); graphicsSheet->addScale("1:5", 0.2); graphicsSheet->addScale("1:2", 0.5); graphicsSheet->addScale("1:1", 1.0); graphicsSheet->addScale("2:1", 2.0); graphicsSheet->addScale("5:1", 5.0); graphicsSheet->addScale("10:1", 10.0); LabelledComboBox* scaleWidget = new LabelledComboBox(toolBar, "Scale: "); scaleWidget->getComboBox()->addItems(graphicsSheet->getScaleNames()); toolBar->addWidget(scaleWidget); QObject::connect(scaleWidget->getComboBox(), SIGNAL(currentIndexChanged(int)), graphicsSheet, SLOT(setScale(int))); graphicsSheet->addZoom("50%", 0.5); graphicsSheet->addZoom("75%", 0.75); graphicsSheet->addZoom("100%", 1.0); graphicsSheet->addZoom("125%", 1.25); graphicsSheet->addZoom("150%", 1.5); graphicsSheet->addZoom("200%", 2.0); LabelledComboBox* zoomWidget = new LabelledComboBox(toolBar, "Zoom: "); zoomWidget->getComboBox()->addItems(graphicsSheet->getZoomNames()); toolBar->addWidget(zoomWidget); QObject::connect(zoomWidget->getComboBox(), SIGNAL(currentIndexChanged(int)), graphicsSheet, SLOT(setZoom(int))); graphicsSheet->setUnit("mm"); graphicsSheet->addSize("DIN A3", QSizeF(297.0, 420.0)); graphicsSheet->addSize("DIN A4", QSizeF(210.0, 297.0)); graphicsSheet->addSize("Letter", QSizeF(215.9, 279.4)); graphicsSheet->addSize("DIN A5", QSizeF(148.0, 210.0)); LabelledComboBox* sizeWidget = new LabelledComboBox(toolBar, "Sheet Size: "); sizeWidget->getComboBox()->addItems(graphicsSheet->getSizeNames()); toolBar->addWidget(sizeWidget); QObject::connect(sizeWidget->getComboBox(), SIGNAL(currentIndexChanged(int)), graphicsSheet, SLOT(setSize(int))); QCheckBox* checkbox = new QCheckBox("Landscape", toolBar); toolBar->addWidget(checkbox); QObject::connect(checkbox, SIGNAL(stateChanged(int)), graphicsSheet, SLOT(setDirection(int))); QIcon icon; icon.addFile(QStringLiteral(":/Icons/file-load.png"), QSize(), QIcon::Normal, QIcon::Off); actionLoad = new QAction(icon, "Load drawing ...", this); toolBar->addAction(actionLoad); QObject::connect(actionLoad, SIGNAL(triggered()), this, SLOT(doActionLoad())); QIcon icon2; icon2.addFile(QStringLiteral(":/Icons/file-save.png"), QSize(), QIcon::Normal, QIcon::Off); actionSave = new QAction(icon2, "Save drawing", this); toolBar->addAction(actionSave); QObject::connect(actionSave, SIGNAL(triggered()), this, SLOT(doActionSave())); QIcon icon3; icon3.addFile(QStringLiteral(":/Icons/file-save-as.png"), QSize(), QIcon::Normal, QIcon::Off); actionSaveAs = new QAction(icon3, "Save drawing as ...", this); toolBar->addAction(actionSaveAs); QObject::connect(actionSaveAs, SIGNAL(triggered()), this, SLOT(doActionSaveAs())); QIcon icon4; icon4.addFile(QStringLiteral(":/Icons/object-select.png"), QSize(), QIcon::Normal, QIcon::Off); actionSelect = new QAction(icon4, "Edit object", this); actionSelect->setCheckable(true); toolBar->addAction(actionSelect); QObject::connect(actionSelect, SIGNAL(triggered()), this, SLOT(doActionSelect())); QIcon icon5; icon5.addFile(QStringLiteral(":/Icons/object-newline.png"), QSize(), QIcon::Normal, QIcon::Off); actionNewLineItem = new QAction(icon5, "New line", this); actionNewLineItem->setCheckable(true); toolBar->addAction(actionNewLineItem); QObject::connect(actionNewLineItem, SIGNAL(triggered()), this, SLOT(doActionNewLineItem())); QIcon icon6; icon6.addFile(QStringLiteral(":/Icons/object-newrect.png"), QSize(), QIcon::Normal, QIcon::Off); actionNewRectItem = new QAction(icon6, "New rectangle", this); actionNewRectItem->setCheckable(true); toolBar->addAction(actionNewRectItem); QObject::connect(actionNewRectItem, SIGNAL(triggered()), this, SLOT(doActionNewRectItem())); QIcon icon7; icon7.addFile(QStringLiteral(":/Icons/object-newtext.png"), QSize(), QIcon::Normal, QIcon::Off); actionNewTextItem = new QAction(icon7, "New text rectangle", this); actionNewTextItem->setCheckable(true); toolBar->addAction(actionNewTextItem); QObject::connect(actionNewTextItem, SIGNAL(triggered()), this, SLOT(doActionNewTextItem())); QIcon icon8; icon8.addFile(QStringLiteral(":/Icons/object-newcircle.png"), QSize(), QIcon::Normal, QIcon::Off); actionNewCircleItem = new QAction(icon8, "New circle", this); actionNewCircleItem->setCheckable(true); toolBar->addAction(actionNewCircleItem); QObject::connect(actionNewCircleItem, SIGNAL(triggered()), this, SLOT(doActionNewCircleItem())); QIcon icon9; icon9.addFile(QStringLiteral(":/Icons/object-newellipse.png"), QSize(), QIcon::Normal, QIcon::Off); actionNewEllipseItem = new QAction(icon9, "New ellipse", this); actionNewEllipseItem->setCheckable(true); toolBar->addAction(actionNewEllipseItem); QObject::connect(actionNewEllipseItem, SIGNAL(triggered()), this, SLOT(doActionNewEllipseItem())); QIcon icon10; icon10.addFile(QStringLiteral(":/Icons/object-newbezier.png"), QSize(), QIcon::Normal, QIcon::Off); actionNewBezierItem = new QAction(icon10, "New bezier curve", this); actionNewBezierItem->setCheckable(true); toolBar->addAction(actionNewBezierItem); QObject::connect(actionNewBezierItem, SIGNAL(triggered()), this, SLOT(doActionNewBezierItem())); QIcon icon11; icon11.addFile(QStringLiteral(":/Icons/object-delete.png"), QSize(), QIcon::Normal, QIcon::Off); actionDeleteItem = new QAction(icon11, "Delete selected objects", this); toolBar->addAction(actionDeleteItem); QObject::connect(actionDeleteItem, SIGNAL(triggered()), graphicsSheet, SLOT(deleteSelectedItems())); QIcon icon12; icon12.addFile(QStringLiteral(":/Icons/edit-redo.png"), QSize(), QIcon::Normal, QIcon::Off); actionRedo = new QAction(icon12, "Redo last undone action", this); toolBar->addAction(actionRedo); QObject::connect(actionRedo, SIGNAL(triggered()), this, SLOT(doActionRedo())); QIcon icon13; icon13.addFile(QStringLiteral(":/Icons/edit-undo.png"), QSize(), QIcon::Normal, QIcon::Off); actionUndo = new QAction(icon13, "Undo last action", this); toolBar->addAction(actionUndo); QObject::connect(actionUndo, SIGNAL(triggered()), this, SLOT(doActionUndo())); QActionGroup* actionGroup = new QActionGroup(this); actionGroup->addAction(actionSelect); actionGroup->addAction(actionNewLineItem); actionGroup->addAction(actionNewRectItem); actionGroup->addAction(actionNewTextItem); actionGroup->addAction(actionNewCircleItem); actionGroup->addAction(actionNewEllipseItem); actionGroup->addAction(actionNewBezierItem); actionSelect->setChecked(true); #if 0 QAction* actionInfo = new QAction("Info", this); toolBar->addAction(actionInfo); QObject::connect(actionInfo, SIGNAL(triggered(bool)), this, SLOT(printInfo())); QAction* actionRotate = new QAction("Rotate", this); toolBar->addAction(actionRotate); QObject::connect(actionRotate, SIGNAL(triggered(bool)), this, SLOT(rotateItem())); QAction* actionResize = new QAction("ResizeHandle", this); toolBar->addAction(actionResize); QObject::connect(actionResize, SIGNAL(triggered(bool)), this, SLOT(resizeItem())); #endif zoomWidget->getComboBox()->setCurrentIndex(2); sizeWidget->getComboBox()->setCurrentIndex(3); scaleWidget->getComboBox()->setCurrentIndex(2); checkbox->setChecked(true); /*****************************************************************************/ GraphicsScene* scene = dynamic_cast<GraphicsScene*>(graphicsSheet->scene()); QObject::connect(scene, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); scene->loadFromFile("sample.drw"); selectInteractor = new EditItemInteractor(); // TODO: get all registered items from the factory! #if 0 newLineItemInteractor = new NewItemInteractor(LineItem::create, 1); // LineItem::P2Handle); QObject::connect(newLineItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect())); newRectItemInteractor = new NewItemInteractor(RectItem::create, 1); // RectItem::BottomRightHandle); QObject::connect(newRectItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect())); newTextItemInteractor = new NewItemInteractor(TextItem::create, 1); // TextItem::BottomRightHandle); QObject::connect(newTextItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect())); newCircleItemInteractor = new NewItemInteractor(CircleItem::create, 1); // CircleItem::RadHandle); QObject::connect(newCircleItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect())); newEllipseItemInteractor = new NewItemInteractor(EllipseItem::create, 1); // EllipseItem::BottomRightHandle); QObject::connect(newEllipseItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect())); newBezierItemInteractor = new NewItemInteractor(BezierItem::create, 1); // BezierItem::P2Handle); QObject::connect(newBezierItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect())); #endif graphicsSheet->setInteractor(selectInteractor); graphicsSheet->setSnapper(new EdgeSnapper(new GridSnapper())); propertyEditor = new ObjectController(); QDockWidget* propertiesDock = new QDockWidget(this); propertiesDock->setObjectName(QStringLiteral("propertiesDock")); propertiesDock->setFeatures(QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable); propertiesDock->setWindowTitle("Item properties"); propertiesDock->setWidget(propertyEditor); addDockWidget(static_cast<Qt::DockWidgetArea>(2), propertiesDock); }