tools/qml/qmlruntime.cpp
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
child 37 758a864f9613
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
    42 #include <qdeclarativeview.h>
    42 #include <qdeclarativeview.h>
    43 
    43 
    44 #ifdef hz
    44 #ifdef hz
    45 #undef hz
    45 #undef hz
    46 #endif
    46 #endif
    47 #include "ui_recopts.h"
    47 #ifdef Q_WS_MAEMO_5
       
    48 #  include <QMaemo5ValueButton>
       
    49 #  include <QMaemo5ListPickSelector>
       
    50 #  include <QWidgetAction>
       
    51 #  include <QStringListModel>
       
    52 #  include "ui_recopts_maemo5.h"
       
    53 #else
       
    54 #  include "ui_recopts.h"
       
    55 #endif
    48 
    56 
    49 #include "qmlruntime.h"
    57 #include "qmlruntime.h"
    50 #include <qdeclarativecontext.h>
    58 #include <qdeclarativecontext.h>
    51 #include <qdeclarativeengine.h>
    59 #include <qdeclarativeengine.h>
    52 #include <qdeclarativenetworkaccessmanagerfactory.h>
    60 #include <qdeclarativenetworkaccessmanagerfactory.h>
    53 #include "qdeclarative.h"
    61 #include "qdeclarative.h"
       
    62 #include <QAbstractAnimation>
    54 #include <private/qabstractanimation_p.h>
    63 #include <private/qabstractanimation_p.h>
    55 #include <QAbstractAnimation>
       
    56 
    64 
    57 #include <QSettings>
    65 #include <QSettings>
    58 #include <QXmlStreamReader>
    66 #include <QXmlStreamReader>
    59 #include <QBuffer>
    67 #include <QBuffer>
    60 #include <QNetworkReply>
    68 #include <QNetworkReply>
    90 #include <QGLWidget>
    98 #include <QGLWidget>
    91 #endif
    99 #endif
    92 
   100 
    93 #include <qdeclarativetester.h>
   101 #include <qdeclarativetester.h>
    94 
   102 
    95 #if defined (Q_OS_SYMBIAN)
       
    96 #define SYMBIAN_NETWORK_INIT
       
    97 #endif
       
    98 
       
    99 #if defined (SYMBIAN_NETWORK_INIT)
       
   100 #include <sys/types.h>
       
   101 #include <sys/stat.h>
       
   102 #include <fcntl.h>
       
   103 #include <unistd.h>
       
   104 #include <QTextCodec>
       
   105 #include "sym_iap_util.h"
       
   106 #endif
       
   107 
       
   108 QT_BEGIN_NAMESPACE
   103 QT_BEGIN_NAMESPACE
   109 
   104 
   110 class Runtime : public QObject
   105 class Runtime : public QObject
   111 {
   106 {
   112     Q_OBJECT
   107     Q_OBJECT
   147 
   142 
   148     bool activeWindow;
   143     bool activeWindow;
   149 };
   144 };
   150 
   145 
   151 
   146 
   152 class SizedMenuBar : public QMenuBar
   147 
   153 {
   148 #if defined(Q_WS_MAEMO_5)
       
   149 
       
   150 class Maemo5PickerAction : public QWidgetAction {
   154     Q_OBJECT
   151     Q_OBJECT
   155 public:
   152 public:
   156     SizedMenuBar(QWidget *parent, QWidget *referenceWidget)
   153     Maemo5PickerAction(const QString &text, QActionGroup *actions, QObject *parent)
   157         : QMenuBar(parent), refWidget(referenceWidget)
   154         : QWidgetAction(parent), m_text(text), m_actions(actions)
   158     {
   155     { }
   159     }
   156 
   160 
   157     QWidget *createWidget(QWidget *parent)
   161     virtual QSize sizeHint() const
   158     {
   162     {
   159 	QMaemo5ValueButton *button = new QMaemo5ValueButton(m_text, parent);
   163         return QSize(refWidget->sizeHint().width(), QMenuBar::sizeHint().height());
   160 	button->setValueLayout(QMaemo5ValueButton::ValueUnderTextCentered);
       
   161         QMaemo5ListPickSelector *pick = new QMaemo5ListPickSelector(button);
       
   162 	button->setPickSelector(pick);
       
   163 	if (m_actions) {
       
   164 	    QStringList sl;
       
   165 	    int curIdx = -1, idx = 0;
       
   166 	    foreach (QAction *a, m_actions->actions()) {
       
   167 		sl << a->text();
       
   168 		if (a->isChecked())
       
   169 		    curIdx = idx;
       
   170 		idx++;
       
   171             }
       
   172 	    pick->setModel(new QStringListModel(sl));
       
   173 	    pick->setCurrentIndex(curIdx);
       
   174 	} else {
       
   175 	    button->setEnabled(false);
       
   176 	}
       
   177 	connect(pick, SIGNAL(selected(QString)), this, SLOT(emitTriggered()));
       
   178 	return button;
       
   179     }
       
   180 
       
   181 private slots:
       
   182     void emitTriggered()
       
   183     {
       
   184 	QMaemo5ListPickSelector *pick = qobject_cast<QMaemo5ListPickSelector *>(sender());
       
   185 	if (!pick)
       
   186 	    return;
       
   187 	int idx = pick->currentIndex();
       
   188 
       
   189 	if (m_actions && idx >= 0 && idx < m_actions->actions().count())
       
   190 	    m_actions->actions().at(idx)->trigger();
   164     }
   191     }
   165 
   192 
   166 private:
   193 private:
   167     QWidget *refWidget;
   194     QString m_text;
       
   195     QPointer<QActionGroup> m_actions;
   168 };
   196 };
       
   197 
       
   198 #endif // Q_WS_MAEMO_5
   169 
   199 
   170 static struct { const char *name, *args; } ffmpegprofiles[] = {
   200 static struct { const char *name, *args; } ffmpegprofiles[] = {
   171     {"Maximum Quality", "-sameq"},
   201     {"Maximum Quality", "-sameq"},
   172     {"High Quality", "-qmax 2"},
   202     {"High Quality", "-qmax 2"},
   173     {"Medium Quality", "-qmax 6"},
   203     {"Medium Quality", "-qmax 6"},
   181 
   211 
   182 public:
   212 public:
   183     RecordingDialog(QWidget *parent) : QDialog(parent)
   213     RecordingDialog(QWidget *parent) : QDialog(parent)
   184     {
   214     {
   185         setupUi(this);
   215         setupUi(this);
       
   216 #ifndef Q_WS_MAEMO_5
   186         hz->setValidator(new QDoubleValidator(hz));
   217         hz->setValidator(new QDoubleValidator(hz));
       
   218 #endif
   187         for (int i=0; ffmpegprofiles[i].name; ++i) {
   219         for (int i=0; ffmpegprofiles[i].name; ++i) {
   188             profile->addItem(ffmpegprofiles[i].name);
   220             profile->addItem(ffmpegprofiles[i].name);
   189         }
   221         }
   190     }
   222     }
   191 
   223 
   207     QString arguments() const
   239     QString arguments() const
   208     {
   240     {
   209         int i = profile->currentIndex();
   241         int i = profile->currentIndex();
   210         return ffmpegprofiles[i].args[0] ? QLatin1String(ffmpegprofiles[i].args) : customargs;
   242         return ffmpegprofiles[i].args[0] ? QLatin1String(ffmpegprofiles[i].args) : customargs;
   211     }
   243     }
       
   244 
       
   245     void setOriginalSize(const QSize &s)
       
   246     {
       
   247         QString str = tr("Original (%1x%2)").arg(s.width()).arg(s.height());
       
   248 
       
   249 #ifdef Q_WS_MAEMO_5
       
   250         sizeCombo->setItemText(0, str);
       
   251 #else
       
   252         sizeOriginal->setText(str);
       
   253         if (sizeWidth->value()<=1) {
       
   254             sizeWidth->setValue(s.width());
       
   255             sizeHeight->setValue(s.height());
       
   256         }
       
   257 #endif
       
   258     }
       
   259 
       
   260     void showffmpegOptions(bool b)
       
   261     {
       
   262 #ifdef Q_WS_MAEMO_5
       
   263         profileLabel->setVisible(b);
       
   264         profile->setVisible(b);
       
   265         ffmpegHelp->setVisible(b);
       
   266         args->setVisible(b);
       
   267 #else
       
   268         ffmpegOptions->setVisible(b);
       
   269 #endif
       
   270     }
       
   271 
       
   272     void showRateOptions(bool b)
       
   273     {
       
   274 #ifdef Q_WS_MAEMO_5
       
   275         rateLabel->setVisible(b);
       
   276         rateCombo->setVisible(b);
       
   277 #else
       
   278         rateOptions->setVisible(b);
       
   279 #endif
       
   280     }
       
   281 
       
   282     void setVideoRate(int rate)
       
   283     {
       
   284 #ifdef Q_WS_MAEMO_5
       
   285         int idx;
       
   286         if (rate >= 60)
       
   287             idx = 0;
       
   288         else if (rate >= 50)
       
   289             idx = 2;
       
   290         else if (rate >= 25)
       
   291             idx = 3;
       
   292         else if (rate >= 24)
       
   293             idx = 4;
       
   294         else if (rate >= 20)
       
   295             idx = 5;
       
   296         else if (rate >= 15)
       
   297             idx = 6;
       
   298         else
       
   299             idx = 7;
       
   300         rateCombo->setCurrentIndex(idx);
       
   301 #else
       
   302         if (rate == 24)
       
   303             hz24->setChecked(true);
       
   304         else if (rate == 25)
       
   305             hz25->setChecked(true);
       
   306         else if (rate == 50)
       
   307             hz50->setChecked(true);
       
   308         else if (rate == 60)
       
   309             hz60->setChecked(true);
       
   310         else {
       
   311             hzCustom->setChecked(true);
       
   312             hz->setText(QString::number(rate));
       
   313         }
       
   314 #endif
       
   315     }
       
   316 
       
   317     int videoRate() const
       
   318     {
       
   319 #ifdef Q_WS_MAEMO_5
       
   320         switch (rateCombo->currentIndex()) {
       
   321             case 0: return 60;
       
   322             case 1: return 50;
       
   323             case 2: return 25;
       
   324             case 3: return 24;
       
   325             case 4: return 20;
       
   326             case 5: return 15;
       
   327             case 7: return 10;
       
   328             default: return 60;
       
   329         }
       
   330 #else
       
   331         if (hz24->isChecked())
       
   332             return 24;
       
   333         else if (hz25->isChecked())
       
   334             return 25;
       
   335         else if (hz50->isChecked())
       
   336             return 50;
       
   337         else if (hz60->isChecked())
       
   338             return 60;
       
   339         else {
       
   340             return hz->text().toInt();
       
   341         }
       
   342 #endif
       
   343     }
       
   344 
       
   345     QSize videoSize() const
       
   346     {
       
   347 #ifdef Q_WS_MAEMO_5
       
   348         switch (sizeCombo->currentIndex()) {
       
   349             case 0: return QSize();
       
   350             case 1: return QSize(640,480);
       
   351             case 2: return QSize(320,240);
       
   352             case 3: return QSize(1280,720);
       
   353             default: return QSize();
       
   354         }
       
   355 #else
       
   356         if (sizeOriginal->isChecked())
       
   357             return QSize();
       
   358         else if (size720p->isChecked())
       
   359             return QSize(1280,720);
       
   360         else if (sizeVGA->isChecked())
       
   361             return QSize(640,480);
       
   362         else if (sizeQVGA->isChecked())
       
   363             return QSize(320,240);
       
   364         else
       
   365             return QSize(sizeWidth->value(), sizeHeight->value());
       
   366 #endif
       
   367     }
       
   368 
       
   369 
   212 
   370 
   213 private slots:
   371 private slots:
   214     void pickProfile(int i)
   372     void pickProfile(int i)
   215     {
   373     {
   216         if (ffmpegprofiles[i].args[0]) {
   374         if (ffmpegprofiles[i].args[0]) {
   271     }
   429     }
   272 
   430 
   273     mutable QMutex mutex;
   431     mutable QMutex mutex;
   274 };
   432 };
   275 
   433 
   276 class NetworkAccessManagerFactory : public QDeclarativeNetworkAccessManagerFactory
   434 class SystemProxyFactory : public QNetworkProxyFactory
   277 {
   435 {
       
   436 public:
       
   437     SystemProxyFactory() : proxyDirty(true), httpProxyInUse(false) {
       
   438     }
       
   439 
       
   440     virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query)
       
   441     {
       
   442         if (proxyDirty)
       
   443             setupProxy();
       
   444         QString protocolTag = query.protocolTag();
       
   445         if (httpProxyInUse && (protocolTag == "http" || protocolTag == "https")) {
       
   446             QList<QNetworkProxy> ret;
       
   447             ret << httpProxy;
       
   448             return ret;
       
   449         }
       
   450 #ifdef Q_OS_WIN
       
   451         // systemProxyForQuery can take insanely long on Windows (QTBUG-10106)
       
   452         return QNetworkProxyFactory::proxyForQuery(query);
       
   453 #else
       
   454         return QNetworkProxyFactory::systemProxyForQuery(query);
       
   455 #endif
       
   456     }
       
   457 
       
   458     void setupProxy() {
       
   459         // Don't bother locking because we know that the proxy only
       
   460         // changes in response to the settings dialog and that
       
   461         // the view will be reloaded.
       
   462         proxyDirty = false;
       
   463         httpProxyInUse = ProxySettings::httpProxyInUse();
       
   464         if (httpProxyInUse)
       
   465             httpProxy = ProxySettings::httpProxy();
       
   466     }
       
   467 
       
   468     void proxyChanged() {
       
   469         proxyDirty = true;
       
   470     }
       
   471 
       
   472 private:
       
   473     volatile bool proxyDirty;
       
   474     bool httpProxyInUse;
       
   475     QNetworkProxy httpProxy;
       
   476 };
       
   477 
       
   478 class NetworkAccessManagerFactory : public QObject, public QDeclarativeNetworkAccessManagerFactory
       
   479 {
       
   480     Q_OBJECT
   278 public:
   481 public:
   279     NetworkAccessManagerFactory() : cacheSize(0) {}
   482     NetworkAccessManagerFactory() : cacheSize(0) {}
   280     ~NetworkAccessManagerFactory() {}
   483     ~NetworkAccessManagerFactory() {}
   281 
   484 
   282     QNetworkAccessManager *create(QObject *parent);
   485     QNetworkAccessManager *create(QObject *parent);
   283 
   486 
   284     void setupProxy(QNetworkAccessManager *nam)
       
   285     {
       
   286         class SystemProxyFactory : public QNetworkProxyFactory
       
   287         {
       
   288         public:
       
   289             virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query)
       
   290             {
       
   291                 QString protocolTag = query.protocolTag();
       
   292                 if (httpProxyInUse && (protocolTag == "http" || protocolTag == "https")) {
       
   293                     QList<QNetworkProxy> ret;
       
   294                     ret << httpProxy;
       
   295                     return ret;
       
   296                 }
       
   297                 return QNetworkProxyFactory::systemProxyForQuery(query);
       
   298             }
       
   299             void setHttpProxy (QNetworkProxy proxy)
       
   300             {
       
   301                 httpProxy = proxy;
       
   302                 httpProxyInUse = true;
       
   303             }
       
   304             void unsetHttpProxy ()
       
   305             {
       
   306                 httpProxyInUse = false;
       
   307             }
       
   308         private:
       
   309             bool httpProxyInUse;
       
   310             QNetworkProxy httpProxy;
       
   311         };
       
   312 
       
   313         SystemProxyFactory *proxyFactory = new SystemProxyFactory;
       
   314         if (ProxySettings::httpProxyInUse())
       
   315             proxyFactory->setHttpProxy(ProxySettings::httpProxy());
       
   316         else
       
   317             proxyFactory->unsetHttpProxy();
       
   318         nam->setProxyFactory(proxyFactory);
       
   319     }
       
   320 
       
   321     void setCacheSize(int size) {
   487     void setCacheSize(int size) {
   322         if (size != cacheSize) {
   488         if (size != cacheSize) {
   323             cacheSize = size;
   489             cacheSize = size;
   324         }
   490         }
   325     }
   491     }
   326 
   492 
       
   493     void proxyChanged() {
       
   494         foreach (QNetworkAccessManager *nam, namList) {
       
   495             static_cast<SystemProxyFactory*>(nam->proxyFactory())->proxyChanged();
       
   496         }
       
   497     }
       
   498 
   327     static PersistentCookieJar *cookieJar;
   499     static PersistentCookieJar *cookieJar;
       
   500 
       
   501 private slots:
       
   502     void managerDestroyed(QObject *obj) {
       
   503         namList.removeOne(static_cast<QNetworkAccessManager*>(obj));
       
   504     }
       
   505 
       
   506 private:
   328     QMutex mutex;
   507     QMutex mutex;
   329     int cacheSize;
   508     int cacheSize;
       
   509     QList<QNetworkAccessManager*> namList;
   330 };
   510 };
   331 
   511 
   332 PersistentCookieJar *NetworkAccessManagerFactory::cookieJar = 0;
   512 PersistentCookieJar *NetworkAccessManagerFactory::cookieJar = 0;
   333 
   513 
   334 static void cleanup_cookieJar()
   514 static void cleanup_cookieJar()
   345         qAddPostRoutine(cleanup_cookieJar);
   525         qAddPostRoutine(cleanup_cookieJar);
   346         cookieJar = new PersistentCookieJar(0);
   526         cookieJar = new PersistentCookieJar(0);
   347     }
   527     }
   348     manager->setCookieJar(cookieJar);
   528     manager->setCookieJar(cookieJar);
   349     cookieJar->setParent(0);
   529     cookieJar->setParent(0);
   350     setupProxy(manager);
   530     manager->setProxyFactory(new SystemProxyFactory);
   351     if (cacheSize > 0) {
   531     if (cacheSize > 0) {
   352         QNetworkDiskCache *cache = new QNetworkDiskCache;
   532         QNetworkDiskCache *cache = new QNetworkDiskCache;
   353         cache->setCacheDirectory(QDir::tempPath()+QLatin1String("/qml-viewer-network-cache"));
   533         cache->setCacheDirectory(QDir::tempPath()+QLatin1String("/qml-viewer-network-cache"));
   354         cache->setMaximumCacheSize(cacheSize);
   534         cache->setMaximumCacheSize(cacheSize);
   355         manager->setCache(cache);
   535         manager->setCache(cache);
   356     } else {
   536     } else {
   357         manager->setCache(0);
   537         manager->setCache(0);
   358     }
   538     }
       
   539     connect(manager, SIGNAL(destroyed(QObject*)), this, SLOT(managerDestroyed(QObject*)));
       
   540     namList.append(manager);
   359     qDebug() << "created new network access manager for" << parent;
   541     qDebug() << "created new network access manager for" << parent;
   360     return manager;
   542     return manager;
   361 }
   543 }
   362 
   544 
   363 QString QDeclarativeViewer::getVideoFileName()
   545 QString QDeclarativeViewer::getVideoFileName()
   369     types += tr("Individual PNG frames")+QLatin1String(" (*.png)");
   551     types += tr("Individual PNG frames")+QLatin1String(" (*.png)");
   370     if (ffmpegAvailable) types += tr("All ffmpeg formats (*.*)");
   552     if (ffmpegAvailable) types += tr("All ffmpeg formats (*.*)");
   371     return QFileDialog::getSaveFileName(this, title, "", types.join(";; "));
   553     return QFileDialog::getSaveFileName(this, title, "", types.join(";; "));
   372 }
   554 }
   373 
   555 
   374 
       
   375 QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags)
   556 QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags)
   376 #if defined(Q_OS_SYMBIAN)
       
   377     : QMainWindow(parent, flags)
   557     : QMainWindow(parent, flags)
   378 #else
   558       , loggerWindow(new LoggerWidget(this))
   379     : QWidget(parent, flags)
   559       , frame_stream(0)
   380 #endif
   560       , orientation(0)
   381       , loggerWindow(new LoggerWidget())
       
   382       , frame_stream(0), mb(0)
       
   383       , portraitOrientation(0), landscapeOrientation(0)
       
   384       , showWarningsWindow(0)
   561       , showWarningsWindow(0)
   385       , m_scriptOptions(0)
   562       , m_scriptOptions(0)
   386       , tester(0)
   563       , tester(0)
   387       , useQmlFileBrowser(true)
   564       , useQmlFileBrowser(true)
   388       , translator(0)
   565       , translator(0)
   389 {
   566 {
   390     QDeclarativeViewer::registerTypes();
   567     QDeclarativeViewer::registerTypes();
   391     setWindowTitle(tr("Qt QML Viewer"));
   568     setWindowTitle(tr("Qt QML Viewer"));
       
   569 #ifdef Q_WS_MAEMO_5
       
   570     setAttribute(Qt::WA_Maemo5StackedWindow);
       
   571 //    setPalette(QApplication::palette("QLabel"));
       
   572 #endif
   392 
   573 
   393     devicemode = false;
   574     devicemode = false;
   394     canvas = 0;
   575     canvas = 0;
   395     record_autotime = 0;
   576     record_autotime = 0;
   396     record_rate = 50;
   577     record_rate = 50;
   399     recdlg = new RecordingDialog(this);
   580     recdlg = new RecordingDialog(this);
   400     connect(recdlg->pickfile, SIGNAL(clicked()), this, SLOT(pickRecordingFile()));
   581     connect(recdlg->pickfile, SIGNAL(clicked()), this, SLOT(pickRecordingFile()));
   401     senseFfmpeg();
   582     senseFfmpeg();
   402     senseImageMagick();
   583     senseImageMagick();
   403     if (!ffmpegAvailable)
   584     if (!ffmpegAvailable)
   404         recdlg->ffmpegOptions->hide();
   585         recdlg->showffmpegOptions(false);
   405     if (!ffmpegAvailable && !convertAvailable)
   586     if (!ffmpegAvailable && !convertAvailable)
   406         recdlg->rateOptions->hide();
   587         recdlg->showRateOptions(false);
   407     QString warn;
   588     QString warn;
   408     if (!ffmpegAvailable) {
   589     if (!ffmpegAvailable) {
   409         if (!convertAvailable)
   590         if (!convertAvailable)
   410             warn = tr("ffmpeg and ImageMagick not available - no video output");
   591             warn = tr("ffmpeg and ImageMagick not available - no video output");
   411         else
   592         else
   428 
   609 
   429     QObject::connect(warningsWidget(), SIGNAL(opened()), this, SLOT(warningsWidgetOpened()));
   610     QObject::connect(warningsWidget(), SIGNAL(opened()), this, SLOT(warningsWidgetOpened()));
   430     QObject::connect(warningsWidget(), SIGNAL(closed()), this, SLOT(warningsWidgetClosed()));
   611     QObject::connect(warningsWidget(), SIGNAL(closed()), this, SLOT(warningsWidgetClosed()));
   431 
   612 
   432     if (!(flags & Qt::FramelessWindowHint)) {
   613     if (!(flags & Qt::FramelessWindowHint)) {
   433         createMenu(menuBar(),0);
   614         createMenu();
   434         setPortrait();
   615         changeOrientation(orientation->actions().value(0));
   435     }
   616     } else {
   436 
   617         setMenuBar(0);
   437 #if !defined(Q_OS_SYMBIAN)
   618     }
   438     QVBoxLayout *layout = new QVBoxLayout;
   619 
   439     layout->setMargin(0);
       
   440     layout->setSpacing(0);
       
   441     setLayout(layout);
       
   442     if (mb)
       
   443         layout->addWidget(mb);
       
   444     layout->addWidget(canvas);
       
   445 #else
       
   446     setCentralWidget(canvas);
   620     setCentralWidget(canvas);
   447 #endif
   621 
   448     namFactory = new NetworkAccessManagerFactory;
   622     namFactory = new NetworkAccessManagerFactory;
   449     canvas->engine()->setNetworkAccessManagerFactory(namFactory);
   623     canvas->engine()->setNetworkAccessManagerFactory(namFactory);
   450 
   624 
   451     connect(&autoStartTimer, SIGNAL(triggered()), this, SLOT(autoStartRecording()));
   625     connect(&autoStartTimer, SIGNAL(timeout()), this, SLOT(autoStartRecording()));
   452     connect(&autoStopTimer, SIGNAL(triggered()), this, SLOT(autoStopRecording()));
   626     connect(&autoStopTimer, SIGNAL(timeout()), this, SLOT(autoStopRecording()));
   453     connect(&recordTimer, SIGNAL(triggered()), this, SLOT(recordFrame()));
   627     connect(&recordTimer, SIGNAL(timeout()), this, SLOT(recordFrame()));
   454     connect(DeviceOrientation::instance(), SIGNAL(orientationChanged()),
   628     connect(DeviceOrientation::instance(), SIGNAL(orientationChanged()),
   455             this, SLOT(orientationChanged()), Qt::QueuedConnection);
   629             this, SLOT(orientationChanged()), Qt::QueuedConnection);
   456     autoStartTimer.setRunning(false);
   630     autoStartTimer.setSingleShot(true);
   457     autoStopTimer.setRunning(false);
   631     autoStopTimer.setSingleShot(true);
   458     recordTimer.setRunning(false);
   632     recordTimer.setSingleShot(false);
   459     recordTimer.setRepeating(true);
   633 
       
   634     QObject::connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(appAboutToQuit()));
   460 }
   635 }
   461 
   636 
   462 QDeclarativeViewer::~QDeclarativeViewer()
   637 QDeclarativeViewer::~QDeclarativeViewer()
   463 {
   638 {
   464     delete loggerWindow;
   639     delete loggerWindow;
   474     canvas->viewport()->grabGesture(Qt::PinchGesture,Qt::DontStartGestureOnChildren|Qt::ReceivePartialGestures|Qt::IgnoredGesturesPropagateToParent);
   649     canvas->viewport()->grabGesture(Qt::PinchGesture,Qt::DontStartGestureOnChildren|Qt::ReceivePartialGestures|Qt::IgnoredGesturesPropagateToParent);
   475     canvas->viewport()->grabGesture(Qt::SwipeGesture,Qt::DontStartGestureOnChildren|Qt::ReceivePartialGestures|Qt::IgnoredGesturesPropagateToParent);
   650     canvas->viewport()->grabGesture(Qt::SwipeGesture,Qt::DontStartGestureOnChildren|Qt::ReceivePartialGestures|Qt::IgnoredGesturesPropagateToParent);
   476     canvas->viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
   651     canvas->viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
   477 }
   652 }
   478 
   653 
   479 int QDeclarativeViewer::menuBarHeight() const
       
   480 {
       
   481     if (!(windowFlags() & Qt::FramelessWindowHint))
       
   482         return menuBar()->height();
       
   483     else
       
   484         return 0; // don't create menu
       
   485 }
       
   486 
       
   487 QMenuBar *QDeclarativeViewer::menuBar() const
       
   488 {
       
   489 #if !defined(Q_OS_SYMBIAN)
       
   490     if (!mb)
       
   491         mb = new SizedMenuBar((QWidget*)this, canvas);
       
   492 #else
       
   493     mb = QMainWindow::menuBar();
       
   494 #endif
       
   495 
       
   496     return mb;
       
   497 }
       
   498 
       
   499 QDeclarativeView *QDeclarativeViewer::view() const
   654 QDeclarativeView *QDeclarativeViewer::view() const
   500 {
   655 {
   501     return canvas;
   656     return canvas;
   502 }
   657 }
   503 
   658 
   504 LoggerWidget *QDeclarativeViewer::warningsWidget() const
   659 LoggerWidget *QDeclarativeViewer::warningsWidget() const
   505 {
   660 {
   506     return loggerWindow;
   661     return loggerWindow;
   507 }
   662 }
   508 
   663 
   509 void QDeclarativeViewer::createMenu(QMenuBar *menu, QMenu *flatmenu)
   664 void QDeclarativeViewer::createMenu()
   510 {
   665 {
   511     QObject *parent = flatmenu ? (QObject*)flatmenu : (QObject*)menu;
   666     QAction *openAction = new QAction(tr("&Open..."), this);
   512 
       
   513     QMenu *fileMenu = flatmenu ? flatmenu : menu->addMenu(tr("&File"));
       
   514 
       
   515     QAction *openAction = new QAction(tr("&Open..."), parent);
       
   516     openAction->setShortcut(QKeySequence("Ctrl+O"));
   667     openAction->setShortcut(QKeySequence("Ctrl+O"));
   517     connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
   668     connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
   518     fileMenu->addAction(openAction);
   669 
   519 
   670     QAction *reloadAction = new QAction(tr("&Reload"), this);
   520     QAction *reloadAction = new QAction(tr("&Reload"), parent);
       
   521     reloadAction->setShortcut(QKeySequence("Ctrl+R"));
   671     reloadAction->setShortcut(QKeySequence("Ctrl+R"));
   522     connect(reloadAction, SIGNAL(triggered()), this, SLOT(reload()));
   672     connect(reloadAction, SIGNAL(triggered()), this, SLOT(reload()));
   523     fileMenu->addAction(reloadAction);
   673 
   524 
   674     QAction *snapshotAction = new QAction(tr("&Take Snapshot"), this);
   525 #if defined(Q_OS_SYMBIAN)
   675     snapshotAction->setShortcut(QKeySequence("F3"));
   526     QAction *networkAction = new QAction(tr("Start &Network"), parent);
       
   527     connect(networkAction, SIGNAL(triggered()), this, SLOT(startNetwork()));
       
   528     fileMenu->addAction(networkAction);
       
   529 #endif
       
   530 
       
   531 #if !defined(Q_OS_SYMBIAN)
       
   532     if (flatmenu) flatmenu->addSeparator();
       
   533 
       
   534     QMenu *recordMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Recording"));
       
   535 
       
   536     QAction *snapshotAction = new QAction(tr("&Take Snapshot\tF3"), parent);
       
   537     connect(snapshotAction, SIGNAL(triggered()), this, SLOT(takeSnapShot()));
   676     connect(snapshotAction, SIGNAL(triggered()), this, SLOT(takeSnapShot()));
   538     recordMenu->addAction(snapshotAction);
   677 
   539 
   678     recordAction = new QAction(tr("Start Recording &Video"), this);
   540     recordAction = new QAction(tr("Start Recording &Video\tF9"), parent);
   679     recordAction->setShortcut(QKeySequence("F9"));
   541     connect(recordAction, SIGNAL(triggered()), this, SLOT(toggleRecordingWithSelection()));
   680     connect(recordAction, SIGNAL(triggered()), this, SLOT(toggleRecordingWithSelection()));
   542     recordMenu->addAction(recordAction);
   681 
   543 
   682     QAction *recordOptions = new QAction(tr("Video &Options..."), this);
   544     QAction *recordOptions = new QAction(tr("Video &Options..."), parent);
       
   545     connect(recordOptions, SIGNAL(triggered()), this, SLOT(chooseRecordingOptions()));
   683     connect(recordOptions, SIGNAL(triggered()), this, SLOT(chooseRecordingOptions()));
   546 
   684 
   547     if (flatmenu)
   685     QAction *slowAction = new QAction(tr("&Slow Down Animations"), this);
   548         flatmenu->addAction(recordOptions);
       
   549 
       
   550     if (flatmenu) flatmenu->addSeparator();
       
   551 
       
   552     QMenu *debugMenu = flatmenu ? flatmenu->addMenu(tr("&Debugging")) : menu->addMenu(tr("&Debugging"));
       
   553 
       
   554     QAction *slowAction = new QAction(tr("&Slow Down Animations"), parent);
       
   555     slowAction->setShortcut(QKeySequence("Ctrl+."));
   686     slowAction->setShortcut(QKeySequence("Ctrl+."));
   556     slowAction->setCheckable(true);
   687     slowAction->setCheckable(true);
   557     connect(slowAction, SIGNAL(triggered(bool)), this, SLOT(setSlowMode(bool)));
   688     connect(slowAction, SIGNAL(triggered(bool)), this, SLOT(setSlowMode(bool)));
   558     debugMenu->addAction(slowAction);
   689 
   559 
   690     showWarningsWindow = new QAction(tr("Show Warnings"), this);
   560     showWarningsWindow = new QAction(tr("Show Warnings"), parent);
       
   561     showWarningsWindow->setCheckable((true));
   691     showWarningsWindow->setCheckable((true));
   562     showWarningsWindow->setChecked(loggerWindow->isVisible());
   692     showWarningsWindow->setChecked(loggerWindow->isVisible());
   563     connect(showWarningsWindow, SIGNAL(triggered(bool)), this, SLOT(showWarnings(bool)));
   693     connect(showWarningsWindow, SIGNAL(triggered(bool)), this, SLOT(showWarnings(bool)));
   564 
   694 
       
   695     QAction *proxyAction = new QAction(tr("HTTP &Proxy..."), this);
       
   696     connect(proxyAction, SIGNAL(triggered()), this, SLOT(showProxySettings()));
       
   697 
       
   698     QAction *fullscreenAction = new QAction(tr("Full Screen"), this);
       
   699     fullscreenAction->setCheckable(true);
       
   700     connect(fullscreenAction, SIGNAL(triggered()), this, SLOT(toggleFullScreen()));
       
   701 
       
   702     QAction *rotateOrientation = new QAction(tr("Rotate orientation"), this);
       
   703     rotateOrientation->setShortcut(QKeySequence("Ctrl+T"));
       
   704     connect(rotateOrientation, SIGNAL(triggered()), this, SLOT(rotateOrientation()));
       
   705 
       
   706     orientation = new QActionGroup(this);
       
   707     orientation->setExclusive(true);
       
   708     connect(orientation, SIGNAL(triggered(QAction*)), this, SLOT(changeOrientation(QAction*)));
       
   709 
       
   710     QAction *portraitAction = new QAction(tr("Portrait"), this);
       
   711     portraitAction->setCheckable(true);
       
   712     QAction *landscapeAction = new QAction(tr("Landscape"), this);
       
   713     landscapeAction->setCheckable(true);
       
   714     QAction *portraitInvAction = new QAction(tr("Portrait (inverted)"), this);
       
   715     portraitInvAction->setCheckable(true);
       
   716     QAction *landscapeInvAction = new QAction(tr("Landscape (inverted)"), this);
       
   717     landscapeInvAction->setCheckable(true);
       
   718 
       
   719     QAction *aboutAction = new QAction(tr("&About Qt..."), this);
       
   720     connect(aboutAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
       
   721 
       
   722     QAction *quitAction = new QAction(tr("&Quit"), this);
       
   723     quitAction->setShortcut(QKeySequence("Ctrl+Q"));
       
   724     connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
       
   725 
       
   726     QMenuBar *menu = menuBar();
       
   727     if (!menu)
       
   728 	return;
       
   729 
       
   730 #if defined(Q_WS_MAEMO_5)
       
   731     menu->addAction(openAction);
       
   732     menu->addAction(reloadAction);
       
   733 
       
   734     menu->addAction(snapshotAction);
       
   735     menu->addAction(recordAction);
       
   736 
       
   737     menu->addAction(recordOptions);
       
   738     menu->addAction(proxyAction);
       
   739 
       
   740     menu->addAction(slowAction);
       
   741     menu->addAction(showWarningsWindow);
       
   742 
       
   743     orientation->addAction(landscapeAction);
       
   744     orientation->addAction(portraitAction);
       
   745     menu->addAction(new Maemo5PickerAction(tr("Set orientation"), orientation, this));
       
   746     menu->addAction(fullscreenAction);
       
   747     return;
       
   748 #endif // Q_WS_MAEMO_5
       
   749 
       
   750     QMenu *fileMenu = menu->addMenu(tr("&File"));
       
   751     fileMenu->addAction(openAction);
       
   752     fileMenu->addAction(reloadAction);
       
   753     fileMenu->addSeparator();
       
   754     fileMenu->addAction(quitAction);
       
   755 
   565 #if !defined(Q_OS_SYMBIAN)
   756 #if !defined(Q_OS_SYMBIAN)
       
   757     QMenu *recordMenu = menu->addMenu(tr("&Recording"));
       
   758     recordMenu->addAction(snapshotAction);
       
   759     recordMenu->addAction(recordAction);
       
   760 
       
   761     QMenu *debugMenu = menu->addMenu(tr("&Debugging"));
       
   762     debugMenu->addAction(slowAction);
   566     debugMenu->addAction(showWarningsWindow);
   763     debugMenu->addAction(showWarningsWindow);
   567 #endif
   764 #endif // ! Q_OS_SYMBIAN
   568 
   765 
   569     if (flatmenu) flatmenu->addSeparator();
   766     QMenu *settingsMenu = menu->addMenu(tr("S&ettings"));
   570 
       
   571 #endif // Q_OS_SYMBIAN
       
   572 
       
   573     QMenu *settingsMenu = flatmenu ? flatmenu : menu->addMenu(tr("S&ettings"));
       
   574     QAction *proxyAction = new QAction(tr("Http &proxy..."), parent);
       
   575     connect(proxyAction, SIGNAL(triggered()), this, SLOT(showProxySettings()));
       
   576     settingsMenu->addAction(proxyAction);
   767     settingsMenu->addAction(proxyAction);
   577 #if !defined(Q_OS_SYMBIAN)
   768 #if !defined(Q_OS_SYMBIAN)
   578     if (!flatmenu)
   769     settingsMenu->addAction(recordOptions);
   579         settingsMenu->addAction(recordOptions);
       
   580 
       
   581     settingsMenu->addMenu(loggerWindow->preferencesMenu());
   770     settingsMenu->addMenu(loggerWindow->preferencesMenu());
   582 #else
   771 #else // ! Q_OS_SYMBIAN
   583     QAction *fullscreenAction = new QAction(tr("Full Screen"), parent);
       
   584     fullscreenAction->setCheckable(true);
       
   585     connect(fullscreenAction, SIGNAL(triggered()), this, SLOT(toggleFullScreen()));
       
   586     settingsMenu->addAction(fullscreenAction);
   772     settingsMenu->addAction(fullscreenAction);
   587 #endif
   773 #endif // Q_OS_SYMBIAN
   588 
   774     settingsMenu->addAction(rotateOrientation);
   589     if (flatmenu) flatmenu->addSeparator();
       
   590 
   775 
   591     QMenu *propertiesMenu = settingsMenu->addMenu(tr("Properties"));
   776     QMenu *propertiesMenu = settingsMenu->addMenu(tr("Properties"));
   592 
   777 
   593     QActionGroup *orientation = new QActionGroup(parent);
   778     orientation->addAction(portraitAction);
   594 
   779     orientation->addAction(landscapeAction);
   595     QAction *toggleOrientation = new QAction(tr("&Toggle Orientation"), parent);
   780     orientation->addAction(portraitInvAction);
   596     toggleOrientation->setCheckable(true);
   781     orientation->addAction(landscapeInvAction);
   597     toggleOrientation->setShortcut(QKeySequence("Ctrl+T"));
   782     propertiesMenu->addActions(orientation->actions());
   598     settingsMenu->addAction(toggleOrientation);
   783 
   599     connect(toggleOrientation, SIGNAL(triggered()), this, SLOT(toggleOrientation()));
   784     QMenu *helpMenu = menu->addMenu(tr("&Help"));
   600 
       
   601     orientation->setExclusive(true);
       
   602     portraitOrientation = new QAction(tr("orientation: Portrait"), parent);
       
   603     portraitOrientation->setCheckable(true);
       
   604     connect(portraitOrientation, SIGNAL(triggered()), this, SLOT(setPortrait()));
       
   605     orientation->addAction(portraitOrientation);
       
   606     propertiesMenu->addAction(portraitOrientation);
       
   607 
       
   608     landscapeOrientation = new QAction(tr("orientation: Landscape"), parent);
       
   609     landscapeOrientation->setCheckable(true);
       
   610     connect(landscapeOrientation, SIGNAL(triggered()), this, SLOT(setLandscape()));
       
   611     orientation->addAction(landscapeOrientation);
       
   612     propertiesMenu->addAction(landscapeOrientation);
       
   613 
       
   614     if (flatmenu) flatmenu->addSeparator();
       
   615 
       
   616     QMenu *helpMenu = flatmenu ? flatmenu : menu->addMenu(tr("&Help"));
       
   617     QAction *aboutAction = new QAction(tr("&About Qt..."), parent);
       
   618     connect(aboutAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
       
   619     helpMenu->addAction(aboutAction);
   785     helpMenu->addAction(aboutAction);
   620 
       
   621     QAction *quitAction = new QAction(tr("&Quit"), parent);
       
   622     quitAction->setShortcut(QKeySequence("Ctrl+Q"));
       
   623     connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
       
   624     fileMenu->addSeparator();
       
   625     fileMenu->addAction(quitAction);
       
   626     if (menu) {
       
   627         menu->setFixedHeight(menu->sizeHint().height());
       
   628         menu->setMinimumWidth(10);
       
   629     }
       
   630 }
   786 }
   631 
   787 
   632 void QDeclarativeViewer::showProxySettings()
   788 void QDeclarativeViewer::showProxySettings()
   633 {
   789 {
   634     ProxySettings settingsDlg (this);
   790     ProxySettings settingsDlg (this);
   638     settingsDlg.exec();
   794     settingsDlg.exec();
   639 }
   795 }
   640 
   796 
   641 void QDeclarativeViewer::proxySettingsChanged()
   797 void QDeclarativeViewer::proxySettingsChanged()
   642 {
   798 {
       
   799     namFactory->proxyChanged();
   643     reload ();
   800     reload ();
   644 }
   801 }
   645 
   802 
   646 void QDeclarativeViewer::setPortrait()
   803 void QDeclarativeViewer::rotateOrientation()
   647 {
   804 {
   648     DeviceOrientation::instance()->setOrientation(DeviceOrientation::Portrait);
   805     QAction *current = orientation->checkedAction();
   649     portraitOrientation->setChecked(true);
   806     QList<QAction *> actions = orientation->actions();
   650 }
   807     int index = actions.indexOf(current);
   651 
   808     if (index < 0)
   652 void QDeclarativeViewer::setLandscape()
   809         return;
   653 {
   810 
   654     DeviceOrientation::instance()->setOrientation(DeviceOrientation::Landscape);
   811     QAction *newOrientation = actions[(index + 1) % actions.count()];
   655     landscapeOrientation->setChecked(true);
   812     changeOrientation(newOrientation);
   656 }
       
   657 
       
   658 void QDeclarativeViewer::toggleOrientation()
       
   659 {
       
   660     DeviceOrientation::instance()->setOrientation(DeviceOrientation::instance()->orientation()==DeviceOrientation::Portrait?DeviceOrientation::Landscape:DeviceOrientation::Portrait);
       
   661 }
   813 }
   662 
   814 
   663 void QDeclarativeViewer::toggleFullScreen()
   815 void QDeclarativeViewer::toggleFullScreen()
   664 {
   816 {
   665     if (isFullScreen())
   817     if (isFullScreen())
   703 {
   855 {
   704     // File
   856     // File
   705     recdlg->file->setText(record_file);
   857     recdlg->file->setText(record_file);
   706 
   858 
   707     // Size
   859     // Size
   708     recdlg->sizeOriginal->setText(tr("Original (%1x%2)").arg(canvas->width()).arg(canvas->height()));
   860     recdlg->setOriginalSize(canvas->size());
   709     if (recdlg->sizeWidth->value()<=1) {
       
   710         recdlg->sizeWidth->setValue(canvas->width());
       
   711         recdlg->sizeHeight->setValue(canvas->height());
       
   712     }
       
   713 
   861 
   714     // Rate
   862     // Rate
   715     if (record_rate == 24)
   863     recdlg->setVideoRate(record_rate);
   716         recdlg->hz24->setChecked(true);
   864 
   717     else if (record_rate == 25)
       
   718         recdlg->hz25->setChecked(true);
       
   719     else if (record_rate == 50)
       
   720         recdlg->hz50->setChecked(true);
       
   721     else if (record_rate == 60)
       
   722         recdlg->hz60->setChecked(true);
       
   723     else {
       
   724         recdlg->hzCustom->setChecked(true);
       
   725         recdlg->hz->setText(QString::number(record_rate));
       
   726     }
       
   727 
   865 
   728     // Profile
   866     // Profile
   729     recdlg->setArguments(record_args.join(" "));
   867     recdlg->setArguments(record_args.join(" "));
   730     if (recdlg->exec()) {
   868     if (recdlg->exec()) {
   731         // File
   869         // File
   732         record_file = recdlg->file->text();
   870         record_file = recdlg->file->text();
   733         // Size
   871         // Size
   734         if (recdlg->sizeOriginal->isChecked())
   872         record_outsize = recdlg->videoSize();
   735             record_outsize = QSize();
       
   736         else if (recdlg->size720p->isChecked())
       
   737             record_outsize = QSize(1280,720);
       
   738         else if (recdlg->sizeVGA->isChecked())
       
   739             record_outsize = QSize(640,480);
       
   740         else if (recdlg->sizeQVGA->isChecked())
       
   741             record_outsize = QSize(320,240);
       
   742         else
       
   743             record_outsize = QSize(recdlg->sizeWidth->value(),recdlg->sizeHeight->value());
       
   744         // Rate
   873         // Rate
   745         if (recdlg->hz24->isChecked())
   874         record_rate = recdlg->videoRate();
   746             record_rate = 24;
       
   747         else if (recdlg->hz25->isChecked())
       
   748             record_rate = 25;
       
   749         else if (recdlg->hz50->isChecked())
       
   750             record_rate = 50;
       
   751         else if (recdlg->hz60->isChecked())
       
   752             record_rate = 60;
       
   753         else {
       
   754             record_rate = recdlg->hz->text().toDouble();
       
   755         }
       
   756         // Profile
   875         // Profile
   757         record_args = recdlg->arguments().split(" ",QString::SkipEmptyParts);
   876         record_args = recdlg->arguments().split(" ",QString::SkipEmptyParts);
   758     }
   877     }
   759 }
   878 }
   760 
   879 
   761 void QDeclarativeViewer::toggleRecordingWithSelection()
   880 void QDeclarativeViewer::toggleRecordingWithSelection()
   762 {
   881 {
   763     if (!recordTimer.isRunning()) {
   882     if (!recordTimer.isActive()) {
   764         if (record_file.isEmpty()) {
   883         if (record_file.isEmpty()) {
   765             QString fileName = getVideoFileName();
   884             QString fileName = getVideoFileName();
   766             if (fileName.isEmpty())
   885             if (fileName.isEmpty())
   767                 return;
   886                 return;
   768             if (!fileName.contains(QRegExp(".[^\\/]*$")))
   887             if (!fileName.contains(QRegExp(".[^\\/]*$")))
   777 {
   896 {
   778     if (record_file.isEmpty()) {
   897     if (record_file.isEmpty()) {
   779         toggleRecordingWithSelection();
   898         toggleRecordingWithSelection();
   780         return;
   899         return;
   781     }
   900     }
   782     bool recording = !recordTimer.isRunning();
   901     bool recording = !recordTimer.isActive();
   783     recordAction->setText(recording ? tr("&Stop Recording Video\tF9") : tr("&Start Recording Video\tF9"));
   902     recordAction->setText(recording ? tr("&Stop Recording Video\tF9") : tr("&Start Recording Video\tF9"));
   784     setRecording(recording);
   903     setRecording(recording);
   785 }
   904 }
   786 
   905 
   787 void QDeclarativeViewer::setSlowMode(bool enable)
   906 void QDeclarativeViewer::setSlowMode(bool enable)
   822 {
   941 {
   823     if (canvas->status() == QDeclarativeView::Error && tester)
   942     if (canvas->status() == QDeclarativeView::Error && tester)
   824         tester->executefailure();
   943         tester->executefailure();
   825 
   944 
   826     if (canvas->status() == QDeclarativeView::Ready) {
   945     if (canvas->status() == QDeclarativeView::Ready) {
   827         initialSize = canvas->sizeHint();
   946         initialSize = canvas->initialSize();
   828         if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) {
   947         updateSizeHints(true);
   829             updateSizeHints();
       
   830             resize(QSize(initialSize.width(), initialSize.height()+menuBarHeight()));
       
   831         }
       
   832     }
   948     }
   833 }
   949 }
   834 
   950 
   835 void QDeclarativeViewer::launch(const QString& file_or_url)
   951 void QDeclarativeViewer::launch(const QString& file_or_url)
   836 {
   952 {
   928     canvas->setSource(url);
  1044     canvas->setSource(url);
   929 
  1045 
   930     return true;
  1046     return true;
   931 }
  1047 }
   932 
  1048 
   933 void QDeclarativeViewer::startNetwork()
       
   934 {
       
   935 #if defined(SYMBIAN_NETWORK_INIT)
       
   936     qt_SetDefaultIap();
       
   937 #endif
       
   938 }
       
   939 
       
   940 void QDeclarativeViewer::setAutoRecord(int from, int to)
  1049 void QDeclarativeViewer::setAutoRecord(int from, int to)
   941 {
  1050 {
   942     if (from==0) from=1; // ensure resized
  1051     if (from==0) from=1; // ensure resized
   943     record_autotime = to-from;
  1052     record_autotime = to-from;
   944     autoStartTimer.setInterval(from);
  1053     autoStartTimer.setInterval(from);
   945     autoStartTimer.setRunning(true);
  1054     autoStartTimer.start();
   946 }
  1055 }
   947 
  1056 
   948 void QDeclarativeViewer::setRecordArgs(const QStringList& a)
  1057 void QDeclarativeViewer::setRecordArgs(const QStringList& a)
   949 {
  1058 {
   950     record_args = a;
  1059     record_args = a;
   958 void QDeclarativeViewer::setRecordRate(int fps)
  1067 void QDeclarativeViewer::setRecordRate(int fps)
   959 {
  1068 {
   960     record_rate = fps;
  1069     record_rate = fps;
   961 }
  1070 }
   962 
  1071 
   963 void QDeclarativeViewer::sceneResized(QSize size)
  1072 void QDeclarativeViewer::sceneResized(QSize)
   964 {
  1073 {
   965     if (size.width() > 0 && size.height() > 0) {
  1074     updateSizeHints();
   966         if (canvas->resizeMode() == QDeclarativeView::SizeViewToRootObject) {
       
   967             updateSizeHints();
       
   968         }
       
   969      }
       
   970 }
  1075 }
   971 
  1076 
   972 void QDeclarativeViewer::keyPressEvent(QKeyEvent *event)
  1077 void QDeclarativeViewer::keyPressEvent(QKeyEvent *event)
   973 {
  1078 {
   974     if (event->key() == Qt::Key_0 && devicemode)
  1079     if (event->key() == Qt::Key_0 && devicemode)
   993     } else if (event->key() == Qt::Key_F5 || (event->key() == Qt::Key_5 && devicemode)) {
  1098     } else if (event->key() == Qt::Key_F5 || (event->key() == Qt::Key_5 && devicemode)) {
   994         reload();
  1099         reload();
   995     } else if (event->key() == Qt::Key_F9 || (event->key() == Qt::Key_9 && devicemode)) {
  1100     } else if (event->key() == Qt::Key_F9 || (event->key() == Qt::Key_9 && devicemode)) {
   996         toggleRecording();
  1101         toggleRecording();
   997     } else if (event->key() == Qt::Key_F10) {
  1102     } else if (event->key() == Qt::Key_F10) {
   998         if (portraitOrientation) {
  1103         rotateOrientation();
   999             if (portraitOrientation->isChecked())
       
  1000                 setLandscape();
       
  1001             else
       
  1002                 setPortrait();
       
  1003         }
       
  1004     }
  1104     }
  1005 
  1105 
  1006     QWidget::keyPressEvent(event);
  1106     QWidget::keyPressEvent(event);
  1007 }
  1107 }
  1008 
  1108 
  1047     connect(recdlg->ffmpegHelp,SIGNAL(clicked()), ffmpegHelpWindow, SLOT(show()));
  1147     connect(recdlg->ffmpegHelp,SIGNAL(clicked()), ffmpegHelpWindow, SLOT(show()));
  1048 }
  1148 }
  1049 
  1149 
  1050 void QDeclarativeViewer::setRecording(bool on)
  1150 void QDeclarativeViewer::setRecording(bool on)
  1051 {
  1151 {
  1052     if (on == recordTimer.isRunning())
  1152     if (on == recordTimer.isActive())
  1053         return;
  1153         return;
  1054 
  1154 
  1055     int period = int(1000/record_rate+0.5);
  1155     int period = int(1000/record_rate+0.5);
  1056     QUnifiedTimer::instance()->setTimingInterval(on ? period:16);
  1156     QUnifiedTimer::instance()->setTimingInterval(on ? period:16);
  1057     QUnifiedTimer::instance()->setConsistentTiming(on);
  1157     QUnifiedTimer::instance()->setConsistentTiming(on);
  1058     if (on) {
  1158     if (on) {
  1059         canvas->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
  1159         canvas->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
  1060         recordTimer.setInterval(period);
  1160         recordTimer.setInterval(period);
  1061         recordTimer.setRunning(true);
  1161         recordTimer.start();
  1062         frame_fmt = record_file.right(4).toLower();
  1162         frame_fmt = record_file.right(4).toLower();
  1063         frame = QImage(canvas->width(),canvas->height(),QImage::Format_RGB32);
  1163         frame = QImage(canvas->width(),canvas->height(),QImage::Format_RGB32);
  1064         if (frame_fmt != ".png" && (!convertAvailable || frame_fmt != ".gif")) {
  1164         if (frame_fmt != ".png" && (!convertAvailable || frame_fmt != ".gif")) {
  1065             // Stream video to ffmpeg
  1165             // Stream video to ffmpeg
  1066 
  1166 
  1087             // Store frames, save to GIF/PNG
  1187             // Store frames, save to GIF/PNG
  1088             frame_stream = 0;
  1188             frame_stream = 0;
  1089         }
  1189         }
  1090     } else {
  1190     } else {
  1091         canvas->setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
  1191         canvas->setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
  1092         recordTimer.setRunning(false);
  1192         recordTimer.stop();
  1093         if (frame_stream) {
  1193         if (frame_stream) {
  1094             qDebug() << "Saving video...";
  1194             qDebug() << "Saving video...";
  1095             frame_stream->close();
  1195             frame_stream->close();
  1096             qDebug() << "Wrote" << record_file;
  1196             qDebug() << "Wrote" << record_file;
  1097         } else {
  1197         } else {
  1167                 QFile::remove(name);
  1267                 QFile::remove(name);
  1168 
  1268 
  1169             frames.clear();
  1269             frames.clear();
  1170         }
  1270         }
  1171     }
  1271     }
  1172     qDebug() << "Recording: " << (recordTimer.isRunning()?"ON":"OFF");
  1272     qDebug() << "Recording: " << (recordTimer.isActive()?"ON":"OFF");
  1173 }
  1273 }
  1174 
  1274 
  1175 void QDeclarativeViewer::ffmpegFinished(int code)
  1275 void QDeclarativeViewer::ffmpegFinished(int code)
  1176 {
  1276 {
  1177     qDebug() << "ffmpeg returned" << code << frame_stream->readAllStandardError();
  1277     qDebug() << "ffmpeg returned" << code << frame_stream->readAllStandardError();
       
  1278 }
       
  1279 
       
  1280 void QDeclarativeViewer::appAboutToQuit()
       
  1281 {
       
  1282     // avoid QGLContext errors about invalid contexts on exit
       
  1283     canvas->setViewport(0);
       
  1284 
       
  1285     // avoid crashes if messages are received after app has closed
       
  1286     delete loggerWindow;
       
  1287     loggerWindow = 0;
  1178 }
  1288 }
  1179 
  1289 
  1180 void QDeclarativeViewer::autoStartRecording()
  1290 void QDeclarativeViewer::autoStartRecording()
  1181 {
  1291 {
  1182     setRecording(true);
  1292     setRecording(true);
  1183     autoStopTimer.setInterval(record_autotime);
  1293     autoStopTimer.setInterval(record_autotime);
  1184     autoStopTimer.setRunning(true);
  1294     autoStopTimer.start();
  1185 }
  1295 }
  1186 
  1296 
  1187 void QDeclarativeViewer::autoStopRecording()
  1297 void QDeclarativeViewer::autoStopRecording()
  1188 {
  1298 {
  1189     setRecording(false);
  1299     setRecording(false);
  1203     } else {
  1313     } else {
  1204         frames.append(new QImage(frame));
  1314         frames.append(new QImage(frame));
  1205     }
  1315     }
  1206 }
  1316 }
  1207 
  1317 
       
  1318 void QDeclarativeViewer::changeOrientation(QAction *action)
       
  1319 {
       
  1320     if (!action)
       
  1321         return;
       
  1322     action->setChecked(true);
       
  1323 
       
  1324     QString o = action->text();
       
  1325     if (o == QLatin1String("Portrait"))
       
  1326         DeviceOrientation::instance()->setOrientation(DeviceOrientation::Portrait);
       
  1327     else if (o == QLatin1String("Landscape"))
       
  1328         DeviceOrientation::instance()->setOrientation(DeviceOrientation::Landscape);
       
  1329     else if (o == QLatin1String("Portrait (inverted)"))
       
  1330         DeviceOrientation::instance()->setOrientation(DeviceOrientation::PortraitInverted);
       
  1331     else if (o == QLatin1String("Landscape (inverted)"))
       
  1332         DeviceOrientation::instance()->setOrientation(DeviceOrientation::LandscapeInverted);
       
  1333 }
       
  1334 
  1208 void QDeclarativeViewer::orientationChanged()
  1335 void QDeclarativeViewer::orientationChanged()
  1209 {
  1336 {
  1210     if (canvas->resizeMode() == QDeclarativeView::SizeRootObjectToView) {
  1337     updateSizeHints();
  1211         if (canvas->rootObject()) {
       
  1212             QSizeF rootObjectSize = canvas->rootObject()->boundingRect().size();
       
  1213             QSize newSize(rootObjectSize.width(), rootObjectSize.height()+menuBarHeight());
       
  1214             if (size() != newSize) {
       
  1215                 resize(newSize);
       
  1216             }
       
  1217         }
       
  1218     }
       
  1219 }
  1338 }
  1220 
  1339 
  1221 void QDeclarativeViewer::setDeviceKeys(bool on)
  1340 void QDeclarativeViewer::setDeviceKeys(bool on)
  1222 {
  1341 {
  1223     devicemode = on;
  1342     devicemode = on;
  1243         //### potentially faster, but causes junk to appear if top-level is Item, not Rectangle
  1362         //### potentially faster, but causes junk to appear if top-level is Item, not Rectangle
  1244         //glWidget->setAutoFillBackground(false);
  1363         //glWidget->setAutoFillBackground(false);
  1245 
  1364 
  1246         canvas->setViewport(glWidget);
  1365         canvas->setViewport(glWidget);
  1247     }
  1366     }
       
  1367 #else
       
  1368     Q_UNUSED(useGL)
  1248 #endif
  1369 #endif
  1249 }
  1370 }
  1250 
  1371 
  1251 void QDeclarativeViewer::setUseNativeFileBrowser(bool use)
  1372 void QDeclarativeViewer::setUseNativeFileBrowser(bool use)
  1252 {
  1373 {
  1260         canvas->setResizeMode(resizeMode);
  1381         canvas->setResizeMode(resizeMode);
  1261         updateSizeHints();
  1382         updateSizeHints();
  1262     }
  1383     }
  1263 }
  1384 }
  1264 
  1385 
  1265 void QDeclarativeViewer::updateSizeHints()
  1386 void QDeclarativeViewer::updateSizeHints(bool initial)
  1266 {
  1387 {
  1267     if (canvas->resizeMode() == QDeclarativeView::SizeViewToRootObject) {
  1388     static bool isRecursive = false;
  1268         QSize newWindowSize = canvas->sizeHint();
  1389 
  1269         newWindowSize.setHeight(newWindowSize.height()+menuBarHeight());
  1390     if (isRecursive)
       
  1391         return;
       
  1392     isRecursive = true;
       
  1393 
       
  1394     if (initial || (canvas->resizeMode() == QDeclarativeView::SizeViewToRootObject)) {
       
  1395         QSize newWindowSize = initial ? initialSize : canvas->sizeHint();
       
  1396         //qWarning() << "USH:" << (initial ? "INIT:" : "V2R:") << "setting fixed size " << newWindowSize;
  1270         if (!isFullScreen() && !isMaximized()) {
  1397         if (!isFullScreen() && !isMaximized()) {
  1271             resize(newWindowSize);
  1398             canvas->setFixedSize(newWindowSize);
  1272             setFixedSize(newWindowSize);
  1399             resize(1, 1);
  1273         }
  1400             layout()->setSizeConstraint(QLayout::SetFixedSize);
  1274     } else { // QDeclarativeView::SizeRootObjectToView
  1401             layout()->activate();
  1275         canvas->setMinimumSize(QSize(0,0));
  1402         }
  1276         canvas->setMaximumSize(QSize(16777215,16777215));
  1403     }
  1277         setMinimumSize(QSize(0,0));
  1404     //qWarning() << "USH: R2V: setting free size ";
  1278         setMaximumSize(QSize(16777215,16777215));
  1405     layout()->setSizeConstraint(QLayout::SetNoConstraint);
  1279     }
  1406     layout()->activate();
  1280     updateGeometry();
  1407     setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
       
  1408     canvas->setMinimumSize(QSize(0,0));
       
  1409     canvas->setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
       
  1410 
       
  1411     isRecursive = false;
  1281 }
  1412 }
  1282 
  1413 
  1283 void QDeclarativeViewer::registerTypes()
  1414 void QDeclarativeViewer::registerTypes()
  1284 {
  1415 {
  1285     static bool registered = false;
  1416     static bool registered = false;