diff --git a/share/qtcreator/examplebrowser/qmlexamples.xml b/share/qtcreator/examplebrowser/qmlexamples.xml new file mode 100644 index 0000000000000000000000000000000000000000..c12744fe52ebbbadd9f549b200aa57767155c0a1 --- /dev/null +++ b/share/qtcreator/examplebrowser/qmlexamples.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="iso-8859-1"?> +<categories name="Qt Examples and Demos"> + <category dirname="declarative/toys" name="Toys"> + <example filename="dynamicscene" name="Dynamic Scene" executable="false" qml="true" /> + <example filename="tic-tac-toe" name="Tic Tac Toe" executable="false" qml="true" /> + <example filename="clocks" name="Clocks" executable="false" qml="true" /> + <example filename="corkboards" name="Corkboards" executable="false" qml="true" /> + <example filename="tvtennis" name="TV Tennis" executable="false" qml="true" /> + </category> + <category dirname="declarative/ui-components" name="QML UI Components"> + <example filename="dialcontrol" name="Dial" executable="false" qml="true" /> + <example filename="flipable" name="Flipable" executable="false" qml="true" /> + <example filename="progressbar" name="Progress Bar" executable="false" qml="true" /> + <example filename="scrollbar" name="Scroll Bar" executable="false" qml="true" /> + <example filename="searchbox" name="Search Box" executable="false" qml="true" /> + <example filename="slideswitch" name="Slide Switch" executable="false" qml="true" /> + <example filename="spinner" name="Spinner" executable="false" qml="true" /> + <example filename="tabwidget" name="Tab Widget" executable="false" qml="true" /> + </category> + <category dirname="declarative/text" name="Text"> + <example filename="fonts" name="Fonts" executable="false" qml="true" /> + <example filename="textselection" name="Text selection" executable="false" qml="true" /> + </category> + <category dirname="declarative/modelviews" name="Models and Views"> + <example filename="package" name="Package" executable="false" qml="true" /> + <example filename="gridview" name="GridView" executable="false" qml="true" /> + <example filename="visualitemmodel" name="VisualItemModel" executable="false" qml="true" /> + <example filename="webview" name="WebView" executable="false" qml="true" /> + <example filename="pathview" name="PathView" executable="false" qml="true" /> + <example filename="parallax" name="Parallax Sliding" executable="false" qml="true" /> + <example filename="listview" name="ListView" executable="false" qml="true" /> + <example filename="objectlistmodel" name="Object List Model" executable="false" qml="true" /> + </category> + <category dirname="declarative/threading" name="Threading"> + <example filename="threadedlistmodel" name="Threaded ListModel" executable="false" qml="true" /> + <example filename="workerscript" name="WorkerScript" executable="false" qml="true" /> + </category> + <category dirname="declarative/animation" name="Animation"> + <example filename="basics" name="Basics" executable="false" qml="true" /> + <example filename="behaviors" name="Behaviors" executable="false" qml="true" /> + <example filename="easing" name="Easing Curves" executable="false" qml="true" /> + <example filename="states" name="States" executable="false" qml="true" /> + </category> + <category dirname="declarative/imageelements" name="Image elements"> + <example filename="image" name="Image" executable="false" qml="true" /> + <example filename="borderimage" name="Border Image" executable="false" qml="true" /> + </category> + <category dirname="declarative/touchinteraction" name="Touch interaction"> + <example filename="gestures" name="Gestures" executable="false" qml="true" /> + <example filename="mousearea" name="MouseArea" executable="false" qml="true" /> + </category> + <category dirname="declarative" name="Miscellaneous"> + <example filename="positioners" name="Positioners" executable="false" qml="true" /> + <example filename="screenorientation" name="Screen Orientation" executable="false" qml="true" /> + <example filename="xml/xmlhttprequest" name="XmlHttpRequest" executable="false" qml="true" /> + <example filename="sqllocalstorage" name="SQL Local Storage" executable="false" qml="true" /> + <example filename="keyinteraction/focus" name="Focus" executable="false" qml="true" /> + </category> +</categories> diff --git a/share/qtcreator/static.pro b/share/qtcreator/static.pro index ddc10bab7043e34c592a7753428a7659bc0f3d1b..94d49be3acef393abab1b2cc421aa8850178433a 100644 --- a/share/qtcreator/static.pro +++ b/share/qtcreator/static.pro @@ -24,6 +24,7 @@ isEmpty(vcproj) { } DATA_DIRS = \ + examplebrowser \ snippets \ templates \ designer \ diff --git a/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.cpp b/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.cpp index eb63ae331505c1d8e61f1a2ce0abe776bcb3137b..bd1f95719c417f93e5eba51df473e02da472b8de 100644 --- a/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.cpp +++ b/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.cpp @@ -140,87 +140,97 @@ GettingStartedWelcomePageWidget::~GettingStartedWelcomePageWidget() delete ui; } - -void GettingStartedWelcomePageWidget::updateExamples(const QString &examplePath, - const QString &demosPath, - const QString &sourcePath) +void GettingStartedWelcomePageWidget::parseXmlFile(QFile *file, QMenuHash &cppSubMenuHash, QMenuHash &qmlSubMenuHash, + const QString &examplePath, const QString &sourcePath) { - QString demoXml = demosPath + "/qtdemo/xml/examples.xml"; - if (!QFile::exists(demoXml)) { - demoXml = sourcePath + "/demos/qtdemo/xml/examples.xml"; - if (!QFile::exists(demoXml)) - return; - } - - QFile description(demoXml); - if (!description.open(QFile::ReadOnly)) - return; - - const QString dropDownLabel = tr("Choose an Example..."); - - ui->qmlExamplesButton->setEnabled(true); - ui->qmlExamplesButton->setText(dropDownLabel); - - QMenu *qmlMenu = new QMenu(ui->qmlExamplesButton); - ui->qmlExamplesButton->setMenu(qmlMenu); - - ui->cppExamplesButton->setEnabled(true); - ui->cppExamplesButton->setText(dropDownLabel); - - QMenu *cppMenu = new QMenu(ui->cppExamplesButton); - ui->cppExamplesButton->setMenu(cppMenu); - - QScopedPointer<QMenu> subMenu; + QMenu *cppSubMenu = 0; + QMenu *qmlSubMenu = 0; bool inExamples = false; QString dirName; - QXmlStreamReader reader(&description); + + QXmlStreamReader reader(file); while (!reader.atEnd()) { switch (reader.readNext()) { case QXmlStreamReader::StartElement: if (reader.name() == QLatin1String("category")) { QString name = reader.attributes().value(QLatin1String("name")).toString(); - if (name.contains(QLatin1String("tutorial"))) + if (name.contains(QLatin1String("Tutorial"))) break; dirName = reader.attributes().value(QLatin1String("dirname")).toString(); - subMenu.reset(new QMenu(name)); + if (!cppSubMenuHash.contains(dirName)) { + cppSubMenu = new QMenu(name, this); + cppSubMenu->setObjectName(dirName); + cppSubMenuHash.insert(dirName, cppSubMenu); + } else { + cppSubMenu = cppSubMenuHash.value(dirName); + } + if (!qmlSubMenuHash.contains(dirName)) { + qmlSubMenu = new QMenu(name, this); + qmlSubMenu->setObjectName(dirName); + qmlSubMenuHash.insert(dirName, qmlSubMenu); + } else { + qmlSubMenu = qmlSubMenuHash.value(dirName); + } inExamples = true; } if (inExamples && reader.name() == QLatin1String("example")) { const QChar slash = QLatin1Char('/'); const QString name = reader.attributes().value(QLatin1String("name")).toString(); const bool isQml = reader.attributes().value(QLatin1String("qml")).toString() == "true"; - const QString fn = reader.attributes().value(QLatin1String("filename")).toString(); + const QString localDir = reader.attributes().value(QLatin1String("filename")).toString(); const QString extension = isQml ? QLatin1String(".qmlproject") : QLatin1String(".pro"); - const QString relativeProPath = slash + dirName + slash + fn + slash + fn + extension; + const QString fileName = localDir.section(',', -1); + const QString relativeProPath = slash + dirName + slash + localDir + slash + fileName + extension; - QString fileName = examplePath + relativeProPath; - if (!QFile::exists(fileName)) - fileName = sourcePath + QLatin1String("/examples") + relativeProPath; + QString finaleFileName = examplePath + relativeProPath; + if (!QFile::exists(finaleFileName)) + finaleFileName = sourcePath + QLatin1String("/examples") + relativeProPath; + + if (!QFile::exists(finaleFileName)) + break; QString dirName1 = dirName; dirName1.replace(slash, QLatin1Char('-')); QString helpPath = QLatin1String("qthelp://com.trolltech.qt/qdoc/") + dirName1 + - QLatin1Char('-') + fn + QLatin1String(".html"); - - QAction *exampleAction; - if (isQml) - exampleAction = qmlMenu->addAction(name); - else - exampleAction = subMenu->addAction(name); - - connect(exampleAction, SIGNAL(triggered()), SLOT(slotOpenExample())); - - exampleAction->setProperty(ExamplePathPropertyName, fileName); - exampleAction->setProperty(HelpPathPropertyName, helpPath); - + QLatin1Char('-') + fileName + QLatin1String(".html"); + + QAction *exampleAction = 0; + QAction *beforeAction = 0; + bool duplicate = false; + QMenu *subMenu; + subMenu = isQml ? qmlSubMenu : cppSubMenu; + + foreach (beforeAction, subMenu->actions()) { + int res = beforeAction->text().compare(name, Qt::CaseInsensitive); + if (res==0) { + duplicate = true; + break; + } else if (res<0) + beforeAction = 0; + else if (res>0) { + break; + } + } + + if (!duplicate) { + exampleAction = new QAction(name, subMenu); + subMenu->insertAction(beforeAction, exampleAction); + connect(exampleAction, SIGNAL(triggered()), SLOT(slotOpenExample())); + exampleAction->setProperty(ExamplePathPropertyName, finaleFileName); + exampleAction->setProperty(HelpPathPropertyName, helpPath); + } } break; case QXmlStreamReader::EndElement: - if (reader.name() == QLatin1String("category")) { - if (!subMenu->actions().isEmpty()) - cppMenu->addMenu(subMenu.take()); + if (inExamples && reader.name() == QLatin1String("category")) { + if (cppSubMenu->actions().isEmpty()) + delete cppSubMenuHash.take(dirName); + + if (qmlSubMenu->actions().isEmpty()) + delete qmlSubMenuHash.take(dirName); + inExamples = false; } break; @@ -230,6 +240,67 @@ void GettingStartedWelcomePageWidget::updateExamples(const QString &examplePath, } } +bool menuEntryCompare(QMenu* first, QMenu* second) +{ + return (QString::localeAwareCompare(first->title(), second->title()) < 0); +} + +void GettingStartedWelcomePageWidget::updateExamples(const QString &examplePath, + const QString &demosPath, + const QString &sourcePath) +{ + + QString demoXml = demosPath + "/qtdemo/xml/examples.xml"; + if (!QFile::exists(demoXml)) { + demoXml = sourcePath + "/demos/qtdemo/xml/examples.xml"; + if (!QFile::exists(demoXml)) + return; + } + + QMenuHash cppSubMenuHash; + QMenuHash qmlSubMenuHash; + + const QString dropDownLabel = tr("Choose an Example..."); + QMenu *cppMenu = new QMenu(ui->cppExamplesButton); + ui->cppExamplesButton->setMenu(cppMenu); + QMenu *qmlMenu = new QMenu(ui->qmlExamplesButton); + + + // let Creator's files take precedence + QString localQmlExamplesXml = + Core::ICore::instance()->resourcePath()+QLatin1String("/examplebrowser/qmlexamples.xml"); + + QFile localDescriptions(localQmlExamplesXml); + if (localDescriptions.open(QFile::ReadOnly)) { + parseXmlFile(&localDescriptions, cppSubMenuHash, qmlSubMenuHash, examplePath, sourcePath); + } + + QFile descriptions(demoXml); + if (!descriptions.open(QFile::ReadOnly)) + return; + + ui->cppExamplesButton->setEnabled(true); + ui->cppExamplesButton->setText(dropDownLabel); + + parseXmlFile(&descriptions, cppSubMenuHash, qmlSubMenuHash, examplePath, sourcePath); + + QList<QMenu*> cppSubMenus = cppSubMenuHash.values(); + qSort(cppSubMenus.begin(), cppSubMenus.end(), menuEntryCompare); + QList<QMenu*> qmlSubMenus = qmlSubMenuHash.values(); + qSort(qmlSubMenus.begin(), qmlSubMenus.end(), menuEntryCompare); + + foreach (QMenu *menu, cppSubMenus) + cppMenu->addMenu(menu); + foreach (QMenu *menu, qmlSubMenus) + qmlMenu->addMenu(menu); + + if (!qmlMenu->isEmpty()) { + ui->qmlExamplesButton->setMenu(qmlMenu); + ui->qmlExamplesButton->setEnabled(true); + ui->qmlExamplesButton->setText(dropDownLabel); + } +} + namespace { void copyRecursive(const QDir& from, const QDir& to, const QString& dir) { diff --git a/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.h b/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.h index ea0fec1d49a9d93abfbff55a91084c11082dd7cb..461d24e88cb1e84a8123f8258201cc7c8c7cc1b7 100644 --- a/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.h +++ b/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.h @@ -37,6 +37,8 @@ QT_BEGIN_NAMESPACE class QUrl; class QLabel; +class QFile; +class QMenu; QT_END_NAMESPACE namespace Core { @@ -55,6 +57,8 @@ namespace Ui { class GettingStartedWelcomePageWidget; } +typedef QHash<QString, QMenu*> QMenuHash; + class PixmapDownloader : public QNetworkAccessManager { Q_OBJECT public: @@ -101,6 +105,8 @@ signals: void startRssFetching(const QUrl&); private: + void parseXmlFile(QFile *file, QMenuHash &cppSubMenuHash, QMenuHash &qmlSubMenuHash, + const QString &examplePath, const QString &sourcePath); QStringList tipsOfTheDay(); Ui::GettingStartedWelcomePageWidget *ui; int m_currentTip; diff --git a/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.ui b/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.ui index 0de51c8a7e8dceec64275f70d3ef2c745618c416..e0b8f48e7b5e7f7d9072d6880116d96efac79964 100644 --- a/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.ui +++ b/src/plugins/qt4projectmanager/gettingstartedwelcomepagewidget.ui @@ -40,15 +40,6 @@ <verstretch>0</verstretch> </sizepolicy> </property> - <property name="minimumSize"> - <size> - <width>250</width> - <height>0</height> - </size> - </property> - <property name="styleSheet"> - <string/> - </property> <layout class="QGridLayout" name="gridLayout_6"> <property name="verticalSpacing"> <number>12</number> @@ -76,12 +67,12 @@ </property> <property name="minimumSize"> <size> - <width>250</width> + <width>230</width> <height>0</height> </size> </property> <property name="styleSheet"> - <string/> + <string notr="true"/> </property> <layout class="QGridLayout" name="gridLayout_11"> <property name="verticalSpacing"> @@ -90,7 +81,57 @@ <property name="rightMargin"> <number>9</number> </property> + <item row="0" column="0"> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <spacer name="verticalSpacer_2"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="Utils::WelcomeModeLabel" name="didYouKnowTitleLabel"> + <property name="text"> + <string>Did You Know?</string> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> <item row="0" column="1"> + <spacer name="horizontalSpacer_5"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="0" column="2"> <layout class="QGridLayout" name="gridLayout_10"> <property name="spacing"> <number>0</number> @@ -170,10 +211,10 @@ </item> </layout> </item> - <item row="1" column="0" colspan="2"> + <item row="1" column="0" colspan="3"> <widget class="QTextBrowser" name="didYouKnowTextBrowser"> <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -195,69 +236,17 @@ </property> </widget> </item> - <item row="0" column="0"> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <spacer name="verticalSpacer_2"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="Utils::WelcomeModeLabel" name="didYouKnowTitleLabel"> - <property name="text"> - <string>Did You Know?</string> - </property> - </widget> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> </layout> </widget> </item> <item row="1" column="0" colspan="2"> <widget class="QFrame" name="demosExamplesFrame_2"> <property name="sizePolicy"> - <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> - <property name="minimumSize"> - <size> - <width>500</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>500</width> - <height>16777215</height> - </size> - </property> - <property name="styleSheet"> - <string/> - </property> <layout class="QGridLayout" name="gridLayout"> <item row="0" column="0"> <widget class="Utils::WelcomeModeLabel" name="demoTitleLabel_4"> @@ -324,39 +313,10 @@ </property> </widget> </item> - <item row="3" column="0"> - <widget class="QLabel" name="demoTitleLabel_3"> - <property name="text"> - <string>Explore Qt C++ mobile examples:</string> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QPushButton" name="mobileExamplesButton"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>30</height> - </size> - </property> - <property name="text"> - <string>Examples Not Installed...</string> - </property> - </widget> - </item> </layout> </widget> </item> - <item row="2" column="0" colspan="2"> + <item row="3" column="0" colspan="2"> <layout class="QHBoxLayout" name="horizontalLayout_2"> <property name="spacing"> <number>6</number> @@ -408,6 +368,22 @@ </item> </layout> </item> + <item row="2" column="0"> + <spacer name="verticalSpacer_8"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::MinimumExpanding</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> </layout> </widget> </item>