File indexing completed on 2025-01-05 04:49:30

0001 /*
0002    SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "zoomtextplugineditorinterface.h"
0008 #include "zoomlabel.h"
0009 #include "zoomtexteditorplugin_debug.h"
0010 #include <KActionCollection>
0011 #include <KActionMenu>
0012 #include <KLocalizedString>
0013 #include <QAction>
0014 #include <TextCustomEditor/RichTextEditor>
0015 
0016 ZoomTextPluginEditorInterface::ZoomTextPluginEditorInterface(QObject *parent)
0017     : MessageComposer::PluginEditorInterface(parent)
0018 {
0019 }
0020 
0021 ZoomTextPluginEditorInterface::~ZoomTextPluginEditorInterface() = default;
0022 
0023 void ZoomTextPluginEditorInterface::createAction(KActionCollection *ac)
0024 {
0025     auto zoomMenu = new KActionMenu(i18n("Zoom..."), this);
0026     ac->addAction(QStringLiteral("zoom_menu"), zoomMenu);
0027 
0028     QAction *zoomInAction = KStandardAction::zoomIn(this, &ZoomTextPluginEditorInterface::slotZoomIn, this);
0029     zoomMenu->addAction(zoomInAction);
0030     ac->addAction(QStringLiteral("zoom_in"), zoomInAction);
0031 
0032     QAction *zoomOutAction = KStandardAction::zoomOut(this, &ZoomTextPluginEditorInterface::slotZoomOut, this);
0033     zoomMenu->addAction(zoomOutAction);
0034     ac->addAction(QStringLiteral("zoom_out"), zoomOutAction);
0035 
0036     zoomMenu->addSeparator();
0037     QAction *zoomResetAction = KStandardAction::actualSize(this, &ZoomTextPluginEditorInterface::slotZoomReset, this);
0038     ac->addAction(QStringLiteral("zoom_reset"), zoomResetAction);
0039     zoomMenu->addAction(zoomResetAction);
0040 
0041     MessageComposer::PluginActionType type(zoomMenu, MessageComposer::PluginActionType::View);
0042     setActionType(type);
0043     mZoomLabelWidget = new ZoomLabel;
0044     connect(this, &ZoomTextPluginEditorInterface::zoomFactorChanged, mZoomLabelWidget, &ZoomLabel::setZoomLabel);
0045     setStatusBarWidget(mZoomLabelWidget);
0046 }
0047 
0048 void ZoomTextPluginEditorInterface::slotZoomOut()
0049 {
0050     mType = ZoomOut;
0051     Q_EMIT emitPluginActivated(this);
0052 }
0053 
0054 void ZoomTextPluginEditorInterface::slotZoomIn()
0055 {
0056     mType = ZoomIn;
0057     Q_EMIT emitPluginActivated(this);
0058 }
0059 
0060 void ZoomTextPluginEditorInterface::slotZoomReset()
0061 {
0062     mType = ZoomReset;
0063     Q_EMIT emitPluginActivated(this);
0064 }
0065 
0066 void ZoomTextPluginEditorInterface::exec()
0067 {
0068     switch (mType) {
0069     case Unknown:
0070         qCDebug(KMAIL_EDITOR_ZOOMTEXT_PLUGIN_LOG) << " There is an error here. We can't call this plugin with unknown type";
0071         break;
0072     case ZoomReset:
0073         zoomReset();
0074         break;
0075     case ZoomIn:
0076         zoomIn();
0077         break;
0078     case ZoomOut:
0079         zoomOut();
0080         break;
0081     }
0082     mType = Unknown;
0083 }
0084 
0085 void ZoomTextPluginEditorInterface::zoomReset()
0086 {
0087     richTextEditor()->slotZoomReset();
0088     Q_EMIT zoomFactorChanged(richTextEditor()->zoomFactor());
0089 }
0090 
0091 void ZoomTextPluginEditorInterface::zoomIn()
0092 {
0093     richTextEditor()->zoomIn();
0094     Q_EMIT zoomFactorChanged(richTextEditor()->zoomFactor());
0095 }
0096 
0097 void ZoomTextPluginEditorInterface::zoomOut()
0098 {
0099     richTextEditor()->zoomOut();
0100     Q_EMIT zoomFactorChanged(richTextEditor()->zoomFactor());
0101 }
0102 
0103 #include "moc_zoomtextplugineditorinterface.cpp"