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);
81 // Hide previous buttons (if any)
83 m_contextButtons->setParent(0);
85 m_contextButtons = m_newContextButtons;
86 m_newContextButtons = 0;
87 m_contextButtons->setParent(this);
88 m_contextButtons->show();
89 setFixedWidth(m_contextButtons->width());
91 // center this widget horizontally to middle of the panel contents area and set outside of
93 const int FROM_PANEL_CONTENTS_LEFT = PANEL_WIDTH / 2 - m_contextButtons->width() / 2;
94 move(PANEL_TAB_BAR_WIDTH + PANEL_BAR_WIDTH + FROM_PANEL_CONTENTS_LEFT, -size().height());
96 // update new target values for animations
97 m_animation->setStartValue(pos());
99 m_animation->setEndValue(QPoint(pos().x(), Y));
102 void ListItemContextButtonBar::hideContextButtonBar()
104 qDebug() << __PRETTY_FUNCTION__;
106 m_state = StateClosing;
107 m_animation->setDirection(QAbstractAnimation::Backward);
108 m_animation->start();
111 void ListItemContextButtonBar::onAnimationFinished()
113 qDebug() << __PRETTY_FUNCTION__;
115 if (m_animation->direction() == QAbstractAnimation::Backward) {
116 m_state = StateHidden;
117 if (m_newContextButtons) {
120 m_waitForOpen = false;
121 showContextButtonBar();
125 m_state = StateVisible;
129 void ListItemContextButtonBar::onListItemSelectionChanged(bool itemIsSelected)
131 qDebug() << __PRETTY_FUNCTION__;
133 if (itemIsSelected) {
134 if (m_newContextButtons)
135 m_waitForOpen = true;
136 else if (m_state != StateVisible)
137 showContextButtonBar();
139 if (m_newContextButtons)
140 m_waitForOpen = false;
141 else if (m_state != StateHidden)
142 hideContextButtonBar();
146 void ListItemContextButtonBar::paintEvent(QPaintEvent *event)
148 qDebug() << __PRETTY_FUNCTION__;
152 QPainter painter(this);
156 painter.drawPixmap(TOP, LEFT, *m_backgroundLeft);
157 painter.drawTiledPixmap(m_backgroundLeft->width(), TOP,
158 width() - m_backgroundLeft->width() - m_backgroundRight->width(),
160 *m_backgroundMiddle);
161 painter.drawPixmap(width() - m_backgroundRight->width(), TOP, *m_backgroundRight);
164 void ListItemContextButtonBar::setContextButtons(QWidget *contextButtons)
166 qDebug() << __PRETTY_FUNCTION__;
168 m_newContextButtons = contextButtons;
169 m_waitForOpen = false;
171 if (m_state != StateHidden)
172 hideContextButtonBar();
177 void ListItemContextButtonBar::showContextButtonBar()
179 qDebug() << __PRETTY_FUNCTION__;
181 m_state = StateOpening;
182 m_animation->setDirection(QAbstractAnimation::Forward);
183 m_animation->start();