• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

Plasma

  • plasma
  • widgets
radiobutton.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2008 Aaron Seigo <aseigo@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, 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 Library General Public
15 * License 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#include "radiobutton.h"
21
22#include <QDir>
23#include <QPainter>
24#include <QRadioButton>
25
26#include <kmimetype.h>
27
28#include "private/themedwidgetinterface_p.h"
29#include "svg.h"
30#include "theme.h"
31
32namespace Plasma
33{
34
35class RadioButtonPrivate : public ThemedWidgetInterface<RadioButton>
36{
37public:
38 RadioButtonPrivate(RadioButton *radio)
39 : ThemedWidgetInterface<RadioButton>(radio),
40 svg(0)
41 {
42 }
43
44 ~RadioButtonPrivate()
45 {
46 delete svg;
47 }
48
49 void setPixmap(RadioButton *q)
50 {
51 if (imagePath.isEmpty()) {
52 return;
53 }
54
55 KMimeType::Ptr mime = KMimeType::findByPath(absImagePath);
56 QPixmap pm(q->size().toSize());
57
58 if (mime->is("image/svg+xml")) {
59 svg = new Svg();
60 QPainter p(&pm);
61 svg->paint(&p, pm.rect());
62 } else {
63 pm = QPixmap(absImagePath);
64 }
65
66 static_cast<QRadioButton*>(q->widget())->setIcon(QIcon(pm));
67 }
68
69 QString imagePath;
70 QString absImagePath;
71 Svg *svg;
72};
73
74RadioButton::RadioButton(QGraphicsWidget *parent)
75 : QGraphicsProxyWidget(parent),
76 d(new RadioButtonPrivate(this))
77{
78 QRadioButton *native = new QRadioButton;
79 connect(native, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
80 d->setWidget(native);
81 native->setWindowIcon(QIcon());
82 native->setAttribute(Qt::WA_NoSystemBackground);
83 d->initTheming();
84}
85
86RadioButton::~RadioButton()
87{
88 delete d;
89}
90
91void RadioButton::setText(const QString &text)
92{
93 static_cast<QRadioButton*>(widget())->setText(text);
94}
95
96QString RadioButton::text() const
97{
98 return static_cast<QRadioButton*>(widget())->text();
99}
100
101void RadioButton::setImage(const QString &path)
102{
103 if (d->imagePath == path) {
104 return;
105 }
106
107 delete d->svg;
108 d->svg = 0;
109 d->imagePath = path;
110
111 bool absolutePath = !path.isEmpty() &&
112 #ifdef Q_WS_WIN
113 !QDir::isRelativePath(path)
114 #else
115 (path[0] == '/' || path.startsWith(QLatin1String(":/")))
116 #endif
117 ;
118
119 if (absolutePath) {
120 d->absImagePath = path;
121 } else {
122 //TODO: package support
123 d->absImagePath = Theme::defaultTheme()->imagePath(path);
124 }
125
126 d->setPixmap(this);
127}
128
129QString RadioButton::image() const
130{
131 return d->imagePath;
132}
133
134void RadioButton::setStyleSheet(const QString &stylesheet)
135{
136 widget()->setStyleSheet(stylesheet);
137}
138
139QString RadioButton::styleSheet()
140{
141 return widget()->styleSheet();
142}
143
144QRadioButton *RadioButton::nativeWidget() const
145{
146 return static_cast<QRadioButton*>(widget());
147}
148
149void RadioButton::resizeEvent(QGraphicsSceneResizeEvent *event)
150{
151 d->setPixmap(this);
152 QGraphicsProxyWidget::resizeEvent(event);
153}
154
155void RadioButton::setChecked(bool checked)
156{
157 static_cast<QRadioButton*>(widget())->setChecked(checked);
158}
159
160bool RadioButton::isChecked() const
161{
162 return static_cast<QRadioButton*>(widget())->isChecked();
163}
164
165void RadioButton::changeEvent(QEvent *event)
166{
167 d->changeEvent(event);
168 QGraphicsProxyWidget::changeEvent(event);
169}
170
171} // namespace Plasma
172
173#include <radiobutton.moc>
174
Plasma::RadioButton::setText
void setText(const QString &text)
Sets the display text for this RadioButton.
Definition: radiobutton.cpp:91
Plasma::RadioButton::checked
bool checked
Definition: radiobutton.h:48
Plasma::RadioButton::toggled
void toggled(bool)
Plasma::RadioButton::isChecked
bool isChecked() const
Definition: radiobutton.cpp:160
Plasma::RadioButton::text
QString text
Definition: radiobutton.h:44
Plasma::RadioButton::setChecked
void setChecked(bool checked)
Sets the checked state.
Definition: radiobutton.cpp:155
Plasma::Theme::imagePath
Q_INVOKABLE QString imagePath(const QString &name) const
Retrieve the path for an SVG image in the current theme.
Definition: theme.cpp:794
Plasma::Theme::defaultTheme
static Theme * defaultTheme()
Singleton pattern accessor.
Definition: theme.cpp:544
QGraphicsProxyWidget
QGraphicsWidget
Plasma
Namespace for everything in libplasma.
Definition: abstractdialogmanager.cpp:25
radiobutton.h
svg.h
theme.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal