ginebra2/WindowToolbarSnippet.cpp
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 6 1c3b8676e58c
child 15 73c48011b8c7
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
       
     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 ToolbarSnippet class to hold the
       
    20  * windows view toolbar buttons
       
    21  *
       
    22  */
       
    23 
       
    24 #include "WindowToolbarSnippet.h"
       
    25 #include "ToolbarChromeItem.h"
       
    26 #include "ViewStack.h"
       
    27 #include <QDebug>
       
    28 
       
    29 namespace GVA {
       
    30 
       
    31     WindowToolbarSnippet::WindowToolbarSnippet(const QString& elementId, ChromeWidget * chrome,
       
    32                                                const QWebElement & element)
       
    33         : DualButtonToolbarSnippet(elementId, chrome, element)
       
    34     {
       
    35         m_type = TOOLBAR_WINDOWS_VIEW;
       
    36     }
       
    37 
       
    38     WindowToolbarSnippet::~WindowToolbarSnippet()
       
    39     {
       
    40     }
       
    41 
       
    42     WindowToolbarSnippet * WindowToolbarSnippet::instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element)
       
    43     {
       
    44         WindowToolbarSnippet * that = new WindowToolbarSnippet(elementId, chrome, element);
       
    45         that->setChromeWidget(new ToolbarChromeItem(that));
       
    46         return that;
       
    47     }
       
    48     
       
    49     void WindowToolbarSnippet::addChild(ChromeSnippet * child) {
       
    50 
       
    51         WebChromeContainerSnippet * s =  dynamic_cast<WebChromeContainerSnippet* >(child);
       
    52         if (!s) {
       
    53             ToolbarActions_t* t = new ToolbarActions_t();
       
    54             if (child->elementId() == "WinBackButton" ) {
       
    55                 t->actionId = WINDOW_VIEW_ACTION_BACK;
       
    56                 t->actionName = WINDOW_TOOLBAR_BACK;
       
    57                 t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back.png";
       
    58                 t->disabledImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back_disabled.png";
       
    59                 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_back_pressed.png";
       
    60 
       
    61             }
       
    62             else if (child->elementId() == "WinAddWindow" ) {
       
    63                 t->actionId = WINDOW_VIEW_ACTION_ADD;
       
    64                 t->actionName = WINDOW_TOOLBAR_ADD;
       
    65                 t->normalImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_add.png";
       
    66                 t->disabledImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_add_disabled.png";
       
    67                 t->activeImg = ":/chrome/bedrockchrome/toolbar.snippet/icons/icon_add_pressed.png";
       
    68             }
       
    69             t->id = child->elementId();
       
    70             m_actionInfo.append(t);
       
    71         }
       
    72 
       
    73         WebChromeContainerSnippet::addChild(child);
       
    74     }
       
    75 
       
    76 
       
    77     void WindowToolbarSnippet::setAction(ChromeSnippet * s) {
       
    78 
       
    79         //qDebug() << "setAction: " << s->elementId();
       
    80         ToolbarSnippet::setAction(s);
       
    81 
       
    82         ActionButtonSnippet * button  = static_cast<ActionButtonSnippet*> (s);
       
    83         int index = getIndex(s);
       
    84 
       
    85         if (index != -1 ) {
       
    86             ToolbarActions_t * t = m_actionInfo.at(index);
       
    87             if (t->actionId == WINDOW_VIEW_ACTION_BACK ) {
       
    88 
       
    89                 QAction * action =  button->getDefaultAction();
       
    90                 connect(action, SIGNAL(triggered()), this, SLOT(handleBackButton()));
       
    91             }
       
    92         }
       
    93     }
       
    94 
       
    95     void WindowToolbarSnippet::handleBackButton() {
       
    96 
       
    97         ViewStack::getSingleton()->switchView( TOOLBAR_WEB_VIEW, TOOLBAR_WINDOWS_VIEW);
       
    98 
       
    99     }
       
   100 
       
   101 } // end of namespace GVA
       
   102 
       
   103