ginebra2/ChromeWidget.h
changeset 6 1c3b8676e58c
parent 5 0f2326c2a325
child 10 232fbd5a2dcb
equal deleted inserted replaced
5:0f2326c2a325 6:1c3b8676e58c
    32 class QWebPage;
    32 class QWebPage;
    33 class QPixmap;
    33 class QPixmap;
    34 
    34 
    35 class MostVisitedPageStore;
    35 class MostVisitedPageStore;
    36 class ControllableViewBase;
    36 class ControllableViewBase;
    37 class QGraphicsSceneContextMenuEvent;
    37 
    38 using namespace WRT;
    38 using namespace WRT;
    39 
    39 
    40 namespace GVA {
    40 namespace GVA {
    41 
    41 
    42   class ChromeSnippet;
    42   class ChromeSnippet;
       
    43   class ChromeLayout;
    43   class ChromeDOM;
    44   class ChromeDOM;
    44   class ChromeRenderer;
    45   class ChromeRenderer;
    45   class GinebraApplication;
    46   class GinebraApplication;
    46   class ViewController;
    47   class ViewController;
    47   class Snippets;
    48   class Snippets;
    51   class LocaleDelegate;
    52   class LocaleDelegate;
    52   class DeviceDelegate;
    53   class DeviceDelegate;
    53   class NetworkDelegate;
    54   class NetworkDelegate;
    54   class Downloads;
    55   class Downloads;
    55 
    56 
    56   enum ChromeAnchor
       
    57   {
       
    58     anchorNone,
       
    59     anchorCenter,
       
    60     anchorTop,
       
    61     anchorBottom,
       
    62     anchorLeft,
       
    63     anchorRight,
       
    64     anchorTopLeft,
       
    65     anchorTopRight,
       
    66     anchorBottomLeft,
       
    67     anchorBottomRight
       
    68   };
       
    69 
       
    70   enum Aspect
       
    71   {
       
    72     portrait,
       
    73     landscape
       
    74   };
       
    75 
       
    76   /*!
    57   /*!
    77    * \brief This class is responsible for maintaining the browser chrome and
    58    * \brief This class is responsible for maintaining the browser chrome and
    78    * most of the other major components of the application.
    59    * most of the other major components of the application.
    79    *
       
    80    */
    60    */
    81   class ChromeWidget : public QGraphicsWidget
    61   class ChromeWidget : public QObject
    82   {
    62   {
    83 
    63 
    84   Q_OBJECT
    64   Q_OBJECT
    85 
    65 
    86   public:
    66   public:
    87     ChromeWidget(QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0);
    67     ChromeWidget(QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0);
    88     virtual ~ChromeWidget();
    68     virtual ~ChromeWidget();
    89     void setChromeBaseDirectory(const QString dir);
    69     void setChromeBaseDirectory(const QString dir);
    90     void setChromeFile(const QString file);
    70     void setChromeFile(const QString file);
    91     void addView(ControllableViewBase * controllableView);
    71     void addView(ControllableViewBase * controllableView);
    92     QGraphicsScene * getScene() { return m_scene; } //NB: change name to scene() !!
    72 
    93     void setScene(QGraphicsScene *scene);
    73     void addViewToLayout(ControllableViewBase * controllableView);
       
    74     ChromeLayout * layout() { return m_layout; }
       
    75     void setLayout(ChromeLayout * layout) { m_layout = layout; }
    94     ChromeRenderer * renderer() { return m_renderer; }
    76     ChromeRenderer * renderer() { return m_renderer; }
    95     ChromeDOM * dom() { return m_dom; }
    77     ChromeDOM * dom() { return m_dom; }
    96     QRect getSnippetRect(const QString &docElementId);
    78     QRect getSnippetRect(const QString &docElementId);
    97     ChromeSnippet * getSnippet(const QString & docElementId, QGraphicsItem * parent = 0);
    79     ChromeSnippet * getSnippet(const QString & docElementId, QGraphicsItem * parent = 0);
    98     //  QScriptValue evalWithEngineContext(const QString& program);
    80     //  QScriptValue evalWithEngineContext(const QString& program);
    99     ControllableViewBase * getView(const QString& name);
    81     ControllableViewBase * getView(const QString& name);
   100     void showView(const QString &name);
    82     void showView(const QString &name);
   101     QWebPage * page() { return m_page; }
    83     QWebPage * page() { return m_page; }
   102     void anchorSnippet(ChromeSnippet * snippet);
       
   103     //NB: get rid of this (see comment in .cpp)!!!
    84     //NB: get rid of this (see comment in .cpp)!!!
   104     void adjustAnchorOffset(ChromeSnippet * snippet, qreal delta);
    85     void adjustAnchorOffset(ChromeSnippet * snippet, qreal delta);
   105     void anchorToView(ChromeSnippet* snippet, const QString & where = "top");
       
   106     void detachFromView(ChromeSnippet* snippet, const QString & where = "top");
       
   107     void anchorTogether(ChromeSnippet* first, const QString &  secondId, qreal x = 0, qreal y = 0);
    86     void anchorTogether(ChromeSnippet* first, const QString &  secondId, qreal x = 0, qreal y = 0);
   108     void unAnchor(ChromeSnippet* first);
       
   109     //void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget* widget = 0);
       
   110     QGraphicsView *graphicsView() { return m_view; }
    87     QGraphicsView *graphicsView() { return m_view; }
   111     void dump();
    88     void dump();
   112     QString getBaseDirectory() const { return m_baseDirectory; }
    89     QString getBaseDirectory() const { return m_baseDirectory; }
   113     ViewController * viewController() { return m_viewController; } // needed for UrlSearchSnippet
    90     ViewController * viewController() { return m_viewController; } // needed for UrlSearchSnippet
   114     QString currentView() {return m_viewController->currentView()->type() ;}
    91     QString currentView() {return m_viewController->currentView()->type() ;}
   115     int bottomBarHeight() { return m_bottomBarHeight;}
       
   116     void updateChromeLayout();
    92     void updateChromeLayout();
   117     void sizeChange(QSize sz){ emit prepareForSizeChange(sz) ;}
    93     void sizeChange(QSize sz){ emit prepareForSizeChange(sz) ;}
   118     void emitPopupShown(const QString &popupId);
    94     void emitPopupShown(const QString &popupId);
   119     void emitPopupHidden(const QString &popupId);
    95     void emitPopupHidden(const QString &popupId);
   120 
    96 
   121   public slots:
    97   public slots:
   122     int width(){return (int)size().width();}
       
   123     void snippetShown(ChromeSnippet * snippet);
       
   124     void snippetHiding(ChromeSnippet * snippet);
       
   125     void loadStarted();
    98     void loadStarted();
   126     void loadFinished(bool ok);
    99     void loadFinished(bool ok);
   127     void exportJSObjects();
   100     void exportJSObjects();
   128     void exportJSObjectsToPage(QWebPage *page);
   101     void exportJSObjectsToPage(QWebPage *page);
   129     void alert(const QString & msg);
   102     void alert(const QString & msg);
   130     qreal slideView(qreal delta);
       
   131     qreal shrinkView(qreal delta);
       
   132     void onViewInstantiated(ControllableViewBase *view);
   103     void onViewInstantiated(ControllableViewBase *view);
   133     void onCurrentViewChanged();
   104     void onCurrentViewChanged();
   134     void chromeInitialized();
   105     void chromeInitialized();
   135     void reloadChrome();
   106     void reloadChrome();
   136     void loadUrlToCurrentPage(const QUrl & url);
   107     void loadUrlToCurrentPage(const QUrl & url);
   137     void pageCreated(WRT::WrtBrowserContainer * page);
   108     void pageCreated(WRT::WrtBrowserContainer * page);
       
   109     void onResize(QSizeF size);
       
   110     void onAspectChanged(int aspect);
   138 
   111 
   139   signals:
   112   signals:
   140     void internalChromeComplete();
   113     void internalChromeComplete();
   141     void chromeComplete();
   114     void chromeComplete();
   142     void aspectChanged(int aspect);
   115     void aspectChanged(int aspect);
   148     void popupHidden(const QString &id);
   121     void popupHidden(const QString &id);
   149 
   122 
   150   public:
   123   public:
   151     Q_PROPERTY(QObjectList snippets READ getSnippets)
   124     Q_PROPERTY(QObjectList snippets READ getSnippets)
   152     QObjectList getSnippets();
   125     QObjectList getSnippets();
   153     /// \brief Returns either "portrait" or "landscape".
       
   154     QString getDisplayMode() const;
       
   155     Q_PROPERTY(QString displayMode READ getDisplayMode)
       
   156 
   126 
   157     QObject* getDisplaySize() const;
   127     QObject* getDisplaySize() const;
   158     Q_PROPERTY(QObject* displaySize READ getDisplaySize)
   128     Q_PROPERTY(QObject* displaySize READ getDisplaySize)
   159 
   129 
   160   protected:
       
   161     virtual void resizeEvent(QGraphicsSceneResizeEvent *ev);
       
   162     virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent* event);
       
   163     //bool eventFilter(QObject *obj, QEvent *ev);
       
   164   private:
   130   private:
   165     void addSnippet( ChromeSnippet * snippet, const QString & docElementId);
   131     void addSnippet( ChromeSnippet * snippet, const QString & docElementId);
   166     void getInitialSnippets();
   132     void getInitialSnippets();
   167     void clearChrome();
   133     void clearChrome();
   168     void addAnchors();
       
   169     void addJSObjectToWindow(QObject *object);
   134     void addJSObjectToWindow(QObject *object);
   170     void addJSObjectToPage(QObject *object, QWebPage *page);
   135     void addJSObjectToPage(QObject *object, QWebPage *page);
   171     void updateMVGeometry();
   136     void updateMVGeometry();
   172     void addViewToLayout(ControllableViewBase * controllableView);
       
   173 
       
   174     //void addJSObjectToEngine(QObject *object);
   137     //void addJSObjectToEngine(QObject *object);
   175     QGraphicsScene * m_scene;
   138     ChromeLayout * m_layout;
   176     QGraphicsView *m_view;
   139     QGraphicsView *m_view; //TBD: not used?
   177     QGraphicsAnchorLayout *m_layout;
       
   178     QString m_baseDirectory;
   140     QString m_baseDirectory;
   179     QWebPage * m_page;
   141     QWebPage * m_page;
   180     ChromeRenderer * m_renderer;
   142     ChromeRenderer * m_renderer;
   181     ChromeDOM * m_dom;
   143     ChromeDOM * m_dom;
   182     Snippets * m_snippets;
   144     Snippets * m_snippets;
   183     ViewController *m_viewController;
   145     ViewController *m_viewController;
   184     //QList<QObject*> m_jsObjects;
   146     //QList<QObject*> m_jsObjects;
   185     //QScriptEngine m_engine;
   147     //QScriptEngine m_engine;
   186     QGraphicsAnchorLayout *m_viewLayout;
       
   187     SlidingWidget *m_viewPort;
       
   188     QGraphicsWidget *m_topBar;
       
   189     QGraphicsWidget *m_bottomBar;
       
   190     QGraphicsWidget *m_leftBar;
       
   191     QGraphicsWidget *m_rightBar;
       
   192     //CollapsingWidget *m_viewBar;
       
   193     GinebraApplication *m_app;
   148     GinebraApplication *m_app;
   194     Aspect m_aspect;
       
   195     ChromeWidgetJSObject *m_jsObject;
   149     ChromeWidgetJSObject *m_jsObject;
   196     LocaleDelegate *m_localeDelegate; // Owned
   150     LocaleDelegate *m_localeDelegate; // Owned
   197     DeviceDelegate *m_deviceDelegate;
   151     DeviceDelegate *m_deviceDelegate;
   198     NetworkDelegate *m_networkDelegate;
   152     NetworkDelegate *m_networkDelegate;
   199     Downloads * m_downloads; // Owned
   153     Downloads * m_downloads; // Owned
   200     int m_bottomBarHeight;
       
   201   };
   154   };
   202 
   155 
   203 } // end of namespace GVA
   156 } // end of namespace GVA
   204 
   157 
   205 Q_DECLARE_METATYPE(QObjectList)
   158 Q_DECLARE_METATYPE(QObjectList)