forked from qt-creator/qt-creator
QmlDesigner: Implement styles in the status bar
Change-Id: I8413394484dc9d19e1bbe64391cefaba0f976f94 Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
This commit is contained in:
@@ -64,10 +64,11 @@ Item {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: kits.right
|
||||
anchors.leftMargin: 32
|
||||
model: [ "Basic", "Default", "Universal", "Material" ]
|
||||
//onActivated: backend.setCurrentWorkspace(workspaces.currentText)
|
||||
model: backend.styles
|
||||
onActivated: backend.setCurrentStyle(styles.currentIndex)
|
||||
openUpwards: true
|
||||
enabled: backend.isInDesignMode
|
||||
currentIndex: backend.currentStyle
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "toolbarbackend.h"
|
||||
|
||||
#include <changestyleaction.h>
|
||||
#include <crumblebar.h>
|
||||
#include <designeractionmanager.h>
|
||||
#include <designmodewidget.h>
|
||||
@@ -174,6 +175,26 @@ void ToolBarBackend::showZoomMenu(int x, int y)
|
||||
mainMenu->deleteLater();
|
||||
}
|
||||
|
||||
void ToolBarBackend::setCurrentStyle(int index)
|
||||
{
|
||||
const QList<StyleWidgetEntry> items = ChangeStyleWidgetAction::getAllStyleItems();
|
||||
|
||||
QTC_ASSERT(items.count() > index, return );
|
||||
QTC_ASSERT(index > 0, return );
|
||||
|
||||
QTC_ASSERT(currentDesignDocument(), return );
|
||||
|
||||
auto item = items.at(index);
|
||||
|
||||
auto view = currentDesignDocument()->rewriterView();
|
||||
|
||||
const QString qmlFile = view->model()->fileUrl().toLocalFile();
|
||||
|
||||
ChangeStyleWidgetAction::changeCurrentStyle(item.styleName, qmlFile);
|
||||
|
||||
view->resetPuppet();
|
||||
}
|
||||
|
||||
bool ToolBarBackend::canGoBack() const
|
||||
{
|
||||
QTC_ASSERT(designModeWidget(), return false);
|
||||
@@ -223,6 +244,11 @@ ToolBarBackend::ToolBarBackend(QObject *parent)
|
||||
this,
|
||||
&ToolBarBackend::documentIndexChanged);
|
||||
|
||||
connect(Core::EditorManager::instance(),
|
||||
&Core::EditorManager::currentEditorChanged,
|
||||
this,
|
||||
&ToolBarBackend::currentStyleChanged);
|
||||
|
||||
connect(designModeWidget(), &Internal::DesignModeWidget::initialized, this, [this]() {
|
||||
const auto dockManager = designModeWidget()->dockManager();
|
||||
|
||||
@@ -300,6 +326,16 @@ QStringList ToolBarBackend::workspaces() const
|
||||
return m_workspaces;
|
||||
}
|
||||
|
||||
QStringList ToolBarBackend::styles() const
|
||||
{
|
||||
const QList<StyleWidgetEntry> items = ChangeStyleWidgetAction::getAllStyleItems();
|
||||
QStringList list;
|
||||
for (const auto &item : items)
|
||||
list.append(item.displayName);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
bool ToolBarBackend::isInDesignMode() const
|
||||
{
|
||||
if (!Core::ModeManager::instance())
|
||||
@@ -316,6 +352,19 @@ bool ToolBarBackend::isDesignModeEnabled() const
|
||||
return false;
|
||||
}
|
||||
|
||||
int ToolBarBackend::currentStyle() const
|
||||
{
|
||||
QTC_ASSERT(currentDesignDocument(), return 0);
|
||||
|
||||
auto view = currentDesignDocument()->rewriterView();
|
||||
|
||||
const QString qmlFile = view->model()->fileUrl().toLocalFile();
|
||||
|
||||
const int index = ChangeStyleWidgetAction::getCurrentStyle(qmlFile);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
void ToolBarBackend::setupWorkspaces()
|
||||
{
|
||||
m_workspaces.clear();
|
||||
|
||||
@@ -74,8 +74,10 @@ class ToolBarBackend : public QObject
|
||||
Q_PROPERTY(int documentIndex READ documentIndex NOTIFY documentIndexChanged)
|
||||
Q_PROPERTY(QString currentWorkspace READ currentWorkspace NOTIFY currentWorkspaceChanged)
|
||||
Q_PROPERTY(QStringList workspaces READ workspaces NOTIFY workspacesChanged)
|
||||
Q_PROPERTY(QStringList styles READ styles FINAL)
|
||||
Q_PROPERTY(bool isInDesignMode READ isInDesignMode NOTIFY isInDesignModeChanged)
|
||||
Q_PROPERTY(bool isDesignModeEnabled READ isDesignModeEnabled NOTIFY isDesignModeEnabledChanged)
|
||||
Q_PROPERTY(int currentStyle READ currentStyle NOTIFY currentStyleChanged)
|
||||
|
||||
public:
|
||||
ToolBarBackend(QObject *parent = nullptr);
|
||||
@@ -92,6 +94,7 @@ public:
|
||||
Q_INVOKABLE void setCurrentWorkspace(const QString &workspace);
|
||||
Q_INVOKABLE void editGlobalAnnoation();
|
||||
Q_INVOKABLE void showZoomMenu(int x, int y);
|
||||
Q_INVOKABLE void setCurrentStyle(int index);
|
||||
|
||||
bool canGoBack() const;
|
||||
bool canGoForward() const;
|
||||
@@ -104,8 +107,11 @@ public:
|
||||
QString currentWorkspace() const;
|
||||
QStringList workspaces() const;
|
||||
|
||||
QStringList styles() const;
|
||||
|
||||
bool isInDesignMode() const;
|
||||
bool isDesignModeEnabled() const;
|
||||
int currentStyle() const;
|
||||
|
||||
signals:
|
||||
void navigationHistoryChanged();
|
||||
@@ -115,6 +121,7 @@ signals:
|
||||
void workspacesChanged();
|
||||
void isInDesignModeChanged();
|
||||
void isDesignModeEnabledChanged();
|
||||
void currentStyleChanged();
|
||||
|
||||
private:
|
||||
void setupWorkspaces();
|
||||
|
||||
Reference in New Issue
Block a user