Web page updated.
[jspeed] / src / toolbaritem.cpp
1 /*
2  * This file is part of jSpeed.
3  *
4  * jSpeed is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * jSpeed is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with jSpeed.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  */
18
19 #include <QtCore/QString>
20 #include <QtCore/QDebug>
21 #include <QtGui/QGraphicsSceneMouseEvent>
22 #include "toolbaritem.h"
23
24 ToolbarItem::ToolbarItem(QString const& filename, QString const& activeFilename, QGraphicsItem *parent):
25 QGraphicsPixmapItem(parent), active_(false)
26 {
27     pixmap_.load(filename);
28     activePixmap_.load(activeFilename);
29     setPixmap(pixmap_);
30 }
31
32 void ToolbarItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
33 {
34     Q_UNUSED(event);
35     setPixmap(activePixmap_);
36     active_ = true;
37 }
38
39 void ToolbarItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
40 {
41     Q_UNUSED(event);
42
43     if(active_)
44     {
45         active_ = false;
46         setPixmap(pixmap_);
47         update();
48         emit clicked();
49     }
50 }
51
52 void ToolbarItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
53 {
54     QPointF pos = event->pos();
55     qreal x = pos.x();
56     qreal y = pos.y();
57
58     if(active_ && (x < 0 || y < 0 || x > activePixmap_.width() || y > activePixmap_.height()))
59     {
60         active_ = false;
61         setPixmap(pixmap_);
62     }
63 }
64