]> Shamusworld >> Repos - architektonas/commitdiff
Added pen and dropper tools, and printing support.
authorShamus Hammons <jlhamm@acm.org>
Sun, 11 Apr 2021 14:31:28 +0000 (09:31 -0500)
committerShamus Hammons <jlhamm@acm.org>
Sun, 11 Apr 2021 14:31:28 +0000 (09:31 -0500)
Currently, print preview is wonky in that you can't control where on the
page the drawing will go.  Also the pen and dropper tools work fairly
well except on objects in containers, where they don't work at all.  :-/

19 files changed:
TODO
architektonas.pro
res/architektonas.qrc
res/cursor-dropper.png [new file with mode: 0644]
res/cursor-marker.png [new file with mode: 0644]
res/pen-dropper.png [new file with mode: 0644]
res/print-preview.png [new file with mode: 0644]
src/applicationwindow.cpp
src/applicationwindow.h
src/drawingview.cpp
src/drawingview.h
src/global.cpp
src/global.h
src/layerwidget.cpp
src/painter.cpp
src/painter.h
src/penwidget.cpp
src/penwidget.h
src/utils.cpp

diff --git a/TODO b/TODO
index 440943875dc5ed738d82c7bbc7ec5e293d704fc8..eb6bfb82cc11c8ea1483817afd34301550ae21a2 100644 (file)
--- a/TODO
+++ b/TODO
@@ -11,7 +11,6 @@ Stuff To Be Implemented/Fixed
  - Add blocks
  - Add page layout
  - Add fill/hatch to Objects
- - Fix zooming to be more intuitive
  - Add other Dimension types, like radial, diametric, leader
  - Restrict movement horizontal/vertical tool (keyboard shortcut?)
  - Fix Arc manipulator. Idea: split edge handles so that the inner half controls
