* add hbox to build

* make hbox share the boxlayout superclass with vbox
* profit

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=692756
This commit is contained in:
Aaron J. Seigo 2007-07-26 07:23:30 +00:00
parent bdb1418dbb
commit 28b20a150a
4 changed files with 14 additions and 126 deletions

View File

@ -30,6 +30,7 @@ set(plasma_LIB_SRCS
karambamanager.cpp karambamanager.cpp
widgets/boxlayout.cpp widgets/boxlayout.cpp
widgets/checkbox.cpp widgets/checkbox.cpp
widgets/hboxlayout.cpp
widgets/icon.cpp widgets/icon.cpp
widgets/lineedit.cpp widgets/lineedit.cpp
widgets/pushbutton.cpp widgets/pushbutton.cpp
@ -94,6 +95,7 @@ install(FILES
install(FILES install(FILES
widgets/boxlayout.h widgets/boxlayout.h
widgets/hboxlayout.h
widgets/icon.h widgets/icon.h
widgets/layout.h widgets/layout.h
widgets/layoutitem.h widgets/layoutitem.h

View File

@ -25,30 +25,14 @@
namespace Plasma namespace Plasma
{ {
class HBoxLayout::Private
{
public:
Private() {}
~Private() {}
QRectF geometry;
QList<LayoutItem *> childList;
};
HBoxLayout::HBoxLayout(LayoutItem *parent) HBoxLayout::HBoxLayout(LayoutItem *parent)
: Layout(parent), : BoxLayout(parent),
d(new Private) d(0)
{ {
} }
HBoxLayout::~HBoxLayout() HBoxLayout::~HBoxLayout()
{ {
foreach (LayoutItem *l, d->childList) {
l->resetLayout();
}
delete d;
} }
Qt::Orientations HBoxLayout::expandingDirections() const Qt::Orientations HBoxLayout::expandingDirections() const
@ -56,16 +40,6 @@ Qt::Orientations HBoxLayout::expandingDirections() const
return Qt::Horizontal; return Qt::Horizontal;
} }
QSizeF HBoxLayout::minimumSize() const
{
return QSizeF();
}
QSizeF HBoxLayout::maximumSize() const
{
return QSizeF();
}
bool HBoxLayout::hasWidthForHeight() const bool HBoxLayout::hasWidthForHeight() const
{ {
return true; return true;
@ -73,14 +47,10 @@ bool HBoxLayout::hasWidthForHeight() const
qreal HBoxLayout::widthForHeight(qreal w) const qreal HBoxLayout::widthForHeight(qreal w) const
{ {
Q_UNUSED(w);
return qreal(); return qreal();
} }
QRectF HBoxLayout::geometry() const
{
return d->geometry;
}
void HBoxLayout::setGeometry(const QRectF& geometry) void HBoxLayout::setGeometry(const QRectF& geometry)
{ {
if (!geometry.isValid() || geometry.isEmpty()) { if (!geometry.isValid() || geometry.isEmpty()) {
@ -88,24 +58,24 @@ void HBoxLayout::setGeometry(const QRectF& geometry)
return; return;
} }
kDebug() << this << " Geometry process " << geometry << " for " << d->childList.count() << " childrens"<< endl; //kDebug() << this << " Geometry process " << geometry << " for " << children().count() << " childrens"<< endl;
QList<LayoutItem *> children; QList<LayoutItem *> fixedChildren;
QList<LayoutItem *> expandingChildren; QList<LayoutItem *> expandingChildren;
QList<QSizeF> sizes; QList<QSizeF> sizes;
QSizeF available = geometry.size() - QSizeF(2 * margin(), 2 * margin()); QSizeF available = geometry.size() - QSizeF(2 * margin(), 2 * margin());
foreach (LayoutItem *l, d->childList) { foreach (LayoutItem *l, children()) {
kDebug() << "testing layout item " << l << endl; kDebug() << "testing layout item " << l << endl;
if (l->expandingDirections() & Qt::Horizontal) { if (l->expandingDirections() & Qt::Horizontal) {
expandingChildren += l; expandingChildren += l;
} else { } else {
children += l; fixedChildren += l;
} }
} }
foreach (LayoutItem *l, children) { foreach (LayoutItem *l, fixedChildren) {
QSizeF hint = l->sizeHint(); QSizeF hint = l->sizeHint();
sizes.insert(indexOf(l), QSizeF(available.width(), hint.height())); sizes.insert(indexOf(l), QSizeF(available.width(), hint.height()));
available -= QSizeF(hint.width() + spacing(), 0.0f); available -= QSizeF(hint.width() + spacing(), 0.0f);
@ -122,16 +92,13 @@ void HBoxLayout::setGeometry(const QRectF& geometry)
start += QPointF(margin(), spacing()); start += QPointF(margin(), spacing());
for (int i = 0; i < sizes.size(); i++) { for (int i = 0; i < sizes.size(); i++) {
LayoutItem *l = itemAt(i); LayoutItem *l = itemAt(i);
kDebug() << "Setting Geometry for child " << l << " to " << QRectF(start, sizes[i]) << endl; kDebug() << "Setting Geometry for child " << l << " to " << QRectF(start, sizes[i]) << endl;
l->setGeometry(QRectF(start, sizes[i])); l->setGeometry(QRectF(start, sizes[i]));
start += QPointF(sizes[i].width() + spacing(), 0.0); start += QPointF(sizes[i].width() + spacing(), 0.0);
} }
d->geometry = geometry; BoxLayout::setGeometry(geometry);
} }
QSizeF HBoxLayout::sizeHint() const QSizeF HBoxLayout::sizeHint() const
@ -139,7 +106,7 @@ QSizeF HBoxLayout::sizeHint() const
qreal hintHeight = 0.0; qreal hintHeight = 0.0;
qreal hintWidth = 0.0; qreal hintWidth = 0.0;
foreach(LayoutItem *l, d->childList) { foreach(LayoutItem *l, children()) {
QSizeF hint = l->sizeHint(); QSizeF hint = l->sizeHint();
@ -150,64 +117,4 @@ QSizeF HBoxLayout::sizeHint() const
return QSizeF(hintWidth, hintHeight); return QSizeF(hintWidth, hintHeight);
} }
int HBoxLayout::count() const
{
return d->childList.count();
}
bool HBoxLayout::isEmpty() const
{
return count() == 0;
}
void HBoxLayout::insertItem(int index, LayoutItem *l)
{
if (!l) {
return;
}
l->setLayout(this);
d->childList.insert(index, l);
setGeometry(geometry());
}
void HBoxLayout::addItem(LayoutItem *l)
{
if (!l) {
return;
}
l->setLayout(this);
d->childList.append(l);
qDebug("Added Child LayoutItem : %p", l);
setGeometry(geometry());
}
void HBoxLayout::removeItem(LayoutItem *l)
{
d->childList.removeAll(l);
}
int HBoxLayout::indexOf(LayoutItem *l) const
{
return d->childList.indexOf(l);
}
LayoutItem *HBoxLayout::itemAt(int i) const
{
return d->childList[i];
}
LayoutItem *HBoxLayout::takeAt(int i)
{
return d->childList.takeAt(i);
setGeometry(geometry());
}
QSizeF HBoxLayout::size() const
{
return geometry().size();
}
} }

View File

@ -23,7 +23,7 @@
#include <QtCore/QSizeF> #include <QtCore/QSizeF>
#include <plasma/plasma_export.h> #include <plasma/plasma_export.h>
#include <plasma/widgets/layout.h> #include <plasma/widgets/boxlayout.h>
namespace Plasma namespace Plasma
{ {
@ -36,7 +36,7 @@ namespace Plasma
* *
* This class implements a Horizontal Box Layout, it just lays items horizontally, from left to right. * This class implements a Horizontal Box Layout, it just lays items horizontally, from left to right.
*/ */
class PLASMA_EXPORT HBoxLayout : public Layout class PLASMA_EXPORT HBoxLayout : public BoxLayout
{ {
public: public:
@ -52,32 +52,13 @@ class PLASMA_EXPORT HBoxLayout : public Layout
Qt::Orientations expandingDirections() const; Qt::Orientations expandingDirections() const;
QSizeF minimumSize() const;
QSizeF maximumSize() const;
bool hasWidthForHeight() const; bool hasWidthForHeight() const;
qreal widthForHeight(qreal w) const; qreal widthForHeight(qreal w) const;
QRectF geometry() const;
void setGeometry(const QRectF& geometry); void setGeometry(const QRectF& geometry);
QSizeF sizeHint() const; QSizeF sizeHint() const;
int count() const;
bool isEmpty() const;
void insertItem(int index, LayoutItem *l);
void addItem(LayoutItem *l);
void removeItem(LayoutItem *l);
int indexOf(LayoutItem *l) const;
LayoutItem *itemAt(int i) const;
LayoutItem *takeAt(int i);
QSizeF size() const;
private: private:
class Private; class Private;
Private *const d; Private *const d;

View File

@ -56,8 +56,6 @@ class PLASMA_EXPORT VBoxLayout : public BoxLayout
QSizeF sizeHint() const; QSizeF sizeHint() const;
QSizeF size() const;
private: private:
class Private; class Private;
Private *const d; Private *const d;