ginebra2/ChromeSnippet.h
changeset 3 0954f5dd2cd0
parent 0 1450b09d0cfd
child 16 3c88a81ff781
equal deleted inserted replaced
1:b0dd75e285d2 3:0954f5dd2cd0
     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
       
     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 *
     4 *
     9 * Initial Contributors:
     5 * This program is free software: you can redistribute it and/or modify
    10 * Nokia Corporation - initial contribution.
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
    11 *
     8 *
    12 * Contributors:
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    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_CHROMESNIPPET_H__
    22 #ifndef __GINEBRA_CHROMESNIPPET_H__
    20 #define __GINEBRA_CHROMESNIPPET_H__
    23 #define __GINEBRA_CHROMESNIPPET_H__
    21 
    24 
    22 #include <QString>
    25 #include <QString>
    23 #include <QObject>
    26 #include <QObject>
    24 #include <QTransform>
    27 #include <QTransform>
    25 #include <QWebElement>
    28 #include <QWebElement>
    26 #include "ChromeWidget.h"
    29 #include "ChromeWidget.h"
       
    30 #include "ChromeLayout.h"
    27 
    31 
    28 class QGraphicsWidget;
    32 class QGraphicsWidget;
    29 
    33 
    30 namespace GVA {
    34 namespace GVA {
    31 
    35 
    32   class VisibilityAnimator;
    36   class VisibilityAnimator;
    33 
    37 
    34   /*! \ingroup JavascriptAPI
    38   /*! \ingroup JavascriptAPI
       
    39    * \brief This class encapsulates an element of the browser's chrome.
       
    40    *
       
    41    * Example HTML declaration of a snippet.
       
    42    * \code
       
    43    *   <div class = "GinebraSnippet" id="StatusBarChromeId" name="statusbar" data-GinebraAnchor="AnchorTop" data-GinebraVisible="true">
       
    44    *     <link rel="stylesheet" id="CSSLink" type="text/css" href="statusbar.snippet/statusbar.css"/>
       
    45    *     <script type="text/javascript">
       
    46    *       new StatusBar();
       
    47    *     </script>
       
    48    *   </div>
       
    49    * \endcode
       
    50    * Example javascript code to toggle the visibility of the snippet defined ablove:
       
    51    * \code
       
    52    * snippets.StatusBarChromeId.toggleVisibility();
       
    53    * \endcode
    35    */
    54    */
    36   class ChromeSnippet : public QObject
    55   class ChromeSnippet : public QObject
    37   {
    56   {
    38     Q_OBJECT
    57     Q_OBJECT
    39   public:
    58   public:
    40     ChromeSnippet(const QString & elementId, ChromeWidget * chrome, QGraphicsWidget * widget, const QWebElement & element);
    59     ChromeSnippet(const QString & elementId, ChromeWidget * chrome, QGraphicsWidget * widget, const QWebElement & element);
    41     virtual ~ChromeSnippet();
    60     virtual ~ChromeSnippet();
    42     ChromeWidget* chrome() { return m_chrome; }
    61     ChromeWidget * chrome() { return m_chrome; }
    43     void setInitiallyVisible(bool initiallyVisible) { m_initiallyVisible = initiallyVisible; } //NB: needed?
    62     void setInitiallyVisible(bool initiallyVisible) { m_initiallyVisible = initiallyVisible; } //NB: needed?
    44     void setHidesContent(bool hidesContent) { m_hidesContent = hidesContent; }
    63     void setHidesContent(bool hidesContent) { m_hidesContent = hidesContent; }
    45     void setAnchor(ChromeAnchor anchor) {m_anchor = anchor;}
    64     void setAnchor(ChromeAnchor anchor) {m_anchor = anchor;}
    46     ChromeAnchor anchor() { return m_anchor; }
    65     ChromeAnchor anchor() { return m_anchor; }
    47     int anchorOffset() {return m_anchorOffset;}
    66     int anchorOffset() {return m_anchorOffset;}
    48     bool initiallyVisible() { return m_initiallyVisible; } //NB: needed?
    67     bool initiallyVisible() { return m_initiallyVisible; } //NB: needed?
    49     bool hidesContent() { return m_hidesContent; }
    68     bool hidesContent() { return m_hidesContent; }
    50     QString elementId() { return m_elementId; }
    69     QString elementId() { return m_elementId; }
    51     QGraphicsWidget* widget() { return m_widget; }
    70     QGraphicsWidget* widget() { return m_widget; }
    52     virtual void setWidget(QGraphicsWidget * widget) { m_widget = widget; }
    71     QGraphicsWidget const * constWidget() const { return m_widget; }
       
    72     virtual void setChromeWidget(QGraphicsWidget * widget);
    53     QString parentId() { return m_parentId; }
    73     QString parentId() { return m_parentId; }
    54     void setParentId(const QString& parent) { m_parentId = parent; }
    74     void setParentId(const QString& parent) { m_parentId = parent; }
    55     void setTransform(QTransform transform);
    75     void setTransform(QTransform transform);
    56     QTransform transform();
    76     QTransform transform();
    57     QPointF position() const;
    77     QPointF position() const;
    58     virtual void addChild(ChromeSnippet * child);
    78     virtual void addChild(ChromeSnippet * child);
    59     QWebElement element() {return m_element;}
    79     QWebElement element() {return m_element;}
    60     void dump();
    80     void dump();
    61     void addLink(ChromeSnippet*);
    81     void addLink(ChromeSnippet*);
    62     QList<ChromeSnippet *> links() {return m_links;}
    82     ChromeSnippet * linkedSnippet() {return m_link;}
    63   public slots:
    83   public slots:
    64     void setAnchor(const QString& anchor, bool update = true);
    84     void setAnchor(const QString& anchor, bool update = true);
    65     void setAnchorOffset(int offset, bool update = true);
    85     void setAnchorOffset(int offset, bool update = true);
    66     virtual void toggleVisibility(bool animate = true);
    86     virtual void toggleVisibility(bool animate = true);
    67     void setVisible(bool visiblity, bool animate = true);
    87     virtual void setVisible(bool visiblity, bool animate = true);
    68     void show(bool animate = true) { setVisible(true, animate);}
    88     void show(bool animate = true) { setVisible(true, animate);}
    69     virtual void hide(bool animate = true) { setVisible(false, animate);}
    89     virtual void hide(bool animate = true) { setVisible(false, animate);}
    70     void setOpacity(qreal opacity);
    90     void setOpacity(qreal opacity);
    71     qreal opacity();
    91     qreal opacity();
    72     void setEffect(const QString & effect);
    92     void setEffect(const QString & effect);
    73     void enableEffect(bool enable);
    93     void enableEffect(bool enable);
    74     void toggleEffect();
    94     void toggleEffect();
    75     void grabFocus();
    95     void grabFocus();
    76     void setVisibilityAnimator(const QString& animator);
    96     QObject *setVisibilityAnimator(const QString& animator);
    77     void visibilityFinished(bool visiblity);
    97     void visibilityFinished(bool visiblity);
    78     void moveBy(int dx, int dy);
    98     void moveBy(int dx, int dy);
    79     void anchorTo(const QString & id, int x = 0, int y = 0);
    99     void anchorTo(const QString & id, int x = 0, int y = 0);
    80     void unAnchor();
   100     void unAnchor();
    81     void anchorToView(const QString& view, const QString& where="top");
   101     void anchorToView(const QString& view, const QString& where="top");
    89     bool isHiding() { return m_hiding; }
   109     bool isHiding() { return m_hiding; }
    90     int zValue();
   110     int zValue();
    91     void setZValue(int z);
   111     void setZValue(int z);
    92     //NB: deprecate repaint: if this is needed, then there are bugs that are preventing updates
   112     //NB: deprecate repaint: if this is needed, then there are bugs that are preventing updates
    93     void repaint() { m_widget->update(); }
   113     void repaint() { m_widget->update(); }
    94     void onContextMenuEvent(QGraphicsSceneContextMenuEvent * ev); 
   114     void onContextMenuEvent(QGraphicsSceneContextMenuEvent * ev);
       
   115 
    95   signals:
   116   signals:
    96     void hidden();
   117     void hidden();
    97     void shown();
   118     void shown();
    98     void externalMouseEvent(
   119     void externalMouseEvent(
    99             int type,
   120             QEvent * ev,
   100             const QString & name,
   121             const QString & name,
   101             const QString & description);
   122             const QString & description);
   102     void contextMenuEvent(int x, int y);
   123     void contextMenuEvent(int x, int y);
   103     void snippetMouseEvent(QEvent::Type );
   124     void snippetMouseEvent(QEvent::Type );
   104 
   125 
   115     Q_PROPERTY(QString anchor READ getAnchorString)
   136     Q_PROPERTY(QString anchor READ getAnchorString)
   116     QString getAnchorString();
   137     QString getAnchorString();
   117     Q_PROPERTY(int anchorOffset READ anchorOffset WRITE setAnchorOffset)
   138     Q_PROPERTY(int anchorOffset READ anchorOffset WRITE setAnchorOffset)
   118     Q_PROPERTY(int zValue READ zValue WRITE setZValue)
   139     Q_PROPERTY(int zValue READ zValue WRITE setZValue)
   119     Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
   140     Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
   120     Q_PROPERTY(bool dontShow READ getDontShowFlag WRITE setDontShowFlag)
   141     Q_PROPERTY(QObject* position READ getPosition)
   121   protected:
   142     Q_PROPERTY(QObject* geometry READ getGeometry)
   122     bool getDontShowFlag() {return m_dontshowFlag;}
   143     Q_PROPERTY(bool enabled WRITE setEnabled READ enabled)
   123     void setDontShowFlag(bool flag){ m_dontshowFlag = flag;}
   144 
       
   145     bool enabled() const;
       
   146     void setEnabled(bool value);
   124   protected:
   147   protected:
   125     QString m_elementId;
   148     QString m_elementId;
   126     QWebElement m_element;
   149     QWebElement m_element;
   127     QString m_parentId;
   150     QString m_parentId;
   128     ChromeWidget * m_chrome;
   151     ChromeWidget * m_chrome;
   134     int m_anchorOffset;
   157     int m_anchorOffset;
   135     VisibilityAnimator * m_vAnimator;
   158     VisibilityAnimator * m_vAnimator;
   136     QGraphicsEffect * m_effect;
   159     QGraphicsEffect * m_effect;
   137     bool m_hiding;
   160     bool m_hiding;
   138     bool m_dontshowFlag;
   161     bool m_dontshowFlag;
   139     QList<ChromeSnippet*> m_links;
   162     bool m_enabled;
       
   163     ChromeSnippet* m_link;
   140   };
   164   };
   141 
   165 
   142 } // end of namespace GVA
   166 } // end of namespace GVA
   143 
   167 
   144 #endif // __GINEBRA_CHROMESNIPPET_H__
   168 #endif // __GINEBRA_CHROMESNIPPET_H__