From ef4d4863ca892387a0644c99662c9b36a920dc5c Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 16 Apr 2008 13:55:23 +0000 Subject: [PATCH] toolbox is vertical panels is starting to appear, still in the wrong position btw. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=797598 --- containment.cpp | 20 ++++++++++++++++++-- paneltoolbox.cpp | 30 +++++++++++++++++++++++++----- toolbox.cpp | 16 ++++++++++++++-- toolbox_p.h | 2 ++ 4 files changed, 59 insertions(+), 9 deletions(-) diff --git a/containment.cpp b/containment.cpp index ee47d41eb..2cb1f6bea 100644 --- a/containment.cpp +++ b/containment.cpp @@ -247,15 +247,31 @@ void Containment::containmentConstraintsUpdated(Plasma::Constraints constraints) } } - if ((constraints & Plasma::SizeConstraint || constraints & Plasma::ScreenConstraint) && d->toolbox) { + if ((constraints & Plasma::SizeConstraint || constraints & Plasma::ScreenConstraint) && + d->toolbox) { + //The placement assumes that the geometry width/height is no more than the screen if (d->type == PanelContainment) { - d->toolbox->setPos(geometry().right(), geometry().height()/2 - d->toolbox->boundingRect().height()/2); + if (formFactor() == Vertical) { + d->toolbox->setPos(geometry().width()/2 - d->toolbox->boundingRect().width()/2, geometry().bottom()); + //defaulting to Horizontal right now + } else { + d->toolbox->setPos(geometry().right(), geometry().height()/2 - d->toolbox->boundingRect().height()/2); + } } else { d->toolbox->setPos(geometry().right() - qAbs(d->toolbox->boundingRect().width()), 0); } d->toolbox->enableTool("addwidgets", !isImmutable()); } + if (constraints & Plasma::FormFactorConstraint) { + if (formFactor() == Vertical) { + d->toolbox->setOrientation(Qt::Vertical); + //defaults to horizontal + } else { + d->toolbox->setOrientation(Qt::Horizontal); + } + } + if (constraints & Plasma::SizeConstraint) { switch (containmentType()) { case PanelContainment: diff --git a/paneltoolbox.cpp b/paneltoolbox.cpp index 276e11b5e..32d1f37cd 100644 --- a/paneltoolbox.cpp +++ b/paneltoolbox.cpp @@ -101,7 +101,12 @@ PanelToolbox::PanelToolbox(QGraphicsItem *parent) QRectF PanelToolbox::boundingRect() const { - return QRectF(0, 0, -size()*2, size()*4); + if (orientation() == Qt::Vertical) { + return QRectF(0, 0, size()*4, -size()*2); + //horizontal + } else { + return QRectF(0, 0, -size()*2, size()*4); + } } void PanelToolbox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) @@ -122,7 +127,13 @@ void PanelToolbox::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti color2.setAlpha(64); QPainterPath p = shape(); - const QPoint gradientCenter(boundingRect().left(), boundingRect().center().y()); + QPoint gradientCenter; + if (orientation() == Qt::Vertical) { + gradientCenter = QPoint(boundingRect().center().x(), boundingRect().top()); + } else { + gradientCenter = QPoint(boundingRect().left(), boundingRect().center().y()); + } + QRadialGradient gradient(gradientCenter, size() + d->animFrame - 1); gradient.setFocalPoint(gradientCenter); gradient.setColorAt(0, color1); @@ -138,7 +149,13 @@ void PanelToolbox::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti painter->restore(); const qreal progress = d->animFrame / size(); - const QRect iconRect(QPoint((int)boundingRect().left() - iconSize().width() + 2, gradientCenter.y() - iconSize().height()/2), iconSize()); + QRect iconRect; + + if (orientation() == Qt::Vertical) { + iconRect = QRect(QPoint(gradientCenter.x() - iconSize().width()/2, (int)boundingRect().top() - iconSize().height() - 2), iconSize()); + } else { + iconRect = QRect(QPoint((int)boundingRect().left() - iconSize().width() + 2, gradientCenter.y() - iconSize().height()/2), iconSize()); + } if (progress <= 0.9) { d->icon.paint(painter, iconRect, Qt::AlignCenter, QIcon::Disabled, QIcon::Off); @@ -158,9 +175,12 @@ QPainterPath PanelToolbox::shape() const { QPainterPath path; int toolSize = size() + (int)d->animFrame; - //path.moveTo(size()*2, 0); - path.arcTo(QRectF(boundingRect().left() - toolSize, boundingRect().center().y() - toolSize, toolSize*2, toolSize*2), 90, 180); + if (orientation() == Qt::Vertical) { + path.arcTo(QRectF(boundingRect().center().x() - toolSize, boundingRect().top() - toolSize, toolSize*2, toolSize*2), 0, 180); + } else { + path.arcTo(QRectF(boundingRect().left() - toolSize, boundingRect().center().y() - toolSize, toolSize*2, toolSize*2), 90, 180); + } return path; } diff --git a/toolbox.cpp b/toolbox.cpp index 8e1e4691b..c9b3ab935 100644 --- a/toolbox.cpp +++ b/toolbox.cpp @@ -43,13 +43,15 @@ public: : size(50), iconSize(32, 32), hidden(false), - showing(false) + showing(false), + orientation(Qt::Horizontal) {} int size; QSize iconSize; bool hidden; bool showing; + Qt::Orientation orientation; }; Toolbox::Toolbox(QGraphicsItem *parent) @@ -148,7 +150,17 @@ bool Toolbox::showing() const void Toolbox::setShowing(const bool show) { - d->showing = show; + d->showing = show; +} + +Qt::Orientation Toolbox::orientation() const +{ + return d->orientation; +} + +void Toolbox::setOrientation( Qt::Orientation orient ) +{ + d->orientation = orient; } } // plasma namespace diff --git a/toolbox_p.h b/toolbox_p.h index ac172d876..179b635dc 100644 --- a/toolbox_p.h +++ b/toolbox_p.h @@ -50,6 +50,8 @@ public: void setIconSize(const QSize newSize); bool showing() const; void setShowing(const bool show); + Qt::Orientation orientation() const; + void setOrientation(Qt::Orientation orient); virtual void showToolbox() = 0; virtual void hideToolbox() = 0;