7#include "zoomactionmenu.h"
8#include <KActionCollection>
9#include <KLocalizedString>
11using namespace WebEngineViewer;
14constexpr qreal zoomBy()
20class WebEngineViewer::ZoomActionMenuPrivate
29 qreal mZoomFactor = 100;
30 QAction *mZoomInAction =
nullptr;
31 QAction *mZoomOutAction =
nullptr;
32 QAction *mZoomResetAction =
nullptr;
37ZoomActionMenu::ZoomActionMenu(
QObject *parent)
39 , d(new WebEngineViewer::ZoomActionMenuPrivate(this))
43ZoomActionMenu::~ZoomActionMenu() =
default;
47 d->mActionCollection = ac;
50void ZoomActionMenu::createZoomActions()
53 d->mZoomInAction = KStandardActions::zoomIn(
this, &ZoomActionMenu::slotZoomIn,
this);
54 d->mActionCollection->addAction(QStringLiteral(
"zoom_in"), d->mZoomInAction);
56 d->mZoomOutAction = KStandardActions::zoomOut(
this, &ZoomActionMenu::slotZoomOut,
this);
57 d->mActionCollection->addAction(QStringLiteral(
"zoom_out"), d->mZoomOutAction);
59 d->mZoomResetAction = KStandardActions::actualSize(
this, &ZoomActionMenu::slotZoomReset,
this);
60 d->mActionCollection->addAction(QStringLiteral(
"zoom_reset"), d->mZoomResetAction);
65QAction *ZoomActionMenu::zoomInAction()
const
67 return d->mZoomInAction;
70QAction *ZoomActionMenu::zoomOutAction()
const
72 return d->mZoomOutAction;
75QAction *ZoomActionMenu::zoomResetAction()
const
77 return d->mZoomResetAction;
80void ZoomActionMenu::setZoomFactor(qreal zoomFactor)
82 d->mZoomFactor = zoomFactor;
85void ZoomActionMenu::setWebViewerZoomFactor(qreal zoomFactor)
87 Q_EMIT zoomChanged(zoomFactor);
90void ZoomActionMenu::slotZoomIn()
92 if (d->mZoomFactor >= 300) {
95 d->mZoomFactor += zoomBy();
96 if (d->mZoomFactor > 300) {
99 Q_EMIT zoomChanged(d->mZoomFactor / 100.0);
102void ZoomActionMenu::slotZoomOut()
104 if (d->mZoomFactor <= 10) {
107 d->mZoomFactor -= zoomBy();
108 if (d->mZoomFactor < 10) {
111 Q_EMIT zoomChanged(d->mZoomFactor / 100.0);
114void ZoomActionMenu::slotZoomReset()
116 d->mZoomFactor = 100;
120qreal ZoomActionMenu::zoomFactor()
const
122 return d->mZoomFactor;
125void ZoomActionMenuPrivate::createMenu()
132 mActionCollection->
addAction(QStringLiteral(
"zoom_menu"), q);
135#include "moc_zoomactionmenu.cpp"
QAction * addAction(const QString &name, const QObject *receiver=nullptr, const char *member=nullptr)
QString i18n(const char *text, const TYPE &arg...)
void setText(const QString &text)