ginebra2/ToolbarChromeItem.cpp
changeset 3 0954f5dd2cd0
parent 0 1450b09d0cfd
child 16 3c88a81ff781
equal deleted inserted replaced
1:b0dd75e285d2 3:0954f5dd2cd0
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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 *
     4 *
     9 * Initial Contributors:
     5 * This program is free software: you can redistribute it and/or modify
    10 * Nokia Corporation - initial contribution.
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
    11 *
     8 *
    12 * Contributors:
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
    13 *
    13 *
    14 * Description: 
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not,
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
    15 *
    19 *
    16 */
    20 */
    17 
    21 
    18 
       
    19 #include "ToolbarChromeItem.h"
    22 #include "ToolbarChromeItem.h"
       
    23 #include "NativeChromeItem.h"
    20 #include "GWebContentView.h"
    24 #include "GWebContentView.h"
    21 #include "WebChromeContainerSnippet.h"
    25 #include "WebChromeContainerSnippet.h"
       
    26 #include "ChromeEffect.h"
    22 
    27 
    23 #include <QDebug>
    28 #include <QDebug>
    24 
    29 
    25 #define TOOLBAR_MARGIN 4
    30 #define TOOLBAR_BG_OPACITY 0.75
    26 #define TOOLBAR_BORDER_WIDTH 3
       
    27 #define TOOLBAR_BORDER_COLOR "#2A3447"
       
    28 #define TOOLBAR_GRADIENT_START "#2E3B57"
    31 #define TOOLBAR_GRADIENT_START "#2E3B57"
    29 #define TOOLBAR_GRADIENT_END "#44587D"
    32 #define TOOLBAR_GRADIENT_END "#44587D"
    30 #define TOOLBAR_RIGHTCORNER_ITEM 2
       
    31 #define TOOLBAR_LEFTCORNER_ITEM 0
    33 #define TOOLBAR_LEFTCORNER_ITEM 0
    32 
    34 
    33 namespace GVA {
    35 namespace GVA {
    34 
    36 
    35   ToolbarChromeItem::ToolbarChromeItem(QGraphicsItem* parent)
    37   ToolbarChromeItem::ToolbarChromeItem(ChromeSnippet* snippet, QGraphicsItem* parent)
    36     : QGraphicsWidget(parent),
    38     : ChromeItem(NULL, parent),
    37       m_snippet(NULL),
       
    38       m_partialbg(NULL),
    39       m_partialbg(NULL),
    39       m_opacity(0.75)
    40       m_opacity(TOOLBAR_BG_OPACITY)
    40   {
    41   {
    41 
    42       setSnippet(snippet);
    42     setProperties();
       
    43 
       
    44 
       
    45   }
    43   }
    46 
    44 
    47   ToolbarChromeItem::~ToolbarChromeItem()
    45   ToolbarChromeItem::~ToolbarChromeItem()
    48   {
    46   {
    49     if (m_partialbg) {
    47     if (m_partialbg) {
    63   {
    61   {
    64     Q_UNUSED(opt)
    62     Q_UNUSED(opt)
    65     Q_UNUSED(widget)
    63     Q_UNUSED(widget)
    66 
    64 
    67     painter->save();
    65     painter->save();
    68  
    66 
    69     painter->setRenderHint(QPainter::Antialiasing);
    67     painter->setRenderHint(QPainter::Antialiasing);
    70  
    68 
    71     painter->setPen(m_pen);
    69     painter->setPen(m_pen);
    72     painter->setOpacity(m_opacity);
    70     painter->setOpacity(m_opacity);
    73  
    71 
    74 
    72 
    75 //    qDebug() << __PRETTY_FUNCTION__ << boundingRect();
    73 //    qDebug() << __PRETTY_FUNCTION__ << boundingRect();
    76     painter->fillPath(*m_partialbg, QBrush(m_grad));
    74     painter->fillPath(*m_partialbg, QBrush(m_grad));
    77     painter->drawPath(*m_partialbg);
    75     painter->drawPath(*m_partialbg);
    78    
    76 
    79     // restore painter
    77     // restore painter
    80     painter->restore(); 
    78     painter->restore();
    81  
       
    82   }
       
    83   void ToolbarChromeItem::setSnippet(WebChromeContainerSnippet* snippet) {
       
    84 
    79 
    85     //qDebug() << __func__ << snippet;
    80     if(!isEnabled()) {
    86     m_snippet = snippet;
    81         // Disabled, apply whitewash.
       
    82         ChromeEffect::paintDisabledRect(painter, opt->exposedRect);
       
    83     }
    87   }
    84   }
    88 
    85 
    89   void ToolbarChromeItem::setProperties() {
    86   void ToolbarChromeItem::setProperties() {
    90 
    87 
    91     m_pen.setWidth(TOOLBAR_BORDER_WIDTH);
    88     m_pen.setWidth(m_borderWidth);
    92     m_pen.setBrush(QBrush(TOOLBAR_BORDER_COLOR));
    89     m_pen.setBrush(QBrush(m_borderColor));
    93    
    90 
    94     m_grad.setColorAt(0, TOOLBAR_GRADIENT_START);
    91     m_grad.setColorAt(0, TOOLBAR_GRADIENT_START);
    95     m_grad.setColorAt(1, TOOLBAR_GRADIENT_END);
    92     m_grad.setColorAt(1, TOOLBAR_GRADIENT_END);
    96         
    93 
    97   }
    94   }
    98 
    95 
    99   void ToolbarChromeItem::addPartialbg() {
    96   void ToolbarChromeItem::addPartialbg() {
   100 
    97 
   101     WebChromeContainerSnippet * s = static_cast<WebChromeContainerSnippet*>(m_snippet);
    98     WebChromeContainerSnippet * s = static_cast<WebChromeContainerSnippet*>(m_snippet);
       
    99     if(!s->layout()->itemAt(TOOLBAR_LEFTCORNER_ITEM))
       
   100         return;
   102     QRectF rc = s->layout()->itemAt(TOOLBAR_LEFTCORNER_ITEM)->geometry();
   101     QRectF rc = s->layout()->itemAt(TOOLBAR_LEFTCORNER_ITEM)->geometry();
   103     if (m_partialbg) {
   102     if (m_partialbg) {
   104       delete m_partialbg;
   103       delete m_partialbg;
   105     }
   104     }
   106 
   105 
   107     m_partialbg = new QPainterPath();
   106     m_partialbg = new QPainterPath();
   108     int width =  rc.width()-TOOLBAR_MARGIN;
   107     qreal width =  rc.width()-m_padding;
   109    
   108 
   110     // Add left corner bg
   109     // Add left corner bg
   111     m_partialbg->addEllipse(1, 1, width, width);
   110     m_partialbg->addEllipse(1, 1, width, width);
   112 
   111 
   113     // Right Corner background
   112     // Right Corner background
   114     int x = boundingRect().width()- rc.width() + 1;
   113     qreal x = boundingRect().width()- rc.width() + 1;
   115     QRectF r(x, 1, width, width);
   114     QRectF r(x, 1, width, width);
   116 
   115 
   117     m_partialbg->addEllipse(r);
   116     m_partialbg->addEllipse(r);
   118   }
   117   }
   119 
   118 
       
   119   void ToolbarChromeItem::setSnippet(ChromeSnippet* snippet) {
       
   120 
       
   121     ChromeItem::setSnippet(snippet);
       
   122     QString cssVal = m_snippet->element().styleProperty("border-top-color",
       
   123         QWebElement::ComputedStyle);
       
   124     NativeChromeItem::CSSToQColor(cssVal, m_borderColor);
       
   125 
       
   126     cssVal = m_snippet->element().styleProperty("padding-top", QWebElement::ComputedStyle);
       
   127     m_padding = cssVal.remove("px").toInt();
       
   128 
       
   129     cssVal = m_snippet->element().styleProperty("border-top-width", QWebElement::ComputedStyle);
       
   130     m_borderWidth = cssVal.remove("px").toInt();
       
   131     setProperties();
       
   132   }
   120 
   133 
   121 } // end of namespace GVA
   134 } // end of namespace GVA
   122 
   135 
   123 
   136