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,
25 #include <QPropertyAnimation>
26 #include <QStateMachine>
28 #include "panelcommon.h"
30 #include "listitemcontextbuttonbar.h"
32 ListItemContextButtonBar::ListItemContextButtonBar(QWidget *parent) :
36 m_newContextButtons(0),
39 qDebug() << __PRETTY_FUNCTION__;
42 const int BAR_HEIGHT = 78;
43 setFixedHeight(BAR_HEIGHT);
45 const int BUTTON_WIDTH = 74;
46 const int BUTTON_COUNT = 3;
47 const int HORIZONTAL_MARGIN = 10;
48 setFixedWidth(BUTTON_COUNT * BUTTON_WIDTH + 2 * HORIZONTAL_MARGIN);
50 m_backgroundLeft = new QPixmap(":/res/images/list_item_context_button_bar_left.png");
51 m_backgroundMiddle = new QPixmap(":/res/images/list_item_context_button_bar_tile.png");
52 m_backgroundRight = new QPixmap(":/res/images/list_item_context_button_bar_right.png");
55 const int ANIMATION_DURATION_MS = 150;
57 m_animation = new QPropertyAnimation(this, "pos", this);
58 m_animation->setDuration(ANIMATION_DURATION_MS);
60 connect(m_animation, SIGNAL(finished()),
61 this, SLOT(onAnimationFinished()));
64 ListItemContextButtonBar::~ListItemContextButtonBar()
66 qDebug() << __PRETTY_FUNCTION__;
69 delete m_backgroundLeft;
71 if (m_backgroundMiddle)
72 delete m_backgroundMiddle;
74 if (m_backgroundRight)
75 delete m_backgroundRight;
78 void ListItemContextButtonBar::changeButtons()
80 qDebug() << __PRETTY_FUNCTION__;
82 Q_ASSERT(m_animation->state() == QAbstractAnimation::Stopped);
87 // Hide previous buttons (if any)
89 m_contextButtons->setParent(0);
91 m_contextButtons = m_newContextButtons;
92 m_newContextButtons = 0;
93 m_contextButtons->setParent(this);
94 m_contextButtons->show();
95 // setFixedWidth(m_contextButtons->width());
97 // center this widget horizontally to middle of the panel contents area and set outside of
99 const int FROM_PANEL_CONTENTS_LEFT = PANEL_WIDTH / 2 - width() / 2;
100 move(PANEL_TAB_BAR_WIDTH + PANEL_BAR_WIDTH + FROM_PANEL_CONTENTS_LEFT, -size().height());
102 // update new target values for animations
103 m_animation->setStartValue(pos());
105 m_animation->setEndValue(QPoint(pos().x(), Y));
108 void ListItemContextButtonBar::hideContextButtonBar()
110 qDebug() << __PRETTY_FUNCTION__;
112 m_state = StateClosing;
113 m_animation->setDirection(QAbstractAnimation::Backward);
114 m_animation->start();
117 void ListItemContextButtonBar::onAnimationFinished()
119 qDebug() << __PRETTY_FUNCTION__;
121 if (m_animation->direction() == QAbstractAnimation::Backward) {
122 m_state = StateHidden;
123 if (m_newContextButtons) {
126 m_waitForOpen = false;
127 showContextButtonBar();
131 m_state = StateVisible;
135 void ListItemContextButtonBar::onListItemSelectionChanged(bool itemIsSelected)
137 qDebug() << __PRETTY_FUNCTION__;
139 if (itemIsSelected) {
140 if (m_newContextButtons)
141 m_waitForOpen = true;
142 else if (m_state != StateVisible)
143 showContextButtonBar();
145 if (m_newContextButtons)
146 m_waitForOpen = false;
147 else if (m_state != StateHidden)
148 hideContextButtonBar();
152 void ListItemContextButtonBar::paintEvent(QPaintEvent *event)
154 qDebug() << __PRETTY_FUNCTION__;
158 QPainter painter(this);
162 painter.drawPixmap(TOP, LEFT, *m_backgroundLeft);
163 painter.drawTiledPixmap(m_backgroundLeft->width(), TOP,
164 width() - m_backgroundLeft->width() - m_backgroundRight->width(),
166 *m_backgroundMiddle);
167 painter.drawPixmap(width() - m_backgroundRight->width(), TOP, *m_backgroundRight);
170 void ListItemContextButtonBar::setContextButtons(QWidget *contextButtons)
172 qDebug() << __PRETTY_FUNCTION__;
174 m_newContextButtons = contextButtons;
175 m_waitForOpen = false;
177 if (m_state != StateHidden)
178 hideContextButtonBar();
183 void ListItemContextButtonBar::showContextButtonBar()
185 qDebug() << __PRETTY_FUNCTION__;
187 if (m_contextButtons->layout()->count() > 0) {
188 m_state = StateOpening;
189 m_animation->setDirection(QAbstractAnimation::Forward);
190 m_animation->start();