[qet] [2095] Delete htmleditor, add ritchEdit

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 2095
Author:   cfdev
Date:     2013-04-09 13:26:53 +0200 (Tue, 09 Apr 2013)
Log Message:
-----------
Delete htmleditor, add ritchEdit

Modified Paths:
--------------
    trunk/qelectrotech.pro
    trunk/sources/diagramtextitem.cpp
    trunk/sources/diagramview.cpp

Added Paths:
-----------
    trunk/sources/richtext/
    trunk/sources/richtext/README.txt
    trunk/sources/richtext/addlinkdialog.ui
    trunk/sources/richtext/richtexteditor.cpp
    trunk/sources/richtext/richtexteditor_p.h
    trunk/sources/richtext/ui_addlinkdialog.h

Removed Paths:
-------------
    trunk/sources/htmleditor/

Modified: trunk/qelectrotech.pro
===================================================================
--- trunk/qelectrotech.pro	2013-04-08 20:06:36 UTC (rev 2094)
+++ trunk/qelectrotech.pro	2013-04-09 11:26:53 UTC (rev 2095)
@@ -63,11 +63,11 @@
 INCLUDEPATH += sources sources/editor sources/titleblock
 
 # Fichiers sources
-HEADERS += sources/*.h   sources/ui/*.h   sources/editor/*.h   sources/titleblock/*.h   sources/htmleditor/*.h
-SOURCES += sources/*.cpp sources/editor/*.cpp sources/titleblock/*.cpp sources/htmleditor/*.cpp
+HEADERS += sources/*.h   sources/ui/*.h   sources/editor/*.h   sources/titleblock/*.h  sources/richtext/*.h
+SOURCES += sources/*.cpp sources/editor/*.cpp sources/titleblock/*.cpp sources/richtext/*.cpp
 
 # Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt
-RESOURCES += qelectrotech.qrc  sources/htmleditor/htmleditor.qrc
+RESOURCES += qelectrotech.qrc
 
 # Liste des ressources Windows
 RC_FILE = ico/windows_icon/qelectrotech.rc
@@ -76,10 +76,10 @@
 TRANSLATIONS += lang/qet_en.ts lang/qet_es.ts lang/qet_fr.ts lang/qet_ru.ts lang/qet_pt.ts lang/qet_cs.ts lang/qet_pl.ts lang/qet_de.ts lang/qet_ro.ts lang/qet_it.ts
 
 # Modules Qt utilises par l'application
-QT += xml svg network sql webkit
+QT += xml svg network sql
 
 # UI DESIGNER FILES AND GENERATION SOURCES FILES
-FORMS = sources/htmleditor/htmleditor.ui sources/htmleditor/inserthtmldialog.ui
+FORMS = sources/richtext/addlinkdialog.ui
 UI_SOURCES_DIR = sources/ui/
 UI_HEADERS_DIR = sources/ui/
 

Modified: trunk/sources/diagramtextitem.cpp
===================================================================
--- trunk/sources/diagramtextitem.cpp	2013-04-08 20:06:36 UTC (rev 2094)
+++ trunk/sources/diagramtextitem.cpp	2013-04-09 11:26:53 UTC (rev 2095)
@@ -20,7 +20,8 @@
 #include "qet.h"
 #include "qetapp.h"
 
-#include "htmleditor/htmleditor.h"
+#include "richtext/richtexteditor_p.h"
+
 /**
 	Constructeur
 	@param parent Le QGraphicsItem parent du champ de texte
@@ -313,13 +314,11 @@
  */
 void DiagramTextItem::edit() {
 	//Open the HtmlEditor
-	HtmlEditor *editor = new HtmlEditor();
+	qdesigner_internal::RichTextEditorDialog *editor = new qdesigner_internal::RichTextEditorDialog();
 	// connect the in/out
 	connect(editor, SIGNAL(applyEditText(const QString &)), this, SLOT(setHtmlText(const QString &)));
 	// load the Html txt
-	editor->loadHtml( toHtml() );
-	// set the minimum controls
-	editor->setSimpleDisplay(true);
+	editor->setText( toHtml() );
 	// show
 	editor->show();
 }

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2013-04-08 20:06:36 UTC (rev 2094)
+++ trunk/sources/diagramview.cpp	2013-04-09 11:26:53 UTC (rev 2095)
@@ -38,7 +38,6 @@
 #include "qetmessagebox.h"
 #include "qtextorientationspinboxwidget.h"
 
-#include "htmleditor/htmleditor.h"
 
 /**
 	Constructeur

Added: trunk/sources/richtext/README.txt
===================================================================
--- trunk/sources/richtext/README.txt	                        (rev 0)
+++ trunk/sources/richtext/README.txt	2013-04-09 11:26:53 UTC (rev 2095)
@@ -0,0 +1 @@
+Example running richtext through XSLT

Added: trunk/sources/richtext/addlinkdialog.ui
===================================================================
--- trunk/sources/richtext/addlinkdialog.ui	                        (rev 0)
+++ trunk/sources/richtext/addlinkdialog.ui	2013-04-09 11:26:53 UTC (rev 2095)
@@ -0,0 +1,112 @@
+<ui version="4.0" >
+ <class>AddLinkDialog</class>
+ <widget class="QDialog" name="AddLinkDialog" >
+  <property name="windowTitle" >
+   <string>Insert Link</string>
+  </property>
+  <property name="sizeGripEnabled" >
+   <bool>false</bool>
+  </property>
+  <property name="modal" >
+   <bool>true</bool>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout" >
+   <item>
+    <layout class="QFormLayout" >
+     <item row="0" column="0" >
+      <widget class="QLabel" name="label" >
+       <property name="text" >
+        <string>Title:</string>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="1" >
+      <widget class="QLineEdit" name="titleInput" >
+       <property name="minimumSize" >
+        <size>
+         <width>337</width>
+         <height>0</height>
+        </size>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="0" >
+      <widget class="QLabel" name="label_2" >
+       <property name="text" >
+        <string>URL:</string>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="1" >
+      <widget class="QLineEdit" name="urlInput" />
+     </item>
+    </layout>
+   </item>
+   <item>
+    <spacer name="verticalSpacer" >
+     <property name="orientation" >
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0" >
+      <size>
+       <width>0</width>
+       <height>0</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item>
+    <widget class="Line" name="line" >
+     <property name="orientation" >
+      <enum>Qt::Horizontal</enum>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox" >
+     <property name="orientation" >
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons" >
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>AddLinkDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>AddLinkDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>

Added: trunk/sources/richtext/richtexteditor.cpp
===================================================================
--- trunk/sources/richtext/richtexteditor.cpp	                        (rev 0)
+++ trunk/sources/richtext/richtexteditor.cpp	2013-04-09 11:26:53 UTC (rev 2095)
@@ -0,0 +1,797 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@xxxxxxxxx)
+**
+** This file is part of the Qt Designer of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights.  These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@xxxxxxxxx.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/**
+	Integration : QElectroTech Team
+	Changelog:
+	- 09/04/2013 : Start integration...Compilation and object creation are successful
+*/
+
+#include "richtexteditor_p.h"
+#include "ui_addlinkdialog.h"
+
+#include <QtDesigner/QDesignerFormEditorInterface>
+
+#include <QtCore/QList>
+#include <QtCore/QMap>
+#include <QtCore/QPointer>
+#include <QtCore/QProcess>
+#include <QtCore/QTemporaryFile>
+#include <QtCore/QDir>
+
+#include <QtGui/QAction>
+#include <QtGui/QColorDialog>
+#include <QtGui/QComboBox>
+#include <QtGui/QFontDatabase>
+#include <QtGui/QTextCursor>
+#include <QtGui/QPainter>
+#include <QtGui/QIcon>
+#include <QtGui/QMenu>
+#include <QtGui/QMoveEvent>
+#include <QtGui/QTabWidget>
+#include <QtGui/QTextDocument>
+#include <QtGui/QTextBlock>
+#include <QtGui/QToolBar>
+#include <QtGui/QToolButton>
+#include <QtGui/QVBoxLayout>
+#include <QtGui/QHBoxLayout>
+#include <QtGui/QPushButton>
+#include <QtGui/QDialogButtonBox>
+
+QT_BEGIN_NAMESPACE
+
+//static const char *RichTextDialogC = "RichTextDialog";
+//static const char *Geometry = "Geometry";
+
+namespace qdesigner_internal {
+
+class RichTextEditor : public QTextEdit
+{
+    Q_OBJECT
+public:
+    RichTextEditor(QWidget *parent = 0);
+    void setDefaultFont(const QFont &font);
+
+    QToolBar *createToolBar(QWidget *parent = 0);
+
+public slots:
+    void setFontBold(bool b);
+    void setFontPointSize(double);
+    void setText(const QString &text);
+    QString text(Qt::TextFormat format) const;
+
+signals:
+    void stateChanged();
+};
+
+class AddLinkDialog : public QDialog
+{
+    Q_OBJECT
+
+public:
+    AddLinkDialog(RichTextEditor *editor, QWidget *parent = 0);
+    ~AddLinkDialog();
+
+    int showDialog();
+
+public slots:
+    void accept();
+
+private:
+    RichTextEditor *m_editor;
+    Ui::AddLinkDialog *m_ui;
+};
+
+AddLinkDialog::AddLinkDialog(RichTextEditor *editor, QWidget *parent) :
+    QDialog(parent),
+    m_ui(new Ui::AddLinkDialog)
+{
+    m_ui->setupUi(this);
+
+    setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
+
+    m_editor = editor;
+}
+
+AddLinkDialog::~AddLinkDialog()
+{
+    delete m_ui;
+}
+
+int AddLinkDialog::showDialog()
+{
+    // Set initial focus
+    const QTextCursor cursor = m_editor->textCursor();
+    if (cursor.hasSelection()) {
+        m_ui->titleInput->setText(cursor.selectedText());
+        m_ui->urlInput->setFocus();
+    } else {
+        m_ui->titleInput->setFocus();
+    }
+
+    return exec();
+}
+
+void AddLinkDialog::accept()
+{
+    const QString title = m_ui->titleInput->text();
+    const QString url = m_ui->urlInput->text();
+
+    if (!title.isEmpty()) {
+        QString html = QLatin1String("<a href=\"");
+        html += url;
+        html += QLatin1String("\">");
+        html += title;
+        html += QLatin1String("</a>");
+
+        m_editor->insertHtml(html);
+    }
+
+    m_ui->titleInput->clear();
+    m_ui->urlInput->clear();
+
+    QDialog::accept();
+}
+
+class HtmlTextEdit : public QTextEdit
+{
+    Q_OBJECT
+
+public:
+    HtmlTextEdit(QWidget *parent = 0)
+        : QTextEdit(parent)
+    {}
+
+    void contextMenuEvent(QContextMenuEvent *event);
+
+private slots:
+    void actionTriggered(QAction *action);
+};
+
+void HtmlTextEdit::contextMenuEvent(QContextMenuEvent *event)
+{
+    QMenu *menu = createStandardContextMenu();
+    QMenu *htmlMenu = new QMenu(tr("Insert HTML entity"), menu);
+
+    typedef struct {
+        const char *text;
+        const char *entity;
+    } Entry;
+
+    const Entry entries[] = {
+        { "&&amp; (&&)", "&amp;" },
+        { "&&nbsp;", "&nbsp;" },
+        { "&&lt; (<)", "&lt;" },
+        { "&&gt; (>)", "&gt;" },
+        { "&&copy; (Copyright)", "&copy;" },
+        { "&&reg; (Trade Mark)", "&reg;" },
+    };
+
+    for (int i = 0; i < 6; ++i) {
+        QAction *entityAction = new QAction(QLatin1String(entries[i].text),
+                                            htmlMenu);
+        entityAction->setData(QLatin1String(entries[i].entity));
+        htmlMenu->addAction(entityAction);
+    }
+
+    menu->addMenu(htmlMenu);
+    connect(htmlMenu, SIGNAL(triggered(QAction*)),
+                      SLOT(actionTriggered(QAction*)));
+    menu->exec(event->globalPos());
+    delete menu;
+}
+
+void HtmlTextEdit::actionTriggered(QAction *action)
+{
+    insertPlainText(action->data().toString());
+}
+
+class ColorAction : public QAction
+{
+    Q_OBJECT
+
+public:
+    ColorAction(QObject *parent);
+
+    const QColor& color() const { return m_color; }
+    void setColor(const QColor &color);
+
+signals:
+    void colorChanged(const QColor &color);
+
+private slots:
+    void chooseColor();
+
+private:
+    QColor m_color;
+};
+
+ColorAction::ColorAction(QObject *parent):
+    QAction(parent)
+{
+    setText(tr("Text Color"));
+    setColor(Qt::black);
+    connect(this, SIGNAL(triggered()), this, SLOT(chooseColor()));
+}
+
+void ColorAction::setColor(const QColor &color)
+{
+    if (color == m_color)
+        return;
+    m_color = color;
+    QPixmap pix(24, 24);
+    QPainter painter(&pix);
+    painter.setRenderHint(QPainter::Antialiasing, false);
+    painter.fillRect(pix.rect(), m_color);
+    painter.setPen(m_color.darker());
+    painter.drawRect(pix.rect().adjusted(0, 0, -1, -1));
+    setIcon(pix);
+}
+
+void ColorAction::chooseColor()
+{
+    const QColor col = QColorDialog::getColor(m_color, 0);
+    if (col.isValid() && col != m_color) {
+        setColor(col);
+        emit colorChanged(m_color);
+    }
+}
+
+class RichTextEditorToolBar : public QToolBar
+{
+    Q_OBJECT
+public:
+    RichTextEditorToolBar(RichTextEditor *editor,
+                          QWidget *parent = 0);
+
+public slots:
+    void updateActions();
+
+private slots:
+    void alignmentActionTriggered(QAction *action);
+    void sizeInputActivated(const QString &size);
+    void colorChanged(const QColor &color);
+    void setVAlignSuper(bool super);
+    void setVAlignSub(bool sub);
+    void insertLink();
+    void insertImage();
+    void runXmlPatterns();
+
+private:
+    QAction *m_bold_action;
+    QAction *m_italic_action;
+    QAction *m_underline_action;
+    QAction *m_valign_sup_action;
+    QAction *m_valign_sub_action;
+    QAction *m_align_left_action;
+    QAction *m_align_center_action;
+    QAction *m_align_right_action;
+    QAction *m_align_justify_action;
+    QAction *m_link_action;
+    QAction *m_image_action;
+    QAction *m_xmlPatterns;
+    ColorAction *m_color_action;
+    QComboBox *m_font_size_input;
+
+    QPointer<RichTextEditor> m_editor;
+};
+
+static QAction *createCheckableAction(const QIcon &icon, const QString &text,
+                                      QObject *receiver, const char *slot,
+                                      QObject *parent = 0)
+{
+    QAction *result = new QAction(parent);
+    result->setIcon(icon);
+    result->setText(text);
+    result->setCheckable(true);
+    result->setChecked(false);
+    if (slot)
+        QObject::connect(result, SIGNAL(triggered(bool)), receiver, slot);
+    return result;
+}
+
+RichTextEditorToolBar::RichTextEditorToolBar(RichTextEditor *editor,
+                                             QWidget *parent) :
+    QToolBar(parent),
+    m_link_action(new QAction(this)),
+    m_image_action(new QAction(this)),
+    m_color_action(new ColorAction(this)),
+    m_font_size_input(new QComboBox),
+    m_editor(editor)
+{
+
+    m_xmlPatterns = new QAction("Run XMLPatterns", this);
+    connect(m_xmlPatterns, SIGNAL(triggered()), this, SLOT(runXmlPatterns()));
+    addAction(m_xmlPatterns);
+	m_xmlPatterns -> setVisible( false );
+	
+    // Font size combo box
+    m_font_size_input->setEditable(false);
+    const QList<int> font_sizes = QFontDatabase::standardSizes();
+    foreach (int font_size, font_sizes)
+        m_font_size_input->addItem(QString::number(font_size));
+
+    connect(m_font_size_input, SIGNAL(activated(QString)),
+            this, SLOT(sizeInputActivated(QString)));
+    addWidget(m_font_size_input);
+
+    addSeparator();
+
+    // Bold, italic and underline buttons
+
+    m_bold_action = createCheckableAction(QIcon(),
+            tr("Bold"), editor, SLOT(setFontBold(bool)), this);
+    m_bold_action->setShortcut(tr("CTRL+B"));
+    addAction(m_bold_action);
+
+    m_italic_action = createCheckableAction(
+            QIcon(),
+            tr("Italic"), editor, SLOT(setFontItalic(bool)), this);
+    m_italic_action->setShortcut(tr("CTRL+I"));
+    addAction(m_italic_action);
+
+    m_underline_action = createCheckableAction(
+            QIcon(),
+            tr("Underline"), editor, SLOT(setFontUnderline(bool)), this);
+    m_underline_action->setShortcut(tr("CTRL+U"));
+    addAction(m_underline_action);
+
+    addSeparator();
+
+    // Left, center, right and justified alignment buttons
+
+    QActionGroup *alignment_group = new QActionGroup(this);
+    connect(alignment_group, SIGNAL(triggered(QAction*)),
+                             SLOT(alignmentActionTriggered(QAction*)));
+
+    m_align_left_action = createCheckableAction(
+            QIcon(),
+            tr("Left Align"), editor, 0, alignment_group);
+    addAction(m_align_left_action);
+
+    m_align_center_action = createCheckableAction(
+            QIcon(),
+            tr("Center"), editor, 0, alignment_group);
+    addAction(m_align_center_action);
+
+    m_align_right_action = createCheckableAction(
+            QIcon(),
+            tr("Right Align"), editor, 0, alignment_group);
+    addAction(m_align_right_action);
+
+    m_align_justify_action = createCheckableAction(
+            QIcon(),
+            tr("Justify"), editor, 0, alignment_group);
+    addAction(m_align_justify_action);
+
+    addSeparator();
+
+    // Superscript and subscript buttons
+
+    m_valign_sup_action = createCheckableAction(
+            QIcon(),
+            tr("Superscript"),
+            this, SLOT(setVAlignSuper(bool)), this);
+    addAction(m_valign_sup_action);
+
+    m_valign_sub_action = createCheckableAction(
+            QIcon(),
+            tr("Subscript"),
+            this, SLOT(setVAlignSub(bool)), this);
+    addAction(m_valign_sub_action);
+	
+	m_valign_sup_action -> setVisible( false );
+	m_valign_sub_action -> setVisible( false );
+
+/*    addSeparator();
+
+    // Insert hyperlink and image buttons
+
+    m_link_action->setText(tr("Insert &Link"));
+    connect(m_link_action, SIGNAL(triggered()), SLOT(insertLink()));
+    addAction(m_link_action);
+
+    m_image_action->setText(tr("Insert &Image"));
+    connect(m_image_action, SIGNAL(triggered()), SLOT(insertImage()));
+    addAction(m_image_action);
+
+    addSeparator();*/
+
+    // Text color button
+    connect(m_color_action, SIGNAL(colorChanged(QColor)),
+            this, SLOT(colorChanged(QColor)));
+    addAction(m_color_action);
+
+    connect(editor, SIGNAL(textChanged()), this, SLOT(updateActions()));
+    connect(editor, SIGNAL(stateChanged()), this, SLOT(updateActions()));
+
+    updateActions();
+}
+
+void RichTextEditorToolBar::alignmentActionTriggered(QAction *action)
+{
+    Qt::Alignment new_alignment;
+
+    if (action == m_align_left_action) {
+        new_alignment = Qt::AlignLeft;
+    } else if (action == m_align_center_action) {
+        new_alignment = Qt::AlignCenter;
+    } else if (action == m_align_right_action) {
+        new_alignment = Qt::AlignRight;
+    } else {
+        new_alignment = Qt::AlignJustify;
+    }
+
+    m_editor->setAlignment(new_alignment);
+}
+
+QString runXSLT(const QString &t)
+{
+    QString pattern = QDir::tempPath();
+    if (!pattern.endsWith('/'))
+        pattern += '/';
+    pattern += "qt_tempXXXXXX.html";
+    QTemporaryFile tf(pattern);
+    if (!tf.open())
+        return QLatin1String("Open failure");
+    const QString tfName = tf.fileName();
+    tf.write(t.toUtf8());
+    tf.close();
+    QProcess p;
+    QStringList args;
+    args << "tohtml.xsl" << tfName;
+    p.start("xmlpatterns",args);
+    if (!p.waitForStarted() || !p.waitForFinished())
+        return QLatin1String("Run failure");
+    const QByteArray output = p.exitStatus() == QProcess::NormalExit &&
+                           p.exitCode() == 0 ?
+                           p.readAllStandardOutput() :
+                           p.readAllStandardError();
+    return QString::fromUtf8(output);
+}
+
+
+void RichTextEditorToolBar::runXmlPatterns()
+{
+    qWarning("%s", qPrintable(runXSLT(m_editor->text(Qt::RichText))));
+}
+
+void RichTextEditorToolBar::colorChanged(const QColor &color)
+{
+    m_editor->setTextColor(color);
+    m_editor->setFocus();
+}
+
+void RichTextEditorToolBar::sizeInputActivated(const QString &size)
+{
+    bool ok;
+    int i = size.toInt(&ok);
+    if (!ok)
+        return;
+
+    m_editor->setFontPointSize(i);
+    m_editor->setFocus();
+}
+
+void RichTextEditorToolBar::setVAlignSuper(bool super)
+{
+    const QTextCharFormat::VerticalAlignment align = super ?
+        QTextCharFormat::AlignSuperScript : QTextCharFormat::AlignNormal;
+
+    QTextCharFormat charFormat = m_editor->currentCharFormat();
+    charFormat.setVerticalAlignment(align);
+    m_editor->setCurrentCharFormat(charFormat);
+
+    m_valign_sub_action->setChecked(false);
+}
+
+void RichTextEditorToolBar::setVAlignSub(bool sub)
+{
+    const QTextCharFormat::VerticalAlignment align = sub ?
+        QTextCharFormat::AlignSubScript : QTextCharFormat::AlignNormal;
+
+    QTextCharFormat charFormat = m_editor->currentCharFormat();
+    charFormat.setVerticalAlignment(align);
+    m_editor->setCurrentCharFormat(charFormat);
+
+    m_valign_sup_action->setChecked(false);
+}
+
+void RichTextEditorToolBar::insertLink()
+{
+    AddLinkDialog linkDialog(m_editor, this);
+    linkDialog.showDialog();
+    m_editor->setFocus();
+}
+
+void RichTextEditorToolBar::insertImage()
+{
+#ifdef hip
+    const QString path = IconSelector::choosePixmapResource(m_core, m_core->resourceModel(), QString(), this);
+    if (!path.isEmpty())
+        m_editor->insertHtml(QLatin1String("<img src=\"") + path + QLatin1String("\"/>"));
+#endif
+}
+
+void RichTextEditorToolBar::updateActions()
+{
+    if (m_editor == 0) {
+        setEnabled(false);
+        return;
+    }
+
+    const Qt::Alignment alignment = m_editor->alignment();
+    const QTextCursor cursor = m_editor->textCursor();
+    const QTextCharFormat charFormat = cursor.charFormat();
+    const QFont font = charFormat.font();
+    const QTextCharFormat::VerticalAlignment valign =
+        charFormat.verticalAlignment();
+    const bool superScript = valign == QTextCharFormat::AlignSuperScript;
+    const bool subScript = valign == QTextCharFormat::AlignSubScript;
+
+    if (alignment & Qt::AlignLeft) {
+        m_align_left_action->setChecked(true);
+    } else if (alignment & Qt::AlignRight) {
+        m_align_right_action->setChecked(true);
+    } else if (alignment & Qt::AlignHCenter) {
+        m_align_center_action->setChecked(true);
+    } else {
+        m_align_justify_action->setChecked(true);
+    }
+
+    m_bold_action->setChecked(font.bold());
+    m_italic_action->setChecked(font.italic());
+    m_underline_action->setChecked(font.underline());
+    m_valign_sup_action->setChecked(superScript);
+    m_valign_sub_action->setChecked(subScript);
+
+    const int size = font.pointSize();
+    const int idx = m_font_size_input->findText(QString::number(size));
+    if (idx != -1)
+        m_font_size_input->setCurrentIndex(idx);
+
+    m_color_action->setColor(m_editor->textColor());
+}
+
+RichTextEditor::RichTextEditor(QWidget *parent)
+    : QTextEdit(parent)
+{
+    connect(this, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
+            this, SIGNAL(stateChanged()));
+    connect(this, SIGNAL(cursorPositionChanged()),
+            this, SIGNAL(stateChanged()));
+}
+
+QToolBar *RichTextEditor::createToolBar(QWidget *parent)
+{
+    return new RichTextEditorToolBar(this, parent);
+}
+
+void RichTextEditor::setFontBold(bool b)
+{
+    if (b)
+        setFontWeight(QFont::Bold);
+    else
+        setFontWeight(QFont::Normal);
+}
+
+void RichTextEditor::setFontPointSize(double d)
+{
+    QTextEdit::setFontPointSize(qreal(d));
+}
+
+void RichTextEditor::setText(const QString &text)
+{
+    if (Qt::mightBeRichText(text))
+        setHtml(text);
+    else
+        setPlainText(text);
+}
+
+void RichTextEditor::setDefaultFont(const QFont &font)
+{
+    document()->setDefaultFont(font);
+    if (font.pointSize() > 0)
+        setFontPointSize(font.pointSize());
+    else
+        setFontPointSize(QFontInfo(font).pointSize());
+    emit textChanged();
+}
+
+QString RichTextEditor::text(Qt::TextFormat format) const
+{
+    switch (format) {
+    case Qt::LogText:
+    case Qt::PlainText:
+        return toPlainText();
+    case Qt::RichText:
+        return toHtml();
+    case Qt::AutoText:
+        break;
+    }
+    const QString html = toHtml();
+    const QString plain = toPlainText();
+    QTextEdit tester;
+    tester.setPlainText(plain);
+    return tester.toHtml() == html ? plain : html;
+}
+
+RichTextEditorDialog::RichTextEditorDialog(QWidget *parent)  :
+    QDialog(parent),
+    m_editor(new RichTextEditor()),
+    m_text_edit(new HtmlTextEdit),
+    m_tab_widget(new QTabWidget),
+    m_state(Clean)
+{
+    setWindowTitle(tr("Edit text"));
+    setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
+
+    m_text_edit->setAcceptRichText(false);
+
+    connect(m_editor, SIGNAL(textChanged()), this, SLOT(richTextChanged()));
+    connect(m_text_edit, SIGNAL(textChanged()), this, SLOT(sourceChanged()));
+
+    // The toolbar needs to be created after the RichTextEditor
+    QToolBar *tool_bar = m_editor->createToolBar();
+    tool_bar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
+
+    QWidget *rich_edit = new QWidget;
+    QVBoxLayout *rich_edit_layout = new QVBoxLayout(rich_edit);
+    rich_edit_layout->addWidget(tool_bar);
+    rich_edit_layout->addWidget(m_editor);
+
+    QWidget *plain_edit = new QWidget;
+    QVBoxLayout *plain_edit_layout = new QVBoxLayout(plain_edit);
+    plain_edit_layout->addWidget(m_text_edit);
+
+    m_tab_widget->setTabPosition(QTabWidget::South);
+    m_tab_widget->addTab(rich_edit, tr("Rich Text"));
+    m_tab_widget->addTab(plain_edit, tr("Source"));
+    connect(m_tab_widget, SIGNAL(currentChanged(int)),
+                          SLOT(tabIndexChanged(int)));
+
+    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
+    QPushButton *ok_button = buttonBox->button(QDialogButtonBox::Ok);
+    ok_button->setText(tr("&OK"));
+    ok_button->setDefault(true);
+    buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("&Cancel"));
+    connect(buttonBox, SIGNAL(accepted()), this, SLOT(on_buttonBox_accepted()));
+    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+
+    QVBoxLayout *layout = new QVBoxLayout(this);
+    layout->addWidget(m_tab_widget);
+    layout->addWidget(buttonBox);
+
+    m_editor->setFocus();
+
+}
+
+RichTextEditorDialog::~RichTextEditorDialog()
+{
+}
+
+/**
+ * @brief RichTextEditorDialog::on_buttonBox_accepted
+ */ 
+void RichTextEditorDialog::on_buttonBox_accepted() {
+	emit applyEditText( text(Qt::RichText) );
+	this->close();
+}
+
+
+int RichTextEditorDialog::showDialog()
+{
+    m_tab_widget->setCurrentIndex(0);
+    m_editor->selectAll();
+    m_editor->setFocus();
+
+    return exec();
+}
+
+void RichTextEditorDialog::setDefaultFont(const QFont &font)
+{
+    m_editor->setDefaultFont(font);
+}
+
+void RichTextEditorDialog::setText(const QString &text)
+{
+    m_editor->setText(text);
+    m_text_edit->setPlainText(text);
+    m_state = Clean;
+}
+
+QString RichTextEditorDialog::text(Qt::TextFormat format) const
+{
+    // In autotext mode, if the user has changed the source, use that
+    if (format == Qt::AutoText && (m_state == Clean || m_state == SourceChanged))
+        return m_text_edit->toPlainText();
+    // If the plain text HTML editor is selected, first copy its contents over
+    // to the rich text editor so that it is converted to Qt-HTML or actual
+    // plain text.
+    if (m_tab_widget->currentIndex() == SourceIndex && m_state == SourceChanged)
+        m_editor->setHtml(m_text_edit->toPlainText());
+    return m_editor->text(format);
+}
+
+void RichTextEditorDialog::tabIndexChanged(int newIndex)
+{
+    // Anything changed, is there a need for a conversion?
+    if (newIndex == SourceIndex && m_state != RichTextChanged)
+        return;
+    if (newIndex == RichTextIndex && m_state != SourceChanged)
+        return;
+    const State oldState = m_state;
+    // Remember the cursor position, since it is invalidated by setPlainText
+    QTextEdit *new_edit = (newIndex == SourceIndex) ? m_text_edit : m_editor;
+    const int position = new_edit->textCursor().position();
+
+    if (newIndex == SourceIndex) {
+        const QString html = m_editor->text(Qt::RichText);
+        qWarning("%s", qPrintable(runXSLT(html)));
+        m_text_edit->setPlainText(html);
+
+    } else
+        m_editor->setHtml(m_text_edit->toPlainText());
+
+    QTextCursor cursor = new_edit->textCursor();
+    cursor.movePosition(QTextCursor::End);
+    if (cursor.position() > position) {
+        cursor.setPosition(position);
+    }
+    new_edit->setTextCursor(cursor);
+    m_state = oldState; // Changed is triggered by setting the text
+}
+
+void RichTextEditorDialog::richTextChanged()
+{
+    m_state = RichTextChanged;
+}
+
+void RichTextEditorDialog::sourceChanged()
+{
+    m_state = SourceChanged;
+}
+
+} // namespace qdesigner_internal
+
+QT_END_NAMESPACE
+
+#include "richtexteditor.moc"

Added: trunk/sources/richtext/richtexteditor_p.h
===================================================================
--- trunk/sources/richtext/richtexteditor_p.h	                        (rev 0)
+++ trunk/sources/richtext/richtexteditor_p.h	2013-04-09 11:26:53 UTC (rev 2095)
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@xxxxxxxxx)
+**
+** This file is part of the Qt Designer of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights.  These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@xxxxxxxxx.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+//  W A R N I N G
+//  -------------
+//
+// This file is not part of the Qt API.  It exists for the convenience
+// of Qt Designer.  This header
+// file may change from version to version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef RICHTEXTEDITOR_H
+#define RICHTEXTEDITOR_H
+
+#include <QtGui/QTextEdit>
+#include <QtGui/QDialog>
+
+QT_BEGIN_NAMESPACE
+
+class QTabWidget;
+class QToolBar;
+
+class QDesignerFormEditorInterface;
+
+namespace qdesigner_internal {
+
+class RichTextEditor;
+
+class RichTextEditorDialog : public QDialog
+{
+    Q_OBJECT
+public:
+    explicit RichTextEditorDialog(QWidget *parent = 0);
+    ~RichTextEditorDialog();
+
+    int showDialog();
+    void setDefaultFont(const QFont &font);
+    void setText(const QString &text);
+    QString text(Qt::TextFormat format = Qt::AutoText) const;
+
+signals:
+	void applyEditText(const QString &);
+
+private slots:
+    void tabIndexChanged(int newIndex);
+    void richTextChanged();
+    void sourceChanged();
+	void on_buttonBox_accepted();
+	
+private:
+    enum TabIndex { RichTextIndex, SourceIndex };
+    enum State { Clean, RichTextChanged, SourceChanged };
+    RichTextEditor *m_editor;
+    QTextEdit      *m_text_edit;
+    QTabWidget     *m_tab_widget;
+    State m_state;
+    };
+
+} // namespace qdesigner_internal
+
+QT_END_NAMESPACE
+
+#endif // RITCHTEXTEDITOR_H

Added: trunk/sources/richtext/ui_addlinkdialog.h
===================================================================
--- trunk/sources/richtext/ui_addlinkdialog.h	                        (rev 0)
+++ trunk/sources/richtext/ui_addlinkdialog.h	2013-04-09 11:26:53 UTC (rev 2095)
@@ -0,0 +1,117 @@
+/********************************************************************************
+** Form generated from reading UI file 'addlinkdialog.ui'
+**
+** Created: Thu 4. Apr 17:13:59 2013
+**      by: Qt User Interface Compiler version 4.8.4
+**
+** WARNING! All changes made in this file will be lost when recompiling UI file!
+********************************************************************************/
+
+#ifndef UI_ADDLINKDIALOG_H
+#define UI_ADDLINKDIALOG_H
+
+#include <QtCore/QVariant>
+#include <QtGui/QAction>
+#include <QtGui/QApplication>
+#include <QtGui/QButtonGroup>
+#include <QtGui/QDialog>
+#include <QtGui/QDialogButtonBox>
+#include <QtGui/QFormLayout>
+#include <QtGui/QFrame>
+#include <QtGui/QHeaderView>
+#include <QtGui/QLabel>
+#include <QtGui/QLineEdit>
+#include <QtGui/QSpacerItem>
+#include <QtGui/QVBoxLayout>
+
+QT_BEGIN_NAMESPACE
+
+class Ui_AddLinkDialog
+{
+public:
+    QVBoxLayout *verticalLayout;
+    QFormLayout *formLayout;
+    QLabel *label;
+    QLineEdit *titleInput;
+    QLabel *label_2;
+    QLineEdit *urlInput;
+    QSpacerItem *verticalSpacer;
+    QFrame *line;
+    QDialogButtonBox *buttonBox;
+
+    void setupUi(QDialog *AddLinkDialog)
+    {
+        if (AddLinkDialog->objectName().isEmpty())
+            AddLinkDialog->setObjectName(QString::fromUtf8("AddLinkDialog"));
+        AddLinkDialog->setSizeGripEnabled(false);
+        AddLinkDialog->setModal(true);
+        verticalLayout = new QVBoxLayout(AddLinkDialog);
+        verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
+        formLayout = new QFormLayout();
+        formLayout->setObjectName(QString::fromUtf8("formLayout"));
+        label = new QLabel(AddLinkDialog);
+        label->setObjectName(QString::fromUtf8("label"));
+
+        formLayout->setWidget(0, QFormLayout::LabelRole, label);
+
+        titleInput = new QLineEdit(AddLinkDialog);
+        titleInput->setObjectName(QString::fromUtf8("titleInput"));
+        titleInput->setMinimumSize(QSize(337, 0));
+
+        formLayout->setWidget(0, QFormLayout::FieldRole, titleInput);
+
+        label_2 = new QLabel(AddLinkDialog);
+        label_2->setObjectName(QString::fromUtf8("label_2"));
+
+        formLayout->setWidget(1, QFormLayout::LabelRole, label_2);
+
+        urlInput = new QLineEdit(AddLinkDialog);
+        urlInput->setObjectName(QString::fromUtf8("urlInput"));
+
+        formLayout->setWidget(1, QFormLayout::FieldRole, urlInput);
+
+
+        verticalLayout->addLayout(formLayout);
+
+        verticalSpacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
+
+        verticalLayout->addItem(verticalSpacer);
+
+        line = new QFrame(AddLinkDialog);
+        line->setObjectName(QString::fromUtf8("line"));
+        line->setFrameShape(QFrame::HLine);
+        line->setFrameShadow(QFrame::Sunken);
+
+        verticalLayout->addWidget(line);
+
+        buttonBox = new QDialogButtonBox(AddLinkDialog);
+        buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
+        buttonBox->setOrientation(Qt::Horizontal);
+        buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
+
+        verticalLayout->addWidget(buttonBox);
+
+
+        retranslateUi(AddLinkDialog);
+        QObject::connect(buttonBox, SIGNAL(accepted()), AddLinkDialog, SLOT(accept()));
+        QObject::connect(buttonBox, SIGNAL(rejected()), AddLinkDialog, SLOT(reject()));
+
+        QMetaObject::connectSlotsByName(AddLinkDialog);
+    } // setupUi
+
+    void retranslateUi(QDialog *AddLinkDialog)
+    {
+        AddLinkDialog->setWindowTitle(QApplication::translate("AddLinkDialog", "Insert Link", 0, QApplication::UnicodeUTF8));
+        label->setText(QApplication::translate("AddLinkDialog", "Title:", 0, QApplication::UnicodeUTF8));
+        label_2->setText(QApplication::translate("AddLinkDialog", "URL:", 0, QApplication::UnicodeUTF8));
+    } // retranslateUi
+
+};
+
+namespace Ui {
+    class AddLinkDialog: public Ui_AddLinkDialog {};
+} // namespace Ui
+
+QT_END_NAMESPACE
+
+#endif // UI_ADDLINKDIALOG_H


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/