- Full Doxygenization
- Ported PushButton to Plasma::Widget API - Two new classes, Rectangle and Label. - All Widgets should now inherit from Plasma::Widget svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=691090
This commit is contained in:
parent
dd7b8b306b
commit
bef5a33ed5
68
widgets/label.cpp
Normal file
68
widgets/label.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
#include "label.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QFontMetricsF>
|
||||
|
||||
namespace Plasma {
|
||||
|
||||
class Label::Private
|
||||
{
|
||||
public:
|
||||
Private() {}
|
||||
|
||||
QString text;
|
||||
};
|
||||
|
||||
Label::Label(Widget *parent)
|
||||
: Widget(parent),
|
||||
d(new Private)
|
||||
{
|
||||
}
|
||||
|
||||
Label::~Label()
|
||||
{
|
||||
}
|
||||
|
||||
Qt::Orientations Label::expandingDirections() const
|
||||
{
|
||||
return Qt::Horizontal | Qt::Vertical;
|
||||
}
|
||||
|
||||
bool Label::hasHeightForWidth() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
qreal Label::heightForWidth(qreal w) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
QSizeF Label::sizeHint() const
|
||||
{
|
||||
QFontMetricsF m(QFont("Arial", 12));
|
||||
|
||||
return m.boundingRect(d->text).size();
|
||||
}
|
||||
|
||||
void Label::setText(const QString& text)
|
||||
{
|
||||
d->text = text;
|
||||
}
|
||||
|
||||
QString Label::text() const
|
||||
{
|
||||
return d->text;
|
||||
}
|
||||
|
||||
void Label::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
|
||||
/* TODO: Add config parameters, like text color, text alignment, and brush. */
|
||||
p->setPen(QPen(Qt::black, 1));
|
||||
p->drawText(localGeometry(), Qt::AlignCenter | Qt::TextWordWrap, d->text);
|
||||
}
|
||||
|
||||
}
|
93
widgets/label.h
Normal file
93
widgets/label.h
Normal file
@ -0,0 +1,93 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) 2007 by Matias Valdenegro T. <mvaldenegro@informatica.utem.cl>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* 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_LABEL__
|
||||
#define __PLASMA_LABEL__
|
||||
|
||||
#include <plasma/widgets/widget.h>
|
||||
|
||||
class QGraphicsTextItem;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
/**
|
||||
* Simple Text Label.
|
||||
*
|
||||
* @author Matias Valdenegro T. <mvaldenegro@informatica.utem.cl>
|
||||
*
|
||||
* This class is a simple text label, it just draws plain text.
|
||||
*/
|
||||
class PLASMA_EXPORT Label : public Plasma::Widget
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
Label(Widget *parent);
|
||||
|
||||
/**
|
||||
* Virtual Destructor.
|
||||
*/
|
||||
virtual ~Label();
|
||||
|
||||
/**
|
||||
* Labels can expand in Horizontal and Vertical directions.
|
||||
*/
|
||||
Qt::Orientations expandingDirections() const;
|
||||
|
||||
/**
|
||||
* Labels can use height-for-width geometry management.
|
||||
*/
|
||||
bool hasHeightForWidth() const;
|
||||
|
||||
/**
|
||||
* Reimplemented from Plasma::Widget.
|
||||
*/
|
||||
qreal heightForWidth(qreal w) const;
|
||||
|
||||
/**
|
||||
* Reimplemented from Plasma::Widget.
|
||||
*/
|
||||
QSizeF sizeHint() const;
|
||||
|
||||
/**
|
||||
* Sets the text to be displayed.
|
||||
*/
|
||||
void setText(const QString& text);
|
||||
|
||||
/**
|
||||
* Returns the displayed text.
|
||||
*/
|
||||
QString text() const;
|
||||
|
||||
/**
|
||||
* Paint function.
|
||||
*/
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private *d;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* __PLASMA_LABEL__ */
|
@ -30,31 +30,90 @@ namespace Plasma
|
||||
|
||||
/**
|
||||
* Base class for Plasma Layout managers
|
||||
*
|
||||
* @author Matias Valdenegro T. <mvaldenegro@informatica.utem.cl>
|
||||
*
|
||||
* All layout managers must implement this class. Normal users should use the specific layouts,
|
||||
* like Plasma::VBoxLayout, Plasma::HBoxLayout and Plasma::GridLayout.
|
||||
*/
|
||||
|
||||
class PLASMA_EXPORT Layout : public LayoutItem
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
Layout(LayoutItem *parent);
|
||||
|
||||
/**
|
||||
* Virtual Destructor.
|
||||
*/
|
||||
virtual ~Layout();
|
||||
|
||||
/**
|
||||
* Returns the margin of this Layout.
|
||||
*/
|
||||
qreal margin() const;
|
||||
|
||||
/**
|
||||
* Sets the margin of this Layout.
|
||||
*/
|
||||
void setMargin(qreal m);
|
||||
|
||||
/**
|
||||
* Returns the spacing between Layout elements of this Layout.
|
||||
*/
|
||||
qreal spacing() const;
|
||||
|
||||
/**
|
||||
* Sets the spacing of this Layout.
|
||||
*/
|
||||
void setSpacing(qreal s);
|
||||
|
||||
/**
|
||||
* Returns the parent of this Layout.
|
||||
*/
|
||||
LayoutItem *parent() const;
|
||||
|
||||
/**
|
||||
* Returns the number of elements of this Layout.
|
||||
*/
|
||||
virtual int count() const = 0;
|
||||
|
||||
/**
|
||||
* Returns true if this Layout contains no elements, false otherwise.
|
||||
*/
|
||||
virtual bool isEmpty() const = 0;
|
||||
|
||||
virtual void addItem(LayoutItem *l) = 0;
|
||||
/**
|
||||
* Adds a Item to this Layout.
|
||||
* @param l Pointer to the Item to be added.
|
||||
*/
|
||||
virtual void addItem(LayoutItem *l) = 0;
|
||||
|
||||
/**
|
||||
* Removes a Item from this Layout.
|
||||
* @param l Pointer to the Item to be removed.
|
||||
*/
|
||||
virtual void removeItem(LayoutItem *l) = 0;
|
||||
|
||||
/**
|
||||
* Returns the index of a Item in this Layout.
|
||||
* @param l Pointer to an Item to be queryed.
|
||||
*/
|
||||
virtual int indexOf(LayoutItem *l) const = 0;
|
||||
|
||||
/**
|
||||
* Returns a Pointer to an Item in this Layout.
|
||||
* @param i Index of the desired Item.
|
||||
*/
|
||||
virtual LayoutItem *itemAt(int i) const = 0;
|
||||
|
||||
/**
|
||||
* Takes the Pointer of an Item in this Layout.
|
||||
* @param i Index of the desired Item.
|
||||
*/
|
||||
virtual LayoutItem *takeAt(int i) = 0;
|
||||
|
||||
private:
|
||||
|
@ -31,27 +31,78 @@ class Layout;
|
||||
|
||||
/**
|
||||
* Base class for Plasma layout-managed items
|
||||
*
|
||||
* @author Matias Valdenegro T. <mvaldenegro@informatica.utem.cl>
|
||||
*
|
||||
* All layout-managed items should implement this class, but regular users just need to use
|
||||
* Plasma::Widget and Plasma::Layout.
|
||||
*/
|
||||
class PLASMA_EXPORT LayoutItem
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
LayoutItem();
|
||||
|
||||
/**
|
||||
* Virtual Destructor.
|
||||
*/
|
||||
virtual ~LayoutItem();
|
||||
|
||||
/**
|
||||
* Returns a bitmask with the directions that this Item can be expanded.
|
||||
*/
|
||||
virtual Qt::Orientations expandingDirections() const = 0;
|
||||
|
||||
/**
|
||||
* Returns the minimum size of this Item and it's contents.
|
||||
*/
|
||||
virtual QSizeF minimumSize() const = 0;
|
||||
|
||||
/**
|
||||
* Returns the maximum size of this Item.
|
||||
*/
|
||||
virtual QSizeF maximumSize() const = 0;
|
||||
|
||||
/**
|
||||
* Returns true whatever this Item can use height-for-width layout management,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool hasHeightForWidth() const;
|
||||
|
||||
/**
|
||||
* Returns the corresponding height for a given width.
|
||||
* @param w Width
|
||||
*/
|
||||
virtual qreal heightForWidth(qreal w) const;
|
||||
|
||||
/**
|
||||
* Returns true whatever this Item can use width-for-height layout management,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool hasWidthForHeight() const;
|
||||
|
||||
/**
|
||||
* Returns the corresponding width for a given height.
|
||||
* @param h Height
|
||||
*/
|
||||
virtual qreal widthForHeight(qreal h) const;
|
||||
|
||||
/**
|
||||
* Returns the geometry of this Item.
|
||||
*/
|
||||
virtual QRectF geometry() const = 0;
|
||||
|
||||
/**
|
||||
* Sets the geometry of this Item.
|
||||
*/
|
||||
virtual void setGeometry(const QRectF& geometry) = 0;
|
||||
|
||||
/**
|
||||
* Returns the most appropiate size of this Item to hold whatever contents it has.
|
||||
*/
|
||||
virtual QSizeF sizeHint() const = 0;
|
||||
|
||||
/**
|
||||
@ -73,7 +124,7 @@ class PLASMA_EXPORT LayoutItem
|
||||
void setLayout(Layout* layout);
|
||||
|
||||
/**
|
||||
* Returns the layout this item is currently associated with
|
||||
* Returns the layout this item is currently associated with.
|
||||
*/
|
||||
Layout* layout();
|
||||
|
||||
|
@ -24,7 +24,9 @@
|
||||
#include <QWidget>
|
||||
#include <QPainter>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QDebug>
|
||||
#include <QFontMetricsF>
|
||||
#include <QApplication>
|
||||
|
||||
#include "pushbutton.moc"
|
||||
|
||||
namespace Plasma
|
||||
@ -43,37 +45,28 @@ class PushButton::Private
|
||||
QSize iconSize;
|
||||
bool hasIcon;
|
||||
int labelTextOpacity;
|
||||
int height;
|
||||
int width;
|
||||
int maxWidth;
|
||||
int minWidth;
|
||||
int minHeight;
|
||||
int maxHeight;
|
||||
int radius;
|
||||
QTimer * updateTimer;
|
||||
QTimer *updateTimer;
|
||||
PushButton::ButtonState state;
|
||||
};
|
||||
|
||||
PushButton::PushButton(QGraphicsItem *parent)
|
||||
PushButton::PushButton(Widget *parent)
|
||||
: QObject(),
|
||||
QGraphicsItem(parent),
|
||||
QLayoutItem (Qt::AlignHCenter),
|
||||
Widget(parent),
|
||||
d(new Private)
|
||||
{
|
||||
setAcceptedMouseButtons(Qt::LeftButton);
|
||||
setAcceptsHoverEvents(true);
|
||||
setEnabled(true);
|
||||
|
||||
d->height = 40;
|
||||
d->width = 100 ;
|
||||
d->minWidth = d->width;
|
||||
d->maxWidth = d->width;
|
||||
d->minHeight = d->height;
|
||||
d->maxHeight = d->height;
|
||||
resize(40.0f, 100.0f);
|
||||
setPos(QPointF(0.0,0.0));
|
||||
|
||||
/*FIXME: Don't use hardcoded strings and colors. */
|
||||
|
||||
d->state = PushButton::None;
|
||||
d->labelText = QString("Plasma");
|
||||
d->labelTextColor = QColor(201,201,255);
|
||||
d->labelTextColor = QColor(201, 201, 255);
|
||||
d->hasIcon = false;
|
||||
d->iconSize = QSize(32,32);
|
||||
}
|
||||
@ -88,11 +81,6 @@ void PushButton::updated(const QString&, const DataEngine::Data &data)
|
||||
Q_UNUSED(data)
|
||||
}
|
||||
|
||||
QRectF PushButton::boundingRect() const
|
||||
{
|
||||
return QRectF(0, 0, d->width, d->height);
|
||||
}
|
||||
|
||||
void PushButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
QStyleOptionButton options;
|
||||
@ -110,7 +98,7 @@ void PushButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
|
||||
|
||||
widget->style()->drawPrimitive(QStyle::PE_PanelButtonCommand, &options, painter, widget);
|
||||
widget->style()->drawPrimitive(QStyle::PE_FrameFocusRect, &options, painter, widget);
|
||||
widget-> style()->drawControl(QStyle::CE_PushButton, &options, painter, widget);
|
||||
widget->style()->drawControl(QStyle::CE_PushButton, &options, painter, widget);
|
||||
}
|
||||
|
||||
void PushButton::setText(const QString& text)
|
||||
@ -127,39 +115,11 @@ void PushButton::setText(const QString& text)
|
||||
|
||||
}
|
||||
|
||||
|
||||
QString PushButton::text() const
|
||||
{
|
||||
return d->labelText;
|
||||
}
|
||||
|
||||
int PushButton::height() const
|
||||
{
|
||||
return d->height;
|
||||
}
|
||||
|
||||
int PushButton::width() const
|
||||
{
|
||||
return d->width;
|
||||
}
|
||||
|
||||
void PushButton::setHeight(int h)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
d->height = h;
|
||||
update();
|
||||
}
|
||||
|
||||
void PushButton::setWidth(int w)
|
||||
{
|
||||
if (!(w >= d->maxWidth))
|
||||
{
|
||||
prepareGeometryChange ();
|
||||
d->width = w;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void PushButton::setIcon(const QString& path)
|
||||
{
|
||||
if (!path.isNull())
|
||||
@ -173,25 +133,6 @@ void PushButton::setIcon(const QString& path)
|
||||
d->hasIcon = false;
|
||||
}
|
||||
|
||||
QSize PushButton::size() const
|
||||
{
|
||||
return QSize(d->width, d->height);
|
||||
}
|
||||
|
||||
void PushButton::setSize(const QSize& s)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
if (!d->maxWidth >= s.width())
|
||||
d->width = s.width();
|
||||
d->height = s.height();
|
||||
update();
|
||||
}
|
||||
|
||||
void PushButton::setMaximumWidth(int w)
|
||||
{
|
||||
d->maxWidth= w;
|
||||
}
|
||||
|
||||
bool PushButton::isDown()
|
||||
{
|
||||
if (d->state == PushButton::Pressed)
|
||||
@ -199,7 +140,7 @@ bool PushButton::isDown()
|
||||
return false;
|
||||
}
|
||||
|
||||
void PushButton::mousePressEvent ( QGraphicsSceneMouseEvent * event )
|
||||
void PushButton::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
d->state = PushButton::Pressed;
|
||||
@ -207,7 +148,7 @@ void PushButton::mousePressEvent ( QGraphicsSceneMouseEvent * event )
|
||||
// emit clicked();
|
||||
}
|
||||
|
||||
void PushButton::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
|
||||
void PushButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
if (d->state == PushButton::Pressed)
|
||||
@ -216,37 +157,28 @@ void PushButton::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
|
||||
update();
|
||||
}
|
||||
|
||||
QSize PushButton::sizeHint() const
|
||||
QSizeF PushButton::sizeHint() const
|
||||
{
|
||||
return QSize(d->width,d->height);
|
||||
return minimumSize();
|
||||
}
|
||||
|
||||
QSize PushButton::minimumSize() const
|
||||
QSizeF PushButton::minimumSize() const
|
||||
{
|
||||
return QSize(d->minWidth,d->minHeight);
|
||||
QFontMetricsF m = qApp->fontMetrics();
|
||||
|
||||
return m.boundingRect(text()).size();
|
||||
}
|
||||
|
||||
QSize PushButton::maximumSize() const
|
||||
QSizeF PushButton::maximumSize() const
|
||||
{
|
||||
return QSize(d->maxWidth,d->maxHeight);
|
||||
return QSizeF();
|
||||
}
|
||||
|
||||
Qt::Orientations PushButton::expandingDirections() const
|
||||
Qt::Orientations PushButton::expandingDirections() const
|
||||
{
|
||||
return Qt::Horizontal;
|
||||
}
|
||||
|
||||
void PushButton::setGeometry(const QRect & r)
|
||||
{
|
||||
setSize(r.size());
|
||||
setPos(r.x(),r.y());
|
||||
}
|
||||
|
||||
QRect PushButton::geometry() const
|
||||
{
|
||||
return boundingRect().toRect();
|
||||
}
|
||||
|
||||
bool PushButton::isEmpty() const
|
||||
{
|
||||
return false;
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2007 by Siraj Razick siraj@kde.org
|
||||
* and Matias Valdenegro <mvaldenegro@informatica.utem.cl>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
@ -24,20 +25,24 @@
|
||||
#include <QtGui/QLayoutItem>
|
||||
|
||||
#include <plasma/dataengine.h>
|
||||
#include <plasma/widgets/widget.h>
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
//TODO
|
||||
//Please Document this class
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
/**
|
||||
* Class that emulates a QPushButton inside plasma
|
||||
* Class that emulates a QPushButton inside Plasma
|
||||
*
|
||||
* @author Siraj Razick and Matias Valdenegro.
|
||||
*
|
||||
*
|
||||
*/
|
||||
class PLASMA_EXPORT PushButton : public QObject, public QGraphicsItem, public QLayoutItem
|
||||
class PLASMA_EXPORT PushButton : public QObject,
|
||||
public Plasma::Widget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum ButtonShape
|
||||
{
|
||||
@ -55,37 +60,68 @@ class PLASMA_EXPORT PushButton : public QObject, public QGraphicsItem, public QL
|
||||
};
|
||||
|
||||
public:
|
||||
PushButton(QGraphicsItem *parent = 0);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
PushButton(Widget *parent = 0);
|
||||
|
||||
/**
|
||||
* Virtual Destructor.
|
||||
*/
|
||||
virtual ~PushButton();
|
||||
|
||||
/**
|
||||
* Returns the text of this Button.
|
||||
*/
|
||||
QString text() const;
|
||||
void setText(const QString &name);
|
||||
|
||||
QSize size() const;
|
||||
void setSize(const QSize& size);
|
||||
|
||||
int height() const;
|
||||
void setHeight(int height);
|
||||
|
||||
int width() const;
|
||||
void setWidth(int width);
|
||||
/**
|
||||
* Sets the text of this Button.
|
||||
*/
|
||||
void setText(const QString &text);
|
||||
|
||||
/**
|
||||
* Sets the icon of this Button.
|
||||
* @param path Path to the icon file. TODO : WTF is path?
|
||||
*/
|
||||
void setIcon(const QString& path);
|
||||
void setMaximumWidth(int maxwidth);
|
||||
|
||||
/**
|
||||
* Paint function.
|
||||
*/
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
virtual QRectF boundingRect() const;
|
||||
|
||||
//layout stufff
|
||||
virtual QSize sizeHint() const ;
|
||||
virtual QSize minimumSize() const;
|
||||
virtual QSize maximumSize() const ;
|
||||
/**
|
||||
* Reimplemented from Plasma::Widget.
|
||||
*/
|
||||
virtual QSizeF sizeHint() const ;
|
||||
|
||||
/**
|
||||
* Reimplemented from Plasma::Widget.
|
||||
*/
|
||||
virtual QSizeF minimumSize() const;
|
||||
|
||||
/**
|
||||
* Reimplemented from Plasma::Widget.
|
||||
*/
|
||||
virtual QSizeF maximumSize() const ;
|
||||
|
||||
/**
|
||||
* Buttons prefer to expand in Horizontal direction.
|
||||
*/
|
||||
virtual Qt::Orientations expandingDirections() const;
|
||||
virtual void setGeometry(const QRect& r);
|
||||
virtual QRect geometry() const ;
|
||||
|
||||
/**
|
||||
* TODO: What does this function do?
|
||||
*/
|
||||
virtual bool isEmpty() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
/**
|
||||
* Triggers whatever this button is clicked.
|
||||
*/
|
||||
void clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
|
34
widgets/rectangle.cpp
Normal file
34
widgets/rectangle.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include "rectangle.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
namespace Plasma {
|
||||
|
||||
Rectangle::Rectangle(Widget *parent)
|
||||
: Widget(parent)
|
||||
{
|
||||
resize(400.0f, 400.0f);
|
||||
setFlag(QGraphicsItem::ItemIsMovable);
|
||||
}
|
||||
|
||||
Rectangle::~Rectangle()
|
||||
{
|
||||
}
|
||||
|
||||
Qt::Orientations Rectangle::expandingDirections() const
|
||||
{
|
||||
return Qt::Horizontal | Qt::Vertical;
|
||||
}
|
||||
|
||||
void Rectangle::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
|
||||
p->setBrush(Qt::white);
|
||||
p->setPen(Qt::black);
|
||||
p->setOpacity(0.5f);
|
||||
p->drawRect(localGeometry());
|
||||
}
|
||||
|
||||
}
|
20
widgets/rectangle.h
Normal file
20
widgets/rectangle.h
Normal file
@ -0,0 +1,20 @@
|
||||
#include <plasma/widgets/widget.h>
|
||||
|
||||
namespace Plasma {
|
||||
|
||||
class PLASMA_EXPORT Rectangle : public Plasma::Widget
|
||||
{
|
||||
public:
|
||||
Rectangle(Widget *parent);
|
||||
virtual ~Rectangle();
|
||||
|
||||
Qt::Orientations expandingDirections() const;
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private const *d;
|
||||
};
|
||||
|
||||
}
|
@ -84,11 +84,11 @@ QRectF VBoxLayout::geometry() const
|
||||
void VBoxLayout::setGeometry(const QRectF& geometry)
|
||||
{
|
||||
if (!geometry.isValid() || geometry.isEmpty()) {
|
||||
kDebug() << "Invalid Geometry!" << endl;
|
||||
kDebug() << "Invalid Geometry " << geometry << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug("Geometry %p : %f, %f by %f, %f", this, geometry.x(), geometry.y(), geometry.width(), geometry.height());
|
||||
kDebug() << this << " Geometry process " << geometry << " for " << d->childList.count() << " childrens"<< endl;
|
||||
|
||||
QList<LayoutItem *> children;
|
||||
QList<LayoutItem *> expandingChildren;
|
||||
@ -118,13 +118,16 @@ void VBoxLayout::setGeometry(const QRectF& geometry)
|
||||
sizes.insert(indexOf(l),QSizeF(available.width(), expandHeight));
|
||||
}
|
||||
|
||||
QPointF start = geometry.topLeft();
|
||||
//QPointF start = geometry.topLeft();
|
||||
QPointF start = QPointF(0.0f, 0.0f);
|
||||
start += QPointF(margin(), spacing());
|
||||
|
||||
for (int i = 0; i < sizes.size(); i++) {
|
||||
|
||||
LayoutItem *l = itemAt(i);
|
||||
|
||||
kDebug() << "Setting Geometry for child " << l << " to " << QRectF(start, sizes[i]) << endl;
|
||||
|
||||
l->setGeometry(QRectF(start, sizes[i]));
|
||||
start += QPointF(0.0, sizes[i].height() + spacing());
|
||||
}
|
||||
|
@ -31,11 +31,23 @@ namespace Plasma
|
||||
|
||||
/**
|
||||
* Vertical Box Layout
|
||||
*
|
||||
* @author Matias Valdenegro T. <mvaldenegro@informatica.utem.cl>
|
||||
*
|
||||
* This class implements a Vertical Box Layout, it just lays items in vertical, from up to down.
|
||||
*/
|
||||
class PLASMA_EXPORT VBoxLayout : public Layout
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
VBoxLayout(LayoutItem *parent = 0);
|
||||
|
||||
/**
|
||||
* Virtual Destructor.
|
||||
*/
|
||||
virtual ~VBoxLayout();
|
||||
|
||||
Qt::Orientations expandingDirections() const;
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include "widget.h"
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
#include <QtCore/QList>
|
||||
|
||||
#include "layout.h"
|
||||
@ -36,7 +38,7 @@ class Widget::Private
|
||||
{ }
|
||||
~Private() { }
|
||||
|
||||
QRectF geometry;
|
||||
QSizeF size;
|
||||
|
||||
Widget *parent;
|
||||
Layout *layout;
|
||||
@ -47,11 +49,11 @@ Widget::Widget(QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent),
|
||||
d(new Private)
|
||||
{
|
||||
d->parent = dynamic_cast<Widget*>(parent);
|
||||
d->parent = dynamic_cast<Widget *>(parent);
|
||||
|
||||
if (d->parent) {
|
||||
d->parent->addChild(this);
|
||||
d->parent->setGeometry(QRectF(QPointF(0.0, 0.0), d->parent->size()));
|
||||
d->parent->invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,14 +103,20 @@ qreal Widget::widthForHeight(qreal h) const
|
||||
|
||||
QRectF Widget::geometry() const
|
||||
{
|
||||
return d->geometry;
|
||||
return QRectF(pos(), size());
|
||||
}
|
||||
|
||||
QRectF Widget::localGeometry() const
|
||||
{
|
||||
return QRectF(QPointF(0.0f, 0.0f), size());
|
||||
}
|
||||
|
||||
void Widget::setGeometry(const QRectF& geometry)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
|
||||
d->geometry = geometry;
|
||||
setPos(geometry.topLeft());
|
||||
d->size = geometry.size();
|
||||
|
||||
updateGeometry();
|
||||
update();
|
||||
@ -117,12 +125,17 @@ void Widget::setGeometry(const QRectF& geometry)
|
||||
void Widget::updateGeometry()
|
||||
{
|
||||
if (layout()) {
|
||||
layout()->setGeometry(QRectF(QPointF(0.0, 0.0), size()));
|
||||
|
||||
kDebug() << (void *) this << " updating geometry to " << size() << endl;
|
||||
|
||||
layout()->setGeometry(geometry());
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::invalidate()
|
||||
{
|
||||
setGeometry(geometry());
|
||||
|
||||
updateGeometry();
|
||||
|
||||
if (parent()) {
|
||||
@ -137,17 +150,17 @@ QSizeF Widget::sizeHint() const
|
||||
|
||||
QSizeF Widget::size() const
|
||||
{
|
||||
return geometry().size();
|
||||
return d->size;
|
||||
}
|
||||
|
||||
QRectF Widget::boundingRect() const
|
||||
{
|
||||
return geometry();
|
||||
return QRectF(QPointF(0.0f, 0.0f), size());
|
||||
}
|
||||
|
||||
void Widget::resize(const QSizeF& size)
|
||||
{
|
||||
setGeometry(QRectF(d->geometry.topLeft(), size));
|
||||
setGeometry(QRectF(pos(), size));
|
||||
}
|
||||
|
||||
void Widget::resize(qreal w, qreal h)
|
||||
@ -157,7 +170,11 @@ void Widget::resize(qreal w, qreal h)
|
||||
|
||||
void Widget::setLayout(Layout *l)
|
||||
{
|
||||
d->layout = l;
|
||||
if(!d->layout) {
|
||||
d->layout = l;
|
||||
} else {
|
||||
kDebug() << "Widget " << this << "already has a layout!" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
Layout *Widget::layout() const
|
||||
@ -189,9 +206,10 @@ void Widget::addChild(Widget *w)
|
||||
|
||||
void Widget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(painter)
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
Q_UNUSED(painter);
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
|
||||
// do nothing, but we need to reimp so we can create Widget items as this method
|
||||
// is pure virtual in QGraphicsItem
|
||||
}
|
||||
|
157
widgets/widget.h
157
widgets/widget.h
@ -34,49 +34,152 @@ namespace Plasma
|
||||
class Layout;
|
||||
|
||||
/**
|
||||
* Class that emulates a QWidget inside plasma
|
||||
* Base class for all Widgets in Plasma.
|
||||
*
|
||||
* @author Alexander Wiedenbruch and Matias Valdenegro.
|
||||
*
|
||||
* Widgets are the basis for User Interfaces inside Plasma.
|
||||
* Widgets are rectangular, but can be in any visible shape by just using transparency to mask
|
||||
* out non-rectangular areas.
|
||||
*
|
||||
* To implement a Widget, just subclass Plasma::Widget and implement at minimum, sizeHint() and paint()
|
||||
*/
|
||||
class PLASMA_EXPORT Widget : public QGraphicsItem, public LayoutItem
|
||||
class PLASMA_EXPORT Widget : public QGraphicsItem,
|
||||
public LayoutItem
|
||||
{
|
||||
public:
|
||||
explicit Widget(QGraphicsItem *parent = 0);
|
||||
virtual ~Widget();
|
||||
public:
|
||||
|
||||
virtual Qt::Orientations expandingDirections() const;
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
explicit Widget(QGraphicsItem *parent = 0);
|
||||
|
||||
virtual QSizeF minimumSize() const;
|
||||
virtual QSizeF maximumSize() const;
|
||||
/**
|
||||
* Virtual Destructor.
|
||||
*/
|
||||
virtual ~Widget();
|
||||
|
||||
virtual bool hasHeightForWidth() const;
|
||||
virtual qreal heightForWidth(qreal w) const;
|
||||
/**
|
||||
* Returns a bitmask with the directions that this Widget can be expanded.
|
||||
*/
|
||||
virtual Qt::Orientations expandingDirections() const;
|
||||
|
||||
virtual bool hasWidthForHeight() const;
|
||||
virtual qreal widthForHeight(qreal h) const;
|
||||
/**
|
||||
* Returns the minimum size of this Widget and it's contents.
|
||||
*/
|
||||
virtual QSizeF minimumSize() const;
|
||||
|
||||
QRectF geometry() const;
|
||||
void setGeometry(const QRectF &geometry);
|
||||
/**
|
||||
* Returns the maximum size of this Widget.
|
||||
*/
|
||||
virtual QSizeF maximumSize() const;
|
||||
|
||||
void updateGeometry();
|
||||
/**
|
||||
* Returns true whatever this Widget can use height-for-width layout management,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool hasHeightForWidth() const;
|
||||
|
||||
virtual void invalidate();
|
||||
/**
|
||||
* Returns the corresponding height for a given width.
|
||||
* @param w Width
|
||||
*/
|
||||
virtual qreal heightForWidth(qreal w) const;
|
||||
|
||||
virtual QSizeF sizeHint() const;
|
||||
/**
|
||||
* Returns true whatever this Widget can use width-for-height layout management,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool hasWidthForHeight() const;
|
||||
|
||||
QSizeF size() const;
|
||||
/**
|
||||
* Returns the corresponding width for a given height.
|
||||
* @param h Height
|
||||
*/
|
||||
virtual qreal widthForHeight(qreal h) const;
|
||||
|
||||
virtual QRectF boundingRect() const;
|
||||
/**
|
||||
* Returns the geometry of this Widget, in parent coordinates.
|
||||
*/
|
||||
QRectF geometry() const;
|
||||
|
||||
void resize(const QSizeF &size);
|
||||
void resize(qreal w, qreal h);
|
||||
/**
|
||||
* Returns the geometry of this Widget, in local coordinates.
|
||||
*/
|
||||
QRectF localGeometry() const;
|
||||
|
||||
void setLayout(Layout *l);
|
||||
Layout *layout() const;
|
||||
/**
|
||||
* Sets the geometry of this Widget.
|
||||
*/
|
||||
void setGeometry(const QRectF &geometry);
|
||||
|
||||
Widget *parent() const;
|
||||
void reparent(Widget *w);
|
||||
/**
|
||||
* Propagates the geometry information to associated layouts and other Widgets.
|
||||
*/
|
||||
void updateGeometry();
|
||||
|
||||
void addChild(Widget *w);
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
/**
|
||||
* Invalidates the geometry information.
|
||||
*/
|
||||
virtual void invalidate();
|
||||
|
||||
/**
|
||||
* Returns the most appropiate size of this Widget to hold it's contents.
|
||||
*/
|
||||
virtual QSizeF sizeHint() const;
|
||||
|
||||
/**
|
||||
* Returns the size of this Widget.
|
||||
*/
|
||||
QSizeF size() const;
|
||||
|
||||
/**
|
||||
* Returns the bounding rectangle of this Widget.
|
||||
*/
|
||||
virtual QRectF boundingRect() const;
|
||||
|
||||
/**
|
||||
* Resizes this Widget.
|
||||
* @param size New size
|
||||
*/
|
||||
void resize(const QSizeF &size);
|
||||
|
||||
/**
|
||||
* Resizes this Widget.
|
||||
* @param w New width
|
||||
* @param h New height
|
||||
*/
|
||||
void resize(qreal w, qreal h);
|
||||
|
||||
/**
|
||||
* Sets the Layout that will manage this Widget's childrens.
|
||||
*/
|
||||
void setLayout(Layout *l);
|
||||
|
||||
/**
|
||||
* Returns the Layout associated with this Widget.
|
||||
*/
|
||||
Layout *layout() const;
|
||||
|
||||
/**
|
||||
* Returns the parent of this Widget.
|
||||
*/
|
||||
Widget *parent() const;
|
||||
|
||||
/**
|
||||
* Changes the parent of this Widget.
|
||||
*/
|
||||
void reparent(Widget *w);
|
||||
|
||||
/**
|
||||
* Appends a child Widget to this Widget.
|
||||
*/
|
||||
void addChild(Widget *w);
|
||||
|
||||
/**
|
||||
* Paint function. Reimplement to draw on this Widget.
|
||||
*/
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
|
||||
private:
|
||||
class Private;
|
||||
|
Loading…
Reference in New Issue
Block a user