ginebra2/ChromeSnippet.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_CHROMESNIPPET_H__
       
    20 #define __GINEBRA_CHROMESNIPPET_H__
       
    21 
       
    22 #include <QString>
       
    23 #include <QObject>
       
    24 #include <QTransform>
       
    25 #include <QWebElement>
       
    26 #include "ChromeWidget.h"
       
    27 
       
    28 class QGraphicsWidget;
       
    29 
       
    30 namespace GVA {
       
    31 
       
    32   class VisibilityAnimator;
       
    33 
       
    34   /*! \ingroup JavascriptAPI
       
    35    */
       
    36   class ChromeSnippet : public QObject
       
    37   {
       
    38     Q_OBJECT
       
    39   public:
       
    40     ChromeSnippet(const QString & elementId, ChromeWidget * chrome, QGraphicsWidget * widget, const QWebElement & element);
       
    41     virtual ~ChromeSnippet();
       
    42     ChromeWidget* chrome() { return m_chrome; }
       
    43     void setInitiallyVisible(bool initiallyVisible) { m_initiallyVisible = initiallyVisible; } //NB: needed?
       
    44     void setHidesContent(bool hidesContent) { m_hidesContent = hidesContent; }
       
    45     void setAnchor(ChromeAnchor anchor) {m_anchor = anchor;}
       
    46     ChromeAnchor anchor() { return m_anchor; }
       
    47     int anchorOffset() {return m_anchorOffset;}
       
    48     bool initiallyVisible() { return m_initiallyVisible; } //NB: needed?
       
    49     bool hidesContent() { return m_hidesContent; }
       
    50     QString elementId() { return m_elementId; }
       
    51     QGraphicsWidget* widget() { return m_widget; }
       
    52     virtual void setWidget(QGraphicsWidget * widget) { m_widget = widget; }
       
    53     QString parentId() { return m_parentId; }
       
    54     void setParentId(const QString& parent) { m_parentId = parent; }
       
    55     void setTransform(QTransform transform);
       
    56     QTransform transform();
       
    57     QPointF position() const;
       
    58     virtual void addChild(ChromeSnippet * child);
       
    59     QWebElement element() {return m_element;}
       
    60     void dump();
       
    61     void addLink(ChromeSnippet*);
       
    62     QList<ChromeSnippet *> links() {return m_links;}
       
    63   public slots:
       
    64     void setAnchor(const QString& anchor, bool update = true);
       
    65     void setAnchorOffset(int offset, bool update = true);
       
    66     virtual void toggleVisibility(bool animate = true);
       
    67     void setVisible(bool visiblity, bool animate = true);
       
    68     void show(bool animate = true) { setVisible(true, animate);}
       
    69     virtual void hide(bool animate = true) { setVisible(false, animate);}
       
    70     void setOpacity(qreal opacity);
       
    71     qreal opacity();
       
    72     void setEffect(const QString & effect);
       
    73     void enableEffect(bool enable);
       
    74     void toggleEffect();
       
    75     void grabFocus();
       
    76     void setVisibilityAnimator(const QString& animator);
       
    77     void visibilityFinished(bool visiblity);
       
    78     void moveBy(int dx, int dy);
       
    79     void anchorTo(const QString & id, int x = 0, int y = 0);
       
    80     void unAnchor();
       
    81     void anchorToView(const QString& view, const QString& where="top");
       
    82     void detachFromView(const QString& view, const QString& where="top");
       
    83     QObject * getGeometry() const;
       
    84     QObject * getPosition() const;
       
    85     void setPosition(int x, int y);
       
    86     QObject * childGeometry(const QString id) const;
       
    87     QObject * animate(int duration);
       
    88     bool isVisible() { return m_visible; }
       
    89     bool isHiding() { return m_hiding; }
       
    90     int zValue();
       
    91     void setZValue(int z);
       
    92     //NB: deprecate repaint: if this is needed, then there are bugs that are preventing updates
       
    93     void repaint() { m_widget->update(); }
       
    94     void onContextMenuEvent(QGraphicsSceneContextMenuEvent * ev); 
       
    95   signals:
       
    96     void hidden();
       
    97     void shown();
       
    98     void externalMouseEvent(
       
    99             int type,
       
   100             const QString & name,
       
   101             const QString & description);
       
   102     void contextMenuEvent(int x, int y);
       
   103     void snippetMouseEvent(QEvent::Type );
       
   104 
       
   105   protected slots:
       
   106     virtual void positionChildren();
       
   107   private slots:
       
   108     void onChromeComplete();
       
   109 
       
   110   public:
       
   111     Q_PROPERTY(QString id READ getId)
       
   112     QString getId() const { return m_elementId; }
       
   113     Q_PROPERTY(bool visible READ isVisible)
       
   114     Q_PROPERTY(bool hiding READ isHiding)
       
   115     Q_PROPERTY(QString anchor READ getAnchorString)
       
   116     QString getAnchorString();
       
   117     Q_PROPERTY(int anchorOffset READ anchorOffset WRITE setAnchorOffset)
       
   118     Q_PROPERTY(int zValue READ zValue WRITE setZValue)
       
   119     Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
       
   120     Q_PROPERTY(bool dontShow READ getDontShowFlag WRITE setDontShowFlag)
       
   121   protected:
       
   122     bool getDontShowFlag() {return m_dontshowFlag;}
       
   123     void setDontShowFlag(bool flag){ m_dontshowFlag = flag;}
       
   124   protected:
       
   125     QString m_elementId;
       
   126     QWebElement m_element;
       
   127     QString m_parentId;
       
   128     ChromeWidget * m_chrome;
       
   129     QGraphicsWidget * m_widget; //Take ownership
       
   130     bool m_initiallyVisible; //NB: needed ?
       
   131     bool m_visible;
       
   132     bool m_hidesContent;
       
   133     ChromeAnchor m_anchor;
       
   134     int m_anchorOffset;
       
   135     VisibilityAnimator * m_vAnimator;
       
   136     QGraphicsEffect * m_effect;
       
   137     bool m_hiding;
       
   138     bool m_dontshowFlag;
       
   139     QList<ChromeSnippet*> m_links;
       
   140   };
       
   141 
       
   142 } // end of namespace GVA
       
   143 
       
   144 #endif // __GINEBRA_CHROMESNIPPET_H__