@@ -23,11 +22,13 @@ Stuff To Be Implemented/Fixed
    remove it and it only, or to cut the entity at other entities crossing)
  - Make Architektonas an MDI application
  - Parallel tool (be able to make copy of object that's parallel to original)
+ - Pen marker doesn't set attributes on the highlighted part of the group.
 
 
 Stuff That's Done
 -----------------
 
+ - Fix zooming to be more intuitive [Shamus 2021]
  - Group selection (kinda done, needs more work though) [Shamus 2020]
  - Take movement code out of Objects and put it into top level Container
    (actually I think this should be more of the state code handling. Have to
@@ -46,3 +47,8 @@ Stuff That's Done
  - Mirror tool (started, needs actual mirroring implementation) (Rotate tool is
    also done :-D) [Shamus 2013-09-01]
 
+
+Things to Ponder
+----------------
+
+Grouping items on different layers currently makes the items *not* on the current layer disappear.  Not sure how this should be handled...  Maybe we should honor the top level Container's attributes, and not the attributes of the contained objects?
index 4375488b723ae70bb20659bebc3ddd6630551527..2af6bc767fcc62ad03e1cc04dc5006ab6f7f3e31 100644 (file)
@@ -11,7 +11,7 @@ CONFIG    += qt warn_on release debug
 #CONFIG    += qt warn_on release
 RESOURCES += res/architektonas.qrc
 #LIBS      += -Ldxflib/lib -ldxf
-QT        += widgets
+QT        += widgets printsupport
 
 # We stuff all the intermediate crap into obj/ so it won't confuse us mere mortals ;-)
 OBJECTS_DIR = obj
index a0ae553999d197cc6e6707c4b1d7f06ebbcd3c17..0929bebab1e634943143739dd4461d82be2021c9 100644 (file)
@@ -44,5 +44,9 @@
                <file>editcopy2.png</file>
                <file>editpaste2.png</file>
                <file>pen-stamp.png</file>
+               <file>pen-dropper.png</file>
+               <file>cursor-marker.png</file>
+               <file>cursor-dropper.png</file>
+               <file>print-preview.png</file>
        </qresource>
 </RCC>
diff --git a/res/cursor-dropper.png b/res/cursor-dropper.png
new file mode 100644 (file)
index 0000000..26acf12
Binary files /dev/null and b/res/cursor-dropper.png differ
diff --git a/res/cursor-marker.png b/res/cursor-marker.png
new file mode 100644 (file)
index 0000000..175ff49
Binary files /dev/null and b/res/cursor-marker.png differ
diff --git a/res/pen-dropper.png b/res/pen-dropper.png
new file mode 100644 (file)
index 0000000..2519689
Binary files /dev/null and b/res/pen-dropper.png differ
diff --git a/res/print-preview.png b/res/print-preview.png
new file mode 100644 (file)
index 0000000..8dbba80
Binary files /dev/null and b/res/print-preview.png differ
index 773146fa63348865180b5159d56e0e785231313f..4c765cbc4e4e507b2248124b4be7ecf456e52ac4 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "applicationwindow.h"
 
+#include <QPrintPreviewDialog>
 #include "about.h"
 #include "blockwidget.h"
 #include "drawingview.h"
 #include "structs.h"
 #include "utils.h"
 
-
 // Class variables
 DrawingView * ApplicationWindow::drawing;
 
-
 ApplicationWindow::ApplicationWindow():
        baseUnitInput(new QLineEdit),
        dimensionSizeInput(new QLineEdit),
@@ -104,7 +103,6 @@ ApplicationWindow::ApplicationWindow():
        connect(drawing, SIGNAL(NeedZoomUpdate()), this, SLOT(UpdateZoom()));
 }
 
-
 void ApplicationWindow::closeEvent(QCloseEvent * event)
 {
        WriteSettings();
@@ -112,7 +110,6 @@ void ApplicationWindow::closeEvent(QCloseEvent * event)
        //Do we have a memory leak here if we don't delete the font in the Object???
 }
 
-
 void ApplicationWindow::FileNew(void)
 {
        // Warn the user if drawing has changed and hasn't been saved...
@@ -153,7 +150,6 @@ void ApplicationWindow::FileNew(void)
        statusBar()->showMessage(tr("New drawing is ready."));
 }
 
-
 void ApplicationWindow::FileOpen(void)
 {
        QString filename = QFileDialog::getOpenFileName(this, tr("Open Drawing"),
@@ -204,7 +200,6 @@ void ApplicationWindow::FileOpen(void)
        statusBar()->showMessage(tr("Drawing loaded."));
 }
 
-
 void ApplicationWindow::FileSave(void)
 {
        if (documentName.isEmpty())
@@ -243,7 +238,6 @@ void ApplicationWindow::FileSave(void)
        statusBar()->showMessage(tr("Drawing saved."));
 }
 
-
 void ApplicationWindow::FileSaveAs(void)
 {
        QString filename = QFileDialog::getSaveFileName(this, tr("Save Drawing As"),
@@ -256,6 +250,27 @@ void ApplicationWindow::FileSaveAs(void)
        }
 }
 
+void ApplicationWindow::PrintPreview(void)
+{
+       QPrintPreviewDialog * dlg = new QPrintPreviewDialog(this);
+
+       connect(dlg, SIGNAL(paintRequested(QPrinter *)), this, SLOT(HandlePrintRequest(QPrinter *)));
+
+       dlg->exec();
+}
+
+void ApplicationWindow::HandlePrintRequest(QPrinter * printer)
+{
+       QPainter qtPainter(printer);
+       Painter painter(&qtPainter);
+
+       // Do object rendering...
+       for(int i=0; i<Global::numLayers; i++)
+       {
+//             if (Global::layerHidden[i] == false)
+               drawing->RenderObjects(&painter, drawing->document.objects, i);
+       }
+}
 
 void ApplicationWindow::contextMenuEvent(QContextMenuEvent * event)
 {
@@ -266,25 +281,21 @@ void ApplicationWindow::contextMenuEvent(QContextMenuEvent * event)
        menu.exec(event->globalPos());
 }
 
-
 void ApplicationWindow::SnapToGridTool(void)
 {
        Global::snapToGrid = snapToGridAct->isChecked();
 }
 
-
 void ApplicationWindow::FixAngle(void)
 {
        Global::fixedAngle = fixAngleAct->isChecked();
 }
 
-
 void ApplicationWindow::FixLength(void)
 {
        Global::fixedLength = fixLengthAct->isChecked();
 }
 
-
 void ApplicationWindow::DeleteTool(void)
 {
        // For this tool, we check first to see if anything is selected. If so, we
@@ -303,14 +314,12 @@ void ApplicationWindow::DeleteTool(void)
        SetInternalToolStates();
 }
 
-
 void ApplicationWindow::DimensionTool(void)
 {
        ClearUIToolStatesExcept(addDimensionAct);
        SetInternalToolStates();
 }
 
-
 void ApplicationWindow::RotateTool(void)
 {
        ClearUIToolStatesExcept(rotateAct);
@@ -322,7 +331,6 @@ void ApplicationWindow::RotateTool(void)
        SetInternalToolStates();
 }
 
-
 void ApplicationWindow::MirrorTool(void)
 {
        ClearUIToolStatesExcept(mirrorAct);
@@ -334,56 +342,48 @@ void ApplicationWindow::MirrorTool(void)
        SetInternalToolStates();
 }
 
-
 void ApplicationWindow::TrimTool(void)
 {
        ClearUIToolStatesExcept(trimAct);
        SetInternalToolStates();
 }
 
-
 void ApplicationWindow::TriangulateTool(void)
 {
        ClearUIToolStatesExcept(triangulateAct);
        SetInternalToolStates();
 }
 
-
 void ApplicationWindow::AddLineTool(void)
 {
        ClearUIToolStatesExcept(addLineAct);
        SetInternalToolStates();
 }
 
-
 void ApplicationWindow::AddCircleTool(void)
 {
        ClearUIToolStatesExcept(addCircleAct);
        SetInternalToolStates();
 }
 
-
 void ApplicationWindow::AddArcTool(void)
 {
        ClearUIToolStatesExcept(addArcAct);
        SetInternalToolStates();
 }
 
-
 void ApplicationWindow::AddPolygonTool(void)
 {
        ClearUIToolStatesExcept(addPolygonAct);
        SetInternalToolStates();
 }
 
-
 void ApplicationWindow::AddSplineTool(void)
 {
        ClearUIToolStatesExcept(addSplineAct);
        SetInternalToolStates();
 }
 
-
 void ApplicationWindow::ZoomInTool(void)
 {
        double zoomFactor = 1.20;
@@ -396,7 +396,6 @@ void ApplicationWindow::ZoomInTool(void)
        UpdateZoom();
 }
 
-
 void ApplicationWindow::ZoomOutTool(void)
 {
        double zoomFactor = 1.20;
@@ -409,7 +408,6 @@ void ApplicationWindow::ZoomOutTool(void)
        UpdateZoom();
 }
 
-
 void ApplicationWindow::UpdateZoom(void)
 {
        // And now, a bunch of heuristics to select the right grid size--autogrid!
@@ -441,7 +439,7 @@ void ApplicationWindow::UpdateZoom(void)
        else
                Global::gridSpacing = 0.015625;
 
-       drawing->SetGridSize((double)(Global::gridSpacing * Global::zoom));
+//     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));
@@ -450,7 +448,6 @@ void ApplicationWindow::UpdateZoom(void)
 //     baseUnitInput->setText(QString("%1").arg(Global::gridSpacing));
 }
 
-
 void ApplicationWindow::ClearUIToolStatesExcept(QAction * exception)
 {
        QAction * actionList[] = {
@@ -466,7 +463,6 @@ 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
@@ -502,13 +498,11 @@ void ApplicationWindow::SetInternalToolStates(void)
        drawing->update();
 }
 
-
 void ApplicationWindow::HelpAbout(void)
 {
        aboutWin->show();
 }
 
-
 void ApplicationWindow::Settings(void)
 {
        SettingsDialog dlg(this);
@@ -522,7 +516,6 @@ void ApplicationWindow::Settings(void)
        WriteSettings();
 }
 
-
 //
 // Group a bunch of selected objects (which can include other groups) together
 // or ungroup a selected group.
@@ -589,7 +582,6 @@ void ApplicationWindow::HandleGrouping(void)
        drawing->update();
 }
 
-
 void ApplicationWindow::HandleConnection(void)
 {
 #if 0
@@ -659,19 +651,16 @@ printf("   -> intersects = %i, t=%lf, u=%lf\n", intersects, t, u);
 #endif
 }
 
-
 void ApplicationWindow::HandleDisconnection(void)
 {
 }
 
-
-void ApplicationWindow::HandleGridSizeInPixels(int size)
+void ApplicationWindow::HandleGridSizeInPixels(int /*size*/)
 {
-       drawing->SetGridSize((uint32_t)size);
+//     drawing->SetGridSize((uint32_t)size);
        drawing->update();
 }
 
-
 void ApplicationWindow::HandleGridSizeInBaseUnits(QString text)
 {
        // Parse the text...
@@ -686,11 +675,10 @@ void ApplicationWindow::HandleGridSizeInBaseUnits(QString text)
 //     Painter::zoom = drawing->gridPixels / drawing->gridSpacing;
        Global::gridSpacing = value;
        Global::zoom = drawing->gridPixels / Global::gridSpacing;
-       drawing->UpdateGridBackground();
+//     drawing->UpdateGridBackground();
        drawing->update();
 }
 
-
 void ApplicationWindow::HandleDimensionSize(QString text)
 {
 /*
@@ -717,7 +705,6 @@ void ApplicationWindow::EditCopy(void)
        }
 }
 
-
 void ApplicationWindow::EditCut(void)
 {
        if (drawing->select.size() > 0)
@@ -728,7 +715,6 @@ void ApplicationWindow::EditCut(void)
        }
 }
 
-
 void ApplicationWindow::EditPaste(void)
 {
        if (clipboard.size() > 0)
@@ -741,7 +727,6 @@ void ApplicationWindow::EditPaste(void)
        }
 }
 
-
 //
 // Select all *visible* objects.  If an object is on a layer that is not
 // visible, skip it.
@@ -753,7 +738,6 @@ void ApplicationWindow::SelectAllObjects(void)
        drawing->update();
 }
 
-
 void ApplicationWindow::CreateActions(void)
 {
        exitAct = CreateAction(tr("&Quit"), tr("Quit"), tr("Exits the application."),
@@ -851,6 +835,9 @@ void ApplicationWindow::CreateActions(void)
        selectAllAct = CreateAction(tr("Select &All"), tr("Select All Objects"), tr("Select all objects in the drawing."), QIcon(), QKeySequence(tr("Ctrl+a")));
        connect(selectAllAct, SIGNAL(triggered()), this, SLOT(SelectAllObjects()));
 
+       printPreviewAct = CreateAction(tr("&Print Preview"), tr("Print Preview"), tr("Shows preview of printing operation."), QIcon(":/res/print-preview.png"), QKeySequence(tr("Ctrl+p")));
+       connect(printPreviewAct, SIGNAL(triggered()), this, SLOT(PrintPreview()));
+
 //Hm. I think we'll have to have separate logic to do the "Radio Group Toolbar" thing...
 // Yup, in order to turn them off, we'd have to have an "OFF" toolbar button. Ick.
 /*     QActionGroup * group = new QActionGroup(this);
@@ -861,7 +848,6 @@ void ApplicationWindow::CreateActions(void)
        group->addAction(addArcAct);//*/
 }
 
-
 //
 // Consolidates action creation from a multi-step process to a single-step one.
 //
@@ -877,7 +863,6 @@ QAction * ApplicationWindow::CreateAction(QString name, QString tooltip,
        return action;
 }
 
-
 //
 // This is essentially the same as the previous function, but this allows more
 // than one key sequence to be added as key shortcuts.
@@ -898,7 +883,6 @@ QAction * ApplicationWindow::CreateAction(QString name, QString tooltip,
        return action;
 }
 
-
 void ApplicationWindow::CreateMenus(void)
 {
        QMenu * menu = menuBar()->addMenu(tr("&File"));
@@ -908,6 +892,8 @@ void ApplicationWindow::CreateMenus(void)
        menu->addAction(fileSaveAsAct);
        menu->addAction(fileCloseAct);
        menu->addSeparator();
+       menu->addAction(printPreviewAct);
+       menu->addSeparator();
        menu->addAction(exitAct);
 
        menu = menuBar()->addMenu(tr("&View"));
@@ -945,7 +931,6 @@ void ApplicationWindow::CreateMenus(void)
        menu->addAction(aboutAct);
 }
 
-
 void ApplicationWindow::CreateToolbars(void)
 {
        QToolBar * toolbar = addToolBar(tr("File"));
@@ -1007,10 +992,11 @@ 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(void)));
+//     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 *)));
 }
 
