]> git.sesse.net Git - kdenlive/blobdiff - src/unicodedialog.cpp
Integrate with the required MLT hooks for getting Movit to work.
[kdenlive] / src / unicodedialog.cpp
index b721cb590bce243a987c2225a97a3c5e113bc474..d55c30dfaffe1edca32bda5b06fdb1b642d9e0f0 100644 (file)
@@ -9,15 +9,40 @@
 
 #include "unicodedialog.h"
 
+#include <QWheelEvent>
+
 /// CONSTANTS
 
 const int MAX_LENGTH_HEX = 4;
 const uint MAX_UNICODE_V1 = 65535;
 
 
+UnicodeDialog::UnicodeDialog(InputMethod inputMeth, QWidget *parent)
+    : KDialog(parent)
+{
+    setCaption( i18n("Details") );
+    setButtons( Ok|Cancel );
+    mUnicodeWidget = new UnicodeWidget(inputMeth);
+    connect(mUnicodeWidget, SIGNAL(charSelected(QString)), SIGNAL(charSelected(QString)));
+    setMainWidget(mUnicodeWidget);
+    connect(this, SIGNAL(okClicked()), SLOT(slotAccept()));
+}
+
+UnicodeDialog::~UnicodeDialog()
+{
+}
+
+void UnicodeDialog::slotAccept()
+{
+    mUnicodeWidget->slotReturnPressed();
+    accept();
+}
+
+
 /// CONSTRUCTORS/DECONSTRUCTORS
 
-UnicodeDialog::UnicodeDialog(InputMethod inputMeth) :
+UnicodeWidget::UnicodeWidget(UnicodeDialog::InputMethod inputMeth, QWidget *parent)
+    : QWidget(parent),
         inputMethod(inputMeth),
         m_lastCursorPos(0)
 {
@@ -30,11 +55,11 @@ UnicodeDialog::UnicodeDialog(InputMethod inputMeth) :
     connect(arrowDown, SIGNAL(clicked()), this, SLOT(slotNextUnicode()));
 
     switch (inputMethod) {
-    case InputHex:
+    case UnicodeDialog::InputHex:
         unicodeNumber->setMaxLength(MAX_LENGTH_HEX);
         break;
 
-    case InputDec:
+    case UnicodeDialog::InputDec:
         break;
     }
 
@@ -45,47 +70,35 @@ UnicodeDialog::UnicodeDialog(InputMethod inputMeth) :
     arrowDown->setToolTip(i18n("Next Unicode character (Arrow Down)"));
     unicodeNumber->setToolTip(i18n("Enter your Unicode number here. Allowed characters: [0-9] and [a-f]."));
     unicodeNumber->selectAll(); // Selection will be reset by setToolTip and similar, so set it here
-
 }
 
-UnicodeDialog::~UnicodeDialog()
+UnicodeWidget::~UnicodeWidget()
 {
 }
-
-
-/// PUBLIC SLOTS
-
-int UnicodeDialog::exec()
-{
-    unicodeNumber->setFocus();
-    return QDialog::exec();
-}
-
-
 /// METHODS
 
-void UnicodeDialog::showLastUnicode()
+void UnicodeWidget::showLastUnicode()
 {
     unicodeNumber->setText(m_lastUnicodeNumber);
     unicodeNumber->selectAll();
     slotTextChanged(m_lastUnicodeNumber);
 }
 
-bool UnicodeDialog::controlCharacter(QString text)
+bool UnicodeWidget::controlCharacter(const QString &text)
 {
     bool isControlCharacter = false;
     QString t = text.toLower();
 
     switch (inputMethod) {
-    case InputHex:
-        if (t == ""
+    case UnicodeDialog::InputHex:
+        if (t.isEmpty()
                 || (t.length() == 1 && !(t == "9" || t == "a" || t == "d"))
                 || (t.length() == 2 && t.at(0) == QChar('1'))) {
             isControlCharacter = true;
         }
         break;
 
-    case InputDec:
+    case UnicodeDialog::InputDec:
         bool ok;
         isControlCharacter = controlCharacter(text.toUInt(&ok, 16));
         break;
@@ -94,7 +107,7 @@ bool UnicodeDialog::controlCharacter(QString text)
     return isControlCharacter;
 }
 
-bool UnicodeDialog::controlCharacter(uint value)
+bool UnicodeWidget::controlCharacter(uint value)
 {
     bool isControlCharacter = false;
 
@@ -105,15 +118,15 @@ bool UnicodeDialog::controlCharacter(uint value)
 
 }
 
-QString UnicodeDialog::trimmedUnicodeNumber(QString text)
+QString UnicodeWidget::trimmedUnicodeNumber(QString text)
 {
-    while (text.length() > 0 && text.at(0) == QChar('0')) {
+    while (!text.isEmpty() && text.at(0) == QChar('0')) {
         text = text.remove(0, 1);
     }
     return text;
 }
 
-QString UnicodeDialog::unicodeInfo(QString unicode)
+QString UnicodeWidget::unicodeInfo(const QString &unicode)
 {
     QString infoText(i18n("<small>(no character selected)</small>"));
     if (unicode.length() == 0) return infoText;
@@ -169,7 +182,7 @@ QString UnicodeDialog::unicodeInfo(QString unicode)
     } else if (u == "266c") {
         infoText = i18n("Sixteenth note (Am.) or semiquaver (Brit.). Half as long as an eighth note (U+266a). See <a href=\"http://en.wikipedia.org/wiki/Sixteenth_note\">Wikipedia:Sixteenth_note</a>");
     } else if (u == "1D162") {
-        infoText = i18n("Thirty-second note (Am.) or demisemiquaver (Brit.). Half as long as a sixteenth note (U+266b). See <a href=\"http://en.wikipedia.org/wiki/Quarter_note\">Wikipedia:Thirty-second_note</a>");
+        infoText = i18n("Thirty-second note (Am.) or demisemiquaver (Brit.). Half as long as a sixteenth note (U+266b). See <a href=\"http://en.wikipedia.org/wiki/Thirty-second_note\">Wikipedia:Thirty-second_note</a>");
     } else {
         infoText = i18n("<small>No additional information available for this character.</small>");
     }
@@ -177,14 +190,14 @@ QString UnicodeDialog::unicodeInfo(QString unicode)
     return infoText;
 }
 
-QString UnicodeDialog::validateText(QString text)
+QString UnicodeWidget::validateText(const QString &text)
 {
     QRegExp regex("([0-9]|[a-f])", Qt::CaseInsensitive, QRegExp::RegExp2);
-    QString newText = "";
+    QString newText;
     int pos = 0;
 
     switch (inputMethod) {
-    case InputHex:
+    case UnicodeDialog::InputHex:
         // Remove all characters we don't want
         while ((pos = regex.indexIn(text, pos)) != -1) {
             newText += regex.cap(1);
@@ -192,7 +205,7 @@ QString UnicodeDialog::validateText(QString text)
         }
         break;
 
-    case InputDec:
+    case UnicodeDialog::InputDec:
         // TODO
         break;
     }
@@ -200,23 +213,23 @@ QString UnicodeDialog::validateText(QString text)
     return newText;
 }
 
-void UnicodeDialog::updateOverviewChars(uint unicode)
+void UnicodeWidget::updateOverviewChars(uint unicode)
 {
-    QString left = "";
-    QString right = "";
+    QString left;
+    QString right;
     uint i;
 
-    for (i = 1; i <= 4; i++) {
+    for (i = 1; i <= 4; ++i) {
         if (unicode > i && !controlCharacter(unicode - i)) {
-            left = " " + left;
+            left = ' ' + left;
             left = QChar(unicode - i) + left;
         }
     }
 
-    for (i = 1; i <= 8; i++) {
+    for (i = 1; i <= 8; ++i) {
         if (unicode + i <= MAX_UNICODE_V1 && !controlCharacter(unicode + i)) {
             right += QChar(unicode + i);
-            right += " ";
+            right += ' ';
         }
     }
 
@@ -225,20 +238,20 @@ void UnicodeDialog::updateOverviewChars(uint unicode)
 
 }
 
-void UnicodeDialog::clearOverviewChars()
+void UnicodeWidget::clearOverviewChars()
 {
     leftChars->setText("");
     rightChars->setText("");
 }
 
-QString UnicodeDialog::nextUnicode(QString text, Direction direction)
+QString UnicodeWidget::nextUnicode(const QString &text, Direction direction)
 {
     uint value = 0;
-    QString newText = "";
+    QString newText;
     bool ok;
 
     switch (inputMethod) {
-    case InputHex:
+    case UnicodeDialog::InputHex:
         value = text.toUInt(&ok, 16);
         switch (direction) {
         case Backward:
@@ -255,14 +268,14 @@ QString UnicodeDialog::nextUnicode(QString text, Direction direction)
         newText.setNum(value, 16);
         break;
 
-    case InputDec:
+    case UnicodeDialog::InputDec:
         break;
     }
 
     return newText;
 }
 
-void UnicodeDialog::readChoices()
+void UnicodeWidget::readChoices()
 {
     // Get a pointer to a shared configuration instance, then get the TitleWidget group.
     KSharedConfigPtr config = KGlobal::config();
@@ -272,7 +285,7 @@ void UnicodeDialog::readChoices()
     m_lastUnicodeNumber = titleConfig.readEntry("unicode_number", QString("2013"));
 }
 
-void UnicodeDialog::writeChoices()
+void UnicodeWidget::writeChoices()
 {
     // Get a pointer to a shared configuration instance, then get the TitleWidget group.
     KSharedConfigPtr config = KGlobal::config();
@@ -287,7 +300,7 @@ void UnicodeDialog::writeChoices()
 /**
  * \brief Validates the entered Unicode number and displays its Unicode character.
  */
-void UnicodeDialog::slotTextChanged(QString text)
+void UnicodeWidget::slotTextChanged(const QString &text)
 {
     unicodeNumber->blockSignals(true);
 
@@ -311,10 +324,10 @@ void UnicodeDialog::slotTextChanged(QString text)
         bool ok;
         uint value = 0;
         switch (inputMethod) {
-        case InputHex:
+        case UnicodeDialog::InputHex:
             value = newText.toUInt(&ok, 16);
             break;
-        case InputDec:
+        case UnicodeDialog::InputDec:
             value = newText.toUInt(&ok, 10);
             break;
         }
@@ -344,26 +357,36 @@ void UnicodeDialog::slotTextChanged(QString text)
  * When return pressed, we return the selected unicode character
  * if it was not a control character.
  */
-void UnicodeDialog::slotReturnPressed()
+void UnicodeWidget::slotReturnPressed()
 {
-    QString text = trimmedUnicodeNumber(unicodeNumber->text());
+    unicodeNumber->setFocus();
+    const QString text = trimmedUnicodeNumber(unicodeNumber->text());
     if (!controlCharacter(text)) {
         emit charSelected(unicodeChar->text());
         writeChoices();
     }
-    emit accept();
 }
 
-void UnicodeDialog::slotNextUnicode()
+void UnicodeWidget::slotNextUnicode()
 {
-    QString text = unicodeNumber->text();
+    const QString text = unicodeNumber->text();
     unicodeNumber->setText(nextUnicode(text, Forward));
 }
 
-void UnicodeDialog::slotPrevUnicode()
+void UnicodeWidget::slotPrevUnicode()
 {
-    QString text = unicodeNumber->text();
+    const QString text = unicodeNumber->text();
     unicodeNumber->setText(nextUnicode(text, Backward));
 }
 
+void UnicodeWidget::wheelEvent(QWheelEvent * event)
+{
+    if (frame->underMouse()) {
+        if (event->delta() > 0)
+            slotNextUnicode();
+        else
+            slotPrevUnicode();
+    }
+}
+
 #include "unicodedialog.moc"