Falkon Develop
Cross-platform Qt-based web browser
sbi_zoomwidget.cpp
Go to the documentation of this file.
1/* ============================================================
2* StatusBarIcons - Extra icons in statusbar for Falkon
3* Copyright (C) 2014-2017 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "sbi_zoomwidget.h"
19#include "tabbedwebview.h"
20#include "browserwindow.h"
21#include "tabwidget.h"
22
24 : QSlider(parent)
25 , m_window(parent)
26{
27 setObjectName(QSL("sbi_zoomwidget"));
28 setOrientation(Qt::Horizontal);
29 setFixedWidth(100);
30 setMaximumHeight(20);
31
32 setPageStep(2);
33 setSingleStep(1);
34 setRange(0, WebView::zoomLevels().count() - 1);
35
36 connect(this, SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int)));
37 connect(m_window->tabWidget(), &TabStackedWidget::currentChanged, this, &SBI_ZoomWidget::currentViewChanged);
38
39 currentViewChanged();
40}
41
42void SBI_ZoomWidget::valueChanged(int value)
43{
44 TabbedWebView* view = m_window->weView();
45
46 if (view) {
47 view->setZoomLevel(value);
48 setToolTip(tr("Zoom: %1%").arg(view->zoomFactor() * 100));
49 }
50}
51
52void SBI_ZoomWidget::currentViewChanged()
53{
54 TabbedWebView* view = m_window->weView();
55
56 if (view) {
57 connect(view, &WebView::zoomLevelChanged, this, &QAbstractSlider::setValue);
58 setValue(view->zoomLevel());
59 }
60}
TabWidget * tabWidget() const
TabbedWebView * weView() const
SBI_ZoomWidget(BrowserWindow *parent=nullptr)
void currentChanged(int index)
static QList< int > zoomLevels()
Definition: webview.cpp:264
int zoomLevel() const
Definition: webview.cpp:229
void zoomLevelChanged(int)
void setZoomLevel(int level)
Definition: webview.cpp:234
int value(const QColor &c)
Definition: colors.cpp:238
#define QSL(x)
Definition: qzcommon.h:40