diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | src/controls/Private/qquickcontrolsettings.cpp | 22 | ||||
-rw-r--r-- | src/controls/Private/qquickcontrolsettings_p.h | 2 | ||||
-rw-r--r-- | src/controls/controls.pro | 27 | ||||
-rw-r--r-- | src/controls/plugin.cpp | 54 | ||||
-rw-r--r-- | src/controls/plugin.h | 3 | ||||
-rw-r--r-- | src/controls/qmldir | 26 |
7 files changed, 105 insertions, 30 deletions
@@ -47,6 +47,7 @@ Makefile* moc_*.cpp ui_*.h qrc_*.cpp +/src/controls/controls.qrc # xemacs temporary files *.flc diff --git a/src/controls/Private/qquickcontrolsettings.cpp b/src/controls/Private/qquickcontrolsettings.cpp index e2daa17f..48e71917 100644 --- a/src/controls/Private/qquickcontrolsettings.cpp +++ b/src/controls/Private/qquickcontrolsettings.cpp @@ -63,18 +63,27 @@ static QString styleImportName() return QFileInfo(name).fileName(); } +static bool fromResource(const QString &path) +{ + return path.startsWith("qrc:"); +} + static QString styleImportPath(QQmlEngine *engine, const QString &styleName) { QString path = qgetenv("QT_QUICK_CONTROLS_STYLE"); QFileInfo info(path); if (info.isRelative()) { + bool found = false; foreach (const QString &import, engine->importPathList()) { QDir dir(import + QLatin1String("/QtQuick/Controls/Styles")); if (dir.exists(styleName)) { + found = true; path = dir.absolutePath(); break; } } + if (!found) + path = "qrc:/QtQuick/Controls/Styles"; } else { path = info.absolutePath(); } @@ -86,7 +95,11 @@ QQuickControlSettings::QQuickControlSettings(QQmlEngine *engine) m_name = styleImportName(); m_path = styleImportPath(engine, m_name); - if (!QFile::exists(styleFilePath())) { + QString path = styleFilePath(); + if (fromResource(path)) + path = path.remove(0, 3); // remove qrc from the path + + if (!QDir(path).exists()) { QString unknownStyle = m_name; m_name = defaultStyleName(); m_path = styleImportPath(engine, m_name); @@ -97,9 +110,12 @@ QQuickControlSettings::QQuickControlSettings(QQmlEngine *engine) connect(this, SIGNAL(stylePathChanged()), SIGNAL(styleChanged())); } -QUrl QQuickControlSettings::style() const +QString QQuickControlSettings::style() const { - return QUrl::fromLocalFile(styleFilePath()); + if (fromResource(styleFilePath())) + return styleFilePath(); + else + return QUrl::fromLocalFile(styleFilePath()).toString(); } QString QQuickControlSettings::styleName() const diff --git a/src/controls/Private/qquickcontrolsettings_p.h b/src/controls/Private/qquickcontrolsettings_p.h index 8ff0ecbf..552c4820 100644 --- a/src/controls/Private/qquickcontrolsettings_p.h +++ b/src/controls/Private/qquickcontrolsettings_p.h @@ -60,7 +60,7 @@ class QQuickControlSettings : public QObject public: QQuickControlSettings(QQmlEngine *engine); - QUrl style() const; + QString style() const; QString styleName() const; void setStyleName(const QString &name); diff --git a/src/controls/controls.pro b/src/controls/controls.pro index 78eadf36..38018353 100644 --- a/src/controls/controls.pro +++ b/src/controls/controls.pro @@ -45,5 +45,32 @@ include(Styles/styles.pri) osx: LIBS += -framework Carbon +# Create the resource file +GENERATED_RESOURCE_FILE = $$OUT_PWD/controls.qrc + +INCLUDED_RESOURCE_FILES = \ + $$CONTROLS_QML_FILES \ + $$PRIVATE_QML_FILES \ + $$STYLES_QML_FILES + +RESOURCE_CONTENT = \ + "<RCC>" \ + "<qresource prefix=\"/QtQuick/Controls\">" + +for(resourcefile, INCLUDED_RESOURCE_FILES) { + resourcefileabsolutepath = $$absolute_path($$resourcefile) + relativepath_in = $$relative_path($$resourcefileabsolutepath, $$_PRO_FILE_PWD_) + relativepath_out = $$relative_path($$resourcefileabsolutepath, $$OUT_PWD) + RESOURCE_CONTENT += "<file alias=\"$$relativepath_in\">$$relativepath_out</file>" +} + +RESOURCE_CONTENT += \ + "</qresource>" \ + "</RCC>" + +write_file($$GENERATED_RESOURCE_FILE, RESOURCE_CONTENT)|error("Aborting.") + +RESOURCES += $$GENERATED_RESOURCE_FILE + CONFIG += no_cxx_module load(qml_plugin) diff --git a/src/controls/plugin.cpp b/src/controls/plugin.cpp index 1e842237..b98e7908 100644 --- a/src/controls/plugin.cpp +++ b/src/controls/plugin.cpp @@ -62,6 +62,38 @@ QT_BEGIN_NAMESPACE +static const struct { + const char *type; + int major, minor; +} qmldir [] = { + { "ApplicationWindow", 1, 0 }, + { "Button", 1, 0 }, + { "CheckBox", 1, 0 }, + { "ComboBox", 1, 0 }, + { "GroupBox", 1, 0 }, + { "Label", 1, 0 }, + { "MenuBar", 1, 0 }, + { "Menu", 1, 0 }, + { "StackView", 1, 0 }, + { "ProgressBar", 1, 0 }, + { "RadioButton", 1, 0 }, + { "ScrollView", 1, 0 }, + { "Slider", 1, 0 }, + { "SpinBox", 1, 0 }, + { "SplitView", 1, 0 }, + { "StackViewDelegate", 1, 0 }, + { "StackViewTransition", 1, 0 }, + { "StatusBar", 1, 0 }, + { "Tab", 1, 0 }, + { "TabView", 1, 0 }, + { "TableView", 1, 0 }, + { "TableViewColumn", 1, 0 }, + { "TextArea", 1, 0 }, + { "TextField", 1, 0 }, + { "ToolBar", 1, 0 }, + { "ToolButton", 1, 0 } +}; + void QtQuickControlsPlugin::registerTypes(const char *uri) { qmlRegisterType<QQuickAction>(uri, 1, 0, "Action"); @@ -76,6 +108,10 @@ void QtQuickControlsPlugin::registerTypes(const char *uri) QLatin1String("Do not create objects of type MenuBase")); qmlRegisterUncreatableType<QQuickStack>(uri, 1, 0, "Stack", QLatin1String("Do not create objects of type Stack")); + + const QString filesLocation = fileLocation(); + for (int i = 0; i < int(sizeof(qmldir)/sizeof(qmldir[0])); i++) + qmlRegisterType(QUrl(filesLocation + "/" + qmldir[i].type + ".qml"), uri, qmldir[i].major, qmldir[i].minor, qmldir[i].type); } void QtQuickControlsPlugin::initializeEngine(QQmlEngine *engine, const char *uri) @@ -96,6 +132,24 @@ void QtQuickControlsPlugin::initializeEngine(QQmlEngine *engine, const char *uri #endif engine->addImageProvider("desktoptheme", new QQuickDesktopIconProvider); + if (isLoadedFromResource()) + engine->addImportPath(QStringLiteral("qrc:/")); +} + +QString QtQuickControlsPlugin::fileLocation() const +{ + if (isLoadedFromResource()) + return "qrc:/QtQuick/Controls"; + return baseUrl().toString(); +} + +bool QtQuickControlsPlugin::isLoadedFromResource() const +{ + // If one file is missing, it will load all the files from the resource + QFile file(baseUrl().toLocalFile() + "/ApplicationWindow.qml"); + if (!file.exists()) + return true; + return false; } QT_END_NAMESPACE diff --git a/src/controls/plugin.h b/src/controls/plugin.h index fe06e806..2acdf02a 100644 --- a/src/controls/plugin.h +++ b/src/controls/plugin.h @@ -55,6 +55,9 @@ class QtQuickControlsPlugin: public QQmlExtensionPlugin public: void registerTypes(const char *uri); void initializeEngine(QQmlEngine *engine, const char *uri); +private: + QString fileLocation() const; + bool isLoadedFromResource() const; }; QT_END_NAMESPACE diff --git a/src/controls/qmldir b/src/controls/qmldir index c243360c..41d4d512 100644 --- a/src/controls/qmldir +++ b/src/controls/qmldir @@ -1,28 +1,2 @@ module QtQuick.Controls plugin qtquickcontrolsplugin -ApplicationWindow 1.0 ApplicationWindow.qml -Button 1.0 Button.qml -CheckBox 1.0 CheckBox.qml -ComboBox 1.0 ComboBox.qml -GroupBox 1.0 GroupBox.qml -Label 1.0 Label.qml -MenuBar 1.0 MenuBar.qml -Menu 1.0 Menu.qml -StackView 1.0 StackView.qml -ProgressBar 1.0 ProgressBar.qml -RadioButton 1.0 RadioButton.qml -ScrollView 1.0 ScrollView.qml -Slider 1.0 Slider.qml -SpinBox 1.0 SpinBox.qml -SplitView 1.0 SplitView.qml -StackViewDelegate 1.0 StackViewDelegate.qml -StackViewTransition 1.0 StackViewTransition.qml -StatusBar 1.0 StatusBar.qml -Tab 1.0 Tab.qml -TabView 1.0 TabView.qml -TableView 1.0 TableView.qml -TableViewColumn 1.0 TableViewColumn.qml -TextArea 1.0 TextArea.qml -TextField 1.0 TextField.qml -ToolBar 1.0 ToolBar.qml -ToolButton 1.0 ToolButton.qml |