examples/webkit/fancybrowser/mainwindow.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    60 
    60 
    61 //! [2]
    61 //! [2]
    62     view = new QWebView(this);
    62     view = new QWebView(this);
    63     view->load(QUrl("http://www.google.com/ncr"));
    63     view->load(QUrl("http://www.google.com/ncr"));
    64     connect(view, SIGNAL(loadFinished(bool)), SLOT(adjustLocation()));
    64     connect(view, SIGNAL(loadFinished(bool)), SLOT(adjustLocation()));
    65     connect(view, SIGNAL(titleChanged(const QString&)), SLOT(adjustTitle()));
    65     connect(view, SIGNAL(titleChanged(QString)), SLOT(adjustTitle()));
    66     connect(view, SIGNAL(loadProgress(int)), SLOT(setProgress(int)));
    66     connect(view, SIGNAL(loadProgress(int)), SLOT(setProgress(int)));
    67     connect(view, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool)));
    67     connect(view, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool)));
    68 
    68 
    69     locationEdit = new QLineEdit(this);
    69     locationEdit = new QLineEdit(this);
    70     locationEdit->setSizePolicy(QSizePolicy::Expanding, locationEdit->sizePolicy().verticalPolicy());
    70     locationEdit->setSizePolicy(QSizePolicy::Expanding, locationEdit->sizePolicy().verticalPolicy());
    80 
    80 
    81 //! [3]
    81 //! [3]
    82     QMenu *effectMenu = menuBar()->addMenu(tr("&Effect"));
    82     QMenu *effectMenu = menuBar()->addMenu(tr("&Effect"));
    83     effectMenu->addAction("Highlight all links", this, SLOT(highlightAllLinks()));
    83     effectMenu->addAction("Highlight all links", this, SLOT(highlightAllLinks()));
    84 
    84 
    85     QAction *rotateAction = new QAction(this);
    85     rotateAction = new QAction(this);
    86     rotateAction->setIcon(style()->standardIcon(QStyle::SP_FileDialogDetailedView));
    86     rotateAction->setIcon(style()->standardIcon(QStyle::SP_FileDialogDetailedView));
    87     rotateAction->setCheckable(true);
    87     rotateAction->setCheckable(true);
    88     rotateAction->setText(tr("Turn images upside down"));
    88     rotateAction->setText(tr("Turn images upside down"));
    89     connect(rotateAction, SIGNAL(toggled(bool)), this, SLOT(rotateImages(bool)));
    89     connect(rotateAction, SIGNAL(toggled(bool)), this, SLOT(rotateImages(bool)));
    90     effectMenu->addAction(rotateAction);
    90     effectMenu->addAction(rotateAction);
   134 void MainWindow::finishLoading(bool)
   134 void MainWindow::finishLoading(bool)
   135 {
   135 {
   136     progress = 100;
   136     progress = 100;
   137     adjustTitle();
   137     adjustTitle();
   138     view->page()->mainFrame()->evaluateJavaScript(jQuery);
   138     view->page()->mainFrame()->evaluateJavaScript(jQuery);
       
   139 
       
   140     rotateImages(rotateAction->isChecked());
   139 }
   141 }
   140 //! [6]
   142 //! [6]
   141 
   143 
   142 //! [7]
   144 //! [7]
   143 void MainWindow::highlightAllLinks()
   145 void MainWindow::highlightAllLinks()
   146     view->page()->mainFrame()->evaluateJavaScript(code);
   148     view->page()->mainFrame()->evaluateJavaScript(code);
   147 }
   149 }
   148 //! [7]
   150 //! [7]
   149 
   151 
   150 //! [8]
   152 //! [8]
   151 void MainWindow::rotateImages(bool toggle)
   153 void MainWindow::rotateImages(bool invert)
   152 {
   154 {
   153     QString code = "$('img').each( function () { $(this).css('-webkit-transition', '-webkit-transform 2s') } )";
   155     QString code;
   154     view->page()->mainFrame()->evaluateJavaScript(code);
   156     if (invert)
   155     if (toggle)
   157         code = "$('img').each( function () { $(this).css('-webkit-transition', '-webkit-transform 2s'); $(this).css('-webkit-transform', 'rotate(180deg)') } )";
   156         code = "$('img').each( function () { $(this).css('-webkit-transform', 'rotate(180deg)') } )";
       
   157     else
   158     else
   158         code = "$('img').each( function () { $(this).css('-webkit-transform', 'rotate(0deg)') } )";
   159         code = "$('img').each( function () { $(this).css('-webkit-transition', '-webkit-transform 2s'); $(this).css('-webkit-transform', 'rotate(0deg)') } )";
   159     view->page()->mainFrame()->evaluateJavaScript(code);
   160     view->page()->mainFrame()->evaluateJavaScript(code);
   160 }
   161 }
   161 //! [8]
   162 //! [8]
   162 
   163 
   163 //! [9]
   164 //! [9]