Skip to content

Commit

Permalink
Fixed Qt6 build issues, fixed wrong calculation of rgba value with sm…
Browse files Browse the repository at this point in the history
…all opacity value (0xCFFFFFF instead of 0x0CFFFFFF)
  • Loading branch information
githubuser0xFFFF committed Nov 22, 2023
1 parent 061247e commit a18634b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/QmlStyleUrlInterceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "QmlStyleUrlInterceptor.h"

#include <QDebug>
#include <QUrl>

#include "QtAdvancedStylesheet.h"

Expand Down
23 changes: 9 additions & 14 deletions src/QtAdvancedStylesheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include <QSvgRenderer>
#include <QPainter>
#include <QSet>
#include <QStringView>


namespace acss
Expand Down Expand Up @@ -387,7 +386,7 @@ QString QtAdvancedStylesheetPrivate::rgbaColor(const QString& RgbColor, float Op
{
int Alpha = 255 * Opacity;
auto RgbaColor = RgbColor;
RgbaColor.insert(1, QString::number(Alpha, 16));
RgbaColor.insert(1, QString("%1").arg(Alpha, 2, 16, QChar('0')));
return RgbaColor;
}

Expand All @@ -405,25 +404,21 @@ void QtAdvancedStylesheetPrivate::replaceStylesheetVariables(QString& Content)
QString ValueString;
QString MatchString = match.captured();
// Use only the value inside of the brackets {{ }} without the brackets
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
auto TemplateVariable = MatchString.midRef(2, MatchString.size() - 4);
#else
auto TemplateVariable = QStringView(MatchString).sliced(2, MatchString.size() - 4);
#endif
auto TemplateVariable = MatchString.mid(2, MatchString.size() - 4);
bool HasOpacity = TemplateVariable.endsWith(')');

if (HasOpacity)
{
auto Values = TemplateVariable.split(QChar('|'));
ValueString = _this->themeVariableValue(Values[0].toString());
auto Values = TemplateVariable.split("|");
ValueString = _this->themeVariableValue(Values[0]);
auto OpacityStr = Values[1].mid(OpacityStrSize, Values[1].size() - OpacityStrSize - 1);
bool Ok;
auto Opacity = OpacityStr.toFloat(&Ok);
ValueString = rgbaColor(ValueString, Opacity);
}
else
{
ValueString = _this->themeVariableValue(TemplateVariable.toString());
ValueString = _this->themeVariableValue(TemplateVariable);
}

Content.replace(index, MatchString.size(), ValueString);
Expand Down Expand Up @@ -530,7 +525,7 @@ bool QtAdvancedStylesheetPrivate::parseVariablesFromXml(
if (s.name() != TagName)
{
setError(QtAdvancedStylesheet::ThemeXmlError, "Malformed theme "
"file - expected tag <" + TagName + "> instead of " + s.name().toString());
"file - expected tag <" + TagName + "> instead of " + s.name().toString());
return false;
}
auto Name = s.attributes().value("name");
Expand Down Expand Up @@ -563,11 +558,11 @@ bool QtAdvancedStylesheetPrivate::parseThemeFile(const QString& Theme)
QFile ThemeFile(ThemeFileName);
ThemeFile.open(QIODevice::ReadOnly);
QXmlStreamReader s(&ThemeFile);
s.readNextStartElement();
if (s.name() != QLatin1String("resources"))
s.readNextStartElement();
if (s.name() != QString("resources"))
{
setError(QtAdvancedStylesheet::ThemeXmlError, "Malformed theme file - "
"expected tag <resources> instead of " + s.name().toString());
"expected tag <resources> instead of " + s.name().toString());
return false;
}

Expand Down

0 comments on commit a18634b

Please sign in to comment.