Merge pull request #3256 from 0penBrain/spinBoxDecPoint
[Gui] Allow dot as decimal separator for locales not using it as thousand separator
This commit is contained in:
@@ -2080,6 +2080,12 @@ void Application::runApplication(void)
|
||||
WheelEventFilter* filter = new WheelEventFilter(&mainApp);
|
||||
mainApp.installEventFilter(filter);
|
||||
}
|
||||
|
||||
//filter keyboard events to substitute decimal separator
|
||||
if (hGrp->GetBool("SubstituteDecimalSeparator", false)) {
|
||||
KeyboardFilter* filter = new KeyboardFilter(&mainApp);
|
||||
mainApp.installEventFilter(filter);
|
||||
}
|
||||
|
||||
#if defined(HAVE_QT5_OPENGL)
|
||||
{
|
||||
|
||||
@@ -26,12 +26,14 @@
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
# include <stdexcept>
|
||||
# include <QAbstractSpinBox>
|
||||
# include <QByteArray>
|
||||
# include <QComboBox>
|
||||
# include <QDataStream>
|
||||
# include <QDebug>
|
||||
# include <QFileInfo>
|
||||
# include <QFileOpenEvent>
|
||||
# include <QKeyEvent>
|
||||
# include <QSessionManager>
|
||||
# include <QTimer>
|
||||
#endif
|
||||
@@ -323,5 +325,29 @@ bool WheelEventFilter::eventFilter(QObject* obj, QEvent* ev)
|
||||
return false;
|
||||
}
|
||||
|
||||
KeyboardFilter::KeyboardFilter(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool KeyboardFilter::eventFilter(QObject* obj, QEvent* ev)
|
||||
{
|
||||
if (ev->type() == QEvent::KeyPress || ev->type() == QEvent::KeyRelease) {
|
||||
QKeyEvent *kev = static_cast<QKeyEvent *>(ev);
|
||||
QAbstractSpinBox *target = dynamic_cast<QAbstractSpinBox *>(obj);
|
||||
if (kev->key() == Qt::Key_Period && target)
|
||||
{
|
||||
QChar decimalPoint = QLocale().decimalPoint();
|
||||
QChar groupSeparator = QLocale().groupSeparator();
|
||||
if (decimalPoint != Qt::Key_Period && (groupSeparator != Qt::Key_Period || (kev->modifiers() & Qt::KeypadModifier))) {
|
||||
QKeyEvent modifiedKeyEvent(kev->type(), decimalPoint.digitValue(), kev->modifiers(), QString(decimalPoint), kev->isAutoRepeat(), kev->count());
|
||||
qApp->sendEvent(obj, &modifiedKeyEvent);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#include "moc_GuiApplication.cpp"
|
||||
|
||||
@@ -92,6 +92,15 @@ public:
|
||||
bool eventFilter(QObject* obj, QEvent* ev);
|
||||
};
|
||||
|
||||
class KeyboardFilter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
KeyboardFilter(QObject* parent);
|
||||
bool eventFilter(QObject* obj, QEvent* ev);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // GUI_APPLICATION_H
|
||||
|
||||
Reference in New Issue
Block a user