ginebra2/ToolbarSnippet.cpp
changeset 3 0954f5dd2cd0
equal deleted inserted replaced
1:b0dd75e285d2 3:0954f5dd2cd0
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     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.
       
     8 *
       
     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 *
       
    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:
       
    19 * This class extends WebChromeContainerSnippet class to hold the
       
    20 * toolbar buttons
       
    21 *
       
    22 */
       
    23 
       
    24 #include "ToolbarSnippet.h"
       
    25 #include "ActionButtonSnippet.h"
       
    26 
       
    27 #include <QDebug>
       
    28 
       
    29 
       
    30 namespace GVA {
       
    31 
       
    32   ToolbarSnippet::ToolbarSnippet(const QString& elementId, ChromeWidget * chrome, const QWebElement & element)
       
    33                        : WebChromeContainerSnippet(elementId, chrome, element)
       
    34   {
       
    35 
       
    36       connect(m_chrome,  SIGNAL(chromeComplete()), this, SLOT(onChromeComplete()));
       
    37 
       
    38   }
       
    39 
       
    40   ToolbarSnippet::~ToolbarSnippet()
       
    41   {
       
    42       foreach(ToolbarActions_t * t, m_actionInfo) {
       
    43           delete t;
       
    44       }
       
    45 
       
    46   }
       
    47 
       
    48   void ToolbarSnippet::updateSize(QSize sz) {
       
    49       //qDebug() << "ToolbarSnippet::updateSize" << sz.width() ;
       
    50       setLayoutWidth(sz.width());
       
    51       WebChromeContainerSnippet::updateSize(sz);
       
    52   }
       
    53 
       
    54   void ToolbarSnippet::updateOwnerArea() {
       
    55 
       
    56     setLayoutWidth(m_chrome->layout()->size().width());
       
    57     WebChromeContainerSnippet::updateOwnerArea();
       
    58 
       
    59   }
       
    60 
       
    61   void ToolbarSnippet::onChromeComplete() {
       
    62 
       
    63       foreach(ToolbarActions_t * t, m_actionInfo) {
       
    64           setAction(m_chrome->getSnippet(t->id));
       
    65       }
       
    66 
       
    67   }
       
    68 
       
    69   void ToolbarSnippet::setAction(ChromeSnippet * s) {
       
    70 
       
    71       //qDebug() << "setAction: " << s->elementId() << m_actionInfo.size();
       
    72      
       
    73       ActionButtonSnippet * button  = static_cast<ActionButtonSnippet*> (s);
       
    74       int index = getIndex(s);
       
    75 
       
    76       if (index != -1) {
       
    77           ToolbarActions_t * t = m_actionInfo.at(index);
       
    78           button->connectAction(t->actionName, m_type);
       
    79 
       
    80           // Set the button icons if it has not been set for any state (we can do this through Javascript)
       
    81           //qDebug() << "setAction " << s->elementId() << button->icon().isNull();
       
    82           if (button->icon().isNull() ) {
       
    83               button->setIcon(t->normalImg);
       
    84               button->setDisabledIcon(t->disabledImg);
       
    85               button->setActiveIcon(t->activeImg);
       
    86           }
       
    87 
       
    88       }
       
    89   }
       
    90 
       
    91   int ToolbarSnippet::getIndex( ChromeSnippet *  s) {
       
    92       int index = -1;
       
    93       for (int i = 0; i < m_actionInfo.size() ; i++ ) {
       
    94 
       
    95           ToolbarActions_t * t = m_actionInfo.at(i);
       
    96           if (t->id == s->elementId()) {
       
    97               index = i;
       
    98               break;
       
    99           }
       
   100 
       
   101       }
       
   102       return index;
       
   103 
       
   104   }
       
   105 
       
   106   int ToolbarSnippet::getIndex( int actionId) {
       
   107       int index = -1;
       
   108       for (int i = 0; i < m_actionInfo.size() ; i++ ) {
       
   109 
       
   110           ToolbarActions_t * t = m_actionInfo.at(i);
       
   111           if (t->actionId == actionId ) {
       
   112               index = i;
       
   113               break;
       
   114           }
       
   115 
       
   116       }
       
   117       return index;
       
   118 
       
   119 
       
   120   }
       
   121 
       
   122   ActionButtonSnippet * ToolbarSnippet::getActionButtonSnippet( int  actionId) {
       
   123 
       
   124       int index = getIndex(actionId);
       
   125       ToolbarActions_t * t = m_actionInfo.at(index);
       
   126       ActionButtonSnippet * button  = static_cast<ActionButtonSnippet*> ( m_chrome->getSnippet(t->id));
       
   127       return button;
       
   128 
       
   129   }
       
   130 
       
   131 
       
   132 } // end of namespace GVA
       
   133 
       
   134