X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fapplicationwindow.cpp;h=8bbdbc1c5646c8c996fdf33244b0f0995f711fa7;hb=41644f6a841b45cb6f1f7a96c93fd550f67a7974;hp=4c765cbc4e4e507b2248124b4be7ecf456e52ac4;hpb=eb39f1bb5e6518c5dc4f4dbd3c88912a97192e95;p=architektonas diff --git a/src/applicationwindow.cpp b/src/applicationwindow.cpp index 4c765cb..8bbdbc1 100644 --- a/src/applicationwindow.cpp +++ b/src/applicationwindow.cpp @@ -31,6 +31,9 @@ #include #include "about.h" #include "blockwidget.h" +#include "commandprocessor.h" +#include "consolewidget.h" +#include "drawingsettingsdlg.h" #include "drawingview.h" #include "fileio.h" #include "generaltab.h" @@ -58,10 +61,8 @@ ApplicationWindow::ApplicationWindow(): aboutWin = new AboutWindow(this); -// ((TTEdit *)qApp)->charWnd = new CharWindow(this); - setWindowIcon(QIcon(":/res/atns-icon.png")); - setWindowTitle("Architektonas"); +// setWindowTitle("Architektonas"); CreateActions(); CreateMenus(); @@ -80,10 +81,16 @@ ApplicationWindow::ApplicationWindow(): ObjectWidget * ow = new ObjectWidget; dock3->setWidget(ow); addDockWidget(Qt::RightDockWidgetArea, dock3); + QDockWidget * dock4 = new QDockWidget(tr("Command"), this); + cw = new ConsoleWidget; + dock4->setWidget(cw); + addDockWidget(Qt::BottomDockWidgetArea, dock4); + // Needed for saveState() dock1->setObjectName("Layers"); dock2->setObjectName("Blocks"); dock3->setObjectName("Object"); + dock4->setObjectName("Commands"); // Create status bar zoomIndicator = new QLabel("Zoom: 100% Grid: 12.0\" BU: Inch"); @@ -91,6 +98,8 @@ ApplicationWindow::ApplicationWindow(): statusBar()->showMessage(tr("Ready")); ReadSettings(); + // Make sure the bottom left corner gets owned by the right side: + setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea); setUnifiedTitleAndToolBarOnMac(true); Global::font = new QFont("Verdana", 15, QFont::Bold); @@ -101,6 +110,8 @@ ApplicationWindow::ApplicationWindow(): connect(drawing, SIGNAL(ObjectHovered(Object *)), ow, SLOT(ShowInfo(Object *))); connect(drawing, SIGNAL(NeedZoomUpdate()), this, SLOT(UpdateZoom())); + + connect(cw->cmdProc, SIGNAL(UpdateNeeded()), this, SLOT(UpdateFromCommand())); } void ApplicationWindow::closeEvent(QCloseEvent * event) @@ -146,7 +157,8 @@ void ApplicationWindow::FileNew(void) drawing->dirty = false; drawing->update(); documentName.clear(); - setWindowTitle("Architektonas - Untitled"); +// setWindowTitle("Architektonas - Untitled"); + setWindowFilePath(documentName); statusBar()->showMessage(tr("New drawing is ready.")); } @@ -159,6 +171,21 @@ void ApplicationWindow::FileOpen(void) if (filename.isEmpty()) return; + LoadFile(filename); +} + +void ApplicationWindow::FileOpenRecent(void) +{ + QAction * action = qobject_cast(sender()); + + if (!action) + return; + + LoadFile(action->data().toString()); +} + +void ApplicationWindow::LoadFile(QString filename) +{ FILE * file = fopen(filename.toUtf8().data(), "r"); if (file == 0) @@ -185,7 +212,6 @@ void ApplicationWindow::FileOpen(void) return; } -//printf("FileOpen: container size = %li\n", container.objects.size()); // Keep memory leaks from happening by getting rid of the old document DeleteContents(drawing->document.objects); emit ReloadLayers(); @@ -196,7 +222,8 @@ void ApplicationWindow::FileOpen(void) drawing->dirty = false; drawing->update(); documentName = filename; - setWindowTitle(QString("Architektonas - %1").arg(documentName)); +// setWindowTitle(QString("Architektonas - %1").arg(documentName)); + AdjustMRU(filename); statusBar()->showMessage(tr("Drawing loaded.")); } @@ -234,7 +261,8 @@ void ApplicationWindow::FileSave(void) } drawing->dirty = false; - setWindowTitle(QString("Architektonas - %1").arg(documentName)); +// setWindowTitle(QString("Architektonas - %1").arg(documentName)); + AdjustMRU(documentName); statusBar()->showMessage(tr("Drawing saved.")); } @@ -264,23 +292,86 @@ void ApplicationWindow::HandlePrintRequest(QPrinter * printer) QPainter qtPainter(printer); Painter painter(&qtPainter); + // Save vars for screen + Point originSave = Global::origin; + double zoomSave = Global::zoom; + Vector screenSizeSave = Global::screenSize; + + // Adjust zoom + origin to fit the paper (or NxM pages if we have 'em) + Rect r = drawing->GetObjectExtents((Object *)(&(drawing->document))); + + QPageLayout pageLayout = printer->pageLayout(); + QRect pageRect = pageLayout.paintRectPixels(printer->resolution()); + + Global::origin = r.BottomLeft(); + Global::screenSize.x = pageRect.width(); + Global::screenSize.y = pageRect.height(); + + double xScale = (double)pageRect.width() / r.Width(); + double yScale = (double)pageRect.height() / r.Height(); + Global::zoom = qMin(xScale, yScale); + + if (xScale < yScale) + Global::origin.y -= (((double)pageRect.height() / Global::zoom) - r.Height()) / 2.0; + else + Global::origin.x -= (((double)pageRect.width() / Global::zoom) - r.Width()) / 2.0; + // Do object rendering... for(int i=0; iRenderObjects(&painter, drawing->document.objects, i); - } + + // Restore vars + Global::origin = originSave; + Global::zoom = zoomSave; + Global::screenSize = screenSizeSave; } +// +// Right-click menu +// void ApplicationWindow::contextMenuEvent(QContextMenuEvent * event) { + // Proof of concept, still need to code up the real thing QMenu menu(this); + + VPVector hovered = drawing->GetHovered(); + + if ((drawing->select.size() > 0) || (hovered.size() > 0)) + { + QMenu * layerMenu = menu.addMenu("To layer"); + + layerAct.clear(); + + for(int i=0; isetData(i); + layerMenu->addAction(act); + layerAct.append(act); + connect(act, SIGNAL(triggered()), this, SLOT(MoveToLayer())); + } + } + menu.addAction(mirrorAct); menu.addAction(rotateAct); menu.addAction(trimAct); menu.exec(event->globalPos()); } +void ApplicationWindow::MoveToLayer(void) +{ + QAction * act = qobject_cast(sender()); + + drawing->MoveSelectedToLayer(act->data().toInt()); + drawing->update(); +} + +void ApplicationWindow::UpdateFromCommand(void) +{ + cw->SetToolPrompt(); + drawing->update(); +} + void ApplicationWindow::SnapToGridTool(void) { Global::snapToGrid = snapToGridAct->isChecked(); @@ -300,7 +391,6 @@ void ApplicationWindow::DeleteTool(void) { // For this tool, we check first to see if anything is selected. If so, we // delete those and *don't* select the delete tool. -// if (drawing->numSelected > 0) if (drawing->select.size() > 0) { DeleteSelectedObjects(drawing->document.objects); @@ -312,6 +402,7 @@ void ApplicationWindow::DeleteTool(void) // Otherwise, toggle the state of the tool ClearUIToolStatesExcept(deleteAct); SetInternalToolStates(); + Global::toolSuppressCrosshair = true; } void ApplicationWindow::DimensionTool(void) @@ -346,6 +437,14 @@ void ApplicationWindow::TrimTool(void) { ClearUIToolStatesExcept(trimAct); SetInternalToolStates(); + Global::toolSuppressCrosshair = true; +} + +void ApplicationWindow::ParallelTool(void) +{ + ClearUIToolStatesExcept(parallelAct); + SetInternalToolStates(); + Global::toolSuppressCrosshair = true; } void ApplicationWindow::TriangulateTool(void) @@ -439,7 +538,6 @@ void ApplicationWindow::UpdateZoom(void) else Global::gridSpacing = 0.015625; -// drawing->SetGridSize((double)(Global::gridSpacing * Global::zoom)); drawing->update(); zoomIndicator->setText(QString("Zoom: %1% Grid: %2\" BU: Inch").arg(Global::zoom * 100.0).arg(Global::gridSpacing)); @@ -453,7 +551,7 @@ void ApplicationWindow::ClearUIToolStatesExcept(QAction * exception) QAction * actionList[] = { addArcAct, addLineAct, addCircleAct, addDimensionAct, addPolygonAct, addSplineAct, deleteAct, rotateAct, mirrorAct, trimAct, - triangulateAct, 0 + triangulateAct, parallelAct, 0 }; for(int i=0; actionList[i]!=0; i++) @@ -466,9 +564,11 @@ void ApplicationWindow::ClearUIToolStatesExcept(QAction * exception) void ApplicationWindow::SetInternalToolStates(void) { // We can be sure that if we've come here, then either an active tool is - // being deactivated, or a new tool is being created. In either case, the - // old tool needs to be deleted. + // being deactivated, or a new tool is being activated. In either case, + // the tool state needs to be reset. Also, we reset the crosshair + // suppression flag. Global::toolState = TSNone; + Global::toolSuppressCrosshair = false; if (addLineAct->isChecked()) Global::tool = TTLine; @@ -490,11 +590,14 @@ void ApplicationWindow::SetInternalToolStates(void) Global::tool = TTRotate; else if (trimAct->isChecked()) Global::tool = TTTrim; + else if (parallelAct->isChecked()) + Global::tool = TTParallel; else if (triangulateAct->isChecked()) Global::tool = TTTriangulate; else Global::tool = TTNone; + cw->SetToolPrompt(); drawing->update(); } @@ -516,6 +619,25 @@ void ApplicationWindow::Settings(void) WriteSettings(); } +void ApplicationWindow::DrawingSettings(void) +{ + DrawingSettingsDlg dlg(this); + dlg.baseUnit->setCurrentIndex(drawing->document.baseUnit); + dlg.unitStyle->setCurrentIndex(drawing->document.unitStyle); + dlg.decimalPrecision->setCurrentIndex(drawing->document.decimalPrecision); + dlg.fractionalPrecision->setCurrentIndex(drawing->document.fractionalPrecision); + + if (dlg.exec() == false) + return; + + // Deal with stuff here (since user hit "OK" button...) + drawing->document.baseUnit = dlg.baseUnit->currentIndex(); + drawing->document.unitStyle = dlg.unitStyle->currentIndex(); + drawing->document.decimalPrecision= dlg.decimalPrecision->currentIndex(); + drawing->document.fractionalPrecision = dlg.fractionalPrecision->currentIndex(); + drawing->update(); +} + // // Group a bunch of selected objects (which can include other groups) together // or ungroup a selected group. @@ -671,11 +793,8 @@ void ApplicationWindow::HandleGridSizeInBaseUnits(QString text) if (!ok || value == 0) return; -// drawing->gridSpacing = value; -// Painter::zoom = drawing->gridPixels / drawing->gridSpacing; Global::gridSpacing = value; Global::zoom = drawing->gridPixels / Global::gridSpacing; -// drawing->UpdateGridBackground(); drawing->update(); } @@ -805,6 +924,9 @@ void ApplicationWindow::CreateActions(void) settingsAct = CreateAction(tr("&Settings"), tr("Settings"), tr("Change certain defaults for Architektonas."), QIcon(":/res/settings.png"), QKeySequence()); connect(settingsAct, SIGNAL(triggered()), this, SLOT(Settings())); + drawingSettingsAct = CreateAction(tr("&Drawing Settings"), tr("Drawing settings"), tr("Change certain defaults for the current drawing."), QIcon(":/res/settings.png"), QKeySequence()); + connect(drawingSettingsAct, SIGNAL(triggered()), this, SLOT(DrawingSettings())); + groupAct = CreateAction(tr("&Group"), tr("Group"), tr("Group/ungroup selected objects."), QIcon(":/res/group-tool.png"), QKeySequence("g")); connect(groupAct, SIGNAL(triggered()), this, SLOT(HandleGrouping())); @@ -820,6 +942,9 @@ void ApplicationWindow::CreateActions(void) trimAct = CreateAction(tr("&Trim"), tr("Trim"), tr("Trim extraneous lines from selected objects."), QIcon(":/res/trim-tool.png"), QKeySequence("t,r"), true); connect(trimAct, SIGNAL(triggered()), this, SLOT(TrimTool())); + parallelAct = CreateAction(tr("&Parallel"), tr("Parallel"), tr("Create copies of objects parallel to the original."), QIcon(":/res/parallel-tool.png"), QKeySequence("p,l"), true); + connect(parallelAct, SIGNAL(triggered()), this, SLOT(ParallelTool())); + triangulateAct = CreateAction(tr("&Triangulate"), tr("Triangulate"), tr("Make triangles from selected lines, preserving their lengths."), QIcon(":/res/triangulate-tool.png"), QKeySequence("t,g"), true); connect(triangulateAct, SIGNAL(triggered()), this, SLOT(TriangulateTool())); @@ -846,6 +971,14 @@ void ApplicationWindow::CreateActions(void) group->addAction(addLineAct); group->addAction(addCircleAct); group->addAction(addArcAct);//*/ + + for(int i=0; isetVisible(false); + connect(rfa, SIGNAL(triggered()), this, SLOT(FileOpenRecent())); + mruAct.append(rfa); + } } // @@ -888,6 +1021,14 @@ void ApplicationWindow::CreateMenus(void) QMenu * menu = menuBar()->addMenu(tr("&File")); menu->addAction(fileNewAct); menu->addAction(fileOpenAct); + + QMenu * recentMenu = menu->addMenu(tr("Open &Recent")); + + for(int i=0; iaddAction(mruAct.at(i)); + + UpdateMRUActionList(); + menu->addAction(fileSaveAct); menu->addAction(fileSaveAsAct); menu->addAction(fileCloseAct); @@ -908,6 +1049,7 @@ void ApplicationWindow::CreateMenus(void) menu->addAction(rotateAct); menu->addAction(mirrorAct); menu->addAction(trimAct); + menu->addAction(parallelAct); menu->addAction(triangulateAct); menu->addAction(connectAct); menu->addAction(disconnectAct); @@ -925,6 +1067,7 @@ void ApplicationWindow::CreateMenus(void) menu->addAction(addSplineAct); menu->addAction(addDimensionAct); menu->addSeparator(); + menu->addAction(drawingSettingsAct); menu->addAction(settingsAct); menu = menuBar()->addMenu(tr("&Help")); @@ -940,7 +1083,6 @@ void ApplicationWindow::CreateToolbars(void) toolbar->addAction(fileSaveAct); toolbar->addAction(fileSaveAsAct); toolbar->addAction(fileCloseAct); -// toolbar->addAction(exitAct); toolbar = addToolBar(tr("View")); toolbar->setObjectName("View"); @@ -949,7 +1091,6 @@ void ApplicationWindow::CreateToolbars(void) QSpinBox * spinbox = new QSpinBox; toolbar->addWidget(spinbox); -// QLineEdit * lineedit = new QLineEdit; toolbar->addWidget(baseUnitInput); toolbar->addWidget(dimensionSizeInput); @@ -962,6 +1103,7 @@ void ApplicationWindow::CreateToolbars(void) toolbar->addAction(rotateAct); toolbar->addAction(mirrorAct); toolbar->addAction(trimAct); + toolbar->addAction(parallelAct); toolbar->addAction(triangulateAct); toolbar->addAction(editCutAct); toolbar->addAction(editCopyAct); @@ -989,10 +1131,6 @@ void ApplicationWindow::CreateToolbars(void) toolbar->setObjectName(tr("Pen")); toolbar->addWidget(pw); connect(drawing, SIGNAL(ObjectSelected(Object *)), pw, SLOT(SetFields(Object *))); - connect(pw, SIGNAL(WidthSelected(float)), drawing, SLOT(HandlePenWidth(float))); - connect(pw, SIGNAL(StyleSelected(int)), drawing, SLOT(HandlePenStyle(int))); - connect(pw, SIGNAL(ColorSelected(uint32_t)), drawing, SLOT(HandlePenColor(uint32_t))); -// connect(pw, SIGNAL(StampSelected(void)), drawing, SLOT(HandlePenStamp(QAction *))); connect(pw->tbStamp, SIGNAL(triggered(QAction *)), drawing, SLOT(HandlePenStamp(QAction *))); connect(pw->tbDropper, SIGNAL(triggered(QAction *)), drawing, SLOT(HandlePenDropper(QAction *))); } @@ -1016,3 +1154,38 @@ void ApplicationWindow::WriteSettings(void) settings.setValue("useAntialiasing", drawing->useAntialiasing); settings.setValue("snapToGrid", snapToGridAct->isChecked()); } + +void ApplicationWindow::UpdateMRUActionList(void) +{ + QStringList mruFilePaths = settings.value("recentFiles").toStringList(); + + int mruSize = (mruFilePaths.size() <= MRU_MAX ? mruFilePaths.size() : MRU_MAX); + + for(int i=0; isetText(filename); + mruAct.at(i)->setData(mruFilePaths.at(i)); + mruAct.at(i)->setVisible(true); + } + + for(int i=mruSize; isetVisible(false); +} + +void ApplicationWindow::AdjustMRU(const QString & filePath) +{ + documentName = filePath; + setWindowFilePath(documentName); + + QStringList mruFilePaths = settings.value("recentFiles").toStringList(); + mruFilePaths.removeAll(filePath); + mruFilePaths.prepend(filePath); + + while (mruFilePaths.size() > MRU_MAX) + mruFilePaths.removeLast(); + + settings.setValue("recentFiles", mruFilePaths); + + UpdateMRUActionList(); +}