]> git.sesse.net Git - kdenlive/commitdiff
Unicode Dialog extended (character list, shortcuts for next/prev character, test...
authorSimon A. Eugster <simon.eu@gmail.com>
Thu, 18 Jun 2009 15:46:40 +0000 (15:46 +0000)
committerSimon A. Eugster <simon.eu@gmail.com>
Thu, 18 Jun 2009 15:46:40 +0000 (15:46 +0000)
svn path=/trunk/kdenlive/; revision=3575

icons/hi16-action-kdenlive-insert-unicode.png
icons/hisc-action-kdenlive-insert-unicode.svgz
icons/ox16-action-kdenlive-insert-unicode.png
icons/oxsc-action-kdenlive-insert-unicode.svgz
src/titlewidget.cpp
src/unicodedialog.cpp
src/unicodedialog.h
src/widgets/unicodedialog_ui.ui

index ec47bea7258833b1153646cbd77b2968f5fcaa27..ec52a7392a9f9f594b98c0aee8ba2738a5963e35 100644 (file)
Binary files a/icons/hi16-action-kdenlive-insert-unicode.png and b/icons/hi16-action-kdenlive-insert-unicode.png differ
index 68525a0f22e3b2bad615dc969ecb1f1f59552491..1c690e4719473edba0117cee66a1156a2d440593 100644 (file)
Binary files a/icons/hisc-action-kdenlive-insert-unicode.svgz and b/icons/hisc-action-kdenlive-insert-unicode.svgz differ
index ec47bea7258833b1153646cbd77b2968f5fcaa27..ec52a7392a9f9f594b98c0aee8ba2738a5963e35 100644 (file)
Binary files a/icons/ox16-action-kdenlive-insert-unicode.png and b/icons/ox16-action-kdenlive-insert-unicode.png differ
index 68525a0f22e3b2bad615dc969ecb1f1f59552491..1c690e4719473edba0117cee66a1156a2d440593 100644 (file)
Binary files a/icons/oxsc-action-kdenlive-insert-unicode.svgz and b/icons/oxsc-action-kdenlive-insert-unicode.svgz differ
index 6902bd329e12c6cedf5b7b4adb5fff55f1ec1d80..023e6ff592c6586410898f3a2c03a46aa1c7226d 100644 (file)
@@ -929,6 +929,7 @@ void TitleWidget::textChanged(QGraphicsTextItem *i) {
 
 void TitleWidget::slotInsertUnicode()
 {
+       m_unicodeDialog->showLastUnicode();
        m_unicodeDialog->exec();
 }
 
index c676d57817f8fac6492a6a59eb09f1e3b1f2b09f..1f588b05550117eb07fd5f23197075ffdf3b00e1 100644 (file)
@@ -12,6 +12,7 @@
 /// CONSTANTS
 
 const int MAX_LENGTH_HEX = 4;
+const uint MAX_UNICODE_V1 = 65535;
  
  
 /// CONSTRUCTORS/DECONSTRUCTORS
@@ -21,6 +22,8 @@ UnicodeDialog::UnicodeDialog(InputMethod inputMeth) : inputMethod(inputMeth), la
        setupUi(this);
        connect(unicodeNumber, SIGNAL(textChanged(QString)), this, SLOT(slotTextChanged(QString)));
        connect(unicodeNumber, SIGNAL(returnPressed()), this, SLOT(slotReturnPressed()));
+       connect(arrowUp, SIGNAL(clicked()), this, SLOT(slotNextUnicode()));
+       connect(arrowDown, SIGNAL(clicked()), this, SLOT(slotPrevUnicode()));
        
        switch (inputMethod) {
                case InputHex:
@@ -30,6 +33,13 @@ UnicodeDialog::UnicodeDialog(InputMethod inputMeth) : inputMethod(inputMeth), la
                case InputDec:
                break;
        }
+       
+       arrowUp->setShortcut(Qt::Key_Up);
+       arrowDown->setShortcut(Qt::Key_Down);
+       
+       arrowUp->setToolTip(i18n("Next Unicode character (Arrow Up)"));
+       arrowDown->setToolTip(i18n("Previous Unicode character (Arrow Down)"));
+       unicodeNumber->setToolTip(i18n("Enter your Unicode number here. Allowed characters: [0-9] and [a-f]."));
 }
 
 UnicodeDialog::~UnicodeDialog()
@@ -39,6 +49,11 @@ UnicodeDialog::~UnicodeDialog()
 
 /// METHODS
 
+void UnicodeDialog::showLastUnicode()
+{
+       unicodeNumber->setText(lastUnicodeNumber);
+}
+
 bool UnicodeDialog::controlCharacter(QString text)
 {
        bool isControlCharacter = false;
@@ -54,12 +69,25 @@ bool UnicodeDialog::controlCharacter(QString text)
                        break;
                        
                case InputDec:
+                       bool ok;
+                       isControlCharacter = controlCharacter(text.toUInt(&ok, 16));
                        break;
        }
        
        return isControlCharacter;
 }
 
+bool UnicodeDialog::controlCharacter(uint value)
+{
+       bool isControlCharacter = false;
+       
+       if (value < 32 && !(value == 9 || value == 10 || value == 13)) {
+               isControlCharacter = true;
+       }
+       return isControlCharacter;
+       
+}
+
 QString UnicodeDialog::trimmedUnicodeNumber(QString text)
 {
        while (text.length() > 0 && text.at(0) == QChar('0')) {
@@ -70,13 +98,37 @@ QString UnicodeDialog::trimmedUnicodeNumber(QString text)
 
 QString UnicodeDialog::unicodeInfo(QString unicode_number)
 {
-       QString infoText("");
-       QString u = trimmedUnicodeNumber(unicode_number);
+       QString infoText(i18n("<small>(no character selected)</small>"));
+       if (unicode_number.length() == 0) return infoText;
+       
+       QString u = trimmedUnicodeNumber(unicode_number).toLower();
        
        if (controlCharacter(u)) {
                infoText = i18n("Control character. Cannot be inserted/printed. See <a href=\"http://en.wikipedia.org/wiki/Control_character\">Wikipedia:Control_character</a>");
+       } else if (u == "a") {
+               infoText = i18n("Line Feed (newline character, \\\\n)");
+       } else if (u == "20") {
+               infoText = i18n("Standard space character. (See U+00a0 and U+2000&#x2013;200b)");
+       } else if (u == "a0") {
+               infoText = i18n("No-break space. &amp;nbsp; in HTML. See U+0020.");
+       } else if (u == "2002") {
+               infoText = i18n("En Space (width of an n)");
+       } else if (u == "2003") {
+               infoText = i18n("Em Space (width of an m)");
+       } else if (u == "2004") {
+               infoText = i18n("Three-Per-Em Space. Width: 1/3 of one <em>em</em>");
+       } else if (u == "2005") {
+               infoText = i18n("Four-Per-Em Space. Width: 1/4 of one <em>em</em>");
+       } else if (u == "2006") {
+               infoText = i18n("Six-Per-Em Space. Width: 1/6 of one <em>em</em>");
+       } else if (u == "2007") {
+               infoText = i18n("Figure space (non-breaking). Width of a digit if digits have fixed width in this font.");
+       } else if (u == "2008") {
+               infoText = i18n("Punctuation Space. Width the same as between a punctuation character and the next character.");
        } 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>");
+               infoText = i18n("Thin space, in HTML also &amp;thinsp;. See <a href=\"http://en.wikipedia.org/wiki/Space_(punctuation)\">Wikipedia:Space_(punctuation)</a>");
+       } else if (u == "200a") {
+               infoText = i18n("Hair Space. Thinner than U+2009.");
        } 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") {
@@ -85,6 +137,8 @@ QString UnicodeDialog::unicodeInfo(QString unicode_number)
                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>");
+       } else {
+               infoText = i18n("<small>No additional information available for this character.</small>");
        }
        
        return infoText;
@@ -113,6 +167,62 @@ QString UnicodeDialog::validateText(QString text)
        return newText;
 }
 
+void UnicodeDialog::updateOverviewChars(uint unicode)
+{
+       QString left = "";
+       QString right = "";
+       uint i;
+       
+       for (i = 1; i <= 4; i++) {
+               if (unicode > i && !controlCharacter(unicode-i)) {
+                       left = " " + left;
+                       left = QChar(unicode-i) + left;
+               }
+       }
+       
+       for (i = 1; i <= 8; i++) {
+               if (unicode + i <= MAX_UNICODE_V1 && !controlCharacter(unicode+i)) {
+                       right += QChar(unicode+i);
+                       right += " ";
+               }
+       }
+       
+       leftChars->setText(left);
+       rightChars->setText(right);
+       
+}
+
+QString UnicodeDialog::nextUnicode(QString text, Direction direction)
+{
+       uint value = 0;
+       QString newText = "";
+       bool ok;
+       
+       switch (inputMethod) {
+               case InputHex:
+                       value = text.toUInt(&ok, 16);
+                       switch (direction) {
+                               case Backward:
+                                       value--;
+                                       break;
+                               default:
+                                       value++;
+                                       break;
+                       }
+                       // Wrapping
+                       if (value == (uint) -1) value = MAX_UNICODE_V1;
+                       if (value > MAX_UNICODE_V1) value = 0;
+                       
+                       newText.setNum(value, 16);
+                       break;
+                       
+               case InputDec:
+                       break;
+       }
+       
+       return newText;
+}
+
 
 /// SLOTS
 
@@ -123,39 +233,51 @@ void UnicodeDialog::slotTextChanged(QString text)
 {
        unicodeNumber->blockSignals(true);
        
-       bool ok;
-       int cursorPos = unicodeNumber->cursorPosition();
        QString newText = validateText(text);
-       
-       unicodeNumber->setText(newText);
-       unicodeNumber->setCursorPosition(cursorPos);
-       
-       // Get the decimal number as uint to create the QChar from
-       uint value;
-       switch (inputMethod) {
-               case InputHex:
-                       value = newText.toUInt(&ok, 16);
-               break;
-               case InputDec:
-                       value = newText.toUInt(&ok, 10);
-               break;
-       }
-       
-       if (!ok) {
-               // Impossible! validateText never fails!
-       }
-       
-       // 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);
+       if (newText.length() == 0) {
+               unicodeChar->setText("");
+               unicodeNumber->setText("");
+               lastCursorPos = 0;
+               lastUnicodeNumber = "";
+               labelInfoText->setText(unicodeInfo(""));
+               
+       } else {
+               
+               int cursorPos = unicodeNumber->cursorPosition();
+               
+               unicodeNumber->setText(newText);
+               unicodeNumber->setCursorPosition(cursorPos);
+               
+               // Get the decimal number as uint to create the QChar from
+               bool ok;
+               uint value = 0;
+               switch (inputMethod) {
+                       case InputHex:
+                               value = newText.toUInt(&ok, 16);
+                       break;
+                       case InputDec:
+                               value = newText.toUInt(&ok, 10);
+                       break;
+               }
+               updateOverviewChars(value);
+               
+               if (!ok) {
+                       // Impossible! validateText never fails!
+               }
+               
+               // 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));
        }
        
-       lastCursorPos = unicodeNumber->cursorPosition();
-       lastUnicodeNumber = newText;
-       
-       labelInfoText->setText(unicodeInfo(newText));
-       unicodeChar->setText(QChar(value));
        unicodeNumber->blockSignals(false);
 }
 
@@ -172,4 +294,16 @@ void UnicodeDialog::slotReturnPressed()
        emit accept();
 }
 
+void UnicodeDialog::slotNextUnicode()
+{
+       QString text = unicodeNumber->text();
+       unicodeNumber->setText(nextUnicode(text, Forward));
+}
+
+void UnicodeDialog::slotPrevUnicode()
+{
+       QString text = unicodeNumber->text();
+       unicodeNumber->setText(nextUnicode(text, Backward));
+}
+
 #include "unicodedialog.moc"
index 52abd3f7c5857dbd432dc52c5e574c234918fc57..697cee96656d62ca2493a294d3ae529c49744774 100644 (file)
@@ -25,10 +25,14 @@ public:
        
        /** \brief Returns infos about a unicode number. Extendable/improvable ;) */
        QString unicodeInfo(QString unicode_number);
+       
+       void showLastUnicode();
 
 private:
        Ui::UnicodeDialog_UI m_view;
        
+       enum Direction { Forward, Backward };
+       
        /** Selected input method */
        InputMethod inputMethod;
        
@@ -38,6 +42,14 @@ private:
        QString trimmedUnicodeNumber(QString text);
        /** \brief Checks whether the given string is a control character */
        bool controlCharacter(QString text);
+       /** \brief Checks whether the given uint is a control character */
+       bool controlCharacter(uint value);
+       
+       /** \brief Returns the next available unicode. */
+       QString nextUnicode(QString text, Direction direction);
+       
+       /** \brief Paints previous and next characters around current char */
+       void updateOverviewChars(uint unicode);
        
        int lastCursorPos;
        QString lastUnicodeNumber;
@@ -49,6 +61,8 @@ signals:
 private slots:
        void slotTextChanged(QString text);
        void slotReturnPressed();
+       void slotNextUnicode();
+       void slotPrevUnicode();
 
 };
 
index 9f6fc905da9e441011b9a3380576236aaed1b143..07f3c4e17f94d8bf4787c458b96b937bea3afa1d 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>614</width>
-    <height>315</height>
+    <width>576</width>
+    <height>211</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -47,7 +47,7 @@
         </property>
        </widget>
       </item>
-      <item row="0" column="2">
+      <item row="0" column="4">
        <spacer name="horizontalSpacer">
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
@@ -60,7 +60,7 @@
         </property>
        </spacer>
       </item>
-      <item row="0" column="4">
+      <item row="0" column="7">
        <widget class="QLabel" name="unicodeChar">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
@@ -78,7 +78,7 @@
         </property>
        </widget>
       </item>
-      <item row="0" column="6">
+      <item row="0" column="10">
        <spacer name="horizontalSpacer_2">
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
@@ -91,7 +91,7 @@
         </property>
        </spacer>
       </item>
-      <item row="0" column="7">
+      <item row="0" column="11">
        <spacer name="horizontalSpacer_3">
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
       <item row="0" column="1">
        <widget class="QLineEdit" name="unicodeNumber">
         <property name="sizePolicy">
-         <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+         <sizepolicy hsizetype="Preferred" 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>
         <property name="text">
          <string notr="true"/>
         </property>
+        <property name="maxLength">
+         <number>7</number>
+        </property>
        </widget>
       </item>
-      <item row="0" column="3">
-       <widget class="Line" name="line_2">
+      <item row="0" column="8">
+       <widget class="Line" name="lineRight">
         <property name="orientation">
          <enum>Qt::Vertical</enum>
         </property>
        </widget>
       </item>
-      <item row="0" column="5">
-       <widget class="Line" name="line_3">
+      <item row="0" column="6">
+       <widget class="Line" name="lineLeft">
         <property name="orientation">
          <enum>Qt::Vertical</enum>
         </property>
        </widget>
       </item>
+      <item row="0" column="5">
+       <widget class="QLabel" name="leftChars">
+        <property name="text">
+         <string notr="true"/>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="9">
+       <widget class="QLabel" name="rightChars">
+        <property name="text">
+         <string notr="true"/>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="2">
+       <layout class="QVBoxLayout" name="verticalLayout_5">
+        <item>
+         <widget class="KArrowButton" name="arrowUp"/>
+        </item>
+        <item>
+         <widget class="KArrowButton" name="arrowDown">
+          <property name="arrowType" stdset="0">
+           <number>2</number>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
      </layout>
     </widget>
    </item>
          <locale language="English" country="UnitedStates"/>
         </property>
         <property name="text">
-         <string>Additional Information:</string>
+         <string>Additional Information</string>
         </property>
        </widget>
       </item>
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>KArrowButton</class>
+   <extends>QPushButton</extends>
+   <header>karrowbutton.h</header>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>