1
/***************************************************************************
2
* Copyright (C) 2010 by Kai Dombrowe <just89@gmx.de> *
4
* This program 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 2 of the License, or *
7
* (at your option) any later version. *
9
* This program 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. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18
***************************************************************************/
22
#include "checkicon.h"
26
#include <kiconloader.h>
28
#include <kiconeffect.h>
31
#include <QtGui/QPainter>
32
#include <QtGui/QPaintEvent>
33
#include <QtGui/QStyle>
34
#include <QtGui/QStyleOption>
37
CheckIcon::CheckIcon(QWidget *parent)
38
: QWidget(parent), m_checked(false), m_hover(false)
45
CheckIcon::~CheckIcon()
53
bool CheckIcon::isChecked() const
61
QString CheckIcon::icon() const
69
void CheckIcon::setIcon(const QString &icon)
73
m_pixmap = KIcon(icon).pixmap(KIconLoader::SizeMedium, KIconLoader::SizeMedium);
80
void CheckIcon::setChecked(const bool &c)
95
void CheckIcon::paintEvent(QPaintEvent *event)
98
if (m_pixmap.isNull()) {
99
kWarning() << "Null pixmap!";
103
QPixmap result = m_pixmap;
105
QPainter pixPainter(&result);
106
pixPainter.setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
109
pixPainter.setPen(Qt::red);
111
pixPainter.setPen(Qt::gray);
114
QLine line1(result.rect().topLeft(), result.rect().bottomRight());
115
QLine line2(result.rect().bottomLeft(), result.rect().topRight());
117
pixPainter.drawLine(line1);
118
pixPainter.drawLine(line2);
127
mode = QIcon::Disabled;
129
mode = QIcon::Normal;
132
QStyleOption options;
133
options.initFrom(this);
135
result = style()->generatedIconPixmap(mode, result, &options);
137
if (isEnabled() && m_hover) {
138
KIconEffect *effect = KIconLoader::global()->iconEffect();
139
if (effect->hasEffect(KIconLoader::NoGroup, KIconLoader::ActiveState)) {
140
result = effect->apply(result, KIconLoader::Desktop, KIconLoader::ActiveState);
144
QPainter painter(this);
145
painter.setClipRegion(event->region());
146
painter.setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
148
QRect rect = contentsRect();
149
rect.setHeight(rect.width());
150
rect.moveCenter(contentsRect().center());
152
painter.drawPixmap(rect, result);
157
void CheckIcon::mousePressEvent(QMouseEvent *event)
165
void CheckIcon::mouseReleaseEvent(QMouseEvent *event)
169
setChecked(!isChecked());
174
void CheckIcon::enterEvent(QEvent *event)
184
void CheckIcon::leaveEvent(QEvent *event)
194
#include "checkicon.moc"