ginebra2/ToolbarChromeItem.cpp
changeset 0 1450b09d0cfd
child 3 0954f5dd2cd0
child 5 0f2326c2a325
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 #include "ToolbarChromeItem.h"
       
    20 #include "GWebContentView.h"
       
    21 #include "WebChromeContainerSnippet.h"
       
    22 
       
    23 #include <QDebug>
       
    24 
       
    25 #define TOOLBAR_MARGIN 4
       
    26 #define TOOLBAR_BORDER_WIDTH 3
       
    27 #define TOOLBAR_BORDER_COLOR "#2A3447"
       
    28 #define TOOLBAR_GRADIENT_START "#2E3B57"
       
    29 #define TOOLBAR_GRADIENT_END "#44587D"
       
    30 #define TOOLBAR_RIGHTCORNER_ITEM 2
       
    31 #define TOOLBAR_LEFTCORNER_ITEM 0
       
    32 
       
    33 namespace GVA {
       
    34 
       
    35   ToolbarChromeItem::ToolbarChromeItem(QGraphicsItem* parent)
       
    36     : QGraphicsWidget(parent),
       
    37       m_snippet(NULL),
       
    38       m_partialbg(NULL),
       
    39       m_opacity(0.75)
       
    40   {
       
    41 
       
    42     setProperties();
       
    43 
       
    44 
       
    45   }
       
    46 
       
    47   ToolbarChromeItem::~ToolbarChromeItem()
       
    48   {
       
    49     if (m_partialbg) {
       
    50       delete m_partialbg;
       
    51     }
       
    52   }
       
    53 
       
    54   void ToolbarChromeItem::resizeEvent(QGraphicsSceneResizeEvent * ev)
       
    55   {
       
    56     Q_UNUSED(ev)
       
    57 
       
    58     addPartialbg();
       
    59 
       
    60   }
       
    61 
       
    62   void ToolbarChromeItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt, QWidget* widget)
       
    63   {
       
    64     Q_UNUSED(opt)
       
    65     Q_UNUSED(widget)
       
    66 
       
    67     painter->save();
       
    68  
       
    69     painter->setRenderHint(QPainter::Antialiasing);
       
    70  
       
    71     painter->setPen(m_pen);
       
    72     painter->setOpacity(m_opacity);
       
    73  
       
    74 
       
    75 //    qDebug() << __PRETTY_FUNCTION__ << boundingRect();
       
    76     painter->fillPath(*m_partialbg, QBrush(m_grad));
       
    77     painter->drawPath(*m_partialbg);
       
    78    
       
    79     // restore painter
       
    80     painter->restore(); 
       
    81  
       
    82   }
       
    83   void ToolbarChromeItem::setSnippet(WebChromeContainerSnippet* snippet) {
       
    84 
       
    85     //qDebug() << __func__ << snippet;
       
    86     m_snippet = snippet;
       
    87   }
       
    88 
       
    89   void ToolbarChromeItem::setProperties() {
       
    90 
       
    91     m_pen.setWidth(TOOLBAR_BORDER_WIDTH);
       
    92     m_pen.setBrush(QBrush(TOOLBAR_BORDER_COLOR));
       
    93    
       
    94     m_grad.setColorAt(0, TOOLBAR_GRADIENT_START);
       
    95     m_grad.setColorAt(1, TOOLBAR_GRADIENT_END);
       
    96         
       
    97   }
       
    98 
       
    99   void ToolbarChromeItem::addPartialbg() {
       
   100 
       
   101     WebChromeContainerSnippet * s = static_cast<WebChromeContainerSnippet*>(m_snippet);
       
   102     QRectF rc = s->layout()->itemAt(TOOLBAR_LEFTCORNER_ITEM)->geometry();
       
   103     if (m_partialbg) {
       
   104       delete m_partialbg;
       
   105     }
       
   106 
       
   107     m_partialbg = new QPainterPath();
       
   108     int width =  rc.width()-TOOLBAR_MARGIN;
       
   109    
       
   110     // Add left corner bg
       
   111     m_partialbg->addEllipse(1, 1, width, width);
       
   112 
       
   113     // Right Corner background
       
   114     int x = boundingRect().width()- rc.width() + 1;
       
   115     QRectF r(x, 1, width, width);
       
   116 
       
   117     m_partialbg->addEllipse(r);
       
   118   }
       
   119 
       
   120 
       
   121 } // end of namespace GVA
       
   122 
       
   123