From 5253b08fab061d23380bbdea04cc3b13e6d55742 Mon Sep 17 00:00:00 2001 From: JJones780 Date: Thu, 28 Mar 2019 18:11:55 -0600 Subject: [PATCH 1/2] Store Mapper assigned row,col in PageView and expose mapper function to allow easy directional navigation of pages. --- src/gui/Layout.cpp | 8 ++++++++ src/gui/Layout.h | 6 ++++++ src/gui/PageView.cpp | 25 +++++++++++++++++++++++++ src/gui/PageView.h | 25 +++++++++++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/src/gui/Layout.cpp b/src/gui/Layout.cpp index 5bca0149..f425dec3 100644 --- a/src/gui/Layout.cpp +++ b/src/gui/Layout.cpp @@ -271,6 +271,7 @@ void Layout::layoutPages() { XojPageView* v = this->view->viewPages[pageAtRowCol]; + v->setMappedRowCol( r,c ); //store row and column for e.g. proper arrow key navigation int vDisplayWidth = v->getDisplayWidth(); { int paddingLeft; @@ -485,3 +486,10 @@ XojPageView* Layout::getViewAt(int x, int y) } + + +int Layout::getIndexAtGridMap(int row, int col) +{ + return this->mapper.map( col, row); //watch out.. x,y --> c,r + +} diff --git a/src/gui/Layout.h b/src/gui/Layout.h index d574ff86..82fa9f3c 100644 --- a/src/gui/Layout.h +++ b/src/gui/Layout.h @@ -95,6 +95,12 @@ public: */ XojPageView* getViewAt(int x, int y); + /** + * Return the page index found ( or -1 if not found) at layout grid row,col + * + */ + int getIndexAtGridMap(int row, int col); + private: void checkScroll(GtkAdjustment* adjustment, double& lastScroll); diff --git a/src/gui/PageView.cpp b/src/gui/PageView.cpp index cc375675..468504f0 100644 --- a/src/gui/PageView.cpp +++ b/src/gui/PageView.cpp @@ -934,6 +934,31 @@ void XojPageView::setY( int y ) this->dispY = y; } +void XojPageView::setMappedRowCol(int row, int col ) +{ + XOJ_CHECK_TYPE(XojPageView); + + this->mappedRow = row; + this->mappedCol = col; +} + + +int XojPageView::getMappedRow() +{ + XOJ_CHECK_TYPE(XojPageView); + + return this->mappedRow; +} + + +int XojPageView::getMappedCol() +{ + XOJ_CHECK_TYPE(XojPageView); + + return this->mappedCol; +} + + PageRef XojPageView::getPage() { XOJ_CHECK_TYPE(XojPageView); diff --git a/src/gui/PageView.h b/src/gui/PageView.h index a9ca6964..6bc1c66b 100644 --- a/src/gui/PageView.h +++ b/src/gui/PageView.h @@ -77,6 +77,17 @@ public: */ bool containsPoint(int x, int y, bool local = false); bool containsY(int y); + + /** + * Returns Row assigned in current layout + */ + int getMappedRow(); + + /** + * Returns Column assigned in current layout + */ + int getMappedCol(); + GtkColorWrapper getSelectionColor(); int getBufferPixels(); @@ -169,6 +180,11 @@ private: void setX(int x); void setY(int y); + void setMappedRowCol(int row, int col ); //row, column assigned by mapper during layout. + + + + private: XOJ_TYPE_ATTRIB; @@ -223,10 +239,19 @@ private: int dispX; //position on display - set in Layout::layoutPages int dispY; + + int mappedRow; + int mappedCol; + + friend class RenderJob; friend class InputHandler; friend class BaseSelectObject; friend class SelectObject; friend class PlayObject; +<<<<<<< HEAD friend void Layout::layoutPages(); //only function allowed to setX(), setY() +======= + friend void Layout::layoutPages(); //only function allowed to setMappedRowCol() +>>>>>>> d0560ff... Store Mapper assigned row,col in PageView and expose mapper function to allow easy directional navigation of pages. }; From d1de8891a93c63bc0aa3dc7b2ef014dc34e394d2 Mon Sep 17 00:00:00 2001 From: JJones780 Date: Fri, 29 Mar 2019 00:43:15 -0600 Subject: [PATCH 2/2] Shifted or numpad Arrow keys call new Directional Page changes. can_set_focus(zoom control, false ) --- src/gui/MainWindow.cpp | 26 ------- src/gui/PageView.h | 6 +- src/gui/XournalView.cpp | 91 +++++++++++++++++++++-- src/gui/XournalView.h | 3 + src/gui/toolbarMenubar/ToolZoomSlider.cpp | 2 + 5 files changed, 89 insertions(+), 39 deletions(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 38ae33ea..1557c02a 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -532,32 +532,6 @@ bool MainWindow::onKeyPressCallback(GtkWidget* widget, GdkEventKey* event, MainW //editing text - give that control return false; } - else if (event->keyval == GDK_KEY_Down) - { - if (win->getControl()->getSettings()->isPresentationMode()) - { - win->getControl()->getScrollHandler()->goToNextPage(); - return true; - } - else - { - win->getLayout()->scrollRelativ(0, 30); - return true; - } - } - else if (event->keyval == GDK_KEY_Up) - { - if (win->getControl()->getSettings()->isPresentationMode()) - { - win->getControl()->getScrollHandler()->goToPreviousPage(); - return true; - } - else - { - win->getLayout()->scrollRelativ(0, -30); - return true; - } - } else if (event->keyval == GDK_KEY_Escape) { win->getControl()->getSearchBar()->showSearchBar(false); diff --git a/src/gui/PageView.h b/src/gui/PageView.h index 6bc1c66b..a28c1c8f 100644 --- a/src/gui/PageView.h +++ b/src/gui/PageView.h @@ -249,9 +249,5 @@ private: friend class BaseSelectObject; friend class SelectObject; friend class PlayObject; -<<<<<<< HEAD - friend void Layout::layoutPages(); //only function allowed to setX(), setY() -======= - friend void Layout::layoutPages(); //only function allowed to setMappedRowCol() ->>>>>>> d0560ff... Store Mapper assigned row,col in PageView and expose mapper function to allow easy directional navigation of pages. + friend void Layout::layoutPages(); //only function allowed to setX(), setY(), setMappedRowCol() }; diff --git a/src/gui/XournalView.cpp b/src/gui/XournalView.cpp index d5c142fa..9c5d6e87 100644 --- a/src/gui/XournalView.cpp +++ b/src/gui/XournalView.cpp @@ -207,12 +207,12 @@ bool XournalView::onKeyPressEvent(GdkEventKey* event) } else { - if (event->keyval == GDK_KEY_Page_Down) + if (event->keyval == GDK_KEY_Page_Down || event->keyval == GDK_KEY_KP_Page_Down) { control->getScrollHandler()->goToNextPage(); return true; } - if (event->keyval == GDK_KEY_Page_Up) + if (event->keyval == GDK_KEY_Page_Up || event->keyval == GDK_KEY_KP_Page_Up) { control->getScrollHandler()->goToPreviousPage(); return true; @@ -228,6 +228,32 @@ bool XournalView::onKeyPressEvent(GdkEventKey* event) return true; } + //Numeric keypad always navigates by page + if (event->keyval == GDK_KEY_KP_Up) + { + this->pageRelativeXY(0,-1); + return true; + } + + if (event->keyval == GDK_KEY_KP_Down) + { + this->pageRelativeXY(0,1); + return true; + } + + if (event->keyval == GDK_KEY_KP_Left) + { + this->pageRelativeXY(-1, 0); + return true; + } + + if (event->keyval == GDK_KEY_KP_Right) + { + this->pageRelativeXY(1,0); + return true; + } + + if (event->keyval == GDK_KEY_Up) { if (control->getSettings()->isPresentationMode()) @@ -237,7 +263,14 @@ bool XournalView::onKeyPressEvent(GdkEventKey* event) } else { - layout->scrollRelativ(0, -scrollKeySize); + if (state & GDK_SHIFT_MASK) + { + this->pageRelativeXY(0,-1); + } + else + { + layout->scrollRelativ(0, -scrollKeySize); + } return true; } } @@ -251,30 +284,51 @@ bool XournalView::onKeyPressEvent(GdkEventKey* event) } else { - layout->scrollRelativ(0, scrollKeySize); + if (state & GDK_SHIFT_MASK) + { + this->pageRelativeXY(0,1); + } + else + { + layout->scrollRelativ(0, scrollKeySize); + } return true; } } if (event->keyval == GDK_KEY_Left) { - control->getScrollHandler()->goToPreviousPage(); + if (state & GDK_SHIFT_MASK) + { + this->pageRelativeXY(-1,0); + } + else + { + layout->scrollRelativ(-scrollKeySize, 0); + } return true; } if (event->keyval == GDK_KEY_Right) { - control->getScrollHandler()->goToNextPage(); + if (state & GDK_SHIFT_MASK) + { + this->pageRelativeXY(1,0); + } + else + { + layout->scrollRelativ(scrollKeySize, 0); + } return true; } - if (event->keyval == GDK_KEY_End) + if (event->keyval == GDK_KEY_End || event->keyval == GDK_KEY_KP_End) { control->getScrollHandler()->goToLastPage(); return true; } - if (event->keyval == GDK_KEY_Home) + if (event->keyval == GDK_KEY_Home || event->keyval == GDK_KEY_KP_Home) { control->getScrollHandler()->goToFirstPage(); return true; @@ -456,6 +510,27 @@ void XournalView::scrollTo(size_t pageNo, double yDocument) control->firePageSelected(pageNo); } + +void XournalView::pageRelativeXY(int offCol, int offRow) +{ + XOJ_CHECK_TYPE(XournalView); + + int currPage = getCurrentPage(); + + XojPageView* view = getViewFor(currPage ); + int row = view->getMappedRow(); + int col = view->getMappedCol(); + + Layout* layout = gtk_xournal_get_layout(this->widget); + int page = layout->getIndexAtGridMap(row +offRow ,col + offCol); + if( page >=0) + { + this-> scrollTo(page, 0); + } + +} + + void XournalView::endTextAllPages(XojPageView* except) { XOJ_CHECK_TYPE(XournalView); diff --git a/src/gui/XournalView.h b/src/gui/XournalView.h index 3f4d4451..5f86a5d9 100644 --- a/src/gui/XournalView.h +++ b/src/gui/XournalView.h @@ -51,6 +51,9 @@ public: void layoutPages(); void scrollTo(size_t pageNo, double y); + + //Relative navigation in current layout: + void pageRelativeXY(int offCol, int offRow ); size_t getCurrentPage(); diff --git a/src/gui/toolbarMenubar/ToolZoomSlider.cpp b/src/gui/toolbarMenubar/ToolZoomSlider.cpp index 957053ab..c6abd2d2 100644 --- a/src/gui/toolbarMenubar/ToolZoomSlider.cpp +++ b/src/gui/toolbarMenubar/ToolZoomSlider.cpp @@ -199,6 +199,8 @@ GtkToolItem* ToolZoomSlider::newItem() g_signal_connect(this->slider, "format-value", G_CALLBACK(sliderFormatValue), this); gtk_scale_set_draw_value(GTK_SCALE(this->slider), true); + gtk_widget_set_can_focus(this->slider, false); + if (this->horizontal) { gtk_widget_set_size_request(GTK_WIDGET(this->slider), 120, 16);