/// CONSTANTS
const int MAX_LENGTH_HEX = 4;
+const uint MAX_UNICODE_V1 = 65535;
/// CONSTRUCTORS/DECONSTRUCTORS
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:
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()
/// METHODS
+void UnicodeDialog::showLastUnicode()
+{
+ unicodeNumber->setText(lastUnicodeNumber);
+}
+
bool UnicodeDialog::controlCharacter(QString text)
{
bool isControlCharacter = false;
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')) {
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–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>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 &thinsp;. See <a href=\"http://en.wikipedia.org/wiki/Space_(punctuation)\">Wikipedia:Space_(punctuation)</a>");
+ infoText = i18n("Thin space, in HTML also &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") {
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;
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
{
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);
}
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"
<rect>
<x>0</x>
<y>0</y>
- <width>614</width>
- <height>315</height>
+ <width>576</width>
+ <height>211</height>
</rect>
</property>
<property name="windowTitle">
</property>
</widget>
</item>
- <item row="0" column="2">
+ <item row="0" column="4">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</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">
</property>
</widget>
</item>
- <item row="0" column="6">
+ <item row="0" column="10">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</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>