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,
25 #include <QAbstractButton>
27 #include "imagebutton.h"
29 ImageButton::ImageButton(QWidget *parent, QString normalIconPictureFileName,
30 QString selectedIconPictureFileName)
31 : QPushButton(parent),
32 m_buttonMode(QIcon::Normal)
34 qDebug() << __PRETTY_FUNCTION__;
36 QPixmap iconPixmap(normalIconPictureFileName);
37 m_buttonSize = iconPixmap.size(); // Get the button size from the normal state icon picture
38 QIcon icon(iconPixmap);
40 // If there is a picture for selected state, use it instead of a simple highlight change
41 if(selectedIconPictureFileName != "")
42 icon.addFile(selectedIconPictureFileName, m_buttonSize, QIcon::Selected);
45 setIconSize(m_buttonSize);
46 setFixedSize(m_buttonSize);
49 void ImageButton::mousePressEvent(QMouseEvent *event)
51 qDebug() << __PRETTY_FUNCTION__;
53 QAbstractButton::mousePressEvent(event);
55 m_buttonMode = QIcon::Selected;
59 void ImageButton::mouseReleaseEvent(QMouseEvent *event)
61 qDebug() << __PRETTY_FUNCTION__;
63 QAbstractButton::mouseReleaseEvent(event);
65 m_buttonMode = QIcon::Normal;
69 void ImageButton::paintEvent(QPaintEvent *event)
71 qDebug() << __PRETTY_FUNCTION__;
75 QPainter painter(this);
76 icon().paint(&painter, this->rect(), NULL, m_buttonMode);