-
 void ApplicationWindow::ReadSettings(void)
 {
        QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
@@ -1022,7 +1008,6 @@ void ApplicationWindow::ReadSettings(void)
        restoreState(settings.value("windowState").toByteArray());
 }
 
-
 void ApplicationWindow::WriteSettings(void)
 {
        settings.setValue("pos", pos());
@@ -1031,4 +1016,3 @@ void ApplicationWindow::WriteSettings(void)
        settings.setValue("useAntialiasing", drawing->useAntialiasing);
        settings.setValue("snapToGrid", snapToGridAct->isChecked());
 }
-
index f35ba1c2ca0270cde3465597b53c641fa1933afb..00c79178601c974c66075d9e1082fa06af97ee59 100644 (file)
@@ -2,6 +2,7 @@
 #define __APPLICATIONWINDOW_H__
 
 #include <QtWidgets>
+#include <QPrinter>
 
 // Forward declarations
 
@@ -26,6 +27,8 @@ class ApplicationWindow: public QMainWindow
                void FileOpen(void);
                void FileSave(void);
                void FileSaveAs(void);
+               void PrintPreview(void);
+               void HandlePrintRequest(QPrinter *);
                void SnapToGridTool(void);
                void FixAngle(void);
                void FixLength(void);
@@ -111,6 +114,7 @@ class ApplicationWindow: public QMainWindow
                QAction * editCopyAct;
                QAction * editPasteAct;
                QAction * selectAllAct;
+               QAction * printPreviewAct;
 
                std::vector<void *> clipboard;
 
index 048eb721b94a18166411bcedb60ae322ca013499..5b0eeeef6b214c5d4ef4b67f8f87b6af9c2c195c 100644 (file)
 #include "global.h"
 #include "mathconstants.h"
 #include "painter.h"
+#include "penwidget.h"
 #include "structs.h"
 #include "utils.h"
 
-
 #define BACKGROUND_MAX_SIZE    512
 
-
 DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        // The value in the settings file will override this.
        useAntialiasing(true), numHovered(0), shiftDown(false),
        ctrlDown(false), altDown(false),
        gridBackground(BACKGROUND_MAX_SIZE, BACKGROUND_MAX_SIZE),
-       scale(1.0), offsetX(-10), offsetY(-10), document(true),
+       scale(1.0), offsetX(-10), offsetY(-10), supressSelected(false),
+       document(true),
        gridPixels(0), collided(false), scrollDrag(false), hoverPointValid(false),
        hoveringIntersection(false), dragged(NULL), draggingObject(false),
        angleSnap(false), dirty(false)
@@ -60,6 +60,9 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        setBackgroundRole(QPalette::Base);
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
+       curMarker = QCursor(QPixmap(":/res/cursor-marker.png"), 1, 18);
+       curDropper = QCursor(QPixmap(":/res/cursor-dropper.png"), 1, 20);
+
        Global::gridSpacing = 12.0;             // In base units (inch is default)
 
        Line * line = new Line(Vector(5, 5), Vector(50, 40), 2.0, 0xFF7F00, LSDash);
@@ -120,11 +123,10 @@ need a thickness parameter similar to the "size" param for dimensions. (And now
 we do! :-)
 
 */
-       gridPixels = 12; //tmp
-       SetGridSize(12.0);      // This is in pixels
+//     gridPixels = 12; //tmp???
+//     SetGridSize(12.0);      // This is in pixels
 }
 
-
 void DrawingView::DrawBackground(Painter * painter)
 {
        Point ul = Painter::QtToCartesianCoords(Vector(0, 0));
@@ -174,7 +176,6 @@ void DrawingView::DrawBackground(Painter * painter)
                painter->DrawHLine(bottomy + i);
 }
 
-
 void DrawingView::DrawSubGrid(Painter * painter, uint32_t color, double step, Vector start, Vector size)
 {
        painter->SetPen(color, 1, 1);
@@ -186,7 +187,7 @@ void DrawingView::DrawSubGrid(Painter * painter, uint32_t color, double step, Ve
                painter->DrawHLine(start.y + i);
 }
 
-
+#if 0
 void DrawingView::SetGridSize(uint32_t size)
 {
 #if 0
@@ -219,7 +220,6 @@ void DrawingView::SetGridSize(uint32_t size)
 #endif
 }
 
-
 void DrawingView::UpdateGridBackground(void)
 {
 #if 0
@@ -300,7 +300,6 @@ zero; so we do another modulus operation on the result to achieve this.
 #endif
 }
 
-
 void DrawingView::SetGridSize(double size)
 {
 #if 0
@@ -362,7 +361,7 @@ void DrawingView::UpdateGridBackgroundF(void)
        setPalette(pal);
 #endif
 }
-
+#endif
 
 //
 // Basically, we just make a single pass through the Container. If the layer #
@@ -398,23 +397,28 @@ void DrawingView::DeleteCurrentLayer(int layer)
        update();
 }
 
-
 void DrawingView::HandleLayerToggle(void)
 {
        // A layer's visibility was toggled, so update the screen...
        update();
 }
 
-
 //
 // A layer was moved up or down in the layer list, so we have to swap the
 // document's object's layer numbers in the layers that were swapped.
 //
 void DrawingView::HandleLayerSwap(int layer1, int layer2)
 {
-// !!! FIX !!! This doesn't properly handle container contents...
 //printf("DrawingView: Swapping layers %i and %i.\n", layer1, layer2);
-       for(VPVectorIter i=document.objects.begin(); i!=document.objects.end(); i++)
+       HandleLayerSwap(layer1, layer2, document.objects);
+}
+
+/*
+We can roll this into the main one above, by having the LayerWidget's emit() call sending NULL for the VPVector, which we can test for and set to document.objects to grab the top layer.  Or, keep it a top level call and a recursive call.  Which is worse?  :-P
+*/
+void DrawingView::HandleLayerSwap(int layer1, int layer2, VPVector & v)
+{
+       for(VPVectorIter i=v.begin(); i!=v.end(); i++)
        {
                Object * obj = (Object *)(*i);
 
@@ -422,10 +426,12 @@ void DrawingView::HandleLayerSwap(int layer1, int layer2)
                        obj->layer = layer2;
                else if (obj->layer == layer2)
                        obj->layer = layer1;
+
+               if (obj->type == OTContainer)
+                       HandleLayerSwap(layer1, layer2, ((Container *)obj)->objects);
        }
 }
 
-
 void DrawingView::HandlePenWidth(float width)
 {
        for(VPVectorIter i=select.begin(); i!=select.end(); i++)
@@ -433,8 +439,10 @@ void DrawingView::HandlePenWidth(float width)
                Object * obj = (Object *)(*i);
                obj->thickness = width;
        }
-}
 
+       supressSelected = true;
+       update();
+}
 
 void DrawingView::HandlePenStyle(int style)
 {
@@ -443,8 +451,10 @@ void DrawingView::HandlePenStyle(int style)
                Object * obj = (Object *)(*i);
                obj->style = style;
        }
-}
 
+       supressSelected = true;
+       update();
+}
 
 void DrawingView::HandlePenColor(uint32_t color)
 {
@@ -453,27 +463,43 @@ void DrawingView::HandlePenColor(uint32_t color)
                Object * obj = (Object *)(*i);
                obj->color = color;
        }
-}
 
+       supressSelected = true;
+       update();
+}
 
-void DrawingView::HandlePenStamp(void)
+void DrawingView::HandlePenStamp(QAction * action)
 {
-       VPVector flat = Flatten(select);
+       PenWidget * pw = (PenWidget *)action->parentWidget();
+       pw->dropperAction->setChecked(false);
+       Global::penDropper = false;
+       Global::penStamp = action->isChecked();
 
-       for(VPVectorIter i=flat.begin(); i!=flat.end(); i++)
-       {
-               Object * obj = (Object *)(*i);
-
-               if (obj->type != OTText)
-                       obj->thickness = Global::penWidth;
+       if (Global::penStamp)
+               setCursor(curMarker);
+       else
+               setCursor(Qt::ArrowCursor);
 
-               obj->style = Global::penStyle;
-               obj->color = Global::penColor;
-       }
+       if (Global::penStamp == false)
+               ClearSelected(document.objects);
 
        update();
 }
 
+void DrawingView::HandlePenDropper(QAction * action)
+{
+       PenWidget * pw = (PenWidget *)action->parentWidget();
+       pw->stampAction->setChecked(false);
+       Global::penStamp = false;
+       Global::penDropper = action->isChecked();
+
+       if (Global::penDropper)
+               setCursor(curDropper);
+       else
+               setCursor(Qt::ArrowCursor);
+
+       update();
+}
 
 QPoint DrawingView::GetAdjustedMousePosition(QMouseEvent * event)
 {
@@ -483,7 +509,6 @@ QPoint DrawingView::GetAdjustedMousePosition(QMouseEvent * event)
        return QPoint(offsetX + event->x(), offsetY + (size().height() - event->y()));
 }
 
-
 QPoint DrawingView::GetAdjustedClientPosition(int x, int y)
 {
        // VOODOO ALERT (ON Y COMPONENT!!!!) (eh?)
@@ -492,7 +517,6 @@ QPoint DrawingView::GetAdjustedClientPosition(int x, int y)
        return QPoint(-offsetX + x, (size().height() - (-offsetY + y)) * +1.0);
 }
 
-
 void DrawingView::focusOutEvent(QFocusEvent * /*event*/)
 {
 //     printf("DrawingView::focusOutEvent()...\n");
@@ -504,6 +528,16 @@ void DrawingView::focusOutEvent(QFocusEvent * /*event*/)
        setCursor(Qt::ArrowCursor);
 }
 
+void DrawingView::focusInEvent(QFocusEvent * /*event*/)
+{
+       if (Global::penStamp)
+               setCursor(curMarker);
+       else if (Global::penDropper)
+               setCursor(curDropper);
+//FocusOut already set this...
+//     else
+//             setCursor(Qt::ArrowCursor);
+}
 
 void DrawingView::paintEvent(QPaintEvent * /*event*/)
 {
@@ -555,7 +589,6 @@ void DrawingView::paintEvent(QPaintEvent * /*event*/)
                painter.DrawInformativeText(informativeText);
 }
 
-
 //
 // Renders objects in the passed in vector
 //
@@ -585,7 +618,16 @@ void DrawingView::RenderObjects(Painter * painter, VPVector & v, int layer, bool
                        painter->SetPen(obj->color, Global::zoom * scaledThickness, obj->style);
                        painter->SetBrush(obj->color);
 
-                       if (obj->selected || obj->hitObject)
+                       // penStamp supresses object highlighting, so that changes can be seen.
+                       if (supressSelected || Global::penStamp)
+                       {
+                               if (obj->hitObject)
+                               {
+                                       painter->SetPen(Global::penColor, Global::zoom * Global::scale * Global::penWidth, Global::penStyle);
+                                       painter->SetBrush(Global::penColor);
+                               }
+                       }
+                       else if (obj->selected || obj->hitObject)
                                painter->SetPen(0xFF0000, Global::zoom * scaledThickness, LSDash);
                }
 
@@ -827,7 +869,7 @@ Where is the text offset?  It looks like it's drawing in the center, but obvious
                {
                        // Containers require recursive rendering...
                        Container * c = (Container *)obj;
-printf("About to render container: # objs=%i, layer=%i\n", (*c).objects.size(), layer);
+//printf("About to render container: # objs=%i, layer=%i\n", (*c).objects.size(), layer);
                        RenderObjects(painter, (*c).objects, layer, ignoreLayer);
 
 //printf("Container extents: <%lf, %lf>, <%lf, %lf>\nsize: %i\n", r.l, r.t, r.r, r.b, c->objects.size());
@@ -846,8 +888,9 @@ printf("About to render container: # objs=%i, layer=%i\n", (*c).objects.size(),
                        break;
                }
        }
-}
 
+       supressSelected = false;
+}
 
 //
 // This toggles the selection being hovered (typically, only 1 object)
@@ -862,7 +905,6 @@ void DrawingView::AddHoveredToSelection(void)
        }
 }
 
-
 VPVector DrawingView::GetSelection(void)
 {
        VPVector v;
@@ -876,7 +918,6 @@ VPVector DrawingView::GetSelection(void)
        return v;
 }
 
-
 VPVector DrawingView::GetHovered(void)
 {
        VPVector v;
@@ -890,14 +931,12 @@ VPVector DrawingView::GetHovered(void)
        return v;
 }
 
-
 void DrawingView::resizeEvent(QResizeEvent * /*event*/)
 {
        Global::screenSize = Vector(size().width(), size().height());
-       UpdateGridBackground();
+//     UpdateGridBackground();
 }
 
-
 void DrawingView::ToolHandler(int mode, Point p)
 {
        // Drop angle snap until it's needed
@@ -923,7 +962,6 @@ void DrawingView::ToolHandler(int mode, Point p)
                ParallelHandler(mode, p);
 }
 
-
 void DrawingView::ToolDraw(Painter * painter)
 {
        if (Global::tool == TTLine)
@@ -1083,7 +1121,6 @@ void DrawingView::ToolDraw(Painter * painter)
        }
 }
 
-
 void DrawingView::LineHandler(int mode, Point p)
 {
        switch (mode)
@@ -1127,7 +1164,6 @@ void DrawingView::LineHandler(int mode, Point p)
        }
 }
 
-
 void DrawingView::CircleHandler(int mode, Point p)
 {
        switch (mode)
@@ -1173,7 +1209,6 @@ void DrawingView::CircleHandler(int mode, Point p)
        }
 }
 
-
 void DrawingView::ArcHandler(int mode, Point p)
 {
        switch (mode)
@@ -1251,7 +1286,6 @@ void DrawingView::ArcHandler(int mode, Point p)
        }
 }
 
-
 void DrawingView::RotateHandler(int mode, Point p)
 {
        switch (mode)
@@ -1406,7 +1440,6 @@ void DrawingView::RotateHandler(int mode, Point p)
        }
 }
 
-
 void DrawingView::MirrorHandler(int mode, Point p)
 {
        switch (mode)
@@ -1520,7 +1553,6 @@ N.B.: When mirroring an arc thru a horizontal axis, this causes the arc to have
        }
 }
 
-
 void DrawingView::DimensionHandler(int mode, Point p)
 {
        switch (mode)
@@ -1564,7 +1596,6 @@ void DrawingView::DimensionHandler(int mode, Point p)
        }
 }
 
-
 void DrawingView::TriangulateHandler(int mode, Point/*p*/)
 {
        switch (mode)
@@ -1652,7 +1683,6 @@ void DrawingView::TriangulateHandler(int mode, Point/*p*/)
        }
 }
 
-
 void DrawingView::TrimHandler(int mode, Point p)
 {
 /*
@@ -1793,7 +1823,6 @@ n.b.: this code is lifted straight out of the old oo code.  needs to be updated.
        }
 }
 
-
 void DrawingView::ParallelHandler(int mode, Point /*p*/)
 {
        switch (mode)
@@ -1818,7 +1847,6 @@ void DrawingView::ParallelHandler(int mode, Point /*p*/)
        }
 }
 
-
 void DrawingView::mousePressEvent(QMouseEvent * event)
 {
        if (event->button() == Qt::LeftButton)
@@ -1864,7 +1892,25 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
 //printf("mousePressEvent::numHovered > 0 (hover2[0]=$%llx, type=%s)\n", dragged, objName[dragged->type]);
 
                        // Alert the pen widget
-                       emit ObjectSelected(dragged);
+// Maybe do this with an eyedropper tool on the pen bar?  [YES]
+//                     emit ObjectSelected(dragged);
+                       if (Global::penDropper)
+                       {
+                               Global::penColor = dragged->color;
+                               Global::penWidth = dragged->thickness;
+                               Global::penStyle = dragged->style;
+                               emit ObjectSelected(dragged);
+                               ClearSelected(document.objects);
+                               return;
+                       }
+
+                       if (Global::penStamp)
+                       {
+                               dragged->color = Global::penColor;
+                               dragged->thickness = Global::penWidth;
+                               dragged->style = Global::penStyle;
+                               return;
+                       }
 
                        // See if anything is using just a straight click on a handle
                        if (HandleObjectClicked())
@@ -1917,7 +1963,6 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
        }
 }
 
-
 void DrawingView::mouseMoveEvent(QMouseEvent * event)
 {
        // It seems that wheelEvent() triggers this for some reason...
@@ -1946,7 +1991,7 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
                delta.y = -delta.y;
                Global::origin -= delta;
 
-               UpdateGridBackground();
+//             UpdateGridBackground();
                update();
                oldPoint = point;
                return;
@@ -1960,7 +2005,11 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
 
                // Make sure previously selected objects stay selected (CTRL held)
                for(VPVectorIter i=select.begin(); i!=select.end(); i++)
-                       ((Object *)(*i))->selected = true;
+               {
+                       // Make sure *not* to select items on hidden layers
+                       if (Global::layerHidden[((Object *)(*i))->layer] == false)
+                               ((Object *)(*i))->selected = true;
+               }
 
                update();
                return;
@@ -2088,7 +2137,6 @@ Except when lines are overlapping, then it doesn't work... !!! FIX !!!
                update();
 }
 
-
 void DrawingView::mouseReleaseEvent(QMouseEvent * event)
 {
        if (event->button() == Qt::LeftButton)
@@ -2125,13 +2173,19 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event)
        else if (event->button() == Qt::MiddleButton)
        {
                scrollDrag = false;
-               setCursor(Qt::ArrowCursor);
+
+               if (Global::penStamp)
+                       setCursor(curMarker);
+               else if (Global::penDropper)
+                       setCursor(curDropper);
+               else
+                       setCursor(Qt::ArrowCursor);
+
                // Need to convert this, since it's in Qt coordinates (for wheelEvent)
                oldPoint = Painter::QtToCartesianCoords(oldPoint);
        }
 }
 
-
 void DrawingView::wheelEvent(QWheelEvent * event)
 {
        double zoomFactor = 1.20;
@@ -2158,7 +2212,6 @@ void DrawingView::wheelEvent(QWheelEvent * event)
        emit(NeedZoomUpdate());
 }
 
-
 void DrawingView::keyPressEvent(QKeyEvent * event)
 {
        bool oldShift = shiftDown;
@@ -2214,7 +2267,6 @@ void DrawingView::keyPressEvent(QKeyEvent * event)
        }
 }
 
-
 void DrawingView::keyReleaseEvent(QKeyEvent * event)
 {
        bool oldShift = shiftDown;
@@ -2239,11 +2291,16 @@ void DrawingView::keyReleaseEvent(QKeyEvent * event)
        if (oldAlt != altDown)
        {
                scrollDrag = false;
-               setCursor(Qt::ArrowCursor);
+
+               if (Global::penStamp)
+                       setCursor(curMarker);
+               else if (Global::penDropper)
+                       setCursor(curDropper);
+               else
+                       setCursor(Qt::ArrowCursor);
        }
 }
 
-
 //
 // This looks strange, but it's really quite simple: We want a point that's
 // more than half-way to the next grid point to snap there while conversely we
@@ -2263,7 +2320,6 @@ Point DrawingView::SnapPointToGrid(Point point)
        return point;
 }
 
-
 Point DrawingView::SnapPointToAngle(Point point)
 {
        // Snap to a single digit angle (using toolpoint #1 as the center)
@@ -2281,7 +2337,6 @@ Point DrawingView::SnapPointToAngle(Point point)
        return point;
 }
 
-
 Rect DrawingView::GetObjectExtents(Object * obj)
 {
        // Default to empty rect, if object checks below fail for some reason
@@ -2367,7 +2422,6 @@ Rect DrawingView::GetObjectExtents(Object * obj)
        return rect;
 }
 
-
 void DrawingView::CheckObjectBounds(void)
 {
        VPVectorIter i;
@@ -2494,7 +2548,6 @@ void DrawingView::CheckObjectBounds(void)
        }
 }
 
-
 bool DrawingView::HitTestObjects(Point point)
 {
        VPVectorIter i;
@@ -2524,7 +2577,6 @@ bool DrawingView::HitTestObjects(Point point)
        return needUpdate;
 }
 
-
 bool DrawingView::HitTest(Object * obj, Point point)
 {
        bool needUpdate = false;
@@ -2810,7 +2862,6 @@ Well, you could if there was only one object in the Container.  But since there
        return needUpdate;
 }
 
-
 bool DrawingView::HandleObjectClicked(void)
 {
        if (dragged->type == OTDimension)
@@ -2854,7 +2905,6 @@ bool DrawingView::HandleObjectClicked(void)
        return false;
 }
 
-
 void DrawingView::HandleObjectMovement(Point point)
 {
        Point delta = point - oldPoint;
@@ -3030,7 +3080,6 @@ The idea is to make it so whichever point on the object in question is being dra
        }
 }
 
-
 void DrawingView::AddDimensionTo(void * o)
 {
        Object * obj = (Object *)o;
@@ -3050,4 +3099,3 @@ void DrawingView::AddDimensionTo(void * o)
                break;
        }
 }
-
index 441b7a8eb61cecfd2b080bc636b11b00000faee8..0c6cc46cf76d18390d908dd8447e7b4661355ac9 100644 (file)
@@ -19,10 +19,10 @@ class DrawingView: public QWidget
 
        public:
                void DrawBackground(Painter *);
-               void SetGridSize(uint32_t);
-               void SetGridSize(double);
-               void UpdateGridBackground(void);
-               void UpdateGridBackgroundF(void);
+//             void SetGridSize(uint32_t);
+//             void SetGridSize(double);
+//             void UpdateGridBackground(void);
+//             void UpdateGridBackgroundF(void);
                Point SnapPointToGrid(Point);
                Point SnapPointToAngle(Point);
                void RenderObjects(Painter *, VPVector &, int, bool ignoreLayer = false);
@@ -55,7 +55,8 @@ class DrawingView: public QWidget
                void HandlePenWidth(float);
                void HandlePenStyle(int);
                void HandlePenColor(uint32_t);
-               void HandlePenStamp(void);
+               void HandlePenStamp(QAction *);
+               void HandlePenDropper(QAction *);
 
        signals:
                void ObjectHovered(Object *);
@@ -64,6 +65,7 @@ class DrawingView: public QWidget
 
        protected:
                void focusOutEvent(QFocusEvent * event);
+               void focusInEvent(QFocusEvent * event);
                void paintEvent(QPaintEvent * event);
                void resizeEvent(QResizeEvent * event);
                void mousePressEvent(QMouseEvent * event);
@@ -74,6 +76,7 @@ class DrawingView: public QWidget
                void keyReleaseEvent(QKeyEvent * event);
 
        private:
+               void HandleLayerSwap(int, int, VPVector &);
                void DrawSubGrid(Painter *, uint32_t, double, Vector, Vector);
                QPoint GetAdjustedMousePosition(QMouseEvent * event);
                QPoint GetAdjustedClientPosition(int x, int y);
@@ -89,6 +92,9 @@ class DrawingView: public QWidget
                QPixmap gridBackground;
                double scale;                                                   // Window scaling factor
                int32_t offsetX, offsetY;                               // Window offsets
+               bool supressSelected;
+               QCursor curMarker;
+               QCursor curDropper;
        public:
                Container document;
                uint32_t gridPixels;                                    // Grid size in pixels
index 7a7cc9b7739829fc1db6e63faef40a29d6d5c847..9ec2a7bba529187dd2040f1a6de2102a8a78a1dd 100644 (file)
@@ -41,6 +41,7 @@ float Global::penWidth = 1.0;
 int Global::penStyle = 1;
 uint32_t Global::penColor = 0x000000;
 bool Global::penStamp = false;
+bool Global::penDropper = false;
 
 Point Global::intersectPoint[16]; // Overkill, yes
 double Global::intersectParam[16]; // Ditto
index 93ad6f7f9484a23ecdba2b373f60413b587cb37f..3a18272ccf01dba0d1a0df682af0785ce8f052ed 100644 (file)
@@ -52,6 +52,7 @@ class Global
                static int penStyle;
                static uint32_t penColor;
                static bool penStamp;
+               static bool penDropper;
 
                static Point intersectPoint[16]; // Overkill, yes
                static double intersectParam[16]; // Ditto
index 9177b206594aa3979a986495f3e8a079d200e89d..4c9dd93ff73db823c0621daca42d6103b7b19636 100644 (file)
@@ -232,8 +232,10 @@ void LayerWidget::EditLayer(void)
        {
                li->name->setText(result);
 
-               int layer = (Global::numLayers - Global::activeLayer) - 1;
-               std::vector<std::string>::iterator i = Global::layerName.begin() + layer;
+               // We don't reverse the layer # here, like elsewhere, because we're
+               // using the layer # directly instead of having to translate it from
+               // the widget.
+               std::vector<std::string>::iterator i = Global::layerName.begin() + Global::activeLayer;
                (*i) = result.toUtf8().data();
        }
 }
index e20f3eeb2247c52c8bd84711dd9589cd430e6692..322e1508ebe7f5bd55172b93ecae6c591fc4a74f 100644 (file)
 #include "global.h"
 #include "mathconstants.h"
 
-
 Painter::Painter(QPainter * p/*= NULL*/): painter(p)
 {
 }
 
-
 Painter::~Painter()
 {
 }
 
-
 Vector Painter::CartesianToQtCoords(Vector v)
 {
        // Convert regular Cartesian coordinates to the inverted Y-axis Qt
@@ -34,7 +31,6 @@ Vector Painter::CartesianToQtCoords(Vector v)
        return Vector((v.x - Global::origin.x) * Global::zoom, Global::screenSize.y - ((v.y - Global::origin.y) * Global::zoom));
 }
 
-
 Vector Painter::QtToCartesianCoords(Vector v)
 {
        // Convert screen location, with inverted Y-axis coordinates, to regular
@@ -63,7 +59,6 @@ The way we calculate the Cartesian to Qt shows the 2nd (origin is cartesian) to
 */
 }
 
-
 void Painter::SetRenderHint(int hint)
 {
        if (!painter)
@@ -72,7 +67,6 @@ void Painter::SetRenderHint(int hint)
        painter->setRenderHint((QPainter::RenderHint)hint);
 }
 
-
 void Painter::SetPen(QPen pen)
 {
        if (!painter)
@@ -81,7 +75,6 @@ void Painter::SetPen(QPen pen)
        painter->setPen(pen);
 }
 
-
 void Painter::SetPen(uint32_t color, float size/*= 0*/, int style/*= 0*/)
 {
        if (!painter)
@@ -92,7 +85,6 @@ void Painter::SetPen(uint32_t color, float size/*= 0*/, int style/*= 0*/)
                size, (Qt::PenStyle)style));
 }
 
-
 void Painter::SetBrush(QBrush brush)
 {
        if (!painter)
@@ -101,7 +93,6 @@ void Painter::SetBrush(QBrush brush)
        painter->setBrush(brush);
 }
 
-
 void Painter::SetBrush(uint32_t color)
 {
        if (!painter)
@@ -110,7 +101,6 @@ void Painter::SetBrush(uint32_t color)
        painter->setBrush(QBrush(QColor(color >> 16, (color >> 8) & 0xFF, color & 0xFF, 255)));
 }
 
-
 void Painter::SetFont(QFont font)
 {
        if (!painter)
@@ -119,7 +109,6 @@ void Painter::SetFont(QFont font)
        painter->setFont(font);
 }
 
