diff options
author | Luiz Agostini <luiz.agostini@openbossa.org> | 2009-11-03 20:53:52 -0300 |
---|---|---|
committer | Luiz Agostini <luiz.agostini@openbossa.org> | 2009-11-05 00:42:09 -0300 |
commit | d972a0c6058340e172f9de2b80efda224ea48bee (patch) | |
tree | d999cf231528f290562fe9e1cd49fc282b85a449 /weather | |
parent | 6ba6816c834d050b8e9a1309c01491d11ab8c269 (diff) |
Weather: scroll bar.
Signed-off-by: Luiz Agostini <luiz.agostini@openbossa.org>
Diffstat (limited to 'weather')
-rw-r--r-- | weather/bootmanager.cpp | 2 | ||||
-rw-r--r-- | weather/images/ui_elements/scroll.png | bin | 281 -> 0 bytes | |||
-rw-r--r-- | weather/images/weather_elements/scroll.png | bin | 0 -> 19088 bytes | |||
-rw-r--r-- | weather/images/weather_elements/scroll_knob.png (renamed from weather/images/ui_elements/scroll_knob.png) | bin | 246 -> 246 bytes | |||
-rw-r--r-- | weather/resources.qrc | 2 | ||||
-rw-r--r-- | weather/scrollbar.cpp | 100 | ||||
-rw-r--r-- | weather/scrollbar.h | 65 | ||||
-rw-r--r-- | weather/weather.pro | 6 |
8 files changed, 173 insertions, 2 deletions
diff --git a/weather/bootmanager.cpp b/weather/bootmanager.cpp index 0280cbe..dbe2da6 100644 --- a/weather/bootmanager.cpp +++ b/weather/bootmanager.cpp @@ -9,6 +9,7 @@ #include "cityinfodisplay.h" #include "titlebar.h" #include "citycarroussel.h" +#include "scrollbar.h" #include <QDebug> @@ -34,6 +35,7 @@ void BootManager::run() count += CityInfoDisplay::loadImages(); count += TitleBar::loadImages(); count += CityCarroussel::loadImages(); + count += ScrollBar::loadImages(); m_imagesLoaded = count == 0; if (m_imagesLoaded) diff --git a/weather/images/ui_elements/scroll.png b/weather/images/ui_elements/scroll.png Binary files differdeleted file mode 100644 index 376e223..0000000 --- a/weather/images/ui_elements/scroll.png +++ /dev/null diff --git a/weather/images/weather_elements/scroll.png b/weather/images/weather_elements/scroll.png Binary files differnew file mode 100644 index 0000000..ff83da6 --- /dev/null +++ b/weather/images/weather_elements/scroll.png diff --git a/weather/images/ui_elements/scroll_knob.png b/weather/images/weather_elements/scroll_knob.png Binary files differindex 9a6bc28..9a6bc28 100644 --- a/weather/images/ui_elements/scroll_knob.png +++ b/weather/images/weather_elements/scroll_knob.png diff --git a/weather/resources.qrc b/weather/resources.qrc index d46c599..c2adf4d 100644 --- a/weather/resources.qrc +++ b/weather/resources.qrc @@ -95,5 +95,7 @@ <file>images/weather_elements/list_item_selected_bg.png</file> <file>images/weather_elements/textfield_add_city.png</file> <file>images/weather_elements/list_top.png</file> + <file>images/weather_elements/scroll.png</file> + <file>images/weather_elements/scroll_knob.png</file> </qresource> </RCC> diff --git a/weather/scrollbar.cpp b/weather/scrollbar.cpp new file mode 100644 index 0000000..5fc1264 --- /dev/null +++ b/weather/scrollbar.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** 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 <QPropertyAnimation> +#include <QDebug> + +#include "scrollbar.h" +#include "pixmaploader.h" + +ScrollBar::ScrollBar(QGraphicsItem* parent) + : QGraphicsPixmapItem(PixmapLoader::getPic("scroll"), parent) + , m_knob(PixmapLoader::getPic("scroll_knob"), this) + , m_height(pixmap().height() - m_knob.pixmap().height()) + , m_value(0.0) + , m_visible(false) +{ + hide(); + setOpacity(0.0); + m_knob.setPos(0.0, 0.0); + m_timer.setSingleShot(true); + m_timer.setInterval(1000); + + connect(&m_timer, SIGNAL(timeout()), this, SLOT(timeout())); +} + +int ScrollBar::loadImages() +{ + PixmapLoader::load("scroll"); + PixmapLoader::load("scroll_knob"); + return 2; +} +bool ScrollBar::startAnimation(bool show) +{ + if (show == m_visible) + return false; + + m_visible = show; + m_timer.stop(); + + if (m_animation) + m_animation->stop(); + + QPropertyAnimation* animation = new QPropertyAnimation(this, "opacity"); + animation->setEasingCurve(QEasingCurve::OutExpo); + animation->setDuration(500); + animation->setEndValue(show ? 1.0 : 0.0); + + if (show) + connect(animation, SIGNAL(finished()), &m_timer, SLOT(start())); + else + connect(animation, SIGNAL(finished()), this, SLOT(hideScrollBar())); + + m_animation = animation; + animation->start(QAbstractAnimation::DeleteWhenStopped); + return true; +} + +void ScrollBar::setValue(qreal value) +{ + if (value < 0 || value > 1.0) + return; + m_value = value; + m_knob.setPos(0, m_value * m_height); + + show(); + if (!startAnimation(true)) + m_timer.start(); +} + + + + diff --git a/weather/scrollbar.h b/weather/scrollbar.h new file mode 100644 index 0000000..fb509d7 --- /dev/null +++ b/weather/scrollbar.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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 SCROLLBAR_H +#define SCROLLBAR_H + +#include <QTimer> +#include <QPointer> +#include <QGraphicsPixmapItem> +#include <QAbstractAnimation> + +class ScrollBar: public QObject, public QGraphicsPixmapItem +{ + Q_OBJECT + Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity); +public: + ScrollBar(QGraphicsItem* parent = 0); + qreal value() const { return m_value; } + void setValue(qreal); + static int loadImages(); + +private slots: + void timeout() { startAnimation(false); } + void hideScrollBar() { hide(); } + +private: + QGraphicsPixmapItem m_knob; + const qreal m_height; + qreal m_value; + QTimer m_timer; + QPointer<QAbstractAnimation> m_animation; + bool m_visible; + + bool startAnimation(bool show); +}; + +#endif /* SCROLLBAR_H */ diff --git a/weather/weather.pro b/weather/weather.pro index 7f73e2b..218579d 100644 --- a/weather/weather.pro +++ b/weather/weather.pro @@ -44,7 +44,8 @@ HEADERS += mainview.h \ forecastprovider.h \ forecastdata.h \ bootmanager.h \ - pixmapbutton.h + pixmapbutton.h \ + scrollbar.h SOURCES += mainview.cpp \ main.cpp \ settings.cpp \ @@ -61,4 +62,5 @@ SOURCES += mainview.cpp \ loading.cpp \ forecastprovider.cpp \ bootmanager.cpp \ - pixmapbutton.cpp + pixmapbutton.cpp \ + scrollbar.cpp |