Plasma
separator.cpp
Go to the documentation of this file.
00001 /* 00002 * Copyright 2009 by Davide Bettio <davide.bettio@kdemail.net> 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 "separator.h" 00021 00022 #include <QtGui/QPainter> 00023 #include <QtGui/QGraphicsSceneMouseEvent> 00024 00025 #include "svg.h" 00026 00027 namespace Plasma 00028 { 00029 class SeparatorPrivate 00030 { 00031 public: 00032 Svg *svg; 00033 Qt::Orientation orientation; 00034 }; 00035 00036 Separator::Separator(QGraphicsItem *parent, Qt::WindowFlags wFlags) 00037 : QGraphicsWidget(parent, wFlags), 00038 d(new SeparatorPrivate()) 00039 { 00040 d->svg = new Svg(); 00041 d->svg->setImagePath("widgets/line"); 00042 d->svg->setContainsMultipleImages(true); 00043 00044 setOrientation(Qt::Horizontal); 00045 } 00046 00047 Separator::~Separator() 00048 { 00049 delete d->svg; 00050 delete d; 00051 } 00052 00053 void Separator::setOrientation(Qt::Orientation orientation) 00054 { 00055 d->orientation = orientation; 00056 00057 if (orientation == Qt::Horizontal) { 00058 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); 00059 } else { 00060 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); 00061 } 00062 } 00063 00064 Qt::Orientation Separator::orientation() 00065 { 00066 return d->orientation; 00067 } 00068 00069 void Separator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) 00070 { 00071 Q_UNUSED(option); 00072 Q_UNUSED(widget); 00073 00074 if (d->svg){ 00075 if (d->orientation == Qt::Horizontal){ 00076 d->svg->paint(painter, boundingRect(), "horizontal-line"); 00077 } else { 00078 d->svg->paint(painter, boundingRect(), "vertical-line"); 00079 } 00080 } 00081 } 00082 00083 QSizeF Separator::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const 00084 { 00085 QSizeF hint = QGraphicsWidget::sizeHint(which, constraint); 00086 00087 if (d->orientation == Qt::Horizontal) { 00088 hint.setHeight(d->svg->elementSize("horizontal-line").height()); 00089 } else { 00090 hint.setWidth(d->svg->elementSize("vertical-line").width()); 00091 } 00092 00093 return hint; 00094 } 00095 00096 00097 } // Plasma namespace 00098 00099 #include "separator.moc"
KDE 4.6 API Reference