ginebra/emulator/chromewindow.cpp
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 2 bf4420e9fa4d
parent 6 1c3b8676e58c
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef Q_OS_SYMBIAN
       
    20 #include <QtGui>
       
    21 #include <QNetworkReply>
       
    22 #include <QNetworkAccessManager>
       
    23 #include <qwebpage.h>
       
    24 #include <qwebframe.h>
       
    25 #include <qwebview.h>
       
    26 #include <assert.h>
       
    27 #include <QtNetwork>
       
    28 #include "chromewindow.h"
       
    29 #include "../chromewidget.h"
       
    30 #include "../chromejsobject.h"
       
    31 #include "../chromeview.h"
       
    32 #include "webcontentview.h"
       
    33 #include "../utilities.h"
       
    34 #include "chromeconsole.h"
       
    35 
       
    36 ChromeWindow::ChromeWindow(const QString chromePath)
       
    37 {
       
    38 	init(chromePath);
       
    39 }
       
    40 
       
    41 ChromeWindow::ChromeWindow()
       
    42 {
       
    43 	init(ChromeView::getChromePath());
       
    44 }
       
    45 
       
    46 void ChromeWindow::init(const QString chromePath)
       
    47 {
       
    48   m_view = new ChromeView(chromePath, this);
       
    49 
       
    50   WebContentView *webView = static_cast<WebContentView *>(m_view->contentView(WebContentView::Type()));
       
    51 
       
    52   setCentralWidget(m_view);
       
    53 
       
    54   initActions();
       
    55   initToolbars();
       
    56   initMenus();
       
    57 
       
    58   resize(360,740);
       
    59 }
       
    60 
       
    61 ChromeWindow::~ChromeWindow(){
       
    62   delete m_view;
       
    63   delete m_portraitAction;
       
    64   delete m_landscapeAction;
       
    65   delete m_networkProxyAction;
       
    66   delete m_setToBedrockChromeAction;
       
    67   delete m_setToDemoChromeAction;
       
    68   delete m_consoleAction;
       
    69 }
       
    70 
       
    71 void ChromeWindow::initActions(){
       
    72   m_reloadAction = new QAction(QIcon("images/reload.png"), tr("&Reload Chrome"), 0);
       
    73   safe_connect(m_reloadAction, SIGNAL(triggered()), m_view, SLOT(reloadChrome()));
       
    74 
       
    75   m_networkProxyAction = new QAction(QIcon("images/net_proxy.png"), tr("&Use Network Proxy"), 0);
       
    76   safe_connect(m_networkProxyAction, SIGNAL(triggered()), this, SLOT(toggleProxy()));
       
    77   m_networkProxyAction->setCheckable(true);
       
    78 
       
    79 
       
    80   m_setToDemoChromeAction = new QAction(tr("&Set Demo Chrome"), 0);
       
    81   m_setToDemoChromeAction->setData(QVariant(QString("chrome/demochrome/chrome.html")));
       
    82   safe_connect(m_setToDemoChromeAction, SIGNAL(triggered()), this, SLOT(setChrome()));
       
    83 
       
    84   m_setToBedrockChromeAction = new QAction(tr("&Set Bedrock Chrome"), 0);
       
    85   m_setToBedrockChromeAction->setData(QVariant(QString("chrome/bedrockchrome/chrome.html")));
       
    86   safe_connect(m_setToBedrockChromeAction, SIGNAL(triggered()), this, SLOT(setChrome()));
       
    87 
       
    88   WebContentView *webView = static_cast<WebContentView *>(m_view->contentView(WebContentView::Type()));
       
    89 
       
    90   // Display orientation actions.
       
    91   QActionGroup *orientGroup = new QActionGroup(this);
       
    92   m_portraitAction = new QAction(QIcon("images/orient_north.png"), tr("&North"), 0);
       
    93   orientGroup->addAction(m_portraitAction);
       
    94   safe_connect(m_portraitAction, SIGNAL(triggered()), this, SLOT(portrait()));
       
    95   m_portraitAction->setCheckable(true);
       
    96   m_portraitAction->setChecked(true);
       
    97 
       
    98   m_landscapeAction = new QAction(QIcon("images/orient_east.png"), tr("&East"), 0);
       
    99   orientGroup->addAction(m_landscapeAction);
       
   100   safe_connect(m_landscapeAction, SIGNAL(triggered()), this, SLOT(landscape()));
       
   101   m_landscapeAction->setCheckable(true);
       
   102 
       
   103   /*
       
   104   m_orientSouthAction = new QAction(QIcon("images/orient_south.png"), tr("&South"), 0);
       
   105   orientGroup->addAction(m_orientSouthAction);
       
   106   safe_connect(m_orientSouthAction, SIGNAL(triggered()), m_view, SLOT(orientSouth()));
       
   107   m_orientSouthAction->setCheckable(true);
       
   108 
       
   109   m_orientWestAction = new QAction(QIcon("images/orient_west.png"), tr("&West"), 0);
       
   110   orientGroup->addAction(m_orientWestAction);
       
   111   safe_connect(m_orientWestAction, SIGNAL(triggered()), m_view, SLOT(orientWest()));
       
   112   m_orientWestAction->setCheckable(true);
       
   113   */
       
   114   m_consoleAction = new QAction(QIcon("images/console.png"), tr("&Console"), 0);
       
   115   orientGroup->addAction(m_consoleAction);
       
   116   safe_connect(m_consoleAction, SIGNAL(triggered()), this, SLOT(openConsole()));
       
   117 }
       
   118 
       
   119 void ChromeWindow::initMenus(){
       
   120   // File menu.
       
   121   QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
       
   122 
       
   123   fileMenu->addAction(m_reloadAction);
       
   124   fileMenu->addAction(m_networkProxyAction);
       
   125 
       
   126   // View menu.
       
   127   QMenu *viewMenu = menuBar()->addMenu(tr("&View"));
       
   128   viewMenu->addAction(m_portraitAction);
       
   129   viewMenu->addAction(m_landscapeAction);
       
   130   //viewMenu->addAction(m_orientSouthAction);
       
   131   //viewMenu->addAction(m_orientWestAction);
       
   132   viewMenu->addSeparator();
       
   133   viewMenu->addAction(m_consoleAction);
       
   134 
       
   135   // Chrome menu
       
   136   QMenu *chromeMenu = menuBar()->addMenu(tr("&Chrome"));
       
   137   chromeMenu->addAction(m_setToDemoChromeAction);
       
   138   chromeMenu->addAction(m_setToBedrockChromeAction);
       
   139 }
       
   140 
       
   141 void ChromeWindow::initToolbars(){
       
   142   QToolBar *toolBar = addToolBar("File");
       
   143   toolBar->setIconSize(QSize(16, 16));
       
   144   toolBar->addAction(m_reloadAction);
       
   145   toolBar->addSeparator();
       
   146   toolBar->addAction(m_portraitAction);
       
   147   toolBar->addAction(m_landscapeAction);
       
   148   //toolBar->addAction(m_orientSouthAction);
       
   149   //toolBar->addAction(m_orientWestAction);
       
   150   toolBar->addSeparator();
       
   151   toolBar->addAction(m_consoleAction);
       
   152 }
       
   153 
       
   154 void ChromeWindow::portrait(){
       
   155   resize(360,720);
       
   156 }
       
   157 
       
   158 void ChromeWindow::landscape(){
       
   159   resize(720,360);
       
   160 }
       
   161 void ChromeWindow::toggleProxy() {  // slot
       
   162   WebContentView *webView = static_cast<WebContentView *>(m_view->contentView(WebContentView::Type()));
       
   163 }
       
   164 
       
   165 void ChromeWindow::setChrome()
       
   166 {
       
   167     if(m_view) {
       
   168         QAction *action = qobject_cast<QAction *>(sender());
       
   169         QString chromePath = action->data().value<QString>();
       
   170         qDebug() << "Setting Chrome: " << chromePath;
       
   171         m_view->setChromeUrl(chromePath);
       
   172         m_view->reloadChrome();
       
   173     }
       
   174 }
       
   175 
       
   176 void ChromeWindow::openConsole() {  // slot
       
   177   ChromeConsole *console = new ChromeConsole(m_view);
       
   178   console->show();
       
   179 }
       
   180 #endif