-
 void Painter::DrawAngledText(Vector center, double angle, QString text, double size)
 {
        if (!painter)
@@ -160,7 +149,6 @@ void Painter::DrawAngledText(Vector center, double angle, QString text, double s
        painter->restore();
 }
 
-
 //
 // Draw angled text. Draws text using point p as the upper left corner.
 // Size is point size, angle is in radians (defaults to 0).
@@ -172,7 +160,7 @@ void Painter::DrawTextObject(Point p, QString text, double size, double angle/*=
 
        p = CartesianToQtCoords(p);
        painter->setFont(QFont("Arial", Global::zoom * size));
-       int textWidth = QFontMetrics(painter->font()).width(text);
+       int textWidth = QFontMetrics(painter->font()).horizontalAdvance(text);
        int textHeight = QFontMetrics(painter->font()).height();
 
        QRectF textBox(0, 0, textWidth, textHeight);
@@ -184,7 +172,6 @@ void Painter::DrawTextObject(Point p, QString text, double size, double angle/*=
        painter->restore();
 }
 
-
 //
 // Return the non-rotated rectangle containing the extents of the text in
 // Cartesian coordiates (starting from <0, 0>, the lower left hand side)
@@ -195,15 +182,13 @@ Rect Painter::MeasureTextObject(QString text, double size)
                return Rect();
 
        painter->setFont(QFont("Arial", Global::zoom * size));
-       int textWidth = QFontMetrics(painter->font()).width(text);
+       int textWidth = QFontMetrics(painter->font()).horizontalAdvance(text);
        int textHeight = QFontMetrics(painter->font()).height();
-       Point measured((double)textWidth / Global::zoom, (double)textHeight / Global::zoom);// = QtToCartesianCoords(Point(textWidth, textHeight));
-//printf("QFontMetrics w/h=%i/%i, measured=%lf/%lf\n", textWidth, textHeight, measured.x, measured.y);
+       Point measured((double)textWidth / Global::zoom, (double)textHeight / Global::zoom);
 
        return Rect(Point(0, 0), measured);
 }
 
-
 void Painter::DrawArc(Vector center, double radius, double startAngle, double span)
 {
        if (!painter)
@@ -219,7 +204,6 @@ void Painter::DrawArc(Vector center, double radius, double startAngle, double sp
        painter->drawArc(rectangle, angle1, angle2);
 }
 
-
 void Painter::DrawEllipse(Vector center, double axis1, double axis2)
 {
        if (!painter)
@@ -230,7 +214,6 @@ void Painter::DrawEllipse(Vector center, double axis1, double axis2)
        painter->drawEllipse(QPointF(center.x, center.y), axis1 * Global::zoom, axis2 * Global::zoom);
 }
 
-
 // This function is for drawing object handles without regard for zoom level;
 // we don't want our object handle size to depend on the zoom level!
 void Painter::DrawHandle(Vector center)
@@ -244,7 +227,6 @@ void Painter::DrawHandle(Vector center)
        painter->drawEllipse(QPointF(center.x, center.y), 4.0, 4.0);
 }
 
-
 // This function is for drawing object handles without regard for zoom level;
 // we don't want our object handle size to depend on the zoom level!
 void Painter::DrawSmallHandle(Vector center)
@@ -258,7 +240,6 @@ void Painter::DrawSmallHandle(Vector center)
        painter->drawEllipse(QPointF(center.x, center.y), 2.0, 2.0);
 }
 
-
 // This function is for drawing feedback points without regard for zoom level;
 // we don't want our feedback point size to depend on the zoom level!
 void Painter::DrawCross(Vector point)
@@ -272,7 +253,6 @@ void Painter::DrawCross(Vector point)
        painter->drawLine(point.x, point.y - 8.0, point.x, point.y + 8.0);
 }
 
-
 // This function is for drawing feedback points without regard for zoom level;
 // we don't want our feedback point size to depend on the zoom level!
 void Painter::DrawRectCorners(Rect rect)
@@ -296,7 +276,6 @@ void Painter::DrawRectCorners(Rect rect)
 
 }
 
-
 // This function is for drawing object handles without regard for zoom level;
 // we don't want our object handle size to depend on the zoom level!
 void Painter::DrawArrowHandle(Vector center, double angle)
@@ -325,7 +304,6 @@ void Painter::DrawArrowHandle(Vector center, double angle)
        painter->drawPolygon(arrow);
 }
 
-
 // This function is for drawing object handles without regard for zoom level;
 // we don't want our object handle size to depend on the zoom level!
 void Painter::DrawArrowToLineHandle(Vector center, double angle)
@@ -349,7 +327,6 @@ void Painter::DrawArrowToLineHandle(Vector center, double angle)
        painter->drawLine(p2.x, p2.y, p3.x, p3.y);
 }
 
-
 void Painter::DrawLine(int x1, int y1, int x2, int y2)
 {
        if (!painter)
@@ -360,7 +337,6 @@ void Painter::DrawLine(int x1, int y1, int x2, int y2)
        painter->drawLine(v1.x, v1.y, v2.x, v2.y);
 }
 
-
 void Painter::DrawLine(Vector v1, Vector v2)
 {
        if (!painter)
@@ -371,7 +347,6 @@ void Painter::DrawLine(Vector v1, Vector v2)
        painter->drawLine(QPointF(v1.x, v1.y), QPointF(v2.x, v2.y));
 }
 
-
 void Painter::DrawHLine(double ypos)
 {
        double width = Global::screenSize.x / Global::zoom;
@@ -380,7 +355,6 @@ void Painter::DrawHLine(double ypos)
        painter->drawLine(QPointF(v1.x, v1.y), QPointF(v2.x, v2.y));
 }
 
-
 void Painter::DrawVLine(double xpos)
 {
        double height = Global::screenSize.y / Global::zoom;
@@ -389,7 +363,6 @@ void Painter::DrawVLine(double xpos)
        painter->drawLine(QPointF(v1.x, v1.y), QPointF(v2.x, v2.y));
 }
 
-
 void Painter::DrawPoint(int x, int y)
 {
        if (!painter)
@@ -399,7 +372,6 @@ void Painter::DrawPoint(int x, int y)
        painter->drawPoint(v.x, v.y);
 }
 
-
 // The rect passed in is in Qt coordinates...
 void Painter::DrawRoundedRect(QRectF rect, double radiusX, double radiusY)
 {
@@ -409,7 +381,6 @@ void Painter::DrawRoundedRect(QRectF rect, double radiusX, double radiusY)
        painter->drawRoundedRect(rect, radiusX, radiusY);
 }
 
-
 // The rect passed in is in Cartesian but we want to pad it by a set number of
 // pixels (currently set at 8), so the pad looks the same regardless of zoom.
 void Painter::DrawPaddedRect(QRectF rect)
@@ -424,7 +395,6 @@ void Painter::DrawPaddedRect(QRectF rect)
        painter->drawRect(screenRect);
 }
 
-
 void Painter::DrawRect(QRectF rect)
 {
        if (!painter)
@@ -436,7 +406,6 @@ void Painter::DrawRect(QRectF rect)
        painter->drawRect(screenRect);
 }
 
-
 void Painter::DrawText(QRectF rect, int type, QString text)
 {
        if (!painter)
@@ -445,7 +414,6 @@ void Painter::DrawText(QRectF rect, int type, QString text)
        painter->drawText(rect, (Qt::AlignmentFlag)type, text);
 }
 
-
 void Painter::DrawArrowhead(Vector head, Vector tail, double size)
 {
        if (!painter)
@@ -472,7 +440,6 @@ void Painter::DrawArrowhead(Vector head, Vector tail, double size)
        painter->drawPolygon(arrow);
 }
 
-
 // Point is given in Cartesian coordinates
 void Painter::DrawCrosshair(Vector point)
 {
@@ -484,7 +451,6 @@ void Painter::DrawCrosshair(Vector point)
        painter->drawLine(screenPoint.x, 0, screenPoint.x, Global::screenSize.y);
 }
 
-
 void Painter::DrawInformativeText(QString text)
 {
        if (!painter)
@@ -505,4 +471,3 @@ void Painter::DrawInformativeText(QString text)
        painter->setPen(pen);
        painter->drawText(bounds, Qt::AlignVCenter, text);
 }
-
index 403476e1617dc7c8820a782a27814daa596736a9..e89f045b7d55a16eb852eb38996e90e2a9b3d777 100644 (file)
@@ -53,4 +53,3 @@ class Painter
 };
 
 #endif // __PAINTER_H__
-
index 4bd966af36e2af3cf3ac4e1f8c1d7a893f768f33..9b80932b2e47fc372f1b4870141616eb640c9156 100644 (file)
 //
 //maybe add a button to have it stamp attributes on all objects clicked on? [added Global::penStamp to facilitate this.]
 //need to add to drawingview the ability to use attributes on new objects [DONE]
-//need to override the selection so you can see the attributes effects immediately when they are changed instead of having to deselect them to see
-
+//need to override the selection so you can see the attributes effects immediately when they are changed instead of having to deselect them to see [IN PROGRESS]
 
 #include "penwidget.h"
 
-
-PenWidget::PenWidget(void): QWidget(), r(0), g(0), b(0), programChange(false)
+PenWidget::PenWidget(void): QWidget(), width(new QLineEdit("1.0")), red(new QLineEdit("00")), green(new QLineEdit("00")), blue(new QLineEdit("00")), style(new QComboBox), r(0), g(0), b(0), programChange(false), stampAction(new QAction(QIcon(":/res/pen-stamp.png"), tr(""), this)), dropperAction(new QAction(QIcon(":/res/pen-dropper.png"), tr(""), this)), tbStamp(new QToolButton(this)), tbDropper(new QToolButton(this))
 {
-       width = new QLineEdit("1.0");
-       red = new QLineEdit("00");
-       green = new QLineEdit("00");
-       blue = new QLineEdit("00");
-       style = new QComboBox;
-
        QLabel * l1 = new QLabel(tr("Width:"));
        QLabel * l2 = new QLabel(tr("RGB:"));
        QLabel * l3 = new QLabel(tr("Style:"));
-       QToolButton * qtb = new QToolButton(this);
 
-       QAction * action = new QAction(QIcon(":/res/pen-stamp.png"), tr(""), this);
-       action->setToolTip(tr("Stamp Selected"));
-       action->setStatusTip(tr("Stamp selected objects with pen attributes."));
-       action->setShortcut(QKeySequence(tr("p,p")));
-//     action->setCheckable(checkable);
-       qtb->setDefaultAction(action);
+       stampAction->setToolTip(tr("Stamp Selected"));
+       stampAction->setStatusTip(tr("Stamp selected objects with pen attributes."));
+       stampAction->setShortcut(QKeySequence(tr("p,p")));
+       stampAction->setCheckable(true);
+       tbStamp->setDefaultAction(stampAction);
+
+       dropperAction->setToolTip(tr("Color Picker"));
+       dropperAction->setStatusTip(tr("Get pen attributes from objects."));
+       dropperAction->setShortcut(QKeySequence(tr("d,d")));
+       dropperAction->setCheckable(true);
+       tbDropper->setDefaultAction(dropperAction);
 
        style->insertItem(1, tr("Solid"));
        style->insertItem(2, tr("Dash"));
@@ -63,15 +59,16 @@ PenWidget::PenWidget(void): QWidget(), r(0), g(0), b(0), programChange(false)
        style->setToolTip(tr("Sets pen style"));
 
        QHBoxLayout * hbox1 = new QHBoxLayout;
-       hbox1->addWidget(l1, 0, Qt::AlignLeft);
-       hbox1->addWidget(width, 0, Qt::AlignLeft);
        hbox1->addWidget(l2, 0, Qt::AlignLeft);
        hbox1->addWidget(red, 0, Qt::AlignLeft);
        hbox1->addWidget(green, 0, Qt::AlignLeft);
        hbox1->addWidget(blue, 0, Qt::AlignLeft);
+       hbox1->addWidget(l1, 0, Qt::AlignLeft);
+       hbox1->addWidget(width, 0, Qt::AlignLeft);
        hbox1->addWidget(l3, 0, Qt::AlignLeft);
        hbox1->addWidget(style, 0, Qt::AlignLeft);
-       hbox1->addWidget(qtb, 0, Qt::AlignLeft);
+       hbox1->addWidget(tbStamp, 0, Qt::AlignLeft);
+       hbox1->addWidget(tbDropper, 0, Qt::AlignLeft);
        hbox1->addStretch(1);
 
        setLayout(hbox1);
@@ -81,15 +78,12 @@ PenWidget::PenWidget(void): QWidget(), r(0), g(0), b(0), programChange(false)
        connect(green, SIGNAL(textEdited(QString)), this, SLOT(HandleGreenSelected(QString)));
        connect(blue, SIGNAL(textEdited(QString)), this, SLOT(HandleBlueSelected(QString)));
        connect(style, SIGNAL(currentIndexChanged(int)), this, SLOT(HandleStyleSelected(int)));
-       connect(qtb, SIGNAL(triggered(QAction *)), this, SLOT(HandleStamp(QAction *)));
 }
 
-
 PenWidget::~PenWidget()
 {
 }
 
-
 void PenWidget::SetFields(Object * obj)
 {
        // Sanity check
@@ -113,7 +107,6 @@ void PenWidget::SetFields(Object * obj)
        programChange = false;
 }
 
-
 void PenWidget::HandleWidthSelected(QString text)
 {
        // Parse the text in the control
@@ -127,7 +120,6 @@ void PenWidget::HandleWidthSelected(QString text)
        emit WidthSelected(Global::penWidth);
 }
 
-
 void PenWidget::HandleStyleSelected(int selected)
 {
        // Change was programmatic, don't do anything
@@ -140,7 +132,6 @@ void PenWidget::HandleStyleSelected(int selected)
        emit StyleSelected(Global::penStyle);
 }
 
-
 void PenWidget::HandleRedSelected(QString text)
 {
        // Parse the text in the control
@@ -155,7 +146,6 @@ void PenWidget::HandleRedSelected(QString text)
        emit ColorSelected(Global::penColor);
 }
 
-
 void PenWidget::HandleGreenSelected(QString text)
 {
        // Parse the text in the control
@@ -170,7 +160,6 @@ void PenWidget::HandleGreenSelected(QString text)
        emit ColorSelected(Global::penColor);
 }
 
-
 void PenWidget::HandleBlueSelected(QString text)
 {
        // Parse the text in the control
@@ -184,10 +173,3 @@ void PenWidget::HandleBlueSelected(QString text)
        Global::penColor = (r << 16) | (g << 8) | b;
        emit ColorSelected(Global::penColor);
 }
-
-
-void PenWidget::HandleStamp(QAction * /* action */)
-{
-       emit StampSelected();
-}
-
index 5809c446731a5e3669826615cf43d9d53a05532c..c08d14bba50bd232b4437c1b92f70058a1c9609a 100644 (file)
@@ -4,7 +4,6 @@
 #include <QtWidgets>
 #include "structs.h"
 
-
 class PenWidget: public QWidget
 {
        Q_OBJECT
@@ -22,13 +21,15 @@ class PenWidget: public QWidget
                void HandleRedSelected(QString);
                void HandleGreenSelected(QString);
                void HandleBlueSelected(QString);
-               void HandleStamp(QAction *);
+//             void HandleStamp(QAction *);
+//             void HandleDropper(QAction *);
 
        signals:
                void WidthSelected(float);
                void StyleSelected(int);
                void ColorSelected(uint32_t);
                void StampSelected(void);
+               void DropperSelected(void);
 
        private:
                QLineEdit * width;
@@ -38,7 +39,12 @@ class PenWidget: public QWidget
                QComboBox * style;
                int r, g, b;
                bool programChange;
+
+       public:
+               QAction * stampAction;
+               QAction * dropperAction;
+               QToolButton * tbStamp;
+               QToolButton * tbDropper;
 };
 
 #endif // __PENWIDGET_H__
-
index b9ca463bbc948bda5ba79bcfeaa220af0588d0c3..7428fbe6a5bdb4f200e8d45a1014ffc8b8d22bef 100644 (file)
@@ -16,7 +16,6 @@
 #include <string.h>            // For memcpy()
 #include "geometry.h"
 
-
 //
 // Copy objects in one vector to another, creating copies and placing them in
 // the other vector. Clearing & etc. of vectors is responsibility of the caller!
@@ -31,7 +30,6 @@ void CopyObjects(VPVector & from, VPVector & to)
        }
 }
 
