ginebra/chromesnippet.h
changeset 0 1450b09d0cfd
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_CHROME_SNIPPET_H_
       
    20 #define _GINEBRA_CHROME_SNIPPET_H_
       
    21 
       
    22 #include <QtGui>
       
    23 #include "visibilityanimator.h"
       
    24 #include "attentionanimator.h"
       
    25 
       
    26 class QTimer;
       
    27 class QGraphicsItemAnimation;
       
    28 class QGraphicsLinearLayout;
       
    29 class ChromeWidget;
       
    30 class ChromeSnippetJSObject;
       
    31 class QGraphicsSceneContextMenuEvent;
       
    32 /**
       
    33  * \brief Encapsulates an individual piece of the browser chrome.
       
    34  * 
       
    35  * The ChromeSnippet class encapsulates an individual piece of the browser chrome.
       
    36  * The contents of the snippet are taken from individual DOM elements (typically DIVs)
       
    37  * in the chrome HTML page by ChromeWidget and can be accessed from javascript in that 
       
    38  * page through the properties, slots and signals provided by this class.
       
    39  * 
       
    40  * \sa ChromeWidget 
       
    41  */
       
    42 class ChromeSnippet: public QGraphicsRectItem 
       
    43 {
       
    44     
       
    45   friend class VisibilityAnimator;
       
    46   friend class AttentionAnimator;
       
    47 
       
    48 public:
       
    49   ChromeSnippet(QGraphicsItem * parent, ChromeWidget * owner, QObject *jsParent, const QString &docElementId);
       
    50   ~ChromeSnippet();
       
    51   void setOwnerArea(const QRectF& ownerArea);
       
    52   QRectF& ownerArea();
       
    53   void updateChildGeometries();
       
    54   void setDocElementId(const QString &id) { m_docElementId = id; }
       
    55   void setDocElementName(const QString &name) { m_docElementName = name; }
       
    56   void setVisibilityAnimator(VisibilityAnimator * animator) {delete m_visibilityAnimator; m_visibilityAnimator = animator; }
       
    57   void setAttentionAnimator(AttentionAnimator * animator) { delete m_visibilityAnimator; m_attentionAnimator = animator; }
       
    58   bool isHiding() { return m_isHiding; }
       
    59   void setHiding(bool value) { m_isHiding = value; }
       
    60   
       
    61 public:
       
    62   void toggleVisibility();
       
    63   void show(bool useAnimation = true);
       
    64   void hide(bool useAnimation = true);
       
    65   void toggleAttention();
       
    66   
       
    67   /// Starts an animation timer.  Returns an animation object that can rotate, move or fade the snippet.
       
    68   /// 
       
    69   /// \sa GraphicsItemAnimation
       
    70   QObject *animate(int duration);
       
    71   
       
    72   QString docElementId() const { return m_docElementId; }
       
    73   
       
    74   void setPosition(int x, int y) { setPos(x, y); }
       
    75   QString  getDisplayMode();
       
    76   //Snippet auto-layout methods
       
    77   QString anchor() { return m_anchor; }
       
    78   void setAnchor(const QString& anchor) { m_anchor = anchor; }
       
    79   int anchorOffset() { return m_anchorOffset; }
       
    80   void setAnchorOffset(int anchorOffset) { m_anchorOffset = anchorOffset; }
       
    81   bool hidesContent(){ return m_hidesContent;}
       
    82   void setHidesContent(bool hidesContent) { m_hidesContent = hidesContent; }
       
    83   
       
    84   /// Set the animation that is triggered when the snippet is shown or hidden.
       
    85   void setVisibilityAnimator(const QString &animatorName); 
       
    86   
       
    87   /// Set the animation that is triggered when the snippet wants attention.
       
    88   void setAttentionAnimator(const QString &animatorName);    
       
    89   
       
    90   void dump() const;
       
    91   
       
    92   /// The snippet's screen geometry.
       
    93   QObject *getGeometry() const;
       
    94   QRect geometry() const { return rect().toRect(); }
       
    95 
       
    96   /// The position of the snippet's top-left corner.
       
    97   QObject *getPosition() const;
       
    98   
       
    99   void resize(const QSizeF &size) { resize(size.width(), size.height()); }
       
   100   void resize(qreal width, qreal height);
       
   101 
       
   102   /// True if the snippet can be dragged with the mouse.  Defaults to false.
       
   103   bool draggable() const { return m_draggable; }
       
   104   void setDraggable(bool value) { m_draggable = value; }
       
   105 
       
   106   /// Repaint the snippet
       
   107   void repaint();
       
   108   
       
   109   QObject *getJSObject();
       
   110   static bool getContextMenuFlag();
       
   111   
       
   112 protected:
       
   113   virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
       
   114   void mousePressEvent(QGraphicsSceneMouseEvent  *ev);
       
   115   void mouseReleaseEvent(QGraphicsSceneMouseEvent  *ev);
       
   116   void mouseDoubleClickEvent(QGraphicsSceneMouseEvent  *ev);
       
   117   void mouseMoveEvent(QGraphicsSceneMouseEvent  *ev);
       
   118   void keyPressEvent ( QKeyEvent * event );
       
   119   void keyReleaseEvent ( QKeyEvent * event );
       
   120   void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
       
   121   void passMouseEventToPage(QEvent::Type type, QGraphicsSceneMouseEvent *ev);
       
   122   virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent* event);
       
   123 
       
   124  private:
       
   125   ChromeWidget* m_owner;
       
   126   QRectF m_ownerArea;
       
   127   QString m_docElementId;
       
   128   QString m_docElementName;
       
   129   QGraphicsLinearLayout * m_layout;
       
   130   VisibilityAnimator *m_visibilityAnimator; //Take ownership
       
   131   AttentionAnimator *m_attentionAnimator; //Take ownership
       
   132   bool m_dragging;
       
   133   bool m_draggable;
       
   134   QString m_anchor;
       
   135   int m_anchorOffset;
       
   136   bool m_hidesContent;
       
   137   bool m_isHiding;
       
   138  QPointer<ChromeSnippetJSObject> m_jsObject;
       
   139   static bool contextMenuFlag;
       
   140 
       
   141 };
       
   142 
       
   143 
       
   144 #endif