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

Plasma

  • sources
  • kde-4.12
  • kdelibs
  • 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 
32 namespace Plasma
33 {
34 
35 class RadioButtonPrivate : public ThemedWidgetInterface<RadioButton>
36 {
37 public:
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 
74 RadioButton::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 
86 RadioButton::~RadioButton()
87 {
88  delete d;
89 }
90 
91 void RadioButton::setText(const QString &text)
92 {
93  static_cast<QRadioButton*>(widget())->setText(text);
94 }
95 
96 QString RadioButton::text() const
97 {
98  return static_cast<QRadioButton*>(widget())->text();
99 }
100 
101 void 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 
129 QString RadioButton::image() const
130 {
131  return d->imagePath;
132 }
133 
134 void RadioButton::setStyleSheet(const QString &stylesheet)
135 {
136  widget()->setStyleSheet(stylesheet);
137 }
138 
139 QString RadioButton::styleSheet()
140 {
141  return widget()->styleSheet();
142 }
143 
144 QRadioButton *RadioButton::nativeWidget() const
145 {
146  return static_cast<QRadioButton*>(widget());
147 }
148 
149 void RadioButton::resizeEvent(QGraphicsSceneResizeEvent *event)
150 {
151  d->setPixmap(this);
152  QGraphicsProxyWidget::resizeEvent(event);
153 }
154 
155 void RadioButton::setChecked(bool checked)
156 {
157  static_cast<QRadioButton*>(widget())->setChecked(checked);
158 }
159 
160 bool RadioButton::isChecked() const
161 {
162  return static_cast<QRadioButton*>(widget())->isChecked();
163 }
164 
165 void 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::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::RadioButton::setText
void setText(const QString &text)
Sets the display text for this RadioButton.
Definition: radiobutton.cpp:91
Plasma::RadioButton::toggled
void toggled(bool)
theme.h
Plasma::RadioButton::styleSheet
QString styleSheet()
Plasma::RadioButton::setImage
void setImage(const QString &path)
Sets the path to an image to display.
Definition: radiobutton.cpp:101
Plasma::RadioButton::text
QString text() const
Plasma::RadioButton::RadioButton
RadioButton(QGraphicsWidget *parent=0)
Definition: radiobutton.cpp:74
Plasma::RadioButton::~RadioButton
~RadioButton()
Definition: radiobutton.cpp:86
Plasma::RadioButton::changeEvent
void changeEvent(QEvent *event)
Definition: radiobutton.cpp:165
QGraphicsProxyWidget
Plasma::RadioButton::isChecked
bool isChecked() const
Definition: radiobutton.cpp:160
Plasma::RadioButton::resizeEvent
void resizeEvent(QGraphicsSceneResizeEvent *event)
Definition: radiobutton.cpp:149
Plasma::Theme::defaultTheme
static Theme * defaultTheme()
Singleton pattern accessor.
Definition: theme.cpp:544
Plasma::RadioButton::nativeWidget
QRadioButton * nativeWidget() const
Plasma::RadioButton::setStyleSheet
void setStyleSheet(const QString &stylesheet)
Sets the stylesheet used to control the visual display of this RadioButton.
Definition: radiobutton.cpp:134
Plasma::RadioButton::setChecked
void setChecked(bool checked)
Sets the checked state.
Definition: radiobutton.cpp:155
Plasma::RadioButton::image
QString image() const
radiobutton.h
svg.h
QGraphicsWidget
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:34 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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