Commit 269b82be authored by Daniel Molkentin's avatar Daniel Molkentin
Browse files

Port the example chooser to a structured menu and a QPushButton.

Looks more structured now.
parent 7e1f9d9f
......@@ -51,10 +51,14 @@
#include <QtGui/QFont>
#include <QtGui/QMessageBox>
#include <QtGui/QPushButton>
#include <QtGui/QMenu>
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("<b>Qt Creator - A quick tour</b>"),
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<QAction*>(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<Help::HelpManager>();
= ExtensionSystem::PluginManager::instance()->getObject<Help::HelpManager>();
Q_ASSERT(helpManager);
helpManager->handleHelpRequest(url);
}
......
......@@ -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();
......
......@@ -86,6 +86,15 @@
<attribute name="headerMinimumSectionSize">
<number>0</number>
</attribute>
<attribute name="headerDefaultSectionSize">
<number>24</number>
</attribute>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<attribute name="headerMinimumSectionSize">
<number>0</number>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
......@@ -125,7 +134,7 @@
<property name="horizontalSpacing">
<number>0</number>
</property>
<item row="0" column="0" colspan="4">
<item row="0" column="0" colspan="3">
<widget class="Utils::WelcomeModeLabel" name="demoTitleLabel">
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
......@@ -133,55 +142,21 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QComboBox" name="examplesComboBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Examples not installed</string>
</property>
</item>
</widget>
</item>
<item row="1" column="2">
<widget class="QToolButton" name="openExampleButton">
<widget class="QPushButton" name="examplesButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Open</string>
<string>Examples not installed...</string>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>6</width>
<height>6</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment