1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

Show page zoom level in locationbar

- Only show up when the zoom level is different than the default zoom
  level set in preferences.

BUG: 399001

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2023-02-18 14:23:07 +01:00
parent 6c5db638ec
commit d50eb6e822
Signed by: SGOrava
GPG Key ID: 13660A3F1D9F093B
9 changed files with 150 additions and 0 deletions

View File

@ -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

View File

@ -34,6 +34,7 @@
#include "colors.h"
#include "autofillicon.h"
#include "completer/locationcompleter.h"
#include "zoomlabel.h"
#include <QTimer>
#include <QMimeData>
@ -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();

View File

@ -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;

View File

@ -0,0 +1,82 @@
/* ============================================================
* ZoomLabel - Shows current zoom level in locationbar
* Copyright (C) 2023 Juraj Oravec <jurajoravec@mailo.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "zoomlabel.h"
#include "locationbar.h"
#include "mainapplication.h"
#include "tabbedwebview.h"
#include "qzsettings.h"
#include <QApplication>
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());
}

View File

@ -0,0 +1,47 @@
/* ============================================================
* ZoomLabel - Shows current zoom level in locationbar
* Copyright (C) 2023 Juraj Oravec <jurajoravec@mailo.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#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

View File

@ -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");

View File

@ -39,6 +39,7 @@ public:
bool showSwitchTab;
bool alwaysShowGoIcon;
bool useInlineCompletion;
bool showZoomLabel;
// SearchEngines
bool searchOnEngineChange;

View File

@ -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());

View File

@ -818,6 +818,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showZoomLabel">
<property name="text">
<string>Show zoom label</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="selectAllOnFocus">
<property name="text">