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

Plasma

radiobutton.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2008 Aaron Seigo <aseigo@kde.org>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License as
00006  *   published by the Free Software Foundation; either version 2, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details
00013  *
00014  *   You should have received a copy of the GNU Library General Public
00015  *   License along with this program; if not, write to the
00016  *   Free Software Foundation, Inc.,
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 #include "radiobutton.h"
00021 
00022 #include <QDir>
00023 #include <QPainter>
00024 #include <QRadioButton>
00025 
00026 #include <kmimetype.h>
00027 
00028 #include "private/themedwidgetinterface_p.h"
00029 #include "svg.h"
00030 #include "theme.h"
00031 
00032 namespace Plasma
00033 {
00034 
00035 class RadioButtonPrivate : public ThemedWidgetInterface<RadioButton>
00036 {
00037 public:
00038     RadioButtonPrivate(RadioButton *radio)
00039         : ThemedWidgetInterface<RadioButton>(radio),
00040          svg(0)
00041     {
00042     }
00043 
00044     ~RadioButtonPrivate()
00045     {
00046         delete svg;
00047     }
00048 
00049     void setPixmap(RadioButton *q)
00050     {
00051         if (imagePath.isEmpty()) {
00052             return;
00053         }
00054 
00055         KMimeType::Ptr mime = KMimeType::findByPath(absImagePath);
00056         QPixmap pm(q->size().toSize());
00057 
00058         if (mime->is("image/svg+xml")) {
00059             svg = new Svg();
00060             QPainter p(&pm);
00061             svg->paint(&p, pm.rect());
00062         } else {
00063             pm = QPixmap(absImagePath);
00064         }
00065 
00066         static_cast<QRadioButton*>(q->widget())->setIcon(QIcon(pm));
00067     }
00068 
00069     QString imagePath;
00070     QString absImagePath;
00071     Svg *svg;
00072 };
00073 
00074 RadioButton::RadioButton(QGraphicsWidget *parent)
00075     : QGraphicsProxyWidget(parent),
00076       d(new RadioButtonPrivate(this))
00077 {
00078     QRadioButton *native = new QRadioButton;
00079     connect(native, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
00080     setWidget(native);
00081     native->setWindowIcon(QIcon());
00082     native->setAttribute(Qt::WA_NoSystemBackground);
00083     d->initTheming();
00084 }
00085 
00086 RadioButton::~RadioButton()
00087 {
00088     delete d;
00089 }
00090 
00091 void RadioButton::setText(const QString &text)
00092 {
00093     static_cast<QRadioButton*>(widget())->setText(text);
00094 }
00095 
00096 QString RadioButton::text() const
00097 {
00098     return static_cast<QRadioButton*>(widget())->text();
00099 }
00100 
00101 void RadioButton::setImage(const QString &path)
00102 {
00103     if (d->imagePath == path) {
00104         return;
00105     }
00106 
00107     delete d->svg;
00108     d->svg = 0;
00109     d->imagePath = path;
00110 
00111     bool absolutePath = !path.isEmpty() &&
00112                         #ifdef Q_WS_WIN
00113                             !QDir::isRelativePath(path)
00114                         #else
00115                             (path[0] == '/' || path.startsWith(QLatin1String(":/")))
00116                         #endif
00117         ;
00118 
00119     if (absolutePath) {
00120         d->absImagePath = path;
00121     } else {
00122         //TODO: package support
00123         d->absImagePath = Theme::defaultTheme()->imagePath(path);
00124     }
00125 
00126     d->setPixmap(this);
00127 }
00128 
00129 QString RadioButton::image() const
00130 {
00131     return d->imagePath;
00132 }
00133 
00134 void RadioButton::setStyleSheet(const QString &stylesheet)
00135 {
00136     widget()->setStyleSheet(stylesheet);
00137 }
00138 
00139 QString RadioButton::styleSheet()
00140 {
00141     return widget()->styleSheet();
00142 }
00143 
00144 QRadioButton *RadioButton::nativeWidget() const
00145 {
00146     return static_cast<QRadioButton*>(widget());
00147 }
00148 
00149 void RadioButton::resizeEvent(QGraphicsSceneResizeEvent *event)
00150 {
00151     d->setPixmap(this);
00152     QGraphicsProxyWidget::resizeEvent(event);
00153 }
00154 
00155 void RadioButton::setChecked(bool checked)
00156 {
00157     static_cast<QRadioButton*>(widget())->setChecked(checked);
00158 }
00159 
00160 bool RadioButton::isChecked() const
00161 {
00162     return static_cast<QRadioButton*>(widget())->isChecked();
00163 }
00164 
00165 void RadioButton::changeEvent(QEvent *event)
00166 {
00167     d->changeEvent(event);
00168     QGraphicsProxyWidget::changeEvent(event);
00169 }
00170 
00171 } // namespace Plasma
00172 
00173 #include <radiobutton.moc>
00174 

Plasma

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal