]> git.sesse.net Git - kdenlive/commitdiff
#596: Added possibility to enter unicode characters in the Title widget.
authorSimon A. Eugster <simon.eu@gmail.com>
Tue, 16 Jun 2009 19:24:39 +0000 (19:24 +0000)
committerSimon A. Eugster <simon.eu@gmail.com>
Tue, 16 Jun 2009 19:24:39 +0000 (19:24 +0000)
svn path=/trunk/kdenlive/; revision=3552

src/CMakeLists.txt
src/titlewidget.cpp
src/titlewidget.h
src/unicodedialog.cpp [new file with mode: 0644]
src/unicodedialog.h [new file with mode: 0644]
src/widgets/titlewidget_ui.ui
src/widgets/unicodedialog_ui.ui [new file with mode: 0644]

index f2fa89f86e3f99ffb26667af0b19d12acb432d4e..e01ea473ee94c3dca1c6de97c9c0d1176d64b149 100644 (file)
@@ -49,6 +49,7 @@ kde4_add_ui_files(kdenlive_UI
   widgets/colorval_ui.ui
   widgets/positionval_ui.ui
   widgets/titlewidget_ui.ui
+  widgets/unicodedialog_ui.ui
   widgets/timelinebuttons_ui.ui
   widgets/renderwidget_ui.ui
   widgets/saveprofile_ui.ui
@@ -117,6 +118,7 @@ set(kdenlive_SRCS
   kdenlivesettingsdialog.cpp
   complexparameter.cpp
   titlewidget.cpp
+  unicodedialog.cpp
   graphicsscenerectmove.cpp
   effectslistwidget.cpp
   titledocument.cpp
index 89870d6102474f2720fa32a5b782fd7b61556b49..6c4aacc1a566e617bb77c4fa4124eb768e7770a0 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
-                          titlewidget.h  -  description
+                          titlewidget.cpp  -  description
                              -------------------
     begin                : Feb 28 2008
     copyright            : (C) 2008 by Marco Gittler
@@ -46,6 +46,7 @@ TitleWidget::TitleWidget(KUrl url, QString projectPath, Render *render, QWidget
         m_endViewport(NULL),
         m_render(render),
         m_count(0),
+               m_unicodeDialog(new UnicodeDialog(UnicodeDialog::InputHex)),
         m_projectPath(projectPath)
 {
     setupUi(this);
@@ -56,11 +57,7 @@ TitleWidget::TitleWidget(KUrl url, QString projectPath, Render *render, QWidget
     text_properties->setFixedHeight(frame_properties->height() + 4);
     m_frameWidth = render->renderWidth();
     m_frameHeight = render->renderHeight();
-    //connect(newTextButton, SIGNAL(clicked()), this, SLOT(slotNewText()));
-    //connect(newRectButton, SIGNAL(clicked()), this, SLOT(slotNewRect()));
-    // kcolorbutton == The color of the background
     connect(kcolorbutton, SIGNAL(clicked()), this, SLOT(slotChangeBackground())) ;
-    // horizontalslider == The alpha of the background
     connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(slotChangeBackground())) ;
        
 
@@ -104,6 +101,8 @@ TitleWidget::TitleWidget(KUrl url, QString projectPath, Render *render, QWidget
     connect(buttonAlignRight, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
     connect(buttonAlignCenter, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
     connect(buttonAlignNone, SIGNAL(clicked()), this, SLOT(slotUpdateText()));
+       connect(buttonInsertUnicode, SIGNAL(clicked()), this, SLOT(slotInsertUnicode()));
+       connect(m_unicodeDialog, SIGNAL(charSelected(QString)), this, SLOT(slotInsertUnicodeString(QString)));
     connect(displayBg, SIGNAL(stateChanged(int)), this, SLOT(displayBackgroundFrame()));
 
     // mbd
@@ -121,6 +120,8 @@ TitleWidget::TitleWidget(KUrl url, QString projectPath, Render *render, QWidget
     buttonAlignRight->setToolTip(i18n("Align right"));
     buttonAlignLeft->setToolTip(i18n("Align left"));
     buttonAlignCenter->setToolTip(i18n("Align center"));
+       buttonInsertUnicode->setToolTip(i18n("Insert Unicode character (Shift+Ctrl+U)"));
+       buttonInsertUnicode->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_U);
        origin_x_left->setToolTip(i18n("Invert x axis and change 0 point"));
        origin_y_top->setToolTip(i18n("Invert y axis and change 0 point"));
        rectBColor->setToolTip(i18n("Select fill color"));
@@ -243,6 +244,7 @@ TitleWidget::~TitleWidget()
     delete m_buttonSave;
     delete m_buttonLoad;
 
+       delete m_unicodeDialog;
     delete m_frameBorder;
     delete m_frameImage;
     delete m_startViewport;
@@ -482,6 +484,8 @@ void TitleWidget::selectionChanged()
                updateTextOriginX();
                updateTextOriginY();
                frame_properties->setEnabled(false);
+               text_properties->setEnabled(false);
+               rect_properties->setEnabled(false);
                if (blockX) origin_x_left->blockSignals(false);
                if (blockY) origin_y_top->blockSignals(false);
        } else if (l.size() == 1) {
@@ -540,6 +544,8 @@ void TitleWidget::selectionChanged()
             //value_w->setValue((int) i->boundingRect().width());
             //value_h->setValue((int) i->boundingRect().height());
             frame_properties->setEnabled(true);
+                       text_properties->setEnabled(true);
+                       rect_properties->setEnabled(false);
             value_w->setEnabled(false);
             value_h->setEnabled(false);
                        
@@ -568,21 +574,27 @@ void TitleWidget::selectionChanged()
                        //value_w->setValue((int) rec->rect().width());
             //value_h->setValue((int) rec->rect().height());
             frame_properties->setEnabled(true);
+                       text_properties->setEnabled(false);
+                       rect_properties->setEnabled(true);
             value_w->setEnabled(true);
             value_h->setEnabled(true);
-        } else if (l.at(0)->type() == IMAGEITEM) {
-                       // TODO
                        
+        } else if (l.at(0)->type() == IMAGEITEM) {
                        updateCoordinates(l.at(0));
                        updateDimension(l.at(0));
                        
                        frame_properties->setEnabled(true);
+                       text_properties->setEnabled(false);
+                       rect_properties->setEnabled(false);
                        value_x->setEnabled(true);
                        value_w->setEnabled(false);
                        value_h->setEnabled(false);
+                       
                } else {
             //toolBox->setCurrentIndex(0);
             frame_properties->setEnabled(false);
+                       text_properties->setEnabled(false);
+                       rect_properties->setEnabled(false);
         }
         zValue->setValue((int)l.at(0)->zValue());
         itemzoom->setValue((int)(m_transformations.value(l.at(0)).scalex * 100.0 + 0.5));
@@ -912,6 +924,22 @@ void TitleWidget::textChanged(QGraphicsTextItem *i) {
        }
 }
 
+void TitleWidget::slotInsertUnicode()
+{
+       m_unicodeDialog->exec();
+}
+
+void TitleWidget::slotInsertUnicodeString(QString text)
+{
+       QList<QGraphicsItem *> l = graphicsView->scene()->selectedItems();
+       if (l.size() > 0) {
+               if (l.at(0)->type() == TEXTITEM) {
+                       QGraphicsTextItem *t = static_cast <QGraphicsTextItem *> (l.at(0));
+                       t->textCursor().insertText(text);
+               }
+       }
+}
+
 void TitleWidget::slotUpdateText()
 {
     QFont font = font_family->currentFont();
index ff49558f183de031ee041026926efd8ee82f39d5..61a70df75ee455a934cda8e6a9983c38ec300047 100644 (file)
@@ -23,6 +23,7 @@
 #include "titledocument.h"
 #include "renderer.h"
 #include "graphicsscenerectmove.h"
+#include "unicodedialog.h"
 
 #include <QMap>
 
@@ -89,6 +90,8 @@ private:
     QAction *m_buttonCursor;
     QAction *m_buttonSave;
     QAction *m_buttonLoad;
+       /** \brief Dialog for entering unicode in text fields */
+       UnicodeDialog *m_unicodeDialog;
     /** project path for storing title clips */
     QString m_projectPath;
     /** \brief Store the current choices of font, background and rect values */
@@ -175,6 +178,8 @@ private slots:
     void slotZoomOneToOne();
        
     void slotUpdateText();
+       void slotInsertUnicode();
+       void slotInsertUnicodeString(QString);
        
     void displayBackgroundFrame();
        
diff --git a/src/unicodedialog.cpp b/src/unicodedialog.cpp
new file mode 100644 (file)
index 0000000..af995ca
--- /dev/null
@@ -0,0 +1,144 @@
+/***************************************************************************
+ *   Copyright (C) 2008 by Simon Andreas Eugster (simon.eu@gmail.com)      *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ ***************************************************************************/
+#include "unicodedialog.h"
+
+/// CONSTANTS
+
+const int MAX_LENGTH_HEX = 4;
+/// CONSTRUCTORS/DECONSTRUCTORS
+
+UnicodeDialog::UnicodeDialog(InputMethod inputMeth) : inputMethod(inputMeth), lastCursorPos(0), lastUnicodeNumber("")
+{
+       setupUi(this);
+       connect(unicodeNumber, SIGNAL(textChanged(QString)), this, SLOT(slotTextChanged(QString)));
+       connect(unicodeNumber, SIGNAL(returnPressed()), this, SLOT(slotReturnPressed()));
+       
+       switch (inputMethod) {
+               case InputHex:
+                       unicodeNumber->setMaxLength(MAX_LENGTH_HEX);
+               break;
+               
+               case InputDec:
+               break;
+       }
+}
+
+UnicodeDialog::~UnicodeDialog()
+{
+}
+
+
+/// METHODS
+
+QString UnicodeDialog::unicodeInfo(QString unicode_number)
+{
+       QString infoText("");
+       QString u = unicode_number;
+       
+       while (unicode_number.at(0) == QChar('0')) {
+               unicode_number = unicode_number.remove(0, 1);
+       }
+       
+       if (false) {
+               // Just a placeholder for reason of ease (shifting around lines)
+       } else if (u == "2009") {
+               infoText = i18n("A thin space, in HTML also &amp;thinsp;. See <a href=\"http://en.wikipedia.org/wiki/Space_(punctuation)\">Wikipedia:Space_(punctuation)</a>");
+       } else if (u == "2019") {
+               infoText = i18n("Punctuation Apostrophe. Should be used instead of U+0027. See <a href=\"http://en.wikipedia.org/wiki/Apostrophe\">Wikipedia:Apostrophe</a>");
+       } else if (u == "2013") {
+               infoText = i18n("An en Dash (dash of the width of an n). See <a href=\"http://en.wikipedia.org/wiki/Dash\">Wikipedia:Dash</a>");
+       } else if (u == "2014") {
+               infoText = i18n("An em Dash (dash of the widht of an m). See <a href=\"http://en.wikipedia.org/wiki/Dash\">Wikipedia:Dash</a>");
+       } else if (u == "2026") {
+               infoText = i18n("Ellipsis: If text has been left out. See <a href=\"http://en.wikipedia.org/wiki/Ellipsis\">Wikipedia:Ellipsis</a>");
+       }
+       
+       return infoText;
+}
+
+/**
+ * Validates an Unicode number.
+ */
+QString UnicodeDialog::validateText(QString text)
+{
+       QRegExp regex("([0-9]|[a-f])", Qt::CaseInsensitive, QRegExp::RegExp2);
+       QString newText = "";
+       int pos = 0;
+       
+       switch (inputMethod) {
+               case InputHex:
+                       while ((pos = regex.indexIn(text, pos)) != -1) {
+                               newText += regex.cap(1);
+                               pos++;
+                       }
+               break;
+               
+               case InputDec:
+                       // TODO
+               break;
+       }
+       
+       return newText;
+}
+
+
+/// SLOTS
+
+/**
+ * \brief Validates the entered Unicode number and displays its Unicode character.
+ */
+void UnicodeDialog::slotTextChanged(QString text)
+{
+       unicodeNumber->blockSignals(true);
+       
+       bool ok;
+       int cursorPos = unicodeNumber->cursorPosition();
+       QString newText = validateText(text);
+       
+       unicodeNumber->setText(newText);
+       unicodeNumber->setCursorPosition(cursorPos);
+       
+       uint value;
+       switch (inputMethod) {
+               case InputHex:
+                       value = newText.toUInt(&ok, 16);
+               break;
+               case InputDec:
+                       value = newText.toUInt(&ok, 10);
+               break;
+       }
+       
+       if (!ok) {
+               //TODO!
+       }
+       
+       // If an invalid character has been entered:
+       // Reset the cursor position because the entered char has been deleted.
+       if (text != newText && newText == lastUnicodeNumber) {
+               unicodeNumber->setCursorPosition(lastCursorPos);
+       }
+       
+       lastCursorPos = unicodeNumber->cursorPosition();
+       lastUnicodeNumber = newText;
+       
+       labelInfoText->setText(unicodeInfo(newText));
+       unicodeChar->setText(QChar(value));
+       unicodeNumber->blockSignals(false);
+}
+
+void UnicodeDialog::slotReturnPressed() 
+{
+       emit charSelected(unicodeChar->text());
+       emit accept();
+}
+
+#include "unicodedialog.moc"
diff --git a/src/unicodedialog.h b/src/unicodedialog.h
new file mode 100644 (file)
index 0000000..4c03766
--- /dev/null
@@ -0,0 +1,50 @@
+/***************************************************************************
+ *   Copyright (C) 2008 by Simon Andreas Eugster (simon.eu@gmail.com)      *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ ***************************************************************************/
+
+#ifndef UNICODEDIALOG_H
+#define UNICODEDIALOG_H
+
+#include "ui_unicodedialog_ui.h"
+
+class UnicodeDialog : public QDialog, public Ui::UnicodeDialog_UI
+{
+       Q_OBJECT
+       
+public:
+       /** \brief The input method for the dialog. Atm only InputHex supported. */
+       enum InputMethod { InputHex, InputDec };
+       
+       UnicodeDialog(InputMethod inputMeth);
+       ~UnicodeDialog();
+       
+       /** \brief Returns infos about an unicode number. Extendable/improvable ;) */
+       QString unicodeInfo(QString unicode_number);
+
+private:
+       Ui::UnicodeDialog_UI m_view;
+       
+       /** Selected input method */
+       InputMethod inputMethod;
+       /** \brief Validates text and removes all invalid characters (non-hex e.g.) */
+       QString validateText(QString text);
+       
+       int lastCursorPos;
+       QString lastUnicodeNumber;
+
+signals:
+       /** \brief Contains the selected unicode character; emitted when Enter is pressed. */
+       void charSelected(const QString&);
+
+private slots:
+       void slotTextChanged(QString text);
+       void slotReturnPressed();
+
+};
+
+#endif
index c191ca44ce93d072b3639153af831a7c1b818fa3..c0e63b87e50cffab1a07e1729f2ea9c014c38785 100644 (file)
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>757</width>
+    <width>902</width>
     <height>442</height>
    </rect>
   </property>
           </property>
          </widget>
         </item>
+        <item>
+         <widget class="QToolButton" name="buttonInsertUnicode">
+          <property name="text">
+           <string>...</string>
+          </property>
+         </widget>
+        </item>
         <item>
          <spacer name="horizontalSpacer_2">
           <property name="orientation">
         <rect>
          <x>0</x>
          <y>0</y>
-         <width>358</width>
-         <height>178</height>
+         <width>441</width>
+         <height>143</height>
         </rect>
        </property>
        <attribute name="label">
         <rect>
          <x>0</x>
          <y>0</y>
-         <width>94</width>
-         <height>65</height>
+         <width>441</width>
+         <height>143</height>
         </rect>
        </property>
        <attribute name="label">
         <rect>
          <x>0</x>
          <y>0</y>
-         <width>232</width>
-         <height>198</height>
+         <width>425</width>
+         <height>224</height>
         </rect>
        </property>
        <attribute name="label">
           <property name="text">
            <string>+X</string>
           </property>
-                 <property name="checkable">
-                  <bool>true</bool>
-                 </property>
-                 <property name="checked">
-                  <bool>false</bool>
-                 </property>
+          <property name="checkable">
+           <bool>true</bool>
+          </property>
+          <property name="checked">
+           <bool>false</bool>
+          </property>
          </widget>
         </item>
         <item>
           <property name="text">
            <string>+Y</string>
           </property>
-                 <property name="checkable">
-                  <bool>true</bool>
-                 </property>
-                 <property name="checked">
-                  <bool>false</bool>
-                 </property>
+          <property name="checkable">
+           <bool>true</bool>
+          </property>
+          <property name="checked">
+           <bool>false</bool>
+          </property>
          </widget>
         </item>
         <item>
   </layout>
  </widget>
  <customwidgets>
-  <customwidget>
-   <class>KIntSpinBox</class>
-   <extends>QSpinBox</extends>
-   <header>knuminput.h</header>
-  </customwidget>
   <customwidget>
    <class>KColorButton</class>
    <extends>QPushButton</extends>
    <header>kcolorbutton.h</header>
   </customwidget>
+  <customwidget>
+   <class>KIntSpinBox</class>
+   <extends>QSpinBox</extends>
+   <header>knuminput.h</header>
+  </customwidget>
  </customwidgets>
  <resources/>
  <connections>
diff --git a/src/widgets/unicodedialog_ui.ui b/src/widgets/unicodedialog_ui.ui
new file mode 100644 (file)
index 0000000..534e917
--- /dev/null
@@ -0,0 +1,214 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>UnicodeDialog_UI</class>
+ <widget class="QDialog" name="UnicodeDialog_UI">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>614</width>
+    <height>315</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Enter Unicode value</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <widget class="QFrame" name="frame">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="frameShape">
+      <enum>QFrame::StyledPanel</enum>
+     </property>
+     <property name="frameShadow">
+      <enum>QFrame::Raised</enum>
+     </property>
+     <layout class="QGridLayout" name="gridLayout_2">
+      <item row="0" column="0">
+       <widget class="QLabel" name="label">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="font">
+         <font>
+          <pointsize>15</pointsize>
+         </font>
+        </property>
+        <property name="text">
+         <string notr="true">U+</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="2">
+       <spacer name="horizontalSpacer">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="0" column="4">
+       <widget class="QLabel" name="unicodeChar">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="font">
+         <font>
+          <pointsize>15</pointsize>
+         </font>
+        </property>
+        <property name="text">
+         <string notr="true"/>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="6">
+       <spacer name="horizontalSpacer_2">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="0" column="7">
+       <spacer name="horizontalSpacer_3">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="0" column="1">
+       <widget class="QLineEdit" name="unicodeNumber">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="minimumSize">
+         <size>
+          <width>12</width>
+          <height>0</height>
+         </size>
+        </property>
+        <property name="font">
+         <font>
+          <pointsize>15</pointsize>
+         </font>
+        </property>
+        <property name="inputMask">
+         <string notr="true"/>
+        </property>
+        <property name="text">
+         <string notr="true"/>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="3">
+       <widget class="Line" name="line_2">
+        <property name="orientation">
+         <enum>Qt::Vertical</enum>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="5">
+       <widget class="Line" name="line_3">
+        <property name="orientation">
+         <enum>Qt::Vertical</enum>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item row="1" column="0">
+    <widget class="QFrame" name="frame_2">
+     <property name="frameShape">
+      <enum>QFrame::StyledPanel</enum>
+     </property>
+     <property name="frameShadow">
+      <enum>QFrame::Raised</enum>
+     </property>
+     <layout class="QGridLayout" name="gridLayout_3">
+      <item row="2" column="0">
+       <widget class="QLabel" name="label_6">
+        <property name="locale">
+         <locale language="English" country="UnitedStates"/>
+        </property>
+        <property name="text">
+         <string>Information about unicode characters: &lt;a href=&quot;http://decodeunicode.org&quot;&gt;http://decodeunicode.org&lt;/a&gt; (Unicode database)</string>
+        </property>
+        <property name="wordWrap">
+         <bool>true</bool>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="labelInfoText">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="locale">
+         <locale language="English" country="UnitedStates"/>
+        </property>
+        <property name="text">
+         <string notr="true"/>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="0">
+       <widget class="QLabel" name="label_2">
+        <property name="font">
+         <font>
+          <italic>true</italic>
+         </font>
+        </property>
+        <property name="locale">
+         <locale language="English" country="UnitedStates"/>
+        </property>
+        <property name="text">
+         <string>Additional Information:</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>