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 m_barLayout = new QHBoxLayout();
56 setLayout(m_barLayout);
57 m_barLayout->setContentsMargins(0, 0, 0, 0);
59 // --- SET POSITION ---
60 // center this widget horizontally to middle of the panel contents area and set outside of
62 const int FROM_PANEL_CONTENTS_LEFT = PANEL_WIDTH / 2 - width() / 2;
63 move(PANEL_TAB_BAR_WIDTH + PANEL_BAR_WIDTH + FROM_PANEL_CONTENTS_LEFT, -size().height());
66 const int ANIMATION_DURATION_MS = 150;
68 m_animation = new QPropertyAnimation(this, "pos", this);
69 m_animation->setDuration(ANIMATION_DURATION_MS);
71 connect(m_animation, SIGNAL(finished()),
72 this, SLOT(onAnimationFinished()));
74 // target values for animations
75 m_animation->setStartValue(pos());
77 m_animation->setEndValue(QPoint(pos().x(), Y));
80 ListItemContextButtonBar::~ListItemContextButtonBar()
82 qDebug() << __PRETTY_FUNCTION__;
85 delete m_backgroundLeft;
87 if (m_backgroundMiddle)
88 delete m_backgroundMiddle;
90 if (m_backgroundRight)
91 delete m_backgroundRight;
94 void ListItemContextButtonBar::changeButtons()
96 qDebug() << __PRETTY_FUNCTION__;
98 Q_ASSERT(m_animation->state() == QAbstractAnimation::Stopped);
103 // Remove old buttons (if any)
104 if (m_contextButtons) {
105 m_barLayout->removeWidget(m_contextButtons);
106 m_contextButtons->setParent(0);
109 m_contextButtons = m_newContextButtons;
110 m_newContextButtons = 0;
112 m_barLayout->addWidget(m_contextButtons, 0, Qt::AlignHCenter);
115 void ListItemContextButtonBar::hideContextButtonBar()
117 qDebug() << __PRETTY_FUNCTION__;
119 m_state = StateClosing;
120 m_animation->setDirection(QAbstractAnimation::Backward);
121 m_animation->start();
124 void ListItemContextButtonBar::onAnimationFinished()
126 qDebug() << __PRETTY_FUNCTION__;
128 if (m_animation->direction() == QAbstractAnimation::Backward) {
129 m_state = StateHidden;
130 if (m_newContextButtons) {
133 m_waitForOpen = false;
134 showContextButtonBar();
138 m_state = StateVisible;
142 void ListItemContextButtonBar::onListItemSelectionChanged(bool itemIsSelected)
144 qDebug() << __PRETTY_FUNCTION__;
146 if (itemIsSelected) {
147 if (m_newContextButtons)
148 m_waitForOpen = true;
149 else if (m_state != StateVisible)
150 showContextButtonBar();
152 if (m_newContextButtons)
153 m_waitForOpen = false;
154 else if (m_state != StateHidden)
155 hideContextButtonBar();
159 void ListItemContextButtonBar::paintEvent(QPaintEvent *event)
161 qDebug() << __PRETTY_FUNCTION__;
165 QPainter painter(this);
169 painter.drawPixmap(TOP, LEFT, *m_backgroundLeft);
170 painter.drawTiledPixmap(m_backgroundLeft->width(), TOP,
171 width() - m_backgroundLeft->width() - m_backgroundRight->width(),
173 *m_backgroundMiddle);
174 painter.drawPixmap(width() - m_backgroundRight->width(), TOP, *m_backgroundRight);
177 void ListItemContextButtonBar::setContextButtons(QWidget *contextButtons)
179 qDebug() << __PRETTY_FUNCTION__;
181 m_newContextButtons = contextButtons;
182 m_waitForOpen = false;
184 if (m_state != StateHidden)
185 hideContextButtonBar();
190 void ListItemContextButtonBar::showContextButtonBar()
192 qDebug() << __PRETTY_FUNCTION__;
194 if (m_contextButtons->layout()->count() > 0) {
195 m_state = StateOpening;
196 m_animation->setDirection(QAbstractAnimation::Forward);
197 m_animation->start();