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 "imagebutton.h"
27 ImageButton::ImageButton(const QString &normalIconPictureFileName,
28 const QString &selectedIconPictureFileName,
29 const QString &disabledIconPictureFileName, QWidget *parent)
30 : QPushButton(parent),
31 m_buttonMode(QIcon::Normal)
33 qDebug() << __PRETTY_FUNCTION__;
35 // If there is a file name provided for icon image, use it as the icon for the button
36 if (!normalIconPictureFileName.isEmpty()) {
37 QPixmap iconPixmap(normalIconPictureFileName);
38 QSize buttonSize = iconPixmap.size(); // Get the button size from the normal state icon picture
39 QIcon icon(iconPixmap);
41 // If there is a picture for selected state, use it instead of a simple highlight change
42 if(!selectedIconPictureFileName.isEmpty())
43 icon.addFile(selectedIconPictureFileName, buttonSize, QIcon::Selected);
45 // If there is a picture for disabled state, use it instead of a simple color change
46 if(!disabledIconPictureFileName.isEmpty())
47 icon.addFile(disabledIconPictureFileName, buttonSize, QIcon::Disabled);
49 initButton(buttonSize, icon);
53 void ImageButton::setButtonIcon(const QPixmap &image)
55 qDebug() << __PRETTY_FUNCTION__;
57 QSize buttonSize = image.size(); // Get the button size from the normal state icon picture
60 initButton(buttonSize, icon);
63 void ImageButton::mousePressEvent(QMouseEvent *event)
65 qDebug() << __PRETTY_FUNCTION__;
67 if(m_buttonMode != QIcon::Disabled) {
68 QPushButton::mousePressEvent(event);
69 setMode(QIcon::Selected);
76 void ImageButton::mouseReleaseEvent(QMouseEvent *event)
78 qDebug() << __PRETTY_FUNCTION__;
80 if(m_buttonMode != QIcon::Disabled) {
81 QPushButton::mouseReleaseEvent(event);
82 setMode(QIcon::Normal);
89 void ImageButton::paintEvent(QPaintEvent *event)
91 qDebug() << __PRETTY_FUNCTION__;
95 QPainter painter(this);
96 icon().paint(&painter, this->rect(), NULL, m_buttonMode);
99 void ImageButton::setMode(QIcon::Mode mode)
101 qDebug() << __PRETTY_FUNCTION__;
107 QIcon::Mode ImageButton::mode()
109 qDebug() << __PRETTY_FUNCTION__;
114 void ImageButton::initButton(const QSize &size, const QIcon &icon)
116 qDebug() << __PRETTY_FUNCTION__;