forked from qt-creator/qt-creator
Port the example chooser to a structured menu and a QPushButton.
Looks more structured now.
This commit is contained in:
@@ -51,10 +51,14 @@
|
|||||||
#include <QtGui/QFont>
|
#include <QtGui/QFont>
|
||||||
#include <QtGui/QMessageBox>
|
#include <QtGui/QMessageBox>
|
||||||
#include <QtGui/QPushButton>
|
#include <QtGui/QPushButton>
|
||||||
|
#include <QtGui/QMenu>
|
||||||
|
|
||||||
namespace Qt4ProjectManager {
|
namespace Qt4ProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
const char ExamplePathPropertyName[] = "__qt_ExamplePath";
|
||||||
|
const char HelpPathPropertyName[] = "__qt_HelpPath";
|
||||||
|
|
||||||
GettingStartedWelcomePageWidget::GettingStartedWelcomePageWidget(QWidget *parent) :
|
GettingStartedWelcomePageWidget::GettingStartedWelcomePageWidget(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::GettingStartedWelcomePageWidget)
|
ui(new Ui::GettingStartedWelcomePageWidget)
|
||||||
@@ -66,8 +70,6 @@ GettingStartedWelcomePageWidget::GettingStartedWelcomePageWidget(QWidget *parent
|
|||||||
ui->didYouKnowTitleLabel->setStyledText(tr("Did You Know?"));
|
ui->didYouKnowTitleLabel->setStyledText(tr("Did You Know?"));
|
||||||
|
|
||||||
connect(ui->tutorialTreeWidget, SIGNAL(activated(QString)), SLOT(slotOpenHelpPage(const QString&)));
|
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>"),
|
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));
|
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))
|
if (!description.open(QFile::ReadOnly))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ui->examplesComboBox->clear();
|
ui->examplesButton->setEnabled(true);
|
||||||
ui->examplesComboBox->setEnabled(true);
|
ui->examplesButton->setText(tr("Choose an example..."));
|
||||||
|
QMenu *menu = new QMenu;
|
||||||
|
ui->examplesButton->setMenu(menu);
|
||||||
|
|
||||||
ui->examplesComboBox->addItem(tr("Choose an example..."));
|
QMenu *subMenu = 0;
|
||||||
QFont f = font();
|
|
||||||
f.setItalic(true);
|
|
||||||
ui->examplesComboBox->setItemData(0, f, Qt::FontRole);
|
|
||||||
f.setItalic(false);
|
|
||||||
bool inExamples = false;
|
bool inExamples = false;
|
||||||
QString dirName;
|
QString dirName;
|
||||||
QXmlStreamReader reader(&description);
|
QXmlStreamReader reader(&description);
|
||||||
|
|
||||||
while (!reader.atEnd()) {
|
while (!reader.atEnd()) {
|
||||||
switch (reader.readNext()) {
|
switch (reader.readNext()) {
|
||||||
case QXmlStreamReader::StartElement:
|
case QXmlStreamReader::StartElement:
|
||||||
@@ -133,10 +134,7 @@ void GettingStartedWelcomePageWidget::updateExamples(const QString &examplePath,
|
|||||||
if (name.contains("tutorial"))
|
if (name.contains("tutorial"))
|
||||||
break;
|
break;
|
||||||
dirName = reader.attributes().value(QLatin1String("dirname")).toString();
|
dirName = reader.attributes().value(QLatin1String("dirname")).toString();
|
||||||
ui->examplesComboBox->addItem(name);
|
subMenu = menu->addMenu(name);
|
||||||
f.setBold(true);
|
|
||||||
ui->examplesComboBox->setItemData(ui->examplesComboBox->count()-1, f, Qt::FontRole);
|
|
||||||
f.setBold(false);
|
|
||||||
inExamples = true;
|
inExamples = true;
|
||||||
}
|
}
|
||||||
if (inExamples && reader.name() == "example") {
|
if (inExamples && reader.name() == "example") {
|
||||||
@@ -151,8 +149,11 @@ void GettingStartedWelcomePageWidget::updateExamples(const QString &examplePath,
|
|||||||
dirName.replace(slash, QLatin1Char('-')) +
|
dirName.replace(slash, QLatin1Char('-')) +
|
||||||
QLatin1Char('-') + fn + QLatin1String(".html");
|
QLatin1Char('-') + fn + QLatin1String(".html");
|
||||||
|
|
||||||
ui->examplesComboBox->addItem(QLatin1String(" ") + name, fileName);
|
QAction *exampleAction = subMenu->addAction(name);
|
||||||
ui->examplesComboBox->setItemData(ui->examplesComboBox->count()-1, helpPath, Qt::UserRole+1);
|
connect(exampleAction, SIGNAL(triggered()), SLOT(slotOpenExample()));
|
||||||
|
|
||||||
|
exampleAction->setProperty(ExamplePathPropertyName, fileName);
|
||||||
|
exampleAction->setProperty(HelpPathPropertyName, helpPath);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QXmlStreamReader::EndElement:
|
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 {
|
namespace {
|
||||||
void copyRecursive(const QDir& from, const QDir& to, const QString& dir)
|
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()
|
void GettingStartedWelcomePageWidget::slotOpenExample()
|
||||||
{
|
{
|
||||||
QComboBox *box = ui->examplesComboBox;
|
QAction *action = qobject_cast<QAction*>(sender());
|
||||||
QString proFile = box->itemData(box->currentIndex(), Qt::UserRole).toString();
|
if (!action)
|
||||||
QString helpFile = box->itemData(box->currentIndex(), Qt::UserRole + 1).toString();
|
return;
|
||||||
|
|
||||||
|
QString helpFile = action->property(HelpPathPropertyName).toString();
|
||||||
|
QString proFile = action->property(ExamplePathPropertyName).toString();
|
||||||
QStringList files;
|
QStringList files;
|
||||||
|
|
||||||
QFileInfo proFileInfo(proFile);
|
QFileInfo proFileInfo(proFile);
|
||||||
// If the Qt is a distro Qt on Linux, it will not be writable, hence compilation will fail
|
// If the Qt is a distro Qt on Linux, it will not be writable, hence compilation will fail
|
||||||
if (!proFileInfo.isWritable())
|
if (!proFileInfo.isWritable())
|
||||||
@@ -266,7 +266,7 @@ void GettingStartedWelcomePageWidget::slotOpenExample()
|
|||||||
void GettingStartedWelcomePageWidget::slotOpenHelpPage(const QString& url)
|
void GettingStartedWelcomePageWidget::slotOpenHelpPage(const QString& url)
|
||||||
{
|
{
|
||||||
Help::HelpManager *helpManager
|
Help::HelpManager *helpManager
|
||||||
= ExtensionSystem::PluginManager::instance()->getObject<Help::HelpManager>();
|
= ExtensionSystem::PluginManager::instance()->getObject<Help::HelpManager>();
|
||||||
Q_ASSERT(helpManager);
|
Q_ASSERT(helpManager);
|
||||||
helpManager->handleHelpRequest(url);
|
helpManager->handleHelpRequest(url);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ public slots:
|
|||||||
private slots:
|
private slots:
|
||||||
void slotOpenHelpPage(const QString &url);
|
void slotOpenHelpPage(const QString &url);
|
||||||
void slotOpenContextHelpPage(const QString &url);
|
void slotOpenContextHelpPage(const QString &url);
|
||||||
void slotEnableExampleButton(int);
|
|
||||||
void slotOpenExample();
|
void slotOpenExample();
|
||||||
void slotNextTip();
|
void slotNextTip();
|
||||||
void slotPrevTip();
|
void slotPrevTip();
|
||||||
|
|||||||
@@ -86,6 +86,15 @@
|
|||||||
<attribute name="headerMinimumSectionSize">
|
<attribute name="headerMinimumSectionSize">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<attribute name="headerDefaultSectionSize">
|
||||||
|
<number>24</number>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="headerVisible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="headerMinimumSectionSize">
|
||||||
|
<number>0</number>
|
||||||
|
</attribute>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string notr="true">1</string>
|
<string notr="true">1</string>
|
||||||
@@ -125,7 +134,7 @@
|
|||||||
<property name="horizontalSpacing">
|
<property name="horizontalSpacing">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="0" colspan="4">
|
<item row="0" column="0" colspan="3">
|
||||||
<widget class="Utils::WelcomeModeLabel" name="demoTitleLabel">
|
<widget class="Utils::WelcomeModeLabel" name="demoTitleLabel">
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
@@ -133,55 +142,21 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QComboBox" name="examplesComboBox">
|
<widget class="QPushButton" name="examplesButton">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||||
<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">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Open</string>
|
<string>Examples not installed...</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user