]> Shamusworld >> Repos - architektonas/blobdiff - src/applicationwindow.cpp
Miscellaneous fixes/updates:
[architektonas] / src / applicationwindow.cpp
index 4c765cbc4e4e507b2248124b4be7ecf456e52ac4..2f78dfc61a6f92ac53229faba2091adea2ac1847 100644 (file)
@@ -31,6 +31,7 @@
 #include <QPrintPreviewDialog>
 #include "about.h"
 #include "blockwidget.h"
+#include "consolewidget.h"
 #include "drawingview.h"
 #include "fileio.h"
 #include "generaltab.h"
@@ -80,10 +81,16 @@ ApplicationWindow::ApplicationWindow():
        ObjectWidget * ow = new ObjectWidget;
        dock3->setWidget(ow);
        addDockWidget(Qt::RightDockWidgetArea, dock3);
+       QDockWidget * dock4 = new QDockWidget(tr("Command"), this);
+       ConsoleWidget * 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");
@@ -264,16 +271,43 @@ 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; 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;
 }
 
 void ApplicationWindow::contextMenuEvent(QContextMenuEvent * event)
 {
+       // Proof of concept, still need to code up the real thing
        QMenu menu(this);
        menu.addAction(mirrorAct);
        menu.addAction(rotateAct);
@@ -348,6 +382,12 @@ void ApplicationWindow::TrimTool(void)
        SetInternalToolStates();
 }
 
+void ApplicationWindow::ParallelTool(void)
+{
+       ClearUIToolStatesExcept(parallelAct);
+       SetInternalToolStates();
+}
+
 void ApplicationWindow::TriangulateTool(void)
 {
        ClearUIToolStatesExcept(triangulateAct);
@@ -490,6 +530,8 @@ 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
@@ -820,6 +862,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,a"), 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()));
 
@@ -908,6 +953,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);
@@ -962,6 +1008,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);