/**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: openBossa - INdT (renato.chencarek@openbossa.org) ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage ** This file contains pre-release code and may not be distributed. ** You may use this file in accordance with the terms and conditions ** contained in the Technology Preview License Agreement accompanying ** this package. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** If you have questions regarding the use of this file, please contact ** the openBossa stream from INdT (renato.chencarek@openbossa.org). ** $QT_END_LICENSE$ ** ****************************************************************************/ #include #include #include #include #include #include #include #include #include #include "dataresource.h" #include "label.h" #include "button.h" #include "phoneview.h" static QFont resourceButtonFont() { QFont font(Resource::stringValue("default/font-family")); font.setBold(true); font.setPixelSize(Resource::intValue("button/font-size")); return font; } class Overlay : public QObject, public QGraphicsRectItem { Q_OBJECT Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity) Q_PROPERTY(bool visible READ isVisible WRITE setVisible) public: Overlay(QGraphicsItem *parent = 0) : QGraphicsRectItem(parent) {} protected: void mousePressEvent(QGraphicsSceneMouseEvent *) { } }; class DialerWidget : public QGraphicsWidget { Q_OBJECT public: DialerWidget(QGraphicsItem *parent = 0); signals: void buttonClicked(const QString &value); protected: void addButton(const QString &label, int row, int col, const QString &imagePrefix); private slots: void onButtonClicked(); private: QGraphicsGridLayout *m_layout; }; DialerWidget::DialerWidget(QGraphicsItem *parent) : QGraphicsWidget(parent) { QGraphicsPixmapItem *background = new QGraphicsPixmapItem(Resource::pixmap("dialer/background.png"), this); background->setPos(0, 0); background->setShapeMode(QGraphicsPixmapItem::BoundingRectShape); const int margin = Resource::intValue("dialer-widget/margin"); const int spacing = Resource::intValue("dialer-widget/spacing"); m_layout = new QGraphicsGridLayout(); m_layout->setSpacing(spacing); m_layout->setContentsMargins(margin, margin, margin, margin); addButton("1", 0, 0, "dialer/top_left_key"); addButton("2", 0, 1, "dialer/middle_key"); addButton("3", 0, 2, "dialer/top_right_key"); addButton("4", 1, 0, "dialer/middle_key"); addButton("5", 1, 1, "dialer/middle_key"); addButton("6", 1, 2, "dialer/middle_key"); addButton("7", 2, 0, "dialer/middle_key"); addButton("8", 2, 1, "dialer/middle_key"); addButton("9", 2, 2, "dialer/middle_key"); addButton("*", 3, 0, "dialer/bottom_left_key"); addButton("0", 3, 1, "dialer/middle_key"); addButton("#", 3, 2, "dialer/bottom_right_key"); setLayout(m_layout); } void DialerWidget::addButton(const QString &label, int row, int col, const QString &imagePrefix) { const QString &normalPath = QString("%1.png").arg(imagePrefix); const QString &pressedPath = QString("%1_pressed.png").arg(imagePrefix); Button *button = new Button(Resource::pixmap(normalPath), Resource::pixmap(pressedPath)); button->setText(label); button->setFont(resourceButtonFont()); connect(button, SIGNAL(clicked()), SLOT(onButtonClicked())); m_layout->addItem(button, row, col); } void DialerWidget::onButtonClicked() { Button *button = dynamic_cast