demos/qtdemo/menumanager.cpp
changeset 37 758a864f9613
parent 33 3e2da88830cd
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
   311     }
   311     }
   312 
   312 
   313     // Send command through remote control even if the process
   313     // Send command through remote control even if the process
   314     // was started to activate assistant and bring it to front:
   314     // was started to activate assistant and bring it to front:
   315     QTextStream str(&this->assistantProcess);
   315     QTextStream str(&this->assistantProcess);
   316     str << "SetSource " << url << QLatin1Char('\0') << endl;
   316     str << "SetSource " << url << QLatin1Char('\n') << endl;
   317 }
   317 }
   318 
   318 
   319 void MenuManager::launchExample(const QString &name)
   319 void MenuManager::launchExample(const QString &name)
   320 {
   320 {
   321     QString executable = this->resolveExeFile(name);
   321     QString executable = this->resolveExeFile(name);
   354 #endif
   354 #endif
   355 }
   355 }
   356 
   356 
   357 void MenuManager::launchQmlExample(const QString &name)
   357 void MenuManager::launchQmlExample(const QString &name)
   358 {
   358 {
       
   359 #ifndef QT_NO_DECLARATIVE
   359     if(!qmlRoot){
   360     if(!qmlRoot){
   360         exampleError(QProcess::UnknownError);
   361         exampleError(QProcess::UnknownError);
   361         return;
   362         return;
   362     }
   363     }
   363     //resolveQmlFilename - refactor to separate fn?
   364     //resolveQmlFilename - refactor to separate fn?
   380     }
   381     }
   381 
   382 
   382     qmlRoot->setProperty("qmlFile", QVariant(""));//unload component
   383     qmlRoot->setProperty("qmlFile", QVariant(""));//unload component
   383     qmlRoot->setProperty("show", QVariant(true));
   384     qmlRoot->setProperty("show", QVariant(true));
   384     qmlRoot->setProperty("qmlFile", QUrl::fromLocalFile(file.fileName()));
   385     qmlRoot->setProperty("qmlFile", QUrl::fromLocalFile(file.fileName()));
       
   386 #else
       
   387     exampleError(QProcess::UnknownError);
       
   388 #endif
       
   389 }
       
   390 
       
   391 void MenuManager::quitQML()
       
   392 {
       
   393     if(qmlRoot)
       
   394         qmlRoot->setProperty("show", QVariant(false));
   385 }
   395 }
   386 
   396 
   387 void MenuManager::exampleFinished()
   397 void MenuManager::exampleFinished()
   388 {
   398 {
   389 }
   399 }
   425         }
   435         }
   426 
   436 
   427         level2MenuNode = level2MenuNode.nextSibling();
   437         level2MenuNode = level2MenuNode.nextSibling();
   428     }
   438     }
   429 
   439 
       
   440     qmlRoot = 0;
       
   441 #ifndef QT_NO_DECLARATIVE
   430     // Create QML Loader
   442     // Create QML Loader
   431     declarativeEngine = new QDeclarativeEngine(this);
   443     declarativeEngine = new QDeclarativeEngine(this);
       
   444     connect(declarativeEngine, SIGNAL(quit()),
       
   445             this, SLOT(quitQML()));
   432 
   446 
   433     QDeclarativeComponent component(declarativeEngine, QUrl("qrc:qml/qmlShell.qml"), this);
   447     QDeclarativeComponent component(declarativeEngine, QUrl("qrc:qml/qmlShell.qml"), this);
   434     qmlRoot = 0;
   448     QDeclarativeItem* qmlRootItem = 0;
   435     if(component.isReady())
   449     if(component.isReady()){
   436         qmlRoot = qobject_cast<QDeclarativeItem*>(component.create());
   450         qmlRoot = component.create();
   437     else
   451         qmlRootItem = qobject_cast<QDeclarativeItem*>(qmlRoot);
       
   452     }else{
   438         qDebug() << component.status() << component.errorString();
   453         qDebug() << component.status() << component.errorString();
   439     if(qmlRoot){
   454     }
   440         qmlRoot->setHeight(this->window->scene->sceneRect().height());
   455 
   441         qmlRoot->setWidth(this->window->scene->sceneRect().width());
   456     if(qmlRootItem){
   442         qmlRoot->setZValue(101);//Above other items
   457         qmlRootItem->setHeight(this->window->scene->sceneRect().height());
   443         qmlRoot->setCursor(Qt::ArrowCursor);
   458         qmlRootItem->setWidth(this->window->scene->sceneRect().width());
   444         window->scene->addItem(qmlRoot);
   459         qmlRootItem->setZValue(101);//Above other items
       
   460         qmlRootItem->setCursor(Qt::ArrowCursor);
       
   461         window->scene->addItem(qmlRootItem);
   445 
   462 
   446         //Note that QML adds key handling to the app.
   463         //Note that QML adds key handling to the app.
   447         window->viewport()->setFocusPolicy(Qt::NoFocus);//Correct keyboard focus handling
   464         window->viewport()->setFocusPolicy(Qt::NoFocus);//Correct keyboard focus handling
   448         window->setFocusPolicy(Qt::StrongFocus);
   465         window->setFocusPolicy(Qt::StrongFocus);
   449         window->scene->setStickyFocus(true);
   466         window->scene->setStickyFocus(true);
   450         window->setFocus();
   467         window->setFocus();
   451     }else{
   468     }else{
   452         qDebug() << "Error intializing QML subsystem, Declarative examples will not work";
   469         qDebug() << "Error initializing QML subsystem, Declarative examples will not work";
   453     }
   470     }
       
   471 #endif
   454 }
   472 }
   455 
   473 
   456 void MenuManager::readInfoAboutExample(const QDomElement &example)
   474 void MenuManager::readInfoAboutExample(const QDomElement &example)
   457 {
   475 {
   458     QString name = example.attribute("name");
   476     QString name = example.attribute("name");