From: Simon A. Eugster Date: Thu, 18 Jun 2009 15:46:40 +0000 (+0000) Subject: Unicode Dialog extended (character list, shortcuts for next/prev character, test... X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=c08d0c1b8e25e14fe7be93c3e18ec53de9f56ba4;p=kdenlive Unicode Dialog extended (character list, shortcuts for next/prev character, test for control character, ... svn path=/trunk/kdenlive/; revision=3575 --- diff --git a/icons/hi16-action-kdenlive-insert-unicode.png b/icons/hi16-action-kdenlive-insert-unicode.png index ec47bea7..ec52a739 100644 Binary files a/icons/hi16-action-kdenlive-insert-unicode.png and b/icons/hi16-action-kdenlive-insert-unicode.png differ diff --git a/icons/hisc-action-kdenlive-insert-unicode.svgz b/icons/hisc-action-kdenlive-insert-unicode.svgz index 68525a0f..1c690e47 100644 Binary files a/icons/hisc-action-kdenlive-insert-unicode.svgz and b/icons/hisc-action-kdenlive-insert-unicode.svgz differ diff --git a/icons/ox16-action-kdenlive-insert-unicode.png b/icons/ox16-action-kdenlive-insert-unicode.png index ec47bea7..ec52a739 100644 Binary files a/icons/ox16-action-kdenlive-insert-unicode.png and b/icons/ox16-action-kdenlive-insert-unicode.png differ diff --git a/icons/oxsc-action-kdenlive-insert-unicode.svgz b/icons/oxsc-action-kdenlive-insert-unicode.svgz index 68525a0f..1c690e47 100644 Binary files a/icons/oxsc-action-kdenlive-insert-unicode.svgz and b/icons/oxsc-action-kdenlive-insert-unicode.svgz differ diff --git a/src/titlewidget.cpp b/src/titlewidget.cpp index 6902bd32..023e6ff5 100644 --- a/src/titlewidget.cpp +++ b/src/titlewidget.cpp @@ -929,6 +929,7 @@ void TitleWidget::textChanged(QGraphicsTextItem *i) { void TitleWidget::slotInsertUnicode() { + m_unicodeDialog->showLastUnicode(); m_unicodeDialog->exec(); } diff --git a/src/unicodedialog.cpp b/src/unicodedialog.cpp index c676d578..1f588b05 100644 --- a/src/unicodedialog.cpp +++ b/src/unicodedialog.cpp @@ -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("(no character selected)")); + 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 Wikipedia:Control_character"); + } 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–200b)"); + } else if (u == "a0") { + infoText = i18n("No-break space. &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"); + } else if (u == "2005") { + infoText = i18n("Four-Per-Em Space. Width: 1/4 of one em"); + } else if (u == "2006") { + infoText = i18n("Six-Per-Em Space. Width: 1/6 of one 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 &thinsp;. See Wikipedia:Space_(punctuation)"); + infoText = i18n("Thin space, in HTML also &thinsp;. See Wikipedia:Space_(punctuation)"); + } 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 Wikipedia:Apostrophe"); } 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 Wikipedia:Dash"); } else if (u == "2026") { infoText = i18n("Ellipsis: If text has been left out. See Wikipedia:Ellipsis"); + } else { + infoText = i18n("No additional information available for this character."); } 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" diff --git a/src/unicodedialog.h b/src/unicodedialog.h index 52abd3f7..697cee96 100644 --- a/src/unicodedialog.h +++ b/src/unicodedialog.h @@ -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(); }; diff --git a/src/widgets/unicodedialog_ui.ui b/src/widgets/unicodedialog_ui.ui index 9f6fc905..07f3c4e1 100644 --- a/src/widgets/unicodedialog_ui.ui +++ b/src/widgets/unicodedialog_ui.ui @@ -6,8 +6,8 @@ 0 0 - 614 - 315 + 576 + 211 @@ -47,7 +47,7 @@ - + Qt::Horizontal @@ -60,7 +60,7 @@ - + @@ -78,7 +78,7 @@ - + Qt::Horizontal @@ -91,7 +91,7 @@ - + Qt::Horizontal @@ -107,17 +107,11 @@ - + 0 0 - - - 12 - 0 - - 15 @@ -129,22 +123,53 @@ + + 7 + - - + + Qt::Vertical - - + + Qt::Vertical + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + @@ -203,7 +228,7 @@ - Additional Information: + Additional Information @@ -226,6 +251,13 @@ + + + KArrowButton + QPushButton +
karrowbutton.h
+
+