Merge pull request #989 from peetCreative/improve_zoom

fix various problems with zoom-fit-mode
presentation
peetCreative 7 years ago committed by GitHub
commit b5950a4462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 44
      src/control/Control.cpp
  2. 4
      src/control/Control.h
  3. 50
      src/control/zoom/ZoomControl.cpp
  4. 12
      src/control/zoom/ZoomControl.h
  5. 4
      src/control/zoom/ZoomGesture.cpp
  6. 2
      src/enums/ActionGroup.enum.h
  7. 12
      src/gui/MainWindow.cpp
  8. 5
      src/gui/MainWindow.h
  9. 2
      src/gui/toolbarMenubar/ToolMenuHandler.cpp
  10. 7
      src/gui/toolbarMenubar/ToolZoomSlider.cpp

@ -110,7 +110,7 @@ Control::Control(GladeSearchpath* gladeSearchPath)
this->zoom = new ZoomControl();
this->zoom->setZoomStep(this->settings->getZoomStep()/100.0);
this->zoom->setZoomStepScroll(this->settings->getZoomStepScroll()/100.0);
this->zoom->setZoom100(this->settings->getDisplayDpi() / 72.0);
this->zoom->setZoom100Value(this->settings->getDisplayDpi() / 72.0);
this->toolHandler = new ToolHandler(this, this, this->settings);
this->toolHandler->loadSettings();
@ -833,7 +833,7 @@ void Control::actionPerformed(ActionType type, ActionGroup group, GdkEvent* even
case ACTION_ZOOM_IN:
case ACTION_ZOOM_OUT:
Util::execInUiThread([=]() {
zoomCallback(type);
zoomCallback(type, enabled);
});
break;
@ -1534,22 +1534,19 @@ void Control::calcZoomFitSize()
{
return;
}
double width = p->getWidth() + 20;
double page_width = p->getWidth() + 20;
GtkAllocation allocation = {0};
gtk_widget_get_allocation(win->getXournal()->getWidget(), &allocation);
double factor = ((double) allocation.width) / width;
zoom->setZoomFit(factor);
Rectangle widget_rect = zoom->getVisibleRect();
double factor = widget_rect.width / page_width;
zoom->setZoomFitValue(factor);
}
}
void Control::zoomFit()
void Control::setZoomFitButton(bool zoomFit)
{
XOJ_CHECK_TYPE(Control);
calcZoomFitSize();
zoom->zoomFit();
fireActionSelected(GROUP_ZOOM_FIT, zoomFit ? ACTION_ZOOM_FIT : ACTION_NOT_SELECTED);
}
void Control::setViewPairedPages(bool pairedPages)
@ -1722,7 +1719,7 @@ void Control::setViewLayoutB2T(bool b2t)
* On slower machine this feels more fluent, therefore this will not
* be removed
*/
void Control::zoomCallback(ActionType type)
void Control::zoomCallback(ActionType type, bool enabled)
{
XOJ_CHECK_TYPE(Control);
@ -1732,7 +1729,12 @@ void Control::zoomCallback(ActionType type)
zoom->zoom100();
break;
case ACTION_ZOOM_FIT:
zoomFit();
if(enabled)
{
calcZoomFitSize();
}
//enable/disable ZoomFit
zoom->setZoomFitMode(enabled);
break;
case ACTION_ZOOM_IN:
zoom->zoomOneStep(ZOOM_IN);
@ -2137,7 +2139,7 @@ void Control::showSettings()
this->zoom->setZoomStep(settings->getZoomStep() / 100.0);
this->zoom->setZoomStepScroll(settings->getZoomStepScroll() / 100.0);
this->zoom->setZoom100(settings->getDisplayDpi() / 72.0);
this->zoom->setZoom100Value(settings->getDisplayDpi() / 72.0);
getWindow()->getXournal()->getTouchHelper()->reload();
@ -2386,7 +2388,8 @@ void Control::fileLoaded(int scrollToPage)
}
else
{
this->zoom->zoomFit();
calcZoomFitSize();
zoom->setZoomFitMode(true);
}
updateWindowTitle();
@ -2412,7 +2415,16 @@ bool Control::loadMetadataCallback(MetadataCallbackData* data)
return false;
}
ZoomControl* zoom = data->ctrl->zoom;
zoom->setZoom(data->md.zoom * zoom->getZoom100());
if(zoom->isZoomFitMode())
{
data->ctrl->calcZoomFitSize();
zoom->setZoomFitMode(true);
}
else
{
zoom->setZoomFitMode(false);
zoom->setZoom(data->md.zoom * zoom->getZoom100Value());
}
data->ctrl->scrollHandler->scrollToPage(data->md.page);
delete data;

