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

KDE's Doxygen guidelines are available online.