X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fapplicationwindow.cpp;fp=src%2Fapplicationwindow.cpp;h=47f8149634a40942d86940167bb6afbd7b1eed86;hb=fce575a51ba1f26418869c20e63b9f388e118ab6;hp=2f78dfc61a6f92ac53229faba2091adea2ac1847;hpb=5d8c9e52606315fbfe857f2715b8f051b4f97491;p=architektonas diff --git a/src/applicationwindow.cpp b/src/applicationwindow.cpp index 2f78dfc..47f8149 100644 --- a/src/applicationwindow.cpp +++ b/src/applicationwindow.cpp @@ -59,10 +59,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(); @@ -98,6 +96,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); @@ -166,6 +166,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) @@ -192,7 +207,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(); @@ -203,7 +217,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.")); } @@ -241,7 +256,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.")); } @@ -305,16 +321,46 @@ void ApplicationWindow::HandlePrintRequest(QPrinter * printer) 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::SnapToGridTool(void) { Global::snapToGrid = snapToGridAct->isChecked(); @@ -334,7 +380,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); @@ -346,6 +391,7 @@ void ApplicationWindow::DeleteTool(void) // Otherwise, toggle the state of the tool ClearUIToolStatesExcept(deleteAct); SetInternalToolStates(); + Global::toolSuppressCrosshair = true; } void ApplicationWindow::DimensionTool(void) @@ -380,6 +426,7 @@ void ApplicationWindow::TrimTool(void) { ClearUIToolStatesExcept(trimAct); SetInternalToolStates(); + Global::toolSuppressCrosshair = true; } void ApplicationWindow::ParallelTool(void) @@ -479,7 +526,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)); @@ -506,9 +552,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; @@ -713,11 +761,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(); } @@ -891,6 +936,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); + } } // @@ -933,6 +986,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); @@ -986,7 +1047,6 @@ void ApplicationWindow::CreateToolbars(void) toolbar->addAction(fileSaveAct); toolbar->addAction(fileSaveAsAct); toolbar->addAction(fileCloseAct); -// toolbar->addAction(exitAct); toolbar = addToolBar(tr("View")); toolbar->setObjectName("View"); @@ -995,7 +1055,6 @@ void ApplicationWindow::CreateToolbars(void) QSpinBox * spinbox = new QSpinBox; toolbar->addWidget(spinbox); -// QLineEdit * lineedit = new QLineEdit; toolbar->addWidget(baseUnitInput); toolbar->addWidget(dimensionSizeInput); @@ -1039,7 +1098,6 @@ void ApplicationWindow::CreateToolbars(void) 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 *))); } @@ -1063,3 +1121,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(); +}