show the toolbox as an external solid-background toolbar under the

containment, don't show text on icons except add windgets and add
activity
show the remove activity button in the toolbox for non active ones

svn path=/trunk/KDE/kdelibs/; revision=891209
This commit is contained in:
Marco Martin 2008-12-01 12:40:08 +00:00
parent 258a749f36
commit d9c14c87ba
3 changed files with 105 additions and 35 deletions

View File

@ -216,12 +216,13 @@ void Containment::init()
if (d->type == DesktopContainment && d->toolBox) {
d->toolBox->addTool(this->action("add widgets"));
d->toolBox->addTool(this->action("add sibling containment"));
d->toolBox->addTool(this->action("zoom in"));
d->toolBox->addTool(this->action("zoom out"));
if (immutability() != SystemImmutable) {
d->toolBox->addTool(this->action("lock widgets"));
}
d->toolBox->addTool(this->action("add sibling containment"));
d->toolBox->addTool(this->action("activity settings"));
if (hasConfigurationInterface()) {
// re-use the contianment's action.
@ -825,6 +826,8 @@ void Containment::setScreen(int screen, int desktop)
if (swapScreensWith) {
swapScreensWith->setScreen(oldScreen);
}
enableAction("remove", screen == -1);
}
int Containment::screen() const
@ -1607,9 +1610,14 @@ void ContainmentPrivate::containmentConstraintsEvent(Plasma::Constraints constra
constraints & Plasma::FormFactorConstraint ||
constraints & Plasma::ScreenConstraint ||
constraints & Plasma::StartupCompletedConstraint)) {
kDebug() << "BWUHA!";
//kDebug() << "Positioning toolbox";
positionToolBox();
}
if (toolBox && constraints & Plasma::StartupCompletedConstraint) {
toolBox->addTool(q->action("remove"));
q->enableAction("remove", false);
}
}
Applet *ContainmentPrivate::addApplet(const QString &name, const QVariantList &args,
@ -1736,6 +1744,11 @@ void ContainmentPrivate::positionContainments()
qSort(containments.begin(), containments.end(), containmentSortByPosition);
it.toFront();
int toolBoxMargin = 0;
if (toolBox) {
toolBoxMargin = TOOLBOX_MARGIN;
}
int column = 0;
int x = 0;
int y = 0;
@ -1758,7 +1771,7 @@ void ContainmentPrivate::positionContainments()
if (column == CONTAINMENT_COLUMNS) {
column = 0;
x = 0;
y += rowHeight + INTER_CONTAINMENT_MARGIN;
y += rowHeight + INTER_CONTAINMENT_MARGIN + toolBoxMargin;
rowHeight = 0;
} else {
x += containment->size().width() + INTER_CONTAINMENT_MARGIN;

View File

@ -24,6 +24,7 @@
#include <kmenu.h>
static const int INTER_CONTAINMENT_MARGIN = 6;
static const int TOOLBOX_MARGIN = 150;
static const int CONTAINMENT_COLUMNS = 2;
static const int VERTICAL_STACKING_OFFSET = 10000;

View File

@ -44,16 +44,24 @@ class EmptyGraphicsItem : public QGraphicsItem
{
public:
EmptyGraphicsItem(QGraphicsItem *parent)
: QGraphicsItem(parent)
: QGraphicsItem(parent),
m_toolbar(false)
{
setAcceptsHoverEvents(true);
m_background = new Plasma::FrameSvg();
m_toolbarBackground = new Plasma::FrameSvg();
m_toolbarBackground->setImagePath("widgets/background");
m_background->setImagePath("widgets/translucentbackground");
m_toolbarBackground->setEnabledBorders(FrameSvg::LeftBorder|FrameSvg::RightBorder|FrameSvg::BottomBorder);
m_background->setEnabledBorders(FrameSvg::AllBorders);
}
~EmptyGraphicsItem()
{
delete m_background;
delete m_toolbarBackground;
}
QRectF boundingRect() const
@ -66,25 +74,63 @@ class EmptyGraphicsItem : public QGraphicsItem
return m_rect;
}
void setIsToolbar(bool toolbar)
{
m_toolbar = toolbar;
}
bool isToolbar() const
{
return m_toolbar;
}
void getContentsMargins(qreal &left, qreal &top, qreal &right, qreal &bottom)
{
if (m_toolbar) {
m_toolbarBackground->getMargins(left, top, right, bottom);
} else {
m_background->getMargins(left, top, right, bottom);
}
}
QRectF contentsRect() const
{
qreal left, top, right, bottom;
if (m_toolbar) {
m_toolbarBackground->getMargins(left, top, right, bottom);
} else {
m_background->getMargins(left, top, right, bottom);
}
return m_rect.adjusted(left, top, -right, -bottom);
}
void setRect(const QRectF &rect)
{
//kDebug() << "setting rect to" << rect;
qreal left, top, right, bottom;
m_background->getMargins(left, top, right, bottom);
prepareGeometryChange();
m_rect = rect.adjusted(-left, -top, right, bottom);
m_rect = rect;
setPos(m_rect.topLeft());
m_background->resizeFrame(m_rect.size());
if (m_toolbar) {
m_toolbarBackground->resizeFrame(m_rect.size());
} else {
m_background->resizeFrame(m_rect.size());
}
}
void paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
{
m_background->paintFrame(p);
if (m_toolbar) {
m_toolbarBackground->paintFrame(p);
} else {
m_background->paintFrame(p);
}
}
private:
bool m_toolbar;
QRectF m_rect;
Plasma::FrameSvg *m_toolbarBackground;
Plasma::FrameSvg *m_background;
};
@ -376,11 +422,13 @@ void DesktopToolBox::showToolBox()
Plasma::IconWidget *icon = qgraphicsitem_cast<Plasma::IconWidget *>(tool);
if (icon) {
if (d->viewTransform.isScaling() && d->viewTransform.m11() < Plasma::scalingFactor(Plasma::GroupZoom)) {
icon->setText(QString());
if (d->viewTransform.m11() == Plasma::scalingFactor(Plasma::DesktopZoom) ||
icon->action() == d->containment->action("add sibling containment") ||
icon->action() == d->containment->action("add widgets")) {
icon->setText(icon->action()->text());
icon->resize(icon->sizeFromIconSize(22));
} else {
icon->setText(icon->action()->text());
icon->setText(QString());
icon->resize(icon->sizeFromIconSize(22));
}
}
@ -405,38 +453,49 @@ void DesktopToolBox::showToolBox()
// the rect the tools back should have
QRectF backerRect = QRectF(QPointF(x, startY), QSizeF(maxWidth + 10, y - startY));
if (!d->toolBacker) {
d->toolBacker = new EmptyGraphicsItem(this);
}
d->toolBacker->setIsToolbar(isToolbar());
if (isToolbar()) {
QPointF topRight;
//could that cast ever fail?
if (d->containment) {
topRight = d->viewTransform.map(mapFromParent(d->containment->boundingRect().topRight()));
topRight = d->viewTransform.map(mapFromParent(d->containment->boundingRect().bottomRight()));
} else {
topRight = boundingRect().topRight();
}
backerRect.setSize(QSize(totalWidth, maxHeight));
qreal left, top, right, bottom;
d->toolBacker->getContentsMargins(left, top, right, bottom);
x -= left;
backerRect.setSize(QSize(totalWidth+left+right, maxHeight+top+bottom));
backerRect.moveTopRight(topRight);
}
//kDebug() << "starting at" << x << startY;
} else {
//kDebug() << "starting at" << x << startY;
// now check that is actually fits within the parent's boundaries
backerRect = mapToParent(backerRect).boundingRect();
QSizeF parentSize = parentWidget()->size();
if (backerRect.x() < 5) {
backerRect.moveLeft(5);
} else if (backerRect.right() > parentSize.width() - 5) {
backerRect.moveRight(parentSize.width() - 5);
}
// now check that is actually fits within the parent's boundaries
backerRect = mapToParent(backerRect).boundingRect();
QSizeF parentSize = parentWidget()->size();
if (backerRect.x() < 5) {
backerRect.moveLeft(5);
} else if (backerRect.right() > parentSize.width() - 5) {
backerRect.moveRight(parentSize.width() - 5);
}
if (backerRect.y() < 5) {
backerRect.moveTop(5);
} else if (backerRect.bottom() > parentSize.height() - 5) {
backerRect.moveBottom(parentSize.height() - 5);
}
if (backerRect.y() < 5) {
backerRect.moveTop(5);
} else if (backerRect.bottom() > parentSize.height() - 5) {
backerRect.moveBottom(parentSize.height() - 5);
}
// re-map our starting points back to our coordinate system
backerRect = mapFromParent(backerRect).boundingRect();
// re-map our starting points back to our coordinate system
backerRect = mapFromParent(backerRect).boundingRect();
}
x = backerRect.x() + 5;
y = backerRect.y();
@ -473,9 +532,6 @@ void DesktopToolBox::showToolBox()
}
}
if (!d->toolBacker) {
d->toolBacker = new EmptyGraphicsItem(this);
}
d->toolBacker->setRect(backerRect);
d->toolBacker->show();