• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • 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_direction_ltr(0),
00073             action_direction_rtl(0),
00074             action_text_superscript(0),
00075             action_text_subscript(0)
00076     {
00077     }
00078 
00079     KRichTextWidget *q;
00080 
00081     RichTextSupport richTextSupport;
00082 
00083     QTextCharFormat painterFormat;
00084     bool painterActive;
00085 
00086     QList<KAction*> richTextActionList;
00087 
00088     bool richTextEnabled;
00089     KToggleAction *enableRichText;
00090 
00091     KAction *action_text_foreground_color;
00092     KAction *action_text_background_color;
00093 
00094     KToggleAction *action_text_bold;
00095     KToggleAction *action_text_italic;
00096     KToggleAction *action_text_underline;
00097     KToggleAction *action_text_strikeout;
00098 
00099     KFontAction *action_font_family;
00100     KFontSizeAction *action_font_size;
00101 
00102     KSelectAction *action_list_style;
00103     KAction *action_list_indent;
00104     KAction *action_list_dedent;
00105 
00106     KAction *action_manage_link;
00107     KAction *action_insert_horizontal_rule;
00108     KAction *action_format_painter;
00109     KAction *action_to_plain_text;
00110 
00111     KToggleAction *action_align_left;
00112     KToggleAction *action_align_right;
00113     KToggleAction *action_align_center;
00114     KToggleAction *action_align_justify;
00115 
00116     KToggleAction *action_direction_ltr;
00117     KToggleAction *action_direction_rtl;
00118 
00119     KToggleAction *action_text_superscript;
00120     KToggleAction *action_text_subscript;
00121 
00122     //
00123     // Normal functions
00124     //
00125     void init();
00126 
00127     //
00128     // Slots
00129     //
00130 
00134     void _k_setTextForegroundColor();
00135 
00139     void _k_setTextBackgroundColor();
00140 
00148     void _k_manageLink();
00149 
00155     void _k_formatPainter(bool active);
00156 
00160     void _k_updateCharFormatActions(const QTextCharFormat &format);
00161 
00166     void _k_updateMiscActions();
00167 
00171     void _k_setListStyle(int index);
00172 
00173 };
00174 //@endcond
00175 
00176 void KRichTextWidget::Private::init()
00177 {
00178     q->setRichTextSupport(KRichTextWidget::FullSupport);
00179 }
00180 
00181 KRichTextWidget::KRichTextWidget(QWidget* parent)
00182         : KRichTextEdit(parent),
00183         d(new Private(this))
00184 {
00185     d->init();
00186 }
00187 
00188 KRichTextWidget::KRichTextWidget(const QString& text, QWidget *parent)
00189         : KRichTextEdit(text,parent),
00190         d(new Private(this))
00191 {
00192     d->init();
00193 }
00194 
00195 KRichTextWidget::~KRichTextWidget()
00196 {
00197     delete d;
00198 }
00199 
00200 KRichTextWidget::RichTextSupport KRichTextWidget::richTextSupport() const
00201 {
00202     return d->richTextSupport;
00203 }
00204 
00205 void KRichTextWidget::setRichTextSupport(const KRichTextWidget::RichTextSupport &support)
00206 {
00207     d->richTextSupport = support;
00208 }
00209 
00210 void KRichTextWidget::createActions(KActionCollection *actionCollection)
00211 {
00212     Q_ASSERT(actionCollection);
00213 
00214     // Note to maintainers: If adding new functionality here, make sure to disconnect
00215     // and delete actions which should not be supported.
00216     //
00217     // New Actions need to be added to the following places:
00218     // - possibly the RichTextSupportValues enum
00219     // - the API documentation for createActions()
00220     // - this function
00221     // - the action needs to be added to the private class as a member
00222     // - the constructor of the private class
00223     // - depending on the action, some slot that changes the toggle state when
00224     //   appropriate, such as _k_updateCharFormatActions or _k_updateMiscActions.
00225 
00226     // The list of actions currently supported is also stored internally.
00227     // This is used to disable all actions at once in setActionsEnabled.
00228     d->richTextActionList.clear();
00229 
00230     if (d->richTextSupport & SupportTextForegroundColor) {
00231         //Foreground Color
00232         d->action_text_foreground_color = new KAction(KIcon("format-stroke-color"), i18nc("@action", "Text &Color..."), actionCollection);
00233         d->action_text_foreground_color->setIconText(i18nc("@label stroke color", "Color"));
00234         d->richTextActionList.append((d->action_text_foreground_color));
00235         actionCollection->addAction("format_text_foreground_color", d->action_text_foreground_color);
00236         connect(d->action_text_foreground_color, SIGNAL(triggered()), this, SLOT(_k_setTextForegroundColor()));
00237     } else {
00238         actionCollection->removeAction(d->action_text_foreground_color);
00239         d->action_text_foreground_color = 0;
00240     }
00241 
00242     if (d->richTextSupport & SupportTextBackgroundColor) {
00243         //Background Color
00244         d->action_text_background_color = new KAction(KIcon("format-fill-color"), i18nc("@action", "Text &Highlight..."), actionCollection);
00245         d->richTextActionList.append((d->action_text_background_color));
00246         actionCollection->addAction("format_text_background_color", d->action_text_background_color);
00247         connect(d->action_text_background_color, SIGNAL(triggered()), this, SLOT(_k_setTextBackgroundColor()));
00248     } else {
00249         actionCollection->removeAction(d->action_text_background_color);
00250         d->action_text_background_color = 0;
00251     }
00252 
00253     if (d->richTextSupport & SupportFontFamily) {
00254         //Font Family
00255         d->action_font_family = new KFontAction(i18nc("@action", "&Font"), actionCollection);
00256         d->richTextActionList.append((d->action_font_family));
00257         actionCollection->addAction("format_font_family", d->action_font_family);
00258         connect(d->action_font_family, SIGNAL(triggered(QString)), this, SLOT(setFontFamily(QString)));
00259     } else {
00260         actionCollection->removeAction(d->action_font_family);
00261         d->action_font_family = 0;
00262     }
00263 
00264     if (d->richTextSupport & SupportFontSize) {
00265         //Font Size
00266         d->action_font_size = new KFontSizeAction(i18nc("@action", "Font &Size"), actionCollection);
00267         d->richTextActionList.append((d->action_font_size));
00268         actionCollection->addAction("format_font_size", d->action_font_size);
00269         connect(d->action_font_size, SIGNAL(fontSizeChanged(int)), this, SLOT(setFontSize(int)));
00270     } else {
00271         actionCollection->removeAction(d->action_font_size);
00272         d->action_font_size = 0;
00273     }
00274 
00275     if (d->richTextSupport & SupportBold) {
00276         d->action_text_bold = new KToggleAction(KIcon("format-text-bold"), i18nc("@action boldify selected text", "&Bold"), actionCollection);
00277         QFont bold;
00278         bold.setBold(true);
00279         d->action_text_bold->setFont(bold);
00280         d->richTextActionList.append((d->action_text_bold));
00281         actionCollection->addAction("format_text_bold", d->action_text_bold);
00282         d->action_text_bold->setShortcut(KShortcut(Qt::CTRL + Qt::Key_B));
00283         connect(d->action_text_bold, SIGNAL(triggered(bool)), this, SLOT(setTextBold(bool)));
00284     } else {
00285         actionCollection->removeAction(d->action_text_bold);
00286         d->action_text_bold = 0;
00287     }
00288 
00289     if (d->richTextSupport & SupportItalic) {
00290         d->action_text_italic = new KToggleAction(KIcon("format-text-italic"), i18nc("@action italicize selected text", "&Italic"), actionCollection);
00291         QFont italic;
00292         italic.setItalic(true);
00293         d->action_text_italic->setFont(italic);
00294         d->richTextActionList.append((d->action_text_italic));
00295         actionCollection->addAction("format_text_italic", d->action_text_italic);
00296         d->action_text_italic->setShortcut(KShortcut(Qt::CTRL + Qt::Key_I));
00297         connect(d->action_text_italic, SIGNAL(triggered(bool)),
00298                 this, SLOT(setTextItalic(bool)));
00299     } else {
00300         actionCollection->removeAction(d->action_text_italic);
00301         d->action_text_italic = 0;
00302     }
00303 
00304     if (d->richTextSupport & SupportUnderline) {
00305         d->action_text_underline = new KToggleAction(KIcon("format-text-underline"), i18nc("@action underline selected text", "&Underline"), actionCollection);
00306         QFont underline;
00307         underline.setUnderline(true);
00308         d->action_text_underline->setFont(underline);
00309         d->richTextActionList.append((d->action_text_underline));
00310         actionCollection->addAction("format_text_underline", d->action_text_underline);
00311         d->action_text_underline->setShortcut(KShortcut(Qt::CTRL + Qt::Key_U));
00312         connect(d->action_text_underline, SIGNAL(triggered(bool)),
00313                 this, SLOT(setTextUnderline(bool)));
00314     } else {
00315         actionCollection->removeAction(d->action_text_underline);
00316         d->action_text_underline = 0;
00317     }
00318 
00319     if (d->richTextSupport & SupportStrikeOut) {
00320         d->action_text_strikeout = new KToggleAction(KIcon("format-text-strikethrough"), i18nc("@action", "&Strike Out"), actionCollection);
00321         d->richTextActionList.append((d->action_text_strikeout));
00322         actionCollection->addAction("format_text_strikeout", d->action_text_strikeout);
00323         d->action_text_strikeout->setShortcut(KShortcut(Qt::CTRL + Qt::Key_L));
00324         connect(d->action_text_strikeout, SIGNAL(triggered(bool)),
00325                 this, SLOT(setTextStrikeOut(bool)));
00326     } else {
00327         actionCollection->removeAction(d->action_text_strikeout);
00328         d->action_text_strikeout = 0;
00329     }
00330 
00331     if (d->richTextSupport & SupportAlignment) {
00332         //Alignment
00333         d->action_align_left = new KToggleAction(KIcon("format-justify-left"), i18nc("@action", "Align &Left"), actionCollection);
00334         d->action_align_left->setIconText(i18nc("@label left justify", "Left"));
00335         d->richTextActionList.append((d->action_align_left));
00336         actionCollection->addAction("format_align_left", d->action_align_left);
00337         connect(d->action_align_left, SIGNAL(triggered()),
00338                 this, SLOT(alignLeft()));
00339 
00340         d->action_align_center = new KToggleAction(KIcon("format-justify-center"), i18nc("@action", "Align &Center"), actionCollection);
00341         d->action_align_center->setIconText(i18nc("@label center justify", "Center"));
00342         d->richTextActionList.append((d->action_align_center));
00343         actionCollection->addAction("format_align_center", d->action_align_center);
00344         connect(d->action_align_center, SIGNAL(triggered()),
00345                 this, SLOT(alignCenter()));
00346 
00347         d->action_align_right = new KToggleAction(KIcon("format-justify-right"), i18nc("@action", "Align &Right"), actionCollection);
00348         d->action_align_right->setIconText(i18nc("@label right justify", "Right"));
00349         d->richTextActionList.append((d->action_align_right));
00350         actionCollection->addAction("format_align_right", d->action_align_right);
00351         connect(d->action_align_right, SIGNAL(triggered()),
00352                 this, SLOT(alignRight()));
00353 
00354         d->action_align_justify = new KToggleAction(KIcon("format-justify-fill"), i18nc("@action", "&Justify"), actionCollection);
00355         d->action_align_justify->setIconText(i18nc("@label justify fill", "Justify"));
00356         d->richTextActionList.append((d->action_align_justify));
00357         actionCollection->addAction("format_align_justify", d->action_align_justify);
00358         connect(d->action_align_justify, SIGNAL(triggered()),
00359                 this, SLOT(alignJustify()));
00360 
00361         QActionGroup *alignmentGroup = new QActionGroup(this);
00362         alignmentGroup->addAction(d->action_align_left);
00363         alignmentGroup->addAction(d->action_align_center);
00364         alignmentGroup->addAction(d->action_align_right);
00365         alignmentGroup->addAction(d->action_align_justify);
00366     } else {
00367 
00368         actionCollection->removeAction(d->action_align_left);
00369         actionCollection->removeAction(d->action_align_center);
00370         actionCollection->removeAction(d->action_align_right);
00371         actionCollection->removeAction(d->action_align_justify);
00372 
00373         d->action_align_left = 0;
00374         d->action_align_center = 0;
00375         d->action_align_right = 0;
00376         d->action_align_justify = 0;
00377     }
00378 
00379     if (d->richTextSupport & SupportDirection) {
00380         d->action_direction_ltr = new KToggleAction(KIcon("format-text-direction-ltr"), i18nc("@action", "Left-to-Right"), actionCollection);
00381         d->action_direction_ltr->setIconText(i18nc("@label left-to-right", "Left-to-Right"));
00382         d->richTextActionList.append(d->action_direction_ltr);
00383         actionCollection->addAction("direction_ltr", d->action_direction_ltr);
00384         connect(d->action_direction_ltr, SIGNAL(triggered()),
00385                 this, SLOT(makeLeftToRight()));
00386 
00387         d->action_direction_rtl = new KToggleAction(KIcon("format-text-direction-rtl"), i18nc("@action", "Right-to-Left"), actionCollection);
00388         d->action_direction_rtl->setIconText(i18nc("@label right-to-left", "Right-to-Left"));
00389         d->richTextActionList.append(d->action_direction_rtl);
00390         actionCollection->addAction("direction_rtl", d->action_direction_rtl);
00391         connect(d->action_direction_rtl, SIGNAL(triggered()),
00392                 this, SLOT(makeRightToLeft()));
00393 
00394         QActionGroup *directionGroup = new QActionGroup(this);
00395         directionGroup->addAction(d->action_direction_ltr);
00396         directionGroup->addAction(d->action_direction_rtl);
00397     } else {
00398         actionCollection->removeAction(d->action_direction_ltr);
00399         actionCollection->removeAction(d->action_direction_rtl);
00400 
00401         d->action_direction_ltr = 0;
00402         d->action_direction_rtl = 0;
00403     }
00404 
00405     if (d->richTextSupport & SupportChangeListStyle) {
00406         d->action_list_style = new KSelectAction(KIcon("format-list-unordered"), i18nc("@title:menu", "List Style"), actionCollection);
00407         QStringList listStyles;
00408         listStyles      << i18nc("@item:inmenu no list style", "None")
00409         << i18nc("@item:inmenu disc list style", "Disc")
00410         << i18nc("@item:inmenu circle list style", "Circle")
00411         << i18nc("@item:inmenu square list style", "Square")
00412         << i18nc("@item:inmenu numbered lists", "123")
00413         << i18nc("@item:inmenu lowercase abc lists", "abc")
00414         << i18nc("@item:inmenu uppercase abc lists", "ABC");
00415         d->action_list_style->setItems(listStyles);
00416         d->action_list_style->setCurrentItem(0);
00417         d->richTextActionList.append((d->action_list_style));
00418         actionCollection->addAction("format_list_style", d->action_list_style);
00419         connect(d->action_list_style, SIGNAL(triggered(int)),
00420                 this, SLOT(_k_setListStyle(int)));
00421         connect(d->action_list_style, SIGNAL(triggered()),
00422                 this, SLOT(_k_updateMiscActions()));
00423 
00424     } else {
00425         actionCollection->removeAction(d->action_list_style);
00426         d->action_list_style = 0;
00427     }
00428 
00429     if (d->richTextSupport & SupportIndentLists) {
00430         d->action_list_indent = new KAction(KIcon("format-indent-more"), i18nc("@action", "Increase Indent"), actionCollection);
00431         d->richTextActionList.append((d->action_list_indent));
00432         actionCollection->addAction("format_list_indent_more", d->action_list_indent);
00433         connect(d->action_list_indent, SIGNAL(triggered()),
00434                 this, SLOT(indentListMore()));
00435         connect(d->action_list_indent, SIGNAL(triggered()),
00436                 this, SLOT(_k_updateMiscActions()));
00437     } else {
00438         actionCollection->removeAction(d->action_list_indent);
00439         d->action_list_indent = 0;
00440     }
00441 
00442     if (d->richTextSupport & SupportDedentLists) {
00443         d->action_list_dedent = new KAction(KIcon("format-indent-less"), i18nc("@action", "Decrease Indent"), actionCollection);
00444         d->richTextActionList.append((d->action_list_dedent));
00445         actionCollection->addAction("format_list_indent_less", d->action_list_dedent);
00446         connect(d->action_list_dedent, SIGNAL(triggered()),
00447                 this, SLOT(indentListLess()));
00448         connect(d->action_list_dedent, SIGNAL(triggered()),
00449                 this, SLOT(_k_updateMiscActions()));
00450     } else {
00451         actionCollection->removeAction(d->action_list_dedent);
00452         d->action_list_dedent = 0;
00453     }
00454 
00455     if (d->richTextSupport & SupportRuleLine) {
00456         d->action_insert_horizontal_rule = new KAction(KIcon("insert-horizontal-rule"), i18nc("@action", "Insert Rule Line"), actionCollection);
00457         d->richTextActionList.append((d->action_insert_horizontal_rule));
00458         actionCollection->addAction("insert_horizontal_rule", d->action_insert_horizontal_rule);
00459         connect(d->action_insert_horizontal_rule, SIGNAL(triggered()),
00460                 this, SLOT(insertHorizontalRule()));
00461     } else {
00462         actionCollection->removeAction(d->action_insert_horizontal_rule);
00463         d->action_insert_horizontal_rule = 0;
00464     }
00465 
00466     if (d->richTextSupport & SupportHyperlinks) {
00467         d->action_manage_link = new KAction(KIcon("insert-link"), i18nc("@action", "Link"), actionCollection);
00468         d->richTextActionList.append((d->action_manage_link));
00469         actionCollection->addAction("manage_link", d->action_manage_link);
00470         connect(d->action_manage_link, SIGNAL(triggered()),
00471                 this, SLOT(_k_manageLink()));
00472     } else {
00473         actionCollection->removeAction(d->action_manage_link);
00474         d->action_manage_link = 0;
00475     }
00476 
00477     if (d->richTextSupport & SupportFormatPainting) {
00478         d->action_format_painter = new KToggleAction(KIcon("draw-brush"), i18nc("@action", "Format Painter"), actionCollection);
00479         d->richTextActionList.append((d->action_format_painter));
00480         actionCollection->addAction("format_painter", d->action_format_painter);
00481         connect(d->action_format_painter, SIGNAL(toggled(bool)),
00482                 this, SLOT(_k_formatPainter(bool)));
00483     } else {
00484         actionCollection->removeAction(d->action_format_painter);
00485         d->action_format_painter = 0;
00486     }
00487 
00488     if (d->richTextSupport & SupportToPlainText) {
00489         d->action_to_plain_text = new KToggleAction(i18nc("@action", "To Plain Text"), actionCollection);
00490         d->richTextActionList.append((d->action_to_plain_text));
00491         actionCollection->addAction("action_to_plain_text", d->action_to_plain_text);
00492         connect(d->action_to_plain_text, SIGNAL(triggered()),
00493                 this, SLOT(switchToPlainText()));
00494     } else {
00495         actionCollection->removeAction(d->action_to_plain_text);
00496         d->action_to_plain_text = 0;
00497     }
00498 
00499     if (d->richTextSupport & SupportSuperScriptAndSubScript) {
00500         d->action_text_subscript = new KToggleAction(KIcon("format-text-subscript"), i18nc("@action", "Subscript"), actionCollection);
00501         d->richTextActionList.append((d->action_text_subscript));
00502         actionCollection->addAction("format_text_subscript", d->action_text_subscript);
00503 
00504         connect(d->action_text_subscript, SIGNAL(triggered(bool)),
00505                 this, SLOT(setTextSubScript(bool)));
00506 
00507         d->action_text_superscript = new KToggleAction(KIcon("format-text-superscript"), i18nc("@action", "Superscript"), actionCollection);
00508         d->richTextActionList.append((d->action_text_superscript));
00509         actionCollection->addAction("format_text_superscript", d->action_text_superscript);
00510 
00511         connect(d->action_text_superscript, SIGNAL(triggered(bool)),
00512                 this, SLOT(setTextSuperScript(bool)));
00513     } else {
00514         actionCollection->removeAction(d->action_text_subscript);
00515         d->action_text_subscript = 0;
00516 
00517         actionCollection->removeAction(d->action_text_superscript);
00518         d->action_text_superscript = 0;
00519     }
00520     
00521 
00522     disconnect(this, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)),
00523                this, SLOT(_k_updateCharFormatActions(const QTextCharFormat &)));
00524     disconnect(this, SIGNAL(cursorPositionChanged()),
00525                this, SLOT(_k_updateMiscActions()));
00526     connect(this, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)),
00527             this, SLOT(_k_updateCharFormatActions(const QTextCharFormat &)));
00528     connect(this, SIGNAL(cursorPositionChanged()),
00529             this, SLOT(_k_updateMiscActions()));
00530 
00531     d->_k_updateMiscActions();
00532     d->_k_updateCharFormatActions(currentCharFormat());
00533 }
00534 
00535 
00536 void KRichTextWidget::setActionsEnabled(bool enabled)
00537 {
00538     foreach(QAction* action, d->richTextActionList)
00539     {
00540         action->setEnabled(enabled);
00541     }
00542     d->richTextEnabled = enabled;
00543 }
00544 
00545 void KRichTextWidget::Private::_k_setListStyle(int index)
00546 {
00547     q->setListStyle(index);
00548     _k_updateMiscActions();
00549 }
00550 
00551 void KRichTextWidget::Private::_k_updateCharFormatActions(const QTextCharFormat &format)
00552 {
00553     QFont f = format.font();
00554 
00555     if (richTextSupport & SupportFontFamily) {
00556         action_font_family->setFont(f.family());
00557     }
00558     if (richTextSupport & SupportFontSize) {
00559         if (f.pointSize() > 0)
00560             action_font_size->setFontSize((int)f.pointSize());
00561     }
00562 
00563     if (richTextSupport & SupportBold) {
00564         action_text_bold->setChecked(f.bold());
00565     }
00566 
00567     if (richTextSupport & SupportItalic) {
00568         action_text_italic->setChecked(f.italic());
00569     }
00570 
00571     if (richTextSupport & SupportUnderline) {
00572         action_text_underline->setChecked(f.underline());
00573     }
00574 
00575     if (richTextSupport & SupportStrikeOut) {
00576         action_text_strikeout->setChecked(f.strikeOut());
00577     }
00578 
00579     if (richTextSupport & SupportSuperScriptAndSubScript) {
00580         QTextCharFormat::VerticalAlignment vAlign = format.verticalAlignment();
00581         action_text_superscript->setChecked(vAlign == QTextCharFormat::AlignSuperScript);
00582         action_text_subscript->setChecked(vAlign == QTextCharFormat::AlignSubScript);
00583     }
00584 }
00585 
00586 void KRichTextWidget::Private::_k_updateMiscActions()
00587 {
00588     if (richTextSupport & SupportAlignment) {
00589         Qt::Alignment a = q->alignment();
00590         if (a & Qt::AlignLeft) {
00591             action_align_left->setChecked(true);
00592         } else if (a & Qt::AlignHCenter) {
00593             action_align_center->setChecked(true);
00594         } else if (a & Qt::AlignRight) {
00595             action_align_right->setChecked(true);
00596         } else if (a & Qt::AlignJustify) {
00597             action_align_justify->setChecked(true);
00598         }
00599     }
00600 
00601 
00602     if (richTextSupport & SupportChangeListStyle) {
00603         if (q->textCursor().currentList()) {
00604             action_list_style->setCurrentItem(-q->textCursor().currentList()->format().style());
00605         } else {
00606             action_list_style->setCurrentItem(0);
00607         }
00608     }
00609 
00610 
00611     if ( richTextSupport & SupportIndentLists ) {
00612         if ( richTextEnabled ) {
00613             action_list_indent->setEnabled( q->canIndentList() );
00614         } else {
00615             action_list_indent->setEnabled( false );
00616         }
00617     }
00618 
00619     if ( richTextSupport & SupportDedentLists ) {
00620         if ( richTextEnabled ) {
00621             action_list_dedent->setEnabled( q->canDedentList() );   
00622         } else {
00623             action_list_dedent->setEnabled( false );
00624         }
00625     }
00626 
00627     if (richTextSupport & SupportDirection) {
00628         const Qt::LayoutDirection direction = q->textCursor().blockFormat().layoutDirection();
00629         action_direction_ltr->setChecked(direction == Qt::LeftToRight);
00630         action_direction_rtl->setChecked(direction == Qt::RightToLeft);
00631     }
00632 }
00633 
00634 void KRichTextWidget::Private::_k_setTextForegroundColor()
00635 {
00636     QColor currentTextForegroundColor = q->textColor();
00637 
00638     int result = KColorDialog::getColor(currentTextForegroundColor, KColorScheme(QPalette::Active, KColorScheme::View).foreground().color() , q);
00639     if (!currentTextForegroundColor.isValid())
00640         currentTextForegroundColor = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color() ;
00641     if (result != QDialog::Accepted)
00642         return;
00643 
00644     q->setTextForegroundColor(currentTextForegroundColor);
00645 
00646 }
00647 
00648 void KRichTextWidget::Private::_k_setTextBackgroundColor()
00649 {
00650     QTextCharFormat fmt = q->textCursor().charFormat();
00651     QColor currentTextBackgroundColor = fmt.background().color();
00652 
00653     int result = KColorDialog::getColor(currentTextBackgroundColor, KColorScheme(QPalette::Active, KColorScheme::View).foreground().color() , q);
00654     if (!currentTextBackgroundColor.isValid())
00655         currentTextBackgroundColor = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color() ;
00656     if (result != QDialog::Accepted)
00657         return;
00658 
00659     q->setTextBackgroundColor(currentTextBackgroundColor);
00660 
00661 }
00662 
00663 void KRichTextWidget::Private::_k_manageLink()
00664 {
00665     q->selectLinkText();
00666     KLinkDialog *linkDialog = new KLinkDialog(q);
00667     linkDialog->setLinkText(q->currentLinkText());
00668     linkDialog->setLinkUrl(q->currentLinkUrl());
00669 
00670     if (linkDialog->exec()) {
00671         q->updateLink(linkDialog->linkUrl(), linkDialog->linkText());
00672     }
00673 
00674     delete linkDialog;
00675 
00676 }
00677 
00678 void KRichTextWidget::mouseReleaseEvent(QMouseEvent *event)
00679 {
00680     if (d->painterActive) {
00681         // If the painter is active, paint the selection with the
00682         // correct format.
00683         if (textCursor().hasSelection()) {
00684             textCursor().setCharFormat(d->painterFormat);
00685         }
00686         d->painterActive = false;
00687         d->action_format_painter->setChecked(false);
00688     }
00689     KRichTextEdit::mouseReleaseEvent(event);
00690 }
00691 
00692 void KRichTextWidget::Private::_k_formatPainter(bool active)
00693 {
00694     if (active) {
00695         painterFormat = q->currentCharFormat();
00696         painterActive = true;
00697         q->viewport()->setCursor(QCursor(KIcon("draw-brush").pixmap(32, 32), 0, 32));
00698     } else {
00699         painterFormat = QTextCharFormat();
00700         painterActive = false;
00701         q->viewport()->setCursor(Qt::IBeamCursor);
00702     }
00703 }
00704 
00705 void KRichTextWidget::updateActionStates()
00706 {
00707     d->_k_updateMiscActions();
00708     d->_k_updateCharFormatActions(currentCharFormat());
00709 }
00710 
00711 // kate: space-indent on; indent-width 4; encoding utf-8; replace-tabs on;
00712 #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
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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