Changeset 846 for trunk/demos/qtdemo/menumanager.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/demos/qtdemo/menumanager.cpp
r696 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 153 153 this->launchExample(this->currentInfo); 154 154 break; 155 case LAUNCH_QML: 156 this->launchQmlExample(this->currentInfo); 157 break; 155 158 case DOCUMENTATION: 156 159 this->showDocInAssistant(this->currentInfo); … … 170 173 this->score->queueMovie(this->currentInfo + " -buttons -out", Score::NEW_ANIMATION_ONLY); 171 174 this->score->queueMovie("back -out", Score::ONLY_IF_VISIBLE); 175 if(qmlRoot) 176 qmlRoot->setProperty("show", QVariant(false)); 172 177 // book-keeping: 173 178 this->currentMenuCode = ROOT; … … 192 197 this->score->queueMovie(this->currentMenuButtons + " -out", Score::FROM_START, Score::LOCK_ITEMS); 193 198 this->score->queueMovie(this->currentInfo + " -out"); 199 if(qmlRoot) 200 qmlRoot->setProperty("show", QVariant(false)); 194 201 // book-keeping: 195 202 this->currentMenuCode = MENU1; … … 209 216 this->score->queueMovie(this->currentInfo + " -out", Score::NEW_ANIMATION_ONLY); 210 217 this->score->queueMovie(this->currentInfo + " -buttons -out", Score::NEW_ANIMATION_ONLY); 218 if(qmlRoot) 219 qmlRoot->setProperty("show", QVariant(false)); 211 220 // book-keeping: 212 221 this->currentMenuCode = MENU2; … … 243 252 this->score->queueMovie(this->currentInfo + " -out", Score::NEW_ANIMATION_ONLY); 244 253 this->score->queueMovie(this->currentInfo + " -buttons -out", Score::NEW_ANIMATION_ONLY); 254 if(qmlRoot) 255 qmlRoot->setProperty("show", QVariant(false)); 245 256 // book-keeping: 246 257 this->currentMenuCode = MENU1; … … 303 314 // was started to activate assistant and bring it to front: 304 315 QTextStream str(&this->assistantProcess); 305 str << "SetSource " << url << QLatin1Char('\ 0') << endl;316 str << "SetSource " << url << QLatin1Char('\n') << endl; 306 317 } 307 318 … … 344 355 } 345 356 357 void MenuManager::launchQmlExample(const QString &name) 358 { 359 #ifndef QT_NO_DECLARATIVE 360 if(!qmlRoot){ 361 exampleError(QProcess::UnknownError); 362 return; 363 } 364 //resolveQmlFilename - refactor to separate fn? 365 QString dirName = this->info[name]["dirname"]; 366 QString category = this->info[name]["category"]; 367 QString fileName = this->info[name]["filename"]; 368 QDir dir; 369 if (category == "demos") 370 dir = QDir(QLibraryInfo::location(QLibraryInfo::DemosPath)); 371 else 372 dir = QDir(QLibraryInfo::location(QLibraryInfo::ExamplesPath)); 373 QFile file(dir.path() + "/" + dirName + "/" + fileName + "/" + "main.qml"); 374 if(!file.exists()){ 375 //try dirname.qml as well 376 file.setFileName(dir.path() + "/" + dirName + "/" + fileName + "/" + fileName.split('/').last() + ".qml"); 377 if(!file.exists()){ 378 exampleError(QProcess::UnknownError); 379 return; 380 } 381 } 382 383 qmlRoot->setProperty("qmlFile", QVariant(""));//unload component 384 qmlRoot->setProperty("show", QVariant(true)); 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)); 395 } 396 346 397 void MenuManager::exampleFinished() 347 398 { … … 386 437 level2MenuNode = level2MenuNode.nextSibling(); 387 438 } 439 440 qmlRoot = 0; 441 #ifndef QT_NO_DECLARATIVE 442 // Create QML Loader 443 declarativeEngine = new QDeclarativeEngine(this); 444 connect(declarativeEngine, SIGNAL(quit()), 445 this, SLOT(quitQML())); 446 447 QDeclarativeComponent component(declarativeEngine, QUrl("qrc:qml/qmlShell.qml"), this); 448 QDeclarativeItem* qmlRootItem = 0; 449 if(component.isReady()){ 450 qmlRoot = component.create(); 451 qmlRootItem = qobject_cast<QDeclarativeItem*>(qmlRoot); 452 }else{ 453 qDebug() << component.status() << component.errorString(); 454 } 455 456 if(qmlRootItem){ 457 qmlRootItem->setHeight(this->window->scene->sceneRect().height()); 458 qmlRootItem->setWidth(this->window->scene->sceneRect().width()); 459 qmlRootItem->setZValue(101);//Above other items 460 qmlRootItem->setCursor(Qt::ArrowCursor); 461 window->scene->addItem(qmlRootItem); 462 463 //Note that QML adds key handling to the app. 464 window->viewport()->setFocusPolicy(Qt::NoFocus);//Correct keyboard focus handling 465 window->setFocusPolicy(Qt::StrongFocus); 466 window->scene->setStickyFocus(true); 467 window->setFocus(); 468 }else{ 469 qDebug() << "Error initializing QML subsystem, Declarative examples will not work"; 470 } 471 #endif 388 472 } 389 473 … … 393 477 if (this->info.contains(name)) 394 478 qWarning() << "__WARNING: MenuManager::readInfoAboutExample: Demo/example with name" 395 << name << "appears twi ze in the xml-file!__";479 << name << "appears twice in the xml-file!__"; 396 480 397 481 this->info[name]["filename"] = example.attribute("filename"); … … 400 484 this->info[name]["changedirectory"] = example.attribute("changedirectory"); 401 485 this->info[name]["image"] = example.attribute("image"); 486 this->info[name]["qml"] = example.attribute("qml"); 402 487 } 403 488 … … 434 519 dir.cd(fileName); 435 520 521 fileName = fileName.split("/").last(); 436 522 QFile unixFile(dir.path() + "/" + fileName); 437 523 if (unixFile.exists()) return unixFile.fileName(); … … 457 543 458 544 if (category == "demos") 459 return this->helpRootUrl + "demos-" + fileName + ".html";545 return this->helpRootUrl + "demos-" + fileName.replace("/", "-") + ".html"; 460 546 else 461 547 return this->helpRootUrl + dirName.replace("/", "-") + "-" + fileName + ".html"; … … 477 563 QString category = this->info[name]["category"]; 478 564 QString fileName = this->info[name]["filename"]; 565 bool qml = (this->info[name]["qml"] == QLatin1String("true")); 566 if(qml) 567 fileName = QLatin1String("qml-") + fileName.split('/').last(); 479 568 480 569 if (imageName.isEmpty()){ … … 496 585 QString name = el.attribute("name"); 497 586 createMenu(el, MENU1); 498 createInfo(new MenuContentItem(el, this->window->scene, 0), name + " -info");587 createInfo(new MenuContentItem(el, this->window->scene, this->window->mainSceneRoot), name + " -info"); 499 588 500 589 Movie *menuButtonsIn = this->score->insertMovie(name + " -buttons"); … … 508 597 QString name = el.attribute("name"); 509 598 createMenu(el, MENU2); 510 createInfo(new MenuContentItem(el, this->window->scene, 0), name + " -info");599 createInfo(new MenuContentItem(el, this->window->scene, this->window->mainSceneRoot), name + " -info"); 511 600 } 512 601 … … 514 603 { 515 604 QString name = el.attribute("name"); 516 createInfo(new ExampleContent(name, this->window->scene, 0), name);605 createInfo(new ExampleContent(name, this->window->scene, this->window->mainSceneRoot), name); 517 606 518 607 Movie *infoButtonsIn = this->score->insertMovie(name + " -buttons"); … … 521 610 if (el.attribute("executable") != "false") 522 611 createLowRightLeafButton("Launch", 405, LAUNCH, infoButtonsIn, infoButtonsOut, 0); 612 else if(el.attribute("qml") == "true") 613 createLowRightLeafButton("Display", 405, LAUNCH_QML, infoButtonsIn, infoButtonsOut, 0); 523 614 } 524 615 … … 549 640 // create normal menu button 550 641 QString label = currentNode.toElement().attribute("name"); 551 item = new TextButton(label, TextButton::LEFT, type, this->window->scene, 0);642 item = new TextButton(label, TextButton::LEFT, type, this->window->scene, this->window->mainSceneRoot); 552 643 currentNode = currentNode.nextSibling(); 553 644 … … 649 740 Movie *movieIn, Movie *movieOut, Movie *movieShake, const QString &menuString) 650 741 { 651 TextButton *button = new TextButton(label, TextButton::RIGHT, type, this->window->scene, 0, TextButton::PANEL);742 TextButton *button = new TextButton(label, TextButton::RIGHT, type, this->window->scene, this->window->mainSceneRoot, TextButton::PANEL); 652 743 if (!menuString.isNull()) 653 744 button->setMenuString(menuString); … … 691 782 void MenuManager::createLowRightButton(const QString &label, BUTTON_TYPE type, Movie *movieIn, Movie *movieOut, Movie * /*movieShake*/) 692 783 { 693 TextButton *item = new TextButton(label, TextButton::RIGHT, type, this->window->scene, 0, TextButton::PANEL);784 TextButton *item = new TextButton(label, TextButton::RIGHT, type, this->window->scene, this->window->mainSceneRoot, TextButton::PANEL); 694 785 item->setRecursiveVisible(false); 695 786 item->setZValue(10); … … 718 809 void MenuManager::createLowRightLeafButton(const QString &label, int xOffset, BUTTON_TYPE type, Movie *movieIn, Movie *movieOut, Movie * /*movieShake*/) 719 810 { 720 TextButton *item = new TextButton(label, TextButton::RIGHT, type, this->window->scene, 0, TextButton::PANEL);811 TextButton *item = new TextButton(label, TextButton::RIGHT, type, this->window->scene, this->window->mainSceneRoot, TextButton::PANEL); 721 812 item->setRecursiveVisible(false); 722 813 item->setZValue(10); … … 834 925 float yOffset = 450.0f; 835 926 836 this->upButton = new TextButton("", TextButton::LEFT, MenuManager::UP, this->window->scene, 0, TextButton::UP);927 this->upButton = new TextButton("", TextButton::LEFT, MenuManager::UP, this->window->scene, this->window->mainSceneRoot, TextButton::UP); 837 928 this->upButton->prepare(); 838 929 this->upButton->setPos(xOffset, yOffset); 839 930 this->upButton->setState(TextButton::DISABLED); 840 931 841 this->downButton = new TextButton("", TextButton::LEFT, MenuManager::DOWN, this->window->scene, 0, TextButton::DOWN);932 this->downButton = new TextButton("", TextButton::LEFT, MenuManager::DOWN, this->window->scene, this->window->mainSceneRoot, TextButton::DOWN); 842 933 this->downButton->prepare(); 843 934 this->downButton->setPos(xOffset + 10 + this->downButton->sceneBoundingRect().width(), yOffset);
Note:
See TracChangeset
for help on using the changeset viewer.