forked from qt-creator/qt-creator
welcome: simplify plugin code
This commit is contained in:
@@ -57,14 +57,10 @@
|
|||||||
#include <QtCore/QUrl>
|
#include <QtCore/QUrl>
|
||||||
#include <QtCore/QtPlugin>
|
#include <QtCore/QtPlugin>
|
||||||
|
|
||||||
enum { debug = 0 };
|
enum { debug = 1 };
|
||||||
|
|
||||||
using namespace ExtensionSystem;
|
using namespace ExtensionSystem;
|
||||||
|
|
||||||
namespace Utils {
|
|
||||||
class IWelcomePage;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Welcome {
|
namespace Welcome {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -73,8 +69,13 @@ namespace Internal {
|
|||||||
class ImageWidget : public QWidget
|
class ImageWidget : public QWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ImageWidget(const QImage &bg, QWidget *parent) : QWidget(parent), m_bg(bg) {}
|
explicit ImageWidget(QWidget *parent)
|
||||||
void paintEvent(QPaintEvent *e) {
|
: QWidget(parent),
|
||||||
|
m_bg(":/welcome/images/welcomebg.png")
|
||||||
|
{}
|
||||||
|
|
||||||
|
void paintEvent(QPaintEvent *e)
|
||||||
|
{
|
||||||
if (!m_bg.isNull()) {
|
if (!m_bg.isNull()) {
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
if (m_stretch.size() != size())
|
if (m_stretch.size() != size())
|
||||||
@@ -85,6 +86,7 @@ public:
|
|||||||
}
|
}
|
||||||
QWidget::paintEvent(e);
|
QWidget::paintEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QImage m_bg;
|
QImage m_bg;
|
||||||
QPixmap m_stretch;
|
QPixmap m_stretch;
|
||||||
@@ -107,15 +109,15 @@ private slots:
|
|||||||
void showClickedPage();
|
void showClickedPage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QToolButton *addPageToolButton(Utils::IWelcomePage *plugin, int position = -1);
|
void addPageToolButton(Utils::IWelcomePage *plugin, int position = -1);
|
||||||
|
|
||||||
typedef QMap<QToolButton *, QWidget *> ToolButtonWidgetMap;
|
typedef QMap<QToolButton *, QWidget *> ToolButtonWidgetMap;
|
||||||
|
|
||||||
QScrollArea *m_scrollArea;
|
QScrollArea m_scrollArea;
|
||||||
QWidget *m_outerWidget;
|
QWidget m_outerWidget;
|
||||||
ImageWidget *m_welcomePage;
|
ImageWidget *m_welcomePage;
|
||||||
ToolButtonWidgetMap buttonMap;
|
ToolButtonWidgetMap buttonMap;
|
||||||
QHBoxLayout * buttonLayout;
|
QHBoxLayout *buttonLayout;
|
||||||
Ui::WelcomeMode ui;
|
Ui::WelcomeMode ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -130,25 +132,22 @@ WelcomeMode::WelcomeMode()
|
|||||||
setId(QLatin1String(Core::Constants::MODE_WELCOME));
|
setId(QLatin1String(Core::Constants::MODE_WELCOME));
|
||||||
setType(QLatin1String(Core::Constants::MODE_WELCOME_TYPE));
|
setType(QLatin1String(Core::Constants::MODE_WELCOME_TYPE));
|
||||||
setContextHelpId(QLatin1String("Qt Creator Manual"));
|
setContextHelpId(QLatin1String("Qt Creator Manual"));
|
||||||
|
setContext(Core::Context(Core::Constants::C_WELCOME_MODE));
|
||||||
|
setWidget(&m_scrollArea);
|
||||||
|
|
||||||
m_outerWidget = new QWidget;
|
QVBoxLayout *l = new QVBoxLayout(&m_outerWidget);
|
||||||
QVBoxLayout *l = new QVBoxLayout(m_outerWidget);
|
|
||||||
l->setMargin(0);
|
l->setMargin(0);
|
||||||
l->setSpacing(0);
|
l->setSpacing(0);
|
||||||
l->addWidget(new Utils::StyledBar(m_outerWidget));
|
l->addWidget(new Utils::StyledBar(&m_outerWidget));
|
||||||
m_welcomePage = new ImageWidget(QImage(":/welcome/images/welcomebg.png"), m_outerWidget);
|
m_welcomePage = new ImageWidget(&m_outerWidget);
|
||||||
ui.setupUi(m_welcomePage);
|
ui.setupUi(m_welcomePage);
|
||||||
ui.helpUsLabel->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
ui.helpUsLabel->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||||
ui.feedbackButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
ui.feedbackButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||||
l->addWidget(m_welcomePage);
|
l->addWidget(m_welcomePage);
|
||||||
|
|
||||||
m_scrollArea = new QScrollArea;
|
m_scrollArea.setFrameStyle(QFrame::NoFrame);
|
||||||
m_scrollArea->setFrameStyle(QFrame::NoFrame);
|
m_scrollArea.setWidget(&m_outerWidget);
|
||||||
m_scrollArea->setWidget(m_outerWidget);
|
m_scrollArea.setWidgetResizable(true);
|
||||||
m_scrollArea->setWidgetResizable(true);
|
|
||||||
|
|
||||||
setContext(Core::Context(Core::Constants::C_WELCOME_MODE));
|
|
||||||
setWidget(m_scrollArea);
|
|
||||||
|
|
||||||
PluginManager *pluginManager = PluginManager::instance();
|
PluginManager *pluginManager = PluginManager::instance();
|
||||||
connect(pluginManager, SIGNAL(objectAdded(QObject*)), SLOT(welcomePluginAdded(QObject*)));
|
connect(pluginManager, SIGNAL(objectAdded(QObject*)), SLOT(welcomePluginAdded(QObject*)));
|
||||||
@@ -160,7 +159,6 @@ WelcomeMode::~WelcomeMode()
|
|||||||
{
|
{
|
||||||
QSettings *settings = Core::ICore::instance()->settings();
|
QSettings *settings = Core::ICore::instance()->settings();
|
||||||
settings->setValue(QLatin1String(currentPageSettingsKeyC), ui.stackedWidget->currentIndex());
|
settings->setValue(QLatin1String(currentPageSettingsKeyC), ui.stackedWidget->currentIndex());
|
||||||
delete m_outerWidget;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sortFunction(Utils::IWelcomePage *a, Utils::IWelcomePage *b)
|
bool sortFunction(Utils::IWelcomePage *a, Utils::IWelcomePage *b)
|
||||||
@@ -169,21 +167,19 @@ bool sortFunction(Utils::IWelcomePage *a, Utils::IWelcomePage *b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a QToolButton for a page
|
// Create a QToolButton for a page
|
||||||
QToolButton *WelcomeMode::addPageToolButton(Utils::IWelcomePage *plugin, int position)
|
void WelcomeMode::addPageToolButton(Utils::IWelcomePage *plugin, int position)
|
||||||
{
|
{
|
||||||
QToolButton *btn = new QToolButton;
|
QToolButton *btn = new QToolButton;
|
||||||
btn->setCheckable(true);
|
btn->setCheckable(true);
|
||||||
btn->setText(plugin->title());
|
btn->setText(plugin->title());
|
||||||
btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
btn->setAutoExclusive(true);
|
btn->setAutoExclusive(true);
|
||||||
connect (btn, SIGNAL(clicked()), SLOT(showClickedPage()));
|
connect(btn, SIGNAL(clicked()), SLOT(showClickedPage()));
|
||||||
buttonMap.insert(btn, plugin->page());
|
buttonMap.insert(btn, plugin->page());
|
||||||
if (position >= 0) {
|
if (position >= 0)
|
||||||
buttonLayout->insertWidget(position, btn);
|
buttonLayout->insertWidget(position, btn);
|
||||||
} else {
|
else
|
||||||
buttonLayout->addWidget(btn);
|
buttonLayout->addWidget(btn);
|
||||||
}
|
|
||||||
return btn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WelcomeMode::initPlugins()
|
void WelcomeMode::initPlugins()
|
||||||
@@ -212,20 +208,23 @@ void WelcomeMode::initPlugins()
|
|||||||
|
|
||||||
void WelcomeMode::welcomePluginAdded(QObject *obj)
|
void WelcomeMode::welcomePluginAdded(QObject *obj)
|
||||||
{
|
{
|
||||||
if (Utils::IWelcomePage *plugin = qobject_cast<Utils::IWelcomePage*>(obj)) {
|
Utils::IWelcomePage *plugin = qobject_cast<Utils::IWelcomePage*>(obj);
|
||||||
int insertPos = 0;
|
if (!plugin)
|
||||||
foreach (Utils::IWelcomePage* p, PluginManager::instance()->getObjects<Utils::IWelcomePage>()) {
|
return;
|
||||||
if (plugin->priority() < p->priority())
|
|
||||||
insertPos++;
|
int insertPos = 0;
|
||||||
else
|
QList<Utils::IWelcomePage *> pages
|
||||||
break;
|
= PluginManager::instance()->getObjects<Utils::IWelcomePage>();
|
||||||
}
|
foreach (Utils::IWelcomePage *p, pages) {
|
||||||
ui.stackedWidget->insertWidget(insertPos, plugin->page());
|
if (plugin->priority() >= p->priority())
|
||||||
addPageToolButton(plugin, insertPos);
|
break;
|
||||||
if (debug)
|
insertPos++;
|
||||||
qDebug() << "welcomePluginAdded" << plugin->title() << "at" << insertPos
|
|
||||||
<< " of " << buttonMap.size();
|
|
||||||
}
|
}
|
||||||
|
ui.stackedWidget->insertWidget(insertPos, plugin->page());
|
||||||
|
addPageToolButton(plugin, insertPos);
|
||||||
|
if (debug)
|
||||||
|
qDebug() << "welcomePluginAdded" << plugin->title() << "at" << insertPos
|
||||||
|
<< " of " << buttonMap.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WelcomeMode::showClickedPage()
|
void WelcomeMode::showClickedPage()
|
||||||
|
Reference in New Issue
Block a user