Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Qt6 compatibility #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/core/text/qmsimplevarexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ static QString parseExpression(QString s, const QHash<QString, QString> &vars,
int lastIndex = 0;
while ((index = s.indexOf(reg, index, &match)) != -1) {
hasMatch = true;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(s).sliced(lastIndex, index - lastIndex);
#else
result += s.midRef(lastIndex, index - lastIndex);
#endif

const auto &name = match.captured(1);
QString val;
Expand All @@ -125,7 +129,11 @@ static QString parseExpression(QString s, const QHash<QString, QString> &vars,
index += match.captured(0).size();
lastIndex = index;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(s).sliced(lastIndex);
#else
result += s.midRef(lastIndex);
#endif
s = result;
} while (hasMatch);
s.replace(QStringLiteral("$$"), QStringLiteral("$"));
Expand Down
49 changes: 45 additions & 4 deletions src/widgets/kernel/qmdecoratorv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,14 @@ QString QMDecoratorV2Private::replaceFontSizes(const QString &stylesheet, double
QString result;
result.reserve(stylesheet.size());
while ((index = stylesheet.indexOf(re, index, &match)) != -1) {
result += stylesheet.midRef(lastIndex, index - lastIndex);

QString matchString = match.captured(1);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex, index - lastIndex);
double size = QStringView(matchString).sliced(0, matchString.size() - 2).toDouble();
#else
result += stylesheet.midRef(lastIndex, index - lastIndex);
double size = matchString.midRef(0, matchString.size() - 2).toDouble();
#endif
size *= ratio;
QString valueString = QStringLiteral("font-size: ") +
(rounding ? QString::number(int(size)) : QString::number(size)) +
Expand All @@ -569,7 +573,11 @@ QString QMDecoratorV2Private::replaceFontSizes(const QString &stylesheet, double
index += match.captured().size();
lastIndex = index;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex);
#else
result += stylesheet.midRef(lastIndex);
#endif
return result;
}

Expand All @@ -582,10 +590,15 @@ QString QMDecoratorV2Private::replaceSizes(const QString &stylesheet, double rat
QString result;
result.reserve(stylesheet.size());
while ((index = stylesheet.indexOf(re, index, &match)) != -1) {
result += stylesheet.midRef(lastIndex, index - lastIndex);

QString matchString = match.captured();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex, index - lastIndex);
double size = QStringView(matchString).sliced(0, matchString.size() - 2).toDouble();
#else
result += stylesheet.midRef(lastIndex, index - lastIndex);
double size = matchString.midRef(0, matchString.size() - 2).toDouble();
#endif

size *= ratio;
QString valueString =
(rounding ? QString::number(int(size)) : QString::number(size)) + QStringLiteral("px");
Expand All @@ -594,7 +607,11 @@ QString QMDecoratorV2Private::replaceSizes(const QString &stylesheet, double rat
index += matchString.size();
lastIndex = index;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex);
#else
result += stylesheet.midRef(lastIndex);
#endif
return result;
}

Expand All @@ -610,7 +627,11 @@ QString QMDecoratorV2Private::replaceCustomKeyWithQProperty(const QString &style
QString result;
result.reserve(stylesheet.size());
while ((index = stylesheet.indexOf(re, index, &match)) != -1) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex, index - lastIndex);
#else
result += stylesheet.midRef(lastIndex, index - lastIndex);
#endif

QString matchString = match.captured();
int capturedIndex = match.capturedStart(2) - index;
Expand All @@ -623,7 +644,11 @@ QString QMDecoratorV2Private::replaceCustomKeyWithQProperty(const QString &style
index += matchString.size();
lastIndex = index;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex);
#else
result += stylesheet.midRef(lastIndex);
#endif
return result;
}

Expand All @@ -640,15 +665,23 @@ QString QMDecoratorV2Private::replaceCssGrammars(const QString &stylesheet) {
int index = 0;
int lastIndex = 0;
while ((index = stylesheet.indexOf(re, index, &match)) != -1) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex, index - lastIndex);
#else
result += stylesheet.midRef(lastIndex, index - lastIndex);
#endif

QString matchString = match.captured();
QString valueString = QStringLiteral(":!") + match.captured(1).trimmed();
result += valueString;
index += matchString.size();
lastIndex = index;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex);
#else
result += stylesheet.midRef(lastIndex);
#endif
}

// Replace "svg(...);" to "url(\"[[...]].svgx\");"
Expand All @@ -671,12 +704,20 @@ QString QMDecoratorV2Private::removeAllComments(const QString &stylesheet) {
QString result;
result.reserve(stylesheet.size());
while ((index = stylesheet.indexOf(re, index, &match)) != -1) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex, index - lastIndex);
#else
result += stylesheet.midRef(lastIndex, index - lastIndex);
#endif

index += match.captured(0).size();
lastIndex = index;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex);
#else
result += stylesheet.midRef(lastIndex);
#endif
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/widgets/cmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ class CMenuPrivate : public QObject {
DwmSetWindowAttribute(reinterpret_cast<HWND>(this->q->winId()),
DWMWA_WINDOW_CORNER_PREFERENCE_, &dwcp, sizeof(dwcp));
// Disconnect this connection, don't run again
disconnect(q, &CMenu::aboutToShow, this, &CMenuPrivate::_q_menuFirstAboutToShow);
// disconnect(q, &CMenu::aboutToShow, this, &CMenuPrivate::_q_menuFirstAboutToShow);
}
#endif
};
Expand Down
16 changes: 12 additions & 4 deletions src/widgets/widgettools/cnavframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ CNavFrame::CNavFrame(QWidget *parent) : QFrame(parent), d_ptr(new CNavFramePriva

// Left
d->buttonLayout = new QVBoxLayout();
d->buttonLayout->setMargin(0);
d->buttonLayout->setSpacing(0);

d->leftLayout = new QVBoxLayout();
d->leftLayout->setMargin(0);
d->leftLayout->setSpacing(0);

d->leftLayout->addLayout(d->buttonLayout);
Expand All @@ -67,7 +65,6 @@ CNavFrame::CNavFrame(QWidget *parent) : QFrame(parent), d_ptr(new CNavFramePriva

// Right
d->stack = new QStackedLayout();
d->stack->setMargin(0);

d->rightFrame = new QFrame();
d->rightFrame->setObjectName("right-frame");
Expand All @@ -84,9 +81,20 @@ CNavFrame::CNavFrame(QWidget *parent) : QFrame(parent), d_ptr(new CNavFramePriva
d->splitter->setStretchFactor(1, 1);

d->layout = new QHBoxLayout();
d->layout->setMargin(0);
d->layout->setSpacing(0);

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
d->buttonLayout->setContentsMargins({});
d->leftLayout->setContentsMargins({});
d->stack->setContentsMargins({});
d->layout->setContentsMargins({});
#else
d->buttonLayout->setMargin(0);
d->leftLayout->setMargin(0);
d->stack->setMargin(0);
d->layout->setMargin(0);
#endif

d->layout->addWidget(d->splitter);
setLayout(d->layout);

Expand Down