aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/welcome
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2017-01-06 21:41:46 +0100
committerhjk <hjk@qt.io>2017-01-13 15:38:14 +0000
commit16944277d2aa2cdab194ec05de6c8e2d5ee814cd (patch)
tree65be67b94d693eaf5874880aa60241015acc8c6c /src/plugins/welcome
parent36d1a75118ad31861b64272716d189090e0b4e4d (diff)
Welcome: Start some performance improvements
This is essentially a widgets based re-implementation of the current design. It is still using the QAIM based interface layer between to the real data and display even though this is not needed with this approach. Removal of this layer would further reduce code size and cycle counts. For now: old new Load time 215ms 182ms delete 22ms 2ms Change-Id: I90d779a60a47a78399eaad0f1bc032d39f3ae3c0 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Diffstat (limited to 'src/plugins/welcome')
-rw-r--r--src/plugins/welcome/Welcome.json.in2
-rw-r--r--src/plugins/welcome/welcome.pro9
-rw-r--r--src/plugins/welcome/welcome.qbs7
-rw-r--r--src/plugins/welcome/welcome_dependencies.pri1
-rw-r--r--src/plugins/welcome/welcomeplugin.cpp502
-rw-r--r--src/plugins/welcome/welcomeplugin.h55
6 files changed, 268 insertions, 308 deletions
diff --git a/src/plugins/welcome/Welcome.json.in b/src/plugins/welcome/Welcome.json.in
index 60f79a59fe..f9cfb3f18e 100644
--- a/src/plugins/welcome/Welcome.json.in
+++ b/src/plugins/welcome/Welcome.json.in
@@ -13,7 +13,7 @@
\"Alternatively, this plugin may be used under the terms of the GNU General Public License version 3 as published by the Free Software Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT included in the packaging of this plugin. Please review the following information to ensure the GNU General Public License requirements will be met: https://www.gnu.org/licenses/gpl-3.0.html.\"
],
\"Category\" : \"Qt Creator\",
- \"Description\" : \"Default Welcome Screen Plugin.\",
+ \"Description\" : \"Secondary Welcome Screen Plugin.\",
\"Url\" : \"http://www.qt.io\",
$$dependencyList
}
diff --git a/src/plugins/welcome/welcome.pro b/src/plugins/welcome/welcome.pro
index 9fec122551..612739a692 100644
--- a/src/plugins/welcome/welcome.pro
+++ b/src/plugins/welcome/welcome.pro
@@ -1,15 +1,8 @@
-QT += quick quickwidgets
-
-QML_IMPORT_PATH=../../../share/qtcreator/welcomescreen
-
include(../../qtcreatorplugin.pri)
-HEADERS += welcomeplugin.h
-
SOURCES += welcomeplugin.cpp
DEFINES += WELCOME_LIBRARY
-RESOURCES += \
- welcome.qrc
+RESOURCES += welcome.qrc
diff --git a/src/plugins/welcome/welcome.qbs b/src/plugins/welcome/welcome.qbs
index 2a29e749ae..74dd1d04e4 100644
--- a/src/plugins/welcome/welcome.qbs
+++ b/src/plugins/welcome/welcome.qbs
@@ -3,14 +3,13 @@ import qbs 1.0
QtcPlugin {
name: "Welcome"
- Depends { name: "Qt"; submodules: ["widgets", "network", "quick", "quickwidgets"] }
+ Depends { name: "Qt"; submodules: ["widgets", "network" ] }
Depends { name: "Utils" }
Depends { name: "Core" }
files: [
- "welcomeplugin.cpp",
- "welcomeplugin.h",
- "welcome.qrc",
+ "welcome2plugin.cpp",
+ "welcome2plugin.h",
]
}
diff --git a/src/plugins/welcome/welcome_dependencies.pri b/src/plugins/welcome/welcome_dependencies.pri
index c9a5fc67e1..af40b7285f 100644
--- a/src/plugins/welcome/welcome_dependencies.pri
+++ b/src/plugins/welcome/welcome_dependencies.pri
@@ -4,3 +4,4 @@ QTC_LIB_DEPENDS += \
utils
QTC_PLUGIN_DEPENDS += \
coreplugin
+
diff --git a/src/plugins/welcome/welcomeplugin.cpp b/src/plugins/welcome/welcomeplugin.cpp
index c10c5ffab2..2c6f88956a 100644
--- a/src/plugins/welcome/welcomeplugin.cpp
+++ b/src/plugins/welcome/welcomeplugin.cpp
@@ -23,13 +23,11 @@
**
****************************************************************************/
-#include "welcomeplugin.h"
-
+#include <extensionsystem/iplugin.h>
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
-
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
#include <coreplugin/imode.h>
@@ -43,278 +41,318 @@
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
#include <utils/styledbar.h>
-
+#include <utils/treemodel.h>
#include <utils/theme/theme.h>
-#include <QVBoxLayout>
-#include <QMessageBox>
-
-#include <QDir>
-#include <QQmlPropertyMap>
-#include <QQuickImageProvider>
+#include <QDesktopServices>
+#include <QHeaderView>
+#include <QLabel>
+#include <QMouseEvent>
+#include <QPainter>
+#include <QStackedWidget>
#include <QTimer>
-
-#include <QtQuickWidgets/QQuickWidget>
-#include <QtQml/QQmlContext>
-#include <QtQml/QQmlEngine>
-
-enum { debug = 0 };
+#include <QVBoxLayout>
using namespace Core;
using namespace ExtensionSystem;
using namespace Utils;
-static const char currentPageSettingsKeyC[] = "WelcomeTab";
-
namespace Welcome {
namespace Internal {
-static QString applicationDirPath()
+class SideBar;
+
+const int lrPadding = 34;
+const char currentPageSettingsKeyC[] = "Welcome2Tab";
+
+static QColor themeColor(Theme::Color role)
+{
+ return Utils::creatorTheme()->color(role);
+}
+
+static QFont sizedFont(int size, const QWidget *widget, bool underline = false)
{
- // normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows
- return FileUtils::normalizePathName(QCoreApplication::applicationDirPath());
+ QFont f = widget->font();
+ f.setPixelSize(size);
+ f.setUnderline(underline);
+ return f;
}
-static QString resourcePath()
+static QPalette lightText()
{
- // normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows
- return FileUtils::normalizePathName(ICore::resourcePath());
+ QPalette pal;
+ pal.setColor(QPalette::Foreground, themeColor(Theme::Welcome_ForegroundPrimaryColor));
+ pal.setColor(QPalette::WindowText, themeColor(Theme::Welcome_ForegroundPrimaryColor));
+ return pal;
}
-class WelcomeImageIconProvider : public QQuickImageProvider
+class WelcomeMode : public IMode
{
+ Q_OBJECT
public:
- WelcomeImageIconProvider()
- : QQuickImageProvider(Pixmap)
- {
- }
+ WelcomeMode();
+ ~WelcomeMode();
- QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override
- {
- Q_UNUSED(requestedSize)
+ void initPlugins();
- QString maskFile;
- Theme::Color themeColor = Theme::Welcome_ForegroundPrimaryColor;
+ Q_INVOKABLE bool openDroppedFiles(const QList<QUrl> &urls);
- const QStringList elements = id.split(QLatin1Char('/'));
+private:
+ void addPage(IWelcomePage *page);
- if (!elements.empty())
- maskFile = elements.first();
+ QWidget *m_modeWidget;
+ QStackedWidget *m_pageStack;
+ SideBar *m_sideBar;
+ QList<IWelcomePage *> m_pluginList;
+ QList<WelcomePageButton *> m_pageButtons;
+ Id m_activePage;
+};
- if (elements.count() >= 2) {
- const static QMetaObject &m = Theme::staticMetaObject;
- const static QMetaEnum e = m.enumerator(m.indexOfEnumerator("Color"));
- bool success = false;
- int value = e.keyToValue(elements.at(1).toLatin1(), &success);
- if (success)
- themeColor = Theme::Color(value);
- }
+class WelcomePlugin : public ExtensionSystem::IPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Welcome.json")
- const QString fileName = QString::fromLatin1(":/welcome/images/%1.png").arg(maskFile);
- const Icon icon({{fileName, themeColor}}, Icon::Tint);
- const QPixmap result = icon.pixmap();
- if (size)
- *size = result.size();
- return result;
+public:
+ WelcomePlugin() {}
+
+ bool initialize(const QStringList &, QString *) final
+ {
+ m_welcomeMode = new WelcomeMode;
+ addAutoReleasedObject(m_welcomeMode);
+ return true;
+ }
+
+ void extensionsInitialized() final
+ {
+ m_welcomeMode->initPlugins();
+ ModeManager::activateMode(m_welcomeMode->id());
}
+
+ WelcomeMode *m_welcomeMode = nullptr;
};
-class WelcomeMode : public IMode
+class IconAndLink : public QWidget
{
- Q_OBJECT
- Q_PROPERTY(int activePlugin READ activePlugin WRITE setActivePlugin NOTIFY activePluginChanged)
- Q_PROPERTY(QStringList recentProjectsShortcuts READ recentProjectsShortcuts NOTIFY recentProjectsShortcutsChanged)
- Q_PROPERTY(QStringList sessionsShortcuts READ sessionsShortcuts NOTIFY sessionsShortcutsChanged)
public:
- WelcomeMode();
- ~WelcomeMode();
+ IconAndLink(const QString &iconSource,
+ const QString &title,
+ const QString &openUrl,
+ QWidget *parent)
+ : QWidget(parent), m_iconSource(iconSource), m_title(title), m_openUrl(openUrl)
+ {
+ setAutoFillBackground(true);
- void activated();
- void initPlugins();
- int activePlugin() const { return m_activePlugin; }
+ const QString fileName = QString(":/welcome/images/%1.png").arg(iconSource);
+ const Icon icon({{ fileName, Theme::Welcome_ForegroundPrimaryColor }}, Icon::Tint);
- QStringList recentProjectsShortcuts() const { return m_recentProjectsShortcuts; }
- QStringList sessionsShortcuts() const { return m_sessionsShortcuts; }
+ m_icon = new QLabel;
+ m_icon->setPixmap(icon.pixmap());
- Q_INVOKABLE bool openDroppedFiles(const QList<QUrl> &urls);
+ m_label = new QLabel(title);
+ m_label->setFont(sizedFont(11, m_label, false));
-public slots:
- void setActivePlugin(int pos)
+ auto layout = new QHBoxLayout;
+ layout->setContentsMargins(lrPadding, 0, lrPadding, 0);
+ layout->addWidget(m_icon);
+ layout->addSpacing(2);
+ layout->addWidget(m_label);
+ layout->addStretch(1);
+ setLayout(layout);
+ }
+
+ void enterEvent(QEvent *) override
{
- if (m_activePlugin != pos) {
- m_activePlugin = pos;
- emit activePluginChanged(pos);
- }
+ QPalette pal;
+ pal.setColor(QPalette::Background, themeColor(Theme::Welcome_HoverColor));
+ setPalette(pal);
+ m_label->setFont(sizedFont(11, m_label, true));
+ update();
}
-signals:
- void activePluginChanged(int pos);
+ void leaveEvent(QEvent *) override
+ {
+ QPalette pal;
+ pal.setColor(QPalette::Background, themeColor(Theme::Welcome_BackgroundColor));
+ setPalette(pal);
+ m_label->setFont(sizedFont(11, m_label, false));
+ update();
+ }
- void openSessionTriggered(int index);
- void openRecentProjectTriggered(int index);
+ void mousePressEvent(QMouseEvent *) override
+ {
+ QDesktopServices::openUrl(m_openUrl);
+ }
- void recentProjectsShortcutsChanged(QStringList recentProjectsShortcuts);
- void sessionsShortcutsChanged(QStringList sessionsShortcuts);
+ QString m_iconSource;
+ QString m_title;
+ QString m_openUrl;
-private:
- void welcomePluginAdded(QObject*);
- void sceneGraphError(QQuickWindow::SceneGraphError, const QString &message);
- void facilitateQml(QQmlEngine *engine);
- void addPages(QQmlEngine *engine, const QList<IWelcomePage *> &pages);
- void addKeyboardShortcuts();
+ QLabel *m_icon;
+ QLabel *m_label;
+};
- QWidget *m_modeWidget;
- QQuickWidget *m_welcomePage;
- QMap<Id, IWelcomePage *> m_idPageMap;
- QList<IWelcomePage *> m_pluginList;
- int m_activePlugin;
- QStringList m_recentProjectsShortcuts;
- QStringList m_sessionsShortcuts;
+class SideBar : public QWidget
+{
+ Q_OBJECT
+public:
+ SideBar(QWidget *parent)
+ : QWidget(parent)
+ {
+ setAutoFillBackground(true);
+ setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
+ setPalette(themeColor(Theme::Welcome_BackgroundColor));
+
+ auto vbox = new QVBoxLayout(this);
+ vbox->setSpacing(0);
+ vbox->setContentsMargins(0, 27, 0, 0);
+
+ int sd = IWelcomePage::screenDependHeightDistance();
+
+ {
+ auto l = m_pluginButtons = new QVBoxLayout;
+ l->setContentsMargins(lrPadding, 0, lrPadding, 0);
+ l->setSpacing(sd + 3);
+ vbox->addItem(l);
+ vbox->addSpacing(62);
+ }
+
+ {
+ auto l = new QVBoxLayout;
+ l->setContentsMargins(lrPadding, 0, lrPadding, 0);
+ l->setSpacing(sd - 8);
+
+ auto newLabel = new QLabel(tr("New to Qt?"), this);
+ newLabel->setFont(sizedFont(18, this));
+ l->addWidget(newLabel);
+
+ auto learnLabel = new QLabel(tr("Learn how to develop your own applications "
+ "and explore Qt Creator."), this);
+ learnLabel->setMaximumWidth(200);
+ learnLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
+ learnLabel->setWordWrap(true);
+ learnLabel->setFont(sizedFont(12, this));
+ learnLabel->setPalette(lightText());
+ l->addWidget(learnLabel);
+
+ l->addSpacing(12);
+
+ auto getStartedButton = new WelcomePageButton(this);
+ getStartedButton->setText(tr("Get Started Now"));
+ getStartedButton->setOnClicked([] {
+ QDesktopServices::openUrl(QString("qthelp://org.qt-project.qtcreator/doc/index.html"));
+ });
+ l->addWidget(getStartedButton);
+
+ vbox->addItem(l);
+ vbox->addSpacing(77);
+ }
+
+ {
+ auto l = new QVBoxLayout;
+ l->setContentsMargins(0, 0, 0, 0);
+ l->setSpacing(sd + 3);
+ l->addWidget(new IconAndLink("qtaccount", tr("Qt Account"), "https://account.qt.io", this));
+ l->addWidget(new IconAndLink("community", tr("Online Community"), "http://forum.qt.io", this));
+ l->addWidget(new IconAndLink("blogs", tr("Blogs"), "http://planet.qt.io", this));
+ l->addWidget(new IconAndLink("userguide", tr("User Guide"),
+ "qthelp://org.qt-project.qtcreator/doc/index.html", this));
+ vbox->addItem(l);
+ }
+
+ vbox->addStretch(1);
+ }
+
+ QVBoxLayout *m_pluginButtons = nullptr;
};
WelcomeMode::WelcomeMode()
- : m_activePlugin(0)
{
setDisplayName(tr("Welcome"));
- const Utils::Icon MODE_WELCOME_CLASSIC(
- QLatin1String(":/welcome/images/mode_welcome.png"));
- const Utils::Icon MODE_WELCOME_FLAT({
- {QLatin1String(":/welcome/images/mode_welcome_mask.png"), Utils::Theme::IconsBaseColor}});
- const Utils::Icon MODE_WELCOME_FLAT_ACTIVE({
- {QLatin1String(":/welcome/images/mode_welcome_mask.png"), Utils::Theme::IconsModeWelcomeActiveColor}});
+ const Icon CLASSIC(":/welcome/images/mode_welcome.png");
+ const Icon FLAT({{":/welcome/images/mode_welcome_mask.png",
+ Theme::IconsBaseColor}});
+ const Icon FLAT_ACTIVE({{":/welcome/images/mode_welcome_mask.png",
+ Theme::IconsModeWelcomeActiveColor}});
+ setIcon(Icon::modeIcon(CLASSIC, FLAT, FLAT_ACTIVE));
- setIcon(Utils::Icon::modeIcon(MODE_WELCOME_CLASSIC,
- MODE_WELCOME_FLAT, MODE_WELCOME_FLAT_ACTIVE));
setPriority(Constants::P_MODE_WELCOME);
setId(Constants::MODE_WELCOME);
- setContextHelpId(QLatin1String("Qt Creator Manual"));
+ setContextHelpId("Qt Creator Manual");
setContext(Context(Constants::C_WELCOME_MODE));
- m_modeWidget = new QWidget;
- m_modeWidget->setObjectName(QLatin1String("WelcomePageModeWidget"));
- QVBoxLayout *layout = new QVBoxLayout(m_modeWidget);
- layout->setMargin(0);
- layout->setSpacing(0);
+ QPalette palette = creatorTheme()->palette();
+ palette.setColor(QPalette::Background, themeColor(Theme::Welcome_BackgroundColor));
- m_welcomePage = new QQuickWidget;
- m_welcomePage->setResizeMode(QQuickWidget::SizeRootObjectToView);
+ m_modeWidget = new QWidget;
+ m_modeWidget->setPalette(palette);
- m_welcomePage->setObjectName(QLatin1String("WelcomePage"));
+ m_sideBar = new SideBar(m_modeWidget);
- connect(m_welcomePage, &QQuickWidget::sceneGraphError,
- this, &WelcomeMode::sceneGraphError);
+ auto divider = new QWidget(m_modeWidget);
+ divider->setMaximumWidth(1);
+ divider->setMinimumWidth(1);
+ divider->setAutoFillBackground(true);
+ divider->setPalette(themeColor(Theme::Welcome_DividerColor));
- StyledBar *styledBar = new StyledBar(m_modeWidget);
- styledBar->setObjectName(QLatin1String("WelcomePageStyledBar"));
- layout->addWidget(styledBar);
+ m_pageStack = new QStackedWidget(m_modeWidget);
+ m_pageStack->setAutoFillBackground(true);
- m_welcomePage->setParent(m_modeWidget);
- layout->addWidget(m_welcomePage);
+ auto hbox = new QHBoxLayout;
+ hbox->addWidget(m_sideBar);
+ hbox->addWidget(divider);
+ hbox->addWidget(m_pageStack);
+ hbox->setStretchFactor(m_pageStack, 10);
- addKeyboardShortcuts();
+ auto layout = new QVBoxLayout(m_modeWidget);
+ layout->setMargin(0);
+ layout->setSpacing(0);
+ layout->addWidget(new StyledBar(m_modeWidget));
+ layout->addItem(hbox);
setWidget(m_modeWidget);
}
-void WelcomeMode::addKeyboardShortcuts()
-{
- const int actionsCount = 9;
- Context welcomeContext(Core::Constants::C_WELCOME_MODE);
-
- const Id sessionBase = "Welcome.OpenSession";
- for (int i = 1; i <= actionsCount; ++i) {
- auto act = new QAction(tr("Open Session #%1").arg(i), this);
- Command *cmd = ActionManager::registerAction(act, sessionBase.withSuffix(i), welcomeContext);
- cmd->setDefaultKeySequence(QKeySequence((UseMacShortcuts ? tr("Ctrl+Meta+%1") : tr("Ctrl+Alt+%1")).arg(i)));
- m_sessionsShortcuts.append(cmd->keySequence().toString(QKeySequence::NativeText));
-
- connect(act, &QAction::triggered, this, [this, i] { openSessionTriggered(i-1); });
- connect(cmd, &Command::keySequenceChanged, this, [this, i, cmd] {
- m_sessionsShortcuts[i-1] = cmd->keySequence().toString(QKeySequence::NativeText);
- emit sessionsShortcutsChanged(m_sessionsShortcuts);
- });
- }
-
- const Id projectBase = "Welcome.OpenRecentProject";
- for (int i = 1; i <= actionsCount; ++i) {
- auto act = new QAction(tr("Open Recent Project #%1").arg(i), this);
- Command *cmd = ActionManager::registerAction(act, projectBase.withSuffix(i), welcomeContext);
- cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+%1").arg(i)));
- m_recentProjectsShortcuts.append(cmd->keySequence().toString(QKeySequence::NativeText));
-
- connect(act, &QAction::triggered, this, [this, i] { openRecentProjectTriggered(i-1); });
- connect(cmd, &Command::keySequenceChanged, this, [this, i, cmd] {
- m_recentProjectsShortcuts[i-1] = cmd->keySequence().toString(QKeySequence::NativeText);
- emit recentProjectsShortcutsChanged(m_recentProjectsShortcuts);
- });
- }
-}
-
WelcomeMode::~WelcomeMode()
{
QSettings *settings = ICore::settings();
- settings->setValue(QLatin1String(currentPageSettingsKeyC), activePlugin());
+ settings->setValue(currentPageSettingsKeyC, m_activePage.toSetting());
delete m_modeWidget;
}
-void WelcomeMode::sceneGraphError(QQuickWindow::SceneGraphError, const QString &message)
-{
- QMessageBox *messageBox =
- new QMessageBox(QMessageBox::Warning,
- tr("Welcome Mode Load Error"), message,
- QMessageBox::Close, m_modeWidget);
- messageBox->setModal(false);
- messageBox->setAttribute(Qt::WA_DeleteOnClose);
- messageBox->show();
-}
-
-void WelcomeMode::facilitateQml(QQmlEngine *engine)
-{
- QStringList importPathList = engine->importPathList();
- importPathList.append(resourcePath() + QLatin1String("/welcomescreen"));
- engine->addImageProvider(QLatin1String("icons"), new WelcomeImageIconProvider);
- if (!debug)
- engine->setOutputWarningsToStandardError(false);
-
- QString pluginPath = applicationDirPath();
- if (HostOsInfo::isMacHost())
- pluginPath += QLatin1String("/../PlugIns");
- else
- pluginPath += QLatin1String("/../" IDE_LIBRARY_BASENAME "/qtcreator");
- importPathList.append(QDir::cleanPath(pluginPath));
- engine->setImportPathList(importPathList);
-
- QQmlContext *ctx = engine->rootContext();
- ctx->setContextProperty(QLatin1String("welcomeMode"), this);
- ctx->setContextProperty(QLatin1String("creatorTheme"), Utils::creatorTheme()->values());
- ctx->setContextProperty(QLatin1String("useNativeText"), true);
-}
-
void WelcomeMode::initPlugins()
{
QSettings *settings = ICore::settings();
- setActivePlugin(settings->value(QLatin1String(currentPageSettingsKeyC)).toInt());
+ m_activePage = Id::fromSetting(settings->value(currentPageSettingsKeyC));
- QQmlEngine *engine = m_welcomePage->engine();
- facilitateQml(engine);
+ const QList<IWelcomePage *> availablePages = PluginManager::getObjects<IWelcomePage>();
+ for (IWelcomePage *page : availablePages)
+ addPage(page);
- QList<IWelcomePage *> availablePages = PluginManager::getObjects<IWelcomePage>();
- addPages(engine, availablePages);
// make sure later added pages are made available too:
- connect(PluginManager::instance(), &PluginManager::objectAdded, engine, [this, engine](QObject *obj) {
+ connect(PluginManager::instance(), &PluginManager::objectAdded, this, [this](QObject *obj) {
if (IWelcomePage *page = qobject_cast<IWelcomePage*>(obj))
- addPages(engine, QList<IWelcomePage *>() << page);
+ addPage(page);
});
- QString path = resourcePath() + QLatin1String("/welcomescreen/welcomescreen.qml");
-
- // finally, load the root page
- m_welcomePage->setSource(QUrl::fromLocalFile(path));
+ if (!m_activePage.isValid() && !m_pageButtons.isEmpty()) {
+ m_activePage = m_pluginList.at(0)->id();
+ m_pageButtons.at(0)->click();
+ }
}
bool WelcomeMode::openDroppedFiles(const QList<QUrl> &urls)
{
+// DropArea {
+// anchors.fill: parent
+// keys: ["text/uri-list"]
+// onDropped: {
+// if ((drop.supportedActions & Qt.CopyAction != 0)
+// && welcomeMode.openDroppedFiles(drop.urls))
+// drop.accept(Qt.CopyAction);
+// }
+// }
const QList<QUrl> localUrls = Utils::filtered(urls, &QUrl::isLocalFile);
if (!localUrls.isEmpty()) {
QTimer::singleShot(0, [localUrls]() {
@@ -325,54 +363,38 @@ bool WelcomeMode::openDroppedFiles(const QList<QUrl> &urls)
return false;
}
-void WelcomeMode::addPages(QQmlEngine *engine, const QList<IWelcomePage *> &pages)
+void WelcomeMode::addPage(IWelcomePage *page)
{
- QList<IWelcomePage *> addedPages = pages;
- Utils::sort(addedPages, &IWelcomePage::priority);
- // insert into m_pluginList, keeping m_pluginList sorted by priority
- auto addIt = addedPages.cbegin();
- auto currentIt = m_pluginList.begin();
- while (addIt != addedPages.cend()) {
- IWelcomePage *page = *addIt;
- QTC_ASSERT(!m_idPageMap.contains(page->id()), ++addIt; continue);
- while (currentIt != m_pluginList.end() && (*currentIt)->priority() <= page->priority())
- ++currentIt;
- // currentIt is now either end() or a page with higher value
- currentIt = m_pluginList.insert(currentIt, page);
- m_idPageMap.insert(page->id(), page);
- page->facilitateQml(engine);
- ++currentIt;
- ++addIt;
+ int idx;
+ int pagePriority = page->priority();
+ for (idx = 0; idx != m_pluginList.size(); ++idx) {
+ if (m_pluginList.at(idx)->priority() >= pagePriority)
+ break;
}
- // update model through reset
- QQmlContext *ctx = engine->rootContext();
- ctx->setContextProperty(QLatin1String("pagesModel"), QVariant::fromValue(
- Utils::transform(m_pluginList, // transform into QList<QObject *>
- [](IWelcomePage *page) -> QObject * {
- return page;
- })));
-}
-
-WelcomePlugin::WelcomePlugin()
- : m_welcomeMode(0)
-{
-}
-
-bool WelcomePlugin::initialize(const QStringList & /* arguments */, QString *errorMessage)
-{
- if (!Utils::HostOsInfo::canCreateOpenGLContext(errorMessage))
- return false;
-
- m_welcomeMode = new WelcomeMode;
- addAutoReleasedObject(m_welcomeMode);
-
- return true;
-}
-
-void WelcomePlugin::extensionsInitialized()
-{
- m_welcomeMode->initPlugins();
- ModeManager::activateMode(m_welcomeMode->id());
+ auto pageButton = new WelcomePageButton(m_sideBar);
+ auto pageId = page->id();
+ pageButton->setText(page->title());
+ pageButton->setActiveChecker([this, pageId] { return m_activePage == pageId; });
+
+ m_pluginList.append(page);
+ m_pageButtons.append(pageButton);
+
+ m_sideBar->m_pluginButtons->insertWidget(idx, pageButton);
+
+ QWidget *stackPage = page->createWidget();
+ stackPage->setAutoFillBackground(true);
+ m_pageStack->insertWidget(idx, stackPage);
+
+ auto onClicked = [this, page, pageId, stackPage] {
+ m_activePage = pageId;
+ m_pageStack->setCurrentWidget(stackPage);
+ for (WelcomePageButton *pageButton : m_pageButtons)
+ pageButton->recheckActive();
+ };
+
+ pageButton->setOnClicked(onClicked);
+ if (pageId == m_activePage)
+ onClicked();
}
} // namespace Internal
diff --git a/src/plugins/welcome/welcomeplugin.h b/src/plugins/welcome/welcomeplugin.h
deleted file mode 100644
index fe05ee8a04..0000000000
--- a/src/plugins/welcome/welcomeplugin.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt Creator.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-****************************************************************************/
-
-#pragma once
-
-#include <extensionsystem/iplugin.h>
-
-QT_BEGIN_NAMESPACE
-class QQmlEngine;
-QT_END_NAMESPACE
-
-namespace Welcome {
-namespace Internal {
-
-class WelcomeMode;
-
-class WelcomePlugin : public ExtensionSystem::IPlugin
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Welcome.json")
-
-public:
- WelcomePlugin();
-
- virtual bool initialize(const QStringList &arguments, QString *errorMessage);
- virtual void extensionsInitialized();
-
-private:
- WelcomeMode *m_welcomeMode;
-};
-
-} // namespace Welcome
-} // namespace Internal