1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 5 ** 6 ** This file is part of the demonstration applications of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see http://www.qt.io/terms-conditions. For further 15 ** information use the contact form at http://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** As a special exception, The Qt Company gives you certain additional 27 ** rights. These rights are described in The Qt Company LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** GNU General Public License Usage 31 ** Alternatively, this file may be used under the terms of the GNU 32 ** General Public License version 3.0 as published by the Free Software 33 ** Foundation and appearing in the file LICENSE.GPL included in the 34 ** packaging of this file. Please review the following information to 35 ** ensure the GNU General Public License version 3.0 requirements will be 36 ** met: http://www.gnu.org/copyleft/gpl.html. 37 ** 38 ** $QT_END_LICENSE$ 39 ** 40 ****************************************************************************/ 41 42 #ifndef MENU_MANAGER_H 43 #define MENU_MANAGER_H 44 45 #include <QtGui> 46 #include <QtXml> 47 #include <QtHelp/QHelpEngineCore> 48 #ifndef QT_NO_DECLARATIVE 49 #include <QtDeclarative> 50 #endif 51 52 #include "score.h" 53 #include "textbutton.h" 54 #include "mainwindow.h" 55 #include "itemcircleanimation.h" 56 57 typedef QHash<QString, QString> StringHash; 58 typedef QHash<QString, StringHash> HashHash; 59 60 class TextButton; 61 62 class MenuManager : public QObject 63 { 64 Q_OBJECT 65 66 public: 67 enum BUTTON_TYPE {ROOT, MENU1, MENU2, LAUNCH, DOCUMENTATION, QUIT, FULLSCREEN, UP, DOWN, BACK, LAUNCH_QML}; 68 69 // singleton pattern: 70 static MenuManager *instance(); 71 virtual ~MenuManager(); 72 73 void init(MainWindow *window); 74 void itemSelected(int userCode, const QString &menuName = ""); 75 76 QByteArray getHtml(const QString &name); 77 QByteArray getImage(const QString &name); 78 QString resolveExeFile(const QString &name); 79 QString resolveDocUrl(const QString &name); 80 QString resolveImageUrl(const QString &name); 81 QString resolveDataDir(const QString &name); 82 83 HashHash info; 84 ItemCircleAnimation *ticker; 85 MainWindow *window; 86 Score *score; 87 int currentMenuCode; 88 89 QObject *qmlRoot; 90 #ifndef QT_NO_DECLARATIVE 91 QDeclarativeEngine* declarativeEngine; 92 #endif 93 94 private slots: 95 void exampleFinished(); 96 void exampleError(QProcess::ProcessError error); 97 98 void quitQML(); 99 100 private: 101 // singleton pattern: 102 MenuManager(); 103 static MenuManager *pInstance; 104 105 QByteArray getResource(const QString &name); 106 107 void readXmlDocument(); 108 void initHelpEngine(); 109 void getDocumentationDir(); 110 void readInfoAboutExample(const QDomElement &example); 111 void showDocInAssistant(const QString &docFile); 112 void launchExample(const QString &uniqueName); 113 void launchQmlExample(const QString &uniqueName); 114 115 void createMenu(const QDomElement &category, BUTTON_TYPE type); 116 void createLowLeftButton(const QString &label, BUTTON_TYPE type, 117 Movie *movieIn, Movie *movieOut, Movie *movieShake, const QString &menuString = QString()); 118 void createLowRightButton(const QString &label, BUTTON_TYPE type, Movie *movieIn, Movie *movieOut, Movie *movieShake); 119 void createLowRightLeafButton(const QString &label, int pos, BUTTON_TYPE type, Movie *movieIn, Movie *movieOut, Movie * /*movieShake*/); 120 void createRootMenu(const QDomElement &el); 121 void createSubMenu(const QDomElement &el); 122 void createLeafMenu(const QDomElement &el); 123 void createInfo(DemoItem *item, const QString &name); 124 void createTicker(); 125 void createUpnDownButtons(); 126 void createBackButton(); 127 128 QDomDocument *contentsDoc; 129 QProcess assistantProcess; 130 QString currentMenu; 131 QString currentCategory; 132 QString currentMenuButtons; 133 QString currentInfo; 134 QString helpRootUrl; 135 DemoItemAnimation *tickerInAnim; 136 QDir docDir; 137 QDir imgDir; 138 QHelpEngineCore *helpEngine; 139 140 TextButton *upButton; 141 TextButton *downButton; 142 143 }; 144 145 #endif // MENU_MANAGER_H 146 147