Qt6 port:
* Constructor of QFontDatabase is deprecated, use static functions instead * Fix QuantitySpinBox::selectNumber() * Fix InputField::selectNumber() * Make InputField::fixup() compatible with Qt6 * QFont::setWeight requires an enum now * QInputEvent reuires a pointing device now * QAbstractItemView::viewOptions() has been renamed to QAbstractItemView::initViewItemOption()
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
# include <QContextMenuEvent>
|
||||
# include <QMenu>
|
||||
# include <QPixmapCache>
|
||||
# include <QRegularExpression>
|
||||
# include <QRegularExpressionMatch>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
@@ -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
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
# include <QFocusEvent>
|
||||
# include <QFontMetrics>
|
||||
# include <QLineEdit>
|
||||
# include <QRegularExpression>
|
||||
# include <QRegularExpressionMatch>
|
||||
# include <QStyle>
|
||||
# include <QStyleOptionSpinBox>
|
||||
# include <QToolTip>
|
||||
@@ -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
|
||||
|
||||
@@ -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<QEvent::Type>(event)), handled(false)
|
||||
#else
|
||||
EventBase::EventBase(QEvent::Type event) : QInputEvent(static_cast<QEvent::Type>(event), QPointingDevice::primaryPointingDevice()), handled(false)
|
||||
#endif
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<PropertyItem*>(index.internalPointer());
|
||||
if (property && property->isSeparator()) {
|
||||
painter->fillRect(rect, this->background);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include <QFileDialog>
|
||||
#include <QHeaderView>
|
||||
#include <QMessageBox>
|
||||
#include <QRegularExpression>
|
||||
#include <QRegularExpressionMatch>
|
||||
#include <QStyleOptionButton>
|
||||
#include <QStylePainter>
|
||||
#include <QToolTip>
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user