From 28b20a150aeebbd6786c5a65e26978e863d25d57 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Thu, 26 Jul 2007 07:23:30 +0000 Subject: [PATCH] * add hbox to build * make hbox share the boxlayout superclass with vbox * profit svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=692756 --- CMakeLists.txt | 2 + widgets/hboxlayout.cpp | 113 ++++------------------------------------- widgets/hboxlayout.h | 23 +-------- widgets/vboxlayout.h | 2 - 4 files changed, 14 insertions(+), 126 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64c913669..bd00f3385 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ set(plasma_LIB_SRCS karambamanager.cpp widgets/boxlayout.cpp widgets/checkbox.cpp + widgets/hboxlayout.cpp widgets/icon.cpp widgets/lineedit.cpp widgets/pushbutton.cpp @@ -94,6 +95,7 @@ install(FILES install(FILES widgets/boxlayout.h + widgets/hboxlayout.h widgets/icon.h widgets/layout.h widgets/layoutitem.h diff --git a/widgets/hboxlayout.cpp b/widgets/hboxlayout.cpp index 141fb1098..42dd8ac0f 100755 --- a/widgets/hboxlayout.cpp +++ b/widgets/hboxlayout.cpp @@ -25,30 +25,14 @@ namespace Plasma { -class HBoxLayout::Private -{ - public: - Private() {} - ~Private() {} - - QRectF geometry; - QList childList; -}; - - HBoxLayout::HBoxLayout(LayoutItem *parent) - : Layout(parent), - d(new Private) + : BoxLayout(parent), + d(0) { } HBoxLayout::~HBoxLayout() { - foreach (LayoutItem *l, d->childList) { - l->resetLayout(); - } - - delete d; } Qt::Orientations HBoxLayout::expandingDirections() const @@ -56,16 +40,6 @@ Qt::Orientations HBoxLayout::expandingDirections() const return Qt::Horizontal; } -QSizeF HBoxLayout::minimumSize() const -{ - return QSizeF(); -} - -QSizeF HBoxLayout::maximumSize() const -{ - return QSizeF(); -} - bool HBoxLayout::hasWidthForHeight() const { return true; @@ -73,14 +47,10 @@ bool HBoxLayout::hasWidthForHeight() const qreal HBoxLayout::widthForHeight(qreal w) const { + Q_UNUSED(w); return qreal(); } -QRectF HBoxLayout::geometry() const -{ - return d->geometry; -} - void HBoxLayout::setGeometry(const QRectF& geometry) { if (!geometry.isValid() || geometry.isEmpty()) { @@ -88,24 +58,24 @@ void HBoxLayout::setGeometry(const QRectF& geometry) return; } - kDebug() << this << " Geometry process " << geometry << " for " << d->childList.count() << " childrens"<< endl; + //kDebug() << this << " Geometry process " << geometry << " for " << children().count() << " childrens"<< endl; - QList children; + QList fixedChildren; QList expandingChildren; QList sizes; QSizeF available = geometry.size() - QSizeF(2 * margin(), 2 * margin()); - foreach (LayoutItem *l, d->childList) { + foreach (LayoutItem *l, children()) { kDebug() << "testing layout item " << l << endl; if (l->expandingDirections() & Qt::Horizontal) { expandingChildren += l; } else { - children += l; + fixedChildren += l; } } - foreach (LayoutItem *l, children) { + foreach (LayoutItem *l, fixedChildren) { QSizeF hint = l->sizeHint(); sizes.insert(indexOf(l), QSizeF(available.width(), hint.height())); available -= QSizeF(hint.width() + spacing(), 0.0f); @@ -122,16 +92,13 @@ void HBoxLayout::setGeometry(const QRectF& geometry) start += QPointF(margin(), spacing()); for (int i = 0; i < sizes.size(); i++) { - LayoutItem *l = itemAt(i); - kDebug() << "Setting Geometry for child " << l << " to " << QRectF(start, sizes[i]) << endl; - l->setGeometry(QRectF(start, sizes[i])); start += QPointF(sizes[i].width() + spacing(), 0.0); } - d->geometry = geometry; + BoxLayout::setGeometry(geometry); } QSizeF HBoxLayout::sizeHint() const @@ -139,7 +106,7 @@ QSizeF HBoxLayout::sizeHint() const qreal hintHeight = 0.0; qreal hintWidth = 0.0; - foreach(LayoutItem *l, d->childList) { + foreach(LayoutItem *l, children()) { QSizeF hint = l->sizeHint(); @@ -150,64 +117,4 @@ QSizeF HBoxLayout::sizeHint() const 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(); -} - } diff --git a/widgets/hboxlayout.h b/widgets/hboxlayout.h index 15d1262a2..4e8fc7b33 100755 --- a/widgets/hboxlayout.h +++ b/widgets/hboxlayout.h @@ -23,7 +23,7 @@ #include #include -#include +#include namespace Plasma { @@ -36,7 +36,7 @@ namespace Plasma * * 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: @@ -52,32 +52,13 @@ class PLASMA_EXPORT HBoxLayout : public Layout Qt::Orientations expandingDirections() const; - QSizeF minimumSize() const; - QSizeF maximumSize() const; - bool hasWidthForHeight() const; qreal widthForHeight(qreal w) const; - QRectF geometry() const; void setGeometry(const QRectF& geometry); 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: class Private; Private *const d; diff --git a/widgets/vboxlayout.h b/widgets/vboxlayout.h index b9449c85e..25e04ef39 100644 --- a/widgets/vboxlayout.h +++ b/widgets/vboxlayout.h @@ -56,8 +56,6 @@ class PLASMA_EXPORT VBoxLayout : public BoxLayout QSizeF sizeHint() const; - QSizeF size() const; - private: class Private; Private *const d;