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,
23 #include <QPropertyAnimation>
24 #include <QStateMachine>
26 #include "panelcommon.h"
28 #include "listitemcontextbuttonbar.h"
30 ListItemContextButtonBar::ListItemContextButtonBar(QWidget *parent) :
34 m_newContextButtons(0),
37 qDebug() << __PRETTY_FUNCTION__;
39 const int ANIMATION_DURATION_MS = 150;
41 m_animation = new QPropertyAnimation(this, "pos", this);
42 m_animation->setDuration(ANIMATION_DURATION_MS);
44 connect(m_animation, SIGNAL(finished()),
45 this, SLOT(onAnimationFinished()));
48 void ListItemContextButtonBar::changeButtons()
50 qDebug() << __PRETTY_FUNCTION__;
52 Q_ASSERT(m_animation->state() == QAbstractAnimation::Stopped);
54 // Hide previous buttons (if any)
56 m_contextButtons->setParent(0);
58 m_contextButtons = m_newContextButtons;
59 m_newContextButtons = 0;
60 m_contextButtons->setParent(this);
61 m_contextButtons->show();
62 setFixedSize(m_contextButtons->size());
64 // center this widget horizontally to middle of the panel contents area and set outside of
66 const int FROM_PANEL_CONTENTS_LEFT = PANEL_WIDTH / 2 - m_contextButtons->width() / 2;
67 move(PANEL_TAB_BAR_WIDTH + PANEL_BAR_WIDTH + FROM_PANEL_CONTENTS_LEFT, -size().height());
69 // update new target values for animations
70 m_animation->setStartValue(pos());
72 m_animation->setEndValue(QPoint(pos().x(), Y));
75 void ListItemContextButtonBar::hideContextButtonBar()
77 qDebug() << __PRETTY_FUNCTION__;
79 m_state = StateClosing;
80 m_animation->setDirection(QAbstractAnimation::Backward);
84 void ListItemContextButtonBar::onAnimationFinished()
86 qDebug() << __PRETTY_FUNCTION__;
88 if (m_animation->direction() == QAbstractAnimation::Backward) {
89 m_state = StateHidden;
90 if (m_newContextButtons) {
93 m_waitForOpen = false;
94 showContextButtonBar();
98 m_state = StateVisible;
102 void ListItemContextButtonBar::onListItemSelectionChanged(bool itemIsSelected)
104 qDebug() << __PRETTY_FUNCTION__;
106 if (itemIsSelected) {
107 if (m_newContextButtons)
108 m_waitForOpen = true;
109 else if (m_state != StateVisible)
110 showContextButtonBar();
112 if (m_newContextButtons)
113 m_waitForOpen = false;
114 else if (m_state != StateHidden)
115 hideContextButtonBar();
119 void ListItemContextButtonBar::setContextButtons(QWidget *contextButtons)
121 qDebug() << __PRETTY_FUNCTION__;
123 m_newContextButtons = contextButtons;
124 m_waitForOpen = false;
126 if (m_state != StateHidden)
127 hideContextButtonBar();
132 void ListItemContextButtonBar::showContextButtonBar()
134 qDebug() << __PRETTY_FUNCTION__;
136 m_state = StateOpening;
137 m_animation->setDirection(QAbstractAnimation::Forward);
138 m_animation->start();