KPimTextEdit

richtextcomposeractions.cpp
1/*
2 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "richtextcomposeractions.h"
8using namespace Qt::Literals::StringLiterals;
9
10#include "richtextcomposercontroler.h"
11#include "tableactionmenu.h"
12#include <KActionCollection>
13#include <KFontAction>
14#include <KFontSizeAction>
15#include <KLocalizedString>
16#include <KToggleAction>
17#include <QActionGroup>
18#include <QTextCharFormat>
19#include <QTextList>
20#include <TextEmoticonsWidgets/EmoticonTextEditAction>
21
22using namespace KPIMTextEdit;
23
24class Q_DECL_HIDDEN RichTextComposerActions::RichTextComposerActionsPrivate
25{
26public:
27 RichTextComposerActionsPrivate(KPIMTextEdit::RichTextComposerControler *controller)
28 : composerControler(controller)
29 {
30 }
31
32 QList<QAction *> richTextActionList;
33
34 KPIMTextEdit::RichTextComposerControler *const composerControler;
35 KToggleAction *action_align_left = nullptr;
36 KToggleAction *action_align_right = nullptr;
37 KToggleAction *action_align_center = nullptr;
38 KToggleAction *action_align_justify = nullptr;
39
40 KToggleAction *action_direction_ltr = nullptr;
41 KToggleAction *action_direction_rtl = nullptr;
42
43 KToggleAction *action_text_superscript = nullptr;
44 KToggleAction *action_text_subscript = nullptr;
45
46 KToggleAction *action_text_bold = nullptr;
47 KToggleAction *action_text_italic = nullptr;
48 KToggleAction *action_text_underline = nullptr;
49 KToggleAction *action_text_strikeout = nullptr;
50
51 KFontAction *action_font_family = nullptr;
52 KFontSizeAction *action_font_size = nullptr;
53
54 QAction *action_insert_horizontal_rule = nullptr;
55 QAction *action_text_foreground_color = nullptr;
56 QAction *action_text_background_color = nullptr;
57 QAction *action_manage_link = nullptr;
58
59 QAction *action_list_indent = nullptr;
60 QAction *action_list_dedent = nullptr;
61
62 KSelectAction *action_list_style = nullptr;
63
64 QAction *action_paste_quotation = nullptr;
65 QAction *action_add_quote_chars = nullptr;
66 QAction *action_remove_quote_chars = nullptr;
67 QAction *action_paste_without_formatting = nullptr;
68
69 QAction *action_add_image = nullptr;
70 TextEmoticonsWidgets::EmoticonTextEditAction *action_add_emoticon = nullptr;
71 QAction *action_insert_html = nullptr;
72 KPIMTextEdit::TableActionMenu *action_add_table = nullptr;
73 QAction *action_format_reset = nullptr;
74
75 KToggleAction *action_format_painter = nullptr;
76 KSelectAction *action_heading_level = nullptr;
77 KToggleAction *action_list_checkbox = nullptr;
78
79 bool richTextEnabled = false;
80};
81
82RichTextComposerActions::RichTextComposerActions(KPIMTextEdit::RichTextComposerControler *controller, QObject *parent)
83 : QObject(parent)
84 , d(new RichTextComposerActions::RichTextComposerActionsPrivate(controller))
85{
86}
87
88RichTextComposerActions::~RichTextComposerActions() = default;
89
90QList<QAction *> RichTextComposerActions::richTextActionList() const
91{
92 return d->richTextActionList;
93}
94
95int RichTextComposerActions::numberOfActions() const
96{
97 return d->richTextActionList.count();
98}
99
100void RichTextComposerActions::createActions(KActionCollection *ac)
101{
102 // Alignment
103 d->action_align_left = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-justify-left")), i18nc("@action", "Align &Left"), this);
104 d->action_align_left->setIconText(i18nc("@label left justify", "Left"));
105 d->richTextActionList.append((d->action_align_left));
106 d->action_align_left->setObjectName("format_align_left"_L1);
107 connect(d->action_align_left, &KToggleAction::triggered, d->composerControler, &RichTextComposerControler::alignLeft);
108 if (ac) {
109 ac->addAction(QStringLiteral("format_align_left"), d->action_align_left);
110 }
111
112 d->action_align_center = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-justify-center")), i18nc("@action", "Align &Center"), this);
113 d->action_align_center->setIconText(i18nc("@label center justify", "Center"));
114 d->richTextActionList.append((d->action_align_center));
115 d->action_align_center->setObjectName("format_align_center"_L1);
116 connect(d->action_align_center, &KToggleAction::triggered, d->composerControler, &RichTextComposerControler::alignCenter);
117 if (ac) {
118 ac->addAction(QStringLiteral("format_align_center"), d->action_align_center);
119 }
120
121 d->action_align_right = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-justify-right")), i18nc("@action", "Align &Right"), this);
122 d->action_align_right->setIconText(i18nc("@label right justify", "Right"));
123 d->richTextActionList.append((d->action_align_right));
124 d->action_align_right->setObjectName("format_align_right"_L1);
125 connect(d->action_align_right, &KToggleAction::triggered, d->composerControler, &RichTextComposerControler::alignRight);
126 if (ac) {
127 ac->addAction(QStringLiteral("format_align_right"), d->action_align_right);
128 }
129
130 d->action_align_justify = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-justify-fill")), i18nc("@action", "&Justify"), this);
131 d->action_align_justify->setIconText(i18nc("@label justify fill", "Justify"));
132 d->richTextActionList.append((d->action_align_justify));
133 d->action_align_justify->setObjectName("format_align_justify"_L1);
134 connect(d->action_align_justify, &KToggleAction::triggered, d->composerControler, &RichTextComposerControler::alignJustify);
135 if (ac) {
136 ac->addAction(QStringLiteral("format_align_justify"), d->action_align_justify);
137 }
138
139 auto alignmentGroup = new QActionGroup(this);
140 alignmentGroup->addAction(d->action_align_left);
141 alignmentGroup->addAction(d->action_align_center);
142 alignmentGroup->addAction(d->action_align_right);
143 alignmentGroup->addAction(d->action_align_justify);
144
145 // Align text
146 d->action_direction_ltr = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-text-direction-ltr")), i18nc("@action", "Left-to-Right"), this);
147 d->action_direction_ltr->setIconText(i18nc("@label left-to-right", "Left-to-Right"));
148 d->richTextActionList.append(d->action_direction_ltr);
149 d->action_direction_ltr->setObjectName("direction_ltr"_L1);
150 connect(d->action_direction_ltr, &KToggleAction::triggered, d->composerControler, &RichTextComposerControler::makeLeftToRight);
151 if (ac) {
152 ac->addAction(QStringLiteral("direction_ltr"), d->action_direction_ltr);
153 }
154
155 d->action_direction_rtl = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-text-direction-rtl")), i18nc("@action", "Right-to-Left"), this);
156 d->action_direction_rtl->setIconText(i18nc("@label right-to-left", "Right-to-Left"));
157 d->richTextActionList.append(d->action_direction_rtl);
158 d->action_direction_rtl->setObjectName("direction_rtl"_L1);
159 connect(d->action_direction_rtl, &KToggleAction::triggered, d->composerControler, &RichTextComposerControler::makeRightToLeft);
160 if (ac) {
161 ac->addAction(QStringLiteral("direction_rtl"), d->action_direction_rtl);
162 }
163
164 auto directionGroup = new QActionGroup(this);
165 directionGroup->addAction(d->action_direction_ltr);
166 directionGroup->addAction(d->action_direction_rtl);
167
168 // Sub/Super script
169 d->action_text_subscript = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-text-subscript")), i18nc("@action", "Subscript"), this);
170 d->richTextActionList.append((d->action_text_subscript));
171 d->action_text_subscript->setObjectName("format_text_subscript"_L1);
172 connect(d->action_text_subscript, &KToggleAction::triggered, d->composerControler, &RichTextComposerControler::setTextSubScript);
173 if (ac) {
174 ac->addAction(QStringLiteral("format_text_subscript"), d->action_text_subscript);
175 }
176
177 d->action_text_superscript = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-text-superscript")), i18nc("@action", "Superscript"), this);
178 d->richTextActionList.append((d->action_text_superscript));
179 d->action_text_superscript->setObjectName("format_text_superscript"_L1);
180 connect(d->action_text_superscript, &KToggleAction::triggered, d->composerControler, &RichTextComposerControler::setTextSuperScript);
181 if (ac) {
182 ac->addAction(QStringLiteral("format_text_superscript"), d->action_text_superscript);
183 }
184
185 d->action_text_bold = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-text-bold")), i18nc("@action boldify selected text", "&Bold"), this);
186 QFont bold;
187 bold.setBold(true);
188 d->action_text_bold->setFont(bold);
189 d->richTextActionList.append((d->action_text_bold));
190 d->action_text_bold->setObjectName("format_text_bold"_L1);
191 if (ac) {
192 ac->addAction(QStringLiteral("format_text_bold"), d->action_text_bold);
193 ac->setDefaultShortcut(d->action_text_bold, Qt::CTRL | Qt::Key_B);
194 }
195 connect(d->action_text_bold, &KToggleAction::triggered, d->composerControler, &RichTextComposerControler::setTextBold);
196
197 d->action_text_italic =
198 new KToggleAction(QIcon::fromTheme(QStringLiteral("format-text-italic")), i18nc("@action italicize selected text", "&Italic"), this);
199 QFont italic;
200 italic.setItalic(true);
201 d->action_text_italic->setFont(italic);
202 d->richTextActionList.append((d->action_text_italic));
203 d->action_text_italic->setObjectName("format_text_italic"_L1);
204 if (ac) {
205 ac->addAction(QStringLiteral("format_text_italic"), d->action_text_italic);
206 ac->setDefaultShortcut(d->action_text_italic, Qt::CTRL | Qt::Key_I);
207 }
208 connect(d->action_text_italic, &KToggleAction::triggered, d->composerControler, &RichTextComposerControler::setTextItalic);
209
210 d->action_text_underline =
211 new KToggleAction(QIcon::fromTheme(QStringLiteral("format-text-underline")), i18nc("@action underline selected text", "&Underline"), this);
212 QFont underline;
213 underline.setUnderline(true);
214 d->action_text_underline->setFont(underline);
215 d->richTextActionList.append((d->action_text_underline));
216 d->action_text_underline->setObjectName("format_text_underline"_L1);
217 if (ac) {
218 ac->addAction(QStringLiteral("format_text_underline"), d->action_text_underline);
219 ac->setDefaultShortcut(d->action_text_underline, Qt::CTRL | Qt::Key_U);
220 }
221 connect(d->action_text_underline, &KToggleAction::triggered, d->composerControler, &RichTextComposerControler::setTextUnderline);
222
223 d->action_text_strikeout = new KToggleAction(QIcon::fromTheme(QStringLiteral("format-text-strikethrough")), i18nc("@action", "&Strike Out"), this);
224 QFont strikeout;
225 strikeout.setStrikeOut(true);
226 d->action_text_strikeout->setFont(strikeout);
227 d->richTextActionList.append((d->action_text_strikeout));
228 if (ac) {
229 ac->addAction(QStringLiteral("format_text_strikeout"), d->action_text_strikeout);
230 }
231 d->action_text_strikeout->setObjectName("format_text_strikeout"_L1);
232 if (ac) {
233 ac->setDefaultShortcut(d->action_text_strikeout, Qt::CTRL | Qt::Key_L);
234 }
235 connect(d->action_text_strikeout, &KToggleAction::triggered, d->composerControler, &RichTextComposerControler::setTextStrikeOut);
236
237 // Font Family
238 d->action_font_family = new KFontAction(i18nc("@action", "&Font"), this);
239 d->richTextActionList.append((d->action_font_family));
240 d->action_font_family->setObjectName("format_font_family"_L1);
241 if (ac) {
242 ac->addAction(QStringLiteral("format_font_family"), d->action_font_family);
243 }
244 connect(d->action_font_family, &KFontAction::textTriggered, d->composerControler, &RichTextComposerControler::setFontFamily);
245
246 // Font Size
247 d->action_font_size = new KFontSizeAction(i18nc("@action", "Font &Size"), this);
248 d->richTextActionList.append((d->action_font_size));
249 d->action_font_size->setObjectName("format_font_size"_L1);
250 if (ac) {
251 ac->addAction(QStringLiteral("format_font_size"), d->action_font_size);
252 }
253 connect(d->action_font_size, &KFontSizeAction::fontSizeChanged, d->composerControler, &RichTextComposerControler::setFontSize);
254
255 d->action_insert_horizontal_rule = new QAction(QIcon::fromTheme(QStringLiteral("insert-horizontal-rule")), i18nc("@action", "Insert Rule Line"), this);
256 d->richTextActionList.append((d->action_insert_horizontal_rule));
257 d->action_insert_horizontal_rule->setObjectName("insert_horizontal_rule"_L1);
258 if (ac) {
259 ac->addAction(QStringLiteral("insert_horizontal_rule"), d->action_insert_horizontal_rule);
260 }
261 connect(d->action_insert_horizontal_rule, &QAction::triggered, d->composerControler, &RichTextComposerControler::insertHorizontalRule);
262
263 // Foreground Color
264 d->action_text_foreground_color = new QAction(QIcon::fromTheme(QStringLiteral("format-stroke-color")), i18nc("@action", "Text &Color…"), this);
265 d->action_text_foreground_color->setIconText(i18nc("@label stroke color", "Color"));
266 d->richTextActionList.append((d->action_text_foreground_color));
267 d->action_text_foreground_color->setObjectName("format_text_foreground_color"_L1);
268 if (ac) {
269 ac->addAction(QStringLiteral("format_text_foreground_color"), d->action_text_foreground_color);
270 }
271 connect(d->action_text_foreground_color, &QAction::triggered, d->composerControler, &RichTextComposerControler::setChangeTextForegroundColor);
272 // Background Color
273 d->action_text_background_color = new QAction(QIcon::fromTheme(QStringLiteral("format-fill-color")), i18nc("@action", "Text &Highlight…"), this);
274 d->richTextActionList.append((d->action_text_background_color));
275 if (ac) {
276 ac->addAction(QStringLiteral("format_text_background_color"), d->action_text_background_color);
277 }
278 d->action_text_background_color->setObjectName("format_text_background_color"_L1);
279 connect(d->action_text_background_color, &QAction::triggered, d->composerControler, &RichTextComposerControler::setChangeTextBackgroundColor);
280
281 d->action_manage_link = new QAction(QIcon::fromTheme(QStringLiteral("insert-link")), i18nc("@action", "Link"), this);
282 d->richTextActionList.append((d->action_manage_link));
283 d->action_manage_link->setObjectName("manage_link"_L1);
284 if (ac) {
285 ac->addAction(QStringLiteral("manage_link"), d->action_manage_link);
286 }
287 connect(d->action_manage_link, &QAction::triggered, d->composerControler, &RichTextComposerControler::manageLink);
288
289 d->action_list_indent = new QAction(QIcon::fromTheme(QStringLiteral("format-indent-more")), i18nc("@action", "Increase List Level"), this);
290 d->richTextActionList.append((d->action_list_indent));
291 d->action_list_indent->setObjectName("format_list_indent_more"_L1);
292 if (ac) {
293 ac->addAction(QStringLiteral("format_list_indent_more"), d->action_list_indent);
294 }
295 connect(d->action_list_indent, &QAction::triggered, d->composerControler, &RichTextComposerControler::indentListMore);
296 connect(d->action_list_indent, &QAction::triggered, this, &RichTextComposerActions::slotUpdateMiscActions);
297 d->action_list_dedent = new QAction(QIcon::fromTheme(QStringLiteral("format-indent-less")), i18nc("@action", "Decrease List Level"), this);
298 d->richTextActionList.append((d->action_list_dedent));
299 d->action_list_dedent->setObjectName("format_list_indent_less"_L1);
300 if (ac) {
301 ac->addAction(QStringLiteral("format_list_indent_less"), d->action_list_dedent);
302 }
303 connect(d->action_list_dedent, &QAction::triggered, d->composerControler, &RichTextComposerControler::indentListLess);
304 connect(d->action_list_dedent, &QAction::triggered, this, &RichTextComposerActions::slotUpdateMiscActions);
305
306 d->action_list_style = new KSelectAction(QIcon::fromTheme(QStringLiteral("format-list-unordered")), i18nc("@title:menu", "List Style"), this);
307 QStringList listStyles;
308 listStyles << i18nc("@item:inmenu no list style", "None") << i18nc("@item:inmenu disc list style", "Disc")
309 << i18nc("@item:inmenu circle list style", "Circle") << i18nc("@item:inmenu square list style", "Square")
310 << i18nc("@item:inmenu numbered lists", "123") << i18nc("@item:inmenu lowercase abc lists", "abc")
311 << i18nc("@item:inmenu uppercase abc lists", "ABC") << i18nc("@item:inmenu lower case roman numerals", "i ii iii")
312 << i18nc("@item:inmenu upper case roman numerals", "I II III");
313
314 d->action_list_style->setItems(listStyles);
315 d->action_list_style->setCurrentItem(0);
316 d->richTextActionList.append((d->action_list_style));
317 d->action_list_style->setObjectName("format_list_style"_L1);
318 if (ac) {
319 ac->addAction(QStringLiteral("format_list_style"), d->action_list_style);
320 }
321 connect(d->action_list_style, &KSelectAction::indexTriggered, this, &RichTextComposerActions::setListStyle);
322 connect(d->action_list_style, &QAction::triggered, this, &RichTextComposerActions::slotUpdateMiscActions);
323 d->action_paste_quotation = new QAction(i18nc("@action", "Pa&ste as Quotation"), this);
324 d->action_paste_quotation->setObjectName("paste_quoted"_L1);
325 if (ac) {
326 ac->addAction(QStringLiteral("paste_quoted"), d->action_paste_quotation);
327 ac->setDefaultShortcut(d->action_paste_quotation, QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_O));
328 }
329 connect(d->action_paste_quotation, &QAction::triggered, d->composerControler, &RichTextComposerControler::slotPasteAsQuotation);
330
331 d->action_add_quote_chars = new QAction(i18nc("@action", "Add &Quote Characters"), this);
332 d->action_add_quote_chars->setObjectName("tools_quote"_L1);
333 if (ac) {
334 ac->addAction(QStringLiteral("tools_quote"), d->action_add_quote_chars);
335 }
336 connect(d->action_add_quote_chars, &QAction::triggered, d->composerControler, &RichTextComposerControler::slotAddQuotes);
337
338 d->action_remove_quote_chars = new QAction(i18nc("@action", "Re&move Quote Characters"), this);
339 d->action_remove_quote_chars->setObjectName("tools_unquote"_L1);
340 connect(d->action_remove_quote_chars, &QAction::triggered, d->composerControler, &RichTextComposerControler::slotRemoveQuotes);
341 if (ac) {
342 ac->addAction(QStringLiteral("tools_unquote"), d->action_remove_quote_chars);
343 }
344
345 d->action_paste_without_formatting = new QAction(i18nc("@action", "Paste Without Formatting"), this);
346 d->action_paste_without_formatting->setObjectName("paste_without_formatting"_L1);
347 if (ac) {
348 ac->addAction(QStringLiteral("paste_without_formatting"), d->action_paste_without_formatting);
349 ac->setDefaultShortcut(d->action_paste_without_formatting, QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_V));
350 }
351 connect(d->action_paste_without_formatting, &QAction::triggered, d->composerControler, &RichTextComposerControler::slotPasteWithoutFormatting);
352
353 d->action_add_image = new QAction(QIcon::fromTheme(QStringLiteral("insert-image")), i18n("Add Image"), this);
354 d->action_add_image->setObjectName("add_image"_L1);
355 if (ac) {
356 ac->addAction(QStringLiteral("add_image"), d->action_add_image);
357 }
358 connect(d->action_add_image, &QAction::triggered, d->composerControler, &RichTextComposerControler::slotAddImage);
359 d->richTextActionList.append(d->action_add_image);
360
361 d->action_add_emoticon = new TextEmoticonsWidgets::EmoticonTextEditAction(this);
362 d->action_add_emoticon->setObjectName("add_emoticon"_L1);
363 if (ac) {
364 ac->addAction(QStringLiteral("add_emoticon"), d->action_add_emoticon);
365 }
366 // Don't add to d->richTextActionList as we want to use it when we use plain text email too
367 connect(d->action_add_emoticon,
369 d->composerControler->richTextComposer(),
370 &RichTextComposer::insertEmoticon);
371
372 d->action_insert_html = new QAction(i18nc("@action", "Insert HTML"), this);
373 d->action_insert_html->setObjectName("insert_html"_L1);
374 if (ac) {
375 ac->addAction(QStringLiteral("insert_html"), d->action_insert_html);
376 }
377 connect(d->action_insert_html, &QAction::triggered, d->composerControler, &RichTextComposerControler::slotInsertHtml);
378 d->richTextActionList.append(d->action_insert_html);
379
380 d->action_add_table = new KPIMTextEdit::TableActionMenu(d->composerControler->richTextComposer());
381 d->action_add_table->setIcon(QIcon::fromTheme(QStringLiteral("insert-table")));
382 d->action_add_table->setText(i18n("Table"));
383 d->action_add_table->setPopupMode(QToolButton::InstantPopup);
384
385 d->action_add_table->setObjectName("insert_table"_L1);
386 d->richTextActionList.append(d->action_add_table);
387 if (ac) {
388 ac->addAction(QStringLiteral("insert_table"), d->action_add_table);
389 }
390
391 d->action_format_reset = new QAction(QIcon::fromTheme(QStringLiteral("draw-eraser")), i18n("Reset Font Settings"), this);
392 d->action_format_reset->setIconText(i18n("Reset Font"));
393 d->action_format_reset->setObjectName("format_reset"_L1);
394 connect(d->action_format_reset, &QAction::triggered, d->composerControler, &RichTextComposerControler::slotFormatReset);
395 if (ac) {
396 ac->addAction(QStringLiteral("format_reset"), d->action_format_reset);
397 }
398 d->richTextActionList.append(d->action_format_reset);
399
400 d->action_format_painter = new KToggleAction(QIcon::fromTheme(QStringLiteral("draw-brush")), i18nc("@action", "Format Painter"), this);
401 d->richTextActionList.append(d->action_format_painter);
402 d->action_format_painter->setObjectName("format_painter"_L1);
403 if (ac) {
404 ac->addAction(QStringLiteral("format_painter"), d->action_format_painter);
405 }
406 connect(d->action_format_painter, &QAction::toggled, d->composerControler, &RichTextComposerControler::slotFormatPainter);
407
408 d->action_heading_level = new KSelectAction(i18nc("@title:menu", "Heading Level"), this);
409 const QStringList headingLevels = {i18nc("@item:inmenu no heading", "Basic text"),
410 i18nc("@item:inmenu heading level 1 (largest)", "Title"),
411 i18nc("@item:inmenu heading level 2", "Subtitle"),
412 i18nc("@item:inmenu heading level 3", "Section"),
413 i18nc("@item:inmenu heading level 4", "Subsection"),
414 i18nc("@item:inmenu heading level 5", "Paragraph"),
415 i18nc("@item:inmenu heading level 6 (smallest)", "Subparagraph")};
416
417 d->action_heading_level->setItems(headingLevels);
418 d->action_heading_level->setCurrentItem(0);
419 d->richTextActionList.append(d->action_heading_level);
420 d->action_heading_level->setObjectName("format_heading_level"_L1);
421 connect(d->action_heading_level, &KSelectAction::indexTriggered, this, &RichTextComposerActions::setHeadingLevel);
422 if (ac) {
423 ac->addAction(QStringLiteral("format_heading_level"), d->action_heading_level);
424 }
425
426 d->action_list_checkbox = new KToggleAction(QIcon::fromTheme(QStringLiteral("checkbox")), i18nc("@action", "Checkbox"), this);
427 d->richTextActionList.append(d->action_list_checkbox);
428 d->action_list_checkbox->setObjectName("format_list_checkbox"_L1);
429 connect(d->action_list_checkbox, &KToggleAction::toggled, d->composerControler, &RichTextComposerControler::addCheckbox);
430 if (ac) {
431 ac->addAction(QStringLiteral("format_list_checkbox"), d->action_list_checkbox);
432 }
433
434 disconnect(d->composerControler->richTextComposer(), &QTextEdit::currentCharFormatChanged, this, &RichTextComposerActions::slotUpdateCharFormatActions);
435 disconnect(d->composerControler->richTextComposer(), &QTextEdit::cursorPositionChanged, this, &RichTextComposerActions::slotUpdateMiscActions);
436
437 connect(d->composerControler->richTextComposer(), &QTextEdit::currentCharFormatChanged, this, &RichTextComposerActions::slotUpdateCharFormatActions);
438 connect(d->composerControler->richTextComposer(), &QTextEdit::cursorPositionChanged, this, &RichTextComposerActions::slotUpdateMiscActions);
439
440 updateActionStates();
441}
442
443void RichTextComposerActions::updateActionStates()
444{
445 slotUpdateMiscActions();
446 slotUpdateCharFormatActions(d->composerControler->richTextComposer()->currentCharFormat());
447}
448
449void RichTextComposerActions::setHeadingLevel(int level)
450{
451 d->composerControler->setHeadingLevel(level);
452 slotUpdateMiscActions();
453}
454
455void RichTextComposerActions::setListStyle(int _styleindex)
456{
457 d->composerControler->setListStyle(_styleindex);
458 slotUpdateMiscActions();
459}
460
461void RichTextComposerActions::setActionsEnabled(bool enabled)
462{
463 for (QAction *action : std::as_const(d->richTextActionList)) {
464 action->setEnabled(enabled);
465 }
466 d->richTextEnabled = enabled;
467}
468
469void RichTextComposerActions::slotUpdateCharFormatActions(const QTextCharFormat &format)
470{
471 QFont f = format.font();
472
473 d->action_font_family->setFont(f.family());
474 if (f.pointSize() > 0) {
475 d->action_font_size->setFontSize(f.pointSize());
476 }
477 d->action_text_bold->setChecked(f.bold());
478 d->action_text_italic->setChecked(f.italic());
479 d->action_text_underline->setChecked(f.underline());
480 d->action_text_strikeout->setChecked(f.strikeOut());
482 d->action_text_superscript->setChecked(vAlign == QTextCharFormat::AlignSuperScript);
483 d->action_text_subscript->setChecked(vAlign == QTextCharFormat::AlignSubScript);
484}
485
486void RichTextComposerActions::slotUpdateMiscActions()
487{
488 const RichTextComposer *richTextComposer = d->composerControler->richTextComposer();
489 const Qt::Alignment a = richTextComposer->alignment();
490 if (a & Qt::AlignLeft) {
491 d->action_align_left->setChecked(true);
492 } else if (a & Qt::AlignHCenter) {
493 d->action_align_center->setChecked(true);
494 } else if (a & Qt::AlignRight) {
495 d->action_align_right->setChecked(true);
496 } else if (a & Qt::AlignJustify) {
497 d->action_align_justify->setChecked(true);
498 }
499 if (richTextComposer->textCursor().currentList()) {
500 d->action_list_style->setCurrentItem(-richTextComposer->textCursor().currentList()->format().style());
501 } else {
502 d->action_list_style->setCurrentItem(0);
503 }
504 if (d->richTextEnabled) {
505 d->action_list_indent->setEnabled(d->composerControler->canIndentList());
506 } else {
507 d->action_list_indent->setEnabled(false);
508 }
509 if (d->richTextEnabled) {
510 d->action_list_dedent->setEnabled(d->composerControler->canDedentList());
511 } else {
512 d->action_list_dedent->setEnabled(false);
513 }
514
515 const Qt::LayoutDirection direction = richTextComposer->textCursor().blockFormat().layoutDirection();
516 d->action_direction_ltr->setChecked(direction == Qt::LeftToRight);
517 d->action_direction_rtl->setChecked(direction == Qt::RightToLeft);
518 d->action_heading_level->setCurrentItem(richTextComposer->textCursor().blockFormat().headingLevel());
519 d->action_list_checkbox->setChecked(richTextComposer->textCursor().blockFormat().marker() != QTextBlockFormat::MarkerType::NoMarker);
520}
521
522void RichTextComposerActions::uncheckActionFormatPainter()
523{
524 d->action_format_painter->setChecked(false);
525}
526
527void RichTextComposerActions::textModeChanged(KPIMTextEdit::RichTextComposer::Mode mode)
528{
529 if (d->action_add_table) {
530 d->action_add_table->setRichTextMode(mode == KPIMTextEdit::RichTextComposer::Rich);
531 }
532}
533
534#include "moc_richtextcomposeractions.cpp"
QAction * addAction(const QString &name, const QObject *receiver=nullptr, const char *member=nullptr)
static void setDefaultShortcut(QAction *action, const QKeySequence &shortcut)
The RichTextComposerActions class.
The RichTextComposerControler class.
The RichTextComposer class.
void indexTriggered(int index)
void textTriggered(const QString &text)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void toggled(bool checked)
void triggered(bool checked)
bool bold() const const
QString family() const const
bool italic() const const
int pointSize() const const
void setBold(bool enable)
void setItalic(bool enable)
void setStrikeOut(bool enable)
void setUnderline(bool enable)
bool strikeOut() const const
bool underline() const const
QIcon fromTheme(const QString &name)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
typedef Alignment
LayoutDirection
int headingLevel() const const
MarkerType marker() const const
QFont font() const const
VerticalAlignment verticalAlignment() const const
QTextBlockFormat blockFormat() const const
QTextList * currentList() const const
Qt::Alignment alignment() const const
void currentCharFormatChanged(const QTextCharFormat &f)
void cursorPositionChanged()
QTextCursor textCursor() const const
Qt::LayoutDirection layoutDirection() const const
QTextListFormat format() const const
Style style() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:55:51 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.