ginebra2/ToolbarChromeItem.cpp
changeset 5 0f2326c2a325
parent 0 1450b09d0cfd
child 6 1c3b8676e58c
--- a/ginebra2/ToolbarChromeItem.cpp	Fri May 14 15:40:36 2010 +0300
+++ b/ginebra2/ToolbarChromeItem.cpp	Wed Jun 23 17:59:43 2010 +0300
@@ -1,47 +1,44 @@
 /*
 * 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 "ToolbarChromeItem.h"
+#include "NativeChromeItem.h"
 #include "GWebContentView.h"
 #include "WebChromeContainerSnippet.h"
 
 #include <QDebug>
 
-#define TOOLBAR_MARGIN 4
-#define TOOLBAR_BORDER_WIDTH 3
-#define TOOLBAR_BORDER_COLOR "#2A3447"
+#define TOOLBAR_BG_OPACITY 0.75
 #define TOOLBAR_GRADIENT_START "#2E3B57"
 #define TOOLBAR_GRADIENT_END "#44587D"
-#define TOOLBAR_RIGHTCORNER_ITEM 2
 #define TOOLBAR_LEFTCORNER_ITEM 0
 
 namespace GVA {
 
   ToolbarChromeItem::ToolbarChromeItem(QGraphicsItem* parent)
-    : QGraphicsWidget(parent),
-      m_snippet(NULL),
+    : ChromeItem(NULL, parent),
       m_partialbg(NULL),
-      m_opacity(0.75)
+      m_opacity(TOOLBAR_BG_OPACITY)
   {
 
-    setProperties();
-
-
   }
 
   ToolbarChromeItem::~ToolbarChromeItem()
@@ -65,35 +62,30 @@
     Q_UNUSED(widget)
 
     painter->save();
- 
+
     painter->setRenderHint(QPainter::Antialiasing);
- 
+
     painter->setPen(m_pen);
     painter->setOpacity(m_opacity);
- 
+
 
 //    qDebug() << __PRETTY_FUNCTION__ << boundingRect();
     painter->fillPath(*m_partialbg, QBrush(m_grad));
     painter->drawPath(*m_partialbg);
-   
+
     // restore painter
-    painter->restore(); 
- 
-  }
-  void ToolbarChromeItem::setSnippet(WebChromeContainerSnippet* snippet) {
+    painter->restore();
 
-    //qDebug() << __func__ << snippet;
-    m_snippet = snippet;
   }
 
   void ToolbarChromeItem::setProperties() {
 
-    m_pen.setWidth(TOOLBAR_BORDER_WIDTH);
-    m_pen.setBrush(QBrush(TOOLBAR_BORDER_COLOR));
-   
+    m_pen.setWidth(m_borderWidth);
+    m_pen.setBrush(QBrush(m_borderColor));
+
     m_grad.setColorAt(0, TOOLBAR_GRADIENT_START);
     m_grad.setColorAt(1, TOOLBAR_GRADIENT_END);
-        
+
   }
 
   void ToolbarChromeItem::addPartialbg() {
@@ -105,18 +97,34 @@
     }
 
     m_partialbg = new QPainterPath();
-    int width =  rc.width()-TOOLBAR_MARGIN;
-   
+    qreal width =  rc.width()-m_padding;
+
     // Add left corner bg
     m_partialbg->addEllipse(1, 1, width, width);
 
     // Right Corner background
-    int x = boundingRect().width()- rc.width() + 1;
+    qreal x = boundingRect().width()- rc.width() + 1;
     QRectF r(x, 1, width, width);
 
     m_partialbg->addEllipse(r);
   }
 
+  void ToolbarChromeItem::setSnippet(ChromeSnippet* snippet) {
+
+    ChromeItem::setSnippet(snippet);
+
+    QString cssVal = m_snippet->element().styleProperty("border-top-color", QWebElement::ComputedStyle);
+    NativeChromeItem::CSSToQColor(cssVal, m_borderColor);
+
+    cssVal = m_snippet->element().styleProperty("padding-top", QWebElement::ComputedStyle);
+    m_padding =  cssVal.remove("px").toInt();
+
+
+    cssVal = m_snippet->element().styleProperty("border-top-width", QWebElement::ComputedStyle);
+    m_borderWidth = cssVal.remove("px").toInt();
+
+    setProperties();
+  }
 
 } // end of namespace GVA