Implementing basic layouting in the applet layout.

get the rest compiling

svn path=/trunk/KDE/kdebase/workspace/plasma/lib/; revision=492691
This commit is contained in:
Zack Rusin 2005-12-30 20:09:10 +00:00
parent 879fbb19a0
commit 5d043ae79d
4 changed files with 149 additions and 3 deletions

View File

@ -19,6 +19,11 @@
#include "applet.h" #include "applet.h"
#include "appletChain.h" #include "appletChain.h"
#include <kdebug.h>
#include <QApplication>
#include <QDesktopWidget>
namespace Plasma namespace Plasma
{ {
@ -87,12 +92,12 @@ void AppletChain::setXineramaScreen(int screen)
d->screen = screen; d->screen = screen;
} }
void loadApplet(KService::Ptr) void AppletChain::loadApplet(KService::Ptr)
{ {
//TODO: load the buggers from a KService pointer! //TODO: load the buggers from a KService pointer!
} }
void addApplet(Plasma::Applet* applet) void AppletChain::addApplet(Plasma::Applet* applet)
{ {
d->applets.append(applet); d->applets.append(applet);
} }

View File

@ -26,6 +26,8 @@
namespace Plasma namespace Plasma
{ {
class Applet;
class KDE_EXPORT AppletChain : public QObject, public KShared class KDE_EXPORT AppletChain : public QObject, public KShared
{ {
Q_OBJECT Q_OBJECT

View File

@ -1,13 +1,136 @@
#include "appletLayout.h" #include "appletLayout.h"
#include <QLayoutItem>
#include <QSizePolicy>
#include <QRect>
namespace Plasma namespace Plasma
{ {
struct AppletLayoutItem
{
public:
AppletLayoutItem(QLayoutItem *it);
private:
QLayoutItem *item;
};
class AppletLayout::Private
{
public:
~Private()
{
QLayoutItem *item;
while ((item = takeAt(0)))
delete item;
}
QLayoutItem *takeAt(int index)
{
if (index >= 0 && index < itemList.size())
return itemList.takeAt(index);
else
return 0;
}
QList<QLayoutItem *> itemList;
};
AppletLayout::AppletLayout(QWidget *parent) AppletLayout::AppletLayout(QWidget *parent)
: QLayout(parent) : QLayout(parent),
d(new Private)
{ {
} }
AppletLayout::~AppletLayout()
{
delete d; d = 0;
} }
void AppletLayout::addItem(QLayoutItem *item)
{
d->itemList.append(item);
}
Qt::Orientations AppletLayout::expandingDirections() const
{
return 0;
}
bool AppletLayout::hasHeightForWidth() const
{
return true;
}
int AppletLayout::heightForWidth(int width) const
{
int height = layoutApplets(QRect(0, 0, width, 0), true);
return height;
}
int AppletLayout::count() const
{
return d->itemList.size();
}
QLayoutItem *AppletLayout::itemAt(int index) const
{
return d->itemList.value(index);
}
QSize AppletLayout::minimumSize() const
{
QSize size;
QLayoutItem *item;
foreach (item, d->itemList)
size = size.expandedTo(item->minimumSize());
size += QSize(2*margin(), 2*margin());
return size;
}
void AppletLayout::setGeometry(const QRect &rect)
{
QLayout::setGeometry(rect);
layoutApplets(rect, false);
}
QSize AppletLayout::sizeHint() const
{
return minimumSize();
}
QLayoutItem * AppletLayout::takeAt(int index)
{
return d->takeAt(index);
}
int AppletLayout::layoutApplets(const QRect &rect, bool computeHeightOnly) const
{
int x = rect.x();
int y = rect.y();
int lineHeight = 0;
QLayoutItem *item;
foreach (item, d->itemList) {
int nextX = x + item->sizeHint().width() + spacing();
if (nextX - spacing() > rect.right() && lineHeight > 0) {
x = rect.x();
y = y + lineHeight + spacing();
nextX = x + item->sizeHint().width() + spacing();
lineHeight = 0;
}
if (!computeHeightOnly)
item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
x = nextX;
lineHeight = qMax(lineHeight, item->sizeHint().height());
}
return y + lineHeight - rect.y();
}
} //end namespace Plasma
#include "appletLayout.moc" #include "appletLayout.moc"

View File

@ -4,7 +4,10 @@
#include "kdelibs_export.h" #include "kdelibs_export.h"
#include <QLayout> #include <QLayout>
#include <QSize>
class QLayoutItem;
class QRect;
namespace Plasma namespace Plasma
{ {
@ -19,10 +22,23 @@ class KDE_EXPORT AppletLayout : public QLayout
Q_OBJECT Q_OBJECT
public: public:
AppletLayout(QWidget *parent); AppletLayout(QWidget *parent);
~AppletLayout();
virtual void addItem(QLayoutItem *item);
virtual Qt::Orientations expandingDirections() const;
virtual bool hasHeightForWidth() const;
virtual int heightForWidth(int) const;
virtual int count() const;
virtual QLayoutItem *itemAt(int index) const;
virtual QSize minimumSize() const;
virtual void setGeometry(const QRect &rect);
virtual QSize sizeHint() const;
virtual QLayoutItem *takeAt(int index);
signals: signals:
void mergeTwoApplets(); void mergeTwoApplets();
void splitTwoApplets(); void splitTwoApplets();
protected:
int layoutApplets(const QRect &rect, bool computeHeightOnly) const;
private: private:
class Private; class Private;
Private *d; Private *d;