diff -r b0dd75e285d2 -r 0f2326c2a325 ginebra2/ToolbarSnippet.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ginebra2/ToolbarSnippet.cpp Wed Jun 23 17:59:43 2010 +0300 @@ -0,0 +1,137 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* +* 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. +* +* 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. +* +* 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: +* This class extends WebChromeContainerSnippet class to hold the +* toolbar buttons +* +*/ + +#include "ToolbarSnippet.h" +#include "ActionButtonSnippet.h" + +#include + + +namespace GVA { + + ToolbarSnippet::ToolbarSnippet(const QString& elementId, ChromeWidget * chrome, const QRectF& ownerArea, const QWebElement & element, QGraphicsWidget * widget) + : WebChromeContainerSnippet(elementId, chrome, ownerArea, element, widget) + { + + connect(m_chrome, SIGNAL(chromeComplete()), this, SLOT(onChromeComplete())); + + } + + ToolbarSnippet::~ToolbarSnippet() + { + foreach(ToolbarActions_t * t, m_actionInfo) { + delete t; + } + + } + + void ToolbarSnippet::updateSize(QSize sz) { + //qDebug() << "ToolbarSnippet::updateSize" << sz.width() ; + setLayoutWidth(sz.width()); + WebChromeContainerSnippet::updateSize(sz); + } + + void ToolbarSnippet::updateOwnerArea() { + + setLayoutWidth(m_chrome->width()); + WebChromeContainerSnippet::updateOwnerArea(); + + } + + void ToolbarSnippet::onChromeComplete() { + + foreach(ToolbarActions_t * t, m_actionInfo) { + setAction(m_chrome->getSnippet(t->id)); + } + + } + + void ToolbarSnippet::setAction(ChromeSnippet * s) { + + //qDebug() << "setAction: " << s->elementId() << m_actionInfo.size(); + ChromeItem * item = static_cast(s->widget()); + + bool res = connect(item, SIGNAL(mouseEvent( QEvent::Type )), this, SLOT(onMouseEvent(QEvent::Type))); + + ActionButtonSnippet * button = static_cast (s); + int index = getIndex(s); + + if (index != -1) { + ToolbarActions_t * t = m_actionInfo.at(index); + button->connectAction(t->actionName, m_type); + + // Set the button icons if it has not been set for any state (we can do this through Javascript) + //qDebug() << "setAction " << s->elementId() << button->icon().isNull(); + if (button->icon().isNull() ) { + button->setIcon(t->activeImg); + button->setDisabledIcon(t->disabledImg); + button->setSelectedIcon(t->selectedImg); + } + + } + } + + int ToolbarSnippet::getIndex( ChromeSnippet * s) { + int index = -1; + for (int i = 0; i < m_actionInfo.size() ; i++ ) { + + ToolbarActions_t * t = m_actionInfo.at(i); + if (t->id == s->elementId()) { + index = i; + break; + } + + } + return index; + + } + + int ToolbarSnippet::getIndex( int actionId) { + int index = -1; + for (int i = 0; i < m_actionInfo.size() ; i++ ) { + + ToolbarActions_t * t = m_actionInfo.at(i); + if (t->actionId == actionId ) { + index = i; + break; + } + + } + return index; + + + } + + ActionButtonSnippet * ToolbarSnippet::getActionButtonSnippet( int actionId) { + + int index = getIndex(actionId); + ToolbarActions_t * t = m_actionInfo.at(index); + ActionButtonSnippet * button = static_cast ( m_chrome->getSnippet(t->id)); + return button; + + } + + +} // end of namespace GVA + +