File indexing completed on 2024-05-19 04:59:19

0001 /* ============================================================
0002 * StatusBarIcons - Extra icons in statusbar for Falkon
0003 * Copyright (C) 2014-2017 David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #include "sbi_zoomwidget.h"
0019 #include "tabbedwebview.h"
0020 #include "browserwindow.h"
0021 #include "tabwidget.h"
0022 
0023 SBI_ZoomWidget::SBI_ZoomWidget(BrowserWindow* parent)
0024     : QSlider(parent)
0025     , m_window(parent)
0026 {
0027     setObjectName(QSL("sbi_zoomwidget"));
0028     setOrientation(Qt::Horizontal);
0029     setFixedWidth(100);
0030     setMaximumHeight(20);
0031 
0032     setPageStep(2);
0033     setSingleStep(1);
0034     setRange(0, WebView::zoomLevels().count() - 1);
0035 
0036     connect(this, SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int)));
0037     connect(m_window->tabWidget(), &TabStackedWidget::currentChanged, this, &SBI_ZoomWidget::currentViewChanged);
0038 
0039     currentViewChanged();
0040 }
0041 
0042 void SBI_ZoomWidget::valueChanged(int value)
0043 {
0044     TabbedWebView* view = m_window->weView();
0045 
0046     if (view) {
0047         view->setZoomLevel(value);
0048         setToolTip(tr("Zoom: %1%").arg(view->zoomFactor() * 100));
0049     }
0050 }
0051 
0052 void SBI_ZoomWidget::currentViewChanged()
0053 {
0054     TabbedWebView* view = m_window->weView();
0055 
0056     if (view) {
0057         connect(view, &WebView::zoomLevelChanged, this, &QAbstractSlider::setValue);
0058         setValue(view->zoomLevel());
0059     }
0060 }