ginebra2/ChromeWidget.h
changeset 5 0f2326c2a325
parent 0 1450b09d0cfd
child 6 1c3b8676e58c
equal deleted inserted replaced
1:b0dd75e285d2 5:0f2326c2a325
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 *
     5 * under the terms of "Eclipse Public License v1.0"
     5 * This program is free software: you can redistribute it and/or modify
     6 * which accompanies this distribution, and is available
     6 * it under the terms of the GNU Lesser General Public License as published by
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * the Free Software Foundation, version 2.1 of the License.
     8 *
     8 *
     9 * Initial Contributors:
     9 * This program is distributed in the hope that it will be useful,
    10 * Nokia Corporation - initial contribution.
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11 *
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12 * Contributors:
    12 * GNU Lesser General Public License for more details.
    13 *
    13 *
    14 * Description: 
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not,
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
    15 *
    19 *
    16 */
    20 */
    17 
       
    18 
    21 
    19 #ifndef __GINEBRA_CHROMEWIDGET_H__
    22 #ifndef __GINEBRA_CHROMEWIDGET_H__
    20 #define __GINEBRA_CHROMEWIDGET_H__
    23 #define __GINEBRA_CHROMEWIDGET_H__
    21 
    24 
    22 #include "BWFGlobal.h"
    25 #include "BWFGlobal.h"
    23 #include <QMap>
    26 #include <QMap>
    24 #include <QtGui>
    27 #include <QtGui>
    25 //#include <QtScript>
    28 //#include <QtScript>
    26 #include "wrtbrowsercontainer.h"
    29 #include "wrtbrowsercontainer.h"
    27 #include "GreenChromeSnippet.h"
       
    28 #include "ViewController.h"
    30 #include "ViewController.h"
    29 
    31 
    30 class QWebPage;
    32 class QWebPage;
    31 class QPixmap;
    33 class QPixmap;
    32 
    34 
    35 class QGraphicsSceneContextMenuEvent;
    37 class QGraphicsSceneContextMenuEvent;
    36 using namespace WRT;
    38 using namespace WRT;
    37 
    39 
    38 namespace GVA {
    40 namespace GVA {
    39 
    41 
    40   class AppContentView;
       
    41   class ChromeSnippet;
    42   class ChromeSnippet;
    42   class ChromeDOM;
    43   class ChromeDOM;
    43   class ChromeRenderer;
    44   class ChromeRenderer;
    44   class GinebraApplication;
    45   class GinebraApplication;
    45   class ViewController;
    46   class ViewController;
    47   //  class CollapsingWidget;
    48   //  class CollapsingWidget;
    48   class SlidingWidget;
    49   class SlidingWidget;
    49   class ChromeWidgetJSObject;
    50   class ChromeWidgetJSObject;
    50   class LocaleDelegate;
    51   class LocaleDelegate;
    51   class DeviceDelegate;
    52   class DeviceDelegate;
       
    53   class NetworkDelegate;
    52   class Downloads;
    54   class Downloads;
    53 
    55 
    54   enum ChromeAnchor
    56   enum ChromeAnchor
    55   {
    57   {
    56     anchorNone,
    58     anchorNone,
    62     anchorTopLeft,
    64     anchorTopLeft,
    63     anchorTopRight,
    65     anchorTopRight,
    64     anchorBottomLeft,
    66     anchorBottomLeft,
    65     anchorBottomRight
    67     anchorBottomRight
    66   };
    68   };
    67   
    69 
    68   enum Aspect
    70   enum Aspect
    69   {
    71   {
    70     portrait,
    72     portrait,
    71     landscape
    73     landscape
    72   };
    74   };
    73 
    75 
       
    76   /*!
       
    77    * \brief This class is responsible for maintaining the browser chrome and
       
    78    * most of the other major components of the application.
       
    79    *
       
    80    */
    74   class ChromeWidget : public QGraphicsWidget
    81   class ChromeWidget : public QGraphicsWidget
    75   {
    82   {
    76 
    83 
    77   Q_OBJECT
    84   Q_OBJECT
    78 
    85 
    81     virtual ~ChromeWidget();
    88     virtual ~ChromeWidget();
    82     void setChromeBaseDirectory(const QString dir);
    89     void setChromeBaseDirectory(const QString dir);
    83     void setChromeFile(const QString file);
    90     void setChromeFile(const QString file);
    84     void addView(ControllableViewBase * controllableView);
    91     void addView(ControllableViewBase * controllableView);
    85     QGraphicsScene * getScene() { return m_scene; } //NB: change name to scene() !!
    92     QGraphicsScene * getScene() { return m_scene; } //NB: change name to scene() !!
       
    93     void setScene(QGraphicsScene *scene);
    86     ChromeRenderer * renderer() { return m_renderer; }
    94     ChromeRenderer * renderer() { return m_renderer; }
    87     ChromeDOM * dom() { return m_dom; }
    95     ChromeDOM * dom() { return m_dom; }
    88     QRect getSnippetRect(const QString &docElementId);
    96     QRect getSnippetRect(const QString &docElementId);
    89     ChromeSnippet * getSnippet(const QString & docElementId, QGraphicsItem * parent = 0);
    97     ChromeSnippet * getSnippet(const QString & docElementId, QGraphicsItem * parent = 0);
    90     //  QScriptValue evalWithEngineContext(const QString& program);
    98     //  QScriptValue evalWithEngineContext(const QString& program);
   102     QGraphicsView *graphicsView() { return m_view; }
   110     QGraphicsView *graphicsView() { return m_view; }
   103     void dump();
   111     void dump();
   104     QString getBaseDirectory() const { return m_baseDirectory; }
   112     QString getBaseDirectory() const { return m_baseDirectory; }
   105     ViewController * viewController() { return m_viewController; } // needed for UrlSearchSnippet
   113     ViewController * viewController() { return m_viewController; } // needed for UrlSearchSnippet
   106     QString currentView() {return m_viewController->currentView()->type() ;}
   114     QString currentView() {return m_viewController->currentView()->type() ;}
   107   public slots: //NB: Many of these should not be exported to JS, so a separate a JS delegate would be better
   115     int bottomBarHeight() { return m_bottomBarHeight;}
       
   116     void updateChromeLayout();
       
   117     void sizeChange(QSize sz){ emit prepareForSizeChange(sz) ;}
       
   118     void emitPopupShown(const QString &popupId);
       
   119     void emitPopupHidden(const QString &popupId);
       
   120 
       
   121   public slots:
   108     int width(){return (int)size().width();}
   122     int width(){return (int)size().width();}
   109     void snippetShown(ChromeSnippet * snippet); 
   123     void snippetShown(ChromeSnippet * snippet);
   110     void snippetHiding(ChromeSnippet * snippet);
   124     void snippetHiding(ChromeSnippet * snippet);
   111     void loadStarted();
   125     void loadStarted();
   112     void loadFinished(bool ok);
   126     void loadFinished(bool ok);
   113     void exportJSObjects();
   127     void exportJSObjects();
   114     void exportJSObjectsToPage(QWebPage *page);
   128     void exportJSObjectsToPage(QWebPage *page);
   115     void alert(const QString & msg);
   129     void alert(const QString & msg);
   116     qreal slideView(qreal delta);
   130     qreal slideView(qreal delta);
       
   131     qreal shrinkView(qreal delta);
   117     void onViewInstantiated(ControllableViewBase *view);
   132     void onViewInstantiated(ControllableViewBase *view);
   118     void onCurrentViewChanged();
   133     void onCurrentViewChanged();
   119     void chromeInitialized();
   134     void chromeInitialized();
   120     void reloadChrome();
   135     void reloadChrome();
   121     void loadUrlToCurrentPage(const QUrl & url);
   136     void loadUrlToCurrentPage(const QUrl & url);
   122     void pageCreated(WRT::WrtBrowserContainer * page);
   137     void pageCreated(WRT::WrtBrowserContainer * page);
   123     
   138 
   124   signals:
   139   signals:
   125     void internalChromeComplete();
   140     void internalChromeComplete();
   126     void chromeComplete();
   141     void chromeComplete();
   127     void aspectChanged(int aspect);
   142     void aspectChanged(int aspect);
   128     void prepareForGeometryChange();
   143     void prepareForGeometryChange();
       
   144     void prepareForSizeChange(QSize);
   129     //NB: This should be symbian ifdef'd but that would require symbian-specific chrome
   145     //NB: This should be symbian ifdef'd but that would require symbian-specific chrome
   130     void symbianCarriageReturn();
   146     void symbianCarriageReturn();
       
   147     void popupShown(const QString &id);
       
   148     void popupHidden(const QString &id);
   131 
   149 
   132   public:
   150   public:
   133     Q_PROPERTY(QObjectList snippets READ getSnippets)
   151     Q_PROPERTY(QObjectList snippets READ getSnippets)
   134     QObjectList getSnippets();
   152     QObjectList getSnippets();
   135     /// \brief Returns either "portrait" or "landscape".
   153     /// \brief Returns either "portrait" or "landscape".
   150     void addAnchors();
   168     void addAnchors();
   151     void addJSObjectToWindow(QObject *object);
   169     void addJSObjectToWindow(QObject *object);
   152     void addJSObjectToPage(QObject *object, QWebPage *page);
   170     void addJSObjectToPage(QObject *object, QWebPage *page);
   153     void updateMVGeometry();
   171     void updateMVGeometry();
   154     void addViewToLayout(ControllableViewBase * controllableView);
   172     void addViewToLayout(ControllableViewBase * controllableView);
       
   173 
   155     //void addJSObjectToEngine(QObject *object);
   174     //void addJSObjectToEngine(QObject *object);
   156     QGraphicsScene * m_scene;
   175     QGraphicsScene * m_scene;
   157     QGraphicsView *m_view;
   176     QGraphicsView *m_view;
   158     QGraphicsAnchorLayout *m_layout;
   177     QGraphicsAnchorLayout *m_layout;
   159     QString m_baseDirectory;
   178     QString m_baseDirectory;
   160     QWebPage * m_page;
   179     QWebPage * m_page;
   161     ChromeRenderer * m_renderer;
   180     ChromeRenderer * m_renderer;
   162     ChromeDOM * m_dom;
   181     ChromeDOM * m_dom;
   163     Snippets * m_snippets;
   182     Snippets * m_snippets;
   164     ViewController *m_viewController;
   183     ViewController *m_viewController;
   165     AppContentView * m_appView;
   184     //QList<QObject*> m_jsObjects;
   166     QList<QObject*> m_jsObjects;
       
   167     //QScriptEngine m_engine;
   185     //QScriptEngine m_engine;
   168     QGraphicsAnchorLayout *m_viewLayout;
   186     QGraphicsAnchorLayout *m_viewLayout;
   169     SlidingWidget *m_viewPort;
   187     SlidingWidget *m_viewPort;
   170     QGraphicsWidget *m_topBar;
   188     QGraphicsWidget *m_topBar;
   171     QGraphicsWidget *m_bottomBar;
   189     QGraphicsWidget *m_bottomBar;
   175     GinebraApplication *m_app;
   193     GinebraApplication *m_app;
   176     Aspect m_aspect;
   194     Aspect m_aspect;
   177     ChromeWidgetJSObject *m_jsObject;
   195     ChromeWidgetJSObject *m_jsObject;
   178     LocaleDelegate *m_localeDelegate; // Owned
   196     LocaleDelegate *m_localeDelegate; // Owned
   179     DeviceDelegate *m_deviceDelegate;
   197     DeviceDelegate *m_deviceDelegate;
       
   198     NetworkDelegate *m_networkDelegate;
   180     Downloads * m_downloads; // Owned
   199     Downloads * m_downloads; // Owned
       
   200     int m_bottomBarHeight;
   181   };
   201   };
   182 
   202 
   183 } // end of namespace GVA
   203 } // end of namespace GVA
   184 
   204 
   185 Q_DECLARE_METATYPE(QObjectList)
   205 Q_DECLARE_METATYPE(QObjectList)