2009-08-30 13:28:34 +02:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2012-02-02 10:35:53 +01:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
2009-08-30 13:28:34 +02:00
|
|
|
|
|
|
|
#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);
|
2009-09-21 15:57:32 +02:00
|
|
|
|
|
|
|
setOrientation(Qt::Horizontal);
|
2009-08-30 13:28:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Separator::~Separator()
|
|
|
|
{
|
2009-11-19 20:05:50 +01:00
|
|
|
delete d->svg;
|
2009-08-30 13:28:34 +02:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Separator::setOrientation(Qt::Orientation orientation)
|
|
|
|
{
|
2009-09-21 16:14:38 +02:00
|
|
|
d->orientation = orientation;
|
|
|
|
|
2009-09-21 15:57:32 +02:00
|
|
|
if (orientation == Qt::Horizontal) {
|
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
} else {
|
|
|
|
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
|
|
|
}
|
2009-08-30 13:28:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
2009-09-21 15:57:32 +02:00
|
|
|
} else {
|
2009-08-30 13:28:34 +02:00
|
|
|
d->svg->paint(painter, boundingRect(), "vertical-line");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-21 16:00:53 +02:00
|
|
|
QSizeF Separator::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
|
2009-09-21 15:57:32 +02:00
|
|
|
{
|
|
|
|
QSizeF hint = QGraphicsWidget::sizeHint(which, constraint);
|
|
|
|
|
2009-09-21 16:14:38 +02:00
|
|
|
if (d->orientation == Qt::Horizontal) {
|
|
|
|
hint.setHeight(d->svg->elementSize("horizontal-line").height());
|
|
|
|
} else {
|
|
|
|
hint.setWidth(d->svg->elementSize("vertical-line").width());
|
2009-09-21 15:57:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hint;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-30 13:28:34 +02:00
|
|
|
} // Plasma namespace
|
|
|
|
|
2012-02-08 23:33:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include "moc_separator.cpp"
|