Libksieve

sieveeditormenubar.cpp
1 /*
2  SPDX-FileCopyrightText: 2015-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
7 #include "sieveeditormenubar.h"
8 #include "sieveeditortabwidget.h"
9 #include "sieveeditortextmodewidget.h"
10 
11 #include <KLocalizedString>
12 #include <KStandardAction>
13 #include <QAction>
14 #include <QIcon>
15 using namespace KSieveUi;
16 
17 SieveEditorMenuBar::SieveEditorMenuBar(QWidget *parent)
18  : QMenuBar(parent)
19 {
20  initActions();
21  initMenus();
22 }
23 
24 SieveEditorMenuBar::~SieveEditorMenuBar()
25 {
26 }
27 
28 void SieveEditorMenuBar::setEditorMode(bool editorMode)
29 {
30  mGoToLine->setEnabled(editorMode);
31  mFindAction->setEnabled(editorMode);
32  mReplaceAction->setEnabled(editorMode);
33  mUndoAction->setEnabled(editorMode);
34  mRedoAction->setEnabled(editorMode);
35  mCopyAction->setEnabled(editorMode);
36  mPasteAction->setEnabled(editorMode);
37  mCutAction->setEnabled(editorMode);
38  mSelectAllAction->setEnabled(editorMode);
39  mCommentCodeAction->setEnabled(editorMode);
40  mUncommentCodeAction->setEnabled(editorMode);
41  mZoomInAction->setEnabled(editorMode);
42  mZoomOutAction->setEnabled(editorMode);
43  mZoomResetAction->setEnabled(editorMode);
44  mDebugSieveAction->setEnabled(editorMode);
45  mWordWrapAction->setEnabled(editorMode);
46  mPrintAction->setEnabled(editorMode);
47  mPrintPreviewAction->setEnabled(editorMode);
48 }
49 
50 void SieveEditorMenuBar::initActions()
51 {
52  mGoToLine = new QAction(i18n("Go to Line"), this);
53  mGoToLine->setIcon(QIcon::fromTheme(QStringLiteral("go-jump")));
54  mGoToLine->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_G));
55  connect(mGoToLine, &QAction::triggered, this, &SieveEditorMenuBar::gotoLine);
56 
57  mCommentCodeAction = new QAction(i18n("Comment"), this);
58  mCommentCodeAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_D));
59  connect(mCommentCodeAction, &QAction::triggered, this, &SieveEditorMenuBar::comment);
60 
61  mUncommentCodeAction = new QAction(i18n("Uncomment"), this);
62  mUncommentCodeAction->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_D));
63  connect(mUncommentCodeAction, &QAction::triggered, this, &SieveEditorMenuBar::uncomment);
64 
65  mDebugSieveAction = new QAction(i18n("Debug Sieve Script..."), this);
66  mDebugSieveAction->setShortcut(QKeySequence(Qt::ALT | Qt::Key_D));
67  connect(mDebugSieveAction, &QAction::triggered, this, &SieveEditorMenuBar::debugSieveScript);
68 
69  mFindAction = KStandardAction::find(this, &SieveEditorMenuBar::find, this);
70  mReplaceAction = KStandardAction::replace(this, &SieveEditorMenuBar::replace, this);
71  mUndoAction = KStandardAction::undo(this, &SieveEditorMenuBar::undo, this);
72  mRedoAction = KStandardAction::redo(this, &SieveEditorMenuBar::redo, this);
73  mCopyAction = KStandardAction::copy(this, &SieveEditorMenuBar::copy, this);
74  mPasteAction = KStandardAction::paste(this, &SieveEditorMenuBar::paste, this);
75  mCutAction = KStandardAction::cut(this, &SieveEditorMenuBar::cut, this);
76  mSelectAllAction = KStandardAction::selectAll(this, &SieveEditorMenuBar::selectAll, this);
77  mZoomInAction = KStandardAction::zoomIn(this, &SieveEditorMenuBar::zoomIn, this);
78  mZoomOutAction = KStandardAction::zoomOut(this, &SieveEditorMenuBar::zoomOut, this);
79  mPrintAction = KStandardAction::print(this, &SieveEditorMenuBar::print, this);
80  mPrintPreviewAction = KStandardAction::printPreview(this, &SieveEditorMenuBar::printPreview, this);
81 
82  mZoomResetAction = KStandardAction::actualSize(this, &SieveEditorMenuBar::zoomReset, this);
83  mWordWrapAction = new QAction(i18n("Wordwrap"), this);
84  mWordWrapAction->setCheckable(true);
85  connect(mWordWrapAction, &QAction::triggered, this, &SieveEditorMenuBar::wordWrap);
86 
87  mUndoAction->setEnabled(false);
88  mRedoAction->setEnabled(false);
89  mCopyAction->setEnabled(false);
90  mCutAction->setEnabled(false);
91 }
92 
93 QMenu *SieveEditorMenuBar::editorMenu() const
94 {
95  return mEditorMenu;
96 }
97 
98 void SieveEditorMenuBar::initMenus()
99 {
100  mFileMenu = addMenu(i18nc("@title:menu", "File"));
101  mFileMenu->addAction(mPrintAction);
102  mFileMenu->addAction(mPrintPreviewAction);
103  mEditorMenu = addMenu(i18nc("@title:menu", "Edit"));
104  mEditorMenu->addAction(mUndoAction);
105  mEditorMenu->addAction(mRedoAction);
106  mEditorMenu->addSeparator();
107  mEditorMenu->addAction(mCutAction);
108  mEditorMenu->addAction(mCopyAction);
109  mEditorMenu->addAction(mPasteAction);
110  mEditorMenu->addSeparator();
111  mEditorMenu->addAction(mSelectAllAction);
112  mEditorMenu->addSeparator();
113  mEditorMenu->addAction(mFindAction);
114  mEditorMenu->addAction(mReplaceAction);
115  mEditorMenu->addSeparator();
116  mEditorMenu->addAction(mGoToLine);
117  mEditorMenu->addSeparator();
118  mEditorMenu->addAction(mWordWrapAction);
119  mEditorMenu->addSeparator();
120  mEditorMenu->addAction(mCommentCodeAction);
121  mEditorMenu->addAction(mUncommentCodeAction);
122 
123  mViewMenu = addMenu(i18nc("@title:menu", "View"));
124  mViewMenu->addAction(mZoomInAction);
125  mViewMenu->addAction(mZoomOutAction);
126  mViewMenu->addSeparator();
127  mViewMenu->addAction(mZoomResetAction);
128 
129  mToolsMenu = addMenu(i18nc("@title:menu", "Tools"));
130  mToolsMenu->addAction(mDebugSieveAction);
131 }
132 
133 QAction *SieveEditorMenuBar::printAction() const
134 {
135  return mPrintAction;
136 }
137 
138 void SieveEditorMenuBar::slotUpdateActions()
139 {
140  const bool hasActionInHtmlModeToo = mTextModeWidget->tabWidget()->currentPageIsHtmlPage();
141 
142  mGoToLine->setEnabled(!hasActionInHtmlModeToo);
143  mFindAction->setEnabled(true);
144  mReplaceAction->setEnabled(!hasActionInHtmlModeToo);
145  mUndoAction->setEnabled(!hasActionInHtmlModeToo);
146  mRedoAction->setEnabled(!hasActionInHtmlModeToo);
147  mCopyAction->setEnabled(true);
148  mPasteAction->setEnabled(!hasActionInHtmlModeToo);
149  mCutAction->setEnabled(!hasActionInHtmlModeToo);
150  mSelectAllAction->setEnabled(true);
151  mCommentCodeAction->setEnabled(!hasActionInHtmlModeToo);
152  mUncommentCodeAction->setEnabled(!hasActionInHtmlModeToo);
153  mZoomInAction->setEnabled(true);
154  mZoomOutAction->setEnabled(true);
155  mZoomResetAction->setEnabled(true);
156  mDebugSieveAction->setEnabled(!hasActionInHtmlModeToo);
157  mWordWrapAction->setEnabled(!hasActionInHtmlModeToo);
158  mPrintAction->setEnabled(!hasActionInHtmlModeToo);
159  mPrintPreviewAction->setEnabled(!hasActionInHtmlModeToo);
160 }
161 
162 QMenu *SieveEditorMenuBar::viewMenu() const
163 {
164  return mViewMenu;
165 }
166 
167 void SieveEditorMenuBar::setTextModeWidget(SieveEditorTextModeWidget *textModeWidget)
168 {
169  if (!mTextModeWidget) {
170  mTextModeWidget = textModeWidget;
171  connect(mTextModeWidget->tabWidget(), &QTabWidget::currentChanged, this, &SieveEditorMenuBar::slotUpdateActions);
172  }
173 }
174 
175 QAction *SieveEditorMenuBar::printPreviewAction() const
176 {
177  return mPrintPreviewAction;
178 }
179 
180 QAction *SieveEditorMenuBar::uncommentCodeAction() const
181 {
182  return mUncommentCodeAction;
183 }
184 
185 QAction *SieveEditorMenuBar::zoomResetAction() const
186 {
187  return mZoomResetAction;
188 }
189 
190 QAction *SieveEditorMenuBar::wordWrapAction() const
191 {
192  return mWordWrapAction;
193 }
194 
195 QAction *SieveEditorMenuBar::zoomInAction() const
196 {
197  return mZoomInAction;
198 }
199 
200 QAction *SieveEditorMenuBar::zoomOutAction() const
201 {
202  return mZoomOutAction;
203 }
204 
205 QAction *SieveEditorMenuBar::debugSieveScriptAction() const
206 {
207  return mDebugSieveAction;
208 }
209 
210 QAction *SieveEditorMenuBar::commentCodeAction() const
211 {
212  return mCommentCodeAction;
213 }
214 
215 QMenu *SieveEditorMenuBar::fileMenu() const
216 {
217  return mFileMenu;
218 }
219 
220 QMenu *SieveEditorMenuBar::toolsMenu() const
221 {
222  return mToolsMenu;
223 }
224 
225 QAction *SieveEditorMenuBar::selectAllAction() const
226 {
227  return mSelectAllAction;
228 }
229 
230 QAction *SieveEditorMenuBar::cutAction() const
231 {
232  return mCutAction;
233 }
234 
235 QAction *SieveEditorMenuBar::pasteAction() const
236 {
237  return mPasteAction;
238 }
239 
240 QAction *SieveEditorMenuBar::copyAction() const
241 {
242  return mCopyAction;
243 }
244 
245 QAction *SieveEditorMenuBar::redoAction() const
246 {
247  return mRedoAction;
248 }
249 
250 QAction *SieveEditorMenuBar::undoAction() const
251 {
252  return mUndoAction;
253 }
254 
255 QAction *SieveEditorMenuBar::replaceAction() const
256 {
257  return mReplaceAction;
258 }
259 
260 QAction *SieveEditorMenuBar::findAction() const
261 {
262  return mFindAction;
263 }
264 
265 QAction *SieveEditorMenuBar::goToLineAction() const
266 {
267  return mGoToLine;
268 }
269 
270 void SieveEditorMenuBar::slotUndoAvailable(bool b)
271 {
272  mUndoAction->setEnabled(b);
273 }
274 
275 void SieveEditorMenuBar::slotRedoAvailable(bool b)
276 {
277  mRedoAction->setEnabled(b);
278 }
279 
280 void SieveEditorMenuBar::slotCopyAvailable(bool b)
281 {
282  mCutAction->setEnabled(b);
283  mCopyAction->setEnabled(b);
284 }
QAction * selectAll(const QObject *recvr, const char *slot, QObject *parent)
void triggered(bool checked)
QAction * cut(const QObject *recvr, const char *slot, QObject *parent)
QAction * actualSize(const QObject *recvr, const char *slot, QObject *parent)
QAction * paste(const QObject *recvr, const char *slot, QObject *parent)
The SieveEditorTextModeWidget class.
QAction * undo(const QObject *recvr, const char *slot, QObject *parent)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void currentChanged(int index)
QAction * copy(const QObject *recvr, const char *slot, QObject *parent)
QAction * print(const QObject *recvr, const char *slot, QObject *parent)
QAction * replace(const QObject *recvr, const char *slot, QObject *parent)
QString i18n(const char *text, const TYPE &arg...)
QAction * zoomIn(const QObject *recvr, const char *slot, QObject *parent)
QAction * redo(const QObject *recvr, const char *slot, QObject *parent)
QIcon fromTheme(const QString &name)
QAction * printPreview(const QObject *recvr, const char *slot, QObject *parent)
QAction * zoomOut(const QObject *recvr, const char *slot, QObject *parent)
QAction * find(const QObject *recvr, const char *slot, QObject *parent)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setEnabled(bool)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 16 2021 23:09:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.