forked from qt-creator/qt-creator
QmlDesigner: Fix for styles ComboBox
- New styles; - Rework to be more reliable with complex names. Task-number: QDS-4750 Change-Id: I63d89575540a463e8b6786c82a28effa185f10c5 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Aleksei German <aleksei.german@qt.io>
This commit is contained in:
@@ -48,6 +48,24 @@ static QString styleConfigFileName(const QString &qmlFileName)
|
|||||||
|
|
||||||
ChangeStyleWidgetAction::ChangeStyleWidgetAction(QObject *parent) : QWidgetAction(parent)
|
ChangeStyleWidgetAction::ChangeStyleWidgetAction(QObject *parent) : QWidgetAction(parent)
|
||||||
{
|
{
|
||||||
|
// The Default style was renamed to Basic in Qt 6. In Qt 6, "Default"
|
||||||
|
// will result in a platform-specific style being chosen.
|
||||||
|
items = {
|
||||||
|
{"Basic", "Basic", {}},
|
||||||
|
{"Default", "Default", {}},
|
||||||
|
{"Fusion", "Fusion", {}},
|
||||||
|
{"Imagine", "Imagine", {}},
|
||||||
|
{"Material Light", "Material", "Light"},
|
||||||
|
{"Material Dark", "Material", "Dark"},
|
||||||
|
{"Universal Light", "Universal", "Light"},
|
||||||
|
{"Universal Dark", "Universal", "Dark"},
|
||||||
|
{"Universal System", "Universal", "System"}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (Utils::HostOsInfo::isMacHost())
|
||||||
|
items.append({"macOS", "macOS", {}});
|
||||||
|
if (Utils::HostOsInfo::isWindowsHost())
|
||||||
|
items.append({"Windows", "Windows", {}});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChangeStyleWidgetAction::handleModelUpdate(const QString &style)
|
void ChangeStyleWidgetAction::handleModelUpdate(const QString &style)
|
||||||
@@ -55,6 +73,48 @@ void ChangeStyleWidgetAction::handleModelUpdate(const QString &style)
|
|||||||
emit modelUpdated(style);
|
emit modelUpdated(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QList<StyleWidgetEntry> ChangeStyleWidgetAction::styleItems() const
|
||||||
|
{
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChangeStyleWidgetAction::changeStyle(const QString &style)
|
||||||
|
{
|
||||||
|
if (style.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
const Utils::FilePath configFileName = Utils::FilePath::fromString(styleConfigFileName(qmlFileName));
|
||||||
|
|
||||||
|
if (configFileName.exists()) {
|
||||||
|
QSettings infiFile(configFileName.toString(), QSettings::IniFormat);
|
||||||
|
|
||||||
|
int contains = -1;
|
||||||
|
|
||||||
|
for (const auto &item : qAsConst(items)) {
|
||||||
|
if (item.displayName == style) {
|
||||||
|
contains = items.indexOf(item);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contains >= 0) {
|
||||||
|
const QString styleName = items.at(contains).styleName;
|
||||||
|
const QString styleTheme = items.at(contains).styleTheme;
|
||||||
|
|
||||||
|
infiFile.setValue("Controls/Style", styleName);
|
||||||
|
|
||||||
|
if (!styleTheme.isEmpty())
|
||||||
|
infiFile.setValue((styleName + "/Theme"), styleTheme);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
infiFile.setValue("Controls/Style", style);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (view)
|
||||||
|
view->resetPuppet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const char enabledTooltip[] = QT_TRANSLATE_NOOP("ChangeStyleWidgetAction",
|
const char enabledTooltip[] = QT_TRANSLATE_NOOP("ChangeStyleWidgetAction",
|
||||||
"Change style for Qt Quick Controls 2.");
|
"Change style for Qt Quick Controls 2.");
|
||||||
const char disbledTooltip[] = QT_TRANSLATE_NOOP("ChangeStyleWidgetAction",
|
const char disbledTooltip[] = QT_TRANSLATE_NOOP("ChangeStyleWidgetAction",
|
||||||
@@ -64,18 +124,10 @@ QWidget *ChangeStyleWidgetAction::createWidget(QWidget *parent)
|
|||||||
{
|
{
|
||||||
auto comboBox = new QComboBox(parent);
|
auto comboBox = new QComboBox(parent);
|
||||||
comboBox->setToolTip(tr(enabledTooltip));
|
comboBox->setToolTip(tr(enabledTooltip));
|
||||||
// The Default style was renamed to Basic in Qt 6. In Qt 6, "Default"
|
|
||||||
// will result in a platform-specific style being chosen.
|
for (const auto &item : qAsConst(items))
|
||||||
comboBox->addItem("Basic");
|
comboBox->addItem(item.displayName);
|
||||||
comboBox->addItem("Default");
|
|
||||||
comboBox->addItem("Fusion");
|
|
||||||
comboBox->addItem("Imagine");
|
|
||||||
if (Utils::HostOsInfo::isMacHost())
|
|
||||||
comboBox->addItem("macOS");
|
|
||||||
comboBox->addItem("Material");
|
|
||||||
comboBox->addItem("Universal");
|
|
||||||
if (Utils::HostOsInfo::isWindowsHost())
|
|
||||||
comboBox->addItem("Windows");
|
|
||||||
comboBox->setEditable(true);
|
comboBox->setEditable(true);
|
||||||
comboBox->setCurrentIndex(0);
|
comboBox->setCurrentIndex(0);
|
||||||
|
|
||||||
@@ -97,23 +149,8 @@ QWidget *ChangeStyleWidgetAction::createWidget(QWidget *parent)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(comboBox,
|
connect(comboBox, &QComboBox::textActivated,
|
||||||
&QComboBox::textActivated,
|
this, &ChangeStyleWidgetAction::changeStyle);
|
||||||
this,
|
|
||||||
[this](const QString &style) {
|
|
||||||
|
|
||||||
if (style.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
const Utils::FilePath configFileName = Utils::FilePath::fromString(styleConfigFileName(qmlFileName));
|
|
||||||
|
|
||||||
if (configFileName.exists()) {
|
|
||||||
QSettings infiFile(configFileName.toString(), QSettings::IniFormat);
|
|
||||||
infiFile.setValue("Controls/Style", style);
|
|
||||||
if (view)
|
|
||||||
view->resetPuppet();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return comboBox;
|
return comboBox;
|
||||||
}
|
}
|
||||||
@@ -135,11 +172,27 @@ void ChangeStyleAction::currentContextChanged(const SelectionContext &selectionC
|
|||||||
|
|
||||||
if (Utils::FilePath::fromString(confFileName).exists()) {
|
if (Utils::FilePath::fromString(confFileName).exists()) {
|
||||||
QSettings infiFile(confFileName, QSettings::IniFormat);
|
QSettings infiFile(confFileName, QSettings::IniFormat);
|
||||||
m_action->handleModelUpdate(infiFile.value("Controls/Style", "Basic").toString());
|
const QString styleName = infiFile.value("Controls/Style", "Basic").toString();
|
||||||
|
const QString styleTheme = infiFile.value(styleName + "/Theme", "").toString();
|
||||||
|
const auto items = m_action->styleItems();
|
||||||
|
|
||||||
|
QString comboBoxEntry = styleName;
|
||||||
|
|
||||||
|
for (const auto &item : items) {
|
||||||
|
if (item.styleName == styleName) {
|
||||||
|
if (!styleTheme.isEmpty() && (item.styleTheme == styleTheme)) {
|
||||||
|
comboBoxEntry.append(" ");
|
||||||
|
comboBoxEntry.append(styleTheme);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_action->handleModelUpdate(comboBoxEntry);
|
||||||
} else {
|
} else {
|
||||||
m_action->handleModelUpdate("");
|
m_action->handleModelUpdate("");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,24 @@ namespace QmlDesigner {
|
|||||||
|
|
||||||
class AbstractView;
|
class AbstractView;
|
||||||
|
|
||||||
|
struct StyleWidgetEntry {
|
||||||
|
QString displayName;
|
||||||
|
|
||||||
|
QString styleName;
|
||||||
|
QString styleTheme;
|
||||||
|
|
||||||
|
bool operator==(const StyleWidgetEntry &entry) const {
|
||||||
|
if (displayName != entry.displayName)
|
||||||
|
return false;
|
||||||
|
if (styleName != entry.styleName)
|
||||||
|
return false;
|
||||||
|
if (styleTheme != entry.styleTheme)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
class ChangeStyleWidgetAction : public QWidgetAction
|
class ChangeStyleWidgetAction : public QWidgetAction
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -46,6 +64,11 @@ public:
|
|||||||
explicit ChangeStyleWidgetAction(QObject *parent = nullptr);
|
explicit ChangeStyleWidgetAction(QObject *parent = nullptr);
|
||||||
void handleModelUpdate(const QString &style);
|
void handleModelUpdate(const QString &style);
|
||||||
|
|
||||||
|
const QList<StyleWidgetEntry> styleItems() const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void changeStyle(const QString &style);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QWidget *createWidget(QWidget *parent) override;
|
QWidget *createWidget(QWidget *parent) override;
|
||||||
|
|
||||||
@@ -55,6 +78,8 @@ signals:
|
|||||||
public:
|
public:
|
||||||
QString qmlFileName;
|
QString qmlFileName;
|
||||||
QPointer<AbstractView> view;
|
QPointer<AbstractView> view;
|
||||||
|
|
||||||
|
QList<StyleWidgetEntry> items;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ChangeStyleAction : public ActionInterface
|
class ChangeStyleAction : public ActionInterface
|
||||||
|
|||||||
Reference in New Issue
Block a user