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;
case Containment::DesktopContainment:
toolBox = new DesktopToolBox(q);
toolBox->setSize(KIconLoader::SizeSmallMedium);
toolBox->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall));
break;
default:
break;

View File

@ -143,6 +143,7 @@ class DesktopToolBoxPrivate
public:
DesktopToolBoxPrivate(DesktopToolBox *toolbox)
: q(toolbox),
background(0),
containment(0),
icon("plasma"),
toolBacker(0),
@ -153,6 +154,36 @@ public:
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;
Plasma::FrameSvg *background;
@ -173,15 +204,15 @@ DesktopToolBox::DesktopToolBox(Containment *parent)
: ToolBox(parent),
d(new DesktopToolBoxPrivate(this))
{
d->background = new Plasma::FrameSvg();
d->background->setImagePath("widgets/toolbox");
d->containment = parent;
setZValue(10000000);
setIsMovable(true);
assignColors();
d->background = new Plasma::FrameSvg();
d->background->setImagePath("widgets/toolbox");
connect(Plasma::Animator::self(), SIGNAL(movementFinished(QGraphicsItem*)),
this, SLOT(toolMoved(QGraphicsItem*)));
connect(this, SIGNAL(toggled()), this, SLOT(toggle()));
@ -196,7 +227,22 @@ DesktopToolBox::~DesktopToolBox()
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()
@ -225,71 +271,55 @@ void DesktopToolBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
QRect backgroundRect;
const QRectF rect = boundingRect();
const QSize icons = iconSize();
bool atCorner;
QString cornerElement;
switch (corner()) {
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;
}
const QString activityName = d->containment->activity();
if (atCorner) {
d->background->paint(painter, backgroundRect, cornerElement);
const QSize textSize = Plasma::Theme::defaultTheme()->fontMetrics().size(Qt::TextSingleLine, activityName);
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 {
d->background->resizeFrame(rect.size());
d->background->paintFrame(painter);
Qt::Alignment alignment;
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;
if (qFuzzyCompare(qreal(1.0), progress)) {
@ -305,6 +335,35 @@ void DesktopToolBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
d->icon.pixmap(iconSize()), progress);
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

View File

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