ginebra2/ChromeSnippet.cpp
changeset 6 1c3b8676e58c
parent 5 0f2326c2a325
equal deleted inserted replaced
5:0f2326c2a325 6:1c3b8676e58c
    74   //widget implementations as appropriate. Currently this hooked up in WebChromeSnippet
    74   //widget implementations as appropriate. Currently this hooked up in WebChromeSnippet
    75   //to the webkit context menu.
    75   //to the webkit context menu.
    76 
    76 
    77   void ChromeSnippet::onContextMenuEvent(QGraphicsSceneContextMenuEvent * ev)
    77   void ChromeSnippet::onContextMenuEvent(QGraphicsSceneContextMenuEvent * ev)
    78   {
    78   {
    79     qDebug() << "ChromeSnippet::contextMenuEvent: " << ev->pos();
       
    80     emit contextMenuEvent(ev->pos().x(), ev->pos().y());
    79     emit contextMenuEvent(ev->pos().x(), ev->pos().y());
    81   }
    80   }
    82 
    81 
       
    82   void ChromeSnippet::setChromeWidget(QGraphicsWidget * widget)
       
    83   { 
       
    84       m_widget = widget; 
       
    85       m_widget->hide(); 
       
    86   }
    83 
    87 
    84   //NB: Would be architecturally cleaner to do this translation in ChromeDOM
    88   //NB: Would be architecturally cleaner to do this translation in ChromeDOM
    85   //so snippets don't have to know anything about dom attribute string values
    89   //so snippets don't have to know anything about dom attribute string values
    86 
    90 
    87   void ChromeSnippet::setAnchor(const QString& anchor, bool update)
    91   void ChromeSnippet::setAnchor(const QString& anchor, bool update)
   106     else if (anchor == "AnchorBottomRight")
   110     else if (anchor == "AnchorBottomRight")
   107       setAnchor(anchorBottomRight);
   111       setAnchor(anchorBottomRight);
   108     else
   112     else
   109       setAnchor(anchorNone);
   113       setAnchor(anchorNone);
   110     if (update)
   114     if (update)
   111       m_chrome->anchorSnippet(this);
   115       m_chrome->layout()->anchorSnippet(this);
   112   }
   116   }
   113 
   117 
   114   void ChromeSnippet::setAnchorOffset(int offset, bool update)
   118   void ChromeSnippet::setAnchorOffset(int offset, bool update)
   115   {
   119   {
   116     int delta = offset - m_anchorOffset;
   120     int delta = offset - m_anchorOffset;
   117     m_anchorOffset = offset;
   121     m_anchorOffset = offset;
   118 
   122 
   119     if (update){
   123     if (update){
   120       if (m_widget->isVisible())
   124       if (m_widget->isVisible())
   121     m_chrome->adjustAnchorOffset(this, delta);
   125 	m_chrome->adjustAnchorOffset(this, delta);
   122       m_chrome->anchorSnippet(this);
   126       m_chrome->layout()->anchorSnippet(this);
   123     }
   127     }
   124   }
   128   }
   125 
   129 
   126   QString ChromeSnippet::getAnchorString() {
   130   QString ChromeSnippet::getAnchorString() {
   127     switch (anchor()) {
   131     switch (anchor()) {
   164       if (m_vAnimator && !animate)
   168       if (m_vAnimator && !animate)
   165         m_vAnimator->setVisible(m_visible, animate);
   169         m_vAnimator->setVisible(m_visible, animate);
   166       m_widget->show();
   170       m_widget->show();
   167       if (m_vAnimator && animate)
   171       if (m_vAnimator && animate)
   168         m_vAnimator->setVisible(m_visible, animate);
   172         m_vAnimator->setVisible(m_visible, animate);
   169       m_chrome->snippetShown(this); //NB: handle this via shown signal
   173       m_chrome->layout()->snippetShown(this); //NB: handle this via shown signal
   170       m_hiding = false;
   174       m_hiding = false;
   171       emit shown();
   175       emit shown();
   172     }
   176     }
   173     else{
   177     else{
   174       m_chrome->snippetHiding(this); //NB: handle this via hiding signal
   178       m_chrome->layout()->snippetHiding(this); //NB: handle this via hiding signal
   175       m_hiding = true;
   179       m_hiding = true;
   176       if (m_vAnimator)
   180       if (m_vAnimator)
   177         m_vAnimator->setVisible(m_visible, animate);
   181         m_vAnimator->setVisible(m_visible, animate);
   178       else {
   182       else {
   179         m_widget->hide();
   183         m_widget->hide();
   208   bool ChromeSnippet::enabled() const {
   212   bool ChromeSnippet::enabled() const {
   209       return m_enabled;
   213       return m_enabled;
   210   }
   214   }
   211 
   215 
   212   void ChromeSnippet::setEnabled(bool value) {
   216   void ChromeSnippet::setEnabled(bool value) {
   213       qDebug() << "ChromeSnippet::setEnabled: " << objectName() << value;
   217        if(m_enabled == value)
   214       if(m_enabled == value)
       
   215           return;
   218           return;
   216 
   219 
   217       m_enabled = value;
   220       m_enabled = value;
   218       m_widget->setEnabled(value);
   221       m_widget->setEnabled(value);
   219   }
   222   }
   313       ChromeSnippet * childSnippet = m_chrome->getSnippet(child.attribute("id"));
   316       ChromeSnippet * childSnippet = m_chrome->getSnippet(child.attribute("id"));
   314       QRect childGeo = child.geometry();
   317       QRect childGeo = child.geometry();
   315       QRect parentGeo = m_element.geometry();
   318       QRect parentGeo = m_element.geometry();
   316       //Get child geometry relative to parent
   319       //Get child geometry relative to parent
   317       QRectF childGeom(childGeo.x()-parentGeo.x(), childGeo.y()-parentGeo.y(), childGeo.width(), childGeo.height());
   320       QRectF childGeom(childGeo.x()-parentGeo.x(), childGeo.y()-parentGeo.y(), childGeo.width(), childGeo.height());
   318       qDebug() << "Parent geometry: " << parentGeo << " child geometry: " << childGeo;
       
   319       childSnippet->widget()->setGeometry(childGeom);
   321       childSnippet->widget()->setGeometry(childGeom);
   320     }
   322     }
   321 
   323 
   322   }
   324   }
   323 
   325 
   324   void ChromeSnippet::addChild(ChromeSnippet * child)
   326   void ChromeSnippet::addChild(ChromeSnippet * child)
   325   {
   327   {
   326     qDebug() << "ChromeSnippet::addChild: " << child->elementId();
       
   327     QWebElement c = m_element.findFirst("#" + child->elementId());
   328     QWebElement c = m_element.findFirst("#" + child->elementId());
   328     if (c.isNull())
   329     if (c.isNull())
   329       return;
   330       return;
   330     QRect childGeo = c.geometry();
   331     QRect childGeo = c.geometry();
   331     QRect parentGeo = m_element.geometry();
   332     QRect parentGeo = m_element.geometry();
   355   }
   356   }
   356 
   357 
   357   void ChromeSnippet::anchorToView(const QString& view, const QString& where)
   358   void ChromeSnippet::anchorToView(const QString& view, const QString& where)
   358   {
   359   {
   359     Q_UNUSED(where)
   360     Q_UNUSED(where)
   360     m_chrome->anchorToView(this, view);
   361     m_chrome->layout()->anchorToView(this, view);
   361   }
   362   }
   362 
   363 
   363   void ChromeSnippet::detachFromView(const QString& view, const QString& where)
   364   void ChromeSnippet::detachFromView(const QString& view, const QString& where)
   364   {
   365   {
   365     Q_UNUSED(where)
   366     Q_UNUSED(where)
   366     m_chrome->detachFromView(this, view);
   367     m_chrome->layout()->detachFromView(this, view);
   367   }
   368   }
   368 
   369 
   369   void ChromeSnippet::anchorTo(const QString & id, int x, int y)
   370   void ChromeSnippet::anchorTo(const QString & id, int x, int y)
   370   {
   371   {
   371     m_chrome->anchorTogether(this, id, x, y);
   372     m_chrome->anchorTogether(this, id, x, y);
   372   }
   373   }
   373 
   374 
   374   void ChromeSnippet::unAnchor()
   375   void ChromeSnippet::unAnchor()
   375   {
   376   {
   376     setAnchor("AnchorNone");
   377     setAnchor("AnchorNone");
   377     m_chrome->unAnchor(this);
   378     m_chrome->layout()->unAnchor(this);
   378   }
   379   }
   379 
   380 
   380  QObject *ChromeSnippet::animate(int duration) {
   381  QObject *ChromeSnippet::animate(int duration) {
   381     GraphicsItemAnimation *an = new GraphicsItemAnimation(this, duration);
   382     GraphicsItemAnimation *an = new GraphicsItemAnimation(this, duration);
   382     m_chrome->page()->mainFrame()->addToJavaScriptWindowObject("animation", an, QScriptEngine::ScriptOwnership);
   383     m_chrome->page()->mainFrame()->addToJavaScriptWindowObject("animation", an, QScriptEngine::ScriptOwnership);
   390     return m_vAnimator;
   391     return m_vAnimator;
   391   }
   392   }
   392 
   393 
   393   void ChromeSnippet::grabFocus()
   394   void ChromeSnippet::grabFocus()
   394   {
   395   {
   395     qDebug() << "ChromeSnippet::grabFocus()";
   396      m_widget->setFocus();
   396     m_widget->setFocus();
       
   397   }
   397   }
   398 
   398 
   399   int ChromeSnippet::zValue()
   399   int ChromeSnippet::zValue()
   400   {
   400   {
   401     return m_widget->zValue();
   401     return m_widget->zValue();