Commit 7a74d9ca authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Use a real dialogbox so we understand how to cancel/accept unicode characters...

Use a real dialogbox so we understand how to cancel/accept unicode characters (ok I saw press enter in code but not easy for new user)
parent 7ac877ea
......@@ -249,7 +249,7 @@ kde4_add_ui_files(kdenlive_UIS
widgets/trackheader_ui.ui
widgets/tracksconfigdialog_ui.ui
widgets/transitionsettings_ui.ui
widgets/unicodedialog_ui.ui
widgets/unicodewidget_ui.ui
widgets/urlval_ui.ui
widgets/vectorscope_ui.ui
widgets/waveform_ui.ui
......
......@@ -17,9 +17,32 @@ 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)
{
......@@ -32,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;
}
......@@ -50,36 +73,27 @@ UnicodeDialog::UnicodeDialog(InputMethod inputMeth) :
}
UnicodeDialog::~UnicodeDialog()
{
}
/// PUBLIC SLOTS
int UnicodeDialog::exec()
UnicodeWidget::~UnicodeWidget()
{
unicodeNumber->setFocus();
return QDialog::exec();
}
/// METHODS
void UnicodeDialog::showLastUnicode()
void UnicodeWidget::showLastUnicode()
{
unicodeNumber->setText(m_lastUnicodeNumber);
unicodeNumber->selectAll();
slotTextChanged(m_lastUnicodeNumber);
}
bool UnicodeDialog::controlCharacter(const QString &text)
bool UnicodeWidget::controlCharacter(const QString &text)
{
bool isControlCharacter = false;
QString t = text.toLower();
switch (inputMethod) {
case InputHex:
case UnicodeDialog::InputHex:
if (t.isEmpty()
|| (t.length() == 1 && !(t == "9" || t == "a" || t == "d"))
|| (t.length() == 2 && t.at(0) == QChar('1'))) {
......@@ -87,7 +101,7 @@ bool UnicodeDialog::controlCharacter(const QString &text)
}
break;
case InputDec:
case UnicodeDialog::InputDec:
bool ok;
isControlCharacter = controlCharacter(text.toUInt(&ok, 16));
break;
......@@ -96,7 +110,7 @@ bool UnicodeDialog::controlCharacter(const QString &text)
return isControlCharacter;
}
bool UnicodeDialog::controlCharacter(uint value)
bool UnicodeWidget::controlCharacter(uint value)
{
bool isControlCharacter = false;
......@@ -107,7 +121,7 @@ bool UnicodeDialog::controlCharacter(uint value)
}
QString UnicodeDialog::trimmedUnicodeNumber(QString text)
QString UnicodeWidget::trimmedUnicodeNumber(QString text)
{
while (text.length() > 0 && text.at(0) == QChar('0')) {
text = text.remove(0, 1);
......@@ -115,7 +129,7 @@ QString UnicodeDialog::trimmedUnicodeNumber(QString text)
return text;
}
QString UnicodeDialog::unicodeInfo(const QString &unicode)
QString UnicodeWidget::unicodeInfo(const QString &unicode)
{
QString infoText(i18n("<small>(no character selected)</small>"));
if (unicode.length() == 0) return infoText;
......@@ -179,14 +193,14 @@ QString UnicodeDialog::unicodeInfo(const QString &unicode)
return infoText;
}
QString UnicodeDialog::validateText(const QString &text)
QString UnicodeWidget::validateText(const QString &text)
{
QRegExp regex("([0-9]|[a-f])", Qt::CaseInsensitive, QRegExp::RegExp2);
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);
......@@ -194,7 +208,7 @@ QString UnicodeDialog::validateText(const QString &text)
}
break;
case InputDec:
case UnicodeDialog::InputDec:
// TODO
break;
}
......@@ -202,7 +216,7 @@ QString UnicodeDialog::validateText(const QString &text)
return newText;
}
void UnicodeDialog::updateOverviewChars(uint unicode)
void UnicodeWidget::updateOverviewChars(uint unicode)
{
QString left;
QString right;
......@@ -227,20 +241,20 @@ void UnicodeDialog::updateOverviewChars(uint unicode)
}
void UnicodeDialog::clearOverviewChars()
void UnicodeWidget::clearOverviewChars()
{
leftChars->setText("");
rightChars->setText("");
}
QString UnicodeDialog::nextUnicode(const 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:
......@@ -257,14 +271,14 @@ QString UnicodeDialog::nextUnicode(const 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();
......@@ -274,7 +288,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();
......@@ -289,7 +303,7 @@ void UnicodeDialog::writeChoices()
/**
* \brief Validates the entered Unicode number and displays its Unicode character.
*/
void UnicodeDialog::slotTextChanged(const QString &text)
void UnicodeWidget::slotTextChanged(const QString &text)
{
unicodeNumber->blockSignals(true);
......@@ -313,10 +327,10 @@ void UnicodeDialog::slotTextChanged(const 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;
}
......@@ -346,33 +360,35 @@ void UnicodeDialog::slotTextChanged(const 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 UnicodeDialog::wheelEvent(QWheelEvent * event)
void UnicodeWidget::wheelEvent(QWheelEvent * event)
{
if (frame->underMouse()) {
if (event->delta() > 0) slotNextUnicode();
else slotPrevUnicode();
if (event->delta() > 0)
slotNextUnicode();
else
slotPrevUnicode();
}
}
......
......@@ -10,38 +10,52 @@
#ifndef UNICODEDIALOG_H
#define UNICODEDIALOG_H
#include "ui_unicodedialog_ui.h"
class UnicodeDialog : public QDialog, public Ui::UnicodeDialog_UI
#include "ui_unicodewidget_ui.h"
#include <KDialog>
class UnicodeWidget;
class UnicodeDialog : public KDialog
{
Q_OBJECT
public:
/** \brief The input method for the dialog. Atm only InputHex supported. */
enum InputMethod { InputHex, InputDec };
UnicodeDialog(InputMethod inputMeth);
explicit UnicodeDialog(InputMethod inputMeth, QWidget *parent = 0);
~UnicodeDialog();
private Q_SLOTS:
void slotAccept();
Q_SIGNALS:
/** \brief Contains the selected unicode character; emitted when Enter is pressed. */
void charSelected(const QString&);
private:
UnicodeWidget *mUnicodeWidget;
};
class UnicodeWidget : public QWidget, public Ui::UnicodeWidget_UI
{
Q_OBJECT
public:
explicit UnicodeWidget(UnicodeDialog::InputMethod inputMeth, QWidget *parent = 0);
~UnicodeWidget();
/** \brief Returns infos about a unicode number. Extendable/improvable ;) */
QString unicodeInfo(const QString &unicode);
void showLastUnicode();
protected:
virtual void wheelEvent(QWheelEvent * event);
public slots:
/** \brief Override QDialog::exec() to assure the focus being on the unicode input field */
int exec();
void wheelEvent(QWheelEvent * event);
private:
Ui::UnicodeDialog_UI m_view;
Ui::UnicodeWidget_UI m_view;
enum Direction { Forward, Backward };
/** Selected input method */
InputMethod inputMethod;
UnicodeDialog::InputMethod inputMethod;
/** \brief Validates text and removes all invalid characters (non-hex e.g.) */
QString validateText(const QString &text);
......@@ -71,12 +85,15 @@ signals:
/** \brief Contains the selected unicode character; emitted when Enter is pressed. */
void charSelected(const QString&);
public slots:
void slotReturnPressed();
private slots:
void slotTextChanged(const QString &text);
void slotReturnPressed();
void slotNextUnicode();
void slotPrevUnicode();
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UnicodeDialog_UI</class>
<widget class="QDialog" name="UnicodeDialog_UI">
<class>UnicodeWidget_UI</class>
<widget class="QWidget" name="UnicodeWidget_UI">
<property name="geometry">
<rect>
<x>0</x>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment