2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Pekka Nissinen - pekka.nissinen@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 <QSignalTransition>
26 #include <QStateMachine>
28 #include "panelcontextbuttonbar.h"
30 const int PANEL_CONTEXT_BUTTON_BAR_WIDTH = 78;
32 PanelContextButtonBar::PanelContextButtonBar(QWidget *parent)
37 qDebug() << __PRETTY_FUNCTION__;
39 setFixedWidth(PANEL_CONTEXT_BUTTON_BAR_WIDTH);
41 m_barTile.load(":/res/images/panel_context_button_bar_tile.png");
42 m_barTop.load(":/res/images/panel_context_button_bar_top.png");
44 // --- BAR ANIMATION ---
45 QStateMachine *stateMachine = new QStateMachine(this);
47 m_stateHidden = new QState(stateMachine);
48 m_stateVisible = new QState(stateMachine);
50 QPropertyAnimation *animation = new QPropertyAnimation(this, "pos", this);
52 stateMachine->setInitialState(m_stateHidden);
54 QSignalTransition *showSignalTransition = m_stateHidden->addTransition(this,
55 SIGNAL(toggleState()),
57 showSignalTransition->addAnimation(animation);
59 QSignalTransition *hideSignalTransition = m_stateVisible->addTransition(this,
60 SIGNAL(toggleState()),
62 hideSignalTransition->addAnimation(animation);
64 connect(animation, SIGNAL(finished()),
65 this, SLOT(contextButtonBarStateChanged()));
67 QPoint hiddenPosition(pos().x(), pos().y());
68 m_stateHidden->assignProperty(this, "pos", hiddenPosition);
70 QPoint visiblePosition(pos().x(), pos().y() - height());
71 m_stateVisible->assignProperty(this, "pos", visiblePosition);
73 stateMachine->start();
76 void PanelContextButtonBar::contextButtonBarStateChanged()
78 qDebug() << __PRETTY_FUNCTION__;
86 void PanelContextButtonBar::hideContextButtonBar()
88 qDebug() << __PRETTY_FUNCTION__;
96 bool PanelContextButtonBar::isBarVisible() const
98 qDebug() << __PRETTY_FUNCTION__;
103 void PanelContextButtonBar::move(int x, int y)
105 qDebug() << __PRETTY_FUNCTION__;
108 QWidget::move(x, y - height());
112 QPoint hiddenPosition(x, y);
113 m_stateHidden->assignProperty(this, "pos", hiddenPosition);
115 QPoint visiblePosition(x, y - height());
116 m_stateVisible->assignProperty(this, "pos", visiblePosition);
119 void PanelContextButtonBar::paintEvent(QPaintEvent *event)
121 qDebug() << __PRETTY_FUNCTION__;
125 const int CONTEXT_BUTTON_BAR_RECT_X = 0;
126 const int CONTEXT_BUTTON_BAR_TOP_HEIGHT = 32;
127 const int CONTEXT_BUTTON_BAR_TOP_X = 0;
128 const int CONTEXT_BUTTON_BAR_TOP_Y = 0;
130 QPainter painter(this);
132 m_barRect.setRect(CONTEXT_BUTTON_BAR_RECT_X, CONTEXT_BUTTON_BAR_TOP_HEIGHT,
133 PANEL_CONTEXT_BUTTON_BAR_WIDTH, height() - CONTEXT_BUTTON_BAR_TOP_HEIGHT);
135 painter.drawPixmap(CONTEXT_BUTTON_BAR_TOP_X, CONTEXT_BUTTON_BAR_TOP_Y, m_barTop);
136 painter.drawTiledPixmap(m_barRect, m_barTile);
139 void PanelContextButtonBar::setContextButtons(QWidget *contextButtons)
141 qDebug() << __PRETTY_FUNCTION__;
143 // Hide previous buttons (if any)
144 if (m_contextButtons)
145 m_contextButtons->setParent(0);
147 m_contextButtons = contextButtons;
149 m_contextButtons->setParent(this);
150 m_contextButtons->setVisible(true);
152 setFixedHeight(m_contextButtons->height());
154 emit positionChangeRequested();
157 void PanelContextButtonBar::showContextButtonBar()
159 qDebug() << __PRETTY_FUNCTION__;