summaryrefslogtreecommitdiff
path: root/src/plugins/welcome
diff options
context:
space:
mode:
authorhjk <qtc-committer@nokia.com>2011-04-13 17:09:44 +0200
committerhjk <qtc-committer@nokia.com>2011-04-14 11:15:08 +0200
commitba52d6725b3b84237fa31d1fbb28071125c5d28e (patch)
treeadb6bdd3174226550c98593de15ae95069a0c3c8 /src/plugins/welcome
parentbe9455bc507a4cd566d296c96407a89adc1bd1c2 (diff)
downloadqt-creator-ba52d6725b3b84237fa31d1fbb28071125c5d28e.tar.gz
welcomemode: simplify WelcomeMode
Diffstat (limited to 'src/plugins/welcome')
-rw-r--r--src/plugins/welcome/welcome.pro7
-rw-r--r--src/plugins/welcome/welcomemode.cpp222
-rw-r--r--src/plugins/welcome/welcomemode.h76
-rw-r--r--src/plugins/welcome/welcomeplugin.cpp220
-rw-r--r--src/plugins/welcome/welcomeplugin.h6
5 files changed, 221 insertions, 310 deletions
diff --git a/src/plugins/welcome/welcome.pro b/src/plugins/welcome/welcome.pro
index 9fcb3be5f9..19a6d8745e 100644
--- a/src/plugins/welcome/welcome.pro
+++ b/src/plugins/welcome/welcome.pro
@@ -1,19 +1,22 @@
TEMPLATE = lib
TARGET = Welcome
QT += network
+
include(../../qtcreatorplugin.pri)
include(welcome_dependencies.pri)
+
HEADERS += welcomeplugin.h \
- welcomemode.h \
communitywelcomepagewidget.h \
communitywelcomepage.h \
welcome_global.h
+
SOURCES += welcomeplugin.cpp \
- welcomemode.cpp \
communitywelcomepagewidget.cpp \
communitywelcomepage.cpp
FORMS += welcomemode.ui \
communitywelcomepagewidget.ui
+
RESOURCES += welcome.qrc
+
DEFINES += WELCOME_LIBRARY
diff --git a/src/plugins/welcome/welcomemode.cpp b/src/plugins/welcome/welcomemode.cpp
deleted file mode 100644
index 1b253e26ce..0000000000
--- a/src/plugins/welcome/welcomemode.cpp
+++ /dev/null
@@ -1,222 +0,0 @@
-/**************************************************************************
-**
-** This file is part of Qt Creator
-**
-** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
-**
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** No Commercial Usage
-**
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-**
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**************************************************************************/
-
-#include "welcomemode.h"
-#include "ui_welcomemode.h"
-
-#include <extensionsystem/pluginmanager.h>
-
-#include <coreplugin/icore.h>
-#include <coreplugin/coreconstants.h>
-
-#include <utils/styledbar.h>
-#include <utils/welcomemodetreewidget.h>
-#include <utils/iwelcomepage.h>
-
-#include <QtGui/QScrollArea>
-#include <QtGui/QDesktopServices>
-#include <QtGui/QToolButton>
-#include <QtGui/QPainter>
-
-#include <QtCore/QSettings>
-#include <QtCore/QDebug>
-#include <QtCore/QUrl>
-
-enum { debug = 0 };
-
-using namespace ExtensionSystem;
-
-static const char currentPageSettingsKeyC[] = "General/WelcomeTab";
-
-namespace Welcome {
-
-// Helper class introduced to cache the scaled background image
-// so we avoid re-scaling for every repaint.
-class ImageWidget : public QWidget
-{
-public:
- ImageWidget(const QImage &bg, QWidget *parent) : QWidget(parent), m_bg(bg) {}
- void paintEvent(QPaintEvent *e) {
- if (!m_bg.isNull()) {
- QPainter painter(this);
- if (m_stretch.size() != size())
- m_stretch = QPixmap::fromImage(m_bg.scaled(size(), Qt::IgnoreAspectRatio,
- Qt::SmoothTransformation));
- if (!m_stretch.size().isEmpty())
- painter.drawPixmap(rect(), m_stretch);
- }
- QWidget::paintEvent(e);
- }
-private:
- QImage m_bg;
- QPixmap m_stretch;
-};
-
-struct WelcomeModePrivate
-{
- typedef QMap<QToolButton*, QWidget*> ToolButtonWidgetMap;
-
- WelcomeModePrivate() {}
-
- QScrollArea *m_scrollArea;
- QWidget *m_widget;
- ImageWidget *m_welcomePage;
- ToolButtonWidgetMap buttonMap;
- QHBoxLayout * buttonLayout;
- Ui::WelcomeMode ui;
-};
-
-// --- WelcomeMode
-WelcomeMode::WelcomeMode() :
- m_d(new WelcomeModePrivate)
-{
- setDisplayName(tr("Welcome"));
- setIcon(QIcon(QLatin1String(Core::Constants::ICON_QTLOGO_32)));
- setPriority(Core::Constants::P_MODE_WELCOME);
- setId(QLatin1String(Core::Constants::MODE_WELCOME));
- setType(QLatin1String(Core::Constants::MODE_WELCOME_TYPE));
- setContextHelpId(QLatin1String("Qt Creator Manual"));
-
- m_d->m_widget = new QWidget;
- QVBoxLayout *l = new QVBoxLayout(m_d->m_widget);
- l->setMargin(0);
- l->setSpacing(0);
- l->addWidget(new Utils::StyledBar(m_d->m_widget));
- m_d->m_welcomePage = new ImageWidget(QImage(":/welcome/images/welcomebg.png"), m_d->m_widget);
- m_d->ui.setupUi(m_d->m_welcomePage);
- m_d->ui.helpUsLabel->setAttribute(Qt::WA_LayoutUsesWidgetRect);
- m_d->ui.feedbackButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
- l->addWidget(m_d->m_welcomePage);
-
- m_d->m_scrollArea = new QScrollArea;
- m_d->m_scrollArea->setFrameStyle(QFrame::NoFrame);
- m_d->m_scrollArea->setWidget(m_d->m_widget);
- m_d->m_scrollArea->setWidgetResizable(true);
-
- setContext(Core::Context(Core::Constants::C_WELCOME_MODE));
- setWidget(m_d->m_scrollArea);
-
- PluginManager *pluginManager = PluginManager::instance();
- connect(pluginManager, SIGNAL(objectAdded(QObject*)), SLOT(welcomePluginAdded(QObject*)));
-
- connect(m_d->ui.feedbackButton, SIGNAL(clicked()), SLOT(slotFeedback()));
-}
-
-WelcomeMode::~WelcomeMode()
-{
- QSettings *settings = Core::ICore::instance()->settings();
- settings->setValue(QLatin1String(currentPageSettingsKeyC), m_d->ui.stackedWidget->currentIndex());
- delete m_d->m_widget;
- delete m_d;
-}
-
-bool sortFunction(Utils::IWelcomePage *a, Utils::IWelcomePage *b)
-{
- return a->priority() < b->priority();
-}
-
-// Create a QToolButton for a page
-QToolButton *WelcomeMode::addPageToolButton(Utils::IWelcomePage *plugin, int position)
-{
- QToolButton *btn = new QToolButton;
- btn->setCheckable(true);
- btn->setText(plugin->title());
- btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
- btn->setAutoExclusive(true);
- connect (btn, SIGNAL(clicked()), SLOT(showClickedPage()));
- m_d->buttonMap.insert(btn, plugin->page());
- if (position >= 0) {
- m_d->buttonLayout->insertWidget(position, btn);
- } else {
- m_d->buttonLayout->addWidget(btn);
- }
- return btn;
-}
-
-void WelcomeMode::initPlugins()
-{
- m_d->buttonLayout = new QHBoxLayout(m_d->ui.navFrame);
- m_d->buttonLayout->setMargin(0);
- m_d->buttonLayout->setSpacing(0);
- QList<Utils::IWelcomePage*> plugins = PluginManager::instance()->getObjects<Utils::IWelcomePage>();
- qSort(plugins.begin(), plugins.end(), &sortFunction);
- foreach (Utils::IWelcomePage *plugin, plugins) {
- m_d->ui.stackedWidget->addWidget(plugin->page());
- addPageToolButton(plugin);
- if (debug)
- qDebug() << "WelcomeMode::initPlugins" << plugin->title();
- }
- QSettings *settings = Core::ICore::instance()->settings();
- const int tabId = settings->value(QLatin1String(currentPageSettingsKeyC), 0).toInt();
-
- const int pluginCount = m_d->ui.stackedWidget->count();
- if (tabId >= 0 && tabId < pluginCount) {
- m_d->ui.stackedWidget->setCurrentIndex(tabId);
- if (QToolButton *btn = m_d->buttonMap.key(m_d->ui.stackedWidget->currentWidget()))
- btn->setChecked(true);
- }
-}
-
-void WelcomeMode::welcomePluginAdded(QObject *obj)
-{
- if (Utils::IWelcomePage *plugin = qobject_cast<Utils::IWelcomePage*>(obj)) {
- int insertPos = 0;
- foreach (Utils::IWelcomePage* p, PluginManager::instance()->getObjects<Utils::IWelcomePage>()) {
- if (plugin->priority() < p->priority())
- insertPos++;
- else
- break;
- }
- m_d->ui.stackedWidget->insertWidget(insertPos, plugin->page());
- addPageToolButton(plugin, insertPos);
- if (debug)
- qDebug() << "welcomePluginAdded" << plugin->title() << "at" << insertPos
- << " of " << m_d->buttonMap.size();
- }
-}
-
-void WelcomeMode::showClickedPage()
-{
- QToolButton *btn = qobject_cast<QToolButton*>(sender());
- const WelcomeModePrivate::ToolButtonWidgetMap::const_iterator it = m_d->buttonMap.constFind(btn);
- if (it != m_d->buttonMap.constEnd())
- m_d->ui.stackedWidget->setCurrentWidget(it.value());
-}
-
-void WelcomeMode::slotFeedback()
-{
- QDesktopServices::openUrl(QUrl(QLatin1String(
- "http://qt.nokia.com/forms/feedback-forms/qt-creator-user-feedback/view")));
-}
-
-} // namespace Welcome
diff --git a/src/plugins/welcome/welcomemode.h b/src/plugins/welcome/welcomemode.h
deleted file mode 100644
index a4321aae0d..0000000000
--- a/src/plugins/welcome/welcomemode.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/**************************************************************************
-**
-** This file is part of Qt Creator
-**
-** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
-**
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** No Commercial Usage
-**
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-**
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**************************************************************************/
-
-#ifndef WELCOMEMODE_H
-#define WELCOMEMODE_H
-
-#include "welcome_global.h"
-
-#include <coreplugin/imode.h>
-
-QT_BEGIN_NAMESPACE
-class QToolButton;
-QT_END_NAMESPACE
-
-namespace Utils {
- class IWelcomePage;
-}
-namespace Welcome {
-
-struct WelcomeModePrivate;
-
-class WELCOME_EXPORT WelcomeMode : public Core::IMode
-{
- Q_OBJECT
-
-public:
- WelcomeMode();
- ~WelcomeMode();
-
- void activated();
- void initPlugins();
-
-private slots:
- void slotFeedback();
- void welcomePluginAdded(QObject*);
- void showClickedPage();
-
-private:
- QToolButton *addPageToolButton(Utils::IWelcomePage *plugin, int position = -1);
-
- WelcomeModePrivate *m_d;
-};
-
-} // namespace Welcome
-
-#endif // WELCOMEMODE_H
diff --git a/src/plugins/welcome/welcomeplugin.cpp b/src/plugins/welcome/welcomeplugin.cpp
index 4869dea168..d8524251b8 100644
--- a/src/plugins/welcome/welcomeplugin.cpp
+++ b/src/plugins/welcome/welcomeplugin.cpp
@@ -32,21 +32,223 @@
**************************************************************************/
#include "welcomeplugin.h"
-#include "welcomemode.h"
+
#include "communitywelcomepage.h"
+#include "ui_welcomemode.h"
+
+#include <extensionsystem/pluginmanager.h>
+#include <coreplugin/coreconstants.h>
+#include <coreplugin/icore.h>
+#include <coreplugin/imode.h>
#include <coreplugin/modemanager.h>
+#include <utils/styledbar.h>
+#include <utils/welcomemodetreewidget.h>
+#include <utils/iwelcomepage.h>
+
+#include <QtGui/QScrollArea>
+#include <QtGui/QDesktopServices>
+#include <QtGui/QToolButton>
+#include <QtGui/QPainter>
+
+#include <QtCore/QSettings>
+#include <QtCore/QDebug>
+#include <QtCore/QUrl>
#include <QtCore/QtPlugin>
-using namespace Welcome::Internal;
+enum { debug = 0 };
-WelcomePlugin::WelcomePlugin()
- : m_welcomeMode(0)
+using namespace ExtensionSystem;
+
+namespace Utils {
+ class IWelcomePage;
+}
+
+namespace Welcome {
+namespace Internal {
+
+// Helper class introduced to cache the scaled background image
+// so we avoid re-scaling for every repaint.
+class ImageWidget : public QWidget
+{
+public:
+ ImageWidget(const QImage &bg, QWidget *parent) : QWidget(parent), m_bg(bg) {}
+ void paintEvent(QPaintEvent *e) {
+ if (!m_bg.isNull()) {
+ QPainter painter(this);
+ if (m_stretch.size() != size())
+ m_stretch = QPixmap::fromImage(m_bg.scaled(size(),
+ Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
+ if (!m_stretch.size().isEmpty())
+ painter.drawPixmap(rect(), m_stretch);
+ }
+ QWidget::paintEvent(e);
+ }
+private:
+ QImage m_bg;
+ QPixmap m_stretch;
+};
+
+class WelcomeMode : public Core::IMode
+{
+ Q_OBJECT
+
+public:
+ WelcomeMode();
+ ~WelcomeMode();
+
+ void activated();
+ void initPlugins();
+
+private slots:
+ void slotFeedback();
+ void welcomePluginAdded(QObject*);
+ void showClickedPage();
+
+private:
+ QToolButton *addPageToolButton(Utils::IWelcomePage *plugin, int position = -1);
+
+ typedef QMap<QToolButton *, QWidget *> ToolButtonWidgetMap;
+
+ QScrollArea *m_scrollArea;
+ QWidget *m_outerWidget;
+ ImageWidget *m_welcomePage;
+ ToolButtonWidgetMap buttonMap;
+ QHBoxLayout * buttonLayout;
+ Ui::WelcomeMode ui;
+};
+
+static const char currentPageSettingsKeyC[] = "General/WelcomeTab";
+
+// --- WelcomeMode
+WelcomeMode::WelcomeMode()
+{
+ setDisplayName(tr("Welcome"));
+ setIcon(QIcon(QLatin1String(Core::Constants::ICON_QTLOGO_32)));
+ setPriority(Core::Constants::P_MODE_WELCOME);
+ setId(QLatin1String(Core::Constants::MODE_WELCOME));
+ setType(QLatin1String(Core::Constants::MODE_WELCOME_TYPE));
+ setContextHelpId(QLatin1String("Qt Creator Manual"));
+
+ m_outerWidget = new QWidget;
+ QVBoxLayout *l = new QVBoxLayout(m_outerWidget);
+ l->setMargin(0);
+ l->setSpacing(0);
+ l->addWidget(new Utils::StyledBar(m_outerWidget));
+ m_welcomePage = new ImageWidget(QImage(":/welcome/images/welcomebg.png"), m_outerWidget);
+ ui.setupUi(m_welcomePage);
+ ui.helpUsLabel->setAttribute(Qt::WA_LayoutUsesWidgetRect);
+ ui.feedbackButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
+ l->addWidget(m_welcomePage);
+
+ m_scrollArea = new QScrollArea;
+ m_scrollArea->setFrameStyle(QFrame::NoFrame);
+ m_scrollArea->setWidget(m_outerWidget);
+ m_scrollArea->setWidgetResizable(true);
+
+ setContext(Core::Context(Core::Constants::C_WELCOME_MODE));
+ setWidget(m_scrollArea);
+
+ PluginManager *pluginManager = PluginManager::instance();
+ connect(pluginManager, SIGNAL(objectAdded(QObject*)), SLOT(welcomePluginAdded(QObject*)));
+
+ connect(ui.feedbackButton, SIGNAL(clicked()), SLOT(slotFeedback()));
+}
+
+WelcomeMode::~WelcomeMode()
{
+ QSettings *settings = Core::ICore::instance()->settings();
+ settings->setValue(QLatin1String(currentPageSettingsKeyC), ui.stackedWidget->currentIndex());
+ delete m_outerWidget;
}
-WelcomePlugin::~WelcomePlugin()
+bool sortFunction(Utils::IWelcomePage *a, Utils::IWelcomePage *b)
+{
+ return a->priority() < b->priority();
+}
+
+// Create a QToolButton for a page
+QToolButton *WelcomeMode::addPageToolButton(Utils::IWelcomePage *plugin, int position)
+{
+ QToolButton *btn = new QToolButton;
+ btn->setCheckable(true);
+ btn->setText(plugin->title());
+ btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+ btn->setAutoExclusive(true);
+ connect (btn, SIGNAL(clicked()), SLOT(showClickedPage()));
+ buttonMap.insert(btn, plugin->page());
+ if (position >= 0) {
+ buttonLayout->insertWidget(position, btn);
+ } else {
+ buttonLayout->addWidget(btn);
+ }
+ return btn;
+}
+
+void WelcomeMode::initPlugins()
+{
+ buttonLayout = new QHBoxLayout(ui.navFrame);
+ buttonLayout->setMargin(0);
+ buttonLayout->setSpacing(0);
+ QList<Utils::IWelcomePage*> plugins = PluginManager::instance()->getObjects<Utils::IWelcomePage>();
+ qSort(plugins.begin(), plugins.end(), &sortFunction);
+ foreach (Utils::IWelcomePage *plugin, plugins) {
+ ui.stackedWidget->addWidget(plugin->page());
+ addPageToolButton(plugin);
+ if (debug)
+ qDebug() << "WelcomeMode::initPlugins" << plugin->title();
+ }
+ QSettings *settings = Core::ICore::instance()->settings();
+ const int tabId = settings->value(QLatin1String(currentPageSettingsKeyC), 0).toInt();
+
+ const int pluginCount = ui.stackedWidget->count();
+ if (tabId >= 0 && tabId < pluginCount) {
+ ui.stackedWidget->setCurrentIndex(tabId);
+ if (QToolButton *btn = buttonMap.key(ui.stackedWidget->currentWidget()))
+ btn->setChecked(true);
+ }
+}
+
+void WelcomeMode::welcomePluginAdded(QObject *obj)
+{
+ if (Utils::IWelcomePage *plugin = qobject_cast<Utils::IWelcomePage*>(obj)) {
+ int insertPos = 0;
+ foreach (Utils::IWelcomePage* p, PluginManager::instance()->getObjects<Utils::IWelcomePage>()) {
+ if (plugin->priority() < p->priority())
+ insertPos++;
+ else
+ break;
+ }
+ ui.stackedWidget->insertWidget(insertPos, plugin->page());
+ addPageToolButton(plugin, insertPos);
+ if (debug)
+ qDebug() << "welcomePluginAdded" << plugin->title() << "at" << insertPos
+ << " of " << buttonMap.size();
+ }
+}
+
+void WelcomeMode::showClickedPage()
+{
+ QToolButton *btn = qobject_cast<QToolButton*>(sender());
+ const ToolButtonWidgetMap::const_iterator it = buttonMap.constFind(btn);
+ if (it != buttonMap.constEnd())
+ ui.stackedWidget->setCurrentWidget(it.value());
+}
+
+void WelcomeMode::slotFeedback()
+{
+ QDesktopServices::openUrl(QUrl(QLatin1String(
+ "http://qt.nokia.com/forms/feedback-forms/qt-creator-user-feedback/view")));
+}
+
+
+//
+
+
+
+WelcomePlugin::WelcomePlugin()
+ : m_welcomeMode(0)
{
}
@@ -83,4 +285,10 @@ void WelcomePlugin::extensionsInitialized()
Core::ModeManager::instance()->activateMode(m_welcomeMode->id());
}
-Q_EXPORT_PLUGIN(WelcomePlugin)
+} // namespace Welcome
+} // namespace Internal
+
+
+Q_EXPORT_PLUGIN(Welcome::Internal::WelcomePlugin)
+
+#include "welcomeplugin.moc"
diff --git a/src/plugins/welcome/welcomeplugin.h b/src/plugins/welcome/welcomeplugin.h
index 115154890e..547ca09a6c 100644
--- a/src/plugins/welcome/welcomeplugin.h
+++ b/src/plugins/welcome/welcomeplugin.h
@@ -37,19 +37,17 @@
#include <extensionsystem/iplugin.h>
namespace Welcome {
-class WelcomeMode;
-
namespace Internal {
+class WelcomeMode;
+
class WelcomePlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
WelcomePlugin();
- virtual ~WelcomePlugin();
virtual bool initialize(const QStringList &arguments, QString *error_message);
-
virtual void extensionsInitialized();
private: