- 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>remotes/origin/kf6
parent
6c5db638ec
commit
d50eb6e822
9 changed files with 150 additions and 0 deletions
@ -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()); |
||||
} |
||||
@ -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
|
||||
Loading…
Reference in new issue