ginebra2/ChromeWidget.h
changeset 0 1450b09d0cfd
child 3 0954f5dd2cd0
child 5 0f2326c2a325
equal deleted inserted replaced
-1:000000000000 0:1450b09d0cfd
       
     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 __GINEBRA_CHROMEWIDGET_H__
       
    20 #define __GINEBRA_CHROMEWIDGET_H__
       
    21 
       
    22 #include "BWFGlobal.h"
       
    23 #include <QMap>
       
    24 #include <QtGui>
       
    25 //#include <QtScript>
       
    26 #include "wrtbrowsercontainer.h"
       
    27 #include "GreenChromeSnippet.h"
       
    28 #include "ViewController.h"
       
    29 
       
    30 class QWebPage;
       
    31 class QPixmap;
       
    32 
       
    33 class MostVisitedPageStore;
       
    34 class ControllableViewBase;
       
    35 class QGraphicsSceneContextMenuEvent;
       
    36 using namespace WRT;
       
    37 
       
    38 namespace GVA {
       
    39 
       
    40   class AppContentView;
       
    41   class ChromeSnippet;
       
    42   class ChromeDOM;
       
    43   class ChromeRenderer;
       
    44   class GinebraApplication;
       
    45   class ViewController;
       
    46   class Snippets;
       
    47   //  class CollapsingWidget;
       
    48   class SlidingWidget;
       
    49   class ChromeWidgetJSObject;
       
    50   class LocaleDelegate;
       
    51   class DeviceDelegate;
       
    52   class Downloads;
       
    53 
       
    54   enum ChromeAnchor
       
    55   {
       
    56     anchorNone,
       
    57     anchorCenter,
       
    58     anchorTop,
       
    59     anchorBottom,
       
    60     anchorLeft,
       
    61     anchorRight,
       
    62     anchorTopLeft,
       
    63     anchorTopRight,
       
    64     anchorBottomLeft,
       
    65     anchorBottomRight
       
    66   };
       
    67   
       
    68   enum Aspect
       
    69   {
       
    70     portrait,
       
    71     landscape
       
    72   };
       
    73 
       
    74   class ChromeWidget : public QGraphicsWidget
       
    75   {
       
    76 
       
    77   Q_OBJECT
       
    78 
       
    79   public:
       
    80     ChromeWidget(QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0);
       
    81     virtual ~ChromeWidget();
       
    82     void setChromeBaseDirectory(const QString dir);
       
    83     void setChromeFile(const QString file);
       
    84     void addView(ControllableViewBase * controllableView);
       
    85     QGraphicsScene * getScene() { return m_scene; } //NB: change name to scene() !!
       
    86     ChromeRenderer * renderer() { return m_renderer; }
       
    87     ChromeDOM * dom() { return m_dom; }
       
    88     QRect getSnippetRect(const QString &docElementId);
       
    89     ChromeSnippet * getSnippet(const QString & docElementId, QGraphicsItem * parent = 0);
       
    90     //  QScriptValue evalWithEngineContext(const QString& program);
       
    91     ControllableViewBase * getView(const QString& name);
       
    92     void showView(const QString &name);
       
    93     QWebPage * page() { return m_page; }
       
    94     void anchorSnippet(ChromeSnippet * snippet);
       
    95     //NB: get rid of this (see comment in .cpp)!!!
       
    96     void adjustAnchorOffset(ChromeSnippet * snippet, qreal delta);
       
    97     void anchorToView(ChromeSnippet* snippet, const QString & where = "top");
       
    98     void detachFromView(ChromeSnippet* snippet, const QString & where = "top");
       
    99     void anchorTogether(ChromeSnippet* first, const QString &  secondId, qreal x = 0, qreal y = 0);
       
   100     void unAnchor(ChromeSnippet* first);
       
   101     //void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget* widget = 0);
       
   102     QGraphicsView *graphicsView() { return m_view; }
       
   103     void dump();
       
   104     QString getBaseDirectory() const { return m_baseDirectory; }
       
   105     ViewController * viewController() { return m_viewController; } // needed for UrlSearchSnippet
       
   106     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
       
   108     int width(){return (int)size().width();}
       
   109     void snippetShown(ChromeSnippet * snippet); 
       
   110     void snippetHiding(ChromeSnippet * snippet);
       
   111     void loadStarted();
       
   112     void loadFinished(bool ok);
       
   113     void exportJSObjects();
       
   114     void exportJSObjectsToPage(QWebPage *page);
       
   115     void alert(const QString & msg);
       
   116     qreal slideView(qreal delta);
       
   117     void onViewInstantiated(ControllableViewBase *view);
       
   118     void onCurrentViewChanged();
       
   119     void chromeInitialized();
       
   120     void reloadChrome();
       
   121     void loadUrlToCurrentPage(const QUrl & url);
       
   122     void pageCreated(WRT::WrtBrowserContainer * page);
       
   123     
       
   124   signals:
       
   125     void internalChromeComplete();
       
   126     void chromeComplete();
       
   127     void aspectChanged(int aspect);
       
   128     void prepareForGeometryChange();
       
   129     //NB: This should be symbian ifdef'd but that would require symbian-specific chrome
       
   130     void symbianCarriageReturn();
       
   131 
       
   132   public:
       
   133     Q_PROPERTY(QObjectList snippets READ getSnippets)
       
   134     QObjectList getSnippets();
       
   135     /// \brief Returns either "portrait" or "landscape".
       
   136     QString getDisplayMode() const;
       
   137     Q_PROPERTY(QString displayMode READ getDisplayMode)
       
   138 
       
   139     QObject* getDisplaySize() const;
       
   140     Q_PROPERTY(QObject* displaySize READ getDisplaySize)
       
   141 
       
   142   protected:
       
   143     virtual void resizeEvent(QGraphicsSceneResizeEvent *ev);
       
   144     virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent* event);
       
   145     //bool eventFilter(QObject *obj, QEvent *ev);
       
   146   private:
       
   147     void addSnippet( ChromeSnippet * snippet, const QString & docElementId);
       
   148     void getInitialSnippets();
       
   149     void clearChrome();
       
   150     void addAnchors();
       
   151     void addJSObjectToWindow(QObject *object);
       
   152     void addJSObjectToPage(QObject *object, QWebPage *page);
       
   153     void updateMVGeometry();
       
   154     void addViewToLayout(ControllableViewBase * controllableView);
       
   155     //void addJSObjectToEngine(QObject *object);
       
   156     QGraphicsScene * m_scene;
       
   157     QGraphicsView *m_view;
       
   158     QGraphicsAnchorLayout *m_layout;
       
   159     QString m_baseDirectory;
       
   160     QWebPage * m_page;
       
   161     ChromeRenderer * m_renderer;
       
   162     ChromeDOM * m_dom;
       
   163     Snippets * m_snippets;
       
   164     ViewController *m_viewController;
       
   165     AppContentView * m_appView;
       
   166     QList<QObject*> m_jsObjects;
       
   167     //QScriptEngine m_engine;
       
   168     QGraphicsAnchorLayout *m_viewLayout;
       
   169     SlidingWidget *m_viewPort;
       
   170     QGraphicsWidget *m_topBar;
       
   171     QGraphicsWidget *m_bottomBar;
       
   172     QGraphicsWidget *m_leftBar;
       
   173     QGraphicsWidget *m_rightBar;
       
   174     //CollapsingWidget *m_viewBar;
       
   175     GinebraApplication *m_app;
       
   176     Aspect m_aspect;
       
   177     ChromeWidgetJSObject *m_jsObject;
       
   178     LocaleDelegate *m_localeDelegate; // Owned
       
   179     DeviceDelegate *m_deviceDelegate;
       
   180     Downloads * m_downloads; // Owned
       
   181   };
       
   182 
       
   183 } // end of namespace GVA
       
   184 
       
   185 Q_DECLARE_METATYPE(QObjectList)
       
   186 
       
   187 #endif // __GINEBRA_CHROMEWIDGET_H__