diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index c778e4a4d..52cc0393b 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -127,6 +127,7 @@ set(SRCS ${SRCS} navigation/reloadstopbutton.cpp navigation/siteicon.cpp navigation/websearchbar.cpp + navigation/zoomlabel.cpp network/networkmanager.cpp network/networkurlinterceptor.cpp network/schemehandlers/extensionschemehandler.cpp @@ -355,6 +356,7 @@ set(SRCS ${SRCS} navigation/reloadstopbutton.h navigation/siteicon.h navigation/websearchbar.h + navigation/zoomlabel.h network/networkmanager.h network/networkurlinterceptor.h network/schemehandlers/extensionschemehandler.h diff --git a/src/lib/navigation/locationbar.cpp b/src/lib/navigation/locationbar.cpp index 316c772d7..098f42db4 100644 --- a/src/lib/navigation/locationbar.cpp +++ b/src/lib/navigation/locationbar.cpp @@ -34,6 +34,7 @@ #include "colors.h" #include "autofillicon.h" #include "completer/locationcompleter.h" +#include "zoomlabel.h" #include #include @@ -63,8 +64,10 @@ LocationBar::LocationBar(QWidget *parent) m_siteIcon = new SiteIcon(this); m_autofillIcon = new AutoFillIcon(this); auto* down = new DownIcon(this); + m_zoomlabel = new ZoomLabel(this); addWidget(m_siteIcon, LineEdit::LeftSide); + addWidget(m_zoomlabel, LineEdit::RightSide); addWidget(m_autofillIcon, LineEdit::RightSide); addWidget(m_bookmarkIcon, LineEdit::RightSide); addWidget(m_goIcon, LineEdit::RightSide); @@ -134,6 +137,7 @@ void LocationBar::setWebView(TabbedWebView* view) m_bookmarkIcon->setWebView(m_webView); m_siteIcon->setWebView(m_webView); + m_zoomlabel->setWebView(m_webView); m_autofillIcon->setWebView(m_webView); connect(m_webView, &QWebEngineView::loadStarted, this, &LocationBar::loadStarted); @@ -364,10 +368,12 @@ void LocationBar::setGoIconVisible(bool state) { if (state) { m_bookmarkIcon->hide(); + m_zoomlabel->hide(); m_goIcon->show(); } else { m_bookmarkIcon->show(); + m_zoomlabel->show(); if (!qzSettings->alwaysShowGoIcon) { m_goIcon->hide(); diff --git a/src/lib/navigation/locationbar.h b/src/lib/navigation/locationbar.h index 37b07725e..d0f813c99 100644 --- a/src/lib/navigation/locationbar.h +++ b/src/lib/navigation/locationbar.h @@ -34,6 +34,7 @@ class SiteIcon; class GoIcon; class AutoFillIcon; class BookmarkItem; +class ZoomLabel; class FALKON_EXPORT LocationBar : public LineEdit { @@ -117,6 +118,7 @@ private: GoIcon* m_goIcon; SiteIcon* m_siteIcon; AutoFillIcon* m_autofillIcon; + ZoomLabel* m_zoomlabel; BrowserWindow* m_window; TabbedWebView* m_webView; diff --git a/src/lib/navigation/zoomlabel.cpp b/src/lib/navigation/zoomlabel.cpp new file mode 100644 index 000000000..7608d4552 --- /dev/null +++ b/src/lib/navigation/zoomlabel.cpp @@ -0,0 +1,82 @@ +/* ============================================================ + * ZoomLabel - Shows current zoom level in locationbar + * Copyright (C) 2023 Juraj Oravec + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * ============================================================ */ +#include "zoomlabel.h" +#include "locationbar.h" +#include "mainapplication.h" +#include "tabbedwebview.h" +#include "qzsettings.h" + +#include + +ZoomLabel::ZoomLabel(LocationBar* parent) + : ClickableLabel(parent) + , m_locationBar(parent) + , m_view(nullptr) +{ + setObjectName(QSL("locationbar-zoomlabel")); + setCursor(Qt::PointingHandCursor); + setFocusPolicy(Qt::NoFocus); + setScaledContents(true); + setToolTip(tr("Reset zoom level")); + + connect(mApp, &MainApplication::settingsReloaded, this, [this]() { + if (this->m_view) { + this->valueChanged(m_view->zoomLevel()); + } + }); +} + +void ZoomLabel::setWebView(WebView* view) +{ + m_view = view; + connect(view, &WebView::zoomLevelChanged, this, &ZoomLabel::valueChanged); + connect(this, &ZoomLabel::clicked, view, &WebView::zoomReset); + valueChanged(m_view->zoomLevel()); +} + +void ZoomLabel::valueChanged(int value) +{ + if ((m_view) && (value != qzSettings->defaultZoomLevel) && (qzSettings->showZoomLabel)) { + setText(QSL("%1%").arg(m_view->zoomFactor() * 100)); + show(); + } + else { + hide(); + } +} + +void ZoomLabel::paintEvent(QPaintEvent* e) +{ + QPainter p(this); + + QFontMetrics fmNormalFont(font()); + QFont smallFont(font()); + smallFont.setPointSizeF(smallFont.pointSizeF() * 0.8); + p.setFont(smallFont); + + QFontMetrics fmSmallFont(smallFont); + int fontSizeDiff = fmNormalFont.height() - fmSmallFont.height(); + + QRect rect = e->rect(); + rect.setY(rect.y() + (fontSizeDiff * 2)); + rect.setHeight(fmSmallFont.height()); + p.fillRect(rect, QApplication::palette().color(QPalette::Base)); + + rect.setX(rect.x() + (fmNormalFont.horizontalAdvance(text()) - fmSmallFont.horizontalAdvance(text())) / 2); + p.drawText(rect, text()); +} diff --git a/src/lib/navigation/zoomlabel.h b/src/lib/navigation/zoomlabel.h new file mode 100644 index 000000000..559f895f3 --- /dev/null +++ b/src/lib/navigation/zoomlabel.h @@ -0,0 +1,47 @@ +/* ============================================================ + * ZoomLabel - Shows current zoom level in locationbar + * Copyright (C) 2023 Juraj Oravec + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * ============================================================ */ +#ifndef ZOOM_LABEL_H +#define ZOOM_LABEL_H + +#include "clickablelabel.h" + +class LocationBar; +class WebView; +class BrowserWindow; + +class ZoomLabel : public ClickableLabel +{ + Q_OBJECT + +public: + explicit ZoomLabel(LocationBar* parent); + + void setWebView(WebView* view); + +protected: + void paintEvent(QPaintEvent* e) override; + +private Q_SLOTS: + void valueChanged(int value); + +private: + LocationBar* m_locationBar; + WebView* m_view; +}; + +#endif // ZOOM_LABEL_H diff --git a/src/lib/other/qzsettings.cpp b/src/lib/other/qzsettings.cpp index 48d1d4361..8d4f1cd29 100644 --- a/src/lib/other/qzsettings.cpp +++ b/src/lib/other/qzsettings.cpp @@ -34,6 +34,7 @@ void QzSettings::loadSettings() showSwitchTab = settings.value("showSwitchTab", true).toBool(); alwaysShowGoIcon = settings.value("alwaysShowGoIcon", false).toBool(); useInlineCompletion = settings.value("useInlineCompletion", true).toBool(); + showZoomLabel = settings.value("showZoomLabel", true).toBool(); settings.endGroup(); settings.beginGroup("SearchEngines"); diff --git a/src/lib/other/qzsettings.h b/src/lib/other/qzsettings.h index b5bcaec2c..b76e6c262 100644 --- a/src/lib/other/qzsettings.h +++ b/src/lib/other/qzsettings.h @@ -39,6 +39,7 @@ public: bool showSwitchTab; bool alwaysShowGoIcon; bool useInlineCompletion; + bool showZoomLabel; // SearchEngines bool searchOnEngineChange; diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index 857493b27..4b2360e0c 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -249,6 +249,7 @@ Preferences::Preferences(BrowserWindow* window) ui->useInlineCompletion->setChecked(settings.value("useInlineCompletion", true).toBool()); ui->completionShowSwitchTab->setChecked(settings.value("showSwitchTab", true).toBool()); ui->alwaysShowGoIcon->setChecked(settings.value("alwaysShowGoIcon", false).toBool()); + ui->showZoomLabel->setChecked(settings.value("showZoomLabel", true).toBool()); ui->selectAllOnFocus->setChecked(settings.value("SelectAllTextOnDoubleClick", true).toBool()); ui->selectAllOnClick->setChecked(settings.value("SelectAllTextOnClick", false).toBool()); bool showPBinAB = settings.value("ShowLoadingProgress", false).toBool(); @@ -1027,6 +1028,7 @@ void Preferences::saveSettings() settings.setValue("showSuggestions", ui->addressbarCompletion->currentIndex()); settings.setValue("useInlineCompletion", ui->useInlineCompletion->isChecked()); settings.setValue("alwaysShowGoIcon", ui->alwaysShowGoIcon->isChecked()); + settings.setValue("showZoomLabel", ui->showZoomLabel->isChecked()); settings.setValue("showSwitchTab", ui->completionShowSwitchTab->isChecked()); settings.setValue("SelectAllTextOnDoubleClick", ui->selectAllOnFocus->isChecked()); settings.setValue("SelectAllTextOnClick", ui->selectAllOnClick->isChecked()); diff --git a/src/lib/preferences/preferences.ui b/src/lib/preferences/preferences.ui index 035ee17a8..ea8babe96 100644 --- a/src/lib/preferences/preferences.ui +++ b/src/lib/preferences/preferences.ui @@ -818,6 +818,13 @@ + + + + Show zoom label + + +