[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdepimlibs] /: Now we can insert html directly
From: Montel Laurent <montel () kde ! org>
Date: 2012-07-17 11:04:39
Message-ID: 20120717110439.E31FBA6094 () git ! kde ! org
[Download RAW message or body]
Git commit ad40d24c1c742894950654e4b96401eca0f62301 by Montel Laurent.
Committed on 17/07/2012 at 13:04.
Pushed by mlaurent into branch 'master'.
Now we can insert html directly
M +1 -1 CMakeLists.txt
M +1 -0 kpimidentities/signatureconfigurator.cpp
M +1 -0 kpimtextedit/CMakeLists.txt
A +64 -0 kpimtextedit/inserthtmldialog.cpp [License: GPL (v2)]
A +37 -0 kpimtextedit/inserthtmldialog.h [License: GPL (v2)]
M +44 -1 kpimtextedit/textedit.cpp
M +8 -0 kpimtextedit/textedit.h
http://commits.kde.org/kdepimlibs/ad40d24c1c742894950654e4b96401eca0f62301
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a2019ab..44c1686 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,7 +7,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
############### The kdepimlibs version (used e.g. in KdepimLibsConfig.cmake) \
############### set(KDEPIMLIBS_VERSION_MAJOR 4)
set(KDEPIMLIBS_VERSION_MINOR 9)
-set(KDEPIMLIBS_VERSION_PATCH 51)
+set(KDEPIMLIBS_VERSION_PATCH 52)
set(KDEPIMLIBS_VERSION \
${KDEPIMLIBS_VERSION_MAJOR}.${KDEPIMLIBS_VERSION_MINOR}.${KDEPIMLIBS_VERSION_PATCH}) \
diff --git a/kpimidentities/signatureconfigurator.cpp \
b/kpimidentities/signatureconfigurator.cpp index bbd2a6e..496616f 100644
--- a/kpimidentities/signatureconfigurator.cpp
+++ b/kpimidentities/signatureconfigurator.cpp
@@ -156,6 +156,7 @@ void SignatureConfigurator::Private::init()
q->mTextEdit = new KPIMTextEdit::TextEdit( q );
static_cast<KPIMTextEdit::TextEdit*>( q->mTextEdit )->enableImageActions();
+ static_cast<KPIMTextEdit::TextEdit*>( q->mTextEdit )->enableInsertHtmlActions();
page_vlay->addWidget( q->mTextEdit, 2 );
q->mTextEdit->setWhatsThis( i18n("Use this field to enter an arbitrary static \
signature.")); // exclude SupportToPlainText.
diff --git a/kpimtextedit/CMakeLists.txt b/kpimtextedit/CMakeLists.txt
index 62e9d95..6ad6ba8 100644
--- a/kpimtextedit/CMakeLists.txt
+++ b/kpimtextedit/CMakeLists.txt
@@ -10,6 +10,7 @@ set(kpimtextedit_lib_srcs
textutils.cpp
emoticontexteditaction.cpp
emoticontexteditselector.cpp
+ inserthtmldialog.cpp
)
kde4_add_library(kpimtextedit ${LIBRARY_TYPE} ${kpimtextedit_lib_srcs})
diff --git a/kpimtextedit/inserthtmldialog.cpp b/kpimtextedit/inserthtmldialog.cpp
new file mode 100644
index 0000000..85fe616
--- /dev/null
+++ b/kpimtextedit/inserthtmldialog.cpp
@@ -0,0 +1,64 @@
+/*
+ Copyright (c) 2012 Montel Laurent <montel@kde.org>
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License, version 2, as
+ published by the Free Software Foundation.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "inserthtmldialog.h"
+#include <KLocale>
+
+#include <KTextEdit>
+#include <QVBoxLayout>
+#include <QLabel>
+using namespace KPIMTextEdit;
+
+class InsertHtmlDialog::InsertHtmlDialogPrivate
+{
+public:
+ InsertHtmlDialogPrivate(InsertHtmlDialog *qq)
+ :q(qq)
+ {
+ q->setCaption( i18n("Insert HTML") );
+ q->setButtons( Ok|Cancel );
+ q->setButtonText(KDialog::Ok,i18n("Insert"));
+ QWidget *page = new QWidget(q );
+ q->setMainWidget( page );
+ QVBoxLayout *lay = new QVBoxLayout(page);
+ editor = new KTextEdit;
+ editor->setAcceptRichText(false);
+ lay->addWidget(editor);
+ QLabel *label = new QLabel(i18n("Example: <i> Hello word </i>"));
+ label->setTextFormat(Qt::PlainText);
+ lay->addWidget(label);
+ }
+ KTextEdit *editor;
+ InsertHtmlDialog *q;
+};
+
+InsertHtmlDialog::InsertHtmlDialog(QWidget *parent)
+ : KDialog(parent), d(new InsertHtmlDialogPrivate(this))
+{
+}
+
+InsertHtmlDialog::~InsertHtmlDialog()
+{
+ delete d;
+}
+
+QString InsertHtmlDialog::html() const
+{
+ return d->editor->toPlainText();
+}
+
+#include "inserthtmldialog.moc"
diff --git a/kpimtextedit/inserthtmldialog.h b/kpimtextedit/inserthtmldialog.h
new file mode 100644
index 0000000..7d7b6f7
--- /dev/null
+++ b/kpimtextedit/inserthtmldialog.h
@@ -0,0 +1,37 @@
+/*
+ Copyright (c) 2012 Montel Laurent <montel@kde.org>
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License, version 2, as
+ published by the Free Software Foundation.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef INSERTHTMLDIALOG_H
+#define INSERTHTMLDIALOG_H
+
+#include <KDialog>
+namespace KPIMTextEdit {
+
+class InsertHtmlDialog : public KDialog
+{
+public:
+ explicit InsertHtmlDialog(QWidget *parent = 0);
+ ~InsertHtmlDialog();
+ QString html() const;
+private:
+ class InsertHtmlDialogPrivate;
+ InsertHtmlDialogPrivate *d;
+};
+
+}
+
+#endif // INSERTHTMLDIALOG_H
diff --git a/kpimtextedit/textedit.cpp b/kpimtextedit/textedit.cpp
index a2dd333..394a11d 100644
--- a/kpimtextedit/textedit.cpp
+++ b/kpimtextedit/textedit.cpp
@@ -23,6 +23,7 @@
#include "emailquotehighlighter.h"
#include "emoticontexteditaction.h"
+#include "inserthtmldialog.h"
#include <kmime/kmime_codecs.h>
@@ -55,9 +56,11 @@ class TextEditPrivate
TextEditPrivate( TextEdit *parent )
: actionAddImage( 0 ),
actionDeleteLine( 0 ),
+ actionInsertHtml( 0 ),
q( parent ),
imageSupportEnabled( false ),
- emoticonSupportEnabled( false )
+ emoticonSupportEnabled( false ),
+ insertHtmlSupportEnabled( false )
{
}
@@ -96,6 +99,9 @@ class TextEditPrivate
void _k_slotDeleteLine();
void _k_slotAddEmoticon(const QString&);
+
+ void _k_slotInsertHtml();
+
/// The action that triggers _k_slotAddImage()
KAction *actionAddImage;
@@ -103,6 +109,7 @@ class TextEditPrivate
KAction *actionDeleteLine;
EmoticonTextEditAction *actionAddEmoticon;
+ KAction *actionInsertHtml;
/// The parent class
TextEdit *q;
@@ -110,6 +117,9 @@ class TextEditPrivate
bool imageSupportEnabled;
bool emoticonSupportEnabled;
+
+ bool insertHtmlSupportEnabled;
+
/**
* The names of embedded images.
* Used to easily obtain the names of the images.
@@ -391,6 +401,13 @@ void TextEdit::createActions( KActionCollection \
*actionCollection )
connect( d->actionAddEmoticon, SIGNAL(emoticonActivated(QString)), \
SLOT(_k_slotAddEmoticon(QString)) ); }
+ if ( d->insertHtmlSupportEnabled ) {
+ d->actionInsertHtml = new KAction( i18n( "Insert HTML" ), this );
+ actionCollection->addAction( QLatin1String( "insert_html" ), d->actionInsertHtml \
); + connect( d->actionInsertHtml, SIGNAL(triggered(bool)), \
SLOT(_k_slotInsertHtml()) ); + }
+
+
d->actionDeleteLine = new KAction( i18n( "Delete Line" ), this );
d->actionDeleteLine->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_K ) );
actionCollection->addAction( QLatin1String( "delete_line" ), d->actionDeleteLine \
); @@ -550,6 +567,22 @@ void TextEditPrivate::_k_slotAddEmoticon( const QString& \
text) cursor.insertText( text );
}
+void TextEditPrivate::_k_slotInsertHtml()
+{
+ if(q->textMode() == KRichTextEdit::Rich ) {
+ InsertHtmlDialog *dialog = new InsertHtmlDialog(q);
+ if(dialog->exec()) {
+ const QString str = dialog->html();
+ if(!str.isEmpty()) {
+ QTextCursor cursor = q->textCursor();
+ cursor.insertHtml( str );
+ }
+ }
+ delete dialog;
+ }
+}
+
+
void TextEditPrivate::_k_slotAddImage()
{
QPointer<KFileDialog> fdlg = new KFileDialog( QString(), QString(), q );
@@ -586,6 +619,16 @@ bool KPIMTextEdit::TextEdit::isEnableEmoticonActions() const
return d->emoticonSupportEnabled;
}
+void KPIMTextEdit::TextEdit::enableInsertHtmlActions()
+{
+ d->insertHtmlSupportEnabled = true;
+}
+
+bool KPIMTextEdit::TextEdit::isEnableInsertHtmlActions() const
+{
+ return d->insertHtmlSupportEnabled;
+}
+
QByteArray KPIMTextEdit::TextEdit::imageNamesToContentIds(
const QByteArray &htmlBody, const KPIMTextEdit::ImageList &imageList )
diff --git a/kpimtextedit/textedit.h b/kpimtextedit/textedit.h
index 3603c44..dfdd01b 100644
--- a/kpimtextedit/textedit.h
+++ b/kpimtextedit/textedit.h
@@ -125,6 +125,8 @@ class KPIMTEXTEDIT_EXPORT TextEdit : public KRichTextWidget,
* Don't call this if you don't want to support emoticons actions.
*/
void enableEmoticonActions();
+
+ void enableInsertHtmlActions();
/**
* Destructor
*/
@@ -283,6 +285,11 @@ class KPIMTEXTEDIT_EXPORT TextEdit : public KRichTextWidget,
*/
void insertImage( const QImage &image, const QFileInfo &info );
+ /**
+ * @since 4.10
+ */
+ bool isEnableInsertHtmlActions() const;
+
protected:
/**
@@ -338,6 +345,7 @@ class KPIMTEXTEDIT_EXPORT TextEdit : public KRichTextWidget,
Q_PRIVATE_SLOT( d, void _k_slotAddImage() )
Q_PRIVATE_SLOT( d, void _k_slotDeleteLine() )
Q_PRIVATE_SLOT( d, void _k_slotAddEmoticon(const QString &) )
+ Q_PRIVATE_SLOT( d, void _k_slotInsertHtml() )
};
} // namespace
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic