bye bye plasma layouts
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=796599
This commit is contained in:
parent
ad159743b2
commit
e187eac834
|
@ -1,581 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 by Matias Valdenegro T. <mvaldenegro@informatica.utem.cl>
|
||||
* Copyright 2007 by Robert Knight <robertknight@gmail.com>
|
||||
* Copyright 2008 by Olivier Goffart <ogoffart@kde.org>
|
||||
*
|
||||
* 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 "boxlayout.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QTimeLine>
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
|
||||
#include "layoutanimator.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class BoxLayout::Private
|
||||
{
|
||||
public:
|
||||
BoxLayout *const q;
|
||||
Direction direction;
|
||||
QList<LayoutItem*> children;
|
||||
bool expandingBoth;
|
||||
bool multiRow;
|
||||
int rowCount;
|
||||
int colCount() const {
|
||||
return ((children.count() - 1) / rowCount) + 1;
|
||||
}
|
||||
|
||||
Private(BoxLayout *parent)
|
||||
: q(parent)
|
||||
, direction(LeftToRight), expandingBoth(false), multiRow(false) , rowCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
// returns the component of 'size' in the expanding direction
|
||||
// of this layout
|
||||
qreal size(const QSizeF& size) const
|
||||
{
|
||||
switch (direction) {
|
||||
case LeftToRight:
|
||||
case RightToLeft:
|
||||
return size.width();
|
||||
case TopToBottom:
|
||||
case BottomToTop:
|
||||
return size.height();
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// returns the component of 'size' in the other direction
|
||||
qreal size_o(const QSizeF& size) const
|
||||
{
|
||||
switch (direction) {
|
||||
case LeftToRight:
|
||||
case RightToLeft:
|
||||
return size.height();
|
||||
case TopToBottom:
|
||||
case BottomToTop:
|
||||
return size.width();
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// returns the directions in which this layout expands
|
||||
// or shrinks
|
||||
Qt::Orientations expandingDirections() const
|
||||
{
|
||||
if (expandingBoth) {
|
||||
return Qt::Horizontal|Qt::Vertical;
|
||||
}
|
||||
|
||||
switch (direction) {
|
||||
case LeftToRight:
|
||||
case RightToLeft:
|
||||
return Qt::Horizontal;
|
||||
case TopToBottom:
|
||||
case BottomToTop:
|
||||
return Qt::Vertical;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
return Qt::Horizontal;
|
||||
}
|
||||
}
|
||||
|
||||
// returns the position from which layouting should
|
||||
// begin depending on the direction of this layout
|
||||
qreal startPos(const QRectF& geometry) const
|
||||
{
|
||||
switch (direction) {
|
||||
case LeftToRight:
|
||||
return geometry.left() + q->margin(LeftMargin);
|
||||
case TopToBottom:
|
||||
return geometry.top() + q->margin(TopMargin);
|
||||
case RightToLeft:
|
||||
return geometry.right() - q->margin(RightMargin);
|
||||
case BottomToTop:
|
||||
return geometry.bottom() - q->margin(BottomMargin);
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// lays out an item
|
||||
//
|
||||
// 'geometry' the geometry of the layout
|
||||
// 'item' the item whoose geometry should be altered
|
||||
// 'pos' the position of the item (in the expanding direction of the layout)
|
||||
// 'size' the size of the item (in the expanding direction of the layout)
|
||||
//
|
||||
// returns the position for the next item in the layout
|
||||
//
|
||||
qreal layoutItem(const QRectF& geometry , LayoutItem *item , const qreal pos , qreal size, int row)
|
||||
{
|
||||
//kDebug() << "layoutItem: " << direction << "item size" << size;
|
||||
|
||||
QRectF newGeometry;
|
||||
qreal newPos = 0;
|
||||
|
||||
qreal top = 0;
|
||||
qreal height = 0;
|
||||
|
||||
const QSizeF minSize = item->minimumSize();
|
||||
const QSizeF maxSize = item->maximumSize();
|
||||
switch (direction) {
|
||||
case LeftToRight:
|
||||
case RightToLeft:
|
||||
height = (geometry.height() - q->spacing() * (rowCount - 1)) / rowCount;
|
||||
top = geometry.top() + row * (height + q->spacing());
|
||||
height = qBound(minSize.height(), height, maxSize.height());
|
||||
if (size > geometry.width()) {
|
||||
size = geometry.width();
|
||||
}
|
||||
break;
|
||||
case TopToBottom:
|
||||
case BottomToTop:
|
||||
height = (geometry.width() - q->spacing() * (rowCount - 1)) / rowCount;
|
||||
top = geometry.left() + row * (height + q->spacing());
|
||||
height = qBound(minSize.width(), height, maxSize.width());
|
||||
if (size > geometry.height()) {
|
||||
size = geometry.height();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch (direction) {
|
||||
case LeftToRight:
|
||||
newGeometry = QRectF(pos, top, size, height);
|
||||
newPos = pos + size + q->spacing();
|
||||
break;
|
||||
case RightToLeft:
|
||||
newGeometry = QRectF(geometry.width() - pos - size, top, size, height);
|
||||
newPos = pos - size - q->spacing();
|
||||
break;
|
||||
case TopToBottom:
|
||||
newGeometry = QRectF(top, pos, height, size);
|
||||
newPos = pos + size + q->spacing();
|
||||
break;
|
||||
case BottomToTop:
|
||||
newGeometry = QRectF(top, geometry.height() - pos - size, height, size);
|
||||
newPos = pos - size - q->spacing();
|
||||
break;
|
||||
}
|
||||
|
||||
// kDebug() << "Item geometry: " << newGeometry;
|
||||
|
||||
if (q->animator()) {
|
||||
q->animator()->setGeometry(item, newGeometry);
|
||||
} else {
|
||||
item->setGeometry(newGeometry);
|
||||
}
|
||||
|
||||
return newPos;
|
||||
}
|
||||
|
||||
enum SizeType
|
||||
{
|
||||
MinSize,
|
||||
MaxSize,
|
||||
HintSize
|
||||
};
|
||||
|
||||
// this provides a + function which can be passed as the 'op'
|
||||
// argument to calculateSize
|
||||
static qreal sum(const qreal a, const qreal b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
// calcualtes a size hint or value for this layout
|
||||
// 'sizeType' - The item size ( minimum , maximum , hint ) to use
|
||||
// 'dir' - The direction component of the item size to use
|
||||
// 'op' - A function to apply to the size of each item in the layout
|
||||
// , usually qMax,qMin or sum
|
||||
template <class T>
|
||||
qreal calculateSize(SizeType sizeType, Qt::Orientation dir, T (*op)(const T, const T)) const
|
||||
{
|
||||
qreal value = 0;
|
||||
for (int i = 0; i < children.count(); i++) {
|
||||
|
||||
QSizeF itemSize;
|
||||
switch (sizeType) {
|
||||
case MinSize:
|
||||
itemSize = children[i]->minimumSize();
|
||||
break;
|
||||
case MaxSize:
|
||||
itemSize = children[i]->maximumSize();
|
||||
break;
|
||||
case HintSize:
|
||||
itemSize = children[i]->sizeHint();
|
||||
break;
|
||||
}
|
||||
|
||||
if (dir == Qt::Horizontal) {
|
||||
value = op(value, itemSize.width());
|
||||
} else {
|
||||
value = op(value, itemSize.height());
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
// calculates a size hint or value for this layout
|
||||
// 'calculateSizeType' specifies the value to be calculated
|
||||
QSizeF calculateSize(SizeType calculateSizeType) const
|
||||
{
|
||||
QSizeF result;
|
||||
|
||||
const qreal totalSpacingC = q->spacing() * (colCount() - 1);
|
||||
const qreal totalSpacingR = q->spacing() * (rowCount - 1);
|
||||
|
||||
switch (direction) {
|
||||
case LeftToRight:
|
||||
case RightToLeft:
|
||||
result = QSizeF(calculateSize(calculateSizeType, Qt::Horizontal, sum) / rowCount,
|
||||
calculateSize(calculateSizeType, Qt::Vertical, qMax<qreal>) * rowCount);
|
||||
|
||||
result.rwidth() += q->margin(LeftMargin) + q->margin(RightMargin) + totalSpacingC;
|
||||
result.rheight() += q->margin(TopMargin) + q->margin(BottomMargin) + totalSpacingR;
|
||||
|
||||
break;
|
||||
case TopToBottom:
|
||||
case BottomToTop:
|
||||
result = QSizeF(calculateSize(calculateSizeType, Qt::Horizontal, qMax<qreal>) / rowCount,
|
||||
calculateSize(calculateSizeType, Qt::Vertical, sum) * rowCount);
|
||||
|
||||
result.rheight() += q->margin(TopMargin) + q->margin(BottomMargin) + totalSpacingC;
|
||||
result.rwidth() += q->margin(LeftMargin) + q->margin(RightMargin) + totalSpacingR;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
BoxLayout::BoxLayout(Direction direction, LayoutItem *parent)
|
||||
: Layout(parent),
|
||||
d(new Private(this))
|
||||
{
|
||||
d->direction = direction;
|
||||
}
|
||||
|
||||
void BoxLayout::setDirection(Direction direction)
|
||||
{
|
||||
d->direction = direction;
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
BoxLayout::Direction BoxLayout::direction() const
|
||||
{
|
||||
return d->direction;
|
||||
}
|
||||
|
||||
BoxLayout::~BoxLayout()
|
||||
{
|
||||
releaseManagedItems();
|
||||
delete d;
|
||||
}
|
||||
|
||||
Qt::Orientations BoxLayout::expandingDirections() const
|
||||
{
|
||||
return d->expandingDirections();
|
||||
}
|
||||
|
||||
int BoxLayout::count() const
|
||||
{
|
||||
return d->children.count();
|
||||
}
|
||||
|
||||
void BoxLayout::setAnimator(LayoutAnimator *animator)
|
||||
{
|
||||
Layout::setAnimator(animator);
|
||||
|
||||
if (animator) {
|
||||
foreach (LayoutItem *item, d->children) {
|
||||
animator->setGeometry(item, item->geometry());
|
||||
animator->setCurrentState(item, LayoutAnimator::StandardState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BoxLayout::insertItem(int index, LayoutItem *item)
|
||||
{
|
||||
if (!item || d->children.contains(item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
item->setManagingLayout(this);
|
||||
|
||||
if (index == -1) {
|
||||
index = d->children.size();
|
||||
}
|
||||
|
||||
d->children.insert(index, item);
|
||||
|
||||
if (animator()) {
|
||||
animator()->setCurrentState(item, LayoutAnimator::InsertedState);
|
||||
}
|
||||
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
void BoxLayout::addItem(LayoutItem *item)
|
||||
{
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
insertItem(-1, item);
|
||||
}
|
||||
|
||||
void BoxLayout::removeItem(LayoutItem *item)
|
||||
{
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
item->unsetManagingLayout(this);
|
||||
d->children.removeAll(item);
|
||||
|
||||
if (animator()) {
|
||||
animator()->setCurrentState(item, LayoutAnimator::RemovedState);
|
||||
}
|
||||
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
int BoxLayout::indexOf(LayoutItem *l) const
|
||||
{
|
||||
return d->children.indexOf(l);
|
||||
}
|
||||
|
||||
LayoutItem *BoxLayout::itemAt(int i) const
|
||||
{
|
||||
if (i >= d->children.count()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return d->children[i];
|
||||
}
|
||||
|
||||
LayoutItem *BoxLayout::takeAt(int i)
|
||||
{
|
||||
if (i >= d->children.count()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return d->children.takeAt(i);
|
||||
// FIXME: This is never reached. Should it be called?
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
void BoxLayout::relayout()
|
||||
{
|
||||
const QRectF margined = geometry().adjusted(margin(LeftMargin), margin(TopMargin), -margin(RightMargin), -margin(BottomMargin));
|
||||
|
||||
//kDebug() << "geo before " << geo << "and with margins" << margined << "margins" << margin(LeftMargin)
|
||||
// << margin(TopMargin) << -margin(RightMargin) << -margin(BottomMargin);
|
||||
//kDebug() << "Box layout beginning with geo" << geometry;
|
||||
//kDebug() << "This box max size" << maximumSize();
|
||||
d->rowCount = 1;
|
||||
if (d->multiRow) {
|
||||
qreal minRowSize = 1;
|
||||
qreal minWidth = 0;
|
||||
for(int i = 0; i < d->children.count(); i++) {
|
||||
minRowSize = qMax(minRowSize, d->size_o(d->children[i]->minimumSize()));
|
||||
minWidth += d->size(d->children[i]->minimumSize());
|
||||
}
|
||||
|
||||
const qreal ratio = 2.25; //maybe this should not be hardcoded
|
||||
//we want the height of items be larger than the minimum size
|
||||
int maxRow = (d->size_o(margined.size()) + spacing()) /
|
||||
(minRowSize + spacing());
|
||||
//we want enough rows to be able to fit each items width.
|
||||
int minRow = (minWidth + d->children.count() * spacing()) /
|
||||
(d->size(margined.size()) + spacing() + 0.1);
|
||||
//FIXME: this formula doesn't take the cellspacing in account
|
||||
// it should also try to "fill" before adding a row
|
||||
d->rowCount = 1 + sqrt(ratio * count() * d->size_o(margined.size()) /
|
||||
(d->size(margined.size()) + 1));
|
||||
|
||||
d->rowCount = qMax(minRow, d->rowCount);
|
||||
d->rowCount = qMin(maxRow, d->rowCount);
|
||||
d->rowCount = qMax(1, d->rowCount);
|
||||
}
|
||||
|
||||
const int colCount = d->colCount();
|
||||
|
||||
QVector<qreal> sizes(colCount, 0);
|
||||
QVector<qreal> expansionSpace(colCount, 0);
|
||||
|
||||
qreal available = d->size(margined.size()) - spacing() * colCount;
|
||||
qreal perItemSize = available / colCount;
|
||||
|
||||
// initial distribution of space to items
|
||||
for (int i = 0; i < colCount; i++) {
|
||||
qreal minItemSize = 0;
|
||||
qreal maxItemSize = 65536;
|
||||
bool isExpanding = true;
|
||||
qreal hint = 0;
|
||||
|
||||
for (int f = i * d->rowCount; f < (i + 1) * d->rowCount; f++) {
|
||||
if (f >= count()) {
|
||||
break;
|
||||
}
|
||||
const LayoutItem *item = d->children[f];
|
||||
const bool itemExp = (item->expandingDirections() & d->expandingDirections());
|
||||
isExpanding = isExpanding && itemExp;
|
||||
minItemSize = qMax(minItemSize, d->size(item->minimumSize()));
|
||||
maxItemSize = qMin(maxItemSize, d->size(item->maximumSize()));
|
||||
if (!itemExp) {
|
||||
hint = qMax(hint, d->size(item->sizeHint()));
|
||||
}
|
||||
}
|
||||
|
||||
if (isExpanding) {
|
||||
sizes[i] = perItemSize;
|
||||
} else {
|
||||
sizes[i] = hint;
|
||||
}
|
||||
|
||||
// kDebug() << "Layout max item " << i << "size: " << maxItemSize;
|
||||
|
||||
sizes[i] = qMin(sizes[i], maxItemSize);
|
||||
sizes[i] = qMax(sizes[i], minItemSize);
|
||||
|
||||
// kDebug() << "Available: " << available << "per item:" << perItemSize <<
|
||||
// "Initial size: " << sizes[i];
|
||||
|
||||
if (isExpanding) {
|
||||
expansionSpace[i] = maxItemSize - sizes[i];
|
||||
} else {
|
||||
expansionSpace[i] = 0;
|
||||
}
|
||||
|
||||
available -= sizes[i];
|
||||
// adjust the per-item size if the space was over or under used
|
||||
if (sizes[i] != perItemSize && i != sizes.count() - 1) {
|
||||
perItemSize = available / (sizes.count() - i - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// distribute out any remaining space to items which can still expand
|
||||
//
|
||||
// space is distributed equally amongst remaining items until we run
|
||||
// out of space or items to expand
|
||||
int expandable = sizes.count();
|
||||
const qreal threshold = 1.0;
|
||||
while (available > threshold && expandable > 0) {
|
||||
|
||||
const qreal extraSpace = available / expandable;
|
||||
for (int i = 0; i < colCount; i++) {
|
||||
if (expansionSpace[i] > threshold) {
|
||||
qreal oldSize = sizes[i];
|
||||
|
||||
sizes[i] += qMin(extraSpace, expansionSpace[i]);
|
||||
|
||||
expansionSpace[i] -= sizes[i] - oldSize;
|
||||
available -= sizes[i] - oldSize;
|
||||
} else {
|
||||
expandable--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set items' geometry according to new sizes
|
||||
qreal pos = d->startPos(geometry());
|
||||
for (int col = 0; col < colCount; col++) {
|
||||
int newPos = pos;
|
||||
for (int row = 0; row < d->rowCount; row++) {
|
||||
int i = col * d->rowCount + row;
|
||||
if (i >= count()) {
|
||||
break;
|
||||
}
|
||||
|
||||
//QObject *obj = dynamic_cast<QObject*>(d->children[i]);
|
||||
//if ( obj )
|
||||
//kDebug() << "Item " << i << obj->metaObject()->className() << "size:" << sizes[i];
|
||||
|
||||
int p = d->layoutItem(margined, d->children[i], pos, sizes[col], row);
|
||||
newPos = (row != 0 && p < pos) ? qMin(p, newPos) : qMax(p, newPos);
|
||||
}
|
||||
pos = newPos;
|
||||
}
|
||||
|
||||
startAnimation();
|
||||
}
|
||||
|
||||
void BoxLayout::releaseManagedItems()
|
||||
{
|
||||
foreach (LayoutItem* item, d->children) {
|
||||
item->unsetManagingLayout(this);
|
||||
}
|
||||
}
|
||||
|
||||
QSizeF BoxLayout::maximumSize() const
|
||||
{
|
||||
return Layout::maximumSize();
|
||||
}
|
||||
QSizeF BoxLayout::minimumSize() const
|
||||
{
|
||||
return d->calculateSize(Private::MinSize);
|
||||
}
|
||||
QSizeF BoxLayout::sizeHint() const
|
||||
{
|
||||
return d->calculateSize(Private::HintSize);
|
||||
}
|
||||
|
||||
void BoxLayout::setMultiRow(bool b)
|
||||
{
|
||||
d->multiRow = b;
|
||||
}
|
||||
|
||||
void BoxLayout::setExpandingBoth(bool both)
|
||||
{
|
||||
d->expandingBoth = both;
|
||||
}
|
||||
|
||||
HBoxLayout::HBoxLayout(LayoutItem *parent)
|
||||
: BoxLayout(LeftToRight, parent)
|
||||
{
|
||||
}
|
||||
|
||||
VBoxLayout::VBoxLayout(LayoutItem *parent)
|
||||
: BoxLayout(TopToBottom, parent)
|
||||
{
|
||||
}
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 by Matias Valdenegro T. <mvaldenegro@informatica.utem.cl>
|
||||
* Copyright 2007 by Robert Knight <robertknight@gmail.com>
|
||||
*
|
||||
* 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_BOX_LAYOUT
|
||||
#define PLASMA_BOX_LAYOUT
|
||||
|
||||
#include <QtCore/QList>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
#include <plasma/layouts/layout.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
/**
|
||||
* The BoxLayout class lays out items in a horizontal or vertical line.
|
||||
*/
|
||||
class PLASMA_EXPORT BoxLayout : public Layout
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This enum describes the directions in which items can be laid
|
||||
* out.
|
||||
*/
|
||||
enum Direction
|
||||
{
|
||||
/** Lay items out horizontally, from left to right. */
|
||||
LeftToRight,
|
||||
/** Lay items out horizontally, from right to left. */
|
||||
RightToLeft,
|
||||
/** Lay items out vertically, from top to bottom. */
|
||||
TopToBottom,
|
||||
/** Lay items out vertically, from bottom to top. */
|
||||
BottomToTop
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new box layout which lays items out in the specified
|
||||
* @p direction
|
||||
*/
|
||||
explicit BoxLayout(Direction direction, LayoutItem *parent = 0);
|
||||
~BoxLayout();
|
||||
|
||||
/** Sets the direction in which items are laid out. */
|
||||
void setDirection(Direction direction);
|
||||
/** Returns the direction in which items are laid out. */
|
||||
Direction direction() const;
|
||||
|
||||
/** Inserts a new item into the layout at the specified index. */
|
||||
void insertItem(int index, LayoutItem *l);
|
||||
|
||||
/** Set whether this layout will take several rows */
|
||||
void setMultiRow(bool b);
|
||||
|
||||
/** Set whether this layout will expand in both directions */
|
||||
void setExpandingBoth(bool both);
|
||||
|
||||
// reimplemented from Layout
|
||||
virtual void addItem(LayoutItem *l);
|
||||
virtual void removeItem(LayoutItem *l);
|
||||
virtual int indexOf(LayoutItem *l) const;
|
||||
virtual LayoutItem *itemAt(int i) const;
|
||||
virtual LayoutItem *takeAt(int i);
|
||||
virtual Qt::Orientations expandingDirections() const;
|
||||
virtual int count() const;
|
||||
virtual void setAnimator(LayoutAnimator* animator);
|
||||
|
||||
virtual QSizeF minimumSize() const;
|
||||
virtual QSizeF maximumSize() const;
|
||||
virtual QSizeF sizeHint() const;
|
||||
|
||||
protected:
|
||||
void relayout();
|
||||
void releaseManagedItems();
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private *const d;
|
||||
};
|
||||
|
||||
/**
|
||||
* A BoxLayout which defaults to laying items out
|
||||
* horizontally in a left-to-right order.
|
||||
*
|
||||
* Equivalent to creating a BoxLayout and passing LeftToRight
|
||||
* in the constructor.
|
||||
*/
|
||||
class PLASMA_EXPORT HBoxLayout : public BoxLayout
|
||||
{
|
||||
public:
|
||||
explicit HBoxLayout(LayoutItem *parent = 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* A BoxLayout which defaults to laying items out
|
||||
* vertically in a top-to-bottom order.
|
||||
*
|
||||
* Equivalent to creating a BoxLayout and passing TopToBottom
|
||||
* in the constructor.
|
||||
*/
|
||||
class PLASMA_EXPORT VBoxLayout : public BoxLayout
|
||||
{
|
||||
public:
|
||||
explicit VBoxLayout(LayoutItem *parent = 0);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* PLASMA_BOX_LAYOUT */
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser/Library General Public License version 2,
|
||||
* or (at your option) any later version, 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 Lesser/Library General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser/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 "fliplayout.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License version 2,
|
||||
* or (at your option) any later version, 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 Lesser General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser 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_FLIPLAYOUT_H_
|
||||
#define PLASMA_FLIPLAYOUT_H_
|
||||
|
||||
#include <plasma/plasma.h>
|
||||
#include <plasma/layouts/layout.h>
|
||||
#include <plasma/widgets/widget.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
template <typename SuperLayout>
|
||||
class FlipLayout : public SuperLayout { //Plasma::Layout
|
||||
public:
|
||||
void setFlip(Flip flip)
|
||||
{
|
||||
m_flip = flip;
|
||||
}
|
||||
|
||||
Flip flip()
|
||||
{
|
||||
return m_flip;
|
||||
}
|
||||
|
||||
private:
|
||||
Flip m_flip;
|
||||
|
||||
protected:
|
||||
void relayout()
|
||||
{
|
||||
SuperLayout::relayout();
|
||||
QRectF rect = SuperLayout::geometry();
|
||||
|
||||
int count = SuperLayout::count();
|
||||
|
||||
if (m_flip == NoFlip) {
|
||||
return;
|
||||
}
|
||||
|
||||
QRectF childGeometry;
|
||||
for (int i = 0; i < count; i++) {
|
||||
Plasma::LayoutItem * item = SuperLayout::itemAt(i);
|
||||
|
||||
if (!item) continue;
|
||||
|
||||
childGeometry = item->geometry();
|
||||
if (m_flip & HorizontalFlip) {
|
||||
// 2 * rect.left() - twice because we already have one
|
||||
// value of rect.left() inside the childGeometry.left()
|
||||
childGeometry.moveLeft(
|
||||
2 * rect.left() + rect.width()
|
||||
- childGeometry.left() - childGeometry.width()
|
||||
);
|
||||
}
|
||||
if (m_flip & VerticalFlip) {
|
||||
// 2 * rect.top() - same reason as aforemontioned
|
||||
childGeometry.moveTop(
|
||||
2 * rect.top() + rect.height()
|
||||
- childGeometry.top() - childGeometry.height()
|
||||
);
|
||||
}
|
||||
item->setGeometry(childGeometry);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /*FlipLayout_H_*/
|
|
@ -1,277 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 by Robert Knight <robertknight@gmail.com>
|
||||
* Copyright 2008 by William Egert <begert@gmail.com>
|
||||
*
|
||||
* 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 of the License, 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 "flowlayout.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QRectF>
|
||||
#include <QtCore/QTimeLine>
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
#include "layoutanimator.h"
|
||||
|
||||
using namespace Plasma;
|
||||
|
||||
class FlowLayout::Private
|
||||
{
|
||||
public:
|
||||
Private() : columnWidth( -1 ) {}
|
||||
QList<LayoutItem*> items;
|
||||
qreal columnWidth;
|
||||
};
|
||||
|
||||
FlowLayout::FlowLayout(LayoutItem* parent)
|
||||
: Layout(parent)
|
||||
, d(new Private)
|
||||
{
|
||||
}
|
||||
|
||||
FlowLayout::~FlowLayout()
|
||||
{
|
||||
releaseManagedItems();
|
||||
delete d;
|
||||
}
|
||||
|
||||
int FlowLayout::count() const
|
||||
{
|
||||
return d->items.count();
|
||||
}
|
||||
|
||||
void FlowLayout::addItem(LayoutItem* item)
|
||||
{
|
||||
if (!item || d->items.contains(item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
item->setManagingLayout(this);
|
||||
d->items << item;
|
||||
|
||||
if (animator()) {
|
||||
animator()->setCurrentState(item,LayoutAnimator::InsertedState);
|
||||
}
|
||||
|
||||
updateGeometry();
|
||||
}
|
||||
void FlowLayout::removeItem(LayoutItem* item)
|
||||
{
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
item->unsetManagingLayout(this);
|
||||
d->items.removeAll(item);
|
||||
|
||||
if (animator()) {
|
||||
animator()->setCurrentState(item,LayoutAnimator::RemovedState);
|
||||
}
|
||||
|
||||
updateGeometry();
|
||||
}
|
||||
int FlowLayout::indexOf(LayoutItem* item) const
|
||||
{
|
||||
if (!item) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return d->items.indexOf(item);
|
||||
}
|
||||
LayoutItem* FlowLayout::itemAt(int i) const
|
||||
{
|
||||
if (i >= d->items.count()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return d->items[i];
|
||||
}
|
||||
|
||||
QSizeF FlowLayout::sizeHint() const
|
||||
{
|
||||
// TODO A proper algorithm here
|
||||
//
|
||||
// Idea: Return a size hint based on the golden ratio to
|
||||
// make it aesthetically good
|
||||
// eg. Longer side is 1.61x the length of the shorter side
|
||||
//
|
||||
|
||||
// testing
|
||||
return QSizeF(500,500);
|
||||
}
|
||||
|
||||
LayoutItem* FlowLayout::takeAt(int i)
|
||||
{
|
||||
if (i >= d->items.count()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return d->items.takeAt(i);
|
||||
// FIXME: Should updateGeometry() be called?
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T qSum(const QList<T>& container)
|
||||
{
|
||||
T total = 0;
|
||||
foreach( const T& item , container ) {
|
||||
total += item;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
void FlowLayout::relayout()
|
||||
{
|
||||
const QRectF rect = adjustToMargins(geometry());
|
||||
|
||||
const qreal space = spacing();
|
||||
const qreal rectWidth = rect.width();
|
||||
const qreal rectHeight = rect.height();
|
||||
const int count = d->items.count();
|
||||
//kDebug() << "Flow layout geometry set to " << geometry();
|
||||
|
||||
// calculate average size of items
|
||||
qreal colWidth = 0;
|
||||
qreal rowHeight = 0;
|
||||
qreal maxItemWidth = 0;
|
||||
qreal minItemWidth = 0;
|
||||
//qreal maxItemHeight = 0;
|
||||
qreal minItemHeight = 0;
|
||||
int colCnt = 0;
|
||||
int rowCnt = 0;
|
||||
|
||||
foreach(LayoutItem *item , d->items) {
|
||||
maxItemWidth = (maxItemWidth < item->maximumSize().width()) ?
|
||||
item->maximumSize().width() : maxItemWidth;
|
||||
minItemWidth = (minItemWidth < item->minimumSize().width()) ?
|
||||
item->minimumSize().width() : minItemWidth;
|
||||
//maxItemHeight = (maxItemHeight < item->maximumSize().height()) ?
|
||||
// item->maximumSize().height() : maxItemHeight;
|
||||
minItemHeight = (minItemHeight < item->minimumSize().height()) ?
|
||||
item->minimumSize().height() : minItemHeight;
|
||||
}
|
||||
|
||||
const int rowMax = ((minItemHeight != 0) && (minItemHeight != rectHeight)) ?
|
||||
(int)(rectHeight / (minItemHeight + space)) : 1;
|
||||
|
||||
if( maxItemWidth == 0 && minItemWidth != 0 ) {
|
||||
kDebug() << "******POSSIBLE DIVIDE BY ZERO: maxItemWidth = minItemWidth ********";
|
||||
maxItemWidth = minItemWidth + space;
|
||||
} else if( maxItemWidth == 0 && minItemWidth == 0 ) {
|
||||
kDebug() << "******POSSIBLE DIVIDE BY ZERO: maxItemWidth = rectWidth ********";
|
||||
maxItemWidth = rectWidth + space;
|
||||
}
|
||||
|
||||
// try to use the maxwidth if there is room
|
||||
// need usedSpace so we don't try to use the leftover
|
||||
// area of our rect to make a item location.
|
||||
maxItemWidth += space;
|
||||
qreal usedSpace = floor( (rectWidth / maxItemWidth ) ) * maxItemWidth;
|
||||
for(int i = 1; (i <= rowMax) && (colWidth == 0); i++) {
|
||||
if( i * (usedSpace / maxItemWidth ) >= count) {
|
||||
colWidth = maxItemWidth;
|
||||
rowHeight = (rectHeight + space) / i;
|
||||
rowCnt = i;
|
||||
colCnt = (int)(usedSpace / colWidth);
|
||||
}
|
||||
}
|
||||
|
||||
//crazy algorithm to make items fit in available space
|
||||
if( colWidth == 0) {
|
||||
// These gave me the most trouble and should
|
||||
// be taken into account if you try and change this:
|
||||
// - maxRow = 3 with 9 items and 3 columns.
|
||||
// - maxRow = 5 with 8 items and 3 colums.
|
||||
// - maxRow = 1 with odd number columns.
|
||||
|
||||
const qreal tmp = (qreal)(count + (count % 2)) / rowMax;
|
||||
if( (tmp - floor(tmp)) > 0.5) {
|
||||
colCnt = (int)ceil(tmp) + 1;
|
||||
} else {
|
||||
colCnt = (int)ceil(tmp);
|
||||
}
|
||||
rowCnt = (int)ceil((qreal)count / colCnt);
|
||||
if( (rowCnt == 1) && (colCnt&2) ) {
|
||||
colCnt--;
|
||||
}
|
||||
colWidth = rectWidth / colCnt;
|
||||
rowHeight = (rectHeight + space) / rowCnt;
|
||||
}
|
||||
|
||||
|
||||
if( minItemHeight > (rowHeight - space) ) {
|
||||
rowHeight = minItemHeight + space;
|
||||
}
|
||||
|
||||
// kDebug() << "colWidth: " << colWidth << "rowHeight: " << rowHeight
|
||||
// << "rowCnt: " << rowCnt << "rowMax: " << rowMax << "colCnt: " << colCnt;
|
||||
|
||||
|
||||
// lay the items out in left-to-right , top-to-bottom order
|
||||
int insertColumn = 0;
|
||||
qreal rowPos = 0;
|
||||
foreach(LayoutItem *item , d->items) {
|
||||
|
||||
if(insertColumn >= colCnt) {
|
||||
insertColumn = 0;
|
||||
rowPos += rowHeight;
|
||||
}
|
||||
|
||||
// position the item
|
||||
const QRectF newGeometry(rect.left() + (insertColumn * colWidth),
|
||||
rect.top() + rowPos,
|
||||
colWidth - space,
|
||||
rowHeight - space);
|
||||
|
||||
//kDebug() << "newGeometry: " << newGeometry;
|
||||
insertColumn++;
|
||||
|
||||
if ( animator() ){
|
||||
animator()->setGeometry( item , newGeometry );
|
||||
} else {
|
||||
item->setGeometry( newGeometry );
|
||||
}
|
||||
}
|
||||
|
||||
startAnimation();
|
||||
}
|
||||
|
||||
void FlowLayout::releaseManagedItems()
|
||||
{
|
||||
foreach (LayoutItem *item, d->items) {
|
||||
item->unsetManagingLayout(this);
|
||||
}
|
||||
}
|
||||
|
||||
Qt::Orientations FlowLayout::expandingDirections() const
|
||||
{
|
||||
return Qt::Vertical | Qt::Horizontal;
|
||||
}
|
||||
|
||||
qreal FlowLayout::columnWidth() const
|
||||
{
|
||||
return d->columnWidth;
|
||||
}
|
||||
|
||||
void FlowLayout::setColumnWidth( const qreal width )
|
||||
{
|
||||
d->columnWidth = width;
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 by Robert Knight <robertknight@gmail.com>
|
||||
*
|
||||
* 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 of the License, 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 __FLOWLAYOUT__
|
||||
#define __FLOWLAYOUT__
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
#include <plasma/layouts/layout.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
/**
|
||||
* A layout which lays items out left-to-right , top-to-bottom.
|
||||
*
|
||||
* This is similar to the layout of items in a QListView.
|
||||
*/
|
||||
class PLASMA_EXPORT FlowLayout : public Layout
|
||||
{
|
||||
public:
|
||||
/** Construct a new flow layout with the specified parent. */
|
||||
explicit FlowLayout(LayoutItem* parent);
|
||||
virtual ~FlowLayout();
|
||||
|
||||
// reimplemented
|
||||
virtual int count() const;
|
||||
virtual void addItem(LayoutItem* item);
|
||||
virtual void removeItem(LayoutItem* item);
|
||||
virtual int indexOf(LayoutItem* item) const;
|
||||
virtual LayoutItem* itemAt(int i) const;
|
||||
virtual LayoutItem* takeAt(int i);
|
||||
|
||||
virtual QSizeF sizeHint() const;
|
||||
virtual Qt::Orientations expandingDirections() const;
|
||||
virtual void setColumnWidth( const qreal width );
|
||||
virtual qreal columnWidth() const;
|
||||
|
||||
protected:
|
||||
void relayout();
|
||||
void releaseManagedItems();
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private *const d;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __FLOWLAYOUT__
|
||||
|
|
@ -1,176 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 by Robert Knight <robertknight@gmail.com>
|
||||
*
|
||||
* 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 "freelayout.h"
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
#include <plasma/layouts/layout.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class FreeLayout::Private
|
||||
{
|
||||
public:
|
||||
QList<LayoutItem*> children;
|
||||
};
|
||||
|
||||
FreeLayout::FreeLayout(LayoutItem *parent)
|
||||
: Layout(parent),
|
||||
d(new Private)
|
||||
{
|
||||
}
|
||||
|
||||
FreeLayout::~FreeLayout()
|
||||
{
|
||||
releaseManagedItems();
|
||||
delete d;
|
||||
}
|
||||
|
||||
Qt::Orientations FreeLayout::expandingDirections() const
|
||||
{
|
||||
return Qt::Horizontal | Qt::Vertical;
|
||||
}
|
||||
|
||||
void FreeLayout::addItem(LayoutItem *item)
|
||||
{
|
||||
if (d->children.contains(item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->children << item;
|
||||
item->setManagingLayout(this);
|
||||
}
|
||||
|
||||
void FreeLayout::removeItem(LayoutItem *item)
|
||||
{
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->children.removeAll(item);
|
||||
item->unsetManagingLayout(this);
|
||||
}
|
||||
|
||||
int FreeLayout::indexOf(LayoutItem *item) const
|
||||
{
|
||||
return d->children.indexOf(item);
|
||||
}
|
||||
|
||||
LayoutItem * FreeLayout::itemAt(int i) const
|
||||
{
|
||||
return d->children[i];
|
||||
}
|
||||
|
||||
int FreeLayout::count() const
|
||||
{
|
||||
return d->children.count();
|
||||
}
|
||||
|
||||
LayoutItem * FreeLayout::takeAt(int i)
|
||||
{
|
||||
return d->children.takeAt(i);
|
||||
}
|
||||
|
||||
void FreeLayout::relayout()
|
||||
{
|
||||
foreach (LayoutItem *child , d->children) {
|
||||
if (child->geometry().size() != child->sizeHint()) {
|
||||
/*
|
||||
* We are setting the new geometry to have the desired size (sizeHint()),
|
||||
* and we are changing the position of the topLeft corner so that the
|
||||
* ratio
|
||||
* d(widgetLeft, layoutLeft) / d(widgetRight, layoutRight)
|
||||
* is kept constant (where d(X,Y) is the distance between X and Y)
|
||||
*
|
||||
* The same goes for the vertical distances.
|
||||
*/
|
||||
|
||||
const QSizeF newSize = child->sizeHint().expandedTo(minimumSize()).boundedTo(maximumSize());
|
||||
|
||||
/*
|
||||
* Since the layout doesn't have to be originated at (0, 0), we are switching
|
||||
* to local coordinates.
|
||||
*/
|
||||
QRectF newGeometry = QRectF(child->geometry().topLeft() - geometry().topLeft(), newSize);
|
||||
|
||||
/*
|
||||
* newWidgetLeft layoutWidth - newWidgetWidth
|
||||
* ------------- = ----------------------------
|
||||
* oldWidgetLeft layoutWidth - oldWidgetWidth
|
||||
*/
|
||||
newGeometry.moveLeft(
|
||||
newGeometry.left() *
|
||||
(geometry().width() - newSize.width()) /
|
||||
(geometry().width() - child->size().width())
|
||||
);
|
||||
|
||||
/*
|
||||
* newWidgetTop layoutHeight - newWidgetHeight
|
||||
* ------------ = ------------------------------
|
||||
* oldWidgetTop layoutHeight - oldWidgetHeight
|
||||
*/
|
||||
newGeometry.moveTop(
|
||||
newGeometry.top() *
|
||||
(geometry().height() - newSize.height()) /
|
||||
(geometry().height() - child->size().height())
|
||||
);
|
||||
|
||||
/*
|
||||
* Moving back from local coordinates to global
|
||||
*/
|
||||
newGeometry.moveTopLeft(newGeometry.topLeft() + geometry().topLeft());
|
||||
|
||||
child->setGeometry(newGeometry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FreeLayout::releaseManagedItems()
|
||||
{
|
||||
foreach (LayoutItem *item, d->children) {
|
||||
item->unsetManagingLayout(this);
|
||||
}
|
||||
}
|
||||
|
||||
QRectF FreeLayout::geometry() const
|
||||
{
|
||||
if (parent()) {
|
||||
return parent()->geometry();
|
||||
}
|
||||
|
||||
return QRectF(QPointF(0, 0), maximumSize());
|
||||
}
|
||||
|
||||
QSizeF FreeLayout::sizeHint() const
|
||||
{
|
||||
if (parent()) {
|
||||
//kDebug() << "returning size hint from freelayout of" << parent()->geometry().size();
|
||||
return parent()->geometry().size();
|
||||
}
|
||||
|
||||
//kDebug() << "returning size hint from freelayout of" << maximumSize();
|
||||
return maximumSize();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 by Robert Knight <robertknight@gmail.com>
|
||||
*
|
||||
* 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_FREE_LAYOUT_H
|
||||
#define PLASMA_FREE_LAYOUT_H
|
||||
|
||||
#include <QtCore/QList>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
#include <plasma/layouts/layout.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
/**
|
||||
* The FreeLayout class is a layout for use in desktop-like workspaces where
|
||||
* items can be moved around freely and applets and widgets are allowed
|
||||
* to determine their own size.
|
||||
*
|
||||
* Whenever this layout is updated, all child items are resized to
|
||||
* their sizeHint() and left in their existing positions relative
|
||||
* to the layout borders.
|
||||
*/
|
||||
class PLASMA_EXPORT FreeLayout : public Layout
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Creates a new free layout
|
||||
*/
|
||||
explicit FreeLayout(LayoutItem *parent = 0);
|
||||
~FreeLayout();
|
||||
|
||||
// reimplemented from Layout
|
||||
virtual void addItem(LayoutItem *l);
|
||||
virtual void removeItem(LayoutItem *l);
|
||||
virtual int indexOf(LayoutItem *l) const;
|
||||
virtual LayoutItem *itemAt(int i) const;
|
||||
virtual LayoutItem *takeAt(int i);
|
||||
virtual Qt::Orientations expandingDirections() const;
|
||||
virtual QRectF geometry() const;
|
||||
virtual int count() const;
|
||||
|
||||
virtual QSizeF sizeHint() const;
|
||||
|
||||
protected:
|
||||
void relayout();
|
||||
void releaseManagedItems();
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private *const d;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* PLASMA_FREE_LAYOUT_H */
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 by Robert Knight <robertknight@gmail.com>
|
||||
*
|
||||
* 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_HBOXLAYOUT
|
||||
#define PLASMA_HBOXLAYOUT
|
||||
|
||||
#include <plasma/layouts/boxlayout.h>
|
||||
|
||||
#endif /* PLASMA_HBOXLAYOUT */
|
|
@ -1,212 +0,0 @@
|
|||
/*
|
||||
* Copyright 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 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 "layout.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <limits>
|
||||
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QTimeLine>
|
||||
#include <QtDebug>
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
#include "widgets/widget.h"
|
||||
#include "layouts/layoutanimator.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class Layout::Private
|
||||
{
|
||||
public:
|
||||
Private()
|
||||
: spacing(6.0),
|
||||
parent(0),
|
||||
animator(0),
|
||||
relayouting(false)
|
||||
{
|
||||
}
|
||||
|
||||
~Private() {}
|
||||
|
||||
qreal spacing;
|
||||
|
||||
LayoutItem *parent;
|
||||
LayoutAnimator *animator;
|
||||
|
||||
bool relayouting;
|
||||
QPointF pos;
|
||||
};
|
||||
|
||||
|
||||
Layout::Layout(LayoutItem *parent)
|
||||
: LayoutItem(),
|
||||
d(new Private)
|
||||
{
|
||||
setMargins(12, 12, 12, 12);
|
||||
setParent(parent);
|
||||
}
|
||||
|
||||
void Layout::setParent(LayoutItem *parent)
|
||||
{
|
||||
if (d->parent == parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (d->parent && d->parent->layout() == this) {
|
||||
d->parent->unsetLayout();
|
||||
releaseManagedItems();
|
||||
}
|
||||
|
||||
d->parent = parent;
|
||||
|
||||
if (parent && parent->layout() != this) {
|
||||
parent->setLayout(this);
|
||||
}
|
||||
}
|
||||
|
||||
Layout::~Layout()
|
||||
{
|
||||
if (d->parent) {
|
||||
d->parent->unsetLayout();
|
||||
d->parent = 0;
|
||||
}
|
||||
|
||||
delete d;
|
||||
}
|
||||
|
||||
bool Layout::isEmpty() const
|
||||
{
|
||||
return count() == 0;
|
||||
}
|
||||
|
||||
void Layout::updateGeometry()
|
||||
{
|
||||
if (d->relayouting) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->relayouting = true;
|
||||
relayout();
|
||||
d->relayouting = false;
|
||||
}
|
||||
|
||||
QRectF Layout::geometry() const
|
||||
{
|
||||
return QRectF(d->pos, size());
|
||||
}
|
||||
|
||||
void Layout::setGeometry(const QRectF &geom)
|
||||
{
|
||||
if (!geom.isValid() || geom == geometry()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QRectF newGeom = geom;
|
||||
|
||||
if (d->parent && !dynamic_cast<Layout*>(d->parent)) {
|
||||
newGeom = d->parent->adjustToMargins(newGeom);
|
||||
//kDebug() << "parent rect is" << d->parent->topLeft() << d->parent->size()
|
||||
// << "and we are" << geometry() << "but aiming for"
|
||||
// << newGeom << "from" << geom;
|
||||
}
|
||||
|
||||
d->pos = newGeom.topLeft();
|
||||
setSize(newGeom.size());
|
||||
// TODO: respect minimum and maximum sizes: is it possible?
|
||||
//setSize(newGeom.size().expandedTo(minimumSize()).boundedTo(maximumSize()));
|
||||
|
||||
//kDebug() << "geometry is now" << geometry();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void Layout::invalidate()
|
||||
{
|
||||
if (d->relayouting) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->relayouting = true;
|
||||
// find and update the top level layout
|
||||
Layout *layout = this;
|
||||
Layout *parentLayout = 0;
|
||||
|
||||
do {
|
||||
parentLayout = dynamic_cast<Layout*>(layout->parent());
|
||||
if (parentLayout) {
|
||||
if (parentLayout->d->relayouting) {
|
||||
break;
|
||||
}
|
||||
layout = parentLayout;
|
||||
}
|
||||
} while (parentLayout);
|
||||
|
||||
layout->relayout();
|
||||
d->relayouting = false;
|
||||
}
|
||||
|
||||
|
||||
LayoutAnimator* Layout::animator() const
|
||||
{
|
||||
return d->animator;
|
||||
}
|
||||
|
||||
void Layout::setAnimator(LayoutAnimator *animator)
|
||||
{
|
||||
d->animator = animator;
|
||||
}
|
||||
|
||||
qreal Layout::spacing() const
|
||||
{
|
||||
return d->spacing;
|
||||
}
|
||||
|
||||
void Layout::setSpacing(qreal s)
|
||||
{
|
||||
d->spacing = s;
|
||||
}
|
||||
|
||||
LayoutItem *Layout::parent() const
|
||||
{
|
||||
return d->parent;
|
||||
}
|
||||
|
||||
QSizeF Layout::minimumSize() const
|
||||
{
|
||||
return QSizeF(0,0);
|
||||
}
|
||||
QSizeF Layout::maximumSize() const
|
||||
{
|
||||
return QSizeF(std::numeric_limits<qreal>::infinity(),std::numeric_limits<qreal>::infinity());
|
||||
}
|
||||
|
||||
void Layout::startAnimation()
|
||||
{
|
||||
if (animator() && animator()->timeLine()) {
|
||||
if (animator()->timeLine()->state() == QTimeLine::NotRunning) {
|
||||
animator()->timeLine()->setCurrentTime(0);
|
||||
animator()->timeLine()->start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
185
layouts/layout.h
185
layouts/layout.h
|
@ -1,185 +0,0 @@
|
|||
/*
|
||||
* Copyright 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 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 __LAYOUT__
|
||||
#define __LAYOUT__
|
||||
|
||||
#include <QtCore/QRectF>
|
||||
#include <QtCore/QSizeF>
|
||||
|
||||
#include <plasma/layouts/layoutitem.h>
|
||||
#include <plasma/plasma_export.h>
|
||||
#include <plasma/plasma.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class LayoutAnimator;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
explicit Layout(LayoutItem *parent);
|
||||
|
||||
/**
|
||||
* Virtual Destructor.
|
||||
*/
|
||||
virtual ~Layout();
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Sets the parent of this layout.
|
||||
*/
|
||||
void setParent(LayoutItem *parent);
|
||||
|
||||
/**
|
||||
* Returns the number of elements of this Layout.
|
||||
*/
|
||||
virtual int count() const = 0;
|
||||
|
||||
/**
|
||||
* Returns true if this Layout contains no elements, false otherwise.
|
||||
*/
|
||||
bool isEmpty() const;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Returns the object controlling animation of changes
|
||||
* in this layout or 0 if no animator has been set.
|
||||
*/
|
||||
virtual LayoutAnimator* animator() const;
|
||||
|
||||
/**
|
||||
* Sets the object controlling animation of changes in this
|
||||
* layout.
|
||||
*/
|
||||
virtual void setAnimator( LayoutAnimator* animator );
|
||||
|
||||
/**
|
||||
* Returns the current geometry for this layout
|
||||
*/
|
||||
virtual QRectF geometry() const;
|
||||
|
||||
/**
|
||||
* Changes the geometry of this layout
|
||||
*/
|
||||
void setGeometry(const QRectF &geometry);
|
||||
|
||||
/** Triggers an update of the layout. */
|
||||
void updateGeometry();
|
||||
|
||||
/**
|
||||
* Returns the minimum size of this layout.
|
||||
* The default implementation allows unlimited resizing.
|
||||
*/
|
||||
virtual QSizeF minimumSize() const;
|
||||
/**
|
||||
* Returns the maximum size of this layout. The default
|
||||
* implementation allows unlimited resizing.
|
||||
*/
|
||||
virtual QSizeF maximumSize() const;
|
||||
|
||||
/** TODO Document me */
|
||||
void invalidate();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Triggers a layout, usually after a change in geometry
|
||||
*/
|
||||
virtual void relayout() = 0;
|
||||
|
||||
/**
|
||||
* When called, the layout must cease management of any
|
||||
* current LayoutItems it is managing.
|
||||
*/
|
||||
virtual void releaseManagedItems() = 0;
|
||||
|
||||
/**
|
||||
* Starts a layout animation. Subclasses may call this
|
||||
* at the end of their relayout() implementation to
|
||||
* start the timeline associated with the layout's animator()
|
||||
* if there is one. If an animation is already in progress then
|
||||
* the timeline is reset to 0ms and the animation continues.
|
||||
*/
|
||||
void startAnimation();
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private *const d;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* __LAYOUT__ */
|
|
@ -1,312 +0,0 @@
|
|||
/*
|
||||
Copyright 2007 by Robert Knight <robertknight@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, 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 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 "layoutanimator.h"
|
||||
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QPointer>
|
||||
#include <QtCore/QTimeLine>
|
||||
#include <QtGui/QGraphicsItem>
|
||||
#include <QtGui/QGraphicsScene>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "layouts/layout.h"
|
||||
#include "widgets/widget.h"
|
||||
|
||||
using namespace Plasma;
|
||||
|
||||
class LayoutAnimator::Private
|
||||
{
|
||||
public:
|
||||
QHash<LayoutAnimator::State,int> effects;
|
||||
|
||||
class ItemGeometry
|
||||
{
|
||||
public:
|
||||
QRectF startGeometry;
|
||||
QRectF endGeometry;
|
||||
};
|
||||
|
||||
QHash<LayoutItem*,ItemGeometry> geometries;
|
||||
QHash<LayoutItem*,LayoutAnimator::State> states;
|
||||
QPointer<QTimeLine> timeLine;
|
||||
qreal lastValue;
|
||||
bool autoDeleteOnRemoval;
|
||||
|
||||
Private()
|
||||
: lastValue(0)
|
||||
, autoDeleteOnRemoval(false)
|
||||
{
|
||||
}
|
||||
|
||||
qreal delta(qreal currentValue) const
|
||||
{
|
||||
if ( currentValue > lastValue ) {
|
||||
return currentValue - lastValue;
|
||||
} else {
|
||||
return (1.0-lastValue) + currentValue;
|
||||
}
|
||||
}
|
||||
|
||||
QRectF interpolateGeometry(LayoutItem* item,qreal value) const
|
||||
{
|
||||
QRectF newGeometry;
|
||||
|
||||
const QRectF& current = geometries[item].startGeometry;
|
||||
const QRectF& next = geometries[item].endGeometry;
|
||||
|
||||
newGeometry.setLeft(current.left() + (next.left()-current.left()) * value);
|
||||
newGeometry.setRight(current.right() + (next.right()-current.right()) * value);
|
||||
newGeometry.setTop(current.top() + (next.top()-current.top()) * value);
|
||||
newGeometry.setBottom(current.bottom() + (next.bottom()-current.bottom()) * value);
|
||||
|
||||
return newGeometry;
|
||||
}
|
||||
|
||||
void prepareItemForState( LayoutItem *item , LayoutAnimator::State state ) {
|
||||
|
||||
// opacity setting for widgets
|
||||
Widget *widget = dynamic_cast<Widget*>(item->graphicsItem());
|
||||
if (widget) {
|
||||
if (state == InsertedState && effects[state] == LayoutAnimator::FadeInMoveEffect) {
|
||||
widget->setOpacity(0); // item is invisible immediately after insertion
|
||||
} else {
|
||||
widget->setOpacity(1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
LayoutAnimator::LayoutAnimator(QObject* parent)
|
||||
: QObject(parent),
|
||||
d(new Private)
|
||||
{
|
||||
d->lastValue = 0;
|
||||
}
|
||||
|
||||
LayoutAnimator::~LayoutAnimator()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void LayoutAnimator::setAutoDeleteOnRemoval(bool autoDelete)
|
||||
{
|
||||
if ( d->autoDeleteOnRemoval == autoDelete )
|
||||
return;
|
||||
|
||||
d->autoDeleteOnRemoval = autoDelete;
|
||||
|
||||
if ( autoDelete ) {
|
||||
connect( this , SIGNAL(stateChanged(Plasma::LayoutItem*,Plasma::LayoutAnimator::State,Plasma::LayoutAnimator::State)) , this ,
|
||||
SLOT(itemAutoDeleter(Plasma::LayoutItem*,Plasma::LayoutAnimator::State,Plasma::LayoutAnimator::State)) );
|
||||
} else {
|
||||
disconnect( this , SIGNAL(stateChanged(Plasma::LayoutItem*,Plasma::LayoutAnimator::State,Plasma::LayoutAnimator::State)) , this ,
|
||||
SLOT(itemAutoDeleter(Plasma::LayoutItem*,Plasma::LayoutAnimator::State,Plasma::LayoutAnimator::State)) );
|
||||
}
|
||||
}
|
||||
|
||||
bool LayoutAnimator::autoDeleteOnRemoval() const
|
||||
{
|
||||
return d->autoDeleteOnRemoval;
|
||||
}
|
||||
|
||||
void LayoutAnimator::itemAutoDeleter(Plasma::LayoutItem *item, Plasma::LayoutAnimator::State oldState, Plasma::LayoutAnimator::State newState)
|
||||
{
|
||||
if ( oldState == RemovedState && newState == DeadState ) {
|
||||
if ( item->graphicsItem() ) {
|
||||
item->graphicsItem()->scene()->removeItem( item->graphicsItem() );
|
||||
|
||||
if ( dynamic_cast<QGraphicsItem*>(item) != dynamic_cast<QGraphicsItem*>(item->graphicsItem()) )
|
||||
delete item->graphicsItem();
|
||||
}
|
||||
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutAnimator::setEffect( State action , int effect )
|
||||
{
|
||||
d->effects[action] = effect;
|
||||
}
|
||||
int LayoutAnimator::effect(State action) const
|
||||
{
|
||||
return d->effects[action];
|
||||
}
|
||||
|
||||
void LayoutAnimator::setCurrentState( LayoutItem* item , State state )
|
||||
{
|
||||
if (state == RemovedState && !d->states.contains(item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
State oldState = d->states[item];
|
||||
|
||||
d->states[item] = state;
|
||||
d->prepareItemForState(item,state);
|
||||
|
||||
emit stateChanged(item,oldState,state);
|
||||
}
|
||||
LayoutAnimator::State LayoutAnimator::state( LayoutItem* item ) const
|
||||
{
|
||||
return !d->states.contains(item) ? DeadState : d->states[item];
|
||||
}
|
||||
|
||||
void LayoutAnimator::setTimeLine(QTimeLine* timeLine)
|
||||
{
|
||||
if ( d->timeLine ) {
|
||||
disconnect( d->timeLine , SIGNAL(valueChanged(qreal)) , this ,
|
||||
SLOT(valueChanged(qreal)) );
|
||||
disconnect( d->timeLine , SIGNAL(finished()) , this ,
|
||||
SLOT(animationCompleted()) );
|
||||
}
|
||||
|
||||
d->timeLine = timeLine;
|
||||
|
||||
connect( d->timeLine , SIGNAL(valueChanged(qreal)) , this ,
|
||||
SLOT(valueChanged(qreal)) );
|
||||
connect( d->timeLine , SIGNAL(finished()) , this ,
|
||||
SLOT(animationCompleted()) );
|
||||
}
|
||||
void LayoutAnimator::animationCompleted()
|
||||
{
|
||||
foreach( LayoutItem* item , d->states.keys() ) {
|
||||
animationFinished(item);
|
||||
}
|
||||
}
|
||||
QTimeLine* LayoutAnimator::timeLine() const
|
||||
{
|
||||
return d->timeLine;
|
||||
}
|
||||
void LayoutAnimator::valueChanged(qreal value)
|
||||
{
|
||||
foreach( LayoutItem* item , d->geometries.keys() ) {
|
||||
updateItem(value,item);
|
||||
}
|
||||
|
||||
d->lastValue = value;
|
||||
}
|
||||
|
||||
void LayoutAnimator::setGeometry( LayoutItem* item , const QRectF& destGeometry )
|
||||
{
|
||||
Q_ASSERT( item );
|
||||
|
||||
Private::ItemGeometry& itemGeometry = d->geometries[item];
|
||||
|
||||
itemGeometry.startGeometry = item->geometry();
|
||||
itemGeometry.endGeometry = destGeometry;
|
||||
}
|
||||
|
||||
void LayoutAnimator::moveEffectUpdateItem( qreal value , LayoutItem* item , Effect effect )
|
||||
{
|
||||
Widget* widget = dynamic_cast<Widget*>(item->graphicsItem());
|
||||
|
||||
if ( widget && effect == FadeInMoveEffect ) {
|
||||
widget->setOpacity( qMin(qreal(1.0),widget->opacity()+d->delta(value)) );
|
||||
} else if ( widget && effect == FadeOutMoveEffect ) {
|
||||
widget->setOpacity( qMax(qreal(0.0),widget->opacity()-d->delta(value)) );
|
||||
}
|
||||
|
||||
|
||||
if ( effect == FadeInMoveEffect || effect == FadeOutMoveEffect ) {
|
||||
const QRectF finalGeometry = d->geometries[item].endGeometry;
|
||||
|
||||
if ( item->geometry() != finalGeometry ) {
|
||||
item->setGeometry( finalGeometry );
|
||||
}
|
||||
} else {
|
||||
item->setGeometry( d->interpolateGeometry(item,value) );
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutAnimator::noEffectUpdateItem( qreal , LayoutItem* item )
|
||||
{
|
||||
const QRectF finalGeometry = d->geometries[item].endGeometry;
|
||||
|
||||
if ( item->geometry() != finalGeometry ) {
|
||||
item->setGeometry( finalGeometry );
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutAnimator::fadeEffectUpdateItem( qreal value , LayoutItem* item )
|
||||
{
|
||||
Widget* widget = dynamic_cast<Widget*>(item->graphicsItem());
|
||||
|
||||
qreal threshold = 0;
|
||||
|
||||
if ( widget != 0 && d->geometries[item].startGeometry != d->geometries[item].endGeometry ) {
|
||||
widget->setOpacity( qAbs( (value*2)-1.0 ) );
|
||||
threshold = 0.5;
|
||||
}
|
||||
|
||||
const QRectF newGeometry = ( value < threshold ) ? d->geometries[item].startGeometry : d->geometries[item].endGeometry;
|
||||
|
||||
item->setGeometry(newGeometry);
|
||||
}
|
||||
|
||||
void LayoutAnimator::animationFinished(LayoutItem* item)
|
||||
{
|
||||
switch ( state(item) )
|
||||
{
|
||||
case InsertedState:
|
||||
setCurrentState(item,StandardState);
|
||||
break;
|
||||
case RemovedState:
|
||||
d->states.remove(item);
|
||||
d->geometries.remove(item);
|
||||
emit stateChanged(item, RemovedState, DeadState);
|
||||
break;
|
||||
case StandardState:
|
||||
d->geometries[item].startGeometry = d->geometries[item].endGeometry;
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutAnimator::updateItem( qreal value , LayoutItem* item )
|
||||
{
|
||||
Q_ASSERT( value >= 0 && value <= 1.0 );
|
||||
Q_ASSERT( item );
|
||||
Q_ASSERT( d->geometries.contains(item) );
|
||||
|
||||
switch ( effect(d->states[item]) )
|
||||
{
|
||||
case NoEffect:
|
||||
noEffectUpdateItem(value,item);
|
||||
break;
|
||||
case MoveEffect:
|
||||
moveEffectUpdateItem(value,item,MoveEffect);
|
||||
break;
|
||||
case FadeInMoveEffect:
|
||||
moveEffectUpdateItem(value,item,FadeInMoveEffect);
|
||||
break;
|
||||
case FadeOutMoveEffect:
|
||||
moveEffectUpdateItem(value,item,FadeOutMoveEffect);
|
||||
break;
|
||||
case FadeEffect:
|
||||
fadeEffectUpdateItem(value,item);
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
#include "layoutanimator.moc"
|
||||
|
|
@ -1,213 +0,0 @@
|
|||
/*
|
||||
Copyright 2007 by Robert Knight <robertknight@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, 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 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 __LAYOUTANIMATOR__
|
||||
#define __LAYOUTANIMATOR__
|
||||
|
||||
#include <QtCore/QRectF>
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
class QTimeLine;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class Layout;
|
||||
class LayoutItem;
|
||||
|
||||
/**
|
||||
* LayoutAnimator can be used to animate changes
|
||||
* in Layouts.
|
||||
*
|
||||
* @code
|
||||
*
|
||||
* LayoutAnimator* animator = new LayoutAnimator;
|
||||
* QTimeLine* timeLine = new QTimeLine;
|
||||
*
|
||||
* animator->setTimeLine(timeLine);
|
||||
* animator->setEffect( LayoutAnimator::InsertedState , LayoutAnimator::FadeInMoveEffect );
|
||||
* animator->setEffect( LayoutAnimator::StandardState , LayoutAnimator::MoveEffect );
|
||||
* animator->setEffect( LayoutAnimator::RemovedState , LayoutAnimator::FadeOutMoveEffect );
|
||||
* myLayout->setAnimator(animator);
|
||||
*
|
||||
* @endcode
|
||||
*/
|
||||
class PLASMA_EXPORT LayoutAnimator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/** Constructs a new layout animator with the specified parent. */
|
||||
explicit LayoutAnimator(QObject* parent = 0);
|
||||
~LayoutAnimator();
|
||||
|
||||
/**
|
||||
* This enum describes the possible states which a layout item may be in.
|
||||
* Different effects can be defined for items which are being inserted,
|
||||
* moved or resized or removed from layouts.
|
||||
*/
|
||||
enum State
|
||||
{
|
||||
/**
|
||||
* State for an item which has recently been added to a layout.
|
||||
* When the animation completes, the item's state will change to
|
||||
* StandardState
|
||||
*/
|
||||
InsertedState,
|
||||
/**
|
||||
* Normal state for items in the layout.
|
||||
* Items will remain in this state until it is explicitly changed
|
||||
* via setCurrentState()
|
||||
*/
|
||||
StandardState,
|
||||
/**
|
||||
* State for an item which is currently being removed from a layout.
|
||||
* When the animation completes, the item will be removed from the
|
||||
* animator and its state will be undefined.
|
||||
*/
|
||||
RemovedState,
|
||||
/**
|
||||
* State for an item whoose geometry is not managed by the animator.
|
||||
*
|
||||
* All LayoutItems are initially in this state and are moved into a
|
||||
* different state ( usually InsertedState ) by calling
|
||||
* setCurrentState( item , state )
|
||||
*
|
||||
* An item transitions into this state when the animation completes
|
||||
* whilst the item is in RemovedState
|
||||
*/
|
||||
DeadState
|
||||
};
|
||||
|
||||
/**
|
||||
* This enum describes the available effects which can be used
|
||||
* to animate changes in a layout.
|
||||
*/
|
||||
enum Effect
|
||||
{
|
||||
/**
|
||||
* No effect. When the animation begins, the item immediately appears
|
||||
* in its final position and size.
|
||||
*/
|
||||
NoEffect,
|
||||
/**
|
||||
* The item is smoothly moved and resized from its initial geometry to its final
|
||||
* geometry as the animation progresses.
|
||||
*/
|
||||
MoveEffect,
|
||||
/**
|
||||
* The item fades out during the first half of the animation in its initial geometry
|
||||
* and then fades in at its final position and size during the second half of
|
||||
* the animation.
|
||||
*/
|
||||
FadeEffect,
|
||||
/**
|
||||
* The item is initially invisible and fades in whilst moving and resizing to
|
||||
* its final position as the animation progresses.
|
||||
*/
|
||||
FadeInMoveEffect,
|
||||
/**
|
||||
* The item is initially fully opqaue and fades out whilst moving and resizing
|
||||
* to its final position as the animation progresses.
|
||||
*/
|
||||
FadeOutMoveEffect
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the @p effect for items in the layout which are under-going a change
|
||||
* specified by @p action.
|
||||
*
|
||||
* This allows different effects to be defined for items which are being added to,
|
||||
* removed from, or repositioned inside layouts.
|
||||
*/
|
||||
void setEffect( State state , int effect );
|
||||
/** See setEffect() */
|
||||
int effect( State state ) const;
|
||||
|
||||
/**
|
||||
* Sets the current action for a particular layout item. The Layout class
|
||||
* should call this before changing an item so that the animator can apply the correct
|
||||
* animation.
|
||||
*
|
||||
* When the current animation completes, depending on the current @p state, the item
|
||||
* may advance into a new state.
|
||||
*/
|
||||
void setCurrentState( LayoutItem* item , State state );
|
||||
/** See setCurrentState() */
|
||||
State state( LayoutItem* item ) const;
|
||||
|
||||
/**
|
||||
* Sets the new geometry for a layout item.
|
||||
* The item will animate from its current geometry to @p geometry, using
|
||||
* the effect specified in setEffect() for the state currently associated
|
||||
* with @p item
|
||||
*/
|
||||
virtual void setGeometry( LayoutItem* item , const QRectF& geometry );
|
||||
|
||||
/**
|
||||
* Sets the time line used by this animator.
|
||||
*
|
||||
* The duration of the animation can be changed by altering @p timeLine 's duration
|
||||
*/
|
||||
void setTimeLine( QTimeLine* timeLine );
|
||||
/** Returns the QTimeLine used by this animator. */
|
||||
QTimeLine* timeLine() const;
|
||||
|
||||
/**
|
||||
* Convenience feature which causes LayoutItems and their associated
|
||||
* QGraphicsItems to be automatically deleted when their removal
|
||||
* animation finishes.
|
||||
*
|
||||
* The default is false.
|
||||
*/
|
||||
void setAutoDeleteOnRemoval(bool autoDelete);
|
||||
/** See setAutoDeleteOnRemoval() */
|
||||
bool autoDeleteOnRemoval() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
/** This signal is emitted when the state of an item in the animator changes. */
|
||||
void stateChanged(Plasma::LayoutItem *item, Plasma::LayoutAnimator::State oldState, Plasma::LayoutAnimator::State newState);
|
||||
|
||||
protected:
|
||||
virtual void updateItem( qreal value , LayoutItem* item );
|
||||
|
||||
private Q_SLOTS:
|
||||
void valueChanged(qreal value);
|
||||
void animationCompleted();
|
||||
void itemAutoDeleter(Plasma::LayoutItem *item, Plasma::LayoutAnimator::State oldState, Plasma::LayoutAnimator::State newState);
|
||||
|
||||
private:
|
||||
void moveEffectUpdateItem(qreal value,LayoutItem* item,Effect effect);
|
||||
void noEffectUpdateItem(qreal value,LayoutItem* item);
|
||||
void fadeEffectUpdateItem(qreal value,LayoutItem* item);
|
||||
|
||||
void animationFinished(LayoutItem* item);
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private* const d;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __LAYOUTANIMATOR__
|
||||
|
|
@ -1,251 +0,0 @@
|
|||
/*
|
||||
* Copyright 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 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 "layoutitem.h"
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
#include "layout.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class LayoutItem::Private
|
||||
{
|
||||
public:
|
||||
Private()
|
||||
: layout(0),
|
||||
managingLayout(0),
|
||||
leftMargin(0),
|
||||
rightMargin(0),
|
||||
topMargin(0),
|
||||
bottomMargin(0)
|
||||
{
|
||||
}
|
||||
|
||||
~Private() {}
|
||||
|
||||
Layout* layout;
|
||||
Layout* managingLayout;
|
||||
QSizeF size;
|
||||
qreal leftMargin;
|
||||
qreal rightMargin;
|
||||
qreal topMargin;
|
||||
qreal bottomMargin;
|
||||
};
|
||||
|
||||
LayoutItem::LayoutItem()
|
||||
: d(new Private())
|
||||
{
|
||||
}
|
||||
|
||||
LayoutItem::~LayoutItem()
|
||||
{
|
||||
if (d->managingLayout) {
|
||||
d->managingLayout->removeItem(this);
|
||||
}
|
||||
|
||||
delete d->layout;
|
||||
delete d;
|
||||
}
|
||||
|
||||
QGraphicsItem* LayoutItem::graphicsItem()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool LayoutItem::hasHeightForWidth() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
qreal LayoutItem::heightForWidth(qreal w) const
|
||||
{
|
||||
Q_UNUSED (w);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
bool LayoutItem::hasWidthForHeight() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
qreal LayoutItem::widthForHeight(qreal h) const
|
||||
{
|
||||
Q_UNUSED (h);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
void LayoutItem::setLayout(Layout* layout)
|
||||
{
|
||||
if (d->layout == layout) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete d->layout;
|
||||
d->layout = layout;
|
||||
|
||||
if (layout) {
|
||||
layout->setParent(this);
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutItem::unsetLayout()
|
||||
{
|
||||
d->layout = 0;
|
||||
}
|
||||
|
||||
Layout* LayoutItem::layout() const
|
||||
{
|
||||
return d->layout;
|
||||
}
|
||||
|
||||
void LayoutItem::setManagingLayout(Layout* layout)
|
||||
{
|
||||
if (layout == d->managingLayout) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (d->managingLayout) {
|
||||
d->managingLayout->removeItem(this);
|
||||
}
|
||||
|
||||
d->managingLayout = layout;
|
||||
managingLayoutChanged();
|
||||
}
|
||||
|
||||
void LayoutItem::unsetManagingLayout(Layout* layout)
|
||||
{
|
||||
if (d->managingLayout == layout) {
|
||||
d->managingLayout = 0;
|
||||
}
|
||||
managingLayoutChanged();
|
||||
}
|
||||
|
||||
void LayoutItem::managingLayoutChanged()
|
||||
{
|
||||
}
|
||||
|
||||
QPointF LayoutItem::topLeft() const
|
||||
{
|
||||
return QPointF(0, 0);
|
||||
}
|
||||
|
||||
Layout* LayoutItem::managingLayout() const
|
||||
{
|
||||
return d->managingLayout;
|
||||
}
|
||||
|
||||
qreal LayoutItem::margin(Plasma::MarginEdge edge) const
|
||||
{
|
||||
switch (edge) {
|
||||
case LeftMargin:
|
||||
return d->leftMargin;
|
||||
break;
|
||||
case RightMargin:
|
||||
return d->rightMargin;
|
||||
break;
|
||||
case TopMargin:
|
||||
return d->topMargin;
|
||||
break;
|
||||
case BottomMargin:
|
||||
return d->bottomMargin;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QRectF LayoutItem::adjustToMargins(const QRectF &rect) const
|
||||
{
|
||||
QRectF r(rect);
|
||||
|
||||
if (r.x() <= d->leftMargin) {
|
||||
r.setX(d->leftMargin);
|
||||
}
|
||||
|
||||
if (r.y() <= d->topMargin) {
|
||||
r.setY(d->topMargin);
|
||||
}
|
||||
|
||||
QPointF tl = topLeft();
|
||||
qreal maxWidth = d->size.width() + tl.x() - d->leftMargin - d->rightMargin;
|
||||
if (r.width() > maxWidth) {
|
||||
r.setWidth(maxWidth);
|
||||
}
|
||||
|
||||
qreal maxHeight = d->size.height() + tl.y() - d->topMargin - d->bottomMargin;
|
||||
if (r.height() > maxHeight) {
|
||||
r.setHeight(maxHeight);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void LayoutItem::setMargin(Plasma::MarginEdge edge, qreal m)
|
||||
{
|
||||
switch (edge) {
|
||||
case LeftMargin:
|
||||
d->leftMargin = m;
|
||||
break;
|
||||
case RightMargin:
|
||||
d->rightMargin = m;
|
||||
break;
|
||||
case TopMargin:
|
||||
d->topMargin = m;
|
||||
break;
|
||||
case BottomMargin:
|
||||
d->bottomMargin = m;
|
||||
break;
|
||||
}
|
||||
|
||||
if (d->layout) {
|
||||
d->layout->setGeometry(d->layout->geometry());
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutItem::setMargin(qreal m)
|
||||
{
|
||||
setMargins(m, m, m, m);
|
||||
}
|
||||
|
||||
void LayoutItem::setMargins(qreal left, qreal top, qreal right, qreal bottom)
|
||||
{
|
||||
d->leftMargin = left;
|
||||
d->rightMargin = right;
|
||||
d->topMargin = top;
|
||||
d->bottomMargin = bottom;
|
||||
|
||||
if (d->layout) {
|
||||
d->layout->setGeometry(d->layout->geometry());
|
||||
}
|
||||
}
|
||||
|
||||
QSizeF LayoutItem::size() const
|
||||
{
|
||||
return d->size;
|
||||
}
|
||||
|
||||
void LayoutItem::setSize(const QSizeF &size)
|
||||
{
|
||||
d->size = size;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,223 +0,0 @@
|
|||
/*
|
||||
* Copyright 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 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 __LAYOUT_ITEM__
|
||||
#define __LAYOUT_ITEM__
|
||||
|
||||
#include <QtCore/QRectF>
|
||||
#include <QtCore/QSizeF>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
#include <plasma/plasma.h>
|
||||
|
||||
class QGraphicsItem;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
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.
|
||||
*/
|
||||
explicit 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;
|
||||
|
||||
/**
|
||||
* Updates the layouting of the item without first changing its geometry.
|
||||
* Calling this may result in a geometry change, but may not, depending
|
||||
* on the managing layout if any.
|
||||
*/
|
||||
virtual void updateGeometry() = 0;
|
||||
|
||||
/**
|
||||
* Returns the most appropriate size of this Item to hold whatever contents it has.
|
||||
*/
|
||||
virtual QSizeF sizeHint() const = 0;
|
||||
|
||||
/**
|
||||
* Sets the layout that will manage children items. The LayoutItem
|
||||
* takes ownership of the layout from that point forward, unless
|
||||
* unsetLayout() is called.
|
||||
*
|
||||
* @param layout The Layout that this LayoutItem will be managed by.
|
||||
*/
|
||||
void setLayout(Layout* layout);
|
||||
|
||||
/**
|
||||
* Resets the layout that will manage children items to no layout.
|
||||
* Note that the caller of this method must alert any items managed
|
||||
* by the layout of this change if necessary. Primarily, this should
|
||||
* only be used from the dtors of LayoutItem subclasses.
|
||||
*/
|
||||
void unsetLayout();
|
||||
|
||||
/**
|
||||
* @return the layout this item is currently associated with.
|
||||
*/
|
||||
Layout* layout() const;
|
||||
|
||||
/**
|
||||
* Sets the layout that manages this item's geometry
|
||||
*
|
||||
* @param layout the layout that manage this item's geometry
|
||||
**/
|
||||
void setManagingLayout(Layout* layout);
|
||||
|
||||
/**
|
||||
* Resets the layout that manges this item's geometry if it is the
|
||||
* currently associated layout
|
||||
*
|
||||
* @param layout to unset
|
||||
**/
|
||||
void unsetManagingLayout(Layout* layout);
|
||||
|
||||
/**
|
||||
* @return the layout that manages this item's geometry, or 0 if none
|
||||
**/
|
||||
Layout* managingLayout() const;
|
||||
|
||||
/**
|
||||
* Returns the margin of this Layout.
|
||||
*/
|
||||
qreal margin(Plasma::MarginEdge edge) const;
|
||||
|
||||
/**
|
||||
* @return the rect adjust to the margins of this item
|
||||
*/
|
||||
QRectF adjustToMargins(const QRectF &rect) const;
|
||||
|
||||
/**
|
||||
* Sets the margin of this Layout.
|
||||
*/
|
||||
void setMargin(Plasma::MarginEdge edge, qreal m);
|
||||
|
||||
/**
|
||||
* Sets all the margins of this Layout.
|
||||
*/
|
||||
void setMargin(qreal m);
|
||||
|
||||
/**
|
||||
* Sets all the margins of this Layout.
|
||||
*/
|
||||
void setMargins(qreal left, qreal top, qreal right, qreal bottom);
|
||||
|
||||
/**
|
||||
* Sets the size of the layout item
|
||||
*/
|
||||
void setSize(const QSizeF &size);
|
||||
|
||||
/**
|
||||
* @return the size of this item
|
||||
*/
|
||||
QSizeF size() const;
|
||||
|
||||
/**
|
||||
* Returns the graphics item associated with this layout item or 0
|
||||
* if there is no associated graphics item.
|
||||
*
|
||||
* The default implementation returns 0.
|
||||
*/
|
||||
virtual QGraphicsItem* graphicsItem();
|
||||
|
||||
/**
|
||||
* Get the topLeft of the item in its coordinate space
|
||||
*/
|
||||
virtual QPointF topLeft() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Reimplement to respond to a change in managing layout
|
||||
*/
|
||||
virtual void managingLayoutChanged();
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private *const d;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* __LAYOUT_ITEM__ */
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 by Robert Knight <robertknight@gmail.com>
|
||||
*
|
||||
* 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_VBOXLAYOUT
|
||||
#define PLASMA_VBOXLAYOUT
|
||||
|
||||
#include <plasma/layouts/boxlayout.h>
|
||||
|
||||
#endif /* PLASMA_VBOXLAYOUT */
|
Loading…
Reference in New Issue
Block a user