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 tools 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 QDECLARATIVEVIEWER_H 43 #define QDECLARATIVEVIEWER_H 44 45 #include <QMainWindow> 46 #include <QTimer> 47 #include <QTime> 48 #include <QList> 49 50 #include "loggerwidget.h" 51 52 QT_BEGIN_NAMESPACE 53 54 class QDeclarativeView; 55 class PreviewDeviceSkin; 56 class QDeclarativeTestEngine; 57 class QProcess; 58 class RecordingDialog; 59 class QDeclarativeTester; 60 class QNetworkReply; 61 class QNetworkCookieJar; 62 class NetworkAccessManagerFactory; 63 class QTranslator; 64 class QActionGroup; 65 class QMenuBar; 66 67 class QDeclarativeViewer 68 : public QMainWindow 69 { 70 Q_OBJECT 71 72 public: 73 QDeclarativeViewer(QWidget *parent = 0, Qt::WindowFlags flags = 0); 74 ~QDeclarativeViewer(); 75 76 static void registerTypes(); 77 78 enum ScriptOption { 79 Play = 0x00000001, 80 Record = 0x00000002, 81 TestImages = 0x00000004, 82 TestErrorProperty = 0x00000008, 83 SaveOnExit = 0x00000010, 84 ExitOnComplete = 0x00000020, 85 ExitOnFailure = 0x00000040, 86 Snapshot = 0x00000080, 87 TestSkipProperty = 0x00000100 88 }; Q_DECLARE_FLAGS(ScriptOptions,ScriptOption)89 Q_DECLARE_FLAGS(ScriptOptions, ScriptOption) 90 void setScript(const QString &s) { m_script = s; } setScriptOptions(ScriptOptions opt)91 void setScriptOptions(ScriptOptions opt) { m_scriptOptions = opt; } setRecordDither(const QString & s)92 void setRecordDither(const QString& s) { record_dither = s; } 93 void setRecordRate(int fps); 94 void setRecordFile(const QString&); 95 void setRecordArgs(const QStringList&); 96 void setRecording(bool on); isRecording()97 bool isRecording() const { return recordTimer.isActive(); } 98 void setAutoRecord(int from, int to); 99 void setDeviceKeys(bool); 100 void setNetworkCacheSize(int size); 101 void addLibraryPath(const QString& lib); 102 void addPluginPath(const QString& plugin); 103 void setUseGL(bool use); 104 void setUseNativeFileBrowser(bool); 105 void setSizeToView(bool sizeToView); 106 107 QDeclarativeView *view() const; 108 LoggerWidget *warningsWidget() const; currentFile()109 QString currentFile() const { return currentFileOrUrl; } 110 111 void enableExperimentalGestures(); 112 113 public slots: 114 void sceneResized(QSize size); 115 bool open(const QString&); 116 void openFile(); 117 void openUrl(); 118 void reload(); 119 void takeSnapShot(); 120 void toggleRecording(); 121 void toggleRecordingWithSelection(); 122 void ffmpegFinished(int code); 123 void showProxySettings (); 124 void proxySettingsChanged (); 125 void rotateOrientation(); 126 void statusChanged(); 127 void setSlowMode(bool); 128 void launch(const QString &); 129 130 protected: 131 virtual void keyPressEvent(QKeyEvent *); 132 virtual bool event(QEvent *); 133 void createMenu(); 134 135 private slots: 136 void appAboutToQuit(); 137 138 void autoStartRecording(); 139 void autoStopRecording(); 140 void recordFrame(); 141 void chooseRecordingOptions(); 142 void pickRecordingFile(); 143 void toggleFullScreen(); 144 void changeOrientation(QAction*); 145 void orientationChanged(); 146 147 void showWarnings(bool show); 148 void warningsWidgetOpened(); 149 void warningsWidgetClosed(); 150 151 private: 152 void updateSizeHints(bool initial = false); 153 154 QString getVideoFileName(); 155 156 LoggerWidget *loggerWindow; 157 QDeclarativeView *canvas; 158 QSize initialSize; 159 QString currentFileOrUrl; 160 QTimer recordTimer; 161 QString frame_fmt; 162 QImage frame; 163 QList<QImage*> frames; 164 QProcess* frame_stream; 165 QTimer autoStartTimer; 166 QTimer autoStopTimer; 167 QString record_dither; 168 QString record_file; 169 QSize record_outsize; 170 QStringList record_args; 171 int record_rate; 172 int record_autotime; 173 bool devicemode; 174 QAction *recordAction; 175 RecordingDialog *recdlg; 176 177 void senseFfmpeg(); 178 QWidget *ffmpegHelpWindow; 179 bool ffmpegAvailable; 180 const bool convertAvailable; 181 182 QAction *rotateAction; 183 QActionGroup *orientation; 184 QAction *showWarningsWindow; 185 186 QString m_script; 187 ScriptOptions m_scriptOptions; 188 QDeclarativeTester *tester; 189 190 NetworkAccessManagerFactory *namFactory; 191 192 bool useQmlFileBrowser; 193 194 QTranslator *translator; 195 void loadTranslationFile(const QString& directory); 196 197 void loadDummyDataFiles(const QString& directory); 198 }; 199 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeViewer::ScriptOptions) 200 201 QT_END_NAMESPACE 202 203 #endif 204