#include <QPrintPreviewDialog>
#include "about.h"
#include "blockwidget.h"
+#include "commandprocessor.h"
+#include "consolewidget.h"
#include "drawingview.h"
#include "fileio.h"
#include "generaltab.h"
aboutWin = new AboutWindow(this);
-// ((TTEdit *)qApp)->charWnd = new CharWindow(this);
-
setWindowIcon(QIcon(":/res/atns-icon.png"));
- setWindowTitle("Architektonas");
+// setWindowTitle("Architektonas");
CreateActions();
CreateMenus();
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");
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);
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)
drawing->dirty = false;
drawing->update();
documentName.clear();
- setWindowTitle("Architektonas - Untitled");
+// setWindowTitle("Architektonas - Untitled");
+ setWindowFilePath(documentName);
statusBar()->showMessage(tr("New drawing is ready."));
}
if (filename.isEmpty())
return;
+ LoadFile(filename);
+}
+
+void ApplicationWindow::FileOpenRecent(void)
+{
+ QAction * action = qobject_cast<QAction *>(sender());
+
+ if (!action)
+ return;
+
+ LoadFile(action->data().toString());
+}
+
+void ApplicationWindow::LoadFile(QString filename)
+{
FILE * file = fopen(filename.toUtf8().data(), "r");
if (file == 0)
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();
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."));
}
}
drawing->dirty = false;
- setWindowTitle(QString("Architektonas - %1").arg(documentName));
+// setWindowTitle(QString("Architektonas - %1").arg(documentName));
+ AdjustMRU(documentName);
statusBar()->showMessage(tr("Drawing saved."));
}
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; i<Global::numLayers; i++)
- {
-// if (Global::layerHidden[i] == false)
drawing->RenderObjects(&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; i<Global::numLayers; i++)
+ {
+ QAction * act = new QAction(QIcon(), Global::layerName[i].c_str(), this);
+ act->setData(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<QAction *>(sender());
+
+ drawing->MoveSelectedToLayer(act->data().toInt());
+ drawing->update();
+}
+
+void ApplicationWindow::UpdateFromCommand(void)
+{
+ cw->SetToolPrompt();
+ drawing->update();
+}
+
void ApplicationWindow::SnapToGridTool(void)
{
Global::snapToGrid = snapToGridAct->isChecked();
{
// 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);
// Otherwise, toggle the state of the tool
ClearUIToolStatesExcept(deleteAct);
SetInternalToolStates();
+ Global::toolSuppressCrosshair = true;
}
void ApplicationWindow::DimensionTool(void)
{
ClearUIToolStatesExcept(trimAct);
SetInternalToolStates();
+ Global::toolSuppressCrosshair = true;
+}
+
+void ApplicationWindow::ParallelTool(void)
+{
+ ClearUIToolStatesExcept(parallelAct);
+ SetInternalToolStates();
+ Global::toolSuppressCrosshair = true;
}
void ApplicationWindow::TriangulateTool(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));
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++)
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;
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();//cw->cmdline);
drawing->update();
}
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();
}
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()));
group->addAction(addLineAct);
group->addAction(addCircleAct);
group->addAction(addArcAct);//*/
+
+ for(int i=0; i<MRU_MAX; i++)
+ {
+ QAction * rfa = new QAction(this);
+ rfa->setVisible(false);
+ connect(rfa, SIGNAL(triggered()), this, SLOT(FileOpenRecent()));
+ mruAct.append(rfa);
+ }
}
//
QMenu * menu = menuBar()->addMenu(tr("&File"));
menu->addAction(fileNewAct);
menu->addAction(fileOpenAct);
+
+ QMenu * recentMenu = menu->addMenu(tr("Open &Recent"));
+
+ for(int i=0; i<MRU_MAX; i++)
+ recentMenu->addAction(mruAct.at(i));
+
+ UpdateMRUActionList();
+
menu->addAction(fileSaveAct);
menu->addAction(fileSaveAsAct);
menu->addAction(fileCloseAct);
menu->addAction(rotateAct);
menu->addAction(mirrorAct);
menu->addAction(trimAct);
+ menu->addAction(parallelAct);
menu->addAction(triangulateAct);
menu->addAction(connectAct);
menu->addAction(disconnectAct);
toolbar->addAction(fileSaveAct);
toolbar->addAction(fileSaveAsAct);
toolbar->addAction(fileCloseAct);
-// toolbar->addAction(exitAct);
toolbar = addToolBar(tr("View"));
toolbar->setObjectName("View");
QSpinBox * spinbox = new QSpinBox;
toolbar->addWidget(spinbox);
-// QLineEdit * lineedit = new QLineEdit;
toolbar->addWidget(baseUnitInput);
toolbar->addWidget(dimensionSizeInput);
toolbar->addAction(rotateAct);
toolbar->addAction(mirrorAct);
toolbar->addAction(trimAct);
+ toolbar->addAction(parallelAct);
toolbar->addAction(triangulateAct);
toolbar->addAction(editCutAct);
toolbar->addAction(editCopyAct);
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 *)));
}
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; i<mruSize; i++)
+ {
+ QString filename = QFileInfo(mruFilePaths.at(i)).fileName();
+ mruAct.at(i)->setText(filename);
+ mruAct.at(i)->setData(mruFilePaths.at(i));
+ mruAct.at(i)->setVisible(true);
+ }
+
+ for(int i=mruSize; i<MRU_MAX; i++)
+ mruAct.at(i)->setVisible(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();
+}