desktop toolbox is more tiny and shows the activity name if any is set

an experiment, let's see how it goes

svn path=/trunk/KDE/kdelibs/; revision=935674
This commit is contained in:
Marco Martin 2009-03-05 22:15:06 +00:00
parent 2e6aae87be
commit 8fd655c54b
3 changed files with 144 additions and 83 deletions

View File

@ -1571,6 +1571,8 @@ ToolBox *ContainmentPrivate::createToolBox()
break; break;
case Containment::DesktopContainment: case Containment::DesktopContainment:
toolBox = new DesktopToolBox(q); toolBox = new DesktopToolBox(q);
toolBox->setSize(KIconLoader::SizeSmallMedium);
toolBox->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall));
break; break;
default: default:
break; break;

View File

@ -143,6 +143,7 @@ class DesktopToolBoxPrivate
public: public:
DesktopToolBoxPrivate(DesktopToolBox *toolbox) DesktopToolBoxPrivate(DesktopToolBox *toolbox)
: q(toolbox), : q(toolbox),
background(0),
containment(0), containment(0),
icon("plasma"), icon("plasma"),
toolBacker(0), toolBacker(0),
@ -153,6 +154,36 @@ public:
hovering(0) hovering(0)
{} {}
void adjustBackgroundBorders()
{
switch (q->corner()) {
case ToolBox::TopRight:
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::LeftBorder);
break;
case ToolBox::Top:
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
break;
case ToolBox::TopLeft:
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::RightBorder);
break;
case ToolBox::Left:
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::RightBorder);
break;
case ToolBox::Right:
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::LeftBorder);
break;
case ToolBox::BottomLeft:
background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::RightBorder);
break;
case ToolBox::Bottom:
background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
break;
case ToolBox::BottomRight:
default:
background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::LeftBorder);
break;
}
}
DesktopToolBox *q; DesktopToolBox *q;
Plasma::FrameSvg *background; Plasma::FrameSvg *background;
@ -173,15 +204,15 @@ DesktopToolBox::DesktopToolBox(Containment *parent)
: ToolBox(parent), : ToolBox(parent),
d(new DesktopToolBoxPrivate(this)) d(new DesktopToolBoxPrivate(this))
{ {
d->background = new Plasma::FrameSvg();
d->background->setImagePath("widgets/toolbox");
d->containment = parent; d->containment = parent;
setZValue(10000000); setZValue(10000000);
setIsMovable(true); setIsMovable(true);
assignColors(); assignColors();
d->background = new Plasma::FrameSvg();
d->background->setImagePath("widgets/toolbox");
connect(Plasma::Animator::self(), SIGNAL(movementFinished(QGraphicsItem*)), connect(Plasma::Animator::self(), SIGNAL(movementFinished(QGraphicsItem*)),
this, SLOT(toolMoved(QGraphicsItem*))); this, SLOT(toolMoved(QGraphicsItem*)));
connect(this, SIGNAL(toggled()), this, SLOT(toggle())); connect(this, SIGNAL(toggled()), this, SLOT(toggle()));
@ -196,7 +227,22 @@ DesktopToolBox::~DesktopToolBox()
QRectF DesktopToolBox::boundingRect() const QRectF DesktopToolBox::boundingRect() const
{ {
return QRectF(0, 0, size(), size()); int extraSpace = size();
d->adjustBackgroundBorders();
if (!d->containment->activity().isNull()) {
extraSpace = Plasma::Theme::defaultTheme()->fontMetrics().width(d->containment->activity());
}
qreal left, top, right, bottom;
d->background->getMargins(left, top, right, bottom);
if (corner() == Left || corner() == Right) {
return QRectF(0, 0, size()+left+right, size()+extraSpace+top+bottom);
} else {
return QRectF(0, 0, size()+extraSpace+left+right, size()+top+bottom);
}
} }
void DesktopToolBox::assignColors() void DesktopToolBox::assignColors()
@ -225,71 +271,55 @@ void DesktopToolBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
QRect backgroundRect; QRect backgroundRect;
const QRectF rect = boundingRect(); const QRectF rect = boundingRect();
const QSize icons = iconSize(); const QSize icons = iconSize();
bool atCorner;
QString cornerElement;
switch (corner()) { const QString activityName = d->containment->activity();
case TopRight:
iconPos = QPoint((int)rect.right() - icons.width() + 2, 2);
cornerElement = "desktop-northeast";
backgroundRect = d->background->elementRect(cornerElement).toRect();
backgroundRect.moveTopRight(rect.topRight().toPoint());
atCorner = true;
break;
case Top:
iconPos = QPoint(rect.center().x() - icons.width() / 2, 2);
atCorner = false;
d->background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
break;
case TopLeft:
iconPos = QPoint(2, 2);
cornerElement = "desktop-northwest";
backgroundRect = d->background->elementRect(cornerElement).toRect();
backgroundRect.moveTopLeft(rect.topLeft().toPoint());
atCorner = true;
break;
case Left:
iconPos = QPoint(2, rect.center().y() - icons.height() / 2);
atCorner = false;
d->background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::RightBorder);
break;
case Right:
iconPos = QPoint((int)rect.right() - icons.width() + 2,
rect.center().y() - icons.height() / 2);
atCorner = false;
d->background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::LeftBorder);
break;
case BottomLeft:
iconPos = QPoint(2, rect.bottom() - icons.height() - 2);
cornerElement = "desktop-southwest";
backgroundRect = d->background->elementRect(cornerElement).toRect();
backgroundRect.moveBottomLeft(rect.bottomLeft().toPoint());
atCorner = true;
break;
case Bottom:
iconPos = QPoint(rect.center().x() - icons.width() / 2,
rect.bottom() - icons.height() - 2);
atCorner = false;
d->background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
break;
case BottomRight:
default:
iconPos = QPoint((int)rect.right() - icons.width() + 2,
(int)rect.bottom() - icons.height() - 2);
cornerElement = "desktop-southeast";
backgroundRect = d->background->elementRect(cornerElement).toRect();
backgroundRect.moveBottomRight(rect.bottomRight().toPoint());
atCorner = true;
break;
}
if (atCorner) { const QSize textSize = Plasma::Theme::defaultTheme()->fontMetrics().size(Qt::TextSingleLine, activityName);
d->background->paint(painter, backgroundRect, cornerElement);
d->adjustBackgroundBorders();
d->background->resizeFrame(rect.size());
d->background->paintFrame(painter);
QRect iconRect;
QRect textRect;
if (corner() == Left || corner() == Right) {
Qt::Alignment alignment;
if (activityName.isNull()) {
alignment = Qt::Alignment(Qt::AlignCenter);
} else {
alignment = Qt::Alignment(Qt::AlignHCenter|Qt::AlignTop);
}
iconRect = QStyle::alignedRect(QApplication::layoutDirection(), alignment, iconSize(), d->background->contentsRect().toRect());
QRect boundRect(QPoint(d->background->contentsRect().top(),
d->background->contentsRect().left()),
QSize(d->background->contentsRect().height(),
d->background->contentsRect().width()));
textRect = QStyle::alignedRect(QApplication::layoutDirection(), Qt::AlignRight|Qt::AlignVCenter, textSize, boundRect);
} else { } else {
d->background->resizeFrame(rect.size()); Qt::Alignment alignment;
d->background->paintFrame(painter);
if (activityName.isNull()) {
alignment = Qt::Alignment(Qt::AlignCenter);
} else {
alignment = Qt::Alignment(Qt::AlignLeft|Qt::AlignVCenter);
}
iconRect = QStyle::alignedRect(QApplication::layoutDirection(), alignment, iconSize(), d->background->contentsRect().toRect());
textRect = QStyle::alignedRect(QApplication::layoutDirection(), Qt::AlignRight|Qt::AlignVCenter, textSize, d->background->contentsRect().toRect());
} }
iconPos = iconRect.topLeft();
const qreal progress = d->animHighlightFrame; const qreal progress = d->animHighlightFrame;
if (qFuzzyCompare(qreal(1.0), progress)) { if (qFuzzyCompare(qreal(1.0), progress)) {
@ -305,6 +335,35 @@ void DesktopToolBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
d->icon.pixmap(iconSize()), progress); d->icon.pixmap(iconSize()), progress);
painter->drawPixmap(QRect(iconPos, iconSize()), result); painter->drawPixmap(QRect(iconPos, iconSize()), result);
} }
if (activityName.isNull()) {
return;
}
QColor textColor = Plasma::Theme::defaultTheme()->color(Theme::TextColor);
QColor shadowColor;
QPoint shadowOffset;
if (qGray(textColor.rgb()) > 192) {
shadowColor = Qt::black;
shadowOffset = QPoint(1,1);
} else {
shadowColor = Qt::white;
shadowOffset = QPoint(0,0);
}
QPixmap shadowText = Plasma::PaintUtils::shadowText(activityName, textColor, shadowColor, shadowOffset);
painter->save();
if (corner() == Left || corner() == Right) {
painter->rotate(90);
painter->translate(textRect.left(), -textRect.top()-textRect.height());
painter->drawPixmap(QPoint(0,0), shadowText);
} else {
painter->drawPixmap(textRect.topLeft(), shadowText);
}
painter->restore();
} }
QPainterPath DesktopToolBox::shape() const QPainterPath DesktopToolBox::shape() const

View File

@ -86,22 +86,22 @@ QPoint ToolBox::toolPosition(int toolHeight)
{ {
switch (d->corner) { switch (d->corner) {
case TopRight: case TopRight:
return QPoint(d->size, -toolHeight); return QPoint(boundingRect().width(), -toolHeight);
case Top: case Top:
return QPoint((int)boundingRect().center().x() - d->iconSize.width(), -toolHeight); return QPoint((int)boundingRect().center().x() - boundingRect().width(), -toolHeight);
case TopLeft: case TopLeft:
return QPoint(-d->size, -toolHeight); return QPoint(-boundingRect().width(), -toolHeight);
case Left: case Left:
return QPoint(-d->size, (int)boundingRect().center().y() - d->iconSize.height()); return QPoint(-boundingRect().width(), (int)boundingRect().center().y() - boundingRect().height());
case Right: case Right:
return QPoint(d->size, (int)boundingRect().center().y() - d->iconSize.height()); return QPoint(boundingRect().width(), (int)boundingRect().center().y() - boundingRect().height());
case BottomLeft: case BottomLeft:
return QPoint(-d->size, toolHeight); return QPoint(-boundingRect().width(), toolHeight);
case Bottom: case Bottom:
return QPoint((int)boundingRect().center().x() - d->iconSize.width(), toolHeight); return QPoint((int)boundingRect().center().x() - d->iconSize.width(), toolHeight);
case BottomRight: case BottomRight:
default: default:
return QPoint(d->size, toolHeight); return QPoint(boundingRect().width(), toolHeight);
} }
} }
@ -382,8 +382,8 @@ void ToolBox::save(KConfigGroup &cg) const
if (d->corner == ToolBox::Left || if (d->corner == ToolBox::Left ||
d->corner == ToolBox::Right) { d->corner == ToolBox::Right) {
offset = y(); offset = y();
} else if (d->corner == ToolBox::Left || } else if (d->corner == ToolBox::Top ||
d->corner == ToolBox::Right) { d->corner == ToolBox::Bottom) {
offset = x(); offset = x();
} }
@ -416,19 +416,19 @@ void ToolBox::load()
setPos(offset, 0); setPos(offset, 0);
break; break;
case ToolBox::TopRight: case ToolBox::TopRight:
setPos(d->containment->size().width() - d->size, 0); setPos(d->containment->size().width() - boundingRect().width(), 0);
break; break;
case ToolBox::Right: case ToolBox::Right:
setPos(d->containment->size().width() - d->size, offset); setPos(d->containment->size().width() - boundingRect().width(), offset);
break; break;
case ToolBox::BottomRight: case ToolBox::BottomRight:
setPos(d->containment->size().width() - d->size, d->containment->size().height() - d->size); setPos(d->containment->size().width() - boundingRect().width(), d->containment->size().height() - boundingRect().height());
break; break;
case ToolBox::Bottom: case ToolBox::Bottom:
setPos(offset, d->containment->size().height() - d->size); setPos(offset, d->containment->size().height() - boundingRect().height());
break; break;
case ToolBox::BottomLeft: case ToolBox::BottomLeft:
setPos(0, d->containment->size().height() - d->size); setPos(0, d->containment->size().height() - boundingRect().height());
break; break;
case ToolBox::Left: case ToolBox::Left:
setPos(0, offset); setPos(0, offset);
@ -486,10 +486,10 @@ void ToolBox::reposition()
if (!d->containment->view() || !d->containment->view()->transform().isScaling()) { if (!d->containment->view() || !d->containment->view()->transform().isScaling()) {
if (QApplication::layoutDirection() == Qt::RightToLeft) { if (QApplication::layoutDirection() == Qt::RightToLeft) {
if (avail.top() > screenGeom.top()) { if (avail.top() > screenGeom.top()) {
setPos(avail.topLeft() - QPoint(0, d->size)); setPos(avail.topLeft() - QPoint(0, boundingRect().height()));
setCorner(ToolBox::Left); setCorner(ToolBox::Left);
} else if (avail.left() > screenGeom.left()) { } else if (avail.left() > screenGeom.left()) {
setPos(avail.topLeft() - QPoint(d->size, 0)); setPos(avail.topLeft() - QPoint(boundingRect().width(), 0));
setCorner(ToolBox::Top); setCorner(ToolBox::Top);
} else { } else {
setPos(avail.topLeft()); setPos(avail.topLeft());
@ -497,13 +497,13 @@ void ToolBox::reposition()
} }
} else { } else {
if (avail.top() > screenGeom.top()) { if (avail.top() > screenGeom.top()) {
setPos(avail.topRight() - QPoint(0, d->size)); setPos(avail.topRight() - QPoint(0, boundingRect().height()));
setCorner(ToolBox::Right); setCorner(ToolBox::Right);
} else if (avail.right() < screenGeom.right()) { } else if (avail.right() < screenGeom.right()) {
setPos(avail.topRight() - QPoint(d->size, 0)); setPos(avail.topRight() - QPoint(boundingRect().width(), 0));
setCorner(ToolBox::Top); setCorner(ToolBox::Top);
} else { } else {
setPos(avail.topRight() - QPoint(d->size, 0)); setPos(avail.topRight() - QPoint(boundingRect().width(), 0));
setCorner(ToolBox::TopRight); setCorner(ToolBox::TopRight);
} }
} }