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

KDEUI

krichtextwidget.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002 
00003    Copyright 2008 Stephen Kelly <steveire@gmail.com>
00004    Copyright 2008 Thomas McGuire <thomas.mcguire@gmx.net>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License version 2 as published by the Free Software Foundation.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "krichtextwidget.h"
00022 
00023 // KDE includes
00024 #include <kactioncollection.h>
00025 #include <kcolordialog.h>
00026 #include <kcolorscheme.h>
00027 #include <kfontaction.h>
00028 #include <kfontsizeaction.h>
00029 #include <klocale.h>
00030 #include <ktoggleaction.h>
00031 #include <kdebug.h>
00032 
00033 // Qt includes
00034 #include <QtGui/QTextList>
00035 
00036 #include "klinkdialog.h"
00037 
00038 // TODO: Add i18n context
00039 
00044 //@cond PRIVATE
00045 class KRichTextWidget::Private
00046 {
00047 public:
00048     Private(KRichTextWidget *parent)
00049             :   q(parent),
00050             painterActive(false),
00051             richTextEnabled(false), // It's only enabled when an action makes text rich.
00052             enableRichText(0),
00053             action_text_foreground_color(0),
00054             action_text_background_color(0),
00055             action_text_bold(0),
00056             action_text_italic(0),
00057             action_text_underline(0),
00058             action_text_strikeout(0),
00059             action_font_family(0),
00060             action_font_size(0),
00061             action_list_style(0),
00062             action_list_indent(0),
00063             action_list_dedent(0),
00064             action_manage_link(0),
00065             action_insert_horizontal_rule(0),
00066             action_format_painter(0),
00067             action_to_plain_text(0),
00068             action_align_left(0),
00069             action_align_right(0),
00070             action_align_center(0),
00071             action_align_justify(0),
00072             action_text_superscript(0),
00073             action_text_subscript(0)
00074     {
00075     }
00076 
00077     KRichTextWidget *q;
00078 
00079     RichTextSupport richTextSupport;
00080 
00081     QTextCharFormat painterFormat;
00082     bool painterActive;
00083 
00084     QList<KAction*> richTextActionList;
00085 
00086     bool richTextEnabled;
00087     KToggleAction *enableRichText;
00088 
00089     KAction *action_text_foreground_color;
00090     KAction *action_text_background_color;
00091 
00092     KToggleAction *action_text_bold;
00093     KToggleAction *action_text_italic;
00094     KToggleAction *action_text_underline;
00095     KToggleAction *action_text_strikeout;
00096 
00097     KFontAction *action_font_family;
00098     KFontSizeAction *action_font_size;
00099 
00100     KSelectAction *action_list_style;
00101     KAction *action_list_indent;
00102     KAction *action_list_dedent;
00103 
00104     KAction *action_manage_link;
00105     KAction *action_insert_horizontal_rule;
00106     KAction *action_format_painter;
00107     KAction *action_to_plain_text;
00108 
00109     KToggleAction *action_align_left;
00110     KToggleAction *action_align_right;
00111     KToggleAction *action_align_center;
00112     KToggleAction *action_align_justify;
00113 
00114     KToggleAction *action_text_superscript;
00115     KToggleAction *action_text_subscript;
00116 
00117     //
00118     // Normal functions
00119     //
00120     void init();
00121 
00122     //
00123     // Slots
00124     //
00125 
00129     void _k_setTextForegroundColor();
00130 
00134     void _k_setTextBackgroundColor();
00135 
00143     void _k_manageLink();
00144 
00150     void _k_formatPainter(bool active);
00151 
00155     void _k_updateCharFormatActions(const QTextCharFormat &format);
00156 
00161     void _k_updateMiscActions();
00162 
00166     void _k_setListStyle(int index);
00167 
00168 };
00169 //@endcond
00170 
00171 void KRichTextWidget::Private::init()
00172 {
00173     q->setRichTextSupport(KRichTextWidget::FullSupport);
00174 }
00175 
00176 KRichTextWidget::KRichTextWidget(QWidget* parent)
00177         : KRichTextEdit(parent),
00178         d(new Private(this))
00179 {
00180     d->init();
00181 }
00182 
00183 KRichTextWidget::KRichTextWidget(const QString& text, QWidget *parent)
00184         : KRichTextEdit(text,parent),
00185         d(new Private(this))
00186 {
00187     d->init();
00188 }
00189 
00190 KRichTextWidget::~KRichTextWidget()
00191 {
00192     delete d;
00193 }
00194 
00195 KRichTextWidget::RichTextSupport KRichTextWidget::richTextSupport() const
00196 {
00197     return d->richTextSupport;
00198 }
00199 
00200 void KRichTextWidget::setRichTextSupport(const KRichTextWidget::RichTextSupport &support)
00201 {
00202     d->richTextSupport = support;
00203 }
00204 
00205 void KRichTextWidget::createActions(KActionCollection *actionCollection)
00206 {
00207     Q_ASSERT(actionCollection);
00208 
00209     // Note to maintainers: If adding new functionality here, make sure to disconnect
00210     // and delete actions which should not be supported.
00211     //
00212     // New Actions need to be added to the following places:
00213     // - possibly the RichTextSupportValues enum
00214     // - the API documentation for createActions()
00215     // - this function
00216     // - the action needs to be added to the private class as a member
00217     // - the constructor of the private class
00218     // - depending on the action, some slot that changes the toggle state when
00219     //   appropriate, such as _k_updateCharFormatActions or _k_updateMiscActions.
00220 
00221     // The list of actions currently supported is also stored internally.
00222     // This is used to disable all actions at once in setActionsEnabled.
00223     d->richTextActionList.clear();
00224 
00225     if (d->richTextSupport & SupportTextForegroundColor) {
00226         //Foreground Color
00227         d->action_text_foreground_color = new KAction(KIcon("format-stroke-color"), i18nc("@action", "Text &Color..."), actionCollection);
00228         d->action_text_foreground_color->setIconText(i18nc("@label stroke color", "Color"));
00229         d->richTextActionList.append((d->action_text_foreground_color));
00230         actionCollection->addAction("format_text_foreground_color", d->action_text_foreground_color);
00231         connect(d->action_text_foreground_color, SIGNAL(triggered()), this, SLOT(_k_setTextForegroundColor()));
00232     } else {
00233         actionCollection->removeAction(d->action_text_foreground_color);
00234         d->action_text_foreground_color = 0;
00235     }
00236 
00237     if (d->richTextSupport & SupportTextBackgroundColor) {
00238         //Background Color
00239         d->action_text_background_color = new KAction(KIcon("format-fill-color"), i18nc("@action", "Text &Highlight..."), actionCollection);
00240         d->richTextActionList.append((d->action_text_background_color));
00241         actionCollection->addAction("format_text_background_color", d->action_text_background_color);
00242         connect(d->action_text_background_color, SIGNAL(triggered()), this, SLOT(_k_setTextBackgroundColor()));
00243     } else {
00244         actionCollection->removeAction(d->action_text_background_color);
00245         d->action_text_background_color = 0;
00246     }
00247 
00248     if (d->richTextSupport & SupportFontFamily) {
00249         //Font Family
00250         d->action_font_family = new KFontAction(i18nc("@action", "&Font"), actionCollection);
00251         d->richTextActionList.append((d->action_font_family));
00252         actionCollection->addAction("format_font_family", d->action_font_family);
00253         connect(d->action_font_family, SIGNAL(triggered(QString)), this, SLOT(setFontFamily(QString)));
00254     } else {
00255         actionCollection->removeAction(d->action_font_family);
00256         d->action_font_family = 0;
00257     }
00258 
00259     if (d->richTextSupport & SupportFontSize) {
00260         //Font Size
00261         d->action_font_size = new KFontSizeAction(i18nc("@action", "Font &Size"), actionCollection);
00262         d->richTextActionList.append((d->action_font_size));
00263         actionCollection->addAction("format_font_size", d->action_font_size);
00264         connect(d->action_font_size, SIGNAL(fontSizeChanged(int)), this, SLOT(setFontSize(int)));
00265     } else {
00266         actionCollection->removeAction(d->action_font_size);
00267         d->action_font_size = 0;
00268     }
00269 
00270     if (d->richTextSupport & SupportBold) {
00271         d->action_text_bold = new KToggleAction(KIcon("format-text-bold"), i18nc("@action boldify selected text", "&Bold"), actionCollection);
00272         QFont bold;
00273         bold.setBold(true);
00274         d->action_text_bold->setFont(bold);
00275         d->richTextActionList.append((d->action_text_bold));
00276         actionCollection->addAction("format_text_bold", d->action_text_bold);
00277         d->action_text_bold->setShortcut(KShortcut(Qt::CTRL + Qt::Key_B));
00278         connect(d->action_text_bold, SIGNAL(triggered(bool)), this, SLOT(setTextBold(bool)));
00279     } else {
00280         actionCollection->removeAction(d->action_text_bold);
00281         d->action_text_bold = 0;
00282     }
00283 
00284     if (d->richTextSupport & SupportItalic) {
00285         d->action_text_italic = new KToggleAction(KIcon("format-text-italic"), i18nc("@action italicize selected text", "&Italic"), actionCollection);
00286         QFont italic;
00287         italic.setItalic(true);
00288         d->action_text_italic->setFont(italic);
00289         d->richTextActionList.append((d->action_text_italic));
00290         actionCollection->addAction("format_text_italic", d->action_text_italic);
00291         d->action_text_italic->setShortcut(KShortcut(Qt::CTRL + Qt::Key_I));
00292         connect(d->action_text_italic, SIGNAL(triggered(bool)),
00293                 this, SLOT(setTextItalic(bool)));
00294     } else {
00295         actionCollection->removeAction(d->action_text_italic);
00296         d->action_text_italic = 0;
00297     }
00298 
00299     if (d->richTextSupport & SupportUnderline) {
00300         d->action_text_underline = new KToggleAction(KIcon("format-text-underline"), i18nc("@action underline selected text", "&Underline"), actionCollection);
00301         QFont underline;
00302         underline.setUnderline(true);
00303         d->action_text_underline->setFont(underline);
00304         d->richTextActionList.append((d->action_text_underline));
00305         actionCollection->addAction("format_text_underline", d->action_text_underline);
00306         d->action_text_underline->setShortcut(KShortcut(Qt::CTRL + Qt::Key_U));
00307         connect(d->action_text_underline, SIGNAL(triggered(bool)),
00308                 this, SLOT(setTextUnderline(bool)));
00309     } else {
00310         actionCollection->removeAction(d->action_text_underline);
00311         d->action_text_underline = 0;
00312     }
00313 
00314     if (d->richTextSupport & SupportStrikeOut) {
00315         d->action_text_strikeout = new KToggleAction(KIcon("format-text-strikethrough"), i18nc("@action", "&Strike Out"), actionCollection);
00316         d->richTextActionList.append((d->action_text_strikeout));
00317         actionCollection->addAction("format_text_strikeout", d->action_text_strikeout);
00318         d->action_text_strikeout->setShortcut(KShortcut(Qt::CTRL + Qt::Key_L));
00319         connect(d->action_text_strikeout, SIGNAL(triggered(bool)),
00320                 this, SLOT(setTextStrikeOut(bool)));
00321     } else {
00322         actionCollection->removeAction(d->action_text_strikeout);
00323         d->action_text_strikeout = 0;
00324     }
00325 
00326     if (d->richTextSupport & SupportAlignment) {
00327         //Alignment
00328         d->action_align_left = new KToggleAction(KIcon("format-justify-left"), i18nc("@action", "Align &Left"), actionCollection);
00329         d->action_align_left->setIconText(i18nc("@label left justify", "Left"));
00330         d->richTextActionList.append((d->action_align_left));
00331         actionCollection->addAction("format_align_left", d->action_align_left);
00332         connect(d->action_align_left, SIGNAL(triggered()),
00333                 this, SLOT(alignLeft()));
00334 
00335         d->action_align_center = new KToggleAction(KIcon("format-justify-center"), i18nc("@action", "Align &Center"), actionCollection);
00336         d->action_align_center->setIconText(i18nc("@label center justify", "Center"));
00337         d->richTextActionList.append((d->action_align_center));
00338         actionCollection->addAction("format_align_center", d->action_align_center);
00339         connect(d->action_align_center, SIGNAL(triggered()),
00340                 this, SLOT(alignCenter()));
00341 
00342         d->action_align_right = new KToggleAction(KIcon("format-justify-right"), i18nc("@action", "Align &Right"), actionCollection);
00343         d->action_align_right->setIconText(i18nc("@label right justify", "Right"));
00344         d->richTextActionList.append((d->action_align_right));
00345         actionCollection->addAction("format_align_right", d->action_align_right);
00346         connect(d->action_align_right, SIGNAL(triggered()),
00347                 this, SLOT(alignRight()));
00348 
00349         d->action_align_justify = new KToggleAction(KIcon("format-justify-fill"), i18nc("@action", "&Justify"), actionCollection);
00350         d->action_align_justify->setIconText(i18nc("@label justify fill", "Justify"));
00351         d->richTextActionList.append((d->action_align_justify));
00352         actionCollection->addAction("format_align_justify", d->action_align_justify);
00353         connect(d->action_align_justify, SIGNAL(triggered()),
00354                 this, SLOT(alignJustify()));
00355 
00356         QActionGroup *alignmentGroup = new QActionGroup(this);
00357         alignmentGroup->addAction(d->action_align_left);
00358         alignmentGroup->addAction(d->action_align_center);
00359         alignmentGroup->addAction(d->action_align_right);
00360         alignmentGroup->addAction(d->action_align_justify);
00361     } else {
00362 
00363         actionCollection->removeAction(d->action_align_left);
00364         actionCollection->removeAction(d->action_align_center);
00365         actionCollection->removeAction(d->action_align_right);
00366         actionCollection->removeAction(d->action_align_justify);
00367 
00368         d->action_align_left = 0;
00369         d->action_align_center = 0;
00370         d->action_align_right = 0;
00371         d->action_align_justify = 0;
00372     }
00373 
00374     if (d->richTextSupport & SupportChangeListStyle) {
00375         d->action_list_style = new KSelectAction(KIcon("format-list-unordered"), i18nc("@title:menu", "List Style"), actionCollection);
00376         QStringList listStyles;
00377         listStyles      << i18nc("@item:inmenu no list style", "None")
00378         << i18nc("@item:inmenu disc list style", "Disc")
00379         << i18nc("@item:inmenu circle list style", "Circle")
00380         << i18nc("@item:inmenu square list style", "Square")
00381         << i18nc("@item:inmenu numbered lists", "123")
00382         << i18nc("@item:inmenu lowercase abc lists", "abc")
00383         << i18nc("@item:inmenu uppercase abc lists", "ABC");
00384         d->action_list_style->setItems(listStyles);
00385         d->action_list_style->setCurrentItem(0);
00386         d->richTextActionList.append((d->action_list_style));
00387         actionCollection->addAction("format_list_style", d->action_list_style);
00388         connect(d->action_list_style, SIGNAL(triggered(int)),
00389                 this, SLOT(_k_setListStyle(int)));
00390         connect(d->action_list_style, SIGNAL(triggered()),
00391                 this, SLOT(_k_updateMiscActions()));
00392 
00393     } else {
00394         actionCollection->removeAction(d->action_list_style);
00395         d->action_list_style = 0;
00396     }
00397 
00398     if (d->richTextSupport & SupportIndentLists) {
00399         d->action_list_indent = new KAction(KIcon("format-indent-more"), i18nc("@action", "Increase Indent"), actionCollection);
00400         d->richTextActionList.append((d->action_list_indent));
00401         actionCollection->addAction("format_list_indent_more", d->action_list_indent);
00402         connect(d->action_list_indent, SIGNAL(triggered()),
00403                 this, SLOT(indentListMore()));
00404         connect(d->action_list_indent, SIGNAL(triggered()),
00405                 this, SLOT(_k_updateMiscActions()));
00406     } else {
00407         actionCollection->removeAction(d->action_list_indent);
00408         d->action_list_indent = 0;
00409     }
00410 
00411     if (d->richTextSupport & SupportDedentLists) {
00412         d->action_list_dedent = new KAction(KIcon("format-indent-less"), i18nc("@action", "Decrease Indent"), actionCollection);
00413         d->richTextActionList.append((d->action_list_dedent));
00414         actionCollection->addAction("format_list_indent_less", d->action_list_dedent);
00415         connect(d->action_list_dedent, SIGNAL(triggered()),
00416                 this, SLOT(indentListLess()));
00417         connect(d->action_list_dedent, SIGNAL(triggered()),
00418                 this, SLOT(_k_updateMiscActions()));
00419     } else {
00420         actionCollection->removeAction(d->action_list_dedent);
00421         d->action_list_dedent = 0;
00422     }
00423 
00424     if (d->richTextSupport & SupportRuleLine) {
00425         d->action_insert_horizontal_rule = new KAction(KIcon("insert-horizontal-rule"), i18nc("@action", "Insert Rule Line"), actionCollection);
00426         d->richTextActionList.append((d->action_insert_horizontal_rule));
00427         actionCollection->addAction("insert_horizontal_rule", d->action_insert_horizontal_rule);
00428         connect(d->action_insert_horizontal_rule, SIGNAL(triggered()),
00429                 this, SLOT(insertHorizontalRule()));
00430     } else {
00431         actionCollection->removeAction(d->action_insert_horizontal_rule);
00432         d->action_insert_horizontal_rule = 0;
00433     }
00434 
00435     if (d->richTextSupport & SupportHyperlinks) {
00436         d->action_manage_link = new KAction(KIcon("insert-link"), i18nc("@action", "Link"), actionCollection);
00437         d->richTextActionList.append((d->action_manage_link));
00438         actionCollection->addAction("manage_link", d->action_manage_link);
00439         connect(d->action_manage_link, SIGNAL(triggered()),
00440                 this, SLOT(_k_manageLink()));
00441     } else {
00442         actionCollection->removeAction(d->action_manage_link);
00443         d->action_manage_link = 0;
00444     }
00445 
00446     if (d->richTextSupport & SupportFormatPainting) {
00447         d->action_format_painter = new KToggleAction(KIcon("draw-brush"), i18nc("@action", "Format Painter"), actionCollection);
00448         d->richTextActionList.append((d->action_format_painter));
00449         actionCollection->addAction("format_painter", d->action_format_painter);
00450         connect(d->action_format_painter, SIGNAL(toggled(bool)),
00451                 this, SLOT(_k_formatPainter(bool)));
00452     } else {
00453         actionCollection->removeAction(d->action_format_painter);
00454         d->action_format_painter = 0;
00455     }
00456 
00457     if (d->richTextSupport & SupportToPlainText) {
00458         d->action_to_plain_text = new KToggleAction(i18nc("@action", "To Plain Text"), actionCollection);
00459         d->richTextActionList.append((d->action_to_plain_text));
00460         actionCollection->addAction("action_to_plain_text", d->action_to_plain_text);
00461         connect(d->action_to_plain_text, SIGNAL(triggered()),
00462                 this, SLOT(switchToPlainText()));
00463     } else {
00464         actionCollection->removeAction(d->action_to_plain_text);
00465         d->action_to_plain_text = 0;
00466     }
00467 
00468     if (d->richTextSupport & SupportSuperScriptAndSubScript) {
00469         d->action_text_subscript = new KToggleAction(KIcon("format-text-subscript"), i18nc("@action", "Subscript"), actionCollection);
00470         d->richTextActionList.append((d->action_text_subscript));
00471         actionCollection->addAction("format_text_subscript", d->action_text_subscript);
00472 
00473         connect(d->action_text_subscript, SIGNAL(triggered(bool)),
00474                 this, SLOT(setTextSubScript(bool)));
00475 
00476         d->action_text_superscript = new KToggleAction(KIcon("format-text-superscript"), i18nc("@action", "Superscript"), actionCollection);
00477         d->richTextActionList.append((d->action_text_superscript));
00478         actionCollection->addAction("format_text_superscript", d->action_text_superscript);
00479 
00480         connect(d->action_text_superscript, SIGNAL(triggered(bool)),
00481                 this, SLOT(setTextSuperScript(bool)));
00482     } else {
00483         actionCollection->removeAction(d->action_text_subscript);
00484         d->action_text_subscript = 0;
00485 
00486         actionCollection->removeAction(d->action_text_superscript);
00487         d->action_text_superscript = 0;
00488     }
00489     
00490 
00491     disconnect(this, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)),
00492                this, SLOT(_k_updateCharFormatActions(const QTextCharFormat &)));
00493     disconnect(this, SIGNAL(cursorPositionChanged()),
00494                this, SLOT(_k_updateMiscActions()));
00495     connect(this, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)),
00496             this, SLOT(_k_updateCharFormatActions(const QTextCharFormat &)));
00497     connect(this, SIGNAL(cursorPositionChanged()),
00498             this, SLOT(_k_updateMiscActions()));
00499 
00500     d->_k_updateMiscActions();
00501     d->_k_updateCharFormatActions(currentCharFormat());
00502 }
00503 
00504 
00505 void KRichTextWidget::setActionsEnabled(bool enabled)
00506 {
00507     foreach(QAction* action, d->richTextActionList)
00508     {
00509         action->setEnabled(enabled);
00510     }
00511     d->richTextEnabled = enabled;
00512 }
00513 
00514 void KRichTextWidget::Private::_k_setListStyle(int index)
00515 {
00516     q->setListStyle(index);
00517     _k_updateMiscActions();
00518 }
00519 
00520 void KRichTextWidget::Private::_k_updateCharFormatActions(const QTextCharFormat &format)
00521 {
00522     QFont f = format.font();
00523 
00524     if (richTextSupport & SupportFontFamily) {
00525         action_font_family->setFont(f.family());
00526     }
00527     if (richTextSupport & SupportFontSize) {
00528         if (f.pointSize() > 0)
00529             action_font_size->setFontSize((int)f.pointSize());
00530     }
00531 
00532     if (richTextSupport & SupportBold) {
00533         action_text_bold->setChecked(f.bold());
00534     }
00535 
00536     if (richTextSupport & SupportItalic) {
00537         action_text_italic->setChecked(f.italic());
00538     }
00539 
00540     if (richTextSupport & SupportUnderline) {
00541         action_text_underline->setChecked(f.underline());
00542     }
00543 
00544     if (richTextSupport & SupportStrikeOut) {
00545         action_text_strikeout->setChecked(f.strikeOut());
00546     }
00547 
00548     if (richTextSupport & SupportSuperScriptAndSubScript) {
00549         QTextCharFormat::VerticalAlignment vAlign = format.verticalAlignment();
00550         action_text_superscript->setChecked(vAlign == QTextCharFormat::AlignSuperScript);
00551         action_text_subscript->setChecked(vAlign == QTextCharFormat::AlignSubScript);
00552     }
00553 }
00554 
00555 void KRichTextWidget::Private::_k_updateMiscActions()
00556 {
00557     if (richTextSupport & SupportAlignment) {
00558         Qt::Alignment a = q->alignment();
00559         if (a & Qt::AlignLeft) {
00560             action_align_left->setChecked(true);
00561         } else if (a & Qt::AlignHCenter) {
00562             action_align_center->setChecked(true);
00563         } else if (a & Qt::AlignRight) {
00564             action_align_right->setChecked(true);
00565         } else if (a & Qt::AlignJustify) {
00566             action_align_justify->setChecked(true);
00567         }
00568     }
00569 
00570 
00571     if (richTextSupport & SupportChangeListStyle) {
00572         if (q->textCursor().currentList()) {
00573             action_list_style->setCurrentItem(-q->textCursor().currentList()->format().style());
00574         } else {
00575             action_list_style->setCurrentItem(0);
00576         }
00577     }
00578 
00579 
00580     if ( richTextSupport & SupportIndentLists ) {
00581         if ( richTextEnabled ) {
00582             action_list_indent->setEnabled( q->canIndentList() );
00583         } else {
00584             action_list_indent->setEnabled( false );
00585         }
00586     }
00587 
00588     if ( richTextSupport & SupportDedentLists ) {
00589         if ( richTextEnabled ) {
00590             action_list_dedent->setEnabled( q->canDedentList() );   
00591         } else {
00592             action_list_dedent->setEnabled( false );
00593         }
00594     }
00595 
00596 }
00597 
00598 void KRichTextWidget::Private::_k_setTextForegroundColor()
00599 {
00600     QColor currentTextForegroundColor = q->textColor();
00601 
00602     int result = KColorDialog::getColor(currentTextForegroundColor, KColorScheme(QPalette::Active, KColorScheme::View).foreground().color() , q);
00603     if (!currentTextForegroundColor.isValid())
00604         currentTextForegroundColor = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color() ;
00605     if (result != QDialog::Accepted)
00606         return;
00607 
00608     q->setTextForegroundColor(currentTextForegroundColor);
00609 
00610 }
00611 
00612 void KRichTextWidget::Private::_k_setTextBackgroundColor()
00613 {
00614     QTextCharFormat fmt = q->textCursor().charFormat();
00615     QColor currentTextBackgroundColor = fmt.background().color();
00616 
00617     int result = KColorDialog::getColor(currentTextBackgroundColor, KColorScheme(QPalette::Active, KColorScheme::View).foreground().color() , q);
00618     if (!currentTextBackgroundColor.isValid())
00619         currentTextBackgroundColor = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color() ;
00620     if (result != QDialog::Accepted)
00621         return;
00622 
00623     q->setTextBackgroundColor(currentTextBackgroundColor);
00624 
00625 }
00626 
00627 void KRichTextWidget::Private::_k_manageLink()
00628 {
00629     q->selectLinkText();
00630     KLinkDialog *linkDialog = new KLinkDialog(q);
00631     linkDialog->setLinkText(q->currentLinkText());
00632     linkDialog->setLinkUrl(q->currentLinkUrl());
00633 
00634     if (linkDialog->exec()) {
00635         q->updateLink(linkDialog->linkUrl(), linkDialog->linkText());
00636     }
00637 
00638     delete linkDialog;
00639 
00640 }
00641 
00642 void KRichTextWidget::mouseReleaseEvent(QMouseEvent *event)
00643 {
00644     if (d->painterActive) {
00645         // If the painter is active, paint the selection with the
00646         // correct format.
00647         if (textCursor().hasSelection()) {
00648             textCursor().setCharFormat(d->painterFormat);
00649         }
00650         d->painterActive = false;
00651         d->action_format_painter->setChecked(false);
00652     }
00653     KRichTextEdit::mouseReleaseEvent(event);
00654 }
00655 
00656 void KRichTextWidget::Private::_k_formatPainter(bool active)
00657 {
00658     if (active) {
00659         painterFormat = q->currentCharFormat();
00660         painterActive = true;
00661         q->viewport()->setCursor(QCursor(KIcon("draw-brush").pixmap(32, 32), 0, 32));
00662     } else {
00663         painterFormat = QTextCharFormat();
00664         painterActive = false;
00665         q->viewport()->setCursor(Qt::IBeamCursor);
00666     }
00667 }
00668 
00669 void KRichTextWidget::updateActionStates()
00670 {
00671     d->_k_updateMiscActions();
00672     d->_k_updateCharFormatActions(currentCharFormat());
00673 }
00674 
00675 // kate: space-indent on; indent-width 4; encoding utf-8; replace-tabs on;
00676 #include "krichtextwidget.moc"

KDEUI

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal