~ubuntu-branches/ubuntu/raring/recorditnow/raring

« back to all changes in this revision

Viewing changes to src/checkicon.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-09 14:54:01 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110109145401-gyckb4airz4fio50
Tags: 0.8.1-0ubuntu1
* New upstream release. (LP: #681270)
  - Update debian/copyright.
* Build-depend on recordmydesktop.
* Add a watch file.
* Drop 01_fix_ftbfs_kwarning_call.diff, fixed upstream.
* Add 01_joschy_install_to_usr_lib.diff.
* Add 02_fix_ftbfs_no-add-needed.diff.
* Add 03_dont_install_header_files.diff.
* Replace dependency on libpolkit-qt-1-0 with policykit-1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2010 by Kai Dombrowe <just89@gmx.de>                    *
 
3
 *                                                                         *
 
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.                                   *
 
8
 *                                                                         *
 
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.                          *
 
13
 *                                                                         *
 
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
 ***************************************************************************/
 
19
 
 
20
 
 
21
// own
 
22
#include "checkicon.h"
 
23
 
 
24
// KDE
 
25
#include <kicon.h>
 
26
#include <kiconloader.h>
 
27
#include <kdebug.h>
 
28
#include <kiconeffect.h>
 
29
 
 
30
// Qt
 
31
#include <QtGui/QPainter>
 
32
#include <QtGui/QPaintEvent>
 
33
#include <QtGui/QStyle>
 
34
#include <QtGui/QStyleOption>
 
35
 
 
36
 
 
37
CheckIcon::CheckIcon(QWidget *parent)
 
38
    : QWidget(parent), m_checked(false), m_hover(false)
 
39
{
 
40
 
 
41
 
 
42
}
 
43
 
 
44
 
 
45
CheckIcon::~CheckIcon()
 
46
{
 
47
 
 
48
 
 
49
 
 
50
}
 
51
 
 
52
 
 
53
bool CheckIcon::isChecked() const
 
54
{
 
55
 
 
56
    return m_checked;
 
57
 
 
58
}
 
59
 
 
60
 
 
61
QString CheckIcon::icon() const
 
62
{
 
63
 
 
64
    return m_icon;
 
65
 
 
66
}
 
67
 
 
68
 
 
69
void CheckIcon::setIcon(const QString &icon)
 
70
{
 
71
 
 
72
    m_icon = icon;
 
73
    m_pixmap = KIcon(icon).pixmap(KIconLoader::SizeMedium, KIconLoader::SizeMedium);
 
74
 
 
75
    update();
 
76
 
 
77
}
 
78
 
 
79
 
 
80
void CheckIcon::setChecked(const bool &c)
 
81
{
 
82
 
 
83
    if (c== m_checked) {
 
84
        return;
 
85
    }
 
86
 
 
87
    m_checked = c;
 
88
    update();
 
89
 
 
90
    emit checked(c);
 
91
 
 
92
}
 
93
 
 
94
 
 
95
void CheckIcon::paintEvent(QPaintEvent *event)
 
96
{
 
97
 
 
98
    if (m_pixmap.isNull()) {
 
99
        kWarning() << "Null pixmap!";
 
100
        return;
 
101
    }
 
102
 
 
103
    QPixmap result = m_pixmap;
 
104
    if (!m_checked) {
 
105
        QPainter pixPainter(&result);
 
106
        pixPainter.setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
 
107
 
 
108
        if (isEnabled()) {
 
109
            pixPainter.setPen(Qt::red);
 
110
        } else {
 
111
            pixPainter.setPen(Qt::gray);
 
112
        }
 
113
 
 
114
        QLine line1(result.rect().topLeft(), result.rect().bottomRight());
 
115
        QLine line2(result.rect().bottomLeft(), result.rect().topRight());
 
116
 
 
117
        pixPainter.drawLine(line1);
 
118
        pixPainter.drawLine(line2);
 
119
 
 
120
        pixPainter.end();
 
121
    }
 
122
 
 
123
 
 
124
    QIcon::Mode mode;
 
125
 
 
126
    if (!isEnabled()) {
 
127
        mode = QIcon::Disabled;
 
128
    } else {
 
129
        mode = QIcon::Normal;
 
130
    }
 
131
 
 
132
    QStyleOption options;
 
133
    options.initFrom(this);
 
134
 
 
135
    result = style()->generatedIconPixmap(mode, result, &options);
 
136
 
 
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);
 
141
        }
 
142
    }
 
143
 
 
144
    QPainter painter(this);
 
145
    painter.setClipRegion(event->region());
 
146
    painter.setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
 
147
 
 
148
    QRect rect = contentsRect();
 
149
    rect.setHeight(rect.width());
 
150
    rect.moveCenter(contentsRect().center());
 
151
 
 
152
    painter.drawPixmap(rect, result);
 
153
 
 
154
}
 
155
 
 
156
 
 
157
void CheckIcon::mousePressEvent(QMouseEvent *event)
 
158
{
 
159
 
 
160
    event->accept();
 
161
 
 
162
}
 
163
 
 
164
 
 
165
void CheckIcon::mouseReleaseEvent(QMouseEvent *event)
 
166
{
 
167
 
 
168
    event->accept();
 
169
    setChecked(!isChecked());
 
170
 
 
171
}
 
172
 
 
173
 
 
174
void CheckIcon::enterEvent(QEvent *event)
 
175
{
 
176
 
 
177
    event->accept();
 
178
    m_hover = true;
 
179
    update();
 
180
 
 
181
}
 
182
 
 
183
 
 
184
void CheckIcon::leaveEvent(QEvent *event)
 
185
{
 
186
 
 
187
    event->accept();
 
188
    m_hover = false;
 
189
    update();
 
190
 
 
191
}
 
192
 
 
193
 
 
194
#include "checkicon.moc"