Added new scalable panels, deleted obsolite bitmaps and made some minor cosmetic...
[situare] / src / ui / panelsliderbar.cpp
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Kaj Wallin - kaj.wallin@ixonos.com
6         Pekka Nissinen - pekka.nissinen@ixonos.com
7
8     Situare is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License
10     version 2 as published by the Free Software Foundation.
11
12     Situare is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with Situare; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20     USA.
21 */
22
23 #include <QDebug>
24 #include <QPainter>
25 #include <QRegion>
26
27 #include "panelsliderbar.h"
28
29 PanelSliderBar::PanelSliderBar(QWidget *parent, Side side)
30     : QWidget(parent)
31 {
32     qDebug() << __PRETTY_FUNCTION__;
33
34     if (side == LEFT)
35         m_sliderButtonArrow.load(":res/images/arrow_right.png");
36     else if (side == RIGHT)
37         m_sliderButtonArrow.load(":res/images/arrow_left.png");
38     else
39         qFatal("Illegal PanelSliderBar 2nd argument");
40
41     m_sliderTile.load(":res/images/sliding_bar_tile.png");
42     m_sliderButton.load(":res/images/sliding_bar_button.png");
43     m_menuDropShadowTile.load(":res/images/menu_bar_drop_shadow.png");
44
45     m_buttonRect.setRect(0, (SLIDER_HEIGHT / 2) - (m_sliderButton.height() / 2),
46                        SLIDER_WIDTH, m_sliderButton.height());
47     m_topRect.setRect(SLIDER_BUTTON_OFFSET, 0, SLIDER_BAR_WIDTH, m_buttonRect.top());
48     m_bottomRect.setRect(SLIDER_BUTTON_OFFSET, m_buttonRect.bottom() + 1,
49                        SLIDER_BAR_WIDTH, SLIDER_HEIGHT - m_topRect.height() - m_buttonRect.height());
50
51     m_sliderRegion = QRegion(m_buttonRect).united(QRegion(m_topRect).united(QRegion(m_bottomRect)));
52     setMask(m_sliderRegion);
53
54     resize(SLIDER_WIDTH, SLIDER_HEIGHT);
55 }
56
57 void PanelSliderBar::paintEvent(QPaintEvent *)
58 {
59     qDebug() << __PRETTY_FUNCTION__;
60
61     QPainter painter(this);
62
63     painter.drawTiledPixmap(m_topRect, m_sliderTile);
64     painter.drawTiledPixmap(m_bottomRect, m_sliderTile);
65     painter.drawTiledPixmap(SLIDER_BUTTON_OFFSET, 0, SLIDER_BAR_WIDTH, m_menuDropShadowTile.height(),
66                             m_menuDropShadowTile);
67     painter.drawPixmap(m_buttonRect, m_sliderButton);
68     painter.drawPixmap((this->width() / 2) - (m_sliderButtonArrow.width() / 2),
69                        (this->height() / 2) - (m_sliderButtonArrow.height() / 2),
70                        m_sliderButtonArrow);
71 }
72
73 void PanelSliderBar::mouseReleaseEvent(QMouseEvent *)
74 {
75     qDebug() << __PRETTY_FUNCTION__;
76
77     emit clicked();
78 }
79
80 void PanelSliderBar::resizeSliderBar(const QSize &size)
81 {
82     qDebug() << __PRETTY_FUNCTION__;
83
84     m_buttonRect.setRect(0, (size.height() / 2) - (m_sliderButton.height() / 2),
85                        SLIDER_WIDTH, m_sliderButton.height());
86     m_topRect.setRect(SLIDER_BUTTON_OFFSET, 0, SLIDER_BAR_WIDTH, m_buttonRect.top());
87     m_bottomRect.setRect(SLIDER_BUTTON_OFFSET, m_buttonRect.bottom() + 1,
88                        SLIDER_BAR_WIDTH, size.height() - m_topRect.height() - m_buttonRect.height());
89
90     m_sliderRegion = QRegion(m_buttonRect).united(QRegion(m_topRect).united(QRegion(m_bottomRect)));
91     setMask(m_sliderRegion);
92
93     resize(SLIDER_WIDTH, size.height() - PANEL_TOP_PADDING - PANEL_BOTTOM_PADDING);
94 }