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(this->pos().x(), this->pos().y());
68 m_stateHidden->assignProperty(this, "pos", hiddenPosition);
70 QPoint visiblePosition(this->pos().x(), this->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::paintEvent(QPaintEvent *event)
105 qDebug() << __PRETTY_FUNCTION__;
109 const int CONTEXT_BUTTON_BAR_RECT_X = 0;
110 const int CONTEXT_BUTTON_BAR_TOP_HEIGHT = 32;
111 const int CONTEXT_BUTTON_BAR_TOP_X = 0;
112 const int CONTEXT_BUTTON_BAR_TOP_Y = 0;
114 QPainter painter(this);
116 m_barRect.setRect(CONTEXT_BUTTON_BAR_RECT_X, CONTEXT_BUTTON_BAR_TOP_HEIGHT,
117 PANEL_CONTEXT_BUTTON_BAR_WIDTH, height() - CONTEXT_BUTTON_BAR_TOP_HEIGHT);
119 painter.drawPixmap(CONTEXT_BUTTON_BAR_TOP_X, CONTEXT_BUTTON_BAR_TOP_Y, m_barTop);
120 painter.drawTiledPixmap(m_barRect, m_barTile);
124 void PanelContextButtonBar::move(int x, int y)
126 qDebug() << __PRETTY_FUNCTION__;
129 QWidget::move(x, y - height());
133 QPoint hiddenPosition(x, y);
134 m_stateHidden->assignProperty(this, "pos", hiddenPosition);
136 QPoint visiblePosition(x, y - height());
137 m_stateVisible->assignProperty(this, "pos", visiblePosition);
140 void PanelContextButtonBar::resizeEvent(QResizeEvent *event)
142 qDebug() << __PRETTY_FUNCTION__;
144 QWidget::resizeEvent(event);
146 QPoint visiblePosition(pos().x(), pos().y() - height());
147 m_stateVisible->assignProperty(this, "pos", visiblePosition);
150 void PanelContextButtonBar::setContextButtons(QWidget *contextButtons)
152 qDebug() << __PRETTY_FUNCTION__;
154 // Hide previous buttons (if any)
155 if (m_contextButtons)
156 m_contextButtons->setParent(0);
158 m_contextButtons = contextButtons;
160 m_contextButtons->setParent(this);
161 m_contextButtons->setVisible(true);
163 setFixedHeight(m_contextButtons->height());
166 void PanelContextButtonBar::showContextButtonBar()
168 qDebug() << __PRETTY_FUNCTION__;