From 269b82be6f11808a8831d39c53275d2ca5e060f3 Mon Sep 17 00:00:00 2001 From: Daniel Molkentin Date: Wed, 7 Apr 2010 18:02:26 +0200 Subject: [PATCH] Port the example chooser to a structured menu and a QPushButton. Looks more structured now. --- .../gettingstartedwelcomepagewidget.cpp | 48 ++++++++--------- .../gettingstartedwelcomepagewidget.h | 1 - .../gettingstartedwelcomepagewidget.ui | 51 +++++-------------- 3 files changed, 37 insertions(+), 63 deletions(-) diff --git a/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.cpp b/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.cpp index 80ffdc4fc83..3b479af45ce 100644 --- a/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.cpp +++ b/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.cpp @@ -51,10 +51,14 @@ #include #include #include +#include namespace Qt4ProjectManager { namespace Internal { +const char ExamplePathPropertyName[] = "__qt_ExamplePath"; +const char HelpPathPropertyName[] = "__qt_HelpPath"; + GettingStartedWelcomePageWidget::GettingStartedWelcomePageWidget(QWidget *parent) : QWidget(parent), ui(new Ui::GettingStartedWelcomePageWidget) @@ -66,8 +70,6 @@ GettingStartedWelcomePageWidget::GettingStartedWelcomePageWidget(QWidget *parent ui->didYouKnowTitleLabel->setStyledText(tr("Did You Know?")); connect(ui->tutorialTreeWidget, SIGNAL(activated(QString)), SLOT(slotOpenHelpPage(const QString&))); - connect(ui->openExampleButton, SIGNAL(clicked()), SLOT(slotOpenExample())); - connect(ui->examplesComboBox, SIGNAL(currentIndexChanged(int)), SLOT(slotEnableExampleButton(int))); ui->tutorialTreeWidget->addItem(tr("Qt Creator - A quick tour"), QString("qthelp://com.nokia.qtcreator.%1%2/doc/index.html").arg(IDE_VERSION_MAJOR).arg(IDE_VERSION_MINOR)); @@ -114,17 +116,16 @@ void GettingStartedWelcomePageWidget::updateExamples(const QString &examplePath, if (!description.open(QFile::ReadOnly)) return; - ui->examplesComboBox->clear(); - ui->examplesComboBox->setEnabled(true); + ui->examplesButton->setEnabled(true); + ui->examplesButton->setText(tr("Choose an example...")); + QMenu *menu = new QMenu; + ui->examplesButton->setMenu(menu); - ui->examplesComboBox->addItem(tr("Choose an example...")); - QFont f = font(); - f.setItalic(true); - ui->examplesComboBox->setItemData(0, f, Qt::FontRole); - f.setItalic(false); + QMenu *subMenu = 0; bool inExamples = false; QString dirName; QXmlStreamReader reader(&description); + while (!reader.atEnd()) { switch (reader.readNext()) { case QXmlStreamReader::StartElement: @@ -133,10 +134,7 @@ void GettingStartedWelcomePageWidget::updateExamples(const QString &examplePath, if (name.contains("tutorial")) break; dirName = reader.attributes().value(QLatin1String("dirname")).toString(); - ui->examplesComboBox->addItem(name); - f.setBold(true); - ui->examplesComboBox->setItemData(ui->examplesComboBox->count()-1, f, Qt::FontRole); - f.setBold(false); + subMenu = menu->addMenu(name); inExamples = true; } if (inExamples && reader.name() == "example") { @@ -151,8 +149,11 @@ void GettingStartedWelcomePageWidget::updateExamples(const QString &examplePath, dirName.replace(slash, QLatin1Char('-')) + QLatin1Char('-') + fn + QLatin1String(".html"); - ui->examplesComboBox->addItem(QLatin1String(" ") + name, fileName); - ui->examplesComboBox->setItemData(ui->examplesComboBox->count()-1, helpPath, Qt::UserRole+1); + QAction *exampleAction = subMenu->addAction(name); + connect(exampleAction, SIGNAL(triggered()), SLOT(slotOpenExample())); + + exampleAction->setProperty(ExamplePathPropertyName, fileName); + exampleAction->setProperty(HelpPathPropertyName, helpPath); } break; case QXmlStreamReader::EndElement: @@ -165,11 +166,6 @@ void GettingStartedWelcomePageWidget::updateExamples(const QString &examplePath, } } -void GettingStartedWelcomePageWidget::slotEnableExampleButton(int index) -{ - QString fileName = ui->examplesComboBox->itemData(index, Qt::UserRole).toString(); - ui->openExampleButton->setEnabled(!fileName.isEmpty()); -} namespace { void copyRecursive(const QDir& from, const QDir& to, const QString& dir) @@ -190,10 +186,14 @@ void copyRecursive(const QDir& from, const QDir& to, const QString& dir) void GettingStartedWelcomePageWidget::slotOpenExample() { - QComboBox *box = ui->examplesComboBox; - QString proFile = box->itemData(box->currentIndex(), Qt::UserRole).toString(); - QString helpFile = box->itemData(box->currentIndex(), Qt::UserRole + 1).toString(); + QAction *action = qobject_cast(sender()); + if (!action) + return; + + QString helpFile = action->property(HelpPathPropertyName).toString(); + QString proFile = action->property(ExamplePathPropertyName).toString(); QStringList files; + QFileInfo proFileInfo(proFile); // If the Qt is a distro Qt on Linux, it will not be writable, hence compilation will fail if (!proFileInfo.isWritable()) @@ -266,7 +266,7 @@ void GettingStartedWelcomePageWidget::slotOpenExample() void GettingStartedWelcomePageWidget::slotOpenHelpPage(const QString& url) { Help::HelpManager *helpManager - = ExtensionSystem::PluginManager::instance()->getObject(); + = ExtensionSystem::PluginManager::instance()->getObject(); Q_ASSERT(helpManager); helpManager->handleHelpRequest(url); } diff --git a/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.h b/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.h index 21cceb1cc8b..a2e981c70f5 100644 --- a/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.h +++ b/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.h @@ -54,7 +54,6 @@ public slots: private slots: void slotOpenHelpPage(const QString &url); void slotOpenContextHelpPage(const QString &url); - void slotEnableExampleButton(int); void slotOpenExample(); void slotNextTip(); void slotPrevTip(); diff --git a/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.ui b/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.ui index 13238718fd9..facd533e3ac 100644 --- a/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.ui +++ b/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.ui @@ -86,6 +86,15 @@ 0 + + 24 + + + false + + + 0 + 1 @@ -125,7 +134,7 @@ 0 - + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop @@ -133,55 +142,21 @@ - + false - - 0 - 0 - - - - - Examples not installed - - - - - - - - false - - - + 0 0 - Open + Examples not installed... - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 6 - 6 - - - -