ginebra2/mostvisitedsnippet.cpp
changeset 3 0954f5dd2cd0
parent 0 1450b09d0cfd
child 12 afcd8e6d025b
--- a/ginebra2/mostvisitedsnippet.cpp	Fri May 14 15:40:36 2010 +0300
+++ b/ginebra2/mostvisitedsnippet.cpp	Tue Jun 29 00:46:29 2010 -0400
@@ -1,20 +1,23 @@
 /*
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation, version 2.1 of the License.
 *
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU Lesser General Public License for more details.
 *
-* Contributors:
+* You should have received a copy of the GNU Lesser General Public License
+* along with this program.  If not,
+* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
 *
-* Description: 
+* Description:
 *
 */
-
 #include "mostvisitedsnippet.h"
 #include "mostvisitedpageview.h"
 
@@ -26,10 +29,18 @@
     m_chrome = chrome;
 }
 
-void MostVisitedSnippet::toggleVisibility(bool animate) 
+MostVisitedSnippet * MostVisitedSnippet::instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element)
+{
+    MostVisitedSnippet* that = new MostVisitedSnippet(elementId, chrome, 0, element);
+    that->setChromeWidget( new MostVisitedPagesWidget(that, chrome) );
+    that->widget()->hide(); //TODO: Shouldn't be needed?
+    return that;
+}
+
+void MostVisitedSnippet::toggleVisibility(bool animate)
 {
     MostVisitedPagesWidget *mostVisitedPagesWidget = dynamic_cast<MostVisitedPagesWidget*>(widget());
-    if (!mostVisitedPagesWidget) 
+    if (!mostVisitedPagesWidget)
         return;
 
     if (!isVisible()) {
@@ -44,10 +55,10 @@
 }
 
 
-void MostVisitedSnippet::setWidget(QGraphicsWidget * widget)
+void MostVisitedSnippet::setChromeWidget(QGraphicsWidget * widget)
 {
     connect(m_chrome , SIGNAL(aspectChanged(int)), this, SLOT(displayModeChanged(int)));
-    ChromeSnippet::setWidget(widget);   
+    ChromeSnippet::setChromeWidget(widget);
     MostVisitedPagesWidget *mostVisitedPagesWidget = dynamic_cast<MostVisitedPagesWidget*>(widget);
     connect(mostVisitedPagesWidget, SIGNAL(closeComplete()), this, SIGNAL(mostVisitedSnippetCloseComplete()));
 }
@@ -59,22 +70,22 @@
 
     ChromeSnippet* visibleSnippet= m_chrome->getSnippet("WebViewToolbarId");
     if (visibleSnippet)
-        toolBarHeight = visibleSnippet->widget()->rect().height(); 
+        toolBarHeight = visibleSnippet->widget()->rect().height();
 
-    mostVisitedPagesWidget->resize(m_chrome->size().toSize());
+    mostVisitedPagesWidget->resize(m_chrome->layout()->size().toSize());
     mostVisitedPagesWidget->updatePos(QPointF(0, 0), toolBarHeight);
 }
 
 void MostVisitedSnippet::displayModeChanged(int newMode)
 {
-    if (isVisible()) {     
+    if (isVisible()) {
         MostVisitedPagesWidget *mostVisitedPagesWidget = dynamic_cast<MostVisitedPagesWidget*>(widget());
-        
-        if (!mostVisitedPagesWidget) 
+
+        if (!mostVisitedPagesWidget)
             return;
 
         updateMVGeometry();
-        
+
         QString  displayMode = (newMode == landscape) ? "Landscape" : "Portrait";
         mostVisitedPagesWidget->displayModeChanged(displayMode);
     }
@@ -83,19 +94,19 @@
 void MostVisitedSnippet::hide(bool animate)
  {
      MostVisitedPagesWidget *mostVisitedPagesWidget = dynamic_cast<MostVisitedPagesWidget*>(widget());
-   
-     if(!mostVisitedPagesWidget) 
+
+     if (!mostVisitedPagesWidget)
        return;
 
      ChromeSnippet::hide(animate);
      mostVisitedPagesWidget->closeAnimationCompleted();
  }
 
-void MostVisitedSnippet::close() 
+void MostVisitedSnippet::close()
 {
      MostVisitedPagesWidget *mostVisitedPagesWidget = dynamic_cast<MostVisitedPagesWidget*>(widget());
-   
-     if(mostVisitedPagesWidget) {
+
+     if (mostVisitedPagesWidget) {
        mostVisitedPagesWidget->close();
      }
 }