mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kdeui: drop KRichTextEdit and KRichTextWidget
because KTextEdit inherits QTextEdit it is rich text-capable and the actions that KRichTextEdit and KRichTextWidget provide are not used anywhere (the actions require explicit setup) Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
c61c158983
commit
3d311955ab
14 changed files with 10 additions and 2353 deletions
|
@ -212,8 +212,6 @@ install(
|
|||
KReplace
|
||||
KReplaceDialog
|
||||
KRestrictedLine
|
||||
KRichTextEdit
|
||||
KRichTextWidget
|
||||
KRuler
|
||||
KRun
|
||||
KSaveFile
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
#include "../krichtextedit.h"
|
|
@ -1 +0,0 @@
|
|||
#include "../krichtextwidget.h"
|
|
@ -209,8 +209,6 @@ set(kdeui_LIB_SRCS
|
|||
widgets/kratingpainter.cpp
|
||||
widgets/kratingwidget.cpp
|
||||
widgets/krestrictedline.cpp
|
||||
widgets/krichtextedit.cpp
|
||||
widgets/krichtextwidget.cpp
|
||||
widgets/kruler.cpp
|
||||
widgets/kselector.cpp
|
||||
widgets/kseparator.cpp
|
||||
|
@ -483,8 +481,6 @@ install(
|
|||
widgets/kratingpainter.h
|
||||
widgets/kratingwidget.h
|
||||
widgets/krestrictedline.h
|
||||
widgets/krichtextedit.h
|
||||
widgets/krichtextwidget.h
|
||||
widgets/kseparator.h
|
||||
widgets/ksqueezedtextlabel.h
|
||||
widgets/ktextedit.h
|
||||
|
|
|
@ -51,7 +51,6 @@ KDEUI_UNIT_TESTS(
|
|||
kiconloader_unittest
|
||||
ktabwidget_unittest
|
||||
ktoolbar_unittest
|
||||
krichtextedittest
|
||||
kselectaction_unittest
|
||||
klistwidgetsearchlinetest
|
||||
kconfigdialog_unittest
|
||||
|
|
|
@ -1,254 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (c) 2009 Thomas McGuire <mcguire@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License or ( at
|
||||
your option ) version 3 or, at the discretion of KDE e.V. ( which shall
|
||||
act as a proxy as in section 14 of the GPLv3 ), any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "krichtextedittest.h"
|
||||
|
||||
#include <krichtextedit.h>
|
||||
#include <kcolorscheme.h>
|
||||
|
||||
#include <QtTest/QtTestGui>
|
||||
#include <qtestevent.h>
|
||||
#include <qtest_kde.h>
|
||||
#include <qtextcursor.h>
|
||||
#include <QTextList>
|
||||
#include <qfont.h>
|
||||
|
||||
#include <kdebug.h>
|
||||
|
||||
QTEST_KDEMAIN(KRichTextEditTest, GUI)
|
||||
|
||||
void KRichTextEditTest::testLinebreaks()
|
||||
{
|
||||
KRichTextEdit edit;
|
||||
edit.enableRichTextMode();
|
||||
|
||||
// Enter the text with keypresses, for some strange reason a normal setText() or
|
||||
// setPlainText() call doesn't do the trick
|
||||
QTest::keyClicks(&edit, "a\r\r");
|
||||
edit.setTextUnderline( true );
|
||||
QTest::keyClicks(&edit, "b\r\r\rc" );
|
||||
QCOMPARE( edit.toPlainText(), QString( "a\n\nb\n\n\nc" ) );
|
||||
|
||||
QString html = edit.toCleanHtml();
|
||||
edit.clear();
|
||||
edit.setHtml( html );
|
||||
QCOMPARE( edit.toPlainText(), QString( "a\n\nb\n\n\nc" ) );
|
||||
}
|
||||
|
||||
void KRichTextEditTest::testUpdateLinkAdd()
|
||||
{
|
||||
KRichTextEdit edit;
|
||||
edit.enableRichTextMode();
|
||||
|
||||
// Add text, apply initial formatting, and add a link
|
||||
QTextCursor cursor = edit.textCursor();
|
||||
cursor.insertText(QString("Test"));
|
||||
QTextCharFormat charFormat = cursor.charFormat();
|
||||
// Note that QTextEdit doesn't use the palette. Black is black.
|
||||
QCOMPARE(charFormat.foreground().color().name(), QColor(Qt::black).name());
|
||||
|
||||
cursor.select(QTextCursor::BlockUnderCursor);
|
||||
edit.setTextCursor(cursor);
|
||||
edit.setTextBold(true);
|
||||
edit.setTextItalic(true);
|
||||
edit.updateLink(QString("http://www.kde.org"), QString("KDE"));
|
||||
|
||||
// Validate text and formatting
|
||||
cursor.movePosition(QTextCursor::Start);
|
||||
cursor.select(QTextCursor::WordUnderCursor);
|
||||
edit.setTextCursor(cursor);
|
||||
QCOMPARE(edit.toPlainText(), QString("KDE "));
|
||||
QCOMPARE(edit.fontItalic(), true);
|
||||
QCOMPARE(edit.fontWeight(), static_cast<int>(QFont::Bold));
|
||||
QCOMPARE(edit.fontUnderline(), true);
|
||||
charFormat = cursor.charFormat();
|
||||
QCOMPARE(charFormat.foreground(), QBrush(KColorScheme(QPalette::Active, KColorScheme::View).foreground(KColorScheme::LinkText).color()));
|
||||
QCOMPARE(charFormat.underlineColor(), KColorScheme(QPalette::Active, KColorScheme::View).foreground(KColorScheme::LinkText).color());
|
||||
QCOMPARE(charFormat.underlineStyle(), QTextCharFormat::SingleUnderline);
|
||||
}
|
||||
|
||||
void KRichTextEditTest::testUpdateLinkRemove()
|
||||
{
|
||||
KRichTextEdit edit;
|
||||
edit.enableRichTextMode();
|
||||
|
||||
// Add text, apply initial formatting, and add a link
|
||||
QTextCursor cursor = edit.textCursor();
|
||||
cursor.insertText(QString("Test"));
|
||||
cursor.select(QTextCursor::BlockUnderCursor);
|
||||
edit.setTextCursor(cursor);
|
||||
edit.setTextBold(true);
|
||||
edit.setTextItalic(true);
|
||||
edit.updateLink(QString("http://www.kde.org"), QString("KDE"));
|
||||
|
||||
// Remove link and validate formatting
|
||||
cursor.movePosition(QTextCursor::Start);
|
||||
cursor.select(QTextCursor::WordUnderCursor);
|
||||
edit.setTextCursor(cursor);
|
||||
edit.updateLink(QString(), QString("KDE"));
|
||||
cursor.movePosition(QTextCursor::Start);
|
||||
cursor.select(QTextCursor::WordUnderCursor);
|
||||
edit.setTextCursor(cursor);
|
||||
QCOMPARE(edit.toPlainText(), QString("KDE "));
|
||||
QCOMPARE(edit.fontItalic(), true);
|
||||
QCOMPARE(edit.fontWeight(), static_cast<int>(QFont::Bold));
|
||||
QCOMPARE(edit.fontUnderline(), false);
|
||||
QTextCharFormat charFormat = cursor.charFormat();
|
||||
QCOMPARE(charFormat.foreground().color().name(), QColor(Qt::black).name());
|
||||
QCOMPARE(charFormat.underlineColor().name(), QColor(Qt::black).name());
|
||||
QCOMPARE(charFormat.underlineStyle(), QTextCharFormat::NoUnderline);
|
||||
}
|
||||
|
||||
|
||||
void KRichTextEditTest::testHTMLLineBreaks()
|
||||
{
|
||||
KRichTextEdit edit;
|
||||
edit.enableRichTextMode();
|
||||
|
||||
// Create the following text:
|
||||
//A
|
||||
//
|
||||
//B
|
||||
QTest::keyClicks(&edit, "a\r");
|
||||
|
||||
edit.setTextUnderline( true );
|
||||
|
||||
QTest::keyClicks(&edit, "\rb");
|
||||
|
||||
QString html = edit.toCleanHtml();
|
||||
|
||||
// The problem we have is that we need to "fake" being a viewer such
|
||||
// as Thunderbird or MS-Outlook to unit test our html line breaks.
|
||||
// For now, we'll parse the 6th line (the empty one) and make sure it has the proper format
|
||||
// The first four (4) HTML code lines are DOCTYPE through <body> declaration
|
||||
|
||||
const QStringList lines = html.split('\n');
|
||||
|
||||
// for (int idx=0; idx<lines.size(); idx++) {
|
||||
// kDebug() << ( idx + 1 ) << QString( " : " ) << lines.at( idx );
|
||||
// }
|
||||
|
||||
QVERIFY2( lines.size() == 7, "we can't perform this unit test: "
|
||||
"the html rendering has changed beyond recognition");
|
||||
|
||||
const QString& line6 = lines.at(5);
|
||||
|
||||
// make sure that this is an empty <p> line
|
||||
QVERIFY( line6.startsWith( QString( "<p style=\"-qt-paragraph-type:empty;" ) ) );
|
||||
|
||||
// make sure that empty lines have the inserted
|
||||
QVERIFY2( line6.endsWith( QString( "> </p>" ) ), "Empty lines must have or otherwise 3rd party "
|
||||
"viewers render those as non-existing lines" );
|
||||
|
||||
}
|
||||
|
||||
void KRichTextEditTest::testHTMLOrderedLists()
|
||||
{
|
||||
|
||||
// The problem we have is that we need to "fake" being a viewer such
|
||||
// as Thunderbird or MS-Outlook to unit test our html lists.
|
||||
// For now, we'll parse the 6th line (the <ol> element) and make sure it has the proper format
|
||||
|
||||
KRichTextEdit edit;
|
||||
edit.enableRichTextMode();
|
||||
|
||||
edit.setTextUnderline( true );
|
||||
|
||||
// create a numbered (ordered) list
|
||||
QTextCursor cursor = edit.textCursor();
|
||||
cursor.insertList( QTextListFormat::ListDecimal );
|
||||
|
||||
QTest::keyClicks(&edit, "a\rb\rc\r");
|
||||
|
||||
QString html = edit.toCleanHtml();
|
||||
|
||||
const QStringList lines = html.split('\n');
|
||||
|
||||
// Uncomment this section in case the first test fails to see if the HTML
|
||||
// rendering has actually introduced a bug, or merely a problem with the unit test itself
|
||||
//
|
||||
// for (int idx=0; idx<lines.size(); idx++) {
|
||||
// kDebug() << ( idx + 1 ) << QString( " : " ) << lines.at( idx );
|
||||
// }
|
||||
|
||||
QVERIFY2( lines.size() == 9, "we can't perform this unit test: "
|
||||
"the html rendering has changed beyond recognition");
|
||||
|
||||
// this is the <ol> declaration line
|
||||
const QString& line6 = lines.at(5);
|
||||
|
||||
// kDebug() << line6;
|
||||
|
||||
// there should not be a margin-left: 0 defined for the <ol> element
|
||||
QRegExp regex( QString ( "<ol.*margin-left: 0px.*><li" ) );
|
||||
regex.setMinimal( true );
|
||||
|
||||
QVERIFY2 ( regex.indexIn( line6, 0 ) == -1, "margin-left: 0px specified for ordered lists "
|
||||
"removes numbers in 3rd party viewers " );
|
||||
|
||||
}
|
||||
|
||||
void KRichTextEditTest::testHTMLUnorderedLists()
|
||||
{
|
||||
// The problem we have is that we need to "fake" being a viewer such
|
||||
// as Thunderbird or MS-Outlook to unit test our html lists.
|
||||
// For now, we'll parse the 6th line (the <ul> element) and make sure it has the proper format
|
||||
// The first four (4) HTML code lines are DOCTYPE through <body> declaration
|
||||
|
||||
KRichTextEdit edit;
|
||||
edit.enableRichTextMode();
|
||||
|
||||
edit.setTextUnderline( true );
|
||||
|
||||
// create a numbered (ordered) list
|
||||
QTextCursor cursor = edit.textCursor();
|
||||
cursor.insertList( QTextListFormat::ListDisc );
|
||||
|
||||
QTest::keyClicks(&edit, "a\rb\rc\r");
|
||||
|
||||
QString html = edit.toCleanHtml();
|
||||
|
||||
const QStringList lines = html.split('\n');
|
||||
|
||||
// Uncomment this section in case the first test fails to see if the HTML
|
||||
// rendering has actually introduced a bug, or merely a problem with the unit test itself
|
||||
//
|
||||
// for (int idx=0; idx<lines.size(); idx++) {
|
||||
// kDebug() << ( idx + 1 ) << QString( " : " ) << lines.at( idx );
|
||||
// }
|
||||
|
||||
QVERIFY2( lines.size() == 9, "we can't perform this unit test: "
|
||||
"the html rendering has changed beyond recognition");
|
||||
|
||||
// this is the <ol> declaration line
|
||||
const QString& line6 = lines.at(5);
|
||||
|
||||
// kDebug() << line6;
|
||||
|
||||
// there should not be a margin-left: 0 defined for the <ol> element
|
||||
QRegExp regex( QString ( "<ul.*margin-left: 0px.*><li" ) );
|
||||
regex.setMinimal( true );
|
||||
|
||||
QVERIFY2 ( regex.indexIn( line6, 0 ) == -1, "margin-left: 0px specified for unordered lists "
|
||||
"removes numbers in 3rd party viewers " );
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (c) 2009 Thomas McGuire <mcguire@kde.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License or ( at
|
||||
your option ) version 3 or, at the discretion of KDE e.V. ( which shall
|
||||
act as a proxy as in section 14 of the GPLv3 ), any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#ifndef KRICHTEXTEDITTEST_H
|
||||
#define KRICHTEXTEDITTEST_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
class KRichTextEditTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
void testLinebreaks();
|
||||
void testUpdateLinkAdd();
|
||||
void testUpdateLinkRemove();
|
||||
void testHTMLLineBreaks();
|
||||
void testHTMLOrderedLists();
|
||||
void testHTMLUnorderedLists();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,577 +0,0 @@
|
|||
/*
|
||||
* krichtextedit
|
||||
*
|
||||
* Copyright 2007 Laurent Montel <montel@kde.org>
|
||||
* Copyright 2008 Thomas McGuire <thomas.mcguire@gmx.net>
|
||||
* Copyright 2008 Stephen Kelly <steveire@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "krichtextedit.h"
|
||||
|
||||
// Own includes
|
||||
#include "nestedlisthelper.h"
|
||||
#include "klinkdialog.h"
|
||||
|
||||
// kdelibs includes
|
||||
#include <kcursor.h>
|
||||
#include <kcolorscheme.h>
|
||||
|
||||
// Qt includes
|
||||
#include <QtGui/QTextDocumentFragment>
|
||||
#include <QtGui/qevent.h>
|
||||
|
||||
/**
|
||||
Private class that helps to provide binary compatibility between releases.
|
||||
@internal
|
||||
*/
|
||||
//@cond PRIVATE
|
||||
class KRichTextEditPrivate : public QObject
|
||||
{
|
||||
public:
|
||||
KRichTextEditPrivate(KRichTextEdit *parent)
|
||||
: q(parent),
|
||||
mMode(KRichTextEdit::Plain) {
|
||||
nestedListHelper = new NestedListHelper(q);
|
||||
}
|
||||
|
||||
~KRichTextEditPrivate() {
|
||||
delete nestedListHelper;
|
||||
}
|
||||
|
||||
//
|
||||
// Normal functions
|
||||
//
|
||||
|
||||
// If the text under the cursor is a link, the cursor's selection is set to
|
||||
// the complete link text. Otherwise selects the current word if there is no
|
||||
// selection.
|
||||
void selectLinkText() const;
|
||||
|
||||
void init();
|
||||
|
||||
// Switches to rich text mode and emits the mode changed signal if the
|
||||
// mode really changed.
|
||||
void activateRichText();
|
||||
|
||||
// Applies formatting to the current word if there is no selection.
|
||||
void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
|
||||
|
||||
void setTextCursor(QTextCursor &cursor);
|
||||
|
||||
|
||||
// Data members
|
||||
|
||||
KRichTextEdit *q;
|
||||
KRichTextEdit::Mode mMode;
|
||||
|
||||
NestedListHelper *nestedListHelper;
|
||||
|
||||
};
|
||||
|
||||
void KRichTextEditPrivate::activateRichText()
|
||||
{
|
||||
if (mMode == KRichTextEdit::Plain) {
|
||||
q->setAcceptRichText(true);
|
||||
mMode = KRichTextEdit::Rich;
|
||||
emit q->textModeChanged(mMode);
|
||||
}
|
||||
}
|
||||
|
||||
void KRichTextEditPrivate::setTextCursor(QTextCursor &cursor)
|
||||
{
|
||||
q->setTextCursor(cursor);
|
||||
}
|
||||
|
||||
void KRichTextEditPrivate::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
|
||||
{
|
||||
QTextCursor cursor = q->textCursor();
|
||||
QTextCursor wordStart(cursor);
|
||||
QTextCursor wordEnd(cursor);
|
||||
|
||||
wordStart.movePosition(QTextCursor::StartOfWord);
|
||||
wordEnd.movePosition(QTextCursor::EndOfWord);
|
||||
|
||||
cursor.beginEditBlock();
|
||||
if (!cursor.hasSelection() && cursor.position() != wordStart.position() && cursor.position() != wordEnd.position())
|
||||
cursor.select(QTextCursor::WordUnderCursor);
|
||||
cursor.mergeCharFormat(format);
|
||||
q->mergeCurrentCharFormat(format);
|
||||
cursor.endEditBlock();
|
||||
}
|
||||
//@endcond
|
||||
|
||||
KRichTextEdit::KRichTextEdit(const QString& text, QWidget *parent)
|
||||
: KTextEdit(text, parent), d(new KRichTextEditPrivate(this))
|
||||
{
|
||||
d->init();
|
||||
}
|
||||
|
||||
KRichTextEdit::KRichTextEdit(QWidget *parent)
|
||||
: KTextEdit(parent), d(new KRichTextEditPrivate(this))
|
||||
{
|
||||
d->init();
|
||||
}
|
||||
|
||||
KRichTextEdit::~KRichTextEdit()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
//@cond PRIVATE
|
||||
void KRichTextEditPrivate::init()
|
||||
{
|
||||
q->setAcceptRichText(false);
|
||||
KCursor::setAutoHideCursor(q, true, true);
|
||||
}
|
||||
//@endcond
|
||||
|
||||
void KRichTextEdit::setListStyle(int _styleIndex)
|
||||
{
|
||||
d->nestedListHelper->handleOnBulletType(-_styleIndex);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::indentListMore()
|
||||
{
|
||||
d->nestedListHelper->handleOnIndentMore();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::indentListLess()
|
||||
{
|
||||
d->nestedListHelper->handleOnIndentLess();
|
||||
}
|
||||
|
||||
void KRichTextEdit::insertHorizontalRule()
|
||||
{
|
||||
QTextCursor cursor = textCursor();
|
||||
QTextBlockFormat bf = cursor.blockFormat();
|
||||
QTextCharFormat cf = cursor.charFormat();
|
||||
|
||||
cursor.beginEditBlock();
|
||||
cursor.insertHtml("<hr>");
|
||||
cursor.insertBlock(bf, cf);
|
||||
setTextCursor(cursor);
|
||||
d->activateRichText();
|
||||
cursor.endEditBlock();
|
||||
}
|
||||
|
||||
void KRichTextEdit::alignLeft()
|
||||
{
|
||||
setAlignment(Qt::AlignLeft);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::alignCenter()
|
||||
{
|
||||
setAlignment(Qt::AlignHCenter);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::alignRight()
|
||||
{
|
||||
setAlignment(Qt::AlignRight);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::alignJustify()
|
||||
{
|
||||
setAlignment(Qt::AlignJustify);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::makeRightToLeft()
|
||||
{
|
||||
QTextBlockFormat format;
|
||||
format.setLayoutDirection(Qt::RightToLeft);
|
||||
QTextCursor cursor = textCursor();
|
||||
cursor.mergeBlockFormat(format);
|
||||
setTextCursor(cursor);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::makeLeftToRight()
|
||||
{
|
||||
QTextBlockFormat format;
|
||||
format.setLayoutDirection(Qt::LeftToRight);
|
||||
QTextCursor cursor = textCursor();
|
||||
cursor.mergeBlockFormat(format);
|
||||
setTextCursor(cursor);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::setTextBold(bool bold)
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setFontWeight(bold ? QFont::Bold : QFont::Normal);
|
||||
d->mergeFormatOnWordOrSelection(fmt);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::setTextItalic(bool italic)
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setFontItalic(italic);
|
||||
d->mergeFormatOnWordOrSelection(fmt);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::setTextUnderline(bool underline)
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setFontUnderline(underline);
|
||||
d->mergeFormatOnWordOrSelection(fmt);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::setTextStrikeOut(bool strikeOut)
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setFontStrikeOut(strikeOut);
|
||||
d->mergeFormatOnWordOrSelection(fmt);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::setTextForegroundColor(const QColor &color)
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setForeground(color);
|
||||
d->mergeFormatOnWordOrSelection(fmt);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::setTextBackgroundColor(const QColor &color)
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setBackground(color);
|
||||
d->mergeFormatOnWordOrSelection(fmt);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::setFontFamily(const QString &fontFamily)
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setFontFamily(fontFamily);
|
||||
d->mergeFormatOnWordOrSelection(fmt);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::setFontSize(int size)
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setFontPointSize(size);
|
||||
d->mergeFormatOnWordOrSelection(fmt);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::setFont(const QFont &font)
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setFont(font);
|
||||
d->mergeFormatOnWordOrSelection(fmt);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::switchToPlainText()
|
||||
{
|
||||
if (d->mMode == Rich) {
|
||||
d->mMode = Plain;
|
||||
document()->setPlainText(document()->toPlainText());
|
||||
setAcceptRichText(false);
|
||||
emit textModeChanged(d->mMode);
|
||||
}
|
||||
}
|
||||
|
||||
void KRichTextEdit::setTextSuperScript(bool superscript)
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setVerticalAlignment(superscript ? QTextCharFormat::AlignSuperScript : QTextCharFormat::AlignNormal);
|
||||
d->mergeFormatOnWordOrSelection(fmt);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::setTextSubScript(bool subscript)
|
||||
{
|
||||
QTextCharFormat fmt;
|
||||
fmt.setVerticalAlignment(subscript ? QTextCharFormat::AlignSubScript : QTextCharFormat::AlignNormal);
|
||||
d->mergeFormatOnWordOrSelection(fmt);
|
||||
setFocus();
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::enableRichTextMode()
|
||||
{
|
||||
d->activateRichText();
|
||||
}
|
||||
|
||||
KRichTextEdit::Mode KRichTextEdit::textMode() const
|
||||
{
|
||||
return d->mMode;
|
||||
}
|
||||
|
||||
QString KRichTextEdit::textOrHtml() const
|
||||
{
|
||||
if (textMode() == Rich)
|
||||
return toCleanHtml();
|
||||
else
|
||||
return toPlainText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::setTextOrHtml(const QString &text)
|
||||
{
|
||||
// might be rich text
|
||||
if (Qt::mightBeRichText(text)) {
|
||||
if (d->mMode == KRichTextEdit::Plain) {
|
||||
d->activateRichText();
|
||||
}
|
||||
setHtml(text);
|
||||
} else {
|
||||
setPlainText(text);
|
||||
}
|
||||
}
|
||||
|
||||
QString KRichTextEdit::currentLinkText() const
|
||||
{
|
||||
QTextCursor cursor = textCursor();
|
||||
selectLinkText(&cursor);
|
||||
return cursor.selectedText();
|
||||
}
|
||||
|
||||
void KRichTextEdit::selectLinkText() const
|
||||
{
|
||||
QTextCursor cursor = textCursor();
|
||||
selectLinkText(&cursor);
|
||||
d->setTextCursor(cursor);
|
||||
}
|
||||
|
||||
void KRichTextEdit::selectLinkText(QTextCursor *cursor) const
|
||||
{
|
||||
// If the cursor is on a link, select the text of the link.
|
||||
if (cursor->charFormat().isAnchor()) {
|
||||
QString aHref = cursor->charFormat().anchorHref();
|
||||
|
||||
// Move cursor to start of link
|
||||
while (cursor->charFormat().anchorHref() == aHref) {
|
||||
if (cursor->atStart())
|
||||
break;
|
||||
cursor->setPosition(cursor->position() - 1);
|
||||
}
|
||||
if (cursor->charFormat().anchorHref() != aHref)
|
||||
cursor->setPosition(cursor->position() + 1, QTextCursor::KeepAnchor);
|
||||
|
||||
// Move selection to the end of the link
|
||||
while (cursor->charFormat().anchorHref() == aHref) {
|
||||
if (cursor->atEnd())
|
||||
break;
|
||||
cursor->setPosition(cursor->position() + 1, QTextCursor::KeepAnchor);
|
||||
}
|
||||
if (cursor->charFormat().anchorHref() != aHref)
|
||||
cursor->setPosition(cursor->position() - 1, QTextCursor::KeepAnchor);
|
||||
} else if (cursor->hasSelection()) {
|
||||
// Nothing to to. Using the currently selected text as the link text.
|
||||
} else {
|
||||
|
||||
// Select current word
|
||||
cursor->movePosition(QTextCursor::StartOfWord);
|
||||
cursor->movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
||||
}
|
||||
}
|
||||
|
||||
QString KRichTextEdit::currentLinkUrl() const
|
||||
{
|
||||
return textCursor().charFormat().anchorHref();
|
||||
}
|
||||
|
||||
void KRichTextEdit::updateLink(const QString &linkUrl, const QString &linkText)
|
||||
{
|
||||
selectLinkText();
|
||||
|
||||
QTextCursor cursor = textCursor();
|
||||
cursor.beginEditBlock();
|
||||
|
||||
if (!cursor.hasSelection()) {
|
||||
cursor.select(QTextCursor::WordUnderCursor);
|
||||
}
|
||||
|
||||
QTextCharFormat format = cursor.charFormat();
|
||||
// Save original format to create an extra space with the existing char
|
||||
// format for the block
|
||||
const QTextCharFormat originalFormat = format;
|
||||
if (!linkUrl.isEmpty()) {
|
||||
// Add link details
|
||||
format.setAnchor(true);
|
||||
format.setAnchorHref(linkUrl);
|
||||
// Workaround for QTBUG-1814:
|
||||
// Link formatting does not get applied immediately when setAnchor(true)
|
||||
// is called. So the formatting needs to be applied manually.
|
||||
format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
|
||||
format.setUnderlineColor(KColorScheme(QPalette::Active, KColorScheme::View).foreground(KColorScheme::LinkText).color());
|
||||
format.setForeground(KColorScheme(QPalette::Active, KColorScheme::View).foreground(KColorScheme::LinkText).color());
|
||||
d->activateRichText();
|
||||
} else {
|
||||
// Remove link details
|
||||
format.setAnchor(false);
|
||||
format.setAnchorHref(QString());
|
||||
// Workaround for QTBUG-1814:
|
||||
// Link formatting does not get removed immediately when setAnchor(false)
|
||||
// is called. So the formatting needs to be applied manually.
|
||||
QTextDocument defaultTextDocument;
|
||||
QTextCharFormat defaultCharFormat = defaultTextDocument.begin().charFormat();
|
||||
|
||||
format.setUnderlineStyle( defaultCharFormat.underlineStyle() );
|
||||
format.setUnderlineColor( defaultCharFormat.underlineColor() );
|
||||
format.setForeground( defaultCharFormat.foreground() );
|
||||
}
|
||||
|
||||
// Insert link text specified in dialog, otherwise write out url.
|
||||
QString _linkText;
|
||||
if (!linkText.isEmpty()) {
|
||||
_linkText = linkText;
|
||||
} else {
|
||||
_linkText = linkUrl;
|
||||
}
|
||||
cursor.insertText(_linkText, format);
|
||||
|
||||
|
||||
// Insert a space after the link if at the end of the block so that
|
||||
// typing some text after the link does not carry link formatting
|
||||
if (!linkUrl.isEmpty() && cursor.atBlockEnd()) {
|
||||
cursor.setPosition(cursor.selectionEnd());
|
||||
cursor.setCharFormat(originalFormat);
|
||||
cursor.insertText(QString(" "));
|
||||
}
|
||||
|
||||
cursor.endEditBlock();
|
||||
}
|
||||
|
||||
void KRichTextEdit::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
bool handled = false;
|
||||
if (textCursor().currentList()) {
|
||||
// handled is False if the key press event was not handled or not completely
|
||||
// handled by the Helper class.
|
||||
handled = d->nestedListHelper->handleBeforeKeyPressEvent(event);
|
||||
}
|
||||
|
||||
if (!handled) {
|
||||
KTextEdit::keyPressEvent(event);
|
||||
}
|
||||
|
||||
if (textCursor().currentList()) {
|
||||
d->nestedListHelper->handleAfterKeyPressEvent(event);
|
||||
}
|
||||
emit cursorPositionChanged();
|
||||
}
|
||||
|
||||
// void KRichTextEdit::dropEvent(QDropEvent *event)
|
||||
// {
|
||||
// int dropSize = event->mimeData()->text().size();
|
||||
//
|
||||
// dropEvent( event );
|
||||
// QTextCursor cursor = textCursor();
|
||||
// int cursorPosition = cursor.position();
|
||||
// cursor.setPosition( cursorPosition - dropSize );
|
||||
// cursor.setPosition( cursorPosition, QTextCursor::KeepAnchor );
|
||||
// setTextCursor( cursor );
|
||||
// d->nestedListHelper->handleAfterDropEvent( event );
|
||||
// }
|
||||
|
||||
|
||||
bool KRichTextEdit::canIndentList() const
|
||||
{
|
||||
return d->nestedListHelper->canIndent();
|
||||
}
|
||||
|
||||
bool KRichTextEdit::canDedentList() const
|
||||
{
|
||||
return d->nestedListHelper->canDedent();
|
||||
}
|
||||
|
||||
QString KRichTextEdit::toCleanHtml() const
|
||||
{
|
||||
QString result = toHtml();
|
||||
|
||||
static const QString EMPTYLINEHTML = QLatin1String(
|
||||
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; "
|
||||
"margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \"> </p>" );
|
||||
|
||||
// Qt inserts various style properties based on the current mode of the editor (underline,
|
||||
// bold, etc), but only empty paragraphs *also* have qt-paragraph-type set to 'empty'.
|
||||
static const QString EMPTYLINEREGEX = QLatin1String(
|
||||
"<p style=\"-qt-paragraph-type:empty;(.*)</p>" );
|
||||
|
||||
static const QString OLLISTPATTERNQT = QLatin1String(
|
||||
"<ol style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px;" );
|
||||
|
||||
static const QString ULLISTPATTERNQT = QLatin1String(
|
||||
"<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px;" );
|
||||
|
||||
static const QString ORDEREDLISTHTML = QLatin1String(
|
||||
"<ol style=\"margin-top: 0px; margin-bottom: 0px;" );
|
||||
|
||||
static const QString UNORDEREDLISTHTML = QLatin1String(
|
||||
"<ul style=\"margin-top: 0px; margin-bottom: 0px;" );
|
||||
|
||||
// fix 1 - empty lines should show as empty lines - MS Outlook treats margin-top:0px; as
|
||||
// a non-existing line.
|
||||
// Although we can simply remove the margin-top style property, we still get unwanted results
|
||||
// if you have three or more empty lines. It's best to replace empty <p> elements with <p> </p>.
|
||||
|
||||
QRegExp emptyLineFinder( EMPTYLINEREGEX );
|
||||
emptyLineFinder.setMinimal( true );
|
||||
|
||||
// find the first occurance
|
||||
int offset = emptyLineFinder.indexIn( result, 0 );
|
||||
while (offset != -1) {
|
||||
// replace all the matching text with the new line text
|
||||
result.replace( offset, emptyLineFinder.matchedLength(), EMPTYLINEHTML );
|
||||
// advance the search offset to just beyond the last replace
|
||||
offset += EMPTYLINEHTML.length();
|
||||
// find the next occurance
|
||||
offset = emptyLineFinder.indexIn( result, offset );
|
||||
}
|
||||
|
||||
// fix 2a - ordered lists - MS Outlook treats margin-left:0px; as
|
||||
// a non-existing number; e.g: "1. First item" turns into "First Item"
|
||||
result.replace(OLLISTPATTERNQT, ORDEREDLISTHTML);
|
||||
|
||||
// fix 2b - unordered lists - MS Outlook treats margin-left:0px; as
|
||||
// a non-existing bullet; e.g: "* First bullet" turns into "First Bullet"
|
||||
result.replace(ULLISTPATTERNQT, UNORDEREDLISTHTML);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#include "moc_krichtextedit.cpp"
|
|
@ -1,376 +0,0 @@
|
|||
/**
|
||||
* krichtextedit.h
|
||||
*
|
||||
* Copyright 2007 Laurent Montel <montel@kde.org>
|
||||
* Copyright 2008 Thomas McGuire <thomas.mcguire@gmx.net>
|
||||
* Copyright 2008 Stephen Kelly <steveire@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef KRICHTEXTEDIT_H
|
||||
#define KRICHTEXTEDIT_H
|
||||
|
||||
#include <ktextedit.h>
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QKeyEvent>
|
||||
|
||||
class KRichTextEditPrivate;
|
||||
|
||||
#include <kdeui_export.h>
|
||||
|
||||
/**
|
||||
* The KRichTextEdit class provides a widget to edit and display rich text.
|
||||
*
|
||||
* It offers several additional rich text editing functions to KTextEdit and makes
|
||||
* them easier to access including:
|
||||
*
|
||||
* @li Changing fonts, sizes.
|
||||
* @li Font formatting, such as bold, underline, italic, foreground and
|
||||
* background color.
|
||||
* @li Paragraph alignment
|
||||
* @li Ability to edit and remove hyperlinks
|
||||
* @li Nested list handling
|
||||
* @li Simple actions to insert tables. TODO
|
||||
*
|
||||
* The KRichTextEdit can be in two modes: Rich text mode and plain text mode.
|
||||
* Calling functions which modify the format/style of the text will automatically
|
||||
* enable the rich text mode. Rich text mode is sometimes also referred to as
|
||||
* HTML mode.
|
||||
*
|
||||
* Do not call setAcceptRichText() or acceptRichText() yourself. Instead simply
|
||||
* connect to the slots which insert the rich text, use switchToPlainText() or
|
||||
* enableRichTextMode().
|
||||
*
|
||||
* \image html krichtextedit.png "KDE Rich Text Edit Widget"
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
class KDEUI_EXPORT KRichTextEdit : public KTextEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* The mode the edit widget is in.
|
||||
*/
|
||||
enum Mode { Plain, ///< Plain text mode
|
||||
Rich ///< Rich text mode
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructs a KRichTextEdit object
|
||||
*
|
||||
* @param text The initial text of the text edit, which is interpreted as
|
||||
* HTML.
|
||||
* @param parent The parent widget
|
||||
*/
|
||||
explicit KRichTextEdit(const QString& text, QWidget *parent = 0);
|
||||
|
||||
/**
|
||||
* Constructs a KRichTextEdit object.
|
||||
*
|
||||
* @param parent The parent widget
|
||||
*/
|
||||
explicit KRichTextEdit(QWidget *parent = 0);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~KRichTextEdit();
|
||||
|
||||
/**
|
||||
* This enables rich text mode. Nothing is done except changing the internal
|
||||
* mode and allowing rich text pastes.
|
||||
*/
|
||||
void enableRichTextMode();
|
||||
|
||||
/**
|
||||
* @return The current text mode
|
||||
*/
|
||||
Mode textMode() const;
|
||||
|
||||
/**
|
||||
* @return The plain text string if in plain text mode or the HTML code
|
||||
* if in rich text mode. The text is not word-wrapped.
|
||||
*/
|
||||
QString textOrHtml() const;
|
||||
|
||||
/**
|
||||
* Replaces all the content of the text edit with the given string.
|
||||
* If the string is in rich text format, the text is inserted as rich text,
|
||||
* otherwise it is inserted as plain text.
|
||||
*
|
||||
* @param text The text to insert
|
||||
*/
|
||||
void setTextOrHtml(const QString &text);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the text of the link at the current position or an empty string
|
||||
* if the cursor is not on a link.
|
||||
*
|
||||
* @sa currentLinkUrl
|
||||
* @return The link text
|
||||
*/
|
||||
QString currentLinkText() const;
|
||||
|
||||
/**
|
||||
* Returns the URL target (href) of the link at the current position or an
|
||||
* empty string if the cursor is not on a link.
|
||||
*
|
||||
* @sa currentLinkText
|
||||
* @return The link target URL
|
||||
*/
|
||||
QString currentLinkUrl() const;
|
||||
|
||||
/**
|
||||
* If the cursor is on a link, sets the @a cursor to a selection of the
|
||||
* text of the link. If the @a cursor is not on a link, selects the current word
|
||||
* or existing selection.
|
||||
*
|
||||
* @param cursor The cursor to use to select the text.
|
||||
* @sa updateLink
|
||||
*/
|
||||
void selectLinkText(QTextCursor* cursor) const;
|
||||
|
||||
/**
|
||||
* Convenience function to select the link text using the active cursor.
|
||||
*
|
||||
* @sa selectLinkText
|
||||
*/
|
||||
void selectLinkText() const;
|
||||
|
||||
/**
|
||||
* Replaces the current selection with a hyperlink with the link URL @a linkUrl
|
||||
* and the link text @a linkText.
|
||||
*
|
||||
* @sa selectLinkText
|
||||
* @sa currentLinkUrl
|
||||
* @sa currentLinkText
|
||||
* @param linkUrl The link will get this URL as href (target)
|
||||
* @param linkText The link will get this alternative text, which is the
|
||||
* text displayed in the text edit.
|
||||
*/
|
||||
void updateLink(const QString &linkUrl, const QString &linkText);
|
||||
|
||||
/**
|
||||
* Returns true if the list item at the current position can be indented.
|
||||
*
|
||||
* @sa canDedentList
|
||||
*/
|
||||
bool canIndentList() const;
|
||||
|
||||
/**
|
||||
* Returns true if the list item at the current position can be dedented.
|
||||
*
|
||||
* @sa canIndentList
|
||||
*/
|
||||
bool canDedentList() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
|
||||
/**
|
||||
* Sets the alignment of the current block to Left Aligned
|
||||
*/
|
||||
void alignLeft();
|
||||
|
||||
/**
|
||||
* Sets the alignment of the current block to Centered
|
||||
*/
|
||||
void alignCenter();
|
||||
|
||||
/**
|
||||
* Sets the alignment of the current block to Right Aligned
|
||||
*/
|
||||
void alignRight();
|
||||
|
||||
/**
|
||||
* Sets the alignment of the current block to Justified
|
||||
*/
|
||||
void alignJustify();
|
||||
|
||||
/**
|
||||
* Sets the direction of the current block to Right-To-Left
|
||||
*
|
||||
* @since 4.6
|
||||
*/
|
||||
void makeRightToLeft();
|
||||
|
||||
/**
|
||||
* Sets the direction of the current block to Left-To-Right
|
||||
*
|
||||
* @since 4.6
|
||||
*/
|
||||
void makeLeftToRight();
|
||||
|
||||
/**
|
||||
* Sets the list style of the current list, or creates a new list using the
|
||||
* current block. The @a _styleindex corresponds to the QTextListFormat::Style
|
||||
*
|
||||
* @param _styleIndex The list will get this style
|
||||
*/
|
||||
void setListStyle(int _styleIndex);
|
||||
|
||||
/**
|
||||
* Increases the nesting level of the current block or selected blocks.
|
||||
*
|
||||
* @sa canIndentList
|
||||
*/
|
||||
void indentListMore();
|
||||
|
||||
/**
|
||||
* Decreases the nesting level of the current block or selected blocks.
|
||||
*
|
||||
* @sa canDedentList
|
||||
*/
|
||||
void indentListLess();
|
||||
|
||||
/**
|
||||
* Sets the current word or selection to the font family @a fontFamily
|
||||
*
|
||||
* @param fontFamily The text's font family will be changed to this one
|
||||
*/
|
||||
void setFontFamily(const QString &fontFamily);
|
||||
|
||||
/**
|
||||
* Sets the current word or selection to the font size @a size
|
||||
*
|
||||
* @param size The text's font will get this size
|
||||
*/
|
||||
void setFontSize(int size);
|
||||
|
||||
/**
|
||||
* Sets the current word or selection to the font @a font
|
||||
*
|
||||
* @param font the font of the text will be set to this font
|
||||
*/
|
||||
void setFont(const QFont &font);
|
||||
|
||||
/**
|
||||
* Toggles the bold formatting of the current word or selection at the current
|
||||
* cursor position.
|
||||
*
|
||||
* @param bold If true, the text will be set to bold
|
||||
*/
|
||||
void setTextBold(bool bold);
|
||||
|
||||
/**
|
||||
* Toggles the italic formatting of the current word or selection at the current
|
||||
* cursor position.
|
||||
*
|
||||
* @param italic If true, the text will be set to italic
|
||||
*/
|
||||
void setTextItalic(bool italic);
|
||||
|
||||
/**
|
||||
* Toggles the underline formatting of the current word or selection at the current
|
||||
* cursor position.
|
||||
*
|
||||
* @param underline If true, the text will be underlined
|
||||
*/
|
||||
void setTextUnderline(bool underline);
|
||||
|
||||
/**
|
||||
* Toggles the strikeout formatting of the current word or selection at the current
|
||||
* cursor position.
|
||||
*
|
||||
* @param strikeOut If true, the text will be struck out
|
||||
*/
|
||||
void setTextStrikeOut(bool strikeOut);
|
||||
|
||||
/**
|
||||
* Sets the foreground color of the current word or selection to @a color.
|
||||
*
|
||||
* @param color The text will get this background color
|
||||
*/
|
||||
void setTextForegroundColor(const QColor &color);
|
||||
|
||||
/**
|
||||
* Sets the background color of the current word or selection to @a color.
|
||||
*
|
||||
* @param color The text will get this foreground color
|
||||
*/
|
||||
void setTextBackgroundColor(const QColor &color);
|
||||
|
||||
/**
|
||||
* Inserts a horizontal rule below the current block.
|
||||
*/
|
||||
void insertHorizontalRule();
|
||||
|
||||
/**
|
||||
* This will switch the editor to plain text mode.
|
||||
* All rich text formatting will be destroyed.
|
||||
*/
|
||||
void switchToPlainText();
|
||||
|
||||
/**
|
||||
* This will clean some of the bad html produced by the underlying QTextEdit
|
||||
* It walks over all lines and cleans up a bit. Should be improved to produce
|
||||
* our own Html.
|
||||
*/
|
||||
QString toCleanHtml() const;
|
||||
|
||||
/**
|
||||
* Toggles the superscript formatting of the current word or selection at the current
|
||||
* cursor position.
|
||||
*
|
||||
* @param superscript If true, the text will be set to superscript
|
||||
*/
|
||||
void setTextSuperScript(bool superscript);
|
||||
|
||||
/**
|
||||
* Toggles the subscript formatting of the current word or selection at the current
|
||||
* cursor position.
|
||||
*
|
||||
* @param subscript If true, the text will be set to subscript
|
||||
*/
|
||||
void setTextSubScript(bool subscript);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
/**
|
||||
* Emitted whenever the text mode is changed.
|
||||
*
|
||||
* @param mode The new text mode
|
||||
*/
|
||||
void textModeChanged(KRichTextEdit::Mode mode);
|
||||
|
||||
/**
|
||||
* Emitted whenever the user has finished making a selection. (on mouse up)
|
||||
*/
|
||||
void selectionFinished();
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Reimplemented.
|
||||
* Catches key press events. Used to handle some key presses on lists.
|
||||
*/
|
||||
virtual void keyPressEvent(QKeyEvent *event);
|
||||
|
||||
private:
|
||||
//@cond PRIVATE
|
||||
KRichTextEditPrivate *const d;
|
||||
friend class KRichTextEditPrivate;
|
||||
//@endcond
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,717 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
|
||||
Copyright 2008 Stephen Kelly <steveire@gmail.com>
|
||||
Copyright 2008 Thomas McGuire <thomas.mcguire@gmx.net>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "krichtextwidget.h"
|
||||
|
||||
// KDE includes
|
||||
#include <kactioncollection.h>
|
||||
#include <kcolorscheme.h>
|
||||
#include <kfontaction.h>
|
||||
#include <kfontsizeaction.h>
|
||||
#include <klocale.h>
|
||||
#include <ktoggleaction.h>
|
||||
#include <kdebug.h>
|
||||
|
||||
// Katie includes
|
||||
#include <QtGui/QTextList>
|
||||
#include <QtGui/QColorDialog>
|
||||
|
||||
#include "klinkdialog.h"
|
||||
|
||||
// TODO: Add i18n context
|
||||
|
||||
/**
|
||||
Private class that helps to provide binary compatibility between releases.
|
||||
@internal
|
||||
*/
|
||||
//@cond PRIVATE
|
||||
class KRichTextWidget::Private
|
||||
{
|
||||
public:
|
||||
Private(KRichTextWidget *parent)
|
||||
: q(parent),
|
||||
painterActive(false),
|
||||
richTextEnabled(false), // It's only enabled when an action makes text rich.
|
||||
enableRichText(0),
|
||||
action_text_foreground_color(0),
|
||||
action_text_background_color(0),
|
||||
action_text_bold(0),
|
||||
action_text_italic(0),
|
||||
action_text_underline(0),
|
||||
action_text_strikeout(0),
|
||||
action_font_family(0),
|
||||
action_font_size(0),
|
||||
action_list_style(0),
|
||||
action_list_indent(0),
|
||||
action_list_dedent(0),
|
||||
action_manage_link(0),
|
||||
action_insert_horizontal_rule(0),
|
||||
action_format_painter(0),
|
||||
action_to_plain_text(0),
|
||||
action_align_left(0),
|
||||
action_align_right(0),
|
||||
action_align_center(0),
|
||||
action_align_justify(0),
|
||||
action_direction_ltr(0),
|
||||
action_direction_rtl(0),
|
||||
action_text_superscript(0),
|
||||
action_text_subscript(0)
|
||||
{
|
||||
}
|
||||
|
||||
KRichTextWidget *q;
|
||||
|
||||
RichTextSupport richTextSupport;
|
||||
|
||||
QTextCharFormat painterFormat;
|
||||
bool painterActive;
|
||||
|
||||
QList<KAction*> richTextActionList;
|
||||
|
||||
bool richTextEnabled;
|
||||
KToggleAction *enableRichText;
|
||||
|
||||
KAction *action_text_foreground_color;
|
||||
KAction *action_text_background_color;
|
||||
|
||||
KToggleAction *action_text_bold;
|
||||
KToggleAction *action_text_italic;
|
||||
KToggleAction *action_text_underline;
|
||||
KToggleAction *action_text_strikeout;
|
||||
|
||||
KFontAction *action_font_family;
|
||||
KFontSizeAction *action_font_size;
|
||||
|
||||
KSelectAction *action_list_style;
|
||||
KAction *action_list_indent;
|
||||
KAction *action_list_dedent;
|
||||
|
||||
KAction *action_manage_link;
|
||||
KAction *action_insert_horizontal_rule;
|
||||
KAction *action_format_painter;
|
||||
KAction *action_to_plain_text;
|
||||
|
||||
KToggleAction *action_align_left;
|
||||
KToggleAction *action_align_right;
|
||||
KToggleAction *action_align_center;
|
||||
KToggleAction *action_align_justify;
|
||||
|
||||
KToggleAction *action_direction_ltr;
|
||||
KToggleAction *action_direction_rtl;
|
||||
|
||||
KToggleAction *action_text_superscript;
|
||||
KToggleAction *action_text_subscript;
|
||||
|
||||
//
|
||||
// Normal functions
|
||||
//
|
||||
void init();
|
||||
|
||||
//
|
||||
// Slots
|
||||
//
|
||||
|
||||
/**
|
||||
* @brief Opens a dialog to allow the user to select a foreground color.
|
||||
*/
|
||||
void _k_setTextForegroundColor();
|
||||
|
||||
/**
|
||||
* @brief Opens a dialog to allow the user to select a background color.
|
||||
*/
|
||||
void _k_setTextBackgroundColor();
|
||||
|
||||
/**
|
||||
* Opens a dialog which lets the user turn the currently selected text into
|
||||
* a link.
|
||||
* If no text is selected, the word under the cursor will be taken.
|
||||
* If the cursor is already over a link, the user can edit that link.
|
||||
*
|
||||
*/
|
||||
void _k_manageLink();
|
||||
|
||||
/**
|
||||
* Activates a format painter to allow the user to copy font/text formatting
|
||||
* to different parts of the document.
|
||||
*
|
||||
*/
|
||||
void _k_formatPainter(bool active);
|
||||
|
||||
/**
|
||||
* @brief Update actions relating to text format (bold, size etc.).
|
||||
*/
|
||||
void _k_updateCharFormatActions(const QTextCharFormat &format);
|
||||
|
||||
/**
|
||||
* Update actions not covered by text formatting, such as alignment,
|
||||
* list style and level.
|
||||
*/
|
||||
void _k_updateMiscActions();
|
||||
|
||||
/**
|
||||
* Change the style of the current list or create a new list with the style given by @a index.
|
||||
*/
|
||||
void _k_setListStyle(int index);
|
||||
|
||||
};
|
||||
//@endcond
|
||||
|
||||
void KRichTextWidget::Private::init()
|
||||
{
|
||||
q->setRichTextSupport(KRichTextWidget::FullSupport);
|
||||
}
|
||||
|
||||
KRichTextWidget::KRichTextWidget(QWidget* parent)
|
||||
: KRichTextEdit(parent),
|
||||
d(new Private(this))
|
||||
{
|
||||
d->init();
|
||||
}
|
||||
|
||||
KRichTextWidget::KRichTextWidget(const QString& text, QWidget *parent)
|
||||
: KRichTextEdit(text,parent),
|
||||
d(new Private(this))
|
||||
{
|
||||
d->init();
|
||||
}
|
||||
|
||||
KRichTextWidget::~KRichTextWidget()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
KRichTextWidget::RichTextSupport KRichTextWidget::richTextSupport() const
|
||||
{
|
||||
return d->richTextSupport;
|
||||
}
|
||||
|
||||
void KRichTextWidget::setRichTextSupport(const KRichTextWidget::RichTextSupport &support)
|
||||
{
|
||||
d->richTextSupport = support;
|
||||
}
|
||||
|
||||
void KRichTextWidget::createActions(KActionCollection *actionCollection)
|
||||
{
|
||||
Q_ASSERT(actionCollection);
|
||||
|
||||
// Note to maintainers: If adding new functionality here, make sure to disconnect
|
||||
// and delete actions which should not be supported.
|
||||
//
|
||||
// New Actions need to be added to the following places:
|
||||
// - possibly the RichTextSupportValues enum
|
||||
// - the API documentation for createActions()
|
||||
// - this function
|
||||
// - the action needs to be added to the private class as a member
|
||||
// - the constructor of the private class
|
||||
// - depending on the action, some slot that changes the toggle state when
|
||||
// appropriate, such as _k_updateCharFormatActions or _k_updateMiscActions.
|
||||
|
||||
// The list of actions currently supported is also stored internally.
|
||||
// This is used to disable all actions at once in setActionsEnabled.
|
||||
d->richTextActionList.clear();
|
||||
|
||||
if (d->richTextSupport & SupportTextForegroundColor) {
|
||||
//Foreground Color
|
||||
d->action_text_foreground_color = new KAction(KIcon("format-stroke-color"), i18nc("@action", "Text &Color..."), actionCollection);
|
||||
d->action_text_foreground_color->setIconText(i18nc("@label stroke color", "Color"));
|
||||
d->richTextActionList.append((d->action_text_foreground_color));
|
||||
actionCollection->addAction("format_text_foreground_color", d->action_text_foreground_color);
|
||||
connect(d->action_text_foreground_color, SIGNAL(triggered()), this, SLOT(_k_setTextForegroundColor()));
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_text_foreground_color);
|
||||
d->action_text_foreground_color = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportTextBackgroundColor) {
|
||||
//Background Color
|
||||
d->action_text_background_color = new KAction(KIcon("format-fill-color"), i18nc("@action", "Text &Highlight..."), actionCollection);
|
||||
d->richTextActionList.append((d->action_text_background_color));
|
||||
actionCollection->addAction("format_text_background_color", d->action_text_background_color);
|
||||
connect(d->action_text_background_color, SIGNAL(triggered()), this, SLOT(_k_setTextBackgroundColor()));
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_text_background_color);
|
||||
d->action_text_background_color = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportFontFamily) {
|
||||
//Font Family
|
||||
d->action_font_family = new KFontAction(i18nc("@action", "&Font"), actionCollection);
|
||||
d->richTextActionList.append((d->action_font_family));
|
||||
actionCollection->addAction("format_font_family", d->action_font_family);
|
||||
connect(d->action_font_family, SIGNAL(triggered(QString)), this, SLOT(setFontFamily(QString)));
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_font_family);
|
||||
d->action_font_family = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportFontSize) {
|
||||
//Font Size
|
||||
d->action_font_size = new KFontSizeAction(i18nc("@action", "Font &Size"), actionCollection);
|
||||
d->richTextActionList.append((d->action_font_size));
|
||||
actionCollection->addAction("format_font_size", d->action_font_size);
|
||||
connect(d->action_font_size, SIGNAL(fontSizeChanged(int)), this, SLOT(setFontSize(int)));
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_font_size);
|
||||
d->action_font_size = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportBold) {
|
||||
d->action_text_bold = new KToggleAction(KIcon("format-text-bold"), i18nc("@action boldify selected text", "&Bold"), actionCollection);
|
||||
QFont bold;
|
||||
bold.setBold(true);
|
||||
d->action_text_bold->setFont(bold);
|
||||
d->richTextActionList.append((d->action_text_bold));
|
||||
actionCollection->addAction("format_text_bold", d->action_text_bold);
|
||||
d->action_text_bold->setShortcut(KShortcut(Qt::CTRL + Qt::Key_B));
|
||||
connect(d->action_text_bold, SIGNAL(triggered(bool)), this, SLOT(setTextBold(bool)));
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_text_bold);
|
||||
d->action_text_bold = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportItalic) {
|
||||
d->action_text_italic = new KToggleAction(KIcon("format-text-italic"), i18nc("@action italicize selected text", "&Italic"), actionCollection);
|
||||
QFont italic;
|
||||
italic.setItalic(true);
|
||||
d->action_text_italic->setFont(italic);
|
||||
d->richTextActionList.append((d->action_text_italic));
|
||||
actionCollection->addAction("format_text_italic", d->action_text_italic);
|
||||
d->action_text_italic->setShortcut(KShortcut(Qt::CTRL + Qt::Key_I));
|
||||
connect(d->action_text_italic, SIGNAL(triggered(bool)),
|
||||
this, SLOT(setTextItalic(bool)));
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_text_italic);
|
||||
d->action_text_italic = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportUnderline) {
|
||||
d->action_text_underline = new KToggleAction(KIcon("format-text-underline"), i18nc("@action underline selected text", "&Underline"), actionCollection);
|
||||
QFont underline;
|
||||
underline.setUnderline(true);
|
||||
d->action_text_underline->setFont(underline);
|
||||
d->richTextActionList.append((d->action_text_underline));
|
||||
actionCollection->addAction("format_text_underline", d->action_text_underline);
|
||||
d->action_text_underline->setShortcut(KShortcut(Qt::CTRL + Qt::Key_U));
|
||||
connect(d->action_text_underline, SIGNAL(triggered(bool)),
|
||||
this, SLOT(setTextUnderline(bool)));
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_text_underline);
|
||||
d->action_text_underline = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportStrikeOut) {
|
||||
d->action_text_strikeout = new KToggleAction(KIcon("format-text-strikethrough"), i18nc("@action", "&Strike Out"), actionCollection);
|
||||
d->richTextActionList.append((d->action_text_strikeout));
|
||||
actionCollection->addAction("format_text_strikeout", d->action_text_strikeout);
|
||||
d->action_text_strikeout->setShortcut(KShortcut(Qt::CTRL + Qt::Key_L));
|
||||
connect(d->action_text_strikeout, SIGNAL(triggered(bool)),
|
||||
this, SLOT(setTextStrikeOut(bool)));
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_text_strikeout);
|
||||
d->action_text_strikeout = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportAlignment) {
|
||||
//Alignment
|
||||
d->action_align_left = new KToggleAction(KIcon("format-justify-left"), i18nc("@action", "Align &Left"), actionCollection);
|
||||
d->action_align_left->setIconText(i18nc("@label left justify", "Left"));
|
||||
d->richTextActionList.append((d->action_align_left));
|
||||
actionCollection->addAction("format_align_left", d->action_align_left);
|
||||
connect(d->action_align_left, SIGNAL(triggered()),
|
||||
this, SLOT(alignLeft()));
|
||||
|
||||
d->action_align_center = new KToggleAction(KIcon("format-justify-center"), i18nc("@action", "Align &Center"), actionCollection);
|
||||
d->action_align_center->setIconText(i18nc("@label center justify", "Center"));
|
||||
d->richTextActionList.append((d->action_align_center));
|
||||
actionCollection->addAction("format_align_center", d->action_align_center);
|
||||
connect(d->action_align_center, SIGNAL(triggered()),
|
||||
this, SLOT(alignCenter()));
|
||||
|
||||
d->action_align_right = new KToggleAction(KIcon("format-justify-right"), i18nc("@action", "Align &Right"), actionCollection);
|
||||
d->action_align_right->setIconText(i18nc("@label right justify", "Right"));
|
||||
d->richTextActionList.append((d->action_align_right));
|
||||
actionCollection->addAction("format_align_right", d->action_align_right);
|
||||
connect(d->action_align_right, SIGNAL(triggered()),
|
||||
this, SLOT(alignRight()));
|
||||
|
||||
d->action_align_justify = new KToggleAction(KIcon("format-justify-fill"), i18nc("@action", "&Justify"), actionCollection);
|
||||
d->action_align_justify->setIconText(i18nc("@label justify fill", "Justify"));
|
||||
d->richTextActionList.append((d->action_align_justify));
|
||||
actionCollection->addAction("format_align_justify", d->action_align_justify);
|
||||
connect(d->action_align_justify, SIGNAL(triggered()),
|
||||
this, SLOT(alignJustify()));
|
||||
|
||||
QActionGroup *alignmentGroup = new QActionGroup(this);
|
||||
alignmentGroup->addAction(d->action_align_left);
|
||||
alignmentGroup->addAction(d->action_align_center);
|
||||
alignmentGroup->addAction(d->action_align_right);
|
||||
alignmentGroup->addAction(d->action_align_justify);
|
||||
} else {
|
||||
|
||||
actionCollection->removeAction(d->action_align_left);
|
||||
actionCollection->removeAction(d->action_align_center);
|
||||
actionCollection->removeAction(d->action_align_right);
|
||||
actionCollection->removeAction(d->action_align_justify);
|
||||
|
||||
d->action_align_left = 0;
|
||||
d->action_align_center = 0;
|
||||
d->action_align_right = 0;
|
||||
d->action_align_justify = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportDirection) {
|
||||
d->action_direction_ltr = new KToggleAction(KIcon("format-text-direction-ltr"), i18nc("@action", "Left-to-Right"), actionCollection);
|
||||
d->action_direction_ltr->setIconText(i18nc("@label left-to-right", "Left-to-Right"));
|
||||
d->richTextActionList.append(d->action_direction_ltr);
|
||||
actionCollection->addAction("direction_ltr", d->action_direction_ltr);
|
||||
connect(d->action_direction_ltr, SIGNAL(triggered()),
|
||||
this, SLOT(makeLeftToRight()));
|
||||
|
||||
d->action_direction_rtl = new KToggleAction(KIcon("format-text-direction-rtl"), i18nc("@action", "Right-to-Left"), actionCollection);
|
||||
d->action_direction_rtl->setIconText(i18nc("@label right-to-left", "Right-to-Left"));
|
||||
d->richTextActionList.append(d->action_direction_rtl);
|
||||
actionCollection->addAction("direction_rtl", d->action_direction_rtl);
|
||||
connect(d->action_direction_rtl, SIGNAL(triggered()),
|
||||
this, SLOT(makeRightToLeft()));
|
||||
|
||||
QActionGroup *directionGroup = new QActionGroup(this);
|
||||
directionGroup->addAction(d->action_direction_ltr);
|
||||
directionGroup->addAction(d->action_direction_rtl);
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_direction_ltr);
|
||||
actionCollection->removeAction(d->action_direction_rtl);
|
||||
|
||||
d->action_direction_ltr = 0;
|
||||
d->action_direction_rtl = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportChangeListStyle) {
|
||||
d->action_list_style = new KSelectAction(KIcon("format-list-unordered"), i18nc("@title:menu", "List Style"), actionCollection);
|
||||
QStringList listStyles;
|
||||
listStyles << i18nc("@item:inmenu no list style", "None")
|
||||
<< i18nc("@item:inmenu disc list style", "Disc")
|
||||
<< i18nc("@item:inmenu circle list style", "Circle")
|
||||
<< i18nc("@item:inmenu square list style", "Square")
|
||||
<< i18nc("@item:inmenu numbered lists", "123")
|
||||
<< i18nc("@item:inmenu lowercase abc lists", "abc")
|
||||
<< i18nc("@item:inmenu uppercase abc lists", "ABC")
|
||||
<< i18nc("@item:inmenu lower case roman numerals", "i ii iii")
|
||||
<< i18nc("@item:inmenu upper case roman numerals", "I II III");
|
||||
|
||||
d->action_list_style->setItems(listStyles);
|
||||
d->action_list_style->setCurrentItem(0);
|
||||
d->richTextActionList.append((d->action_list_style));
|
||||
actionCollection->addAction("format_list_style", d->action_list_style);
|
||||
connect(d->action_list_style, SIGNAL(triggered(int)),
|
||||
this, SLOT(_k_setListStyle(int)));
|
||||
connect(d->action_list_style, SIGNAL(triggered()),
|
||||
this, SLOT(_k_updateMiscActions()));
|
||||
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_list_style);
|
||||
d->action_list_style = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportIndentLists) {
|
||||
d->action_list_indent = new KAction(KIcon("format-indent-more"), i18nc("@action", "Increase Indent"), actionCollection);
|
||||
d->richTextActionList.append((d->action_list_indent));
|
||||
actionCollection->addAction("format_list_indent_more", d->action_list_indent);
|
||||
connect(d->action_list_indent, SIGNAL(triggered()),
|
||||
this, SLOT(indentListMore()));
|
||||
connect(d->action_list_indent, SIGNAL(triggered()),
|
||||
this, SLOT(_k_updateMiscActions()));
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_list_indent);
|
||||
d->action_list_indent = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportDedentLists) {
|
||||
d->action_list_dedent = new KAction(KIcon("format-indent-less"), i18nc("@action", "Decrease Indent"), actionCollection);
|
||||
d->richTextActionList.append((d->action_list_dedent));
|
||||
actionCollection->addAction("format_list_indent_less", d->action_list_dedent);
|
||||
connect(d->action_list_dedent, SIGNAL(triggered()),
|
||||
this, SLOT(indentListLess()));
|
||||
connect(d->action_list_dedent, SIGNAL(triggered()),
|
||||
this, SLOT(_k_updateMiscActions()));
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_list_dedent);
|
||||
d->action_list_dedent = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportRuleLine) {
|
||||
d->action_insert_horizontal_rule = new KAction(KIcon("insert-horizontal-rule"), i18nc("@action", "Insert Rule Line"), actionCollection);
|
||||
d->richTextActionList.append((d->action_insert_horizontal_rule));
|
||||
actionCollection->addAction("insert_horizontal_rule", d->action_insert_horizontal_rule);
|
||||
connect(d->action_insert_horizontal_rule, SIGNAL(triggered()),
|
||||
this, SLOT(insertHorizontalRule()));
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_insert_horizontal_rule);
|
||||
d->action_insert_horizontal_rule = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportHyperlinks) {
|
||||
d->action_manage_link = new KAction(KIcon("insert-link"), i18nc("@action", "Link"), actionCollection);
|
||||
d->richTextActionList.append((d->action_manage_link));
|
||||
actionCollection->addAction("manage_link", d->action_manage_link);
|
||||
connect(d->action_manage_link, SIGNAL(triggered()),
|
||||
this, SLOT(_k_manageLink()));
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_manage_link);
|
||||
d->action_manage_link = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportFormatPainting) {
|
||||
d->action_format_painter = new KToggleAction(KIcon("draw-brush"), i18nc("@action", "Format Painter"), actionCollection);
|
||||
d->richTextActionList.append((d->action_format_painter));
|
||||
actionCollection->addAction("format_painter", d->action_format_painter);
|
||||
connect(d->action_format_painter, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_k_formatPainter(bool)));
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_format_painter);
|
||||
d->action_format_painter = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportToPlainText) {
|
||||
d->action_to_plain_text = new KToggleAction(i18nc("@action", "To Plain Text"), actionCollection);
|
||||
d->richTextActionList.append((d->action_to_plain_text));
|
||||
actionCollection->addAction("action_to_plain_text", d->action_to_plain_text);
|
||||
connect(d->action_to_plain_text, SIGNAL(triggered()),
|
||||
this, SLOT(switchToPlainText()));
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_to_plain_text);
|
||||
d->action_to_plain_text = 0;
|
||||
}
|
||||
|
||||
if (d->richTextSupport & SupportSuperScriptAndSubScript) {
|
||||
d->action_text_subscript = new KToggleAction(KIcon("format-text-subscript"), i18nc("@action", "Subscript"), actionCollection);
|
||||
d->richTextActionList.append((d->action_text_subscript));
|
||||
actionCollection->addAction("format_text_subscript", d->action_text_subscript);
|
||||
|
||||
connect(d->action_text_subscript, SIGNAL(triggered(bool)),
|
||||
this, SLOT(setTextSubScript(bool)));
|
||||
|
||||
d->action_text_superscript = new KToggleAction(KIcon("format-text-superscript"), i18nc("@action", "Superscript"), actionCollection);
|
||||
d->richTextActionList.append((d->action_text_superscript));
|
||||
actionCollection->addAction("format_text_superscript", d->action_text_superscript);
|
||||
|
||||
connect(d->action_text_superscript, SIGNAL(triggered(bool)),
|
||||
this, SLOT(setTextSuperScript(bool)));
|
||||
} else {
|
||||
actionCollection->removeAction(d->action_text_subscript);
|
||||
d->action_text_subscript = 0;
|
||||
|
||||
actionCollection->removeAction(d->action_text_superscript);
|
||||
d->action_text_superscript = 0;
|
||||
}
|
||||
|
||||
|
||||
disconnect(this, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
|
||||
this, SLOT(_k_updateCharFormatActions(QTextCharFormat)));
|
||||
disconnect(this, SIGNAL(cursorPositionChanged()),
|
||||
this, SLOT(_k_updateMiscActions()));
|
||||
connect(this, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
|
||||
this, SLOT(_k_updateCharFormatActions(QTextCharFormat)));
|
||||
connect(this, SIGNAL(cursorPositionChanged()),
|
||||
this, SLOT(_k_updateMiscActions()));
|
||||
|
||||
d->_k_updateMiscActions();
|
||||
d->_k_updateCharFormatActions(currentCharFormat());
|
||||
}
|
||||
|
||||
|
||||
void KRichTextWidget::setActionsEnabled(bool enabled)
|
||||
{
|
||||
foreach(QAction* action, d->richTextActionList)
|
||||
{
|
||||
action->setEnabled(enabled);
|
||||
}
|
||||
d->richTextEnabled = enabled;
|
||||
}
|
||||
|
||||
void KRichTextWidget::Private::_k_setListStyle(int index)
|
||||
{
|
||||
q->setListStyle(index);
|
||||
_k_updateMiscActions();
|
||||
}
|
||||
|
||||
void KRichTextWidget::Private::_k_updateCharFormatActions(const QTextCharFormat &format)
|
||||
{
|
||||
QFont f = format.font();
|
||||
|
||||
if (richTextSupport & SupportFontFamily) {
|
||||
action_font_family->setFont(f.family());
|
||||
}
|
||||
if (richTextSupport & SupportFontSize) {
|
||||
if (f.pointSize() > 0)
|
||||
action_font_size->setFontSize((int)f.pointSize());
|
||||
}
|
||||
|
||||
if (richTextSupport & SupportBold) {
|
||||
action_text_bold->setChecked(f.bold());
|
||||
}
|
||||
|
||||
if (richTextSupport & SupportItalic) {
|
||||
action_text_italic->setChecked(f.italic());
|
||||
}
|
||||
|
||||
if (richTextSupport & SupportUnderline) {
|
||||
action_text_underline->setChecked(f.underline());
|
||||
}
|
||||
|
||||
if (richTextSupport & SupportStrikeOut) {
|
||||
action_text_strikeout->setChecked(f.strikeOut());
|
||||
}
|
||||
|
||||
if (richTextSupport & SupportSuperScriptAndSubScript) {
|
||||
QTextCharFormat::VerticalAlignment vAlign = format.verticalAlignment();
|
||||
action_text_superscript->setChecked(vAlign == QTextCharFormat::AlignSuperScript);
|
||||
action_text_subscript->setChecked(vAlign == QTextCharFormat::AlignSubScript);
|
||||
}
|
||||
}
|
||||
|
||||
void KRichTextWidget::Private::_k_updateMiscActions()
|
||||
{
|
||||
if (richTextSupport & SupportAlignment) {
|
||||
Qt::Alignment a = q->alignment();
|
||||
if (a & Qt::AlignLeft) {
|
||||
action_align_left->setChecked(true);
|
||||
} else if (a & Qt::AlignHCenter) {
|
||||
action_align_center->setChecked(true);
|
||||
} else if (a & Qt::AlignRight) {
|
||||
action_align_right->setChecked(true);
|
||||
} else if (a & Qt::AlignJustify) {
|
||||
action_align_justify->setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (richTextSupport & SupportChangeListStyle) {
|
||||
if (q->textCursor().currentList()) {
|
||||
action_list_style->setCurrentItem(-q->textCursor().currentList()->format().style());
|
||||
} else {
|
||||
action_list_style->setCurrentItem(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( richTextSupport & SupportIndentLists ) {
|
||||
if ( richTextEnabled ) {
|
||||
action_list_indent->setEnabled( q->canIndentList() );
|
||||
} else {
|
||||
action_list_indent->setEnabled( false );
|
||||
}
|
||||
}
|
||||
|
||||
if ( richTextSupport & SupportDedentLists ) {
|
||||
if ( richTextEnabled ) {
|
||||
action_list_dedent->setEnabled( q->canDedentList() );
|
||||
} else {
|
||||
action_list_dedent->setEnabled( false );
|
||||
}
|
||||
}
|
||||
|
||||
if (richTextSupport & SupportDirection) {
|
||||
const Qt::LayoutDirection direction = q->textCursor().blockFormat().layoutDirection();
|
||||
action_direction_ltr->setChecked(direction == Qt::LeftToRight);
|
||||
action_direction_rtl->setChecked(direction == Qt::RightToLeft);
|
||||
}
|
||||
}
|
||||
|
||||
void KRichTextWidget::Private::_k_setTextForegroundColor()
|
||||
{
|
||||
QColor currentTextForegroundColor = q->textColor();
|
||||
const QColor colorSchemeColor = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color();
|
||||
if (!currentTextForegroundColor.isValid()) {
|
||||
currentTextForegroundColor = colorSchemeColor;
|
||||
}
|
||||
currentTextForegroundColor = QColorDialog::getColor(currentTextForegroundColor, q, KDialog::makeStandardCaption(i18n("Select Color"), q));
|
||||
if (!currentTextForegroundColor.isValid()) {
|
||||
currentTextForegroundColor = colorSchemeColor;
|
||||
}
|
||||
q->setTextForegroundColor(currentTextForegroundColor);
|
||||
|
||||
}
|
||||
|
||||
void KRichTextWidget::Private::_k_setTextBackgroundColor()
|
||||
{
|
||||
QTextCharFormat fmt = q->textCursor().charFormat();
|
||||
QColor currentTextBackgroundColor = fmt.background().color();
|
||||
const QColor colorSchemeColor = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color();
|
||||
if (!currentTextBackgroundColor.isValid()) {
|
||||
currentTextBackgroundColor = colorSchemeColor;
|
||||
}
|
||||
currentTextBackgroundColor = QColorDialog::getColor(currentTextBackgroundColor, q, KDialog::makeStandardCaption(i18n("Select Color"), q));
|
||||
if (!currentTextBackgroundColor.isValid()) {
|
||||
currentTextBackgroundColor = colorSchemeColor;
|
||||
}
|
||||
q->setTextBackgroundColor(currentTextBackgroundColor);
|
||||
|
||||
}
|
||||
|
||||
void KRichTextWidget::Private::_k_manageLink()
|
||||
{
|
||||
q->selectLinkText();
|
||||
KLinkDialog *linkDialog = new KLinkDialog(q);
|
||||
linkDialog->setLinkText(q->currentLinkText());
|
||||
linkDialog->setLinkUrl(q->currentLinkUrl());
|
||||
|
||||
if (linkDialog->exec()) {
|
||||
q->updateLink(linkDialog->linkUrl(), linkDialog->linkText());
|
||||
}
|
||||
|
||||
delete linkDialog;
|
||||
|
||||
}
|
||||
|
||||
void KRichTextWidget::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (d->painterActive) {
|
||||
// If the painter is active, paint the selection with the
|
||||
// correct format.
|
||||
if (textCursor().hasSelection()) {
|
||||
textCursor().setCharFormat(d->painterFormat);
|
||||
}
|
||||
d->painterActive = false;
|
||||
d->action_format_painter->setChecked(false);
|
||||
}
|
||||
KRichTextEdit::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void KRichTextWidget::Private::_k_formatPainter(bool active)
|
||||
{
|
||||
if (active) {
|
||||
painterFormat = q->currentCharFormat();
|
||||
painterActive = true;
|
||||
q->viewport()->setCursor(QCursor(KIcon("draw-brush").pixmap(32, 32), 0, 32));
|
||||
} else {
|
||||
painterFormat = QTextCharFormat();
|
||||
painterActive = false;
|
||||
q->viewport()->setCursor(Qt::IBeamCursor);
|
||||
}
|
||||
}
|
||||
|
||||
void KRichTextWidget::updateActionStates()
|
||||
{
|
||||
d->_k_updateMiscActions();
|
||||
d->_k_updateCharFormatActions(currentCharFormat());
|
||||
}
|
||||
|
||||
// kate: space-indent on; indent-width 4; encoding utf-8; replace-tabs on;
|
||||
#include "moc_krichtextwidget.cpp"
|
|
@ -1,362 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
|
||||
Copyright 2008 Stephen Kelly <steveire@gmail.com>
|
||||
Copyright 2008 Thomas McGuire <thomas.mcguire@gmx.net>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#ifndef KRICHTEXTWIDGET_H
|
||||
#define KRICHTEXTWIDGET_H
|
||||
|
||||
#include "krichtextedit.h"
|
||||
|
||||
class KActionCollection;
|
||||
|
||||
/**
|
||||
* @brief A KRichTextEdit with common actions
|
||||
*
|
||||
* This class implements common actions which are often used with KRichTextEdit.
|
||||
* All you need to do is to call createActions(), and the actions will be
|
||||
* added to your KXMLGUIWindow. Remember to also add the chosen actions to
|
||||
* your application ui.rc file.
|
||||
*
|
||||
* See the KRichTextWidget::RichTextSupportValues enum for an overview of
|
||||
* supported actions.
|
||||
*
|
||||
* @author Stephen Kelly <steveire@gmail.com>
|
||||
* @author Thomas McGuire <thomas.mcguire@gmx.net>
|
||||
*
|
||||
* \image html krichtextedit.png "KDE Rich Text Widget"
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
class KDEUI_EXPORT KRichTextWidget : public KRichTextEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_FLAGS(RichTextSupport)
|
||||
Q_PROPERTY(RichTextSupport richTextSupport READ richTextSupport WRITE setRichTextSupport)
|
||||
public:
|
||||
|
||||
/**
|
||||
* These flags describe what actions will be created by createActions() after
|
||||
* passing a combination of these flags to setRichTextSupport().
|
||||
*/
|
||||
enum RichTextSupportValues {
|
||||
/**
|
||||
* No rich text support at all, no actions will be created. Do not use
|
||||
* in combination with other flags.
|
||||
*/
|
||||
DisableRichText = 0x00,
|
||||
|
||||
/**
|
||||
* Action to format the selected text as bold. If no text is selected,
|
||||
* the word under the cursor is formatted bold.
|
||||
* This is a KToggleAction. The status is automatically updated when
|
||||
* the text cursor is moved.
|
||||
*/
|
||||
SupportBold = 0x01,
|
||||
|
||||
/**
|
||||
* Action to format the selected text as italic. If no text is selected,
|
||||
* the word under the cursor is formatted italic.
|
||||
* This is a KToggleAction. The status is automatically updated when
|
||||
* the text cursor is moved.
|
||||
*/
|
||||
SupportItalic = 0x02,
|
||||
|
||||
/**
|
||||
* Action to underline the selected text. If no text is selected,
|
||||
* the word under the cursor is underlined.
|
||||
* This is a KToggleAction. The status is automatically updated when
|
||||
* the text cursor is moved.
|
||||
*/
|
||||
SupportUnderline = 0x04,
|
||||
|
||||
/**
|
||||
* Action to strike out the selected text. If no text is selected,
|
||||
* the word under the cursor is struck out.
|
||||
* This is a KToggleAction. The status is automatically updated when
|
||||
* the text cursor is moved.
|
||||
*/
|
||||
SupportStrikeOut = 0x08,
|
||||
|
||||
/**
|
||||
* Action to change the font family of the currently selected text. If
|
||||
* no text is selected, the font family of the word under the cursor is
|
||||
* changed.
|
||||
* Displayed as a combobox when inserted into the toolbar.
|
||||
* This is a KFontAction. The status is automatically updated when
|
||||
* the text cursor is moved.
|
||||
*/
|
||||
SupportFontFamily = 0x10,
|
||||
|
||||
/**
|
||||
* Action to change the font size of the currently selected text. If no
|
||||
* text is selected, the font size of the word under the cursor is changed.
|
||||
* Displayed as a combobox when inserted into the toolbar.
|
||||
* This is a KFontSizeAction. The status is automatically updated when
|
||||
* the text cursor is moved.
|
||||
*/
|
||||
SupportFontSize = 0x20,
|
||||
|
||||
/**
|
||||
* Action to change the text color of the currently selected text. If no
|
||||
* text is selected, the text color of the word under the cursor is
|
||||
* changed.
|
||||
* Opens a QColorDialog to select the color.
|
||||
*/
|
||||
SupportTextForegroundColor = 0x40,
|
||||
|
||||
/**
|
||||
* Action to change the background color of the currently selected text. If no
|
||||
* text is selected, the backgound color of the word under the cursor is
|
||||
* changed.
|
||||
* Opens a QColorDialog to select the color.
|
||||
*/
|
||||
SupportTextBackgroundColor = 0x80,
|
||||
|
||||
/**
|
||||
* A combination of all the flags above.
|
||||
* Includes all actions that change the format of the text.
|
||||
*/
|
||||
FullTextFormattingSupport = 0xff,
|
||||
|
||||
/**
|
||||
* Action to make the current line a list element, change the
|
||||
* list style or remove list formatting.
|
||||
* Displayed as a combobox when inserted into a toolbar.
|
||||
* This is a KSelectAction. The status is automatically updated when
|
||||
* the text cursor is moved.
|
||||
*/
|
||||
SupportChangeListStyle = 0x100,
|
||||
|
||||
/**
|
||||
* Action to increase the current list nesting level. This makes it
|
||||
* possible to create nested lists.
|
||||
*/
|
||||
SupportIndentLists = 0x200,
|
||||
|
||||
/**
|
||||
* Action to decrease the current list nesting level.
|
||||
*/
|
||||
SupportDedentLists = 0x400,
|
||||
|
||||
/**
|
||||
* All of the three list actions above.
|
||||
* Includes all list-related actions.
|
||||
*/
|
||||
FullListSupport = 0xf00,
|
||||
|
||||
// Not implemented yet.
|
||||
// SupportCreateTables = 0x1000,
|
||||
// SupportChangeCellMargin = 0x2000,
|
||||
// SupportChangeCellPadding = 0x4000,
|
||||
// SupportChangeTableBorderWidth = 0x8000,
|
||||
// SupportChangeTableBorderColor = 0x10000,
|
||||
// SupportChangeTableBorderStyle = 0x20000,
|
||||
// SupportChangeCellBackground = 0x40000,
|
||||
// SupportCellFillPatterns = 0x80000,
|
||||
//
|
||||
// FullTableSupport = 0xff000,
|
||||
|
||||
/**
|
||||
* Actions to align the current paragraph left, righ, center or justify.
|
||||
* These actions are KToogleActions. The status is automatically updated when
|
||||
* the text cursor is moved.
|
||||
*/
|
||||
SupportAlignment = 0x100000,
|
||||
|
||||
// Not yet implemented SupportImages = 0x200000,
|
||||
|
||||
/**
|
||||
* Action to insert a horizontal line.
|
||||
*/
|
||||
SupportRuleLine = 0x400000,
|
||||
|
||||
/**
|
||||
* Action to convert the current text to a hyperlink. If no text is selected,
|
||||
* the word under the cursor is converted.
|
||||
* This action opens a dialog where the user can enter the link target.
|
||||
*/
|
||||
SupportHyperlinks = 0x800000,
|
||||
|
||||
/**
|
||||
* Action to make the mouse cursor a format painter. The user can select
|
||||
* text with that painter. The selected text gets the same format as the
|
||||
* text that was previously selected.
|
||||
*/
|
||||
SupportFormatPainting = 0x1000000,
|
||||
|
||||
/**
|
||||
* Action to change the text of the whole text edit to plain text.
|
||||
* All rich text formatting will get lost.
|
||||
*/
|
||||
SupportToPlainText = 0x2000000,
|
||||
|
||||
/**
|
||||
* Actions to format text as superscript or subscript. If no text is selected,
|
||||
* the word under the cursor is formatted as selected.
|
||||
* This is a KToggleAction. The status is automatically updated when
|
||||
* the text cursor is moved.
|
||||
*/
|
||||
SupportSuperScriptAndSubScript = 0x4000000,
|
||||
|
||||
// SupportChangeParagraphSpacing = 0x200000,
|
||||
|
||||
/**
|
||||
* Action to change direction of text to Right-To-Left or Left-To-Right.
|
||||
*/
|
||||
SupportDirection = 0x8000000,
|
||||
|
||||
/**
|
||||
* Includes all above actions for full rich text support
|
||||
*/
|
||||
FullSupport = 0xffffffff
|
||||
};
|
||||
Q_DECLARE_FLAGS(RichTextSupport, RichTextSupportValues)
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param parent the parent widget
|
||||
*/
|
||||
explicit KRichTextWidget(QWidget *parent);
|
||||
|
||||
/**
|
||||
* Constructs a KRichTextWidget object
|
||||
*
|
||||
* @param text The initial text of the text edit, which is interpreted as
|
||||
* HTML.
|
||||
* @param parent The parent widget
|
||||
*/
|
||||
explicit KRichTextWidget(const QString& text, QWidget *parent = 0);
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
~KRichTextWidget();
|
||||
|
||||
/**
|
||||
* @brief Creates the actions and adds them to the given action collection.
|
||||
*
|
||||
* Call this before calling setupGUI() in your application, but after
|
||||
* calling setRichTextSupport().
|
||||
*
|
||||
* The XML file of your KXmlGuiWindow needs to have the action names in
|
||||
* them, so that the actions actually appear in the menu and in the toolbars.
|
||||
*
|
||||
* Below is a list of actions that are created,depending on the supported rich text
|
||||
* subset set by setRichTextSupport(). The list contains action names.
|
||||
* Those names need to be the same in your XML file.
|
||||
*
|
||||
* See the KRichTextWidget::RichTextSupportValues enum documentation for a
|
||||
* detailed explaination of each action.
|
||||
*
|
||||
* <table>
|
||||
* <tr><td><b>XML Name</b></td><td><b>RichTextSupportValues flag</b></td></tr>
|
||||
* <tr><td>format_text_foreground_color</td><td>SupportTextForegroundColor</td></tr>
|
||||
* <tr><td>format_text_background_color</td><td>SupportTextBackgroundColor</td></tr>
|
||||
* <tr><td>format_font_family</td><td>SupportFontFamily</td></tr>
|
||||
* <tr><td>format_font_size</td><td>SupportFontSize</td></tr>
|
||||
* <tr><td>format_text_bold</td><td>SupportBold</td></tr>
|
||||
* <tr><td>format_text_italic</td><td>SupportItalic</td></tr>
|
||||
* <tr><td>format_text_underline</td><td>SupportUnderline</td></tr>
|
||||
* <tr><td>format_text_strikeout</td><td>SupportStrikeOut</td></tr>
|
||||
* <tr><td>format_align_left</td><td>SupportAlignment</td></tr>
|
||||
* <tr><td>format_align_center</td><td>SupportAlignment</td></tr>
|
||||
* <tr><td>format_align_right</td><td>SupportAlignment</td></tr>
|
||||
* <tr><td>format_align_justify</td><td>SupportAlignment</td></tr>
|
||||
* <tr><td>direction_ltr</td><td>SupportDirection</td></tr>
|
||||
* <tr><td>direction_rtl</td><td>SupportDirection</td></tr>
|
||||
* <tr><td>format_list_style</td><td>SupportChangeListStyle</td></tr>
|
||||
* <tr><td>format_list_indent_more</td><td>SupportIndentLists</td></tr>
|
||||
* <tr><td>format_list_indent_less</td><td>SupportDedentLists</td></tr>
|
||||
* <tr><td>insert_horizontal_rule</td><td>SupportRuleLine</td></tr>
|
||||
* <tr><td>manage_link</td><td>SupportHyperlinks</td></tr>
|
||||
* <tr><td>format_painter</td><td>SupportFormatPainting</td></tr>
|
||||
* <tr><td>action_to_plain_text</td><td>SupportToPlainText</td></tr>
|
||||
* <tr><td>format_text_subscript & format_text_superscript</td><td>SupportSuperScriptAndSubScript</td></tr>
|
||||
* </table>
|
||||
*
|
||||
* @param actionCollection the actions will be added to this action collection
|
||||
*/
|
||||
virtual void createActions(KActionCollection *actionCollection);
|
||||
|
||||
/**
|
||||
* @brief Sets the supported rich text subset available.
|
||||
*
|
||||
* The default is KRichTextWidget::FullSupport and will be set in the
|
||||
* constructor.
|
||||
*
|
||||
* You need to call createActions() afterwards.
|
||||
*
|
||||
* @param support The supported subset.
|
||||
*/
|
||||
void setRichTextSupport(const KRichTextWidget::RichTextSupport &support);
|
||||
|
||||
/**
|
||||
* @brief Returns the supported rich text subset available.
|
||||
* @return The supported subset.
|
||||
*/
|
||||
RichTextSupport richTextSupport() const;
|
||||
|
||||
/**
|
||||
* Tells KRichTextWidget to update the state of the actions created by
|
||||
* createActions().
|
||||
* This is normally automatically done, but there might be a few cases where
|
||||
* you'll need to manually call this function.
|
||||
*
|
||||
* Call this function only after calling createActions().
|
||||
*/
|
||||
void updateActionStates();
|
||||
|
||||
public Q_SLOTS:
|
||||
|
||||
/**
|
||||
* Disables or enables all of the actions created by
|
||||
* createActions().
|
||||
* This may be useful in cases where rich text mode may be set on or off.
|
||||
*
|
||||
* @param enabled Whether to enable or disable the actions.
|
||||
*/
|
||||
void setActionsEnabled(bool enabled);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Reimplemented.
|
||||
* Catches mouse release events. Used to know when a selection has been completed.
|
||||
*/
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event);
|
||||
|
||||
|
||||
private:
|
||||
//@cond PRIVATE
|
||||
class Private;
|
||||
friend class Private;
|
||||
Private *const d;
|
||||
Q_PRIVATE_SLOT(d, void _k_setTextForegroundColor())
|
||||
Q_PRIVATE_SLOT(d, void _k_setTextBackgroundColor())
|
||||
Q_PRIVATE_SLOT(d, void _k_manageLink())
|
||||
Q_PRIVATE_SLOT(d, void _k_formatPainter(bool))
|
||||
Q_PRIVATE_SLOT(d, void _k_updateCharFormatActions(const QTextCharFormat &))
|
||||
Q_PRIVATE_SLOT(d, void _k_updateMiscActions())
|
||||
Q_PRIVATE_SLOT(d, void _k_setListStyle(int))
|
||||
//@endcond
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(KRichTextWidget::RichTextSupport)
|
||||
|
||||
#endif
|
||||
|
||||
// kate: space-indent on; indent-width 4; encoding utf-8; replace-tabs on;
|
|
@ -187,16 +187,6 @@ Group=Display (KDE)
|
|||
ToolTip=Line Edit for restricted input (KDE)
|
||||
Group=Input (KDE)
|
||||
|
||||
[KRichTextEdit]
|
||||
IncludeFile=krichtextedit.h
|
||||
ToolTip=Rich Text Editor (KDE)
|
||||
Group=Input (KDE)
|
||||
|
||||
[KRichTextWidget]
|
||||
IncludeFile=krichtextwidget.h
|
||||
ToolTip=Rich Text Widget (KDE)
|
||||
Group=Input (KDE)
|
||||
|
||||
[KRuler]
|
||||
ToolTip=Measuring Ruler Widget (KDE)
|
||||
WhatsThis=A measuring ruler widget as seen in KWord for page widths and heights
|
||||
|
|
|
@ -152,7 +152,7 @@ bool KEMailDialog::setSubject(const QString &subject)
|
|||
|
||||
QString KEMailDialog::message() const
|
||||
{
|
||||
return d->ui.messagetextedit->textOrHtml();
|
||||
return d->ui.messagetextedit->toHtml();
|
||||
}
|
||||
|
||||
bool KEMailDialog::setMessage(const QString &message)
|
||||
|
@ -225,7 +225,7 @@ void KEMailDialog::slotButtonClicked(int button)
|
|||
} else if (d->ui.subjectlineedit->text().isEmpty()) {
|
||||
KMessageBox::error(this, i18n("No subject specified"));
|
||||
return;
|
||||
} else if (d->ui.messagetextedit->textOrHtml().isEmpty()) {
|
||||
} else if (d->ui.messagetextedit->toHtml().isEmpty()) {
|
||||
KMessageBox::error(this, i18n("No message specified"));
|
||||
return;
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ void KEMailDialog::slotButtonClicked(int button)
|
|||
d->sendMail(
|
||||
d->ui.recipientslistwidget->items(),
|
||||
d->ui.subjectlineedit->text(),
|
||||
d->ui.messagetextedit->textOrHtml(),
|
||||
d->ui.messagetextedit->toHtml(),
|
||||
d->ui.attachlistwidget->items()
|
||||
);
|
||||
return;
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="KRichTextEdit" name="messagetextedit"/>
|
||||
<widget class="KTextEdit" name="messagetextedit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
@ -137,23 +137,23 @@
|
|||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>KRichTextEdit</class>
|
||||
<extends></extends>
|
||||
<header>krichtextedit.h</header>
|
||||
<class>KTextEdit</class>
|
||||
<extends>QTextEdit</extends>
|
||||
<header>ktextedit.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>KLineEdit</class>
|
||||
<extends></extends>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>klineedit.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>KUrlLabel</class>
|
||||
<extends></extends>
|
||||
<extends>QLabel</extends>
|
||||
<header>kurllabel.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>KEditListWidget</class>
|
||||
<extends></extends>
|
||||
<extends>QWidget</extends>
|
||||
<header>keditlistwidget.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
|
|
Loading…
Add table
Reference in a new issue