From cdde036d71eb0ea9b450345bd297c8730591b26b Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Fri, 10 Dec 2021 19:07:32 -0600 Subject: [PATCH] Fixed click selection and pen functionality. Now when a stack of objects is clicked on, clicking on the stack will select them one at a time. Now it's possible to grab objects in a rational way! Also, removed unnecessary pen functions that caused more problems than they solved. Now you must use the stamp function to change objects' visible attributes. --- src/applicationwindow.cpp | 6 +-- src/applicationwindow.h | 1 - src/drawingview.cpp | 107 ++++++++++++++++---------------------- src/drawingview.h | 9 ++-- src/penwidget.cpp | 10 +--- src/penwidget.h | 5 -- 6 files changed, 51 insertions(+), 87 deletions(-) diff --git a/src/applicationwindow.cpp b/src/applicationwindow.cpp index 47f8149..ef77f8b 100644 --- a/src/applicationwindow.cpp +++ b/src/applicationwindow.cpp @@ -153,7 +153,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.")); } @@ -1095,9 +1096,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->tbStamp, SIGNAL(triggered(QAction *)), drawing, SLOT(HandlePenStamp(QAction *))); connect(pw->tbDropper, SIGNAL(triggered(QAction *)), drawing, SLOT(HandlePenDropper(QAction *))); } diff --git a/src/applicationwindow.h b/src/applicationwindow.h index d5a9c08..651add7 100644 --- a/src/applicationwindow.h +++ b/src/applicationwindow.h @@ -126,7 +126,6 @@ class ApplicationWindow: public QMainWindow QAction * editPasteAct; QAction * selectAllAct; QAction * printPreviewAct; -// QAction * moveToLayerAct; QList layerAct; QList mruAct; diff --git a/src/drawingview.cpp b/src/drawingview.cpp index 4ae021c..d8726fe 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -193,7 +193,6 @@ void DrawingView::DrawSubGrid(Painter * painter, uint32_t color, double step, Ve // void DrawingView::DeleteCurrentLayer(int layer) { -//printf("DrawingView::DeleteCurrentLayer(): currentLayer = %i\n", layer); VPVectorIter i = document.objects.begin(); while (i != document.objects.end()) @@ -230,7 +229,6 @@ void DrawingView::HandleLayerToggle(void) // void DrawingView::HandleLayerSwap(int layer1, int layer2) { -//printf("DrawingView: Swapping layers %i and %i.\n", layer1, layer2); HandleLayerSwap(layer1, layer2, document.objects); } @@ -253,42 +251,6 @@ void DrawingView::HandleLayerSwap(int layer1, int layer2, VPVector & v) } } -void DrawingView::HandlePenWidth(float width) -{ - for(VPVectorIter i=select.begin(); i!=select.end(); i++) - { - Object * obj = (Object *)(*i); - obj->thickness = width; - } - - supressSelected = true; - update(); -} - -void DrawingView::HandlePenStyle(int style) -{ - for(VPVectorIter i=select.begin(); i!=select.end(); i++) - { - Object * obj = (Object *)(*i); - obj->style = style; - } - - supressSelected = true; - update(); -} - -void DrawingView::HandlePenColor(uint32_t color) -{ - for(VPVectorIter i=select.begin(); i!=select.end(); i++) - { - Object * obj = (Object *)(*i); - obj->color = color; - } - - supressSelected = true; - update(); -} - void DrawingView::HandlePenStamp(QAction * action) { PenWidget * pw = (PenWidget *)action->parentWidget(); @@ -340,7 +302,6 @@ QPoint DrawingView::GetAdjustedClientPosition(int x, int y) void DrawingView::focusOutEvent(QFocusEvent * /*event*/) { -// printf("DrawingView::focusOutEvent()...\n"); // Make sure all modkeys being held are marked as released when the app // loses focus (N.B.: This only works because the app sets the focus policy // of this object to something other than Qt::NoFocus) @@ -355,9 +316,6 @@ void DrawingView::focusInEvent(QFocusEvent * /*event*/) setCursor(curMarker); else if (Global::penDropper) setCursor(curDropper); -//FocusOut already set this... -// else -// setCursor(Qt::ArrowCursor); } void DrawingView::paintEvent(QPaintEvent * /*event*/) @@ -723,16 +681,45 @@ Where is the text offset? It looks like it's drawing in the center, but obvious } // -// This toggles the selection being hovered (typically, only 1 object) +// This toggles the selection being hovered (typically, only 1 object). We +// toggle because the CTRL key might be held, in which case, we want to +// deselect a selected object. // -void DrawingView::AddHoveredToSelection(void) +void DrawingView::HandleSelectionClick(VPVector & v) { - for(VPVectorIter i=document.objects.begin(); i!=document.objects.end(); i++) + if (ctrlDown) + { + for(VPVectorIter i=v.begin(); i!=v.end(); i++) + { + Object * obj = (Object *)(*i); + + if (obj->hovered) + obj->selected = !obj->selected; + } + + return; + } + + for(VPVectorIter i=v.begin(); i!=v.end(); i++) + ((Object *)(*i))->selected = false; + + // Check if the hover changed, and if so, reset the selection stack + if (oldHover.size() != v.size()) { - if (((Object *)(*i))->hovered) -// ((Object *)(*i))->selected = true; - ((Object *)(*i))->selected = !((Object *)(*i))->selected; + oldHover = v; + currentSelect = 0; } + else + { + // Select next object in the stack under the cursor + currentSelect++; + + if (currentSelect >= v.size()) + currentSelect = 0; + } + + dragged = (Object *)v[currentSelect]; + dragged->selected = true; } VPVector DrawingView::GetSelection(void) @@ -1798,7 +1785,6 @@ void DrawingView::mousePressEvent(QMouseEvent * event) { if (event->button() == Qt::LeftButton) { -//printf("mousePressEvent::Qt::LeftButton numHovered=%li\n", numHovered); Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y())); // Handle tool processing, if any @@ -1819,17 +1805,11 @@ void DrawingView::mousePressEvent(QMouseEvent * event) if (!ctrlDown) ClearSelected(document.objects); - // If any objects are being hovered on click, add them to the selection - // & return + // If any objects are being hovered on click, deal with 'em if (numHovered > 0) { - AddHoveredToSelection(); - update(); // needed?? -// GetHovered(hover); // prolly needed VPVector hover2 = GetHovered(); dragged = (Object *)hover2[0]; - draggingObject = true; -//printf("mousePressEvent::numHovered > 0 (hover2[0]=$%llx, type=%s)\n", dragged, objName[dragged->type]); // Alert the pen widget if (Global::penDropper) @@ -1838,26 +1818,27 @@ void DrawingView::mousePressEvent(QMouseEvent * event) Global::penWidth = dragged->thickness; Global::penStyle = dragged->style; emit ObjectSelected(dragged); - ClearSelected(document.objects); return; } - - if (Global::penStamp) + else 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()) + // See if anything is using just a straight click on a custom + // object handle (like Dimension objects) + else if (HandleObjectClicked()) { - draggingObject = false; update(); return; } + draggingObject = true; + HandleSelectionClick(hover2); + update(); // needed?? + // Needed for grab & moving objects // We do it *after*... why? (doesn't seem to confer any advantage...) if (hoveringIntersection) diff --git a/src/drawingview.h b/src/drawingview.h index 136380c..5906766 100644 --- a/src/drawingview.h +++ b/src/drawingview.h @@ -22,7 +22,7 @@ class DrawingView: public QWidget Point SnapPointToGrid(Point); Point SnapPointToAngle(Point); void RenderObjects(Painter *, VPVector &, int, bool ignoreLayer = false); - void AddHoveredToSelection(void); + void HandleSelectionClick(VPVector &); VPVector GetSelection(void); VPVector GetHovered(bool exclude = false); void MoveSelectedToLayer(int); @@ -51,9 +51,6 @@ class DrawingView: public QWidget void HandleLayerToggle(void); void HandleLayerSwap(int, int); void HandleLayerSwap(int, int, VPVector &); - void HandlePenWidth(float); - void HandlePenStyle(int); - void HandlePenColor(uint32_t); void HandlePenStamp(QAction *); void HandlePenDropper(QAction *); @@ -93,12 +90,11 @@ class DrawingView: public QWidget bool supressSelected; QCursor curMarker; QCursor curDropper; + uint32_t currentSelect; public: Container document; uint32_t gridPixels; // Grid size in pixels double gridPixelsF; // Grid size in pixels (float) -// private: - public: bool collided; bool scrollDrag; Vector oldPoint; @@ -110,6 +106,7 @@ class DrawingView: public QWidget VPVector toolObjects; std::vector toolScratch; VPVector toolScratch2; + VPVector oldHover; Point toolPoint[32]; Object * toolObj[32]; double toolParam[32]; diff --git a/src/penwidget.cpp b/src/penwidget.cpp index a20c0a2..65da6bb 100644 --- a/src/penwidget.cpp +++ b/src/penwidget.cpp @@ -11,9 +11,8 @@ // --- ---------- ----------------------------------------------------------- // JLH 05/07/2017 Created this 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 [IN PROGRESS] +// Maybe add a "pen" pallete, to hold most frequently used pen colors/styles +// #include "penwidget.h" @@ -118,7 +117,6 @@ void PenWidget::HandleWidthSelected(QString text) return; Global::penWidth = value; - emit WidthSelected(Global::penWidth); } void PenWidget::HandleStyleSelected(int selected) @@ -130,7 +128,6 @@ void PenWidget::HandleStyleSelected(int selected) // Styles are 1-based, but the combobox is 0-based, so we compensate for // that here Global::penStyle = selected + 1; - emit StyleSelected(Global::penStyle); } void PenWidget::HandleRedSelected(QString text) @@ -144,7 +141,6 @@ void PenWidget::HandleRedSelected(QString text) r = value; Global::penColor = (r << 16) | (g << 8) | b; - emit ColorSelected(Global::penColor); } void PenWidget::HandleGreenSelected(QString text) @@ -158,7 +154,6 @@ void PenWidget::HandleGreenSelected(QString text) g = value; Global::penColor = (r << 16) | (g << 8) | b; - emit ColorSelected(Global::penColor); } void PenWidget::HandleBlueSelected(QString text) @@ -172,5 +167,4 @@ void PenWidget::HandleBlueSelected(QString text) b = value; Global::penColor = (r << 16) | (g << 8) | b; - emit ColorSelected(Global::penColor); } diff --git a/src/penwidget.h b/src/penwidget.h index c08d14b..4fe0d47 100644 --- a/src/penwidget.h +++ b/src/penwidget.h @@ -21,13 +21,8 @@ class PenWidget: public QWidget void HandleRedSelected(QString); void HandleGreenSelected(QString); void HandleBlueSelected(QString); -// void HandleStamp(QAction *); -// void HandleDropper(QAction *); signals: - void WidthSelected(float); - void StyleSelected(int); - void ColorSelected(uint32_t); void StampSelected(void); void DropperSelected(void); -- 2.37.2