From cbd5d281e051fff81d9e3fa3acf4a4f7725dccb4 Mon Sep 17 00:00:00 2001 From: Adriano Rezende Date: Mon, 16 Nov 2009 11:41:25 -0300 Subject: HyperUI: Adjusted code to use shared classes Signed-off-by: Adriano Rezende --- hyperui/button.cpp | 118 -------------------------------------------------- hyperui/button.h | 74 ------------------------------- hyperui/global.cpp | 8 ++++ hyperui/global.h | 3 ++ hyperui/hyperui.pro | 15 ++++--- hyperui/label.cpp | 112 ----------------------------------------------- hyperui/label.h | 66 ---------------------------- hyperui/menuview.cpp | 3 +- hyperui/phoneview.cpp | 26 ++++++----- 9 files changed, 34 insertions(+), 391 deletions(-) delete mode 100644 hyperui/button.cpp delete mode 100644 hyperui/button.h delete mode 100644 hyperui/label.cpp delete mode 100644 hyperui/label.h diff --git a/hyperui/button.cpp b/hyperui/button.cpp deleted file mode 100644 index abc95f4..0000000 --- a/hyperui/button.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** -** -** 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 "global.h" -#include "button.h" - - -Button::Button(const QPixmap &normal, const QPixmap &pressed, - const QPixmap &disabled, QGraphicsItem *parent) - : QGraphicsWidget(parent), - m_isPressed(false), - m_normalPixmap(normal), - m_pressedPixmap(pressed), - m_disabledPixmap(disabled) -{ - setMinimumSize(normal.size()); - setMaximumSize(normal.size()); - - QFont font(Resource::stringValue("default/font-family")); - font.setBold(true); - font.setPixelSize(Resource::intValue("button/font-size")); - setFont(font); -} - -QString Button::text() const -{ - return m_text; -} - -void Button::setText(const QString &value) -{ - if (m_text != value) { - m_text = value; - update(); - } -} - -void Button::mousePressEvent(QGraphicsSceneMouseEvent *e) -{ - if (e->button() == Qt::LeftButton) { - m_isPressed = true; - update(); - emit pressed(); - } -} - -void Button::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) -{ - if (e->button() == Qt::LeftButton) { - const bool isClick = m_isPressed; - - m_isPressed = false; - update(); - emit released(); - - if (isClick && contains(e->pos())) - emit clicked(); - } -} - -void Button::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget) -{ - Q_UNUSED(widget); - - if (!(option->state & QStyle::State_Enabled)) { - const bool support = !m_disabledPixmap.isNull(); - painter->drawPixmap(0, 0, support ? m_disabledPixmap : m_normalPixmap); - } else if (m_isPressed && !m_pressedPixmap.isNull()) - painter->drawPixmap(0, 0, m_pressedPixmap); - else - painter->drawPixmap(0, 0, m_normalPixmap); - - - if (!m_text.isEmpty()) { - const QRect &textRect = boundingRect().toRect(); - - QFontMetrics metrics(font()); - const QString &elidedText = metrics.elidedText(m_text, Qt::ElideRight, - textRect.width()); - - painter->setFont(font()); - painter->setPen(Qt::white); - painter->drawText(textRect, Qt::TextSingleLine | Qt::AlignCenter, elidedText); - } -} diff --git a/hyperui/button.h b/hyperui/button.h deleted file mode 100644 index 6b023cc..0000000 --- a/hyperui/button.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef BUTTON_H -#define BUTTON_H - -#include -#include - -QT_BEGIN_NAMESPACE -class QGraphicsSceneMouseEvent; -QT_END_NAMESPACE - - -class Button : public QGraphicsWidget -{ - Q_OBJECT - -public: - Button(const QPixmap &normal, const QPixmap &pressed = QPixmap(), - const QPixmap &disabled = QPixmap(), QGraphicsItem *parent = 0); - - QString text() const; - void setText(const QString &value); - - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = 0); - -signals: - void clicked(); - void pressed(); - void released(); - -protected: - void mousePressEvent(QGraphicsSceneMouseEvent *e); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *e); - -private: - QString m_text; - bool m_isPressed; - QPixmap m_normalPixmap; - QPixmap m_pressedPixmap; - QPixmap m_disabledPixmap; -}; - -#endif diff --git a/hyperui/global.cpp b/hyperui/global.cpp index f8a49f0..dd2a9db 100644 --- a/hyperui/global.cpp +++ b/hyperui/global.cpp @@ -65,3 +65,11 @@ QString Resource::stringValue(const QString &key, const QString &value) { return Resource::value(key, value).toString(); } + +QFont Resource::buttonFont() +{ + QFont font(Resource::stringValue("default/font-family")); + font.setBold(true); + font.setPixelSize(Resource::intValue("button/font-size")); + return font; +} diff --git a/hyperui/global.h b/hyperui/global.h index 9315cb2..a36b487 100644 --- a/hyperui/global.h +++ b/hyperui/global.h @@ -32,6 +32,7 @@ #ifndef GLOBAL_H #define GLOBAL_H +#include #include #include #include @@ -42,6 +43,8 @@ class Resource public: static QPixmap pixmap(const QString &path); + static QFont buttonFont(); + static QVariant value(const QString &key, const QVariant &value = QVariant()); static int intValue(const QString &key, int value = 0); diff --git a/hyperui/hyperui.pro b/hyperui/hyperui.pro index d47c511..56b6579 100644 --- a/hyperui/hyperui.pro +++ b/hyperui/hyperui.pro @@ -1,7 +1,7 @@ TEMPLATE = app TARGET = hyperui DEPENDPATH += . -INCLUDEPATH += . +INCLUDEPATH += ../shared target.path = $$PREFIX/bin INSTALLS += target @@ -16,29 +16,30 @@ symbian { } HEADERS += mainwindow.h \ - button.h \ global.h \ pagemenu.h \ view.h \ pageview.h \ menuview.h \ phoneview.h \ - label.h \ draggablepreview.h \ - clockwidget.h + clockwidget.h \ + ../shared/button.h \ + ../shared/label.h + SOURCES += main.cpp \ mainwindow.cpp \ - button.cpp \ global.cpp \ pagemenu.cpp \ view.cpp \ pageview.cpp \ menuview.cpp \ phoneview.cpp \ - label.cpp \ draggablepreview.cpp \ - clockwidget.cpp + clockwidget.cpp \ + ../shared/button.cpp \ + ../shared/label.cpp isEmpty(RESOLUTION) { RESOLUTION = "800x480" diff --git a/hyperui/label.cpp b/hyperui/label.cpp deleted file mode 100644 index 14c9fbc..0000000 --- a/hyperui/label.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** 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 "global.h" -#include "label.h" - - -Label::Label(QGraphicsItem *parent) - : QGraphicsWidget(parent), - m_fontColor(Qt::white), - m_alignment(Qt::AlignLeft), - m_elideMode(Qt::ElideRight) -{ - setFont(QFont(Resource::stringValue("default/font-family"))); -} - -QString Label::text() const -{ - return m_text; -} - -void Label::setText(const QString &value) -{ - if (m_text != value) { - m_text = value; - update(); - } -} - -QColor Label::fontColor() const -{ - return m_fontColor; -} - -void Label::setFontColor(const QColor &color) -{ - if (m_fontColor != color) { - m_fontColor = color; - update(); - } -} - -Qt::TextElideMode Label::elideMode() const -{ - return m_elideMode; -} - -void Label::setElideMode(Qt::TextElideMode mode) -{ - if (m_elideMode != mode) { - m_elideMode = mode; - update(); - } -} - -void Label::setAlignment(Qt::Alignment alignment) -{ - if (m_alignment != alignment) { - m_alignment = alignment; - update(); - } -} - -void Label::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget) -{ - Q_UNUSED(option); - Q_UNUSED(widget); - - if (m_text.isEmpty()) - return; - - const QRect &textRect = boundingRect().toRect(); - - QFontMetrics metrics(font()); - const QString &elidedText = metrics.elidedText(m_text, m_elideMode, - textRect.width()); - - painter->setFont(font()); - painter->setPen(m_fontColor); - painter->drawText(textRect, Qt::TextSingleLine | m_alignment, elidedText); -} diff --git a/hyperui/label.h b/hyperui/label.h deleted file mode 100644 index ac89561..0000000 --- a/hyperui/label.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef LABEL_H -#define LABEL_H - -#include - - -class Label : public QGraphicsWidget -{ - Q_OBJECT - -public: - Label(QGraphicsItem *parent = 0); - - QString text() const; - void setText(const QString &value); - - QColor fontColor() const; - void setFontColor(const QColor &color); - - Qt::TextElideMode elideMode() const; - void setElideMode(Qt::TextElideMode mode); - - void setAlignment(Qt::Alignment alignment); - - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = 0); - -private: - QString m_text; - QColor m_fontColor; - Qt::Alignment m_alignment; - Qt::TextElideMode m_elideMode; -}; - -#endif diff --git a/hyperui/menuview.cpp b/hyperui/menuview.cpp index 0173b72..21e27c5 100644 --- a/hyperui/menuview.cpp +++ b/hyperui/menuview.cpp @@ -75,8 +75,7 @@ MenuView::MenuView(QGraphicsItem *parent) Button *MenuView::addIcon(const QPixmap &pixmap, const QPointF &pos, const char *slot) { - Button *button = new Button(pixmap); - button->setParentItem(this); + Button *button = new Button(pixmap, this); button->setPos(pos); if (slot) diff --git a/hyperui/phoneview.cpp b/hyperui/phoneview.cpp index 3664949..6a88456 100644 --- a/hyperui/phoneview.cpp +++ b/hyperui/phoneview.cpp @@ -123,6 +123,8 @@ void DialerWidget::addButton(const QString &label, int row, int col, Button *button = new Button(Resource::pixmap(normalPath), Resource::pixmap(pressedPath)); button->setText(label); + button->setFont(Resource::buttonFont()); + connect(button, SIGNAL(clicked()), SLOT(onButtonClicked())); m_layout->addItem(button, row, col); @@ -248,16 +250,16 @@ CallBoard::CallBoard(QGraphicsItem *parent) m_bigNameLabel->setFont(font); m_bigNameLabel->setGeometry(bigNameLabelRect); - Button *dialButton = new Button(Resource::pixmap("dialer_bt_dialer.png")); - dialButton->setParentItem(panelInCall); + Button *dialButton = new Button(Resource::pixmap("dialer_bt_dialer.png"), + panelInCall); dialButton->setPos(dialPos); - Button *muteButton = new Button(Resource::pixmap("dialer_bt_mute.png")); - muteButton->setParentItem(panelInCall); + Button *muteButton = new Button(Resource::pixmap("dialer_bt_mute.png"), + panelInCall); muteButton->setPos(mutePos); - Button *speakerButton = new Button(Resource::pixmap("dialer_bt_speaker.png")); - speakerButton->setParentItem(panelInCall); + Button *speakerButton = new Button(Resource::pixmap("dialer_bt_speaker.png"), + panelInCall); speakerButton->setPos(speakerPos); } @@ -417,25 +419,25 @@ PhoneView::PhoneView(QGraphicsItem *parent) m_display = new DialerDisplay(this); m_display->setPos(displayPos); - m_contactsButton = new Button(Resource::pixmap("dialer_bt_contacts.png")); - m_contactsButton->setParentItem(this); + m_contactsButton = new Button(Resource::pixmap("dialer_bt_contacts.png"), this); m_contactsButton->setPos(contactsButtonPos); + m_contactsButton->setFont(Resource::buttonFont()); m_overlay = new Overlay(this); m_overlay->setBrush(Qt::black); m_overlay->setRect(Resource::value("phone-view/overlay-rect").toRect()); m_callButton = new Button(Resource::pixmap("dialer_bt_call.png"), - Resource::pixmap("dialer_bt_call_over.png")); + Resource::pixmap("dialer_bt_call_over.png"), this); m_callButton->setText(tr("CALL")); - m_callButton->setParentItem(this); m_callButton->setPos(callButtonPos); + m_callButton->setFont(Resource::buttonFont()); m_endCallButton = new Button(Resource::pixmap("dialer_bt_endcall.png"), - Resource::pixmap("dialer_bt_endcall_over.png")); + Resource::pixmap("dialer_bt_endcall_over.png"), this); m_endCallButton->setText(tr("END CALL")); - m_endCallButton->setParentItem(this); m_endCallButton->setPos(callButtonPos); + m_endCallButton->setFont(Resource::buttonFont()); m_board = new CallBoard(this); m_board->setPos(dialerBackPos); -- cgit v1.2.3