From 63e601ee51a379727ab66b8395b4680fd28da68a Mon Sep 17 00:00:00 2001 From: JJones780 Date: Thu, 18 Apr 2019 20:02:02 -0600 Subject: [PATCH] Add Delete button alongside Selection editing handles - handy for keyboardless users. --- src/control/tools/CursorSelectionType.h | 1 + src/control/tools/EditSelection.cpp | 53 +++++++++++++++++++++---- src/control/tools/EditSelection.h | 9 +++++ src/gui/Cursor.cpp | 3 ++ 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/control/tools/CursorSelectionType.h b/src/control/tools/CursorSelectionType.h index 5895dc4a..78a021c9 100644 --- a/src/control/tools/CursorSelectionType.h +++ b/src/control/tools/CursorSelectionType.h @@ -29,4 +29,5 @@ enum CursorSelectionType CURSOR_SELECTION_TOP, CURSOR_SELECTION_BOTTOM, CURSOR_SELECTION_ROTATE, + CURSOR_SELECTION_DELETE }; diff --git a/src/control/tools/EditSelection.cpp b/src/control/tools/EditSelection.cpp index ac0df2f0..aee4f0ed 100644 --- a/src/control/tools/EditSelection.cpp +++ b/src/control/tools/EditSelection.cpp @@ -389,14 +389,22 @@ void EditSelection::mouseUp() { XOJ_CHECK_TYPE(EditSelection); - PageRef page = this->view->getPage(); - Layer* layer = page->getSelectedLayer(); - - snapRotation(); + + if (this->mouseDownType == CURSOR_SELECTION_DELETE ) + { + this->view->getXournal()->deleteSelection(); + + } + else + { + PageRef page = this->view->getPage(); + Layer* layer = page->getSelectedLayer(); - this->contents->updateContent(this->x, this->y, this->rotation, this->width, this->height, this->aspectRatio, - layer, page, this->view, this->undo, this->mouseDownType); + snapRotation(); + this->contents->updateContent(this->x, this->y, this->rotation, this->width, this->height, this->aspectRatio, + layer, page, this->view, this->undo, this->mouseDownType); + } this->mouseDownType = CURSOR_SELECTION_NONE; } @@ -690,6 +698,12 @@ CursorSelectionType EditSelection::getSelectionTypeForPos(double x, double y, do return CURSOR_SELECTION_BOTTOM_RIGHT; } + if ( (((x2-x1)*3.0)/4.0) + x1 - 4*zoom <=x && (((x2-x1)*3.0)/4.0) + x1 + 4*zoom >=x && (y1-10*zoom) - 4*zoom <= y && (y1-10*zoom) + 4*zoom >= y) + { + return CURSOR_SELECTION_DELETE; + } + + if (supportRotation && x2 + BORDER_PADDING + 4 <= x && x <= x2 + BORDER_PADDING + 16 && (y2 + y1) / 2 - 4 <= y && (y2 + y1) / 2 + 4 >= y) { return CURSOR_SELECTION_ROTATE; @@ -758,7 +772,7 @@ void EditSelection::snapRotation() /** * Paints the selection to cr, with the given zoom factor. The coordinates of cr - * should be relative to the provideded view by getView() (use translateEvent()) + * should be relative to the provided view by getView() (use translateEvent()) */ void EditSelection::paint(cairo_t* cr, double zoom) { @@ -832,6 +846,9 @@ void EditSelection::paint(cairo_t* cr, double zoom) drawAnchorRect(cr, x, y + height, zoom); // bottom right drawAnchorRect(cr, x + width, y + height, zoom); + + + drawDeleteRect(cr, x + (3 * width)/4, y - 10 , zoom); } void EditSelection::drawAnchorRotation(cairo_t* cr, double x, double y, double zoom) @@ -861,6 +878,28 @@ void EditSelection::drawAnchorRect(cairo_t* cr, double x, double y, double zoom) cairo_fill(cr); } + +/** + * draws an idicator where you can delete the selection + */ +void EditSelection::drawDeleteRect(cairo_t* cr, double x, double y, double zoom) +{ + XOJ_CHECK_TYPE(EditSelection); + + cairo_set_source_rgb(cr, 0, 0, 0); + cairo_rectangle(cr, x * zoom - 4, y * zoom - 4, 8, 8); + cairo_stroke(cr); + cairo_set_source_rgb(cr, 1, 0, 0); + cairo_move_to(cr, x * zoom - 4, y * zoom - 4); + cairo_rel_move_to(cr, 8,0); + cairo_rel_line_to(cr, -8,8); + cairo_rel_move_to(cr, 8,0); + cairo_rel_line_to(cr, -8,-8); + cairo_stroke(cr); +} + + + XojPageView* EditSelection::getView() { XOJ_CHECK_TYPE(EditSelection); diff --git a/src/control/tools/EditSelection.h b/src/control/tools/EditSelection.h index af7cfe90..df7a58fc 100644 --- a/src/control/tools/EditSelection.h +++ b/src/control/tools/EditSelection.h @@ -212,6 +212,15 @@ private: */ void drawAnchorRotation(cairo_t* cr, double x, double y, double zoom); + + /** + * Draws an indicator where you can delete the selection + */ + void drawDeleteRect(cairo_t* cr, double x, double y, double zoom); + + + + /** * Finishes all pending changes, move the elements, scale the elements and add * them to new layer if any or to the old if no new layer diff --git a/src/gui/Cursor.cpp b/src/gui/Cursor.cpp index f73f7184..1b839cba 100644 --- a/src/gui/Cursor.cpp +++ b/src/gui/Cursor.cpp @@ -183,6 +183,9 @@ void Cursor::updateCursor() case CURSOR_SELECTION_ROTATE: cursor = gdk_cursor_new_for_display(gdk_window_get_display(window), GDK_EXCHANGE); break; + case CURSOR_SELECTION_DELETE: + cursor = gdk_cursor_new_for_display(gdk_window_get_display(window), GDK_PIRATE); + break; case CURSOR_SELECTION_TOP: case CURSOR_SELECTION_BOTTOM: cursor = gdk_cursor_new_for_display(gdk_window_get_display(window), GDK_SB_V_DOUBLE_ARROW);