• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • sources
  • kde-4.12
  • kdelibs
  • kdeui
  • widgets
krichtextwidget.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2 
3  Copyright 2008 Stephen Kelly <steveire@gmail.com>
4  Copyright 2008 Thomas McGuire <thomas.mcguire@gmx.net>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "krichtextwidget.h"
22 
23 // KDE includes
24 #include <kactioncollection.h>
25 #include <kcolordialog.h>
26 #include <kcolorscheme.h>
27 #include <kfontaction.h>
28 #include <kfontsizeaction.h>
29 #include <klocale.h>
30 #include <ktoggleaction.h>
31 #include <kdebug.h>
32 
33 // Qt includes
34 #include <QtGui/QTextList>
35 
36 #include "klinkdialog.h"
37 
38 // TODO: Add i18n context
39 
44 //@cond PRIVATE
45 class KRichTextWidget::Private
46 {
47 public:
48  Private(KRichTextWidget *parent)
49  : q(parent),
50  painterActive(false),
51  richTextEnabled(false), // It's only enabled when an action makes text rich.
52  enableRichText(0),
53  action_text_foreground_color(0),
54  action_text_background_color(0),
55  action_text_bold(0),
56  action_text_italic(0),
57  action_text_underline(0),
58  action_text_strikeout(0),
59  action_font_family(0),
60  action_font_size(0),
61  action_list_style(0),
62  action_list_indent(0),
63  action_list_dedent(0),
64  action_manage_link(0),
65  action_insert_horizontal_rule(0),
66  action_format_painter(0),
67  action_to_plain_text(0),
68  action_align_left(0),
69  action_align_right(0),
70  action_align_center(0),
71  action_align_justify(0),
72  action_direction_ltr(0),
73  action_direction_rtl(0),
74  action_text_superscript(0),
75  action_text_subscript(0)
76  {
77  }
78 
79  KRichTextWidget *q;
80 
81  RichTextSupport richTextSupport;
82 
83  QTextCharFormat painterFormat;
84  bool painterActive;
85 
86  QList<KAction*> richTextActionList;
87 
88  bool richTextEnabled;
89  KToggleAction *enableRichText;
90 
91  KAction *action_text_foreground_color;
92  KAction *action_text_background_color;
93 
94  KToggleAction *action_text_bold;
95  KToggleAction *action_text_italic;
96  KToggleAction *action_text_underline;
97  KToggleAction *action_text_strikeout;
98 
99  KFontAction *action_font_family;
100  KFontSizeAction *action_font_size;
101 
102  KSelectAction *action_list_style;
103  KAction *action_list_indent;
104  KAction *action_list_dedent;
105 
106  KAction *action_manage_link;
107  KAction *action_insert_horizontal_rule;
108  KAction *action_format_painter;
109  KAction *action_to_plain_text;
110 
111  KToggleAction *action_align_left;
112  KToggleAction *action_align_right;
113  KToggleAction *action_align_center;
114  KToggleAction *action_align_justify;
115 
116  KToggleAction *action_direction_ltr;
117  KToggleAction *action_direction_rtl;
118 
119  KToggleAction *action_text_superscript;
120  KToggleAction *action_text_subscript;
121 
122  //
123  // Normal functions
124  //
125  void init();
126 
127  //
128  // Slots
129  //
130 
134  void _k_setTextForegroundColor();
135 
139  void _k_setTextBackgroundColor();
140 
148  void _k_manageLink();
149 
155  void _k_formatPainter(bool active);
156 
160  void _k_updateCharFormatActions(const QTextCharFormat &format);
161 
166  void _k_updateMiscActions();
167 
171  void _k_setListStyle(int index);
172 
173 };
174 //@endcond
175 
176 void KRichTextWidget::Private::init()
177 {
178  q->setRichTextSupport(KRichTextWidget::FullSupport);
179 }
180 
181 KRichTextWidget::KRichTextWidget(QWidget* parent)
182  : KRichTextEdit(parent),
183  d(new Private(this))
184 {
185  d->init();
186 }
187 
188 KRichTextWidget::KRichTextWidget(const QString& text, QWidget *parent)
189  : KRichTextEdit(text,parent),
190  d(new Private(this))
191 {
192  d->init();
193 }
194 
195 KRichTextWidget::~KRichTextWidget()
196 {
197  delete d;
198 }
199 
200 KRichTextWidget::RichTextSupport KRichTextWidget::richTextSupport() const
201 {
202  return d->richTextSupport;
203 }
204 
205 void KRichTextWidget::setRichTextSupport(const KRichTextWidget::RichTextSupport &support)
206 {
207  d->richTextSupport = support;
208 }
209 
210 void KRichTextWidget::createActions(KActionCollection *actionCollection)
211 {
212  Q_ASSERT(actionCollection);
213 
214  // Note to maintainers: If adding new functionality here, make sure to disconnect
215  // and delete actions which should not be supported.
216  //
217  // New Actions need to be added to the following places:
218  // - possibly the RichTextSupportValues enum
219  // - the API documentation for createActions()
220  // - this function
221  // - the action needs to be added to the private class as a member
222  // - the constructor of the private class
223  // - depending on the action, some slot that changes the toggle state when
224  // appropriate, such as _k_updateCharFormatActions or _k_updateMiscActions.
225 
226  // The list of actions currently supported is also stored internally.
227  // This is used to disable all actions at once in setActionsEnabled.
228  d->richTextActionList.clear();
229 
230  if (d->richTextSupport & SupportTextForegroundColor) {
231  //Foreground Color
232  d->action_text_foreground_color = new KAction(KIcon("format-stroke-color"), i18nc("@action", "Text &Color..."), actionCollection);
233  d->action_text_foreground_color->setIconText(i18nc("@label stroke color", "Color"));
234  d->richTextActionList.append((d->action_text_foreground_color));
235  actionCollection->addAction("format_text_foreground_color", d->action_text_foreground_color);
236  connect(d->action_text_foreground_color, SIGNAL(triggered()), this, SLOT(_k_setTextForegroundColor()));
237  } else {
238  actionCollection->removeAction(d->action_text_foreground_color);
239  d->action_text_foreground_color = 0;
240  }
241 
242  if (d->richTextSupport & SupportTextBackgroundColor) {
243  //Background Color
244  d->action_text_background_color = new KAction(KIcon("format-fill-color"), i18nc("@action", "Text &Highlight..."), actionCollection);
245  d->richTextActionList.append((d->action_text_background_color));
246  actionCollection->addAction("format_text_background_color", d->action_text_background_color);
247  connect(d->action_text_background_color, SIGNAL(triggered()), this, SLOT(_k_setTextBackgroundColor()));
248  } else {
249  actionCollection->removeAction(d->action_text_background_color);
250  d->action_text_background_color = 0;
251  }
252 
253  if (d->richTextSupport & SupportFontFamily) {
254  //Font Family
255  d->action_font_family = new KFontAction(i18nc("@action", "&Font"), actionCollection);
256  d->richTextActionList.append((d->action_font_family));
257  actionCollection->addAction("format_font_family", d->action_font_family);
258  connect(d->action_font_family, SIGNAL(triggered(QString)), this, SLOT(setFontFamily(QString)));
259  } else {
260  actionCollection->removeAction(d->action_font_family);
261  d->action_font_family = 0;
262  }
263 
264  if (d->richTextSupport & SupportFontSize) {
265  //Font Size
266  d->action_font_size = new KFontSizeAction(i18nc("@action", "Font &Size"), actionCollection);
267  d->richTextActionList.append((d->action_font_size));
268  actionCollection->addAction("format_font_size", d->action_font_size);
269  connect(d->action_font_size, SIGNAL(fontSizeChanged(int)), this, SLOT(setFontSize(int)));
270  } else {
271  actionCollection->removeAction(d->action_font_size);
272  d->action_font_size = 0;
273  }
274 
275  if (d->richTextSupport & SupportBold) {
276  d->action_text_bold = new KToggleAction(KIcon("format-text-bold"), i18nc("@action boldify selected text", "&Bold"), actionCollection);
277  QFont bold;
278  bold.setBold(true);
279  d->action_text_bold->setFont(bold);
280  d->richTextActionList.append((d->action_text_bold));
281  actionCollection->addAction("format_text_bold", d->action_text_bold);
282  d->action_text_bold->setShortcut(KShortcut(Qt::CTRL + Qt::Key_B));
283  connect(d->action_text_bold, SIGNAL(triggered(bool)), this, SLOT(setTextBold(bool)));
284  } else {
285  actionCollection->removeAction(d->action_text_bold);
286  d->action_text_bold = 0;
287  }
288 
289  if (d->richTextSupport & SupportItalic) {
290  d->action_text_italic = new KToggleAction(KIcon("format-text-italic"), i18nc("@action italicize selected text", "&Italic"), actionCollection);
291  QFont italic;
292  italic.setItalic(true);
293  d->action_text_italic->setFont(italic);
294  d->richTextActionList.append((d->action_text_italic));
295  actionCollection->addAction("format_text_italic", d->action_text_italic);
296  d->action_text_italic->setShortcut(KShortcut(Qt::CTRL + Qt::Key_I));
297  connect(d->action_text_italic, SIGNAL(triggered(bool)),
298  this, SLOT(setTextItalic(bool)));
299  } else {
300  actionCollection->removeAction(d->action_text_italic);
301  d->action_text_italic = 0;
302  }
303 
304  if (d->richTextSupport & SupportUnderline) {
305  d->action_text_underline = new KToggleAction(KIcon("format-text-underline"), i18nc("@action underline selected text", "&Underline"), actionCollection);
306  QFont underline;
307  underline.setUnderline(true);
308  d->action_text_underline->setFont(underline);
309  d->richTextActionList.append((d->action_text_underline));
310  actionCollection->addAction("format_text_underline", d->action_text_underline);
311  d->action_text_underline->setShortcut(KShortcut(Qt::CTRL + Qt::Key_U));
312  connect(d->action_text_underline, SIGNAL(triggered(bool)),
313  this, SLOT(setTextUnderline(bool)));
314  } else {
315  actionCollection->removeAction(d->action_text_underline);
316  d->action_text_underline = 0;
317  }
318 
319  if (d->richTextSupport & SupportStrikeOut) {
320  d->action_text_strikeout = new KToggleAction(KIcon("format-text-strikethrough"), i18nc("@action", "&Strike Out"), actionCollection);
321  d->richTextActionList.append((d->action_text_strikeout));
322  actionCollection->addAction("format_text_strikeout", d->action_text_strikeout);
323  d->action_text_strikeout->setShortcut(KShortcut(Qt::CTRL + Qt::Key_L));
324  connect(d->action_text_strikeout, SIGNAL(triggered(bool)),
325  this, SLOT(setTextStrikeOut(bool)));
326  } else {
327  actionCollection->removeAction(d->action_text_strikeout);
328  d->action_text_strikeout = 0;
329  }
330 
331  if (d->richTextSupport & SupportAlignment) {
332  //Alignment
333  d->action_align_left = new KToggleAction(KIcon("format-justify-left"), i18nc("@action", "Align &Left"), actionCollection);
334  d->action_align_left->setIconText(i18nc("@label left justify", "Left"));
335  d->richTextActionList.append((d->action_align_left));
336  actionCollection->addAction("format_align_left", d->action_align_left);
337  connect(d->action_align_left, SIGNAL(triggered()),
338  this, SLOT(alignLeft()));
339 
340  d->action_align_center = new KToggleAction(KIcon("format-justify-center"), i18nc("@action", "Align &Center"), actionCollection);
341  d->action_align_center->setIconText(i18nc("@label center justify", "Center"));
342  d->richTextActionList.append((d->action_align_center));
343  actionCollection->addAction("format_align_center", d->action_align_center);
344  connect(d->action_align_center, SIGNAL(triggered()),
345  this, SLOT(alignCenter()));
346 
347  d->action_align_right = new KToggleAction(KIcon("format-justify-right"), i18nc("@action", "Align &Right"), actionCollection);
348  d->action_align_right->setIconText(i18nc("@label right justify", "Right"));
349  d->richTextActionList.append((d->action_align_right));
350  actionCollection->addAction("format_align_right", d->action_align_right);
351  connect(d->action_align_right, SIGNAL(triggered()),
352  this, SLOT(alignRight()));
353 
354  d->action_align_justify = new KToggleAction(KIcon("format-justify-fill"), i18nc("@action", "&Justify"), actionCollection);
355  d->action_align_justify->setIconText(i18nc("@label justify fill", "Justify"));
356  d->richTextActionList.append((d->action_align_justify));
357  actionCollection->addAction("format_align_justify", d->action_align_justify);
358  connect(d->action_align_justify, SIGNAL(triggered()),
359  this, SLOT(alignJustify()));
360 
361  QActionGroup *alignmentGroup = new QActionGroup(this);
362  alignmentGroup->addAction(d->action_align_left);
363  alignmentGroup->addAction(d->action_align_center);
364  alignmentGroup->addAction(d->action_align_right);
365  alignmentGroup->addAction(d->action_align_justify);
366  } else {
367 
368  actionCollection->removeAction(d->action_align_left);
369  actionCollection->removeAction(d->action_align_center);
370  actionCollection->removeAction(d->action_align_right);
371  actionCollection->removeAction(d->action_align_justify);
372 
373  d->action_align_left = 0;
374  d->action_align_center = 0;
375  d->action_align_right = 0;
376  d->action_align_justify = 0;
377  }
378 
379  if (d->richTextSupport & SupportDirection) {
380  d->action_direction_ltr = new KToggleAction(KIcon("format-text-direction-ltr"), i18nc("@action", "Left-to-Right"), actionCollection);
381  d->action_direction_ltr->setIconText(i18nc("@label left-to-right", "Left-to-Right"));
382  d->richTextActionList.append(d->action_direction_ltr);
383  actionCollection->addAction("direction_ltr", d->action_direction_ltr);
384  connect(d->action_direction_ltr, SIGNAL(triggered()),
385  this, SLOT(makeLeftToRight()));
386 
387  d->action_direction_rtl = new KToggleAction(KIcon("format-text-direction-rtl"), i18nc("@action", "Right-to-Left"), actionCollection);
388  d->action_direction_rtl->setIconText(i18nc("@label right-to-left", "Right-to-Left"));
389  d->richTextActionList.append(d->action_direction_rtl);
390  actionCollection->addAction("direction_rtl", d->action_direction_rtl);
391  connect(d->action_direction_rtl, SIGNAL(triggered()),
392  this, SLOT(makeRightToLeft()));
393 
394  QActionGroup *directionGroup = new QActionGroup(this);
395  directionGroup->addAction(d->action_direction_ltr);
396  directionGroup->addAction(d->action_direction_rtl);
397  } else {
398  actionCollection->removeAction(d->action_direction_ltr);
399  actionCollection->removeAction(d->action_direction_rtl);
400 
401  d->action_direction_ltr = 0;
402  d->action_direction_rtl = 0;
403  }
404 
405  if (d->richTextSupport & SupportChangeListStyle) {
406  d->action_list_style = new KSelectAction(KIcon("format-list-unordered"), i18nc("@title:menu", "List Style"), actionCollection);
407  QStringList listStyles;
408  listStyles << i18nc("@item:inmenu no list style", "None")
409  << i18nc("@item:inmenu disc list style", "Disc")
410  << i18nc("@item:inmenu circle list style", "Circle")
411  << i18nc("@item:inmenu square list style", "Square")
412  << i18nc("@item:inmenu numbered lists", "123")
413  << i18nc("@item:inmenu lowercase abc lists", "abc")
414  << i18nc("@item:inmenu uppercase abc lists", "ABC")
415  << i18nc("@item:inmenu lower case roman numerals", "i ii iii")
416  << i18nc("@item:inmenu upper case roman numerals", "I II III");
417 
418  d->action_list_style->setItems(listStyles);
419  d->action_list_style->setCurrentItem(0);
420  d->richTextActionList.append((d->action_list_style));
421  actionCollection->addAction("format_list_style", d->action_list_style);
422  connect(d->action_list_style, SIGNAL(triggered(int)),
423  this, SLOT(_k_setListStyle(int)));
424  connect(d->action_list_style, SIGNAL(triggered()),
425  this, SLOT(_k_updateMiscActions()));
426 
427  } else {
428  actionCollection->removeAction(d->action_list_style);
429  d->action_list_style = 0;
430  }
431 
432  if (d->richTextSupport & SupportIndentLists) {
433  d->action_list_indent = new KAction(KIcon("format-indent-more"), i18nc("@action", "Increase Indent"), actionCollection);
434  d->richTextActionList.append((d->action_list_indent));
435  actionCollection->addAction("format_list_indent_more", d->action_list_indent);
436  connect(d->action_list_indent, SIGNAL(triggered()),
437  this, SLOT(indentListMore()));
438  connect(d->action_list_indent, SIGNAL(triggered()),
439  this, SLOT(_k_updateMiscActions()));
440  } else {
441  actionCollection->removeAction(d->action_list_indent);
442  d->action_list_indent = 0;
443  }
444 
445  if (d->richTextSupport & SupportDedentLists) {
446  d->action_list_dedent = new KAction(KIcon("format-indent-less"), i18nc("@action", "Decrease Indent"), actionCollection);
447  d->richTextActionList.append((d->action_list_dedent));
448  actionCollection->addAction("format_list_indent_less", d->action_list_dedent);
449  connect(d->action_list_dedent, SIGNAL(triggered()),
450  this, SLOT(indentListLess()));
451  connect(d->action_list_dedent, SIGNAL(triggered()),
452  this, SLOT(_k_updateMiscActions()));
453  } else {
454  actionCollection->removeAction(d->action_list_dedent);
455  d->action_list_dedent = 0;
456  }
457 
458  if (d->richTextSupport & SupportRuleLine) {
459  d->action_insert_horizontal_rule = new KAction(KIcon("insert-horizontal-rule"), i18nc("@action", "Insert Rule Line"), actionCollection);
460  d->richTextActionList.append((d->action_insert_horizontal_rule));
461  actionCollection->addAction("insert_horizontal_rule", d->action_insert_horizontal_rule);
462  connect(d->action_insert_horizontal_rule, SIGNAL(triggered()),
463  this, SLOT(insertHorizontalRule()));
464  } else {
465  actionCollection->removeAction(d->action_insert_horizontal_rule);
466  d->action_insert_horizontal_rule = 0;
467  }
468 
469  if (d->richTextSupport & SupportHyperlinks) {
470  d->action_manage_link = new KAction(KIcon("insert-link"), i18nc("@action", "Link"), actionCollection);
471  d->richTextActionList.append((d->action_manage_link));
472  actionCollection->addAction("manage_link", d->action_manage_link);
473  connect(d->action_manage_link, SIGNAL(triggered()),
474  this, SLOT(_k_manageLink()));
475  } else {
476  actionCollection->removeAction(d->action_manage_link);
477  d->action_manage_link = 0;
478  }
479 
480  if (d->richTextSupport & SupportFormatPainting) {
481  d->action_format_painter = new KToggleAction(KIcon("draw-brush"), i18nc("@action", "Format Painter"), actionCollection);
482  d->richTextActionList.append((d->action_format_painter));
483  actionCollection->addAction("format_painter", d->action_format_painter);
484  connect(d->action_format_painter, SIGNAL(toggled(bool)),
485  this, SLOT(_k_formatPainter(bool)));
486  } else {
487  actionCollection->removeAction(d->action_format_painter);
488  d->action_format_painter = 0;
489  }
490 
491  if (d->richTextSupport & SupportToPlainText) {
492  d->action_to_plain_text = new KToggleAction(i18nc("@action", "To Plain Text"), actionCollection);
493  d->richTextActionList.append((d->action_to_plain_text));
494  actionCollection->addAction("action_to_plain_text", d->action_to_plain_text);
495  connect(d->action_to_plain_text, SIGNAL(triggered()),
496  this, SLOT(switchToPlainText()));
497  } else {
498  actionCollection->removeAction(d->action_to_plain_text);
499  d->action_to_plain_text = 0;
500  }
501 
502  if (d->richTextSupport & SupportSuperScriptAndSubScript) {
503  d->action_text_subscript = new KToggleAction(KIcon("format-text-subscript"), i18nc("@action", "Subscript"), actionCollection);
504  d->richTextActionList.append((d->action_text_subscript));
505  actionCollection->addAction("format_text_subscript", d->action_text_subscript);
506 
507  connect(d->action_text_subscript, SIGNAL(triggered(bool)),
508  this, SLOT(setTextSubScript(bool)));
509 
510  d->action_text_superscript = new KToggleAction(KIcon("format-text-superscript"), i18nc("@action", "Superscript"), actionCollection);
511  d->richTextActionList.append((d->action_text_superscript));
512  actionCollection->addAction("format_text_superscript", d->action_text_superscript);
513 
514  connect(d->action_text_superscript, SIGNAL(triggered(bool)),
515  this, SLOT(setTextSuperScript(bool)));
516  } else {
517  actionCollection->removeAction(d->action_text_subscript);
518  d->action_text_subscript = 0;
519 
520  actionCollection->removeAction(d->action_text_superscript);
521  d->action_text_superscript = 0;
522  }
523 
524 
525  disconnect(this, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
526  this, SLOT(_k_updateCharFormatActions(QTextCharFormat)));
527  disconnect(this, SIGNAL(cursorPositionChanged()),
528  this, SLOT(_k_updateMiscActions()));
529  connect(this, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
530  this, SLOT(_k_updateCharFormatActions(QTextCharFormat)));
531  connect(this, SIGNAL(cursorPositionChanged()),
532  this, SLOT(_k_updateMiscActions()));
533 
534  d->_k_updateMiscActions();
535  d->_k_updateCharFormatActions(currentCharFormat());
536 }
537 
538 
539 void KRichTextWidget::setActionsEnabled(bool enabled)
540 {
541  foreach(QAction* action, d->richTextActionList)
542  {
543  action->setEnabled(enabled);
544  }
545  d->richTextEnabled = enabled;
546 }
547 
548 void KRichTextWidget::Private::_k_setListStyle(int index)
549 {
550  q->setListStyle(index);
551  _k_updateMiscActions();
552 }
553 
554 void KRichTextWidget::Private::_k_updateCharFormatActions(const QTextCharFormat &format)
555 {
556  QFont f = format.font();
557 
558  if (richTextSupport & SupportFontFamily) {
559  action_font_family->setFont(f.family());
560  }
561  if (richTextSupport & SupportFontSize) {
562  if (f.pointSize() > 0)
563  action_font_size->setFontSize((int)f.pointSize());
564  }
565 
566  if (richTextSupport & SupportBold) {
567  action_text_bold->setChecked(f.bold());
568  }
569 
570  if (richTextSupport & SupportItalic) {
571  action_text_italic->setChecked(f.italic());
572  }
573 
574  if (richTextSupport & SupportUnderline) {
575  action_text_underline->setChecked(f.underline());
576  }
577 
578  if (richTextSupport & SupportStrikeOut) {
579  action_text_strikeout->setChecked(f.strikeOut());
580  }
581 
582  if (richTextSupport & SupportSuperScriptAndSubScript) {
583  QTextCharFormat::VerticalAlignment vAlign = format.verticalAlignment();
584  action_text_superscript->setChecked(vAlign == QTextCharFormat::AlignSuperScript);
585  action_text_subscript->setChecked(vAlign == QTextCharFormat::AlignSubScript);
586  }
587 }
588 
589 void KRichTextWidget::Private::_k_updateMiscActions()
590 {
591  if (richTextSupport & SupportAlignment) {
592  Qt::Alignment a = q->alignment();
593  if (a & Qt::AlignLeft) {
594  action_align_left->setChecked(true);
595  } else if (a & Qt::AlignHCenter) {
596  action_align_center->setChecked(true);
597  } else if (a & Qt::AlignRight) {
598  action_align_right->setChecked(true);
599  } else if (a & Qt::AlignJustify) {
600  action_align_justify->setChecked(true);
601  }
602  }
603 
604 
605  if (richTextSupport & SupportChangeListStyle) {
606  if (q->textCursor().currentList()) {
607  action_list_style->setCurrentItem(-q->textCursor().currentList()->format().style());
608  } else {
609  action_list_style->setCurrentItem(0);
610  }
611  }
612 
613 
614  if ( richTextSupport & SupportIndentLists ) {
615  if ( richTextEnabled ) {
616  action_list_indent->setEnabled( q->canIndentList() );
617  } else {
618  action_list_indent->setEnabled( false );
619  }
620  }
621 
622  if ( richTextSupport & SupportDedentLists ) {
623  if ( richTextEnabled ) {
624  action_list_dedent->setEnabled( q->canDedentList() );
625  } else {
626  action_list_dedent->setEnabled( false );
627  }
628  }
629 
630  if (richTextSupport & SupportDirection) {
631  const Qt::LayoutDirection direction = q->textCursor().blockFormat().layoutDirection();
632  action_direction_ltr->setChecked(direction == Qt::LeftToRight);
633  action_direction_rtl->setChecked(direction == Qt::RightToLeft);
634  }
635 }
636 
637 void KRichTextWidget::Private::_k_setTextForegroundColor()
638 {
639  QColor currentTextForegroundColor = q->textColor();
640 
641  const int result = KColorDialog::getColor(currentTextForegroundColor, KColorScheme(QPalette::Active, KColorScheme::View).foreground().color() , q);
642  if (result != QDialog::Accepted)
643  return;
644  if (!currentTextForegroundColor.isValid())
645  currentTextForegroundColor = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color() ;
646 
647  q->setTextForegroundColor(currentTextForegroundColor);
648 
649 }
650 
651 void KRichTextWidget::Private::_k_setTextBackgroundColor()
652 {
653  QTextCharFormat fmt = q->textCursor().charFormat();
654  QColor currentTextBackgroundColor = fmt.background().color();
655 
656  const int result = KColorDialog::getColor(currentTextBackgroundColor, KColorScheme(QPalette::Active, KColorScheme::View).foreground().color() , q);
657  if (result != QDialog::Accepted)
658  return;
659  if (!currentTextBackgroundColor.isValid())
660  currentTextBackgroundColor = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color() ;
661 
662  q->setTextBackgroundColor(currentTextBackgroundColor);
663 
664 }
665 
666 void KRichTextWidget::Private::_k_manageLink()
667 {
668  q->selectLinkText();
669  KLinkDialog *linkDialog = new KLinkDialog(q);
670  linkDialog->setLinkText(q->currentLinkText());
671  linkDialog->setLinkUrl(q->currentLinkUrl());
672 
673  if (linkDialog->exec()) {
674  q->updateLink(linkDialog->linkUrl(), linkDialog->linkText());
675  }
676 
677  delete linkDialog;
678 
679 }
680 
681 void KRichTextWidget::mouseReleaseEvent(QMouseEvent *event)
682 {
683  if (d->painterActive) {
684  // If the painter is active, paint the selection with the
685  // correct format.
686  if (textCursor().hasSelection()) {
687  textCursor().setCharFormat(d->painterFormat);
688  }
689  d->painterActive = false;
690  d->action_format_painter->setChecked(false);
691  }
692  KRichTextEdit::mouseReleaseEvent(event);
693 }
694 
695 void KRichTextWidget::Private::_k_formatPainter(bool active)
696 {
697  if (active) {
698  painterFormat = q->currentCharFormat();
699  painterActive = true;
700  q->viewport()->setCursor(QCursor(KIcon("draw-brush").pixmap(32, 32), 0, 32));
701  } else {
702  painterFormat = QTextCharFormat();
703  painterActive = false;
704  q->viewport()->setCursor(Qt::IBeamCursor);
705  }
706 }
707 
708 void KRichTextWidget::updateActionStates()
709 {
710  d->_k_updateMiscActions();
711  d->_k_updateCharFormatActions(currentCharFormat());
712 }
713 
714 // kate: space-indent on; indent-width 4; encoding utf-8; replace-tabs on;
715 #include "krichtextwidget.moc"
QColor
KRichTextEdit::alignCenter
void alignCenter()
Sets the alignment of the current block to Centered.
Definition: krichtextedit.cpp:182
KRichTextEdit::setTextBold
void setTextBold(bool bold)
Toggles the bold formatting of the current word or selection at the current cursor position...
Definition: krichtextedit.cpp:225
KRichTextEdit::alignJustify
void alignJustify()
Sets the alignment of the current block to Justified.
Definition: krichtextedit.cpp:196
KActionCollection
A container for a set of QAction objects.
Definition: kactioncollection.h:56
QCursor
kdebug.h
KFontSizeAction
An action to allow changing of the font size.
Definition: kfontsizeaction.h:36
KRichTextWidget::SupportFontFamily
Action to change the font family of the currently selected text.
Definition: krichtextwidget.h:103
KRichTextEdit::setTextStrikeOut
void setTextStrikeOut(bool strikeOut)
Toggles the strikeout formatting of the current word or selection at the current cursor position...
Definition: krichtextedit.cpp:252
KRichTextWidget::SupportHyperlinks
Action to convert the current text to a hyperlink.
Definition: krichtextwidget.h:193
KRichTextWidget::FullSupport
Includes all above actions for full rich text support.
Definition: krichtextwidget.h:226
KRichTextEdit::setTextUnderline
void setTextUnderline(bool underline)
Toggles the underline formatting of the current word or selection at the current cursor position...
Definition: krichtextedit.cpp:243
kactioncollection.h
KRichTextEdit::makeRightToLeft
void makeRightToLeft()
Sets the direction of the current block to Right-To-Left.
Definition: krichtextedit.cpp:203
QWidget
KRichTextEdit::setFontSize
void setFontSize(int size)
Sets the current word or selection to the font size size.
Definition: krichtextedit.cpp:288
KRichTextWidget::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *event)
Reimplemented.
KRichTextWidget::SupportAlignment
Actions to align the current paragraph left, righ, center or justify.
Definition: krichtextwidget.h:179
KActionCollection::addAction
QAction * addAction(const QString &name, QAction *action)
Add an action under the given name to the collection.
Definition: kactioncollection.cpp:217
KRichTextWidget::SupportStrikeOut
Action to strike out the selected text.
Definition: krichtextwidget.h:93
QString
klinkdialog.h
klocale.h
KRichTextEdit::alignRight
void alignRight()
Sets the alignment of the current block to Right Aligned.
Definition: krichtextedit.cpp:189
KRichTextWidget::SupportIndentLists
Action to increase the current list nesting level.
Definition: krichtextwidget.h:149
KRichTextEdit::setTextSubScript
void setTextSubScript(bool subscript)
Toggles the subscript formatting of the current word or selection at the current cursor position...
Definition: krichtextedit.cpp:331
i18nc
QString i18nc(const char *ctxt, const char *text)
KRichTextWidget::SupportSuperScriptAndSubScript
Actions to format text as superscript or subscript.
Definition: krichtextwidget.h:214
KShortcut
Represents a keyboard shortcut.
Definition: kshortcut.h:57
KRichTextWidget::SupportChangeListStyle
Action to make the current line a list element, change the list style or remove list formatting...
Definition: krichtextwidget.h:143
KSelectAction
Action for selecting one of several items.
Definition: kselectaction.h:51
kfontaction.h
KRichTextWidget::SupportUnderline
Action to underline the selected text.
Definition: krichtextwidget.h:85
krichtextwidget.h
KFontAction
An action to select a font family.
Definition: kfontaction.h:36
KColorScheme::foreground
QBrush foreground(ForegroundRole=NormalText) const
Retrieve the requested foreground brush.
Definition: kcolorscheme.cpp:459
KRichTextWidget::SupportDedentLists
Action to decrease the current list nesting level.
Definition: krichtextwidget.h:154
KRichTextWidget::SupportFormatPainting
Action to make the mouse cursor a format painter.
Definition: krichtextwidget.h:200
KRichTextWidget
A KRichTextEdit with common actions.
Definition: krichtextwidget.h:45
KRichTextWidget::KRichTextWidget
KRichTextWidget(QWidget *parent)
Constructor.
CTRL
#define CTRL(x)
Definition: kstandardshortcut.cpp:70
QStringList
KRichTextWidget::SupportRuleLine
Action to insert a horizontal line.
Definition: krichtextwidget.h:186
KRichTextWidget::setActionsEnabled
void setActionsEnabled(bool enabled)
Disables or enables all of the actions created by createActions().
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:40
KRichTextWidget::SupportDirection
Action to change direction of text to Right-To-Left or Left-To-Right.
Definition: krichtextwidget.h:221
KRichTextEdit::switchToPlainText
void switchToPlainText()
This will switch the editor to plain text mode.
Definition: krichtextedit.cpp:306
KRichTextEdit::setTextSuperScript
void setTextSuperScript(bool superscript)
Toggles the superscript formatting of the current word or selection at the current cursor position...
Definition: krichtextedit.cpp:322
KRichTextWidget::updateActionStates
void updateActionStates()
Tells KRichTextWidget to update the state of the actions created by createActions().
KColorScheme::View
Views; for example, frames, input fields, etc.
Definition: kcolorscheme.h:87
KRichTextEdit::indentListMore
void indentListMore()
Increases the nesting level of the current block or selected blocks.
Definition: krichtextedit.cpp:150
KActionCollection::removeAction
void removeAction(QAction *action)
Removes an action from the collection and deletes it.
Definition: kactioncollection.cpp:316
KRichTextEdit::insertHorizontalRule
void insertHorizontalRule()
Inserts a horizontal rule below the current block.
Definition: krichtextedit.cpp:161
KRichTextWidget::createActions
virtual void createActions(KActionCollection *actionCollection)
Creates the actions and adds them to the given action collection.
KRichTextEdit::makeLeftToRight
void makeLeftToRight()
Sets the direction of the current block to Left-To-Right.
Definition: krichtextedit.cpp:214
QFont
KRichTextWidget::richTextSupport
RichTextSupport richTextSupport() const
Returns the supported rich text subset available.
KRichTextWidget::SupportToPlainText
Action to change the text of the whole text edit to plain text.
Definition: krichtextwidget.h:206
KRichTextWidget::SupportItalic
Action to format the selected text as italic.
Definition: krichtextwidget.h:77
kcolordialog.h
KColorScheme
A set of methods used to work with colors.
Definition: kcolorscheme.h:71
KRichTextWidget::SupportBold
Action to format the selected text as bold.
Definition: krichtextwidget.h:69
KRichTextWidget::~KRichTextWidget
~KRichTextWidget()
Destructor.
KRichTextEdit
The KRichTextEdit class provides a widget to edit and display rich text.
Definition: krichtextedit.h:65
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:216
KRichTextWidget::SupportTextForegroundColor
Action to change the text color of the currently selected text.
Definition: krichtextwidget.h:120
ktoggleaction.h
KRichTextWidget::setRichTextSupport
void setRichTextSupport(const KRichTextWidget::RichTextSupport &support)
Sets the supported rich text subset available.
KToggleAction
Checkbox like action.
Definition: ktoggleaction.h:40
KColorDialog::getColor
static int getColor(QColor &theColor, QWidget *parent=0L)
Creates a modal color dialog, let the user choose a color, and returns when the dialog is closed...
Definition: kcolordialog.cpp:1492
KRichTextEdit::setFontFamily
void setFontFamily(const QString &fontFamily)
Sets the current word or selection to the font family fontFamily.
Definition: krichtextedit.cpp:279
KRichTextEdit::alignLeft
void alignLeft()
Sets the alignment of the current block to Left Aligned.
Definition: krichtextedit.cpp:175
KRichTextEdit::indentListLess
void indentListLess()
Decreases the nesting level of the current block or selected blocks.
Definition: krichtextedit.cpp:156
KRichTextWidget::SupportTextBackgroundColor
Action to change the background color of the currently selected text.
Definition: krichtextwidget.h:128
kfontsizeaction.h
kcolorscheme.h
KRichTextWidget::SupportFontSize
Action to change the font size of the currently selected text.
Definition: krichtextwidget.h:112
QAction
QList< KAction * >
KRichTextEdit::setTextItalic
void setTextItalic(bool italic)
Toggles the italic formatting of the current word or selection at the current cursor position...
Definition: krichtextedit.cpp:234
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:15 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal