Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/demos/qtdemo/menumanager.cpp

    r696 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    153153        this->launchExample(this->currentInfo);
    154154        break;
     155    case LAUNCH_QML:
     156        this->launchQmlExample(this->currentInfo);
     157        break;
    155158    case DOCUMENTATION:
    156159        this->showDocInAssistant(this->currentInfo);
     
    170173        this->score->queueMovie(this->currentInfo + " -buttons -out", Score::NEW_ANIMATION_ONLY);
    171174        this->score->queueMovie("back -out", Score::ONLY_IF_VISIBLE);
     175        if(qmlRoot)
     176            qmlRoot->setProperty("show", QVariant(false));
    172177        // book-keeping:
    173178        this->currentMenuCode = ROOT;
     
    192197        this->score->queueMovie(this->currentMenuButtons + " -out", Score::FROM_START, Score::LOCK_ITEMS);
    193198        this->score->queueMovie(this->currentInfo + " -out");
     199        if(qmlRoot)
     200            qmlRoot->setProperty("show", QVariant(false));
    194201        // book-keeping:
    195202        this->currentMenuCode = MENU1;
     
    209216        this->score->queueMovie(this->currentInfo + " -out", Score::NEW_ANIMATION_ONLY);
    210217        this->score->queueMovie(this->currentInfo + " -buttons -out", Score::NEW_ANIMATION_ONLY);
     218        if(qmlRoot)
     219            qmlRoot->setProperty("show", QVariant(false));
    211220        // book-keeping:
    212221        this->currentMenuCode = MENU2;
     
    243252            this->score->queueMovie(this->currentInfo + " -out", Score::NEW_ANIMATION_ONLY);
    244253            this->score->queueMovie(this->currentInfo + " -buttons -out", Score::NEW_ANIMATION_ONLY);
     254            if(qmlRoot)
     255                qmlRoot->setProperty("show", QVariant(false));
    245256            // book-keeping:
    246257            this->currentMenuCode = MENU1;
     
    303314    // was started to activate assistant and bring it to front:
    304315    QTextStream str(&this->assistantProcess);
    305     str << "SetSource " << url << QLatin1Char('\0') << endl;
     316    str << "SetSource " << url << QLatin1Char('\n') << endl;
    306317}
    307318
     
    344355}
    345356
     357void 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
     391void MenuManager::quitQML()
     392{
     393    if(qmlRoot)
     394        qmlRoot->setProperty("show", QVariant(false));
     395}
     396
    346397void MenuManager::exampleFinished()
    347398{
     
    386437        level2MenuNode = level2MenuNode.nextSibling();
    387438    }
     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
    388472}
    389473
     
    393477    if (this->info.contains(name))
    394478        qWarning() << "__WARNING: MenuManager::readInfoAboutExample: Demo/example with name"
    395                     << name << "appears twize in the xml-file!__";
     479                    << name << "appears twice in the xml-file!__";
    396480
    397481    this->info[name]["filename"] = example.attribute("filename");
     
    400484    this->info[name]["changedirectory"] = example.attribute("changedirectory");
    401485    this->info[name]["image"] = example.attribute("image");
     486    this->info[name]["qml"] = example.attribute("qml");
    402487}
    403488
     
    434519    dir.cd(fileName);
    435520
     521    fileName = fileName.split("/").last();
    436522    QFile unixFile(dir.path() + "/" + fileName);
    437523    if (unixFile.exists()) return unixFile.fileName();
     
    457543
    458544    if (category == "demos")
    459         return this->helpRootUrl + "demos-" + fileName + ".html";
     545        return this->helpRootUrl + "demos-" + fileName.replace("/", "-") + ".html";
    460546    else
    461547        return this->helpRootUrl + dirName.replace("/", "-") + "-" + fileName + ".html";
     
    477563    QString category = this->info[name]["category"];
    478564    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();
    479568
    480569    if (imageName.isEmpty()){
     
    496585    QString name = el.attribute("name");
    497586    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");
    499588
    500589    Movie *menuButtonsIn = this->score->insertMovie(name + " -buttons");
     
    508597    QString name = el.attribute("name");
    509598    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");
    511600}
    512601
     
    514603{
    515604    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);
    517606
    518607    Movie *infoButtonsIn = this->score->insertMovie(name + " -buttons");
     
    521610    if (el.attribute("executable") != "false")
    522611        createLowRightLeafButton("Launch", 405, LAUNCH, infoButtonsIn, infoButtonsOut, 0);
     612    else if(el.attribute("qml") == "true")
     613        createLowRightLeafButton("Display", 405, LAUNCH_QML, infoButtonsIn, infoButtonsOut, 0);
    523614}
    524615
     
    549640            // create normal menu button
    550641            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);
    552643            currentNode = currentNode.nextSibling();
    553644
     
    649740    Movie *movieIn, Movie *movieOut, Movie *movieShake, const QString &menuString)
    650741{
    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);
    652743    if (!menuString.isNull())
    653744        button->setMenuString(menuString);
     
    691782void MenuManager::createLowRightButton(const QString &label, BUTTON_TYPE type, Movie *movieIn, Movie *movieOut, Movie * /*movieShake*/)
    692783{
    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);
    694785    item->setRecursiveVisible(false);
    695786    item->setZValue(10);
     
    718809void MenuManager::createLowRightLeafButton(const QString &label, int xOffset, BUTTON_TYPE type, Movie *movieIn, Movie *movieOut, Movie * /*movieShake*/)
    719810{
    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);
    721812    item->setRecursiveVisible(false);
    722813    item->setZValue(10);
     
    834925    float yOffset = 450.0f;
    835926
    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);
    837928    this->upButton->prepare();
    838929    this->upButton->setPos(xOffset, yOffset);
    839930    this->upButton->setState(TextButton::DISABLED);
    840931
    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);
    842933    this->downButton->prepare();
    843934    this->downButton->setPos(xOffset + 10 + this->downButton->sceneBoundingRect().width(), yOffset);
Note: See TracChangeset for help on using the changeset viewer.