diff --git a/src/control/ScrollHandler.cpp b/src/control/ScrollHandler.cpp index f48d392a..6c1c5d62 100644 --- a/src/control/ScrollHandler.cpp +++ b/src/control/ScrollHandler.cpp @@ -33,7 +33,7 @@ void ScrollHandler::goToPreviousPage() double disHeight = this->control->getWindow()->getLayout()->getDisplayHeight(); double top = (dHeight - disHeight) / 2.0 + 7.5; //the magic 7.5 is from XOURNAL_PADDING_BETWEEN/2 - scrollToPage(this->control->getWindow()->getXournal()->getCurrentPage() - 1, top); + scrollToPage(this->control->getWindow()->getXournal()->getCurrentPage() - 1, 0); } } else @@ -60,7 +60,7 @@ void ScrollHandler::goToNextPage() //this gets reversed when we are going down if the page is smaller than the display height double top = (-dHeight + disHeight) / 2.0 - 7.5; //the magic 7.5 is from XOURNAL_PADDING_BETWEEN/2 - scrollToPage(this->control->getWindow()->getXournal()->getCurrentPage() + 1, top); + scrollToPage(this->control->getWindow()->getXournal()->getCurrentPage() + 1, 0); } } else diff --git a/src/gui/Layout.cpp b/src/gui/Layout.cpp index 2f6ac283..fe673ab6 100644 --- a/src/gui/Layout.cpp +++ b/src/gui/Layout.cpp @@ -179,8 +179,6 @@ void Layout::layoutPages() { XOJ_CHECK_TYPE(Layout); - int y = 0; - int len = this->view->viewPagesLen; Settings* settings = this->view->getControl()->getSettings(); @@ -188,6 +186,11 @@ void Layout::layoutPages() bool horizontalSpace = settings->getAddHorizontalSpace(); bool dualPage = settings->isShowTwoPages(); + int padding = XOURNAL_PADDING; + + if (settings->isPresentationMode()) { + padding = 0; + } int size[2] = { 0, 0 }; // we need at least 2 page for dual page view @@ -218,25 +221,27 @@ void Layout::layoutPages() int marginRight = 0; int marginTop = 0; int marginBottom = 0; + int width = padding + size[0]; + int y = padding; - y += XOURNAL_PADDING; - - int width = XOURNAL_PADDING + size[0]; if (dualPage) { - width += XOURNAL_PADDING_BETWEEN + size[1] + XOURNAL_PADDING; + width += XOURNAL_PADDING_BETWEEN + size[1] + padding; } else { - width += XOURNAL_PADDING; + width += padding; } GtkAllocation alloc; gtk_widget_get_allocation(this->view->getWidget(), &alloc); marginLeft = marginRight = (alloc.width - width) / 2; - marginLeft = MAX(marginLeft, 10); - marginRight = MAX(marginRight, 10); + int minMargin = 10; + if (settings->isPresentationMode()) + minMargin = 0; + marginLeft = MAX(marginLeft, minMargin); + marginRight = MAX(marginRight, minMargin); if (horizontalSpace) { @@ -277,7 +282,7 @@ void Layout::layoutPages() */ if (i == 0) { - int x = XOURNAL_PADDING + size[0] + XOURNAL_PADDING_BETWEEN; + int x = padding + size[0] + XOURNAL_PADDING_BETWEEN; v->layout.setX(x); v->layout.setY(y); @@ -303,7 +308,7 @@ void Layout::layoutPages() } // left page, align right - int x1 = XOURNAL_PADDING + (size[0] - v->getDisplayWidth()); + int x1 = padding + (size[0] - v->getDisplayWidth()); v->layout.setX(x1); v->layout.setY(y); v->layout.setMarginLeft(marginLeft); @@ -312,7 +317,7 @@ void Layout::layoutPages() // if right page available, align left if (v2 != NULL) { - int x2 = XOURNAL_PADDING + size[0] + XOURNAL_PADDING_BETWEEN; + int x2 = padding + size[0] + XOURNAL_PADDING_BETWEEN; v2->layout.setX(x2); v2->layout.setY(y); @@ -331,7 +336,7 @@ void Layout::layoutPages() * [===] * [=] */ - int x = (size[0] - v->getDisplayWidth()) / 2 + XOURNAL_PADDING; + int x = padding + (size[0] - v->getDisplayWidth()) / 2; v->layout.setX(x); v->layout.setY(y); @@ -341,12 +346,10 @@ void Layout::layoutPages() height = v->getDisplayHeight(); } - y += height; - - y += XOURNAL_PADDING_BETWEEN + verticalSpaceBetweenSlides; + y += height + padding + verticalSpaceBetweenSlides; } - int height = marginTop + XOURNAL_PADDING + y + XOURNAL_PADDING + marginBottom; + int height = marginTop + y + marginBottom + padding; this->setLayoutSize(marginLeft + width + marginRight, height); this->view->pagePosition->update(this->view->viewPages, len, height); @@ -451,8 +454,14 @@ void Layout::ensureRectIsVisible(int x, int y, int width, int height) { XOJ_CHECK_TYPE(Layout); - this->scrollHorizontal->ensureAreaIsVisible(x - 5, x + width + 10); - this->scrollVertical->ensureAreaIsVisible(y - 5, y + height + 10); + // Don't add extra room when presenting + if(this->view->getControl()->getSettings()->isPresentationMode()) { + this->scrollHorizontal->ensureAreaIsVisible(x, x + width); + this->scrollVertical->ensureAreaIsVisible(y, y + height); + } else { + this->scrollHorizontal->ensureAreaIsVisible(x - 5, x + width + 10); + this->scrollVertical->ensureAreaIsVisible(y - 5, y + height + 10); + } } bool Layout::scrollEvent(GdkEventScroll* event) diff --git a/src/gui/XournalView.cpp b/src/gui/XournalView.cpp index 27b59229..a2256481 100644 --- a/src/gui/XournalView.cpp +++ b/src/gui/XournalView.cpp @@ -246,12 +246,22 @@ bool XournalView::onKeyPressEvent(GdkEventKey* event) if (event->keyval == GDK_Left) { + if (control->getSettings()->isPresentationMode()) + { + control->getScrollHandler()->goToPreviousPage(); + return true; + } layout->scrollRelativ(-scrollKeySize, 0); return true; } if (event->keyval == GDK_Right) { + if (control->getSettings()->isPresentationMode()) + { + control->getScrollHandler()->goToNextPage(); + return true; + } layout->scrollRelativ(scrollKeySize, 0); return true; } @@ -633,6 +643,18 @@ double XournalView::getZoom() { XOJ_CHECK_TYPE(XournalView); + size_t p = getCurrentPage(); + if (p != size_t_npos && p < viewPagesLen) + { + PageView* page = viewPages[p]; + if (this->getControl()->getSettings()->isPresentationMode()) + { + double heightZoom = this->getDisplayHeight() / page->getHeight(); + double widthZoom = this->getDisplayWidth() / page->getWidth(); + return (heightZoom < widthZoom) ? heightZoom : widthZoom; + } + } + return control->getZoomControl()->getZoom(); } @@ -758,6 +780,22 @@ void XournalView::layoutPages() layout->layoutPages(); } +int XournalView::getDisplayHeight() const { + XOJ_CHECK_TYPE(XournalView); + + GtkAllocation allocation = { 0 }; + gtk_widget_get_allocation(this->widget, &allocation); + return allocation.height; +} + +int XournalView::getDisplayWidth() const { + XOJ_CHECK_TYPE(XournalView); + + GtkAllocation allocation = { 0 }; + gtk_widget_get_allocation(this->widget, &allocation); + return allocation.width; +} + bool XournalView::isPageVisible(int page, int* visibleHeight) { XOJ_CHECK_TYPE(XournalView); diff --git a/src/gui/XournalView.h b/src/gui/XournalView.h index 82e6f6c8..5a9204cc 100644 --- a/src/gui/XournalView.h +++ b/src/gui/XournalView.h @@ -77,6 +77,9 @@ public: void resetShapeRecognizer(); + int getDisplayWidth() const; + int getDisplayHeight() const; + bool isPageVisible(int page, int* visibleHeight); void ensureRectIsVisible(int x, int y, int width, int heigth);