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,
23 #include <QMouseEvent>
26 #include "imagebutton.h"
28 ImageButton::ImageButton(const QString &normalIconPictureFileName,
29 const QString &selectedIconPictureFileName,
30 const QString &disabledIconPictureFileName, QWidget *parent)
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::paintEvent(QPaintEvent *event)
65 qDebug() << __PRETTY_FUNCTION__;
69 QPainter painter(this);
73 icon().paint(&painter, rect(), NULL, QIcon::Selected);
75 icon().paint(&painter, rect(), NULL, QIcon::Selected);
77 icon().paint(&painter, rect(), NULL, QIcon::Normal);
79 icon().paint(&painter, rect(), NULL, QIcon::Disabled);
83 void ImageButton::initButton(const QSize &size, const QIcon &icon)
85 qDebug() << __PRETTY_FUNCTION__;