-
 VPVector CopyObjects(VPVector & src)
 {
        VPVector copy;
@@ -45,7 +43,6 @@ VPVector CopyObjects(VPVector & src)
        return copy;
 }
 
-
 //
 // Create a copy of the passed in object.
 //
@@ -104,7 +101,6 @@ Object * CopyObject(Object * obj)
        return (Object *)newObject;
 }
 
-
 //
 // Create a copy of the passed in object.  This version calls the second
 // version of CopyObjects() (with one parameter and a vector return value).
@@ -167,7 +163,6 @@ Object * CopyObject2(Object * obj)
        return (Object *)newObject;
 }
 
-
 void MoveSelectedObjectsTo(VPVector & dest, VPVector & from)
 {
        VPVectorIter i = from.begin();
@@ -186,7 +181,6 @@ void MoveSelectedObjectsTo(VPVector & dest, VPVector & from)
        }
 }
 
-
 VPVector MoveSelectedObjectsFrom(VPVector & from)
 {
        VPVector objects;
@@ -208,7 +202,6 @@ VPVector MoveSelectedObjectsFrom(VPVector & from)
        return objects;
 }
 
-
 //hmm, this won't work, as these are just pointers...
 //[should work now]
 void CopySelectedObjectsTo(VPVector & dest, VPVector & from)
@@ -222,7 +215,6 @@ void CopySelectedObjectsTo(VPVector & dest, VPVector & from)
        }
 }
 
-
 VPVector CopySelectedObjects(VPVector & src)
 {
        VPVector copy;
@@ -238,21 +230,18 @@ VPVector CopySelectedObjects(VPVector & src)
        return copy;
 }
 
-
 void AddObjectsTo(VPVector & dest, VPVector & from)
 {
        for(VPVectorIter i=from.begin(); i!=from.end(); i++)
                dest.push_back(*i);
 }
 
-
 void ClearSelected(VPVector & v)
 {
        for(VPVectorIter i=v.begin(); i!=v.end(); i++)
                ((Object *)(*i))->selected = false;
 }
 
-
 //
 // Select all *visible* objects.  If an object's layer is invisible, skip it.
 //
@@ -266,7 +255,6 @@ void SelectAll(VPVector & v)
        }
 }
 
-
 //
 // Recursively go down thru the Container's vectors, deleting all the objects
 // contained therein.  Once that is done, the main Container can be deleted.
@@ -290,7 +278,6 @@ void DeleteContents(VPVector & v)
        v.clear();
 }
 
-
 void DeleteSelectedObjects(VPVector & v)
 {
        VPVectorIter i = v.begin();
@@ -309,7 +296,6 @@ void DeleteSelectedObjects(VPVector & v)
        }
 }
 
-
 //
 // This is used to remove selected objects from one container in order to move
 // them to a different container.
@@ -329,7 +315,6 @@ void RemoveSelectedObjects(VPVector & v)
        }
 }
 
-
 void SavePointsFrom(VPVector & v, std::vector<Object> & save)
 {
        save.clear();
@@ -342,7 +327,6 @@ void SavePointsFrom(VPVector & v, std::vector<Object> & save)
        }
 }
 
-
 void RestorePointsTo(VPVector & v, std::vector<Object> & s)
 {
        std::vector<Object>::iterator i;
@@ -360,7 +344,6 @@ void RestorePointsTo(VPVector & v, std::vector<Object> & s)
        }
 }
 
-
 void RestorePointsTo(VPVector & v, VPVector & s)
 {
        for(VPVectorIter i=s.begin(), j=v.begin(); i!=s.end(); i++, j++)
@@ -383,7 +366,6 @@ void RestorePointsTo(VPVector & v, VPVector & s)
        }
 }
 
-
 //
 // Translate a single object; it it's a Container, translate all its contents,
 // including subcontainers.
@@ -402,7 +384,6 @@ void TranslateObject(Object * obj, Point delta)
        obj->p[1] += delta;
 }
 
-
 /*
 So we need to make it so that we pick the container's point clicked on, and translate all the other parts *not* clicked on.
 */
@@ -464,7 +445,6 @@ void TranslateContainer(Container * c, Point point, Point delta)
        TranslateObject((Object *)c, clickedDelta);
 }
 
-
 //
 // Translate all objects in the passed in vector, including Containers and all
 // the objects they contain.
@@ -485,7 +465,6 @@ void TranslateObjects(VPVector & v, Point delta)
        }
 }
 
-
 //
 // This does not *copy* the objects, it simply flattens out the pointers in the
 // Container and all sub-Containers.
@@ -510,7 +489,6 @@ VPVector Flatten(Container * src)
        return flat;
 }
 
-
 //
 // This does not *copy* the objects, it simply flattens out the pointers in the
 // vector and all sub-Containers in the vector.
@@ -534,4 +512,3 @@ VPVector Flatten(VPVector src)
 
        return flat;
 }
-