From 46152144132f5e915c8a4a90f903c4f477ebff15 Mon Sep 17 00:00:00 2001 From: Yoann Laissus Date: Thu, 16 Aug 2012 14:59:53 +0200 Subject: - Choose the correct MainView in ZoomBar::updateSlider() It fixes issue for the first tab of new windows in case of a "wheel" zoom. - Move the zoom bounding logic from WebView::wheelEvent() to ZoomBar::setValue() It'll avoid Ctrl -/+ to exceed the max value of the slider - Use the round() method instead of my previous hack to compute zoom ratio for wheel events --- src/webview.cpp | 11 +---------- src/zoombar.cpp | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/webview.cpp b/src/webview.cpp index 00112d61..7272e2c2 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -864,17 +864,8 @@ void WebView::wheelEvent(QWheelEvent *event) // Sync with the zoom slider if (event->modifiers() == Qt::ControlModifier) { - // Limits of the slider - if (zoomFactor() > 1.9) - setZoomFactor(1.9); - else if (zoomFactor() < 0.1) - setZoomFactor(0.1); - // Round the factor (Fix slider's end value) - int newFactor = zoomFactor() * 10; - if ((zoomFactor() * 10 - newFactor) > 0.5) - newFactor++; - + int newFactor = round(zoomFactor() * 10); emit zoomChanged(newFactor); } else if (ReKonfig::smoothScrolling() && prevPos != newPos) diff --git a/src/zoombar.cpp b/src/zoombar.cpp index 292ef413..2cf30617 100644 --- a/src/zoombar.cpp +++ b/src/zoombar.cpp @@ -159,8 +159,10 @@ void ZoomBar::zoomNormal() void ZoomBar::updateSlider(int webview) { WebTab *tab = 0; - if (!rApp->mainWindowList().isEmpty()) - tab = rApp->mainWindow()->mainView()->webTab(webview); + MainView *mainView = static_cast(sender()); + + if (mainView) + tab = mainView->webTab(webview); if (!tab) return; @@ -172,12 +174,24 @@ void ZoomBar::updateSlider(int webview) void ZoomBar::setValue(int value) { - m_zoomSlider->setValue(value); - m_percentage->setText(i18nc("percentage of the website zoom", "%1%", QString::number(value * 10))); + int boundedValue = value; + + // Don't exceed the slider min/max value + if (value < 1) + { + boundedValue = 1; + } + else if (value > 19) + { + boundedValue = 19; + } + + m_zoomSlider->setValue(boundedValue); + m_percentage->setText(i18nc("percentage of the website zoom", "%1%", QString::number(boundedValue * 10))); WebTab *tab = rApp->mainWindow()->currentTab(); - saveZoomValue(tab->url().host(), value); - tab->view()->setZoomFactor(QVariant(value).toReal() / 10); // Don't allox max +1 values + saveZoomValue(tab->url().host(), boundedValue); + tab->view()->setZoomFactor(QVariant(boundedValue).toReal() / 10); // Don't allox max +1 values } -- cgit v1.2.1