• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

libplasma

template.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 "<name>.h"
00021 
00022 #include <<Native>>
00023 #include <QPainter>
00024 
00025 #include <KMimeType>
00026 
00027 #include "theme.h"
00028 #include "svg.h"
00029 
00030 namespace Plasma
00031 {
00032 
00033 class <Name>Private
00034 {
00035 public:
00036     <Name>Private()
00037         : svg(0)
00038     {
00039     }
00040 
00041     ~<Name>Private()
00042     {
00043         delete svg;
00044     }
00045 
00046     void setPixmap(<Name> *q)
00047     {
00048         if (imagePath.isEmpty()) {
00049             return;
00050         }
00051 
00052         KMimeType::Ptr mime = KMimeType::findByPath(absImagePath);
00053         QPixmap pm(q->size().toSize());
00054 
00055         if (mime->is("image/svg+xml")) {
00056             svg = new Svg();
00057             QPainter p(&pm);
00058             svg->paint(&p, pm.rect());
00059         } else {
00060             pm = QPixmap(absImagePath);
00061         }
00062 
00063         //TODO: load image into widget
00064         //static_cast<<Native>*>(q->widget())->setPixmappm(pm);
00065         //static_cast<<Native>*>(q->widget())->setIcon(QIcon(pm));
00066     }
00067 
00068     QString imagePath;
00069     QString absImagePath;
00070     Svg *svg;
00071 };
00072 
00073 <Name>::<Name>(QGraphicsWidget *parent)
00074     : QGraphicsProxyWidget(parent),
00075       d(new <Name>Private)
00076 {
00077     <Native>* native = new <Native>;
00078     //TODO: forward signals
00079     //connect(native, SIGNAL(()), this, SIGNAL(()));
00080     setWidget(native);
00081     native->setAttribute(Qt::WA_NoSystemBackground);
00082 }
00083 
00084 <Name>::~<Name>()
00085 {
00086     delete d;
00087 }
00088 
00089 void <Name>::setText(const QString &text)
00090 {
00091     static_cast<<Native>*>(widget())->setText(text);
00092 }
00093 
00094 QString <Name>::text() const
00095 {
00096     return static_cast<<Native>*>(widget())->text();
00097 }
00098 
00099 void <Name>::setImage(const QString &path)
00100 {
00101     if (d->imagePath == path) {
00102         return;
00103     }
00104 
00105     delete d->svg;
00106     d->svg = 0;
00107     d->imagePath = path;
00108 
00109     bool absolutePath = !path.isEmpty() && 
00110                         #ifdef Q_WS_WIN
00111                             !QDir::isRelativePath(path)
00112                         #else
00113                             (path[0] == '/' || path.startsWith(":/"))
00114                         #endif
00115         ;
00116 
00117     if (absolutePath) {
00118         d->absImagePath = path;
00119     } else {
00120         //TODO: package support
00121         d->absImagePath = Theme::defaultTheme()->imagePath(path);
00122     }
00123 
00124     d->setPixmap(this);
00125 }
00126 
00127 QString <Name>::image() const
00128 {
00129     return d->imagePath;
00130 }
00131 
00132 void <Name>::setStyleSheet(const QString &stylesheet)
00133 {
00134     widget()->setStyleSheet(stylesheet);
00135 }
00136 
00137 QString <Name>::styleSheet()
00138 {
00139     return widget()->styleSheet();
00140 }
00141 
00142 <Native>* <Name>::nativeWidget() const
00143 {
00144     return static_cast<<Native>*>(widget());
00145 }
00146 
00147 void <Name>::resizeEvent(QGraphicsSceneResizeEvent *event)
00148 {
00149     d->setPixmap(this);
00150     QGraphicsProxyWidget::resizeEvent(event);
00151 }
00152 
00153 } // namespace Plasma
00154 
00155 #include <<name>.moc>
00156 

libplasma

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

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
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