2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24 #include <QPropertyAnimation>
25 #include <QStateMachine>
27 #include "panelcommon.h"
29 #include "listitemcontextbuttonbar.h"
31 ListItemContextButtonBar::ListItemContextButtonBar(QWidget *parent) :
35 m_newContextButtons(0),
38 qDebug() << __PRETTY_FUNCTION__;
41 const int BAR_HEIGHT = 78;
42 setFixedHeight(BAR_HEIGHT);
44 m_backgroundLeft = new QPixmap(":/res/images/list_item_context_button_bar_left.png");
45 m_backgroundMiddle = new QPixmap(":/res/images/list_item_context_button_bar_tile.png");
46 m_backgroundRight = new QPixmap(":/res/images/list_item_context_button_bar_right.png");
49 const int ANIMATION_DURATION_MS = 150;
51 m_animation = new QPropertyAnimation(this, "pos", this);
52 m_animation->setDuration(ANIMATION_DURATION_MS);
54 connect(m_animation, SIGNAL(finished()),
55 this, SLOT(onAnimationFinished()));
58 ListItemContextButtonBar::~ListItemContextButtonBar()
60 qDebug() << __PRETTY_FUNCTION__;
63 delete m_backgroundLeft;
65 if (m_backgroundMiddle)
66 delete m_backgroundMiddle;
68 if (m_backgroundRight)
69 delete m_backgroundRight;
72 void ListItemContextButtonBar::changeButtons()
74 qDebug() << __PRETTY_FUNCTION__;
76 Q_ASSERT(m_animation->state() == QAbstractAnimation::Stopped);
78 // Hide previous buttons (if any)
80 m_contextButtons->setParent(0);
82 m_contextButtons = m_newContextButtons;
83 m_newContextButtons = 0;
84 m_contextButtons->setParent(this);
85 m_contextButtons->show();
86 setFixedSize(m_contextButtons->size());
88 // center this widget horizontally to middle of the panel contents area and set outside of
90 const int FROM_PANEL_CONTENTS_LEFT = PANEL_WIDTH / 2 - m_contextButtons->width() / 2;
91 move(PANEL_TAB_BAR_WIDTH + PANEL_BAR_WIDTH + FROM_PANEL_CONTENTS_LEFT, -size().height());
93 // update new target values for animations
94 m_animation->setStartValue(pos());
96 m_animation->setEndValue(QPoint(pos().x(), Y));
99 void ListItemContextButtonBar::hideContextButtonBar()
101 qDebug() << __PRETTY_FUNCTION__;
103 m_state = StateClosing;
104 m_animation->setDirection(QAbstractAnimation::Backward);
105 m_animation->start();
108 void ListItemContextButtonBar::onAnimationFinished()
110 qDebug() << __PRETTY_FUNCTION__;
112 if (m_animation->direction() == QAbstractAnimation::Backward) {
113 m_state = StateHidden;
114 if (m_newContextButtons) {
117 m_waitForOpen = false;
118 showContextButtonBar();
122 m_state = StateVisible;
126 void ListItemContextButtonBar::onListItemSelectionChanged(bool itemIsSelected)
128 qDebug() << __PRETTY_FUNCTION__;
130 if (itemIsSelected) {
131 if (m_newContextButtons)
132 m_waitForOpen = true;
133 else if (m_state != StateVisible)
134 showContextButtonBar();
136 if (m_newContextButtons)
137 m_waitForOpen = false;
138 else if (m_state != StateHidden)
139 hideContextButtonBar();
143 void ListItemContextButtonBar::paintEvent(QPaintEvent *event)
145 qDebug() << __PRETTY_FUNCTION__;
149 QPainter painter(this);
151 painter.drawPixmap(0, 0, *m_backgroundLeft);
152 painter.drawTiledPixmap(24, 0, width() - 2 * 24, 78, *m_backgroundMiddle);
153 painter.drawPixmap(width() - 24, 0, *m_backgroundRight);
156 void ListItemContextButtonBar::setContextButtons(QWidget *contextButtons)
158 qDebug() << __PRETTY_FUNCTION__;
160 m_newContextButtons = contextButtons;
161 m_waitForOpen = false;
163 if (m_state != StateHidden)
164 hideContextButtonBar();
169 void ListItemContextButtonBar::showContextButtonBar()
171 qDebug() << __PRETTY_FUNCTION__;
173 m_state = StateOpening;
174 m_animation->setDirection(QAbstractAnimation::Forward);
175 m_animation->start();