diff --git a/src/Gui/DlgEditorImp.cpp b/src/Gui/DlgEditorImp.cpp index d5056d56fd..d7d39a38f6 100644 --- a/src/Gui/DlgEditorImp.cpp +++ b/src/Gui/DlgEditorImp.cpp @@ -247,8 +247,11 @@ void DlgSettingsEditorImp::loadSettings() QByteArray fontName = this->font().family().toLatin1(); - QFontDatabase fdb; - QStringList familyNames = fdb.families( QFontDatabase::Any ); +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) + QStringList familyNames = QFontDatabase().families(QFontDatabase::Any); +#else + QStringList familyNames = QFontDatabase::families(QFontDatabase::Any); +#endif ui->fontFamily->addItems(familyNames); int index = familyNames.indexOf(QString::fromLatin1(hGrp->GetASCII("Font", fontName).c_str())); if (index < 0) index = 0; diff --git a/src/Gui/InputField.cpp b/src/Gui/InputField.cpp index b05c8407f5..416ea6f570 100644 --- a/src/Gui/InputField.cpp +++ b/src/Gui/InputField.cpp @@ -26,6 +26,8 @@ # include # include # include +# include +# include #endif #include @@ -597,30 +599,16 @@ void InputField::setHistorySize(int i) void InputField::selectNumber() { - QString str = text(); - unsigned int i = 0; - - QChar d = locale().decimalPoint(); - QChar g = locale().groupSeparator(); - QChar n = locale().negativeSign(); - QChar e = locale().exponential(); - - for (const auto & it : str) { - if (it.isDigit()) - i++; - else if (it == d) - i++; - else if (it == g) - i++; - else if (it == n) - i++; - else if (it == e && actQuantity.getFormat().format != Base::QuantityFormat::Fixed) - i++; - else // any non-number character - break; + QString expr = QString::fromLatin1("^([%1%2]?[0-9\\%3]*)\\%4?([0-9]+(%5[%1%2]?[0-9]+)?)") + .arg(locale().negativeSign()) + .arg(locale().positiveSign()) + .arg(locale().groupSeparator()) + .arg(locale().decimalPoint()) + .arg(locale().exponential()); + auto rmatch = QRegularExpression(expr).match(text()); + if (rmatch.hasMatch()) { + setSelection(0, rmatch.capturedLength()); } - - setSelection(0, i); } void InputField::showEvent(QShowEvent * event) @@ -732,10 +720,18 @@ void InputField::wheelEvent (QWheelEvent * event) void InputField::fixup(QString& input) const { input.remove(locale().groupSeparator()); - if (locale().negativeSign() != QLatin1Char('-')) - input.replace(locale().negativeSign(), QLatin1Char('-')); - if (locale().positiveSign() != QLatin1Char('+')) - input.replace(locale().positiveSign(), QLatin1Char('+')); + + QString asciiMinus(QStringLiteral("-")); + QString localeMinus(locale().negativeSign()); + if (localeMinus != asciiMinus) { + input.replace(localeMinus, asciiMinus); + } + + QString asciiPlus(QStringLiteral("+")); + QString localePlus(locale().positiveSign()); + if (localePlus != asciiPlus) { + input.replace(localePlus, asciiPlus); + } } QValidator::State InputField::validate(QString& input, int& pos) const diff --git a/src/Gui/NaviCube.cpp b/src/Gui/NaviCube.cpp index 4938d2d774..99433ee876 100644 --- a/src/Gui/NaviCube.cpp +++ b/src/Gui/NaviCube.cpp @@ -362,6 +362,26 @@ char* NaviCubeImplementation::enum2str(int e) { } } +auto convertWeights = [](int weight) -> QFont::Weight { + if (weight >= 87) + return QFont::Black; + if (weight >= 81) + return QFont::ExtraBold; + if (weight >= 75) + return QFont::Bold; + if (weight >= 63) + return QFont::DemiBold; + if (weight >= 57) + return QFont::Medium; + if (weight >= 50) + return QFont::Normal; + if (weight >= 25) + return QFont::Light; + if (weight >= 12) + return QFont::ExtraLight; + return QFont::Thin; +}; + GLuint NaviCubeImplementation::createCubeFaceTex(QtGLWidget* gl, float gap, const char* text, int shape) { int texSize = m_CubeWidgetSize * m_OverSample; float gapi = texSize * gap; @@ -379,7 +399,7 @@ GLuint NaviCubeImplementation::createCubeFaceTex(QtGLWidget* gl, float gap, cons QString fontString = QString::fromUtf8((hGrp->GetASCII("FontString")).c_str()); if (fontString.isEmpty()) { // Improving readability - sansFont.setWeight(hGrp->GetInt("FontWeight", 87)); + sansFont.setWeight(convertWeights(hGrp->GetInt("FontWeight", 87))); sansFont.setStretch(hGrp->GetInt("FontStretch", 62)); } else { @@ -387,7 +407,7 @@ GLuint NaviCubeImplementation::createCubeFaceTex(QtGLWidget* gl, float gap, cons } // Override fromString if (hGrp->GetInt("FontWeight") > 0) { - sansFont.setWeight(hGrp->GetInt("FontWeight")); + sansFont.setWeight(convertWeights(hGrp->GetInt("FontWeight"))); } if (hGrp->GetInt("FontStretch") > 0) { sansFont.setStretch(hGrp->GetInt("FontStretch")); diff --git a/src/Gui/QuantitySpinBox.cpp b/src/Gui/QuantitySpinBox.cpp index a28b184859..b71b943a0a 100644 --- a/src/Gui/QuantitySpinBox.cpp +++ b/src/Gui/QuantitySpinBox.cpp @@ -28,6 +28,8 @@ # include # include # include +# include +# include # include # include # include @@ -848,27 +850,16 @@ void QuantitySpinBox::clear() void QuantitySpinBox::selectNumber() { - QString str = lineEdit()->text(); - unsigned int i = 0; - - QChar d = locale().decimalPoint(); - QChar g = locale().groupSeparator(); - QChar n = locale().negativeSign(); - - for (auto it : str) { - if (it.isDigit()) - i++; - else if (it == d) - i++; - else if (it == g) - i++; - else if (it == n) - i++; - else // any non-number character - break; + QString expr = QString::fromLatin1("^([%1%2]?[0-9\\%3]*)\\%4?([0-9]+(%5[%1%2]?[0-9]+)?)") + .arg(locale().negativeSign()) + .arg(locale().positiveSign()) + .arg(locale().groupSeparator()) + .arg(locale().decimalPoint()) + .arg(locale().exponential()); + auto rmatch = QRegularExpression(expr).match(lineEdit()->text()); + if (rmatch.hasMatch()) { + lineEdit()->setSelection(0, rmatch.capturedLength()); } - - lineEdit()->setSelection(0, i); } QString QuantitySpinBox::textFromValue(const Base::Quantity& value) const diff --git a/src/Gui/SpaceballEvent.cpp b/src/Gui/SpaceballEvent.cpp index 61d4c0abae..7c4b004376 100644 --- a/src/Gui/SpaceballEvent.cpp +++ b/src/Gui/SpaceballEvent.cpp @@ -30,7 +30,11 @@ using namespace Spaceball; int MotionEvent::MotionEventType = -1; int ButtonEvent::ButtonEventType = -1; +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) EventBase::EventBase(QEvent::Type event) : QInputEvent(static_cast(event)), handled(false) +#else +EventBase::EventBase(QEvent::Type event) : QInputEvent(static_cast(event), QPointingDevice::primaryPointingDevice()), handled(false) +#endif { } diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index eb55747ca5..d3bf6e2f82 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -4776,7 +4776,13 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon& icon1, QIcon& icon2 // get the original icon set QIcon icon_org = object()->getIcon(); +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) int w = getTree()->viewOptions().decorationSize.width(); +#else + QStyleOptionViewItem opt; + getTree()->initViewItemOption(&opt); + int w = opt.decorationSize.width(); +#endif QPixmap pxOn, pxOff; diff --git a/src/Gui/propertyeditor/PropertyEditor.cpp b/src/Gui/propertyeditor/PropertyEditor.cpp index 9c3b89ab68..0e3ef5ab7d 100644 --- a/src/Gui/propertyeditor/PropertyEditor.cpp +++ b/src/Gui/propertyeditor/PropertyEditor.cpp @@ -74,7 +74,12 @@ PropertyEditor::PropertyEditor(QWidget *parent) setRootIsDecorated(false); setExpandsOnDoubleClick(true); +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) QStyleOptionViewItem opt = viewOptions(); +#else + QStyleOptionViewItem opt; + initViewItemOption(&opt); +#endif this->background = opt.palette.dark(); this->groupColor = opt.palette.color(QPalette::BrightText); @@ -151,12 +156,20 @@ void PropertyEditor::setGroupTextColor(const QColor& c) this->groupColor = c; } +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) QStyleOptionViewItem PropertyEditor::viewOptions() const { QStyleOptionViewItem option = QTreeView::viewOptions(); option.showDecorationSelected = true; return option; } +#else +void PropertyEditor::initViewItemOption(QStyleOptionViewItem *option) const +{ + QTreeView::initViewItemOption(option); + option->showDecorationSelected = true; +} +#endif bool PropertyEditor::event(QEvent* event) { @@ -498,7 +511,12 @@ void PropertyEditor::drawBranches(QPainter *painter, const QRect &rect, const QM { QTreeView::drawBranches(painter, rect, index); - QStyleOptionViewItem opt = viewOptions(); +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) + //QStyleOptionViewItem opt = viewOptions(); +#else + //QStyleOptionViewItem opt; + //initViewItemOption(&opt); +#endif auto property = static_cast(index.internalPointer()); if (property && property->isSeparator()) { painter->fillRect(rect, this->background); diff --git a/src/Gui/propertyeditor/PropertyEditor.h b/src/Gui/propertyeditor/PropertyEditor.h index f8b21ca329..e3e97b39f3 100644 --- a/src/Gui/propertyeditor/PropertyEditor.h +++ b/src/Gui/propertyeditor/PropertyEditor.h @@ -104,7 +104,11 @@ protected: void rowsInserted (const QModelIndex & parent, int start, int end) override; void rowsAboutToBeRemoved (const QModelIndex & parent, int start, int end) override; void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const override; +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) QStyleOptionViewItem viewOptions() const override; +#else + void initViewItemOption(QStyleOptionViewItem *option) const override; +#endif void contextMenuEvent(QContextMenuEvent *event) override; bool event(QEvent*) override; diff --git a/src/Tools/plugins/widget/customwidgets.cpp b/src/Tools/plugins/widget/customwidgets.cpp index b31ecae8f7..fd3952d5aa 100644 --- a/src/Tools/plugins/widget/customwidgets.cpp +++ b/src/Tools/plugins/widget/customwidgets.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include #include @@ -1290,27 +1292,16 @@ void QuantitySpinBox::clear() void QuantitySpinBox::selectNumber() { - QString str = lineEdit()->text(); - unsigned int i = 0; - - QChar d = locale().decimalPoint(); - QChar g = locale().groupSeparator(); - QChar n = locale().negativeSign(); - - for (QString::iterator it = str.begin(); it != str.end(); ++it) { - if (it->isDigit()) - i++; - else if (*it == d) - i++; - else if (*it == g) - i++; - else if (*it == n) - i++; - else // any non-number character - break; + QString expr = QString::fromLatin1("^([%1%2]?[0-9\\%3]*)\\%4?([0-9]+(%5[%1%2]?[0-9]+)?)") + .arg(locale().negativeSign()) + .arg(locale().positiveSign()) + .arg(locale().groupSeparator()) + .arg(locale().decimalPoint()) + .arg(locale().exponential()); + auto rmatch = QRegularExpression(expr).match(lineEdit()->text()); + if (rmatch.hasMatch()) { + lineEdit()->setSelection(0, rmatch.capturedLength()); } - - lineEdit()->setSelection(0, i); } QString QuantitySpinBox::textFromValue(const Base::Quantity& value) const