Added separator widget that has been posted in the reviewboard some months ago.

http://reviewboard.kde.org/r/672/

svn path=/trunk/KDE/kdelibs/; revision=1017364
This commit is contained in:
Davide Bettio 2009-08-30 11:28:34 +00:00
parent d10470d6ef
commit 9c17a0b105
3 changed files with 139 additions and 0 deletions

View File

@ -123,6 +123,7 @@ set(plasma_LIB_SRCS
widgets/toolbutton.cpp
widgets/busywidget.cpp
widgets/scrollwidget.cpp
widgets/separator.cpp
widgets/svgwidget.cpp
widgets/tabbar.cpp
widgets/textbrowser.cpp
@ -262,6 +263,7 @@ install(FILES
widgets/slider.h
widgets/spinbox.h
widgets/busywidget.h
widgets/separator.h
widgets/svgwidget.h
widgets/scrollwidget.h
widgets/tabbar.h

78
widgets/separator.cpp Normal file
View File

@ -0,0 +1,78 @@
/*
* Copyright 2009 by Davide Bettio <davide.bettio@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "separator.h"
#include <QtGui/QPainter>
#include <QtGui/QGraphicsSceneMouseEvent>
#include "svg.h"
namespace Plasma
{
class SeparatorPrivate
{
public:
Svg *svg;
Qt::Orientation orientation;
};
Separator::Separator(QGraphicsItem *parent, Qt::WindowFlags wFlags)
: QGraphicsWidget(parent, wFlags),
d(new SeparatorPrivate())
{
d->svg = new Svg();
d->svg->setImagePath("widgets/line");
d->svg->setContainsMultipleImages(true);
setMaximumHeight(3);
}
Separator::~Separator()
{
delete d;
}
void Separator::setOrientation(Qt::Orientation orientation)
{
d->orientation = orientation;
}
Qt::Orientation Separator::orientation()
{
return d->orientation;
}
void Separator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
if (d->svg){
if (d->orientation == Qt::Horizontal){
d->svg->paint(painter, boundingRect(), "horizontal-line");
}else{
d->svg->paint(painter, boundingRect(), "vertical-line");
}
}
}
} // Plasma namespace
#include "separator.moc"

59
widgets/separator.h Normal file
View File

@ -0,0 +1,59 @@
/*
* Copyright 2009 by Davide Bettio <davide.bettio@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_SEPARATOR_H
#define PLASMA_SEPARATOR_H
#include <QtGui/QGraphicsWidget>
#include <plasma/plasma_export.h>
#include <plasma/plasma.h>
namespace Plasma
{
class SeparatorPrivate;
/**
* @since 4.4
*/
class PLASMA_EXPORT Separator : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
public:
explicit Separator(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
virtual ~Separator();
void setOrientation(Qt::Orientation orientation);
Qt::Orientation orientation();
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
private:
SeparatorPrivate * const d;
};
} // Plasma namespace
#endif // multiple inclusion guard