@ -127,6 +127,7 @@ public:
void updateWindowTitle();
void calcZoomFitSize();
void setZoomFitButton(bool enabled);
void setViewPairedPages(bool continous);
void setViewPresentationMode(bool continous);
void setPairsOffset(int numOffset);
@ -263,8 +264,7 @@ protected:
* On slower machine this feels more fluent, therefore this will not
* be removed
*/
void zoomCallback(ActionType type);
void zoomFit();
void zoomCallback(ActionType type, bool enabled);
void rotationSnappingToggle();
void gridSnappingToggle();

@ -1,5 +1,6 @@
#include "ZoomControl.h"
#include "control/Control.h"
#include "gui/Layout.h"
#include "gui/PageView.h"
#include "gui/widgets/XournalWidget.h"
@ -28,7 +29,10 @@ void ZoomControl::zoomOneStep(bool zoomIn, double x, double y)
startZoomSequence(x, y);
this->zoomFitMode = false;
if (this->zoomFitMode)
{
this->setZoomFitMode(false);
}
double newZoom;
if (zoomIn)
{
@ -47,6 +51,11 @@ void ZoomControl::zoomScroll(bool zoomIn, double x, double y)
{
XOJ_CHECK_TYPE(ZoomControl);
if (this->zoomFitMode)
{
this->setZoomFitMode(false);
}
if (this->zoomSequenceStart == -1 || scrollCursorPositionX != x || scrollCursorPositionY != y)
{
scrollCursorPositionX = x;
@ -54,7 +63,6 @@ void ZoomControl::zoomScroll(bool zoomIn, double x, double y)
startZoomSequence(x, y);
}
this->zoomFitMode = false;
double newZoom;
if (zoomIn)
{
@ -232,11 +240,10 @@ void ZoomControl::setZoom(double zoom)
XOJ_CHECK_TYPE(ZoomControl);
this->zoom = zoom;
this->zoomFitMode = false;
fireZoomChanged();
}
void ZoomControl::setZoom100(double zoom)
void ZoomControl::setZoom100Value(double zoom)
{
XOJ_CHECK_TYPE(ZoomControl);
@ -248,27 +255,22 @@ void ZoomControl::setZoom100(double zoom)
fireZoomRangeValueChanged();
}
void ZoomControl::setZoomFit(double zoom)
void ZoomControl::setZoomFitValue(double zoom)
{
XOJ_CHECK_TYPE(ZoomControl);
this->zoomFitValue = zoom;
fireZoomRangeValueChanged();
if (this->zoomFitMode)
{
zoomFit();
}
}
double ZoomControl::getZoomFit()
double ZoomControl::getZoomFitValue()
{
XOJ_CHECK_TYPE(ZoomControl);
return this->zoomFitValue;
}
double ZoomControl::getZoom100()
double ZoomControl::getZoom100Value()
{
XOJ_CHECK_TYPE(ZoomControl);
@ -279,21 +281,33 @@ void ZoomControl::zoom100()
{
XOJ_CHECK_TYPE(ZoomControl);
this->zoomFitMode = false;
if(this->zoomFitMode)
{
this->setZoomFitMode(false);
}
startZoomSequence(-1, -1);
this->zoomSequnceChange(this->zoom100Value, false);
endZoomSequence();
}
void ZoomControl::zoomFit()
void ZoomControl::setZoomFitMode(bool isZoomFitMode)
{
XOJ_CHECK_TYPE(ZoomControl);
this->zoomFitMode = true;
startZoomSequence(-1, -1);
this->zoomSequnceChange(this->zoomFitValue, false);
endZoomSequence();
this->zoomFitMode = isZoomFitMode;
if(isZoomFitMode)
{
startZoomSequence(-1, -1);
this->zoomSequnceChange(this->zoomFitValue, false);
endZoomSequence();
}
this->view->getControl()->setZoomFitButton(isZoomFitMode);
}
bool ZoomControl::isZoomFitMode()
{
return this->zoomFitMode;
}
double ZoomControl::getZoomStep()

@ -55,8 +55,8 @@ public:
/**
* Zoom so that the page fits the current size of the window
*/
void zoomFit();
void setZoomFitMode(bool isZoomFitMode);
bool isZoomFitMode();
/**
* Zoom so that the displayed page on the screen has the same size as the real size
* The dpi has to be set correctly
@ -88,11 +88,11 @@ public:
*
* @param zoom zoom value depending zoom100Value
*/
void setZoom100(double zoom);
void setZoomFit(double zoom);
void setZoom100Value(double zoom);
void setZoomFitValue(double zoom);
double getZoomFit();
double getZoom100();
double getZoomFitValue();
double getZoom100Value();
void addZoomListener(ZoomListener* listener);

@ -62,6 +62,10 @@ void ZoomGesture::zoomBegin()
Rectangle zoomSequenceRectangle = zoomControl->getVisibleRect();
if(zoomControl->isZoomFitMode())
{
zoomControl->setZoomFitMode(false);
}
zoomControl->startZoomSequence(x - zoomSequenceRectangle.x, y - zoomSequenceRectangle.y);
}

@ -65,6 +65,8 @@ enum ActionGroup
GROUP_LAYOUT_LR,
GROUP_LAYOUT_TB,
GROUP_ZOOM_FIT,
};
ActionGroup ActionGroup_fromString(string value);

@ -53,6 +53,7 @@ MainWindow::MainWindow(GladeSearchpath* gladeSearchPath, Control* control)
// Window handler
g_signal_connect(this->window, "delete-event", G_CALLBACK(deleteEventCallback), this->control);
g_signal_connect(this->window, "configure-event", G_CALLBACK(configureEventCallback), this->control);
g_signal_connect(this->window, "window_state_event", G_CALLBACK(windowStateEventCallback), this);
g_signal_connect(get("buttonCloseSidebar"), "clicked", G_CALLBACK(buttonCloseSidebarClicked), this);
@ -568,6 +569,17 @@ bool MainWindow::deleteEventCallback(GtkWidget* widget, GdkEvent* event, Control
return true;
}
bool MainWindow::configureEventCallback(GtkWidget* widget, GdkEventConfigure* event, Control* control)
{
control->calcZoomFitSize();
ZoomControl *zoom = control->getZoomControl();
if(zoom->isZoomFitMode())
{
zoom->setZoomFitMode(true);
}
return false;
}
void MainWindow::setSidebarVisible(bool visible)
{
XOJ_CHECK_TYPE(MainWindow);

@ -116,6 +116,11 @@ private:
*/
static bool deleteEventCallback(GtkWidget* widget, GdkEvent* event, Control* control);
/**
* Window has been moved or resized. Needed for Zoomfit
*/
static bool configureEventCallback(GtkWidget* widget, GdkEventConfigure* event, Control* control);
/**
* Key is pressed
*/

@ -422,7 +422,7 @@ void ToolMenuHandler::initToolItems()
ADD_STOCK_ITEM("ZOOM_OUT", ACTION_ZOOM_OUT, "zoom-out", _("Zoom out"));
ADD_STOCK_ITEM("ZOOM_IN", ACTION_ZOOM_IN, "zoom-in", _("Zoom in"));
ADD_STOCK_ITEM("ZOOM_FIT", ACTION_ZOOM_FIT, "zoom-fit-best", _("Zoom fit to screen"));
ADD_CUSTOM_ITEM_TGL("ZOOM_FIT", ACTION_ZOOM_FIT, GROUP_ZOOM_FIT, false, "zoom-fit-best", _("Zoom fit to screen"));
ADD_STOCK_ITEM("ZOOM_100", ACTION_ZOOM_100, "zoom-original", _("Zoom to 100%"));
// Menu Navigation

@ -30,7 +30,7 @@ void ToolZoomSlider::sliderChanged(GtkRange* range, ToolZoomSlider* self)
return;
}
double back = self->zoom->getZoom100() * scaleFuncInv(gtk_range_get_value(range));
double back = self->zoom->getZoom100Value() * scaleFuncInv(gtk_range_get_value(range));
self->zoom->zoomSequnceChange(back, false);
}
@ -41,6 +41,7 @@ bool ToolZoomSlider::sliderButtonPress(GtkRange* range, GdkEvent *event, ToolZoo
if(!self->sliderChangingByUser)
{
self->sliderChangingByUser = true;
self->zoom->setZoomFitMode(false);
self->zoom->startZoomSequence(-1, -1);
}
return false;
@ -110,8 +111,8 @@ void ToolZoomSlider::updateScaleMarks()
}
gtk_scale_clear_marks(GTK_SCALE(this->slider));
gtk_scale_add_mark(GTK_SCALE(this->slider), zoom->getZoom100(), horizontal ? GTK_POS_BOTTOM : GTK_POS_RIGHT, NULL);
gtk_scale_add_mark(GTK_SCALE(this->slider), zoom->getZoomFit(), horizontal ? GTK_POS_BOTTOM : GTK_POS_RIGHT, NULL);
gtk_scale_add_mark(GTK_SCALE(this->slider), scaleFunc(zoom->getZoom100Value()), horizontal ? GTK_POS_BOTTOM : GTK_POS_RIGHT, NULL);
gtk_scale_add_mark(GTK_SCALE(this->slider), scaleFunc(zoom->getZoomFitValue()), horizontal ? GTK_POS_BOTTOM : GTK_POS_RIGHT, NULL);
}
GtkToolItem* ToolZoomSlider::createItem(bool horizontal)

Loading…
Cancel
Save