simplify toolbox positioining and drawing
svn path=/trunk/KDE/kdelibs/; revision=882672
This commit is contained in:
parent
0eb079d33b
commit
cdf562df11
@ -1490,6 +1490,7 @@ void ContainmentPrivate::positionToolBox()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kDebug();
|
||||||
//The placement assumes that the geometry width/height is no more than the screen
|
//The placement assumes that the geometry width/height is no more than the screen
|
||||||
if (type == Containment::PanelContainment) {
|
if (type == Containment::PanelContainment) {
|
||||||
if (q->formFactor() == Vertical) {
|
if (q->formFactor() == Vertical) {
|
||||||
@ -1509,20 +1510,23 @@ void ContainmentPrivate::positionToolBox()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (q->corona()) {
|
} else if (q->corona()) {
|
||||||
|
kDebug() << "desktop";
|
||||||
|
|
||||||
QRectF avail = q->corona()->availableScreenRegion(screen).boundingRect();
|
QRectF avail = q->corona()->availableScreenRegion(screen).boundingRect();
|
||||||
QRectF screenGeom = q->corona()->screenGeometry(screen);
|
QRectF screenGeom = q->corona()->screenGeometry(screen);
|
||||||
|
|
||||||
// Transform to the containment's coordinate system.
|
// Transform to the containment's coordinate system.
|
||||||
avail.translate(-screenGeom.topLeft());
|
avail.translate(-screenGeom.topLeft());
|
||||||
screenGeom.moveTo(0, 0);
|
screenGeom.moveTo(0, 0);
|
||||||
|
const int toolBoxSize = toolBox->size();
|
||||||
|
|
||||||
if (q->view() && !q->view()->transform().isScaling()) {
|
if (!q->view() || !q->view()->transform().isScaling()) {
|
||||||
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
||||||
if (avail.top() > screenGeom.top()) {
|
if (avail.top() > screenGeom.top()) {
|
||||||
toolBox->setPos(avail.topLeft() - QPoint(0, toolBox->size()));
|
toolBox->setPos(avail.topLeft() - QPoint(0, toolBoxSize));
|
||||||
toolBox->setCorner(ToolBox::Left);
|
toolBox->setCorner(ToolBox::Left);
|
||||||
} else if (avail.left() > screenGeom.left()) {
|
} else if (avail.left() > screenGeom.left()) {
|
||||||
toolBox->setPos(avail.topLeft() - QPoint(toolBox->size(), 0));
|
toolBox->setPos(avail.topLeft() - QPoint(toolBoxSize, 0));
|
||||||
toolBox->setCorner(ToolBox::Top);
|
toolBox->setCorner(ToolBox::Top);
|
||||||
} else {
|
} else {
|
||||||
toolBox->setPos(avail.topLeft());
|
toolBox->setPos(avail.topLeft());
|
||||||
@ -1530,13 +1534,13 @@ void ContainmentPrivate::positionToolBox()
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (avail.top() > screenGeom.top()) {
|
if (avail.top() > screenGeom.top()) {
|
||||||
toolBox->setPos(avail.topRight() - QPoint(0, toolBox->size()));
|
toolBox->setPos(avail.topRight() - QPoint(0, toolBoxSize));
|
||||||
toolBox->setCorner(ToolBox::Right);
|
toolBox->setCorner(ToolBox::Right);
|
||||||
} else if (avail.right() < screenGeom.right()) {
|
} else if (avail.right() < screenGeom.right()) {
|
||||||
toolBox->setPos(QPoint(avail.right() - toolBox->boundingRect().width(), avail.top()));
|
toolBox->setPos(avail.topRight() - QPoint(toolBoxSize, 0));
|
||||||
toolBox->setCorner(ToolBox::Top);
|
toolBox->setCorner(ToolBox::Top);
|
||||||
} else {
|
} else {
|
||||||
toolBox->setPos(avail.topRight());
|
toolBox->setPos(avail.topRight() - QPoint(toolBoxSize, 0));
|
||||||
toolBox->setCorner(ToolBox::TopRight);
|
toolBox->setCorner(ToolBox::TopRight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,6 +98,8 @@ public:
|
|||||||
qreal animCircleFrame;
|
qreal animCircleFrame;
|
||||||
qreal animHighlightFrame;
|
qreal animHighlightFrame;
|
||||||
QRect shapeRect;
|
QRect shapeRect;
|
||||||
|
QColor fgColor;
|
||||||
|
QColor bgColor;
|
||||||
bool hovering : 1;
|
bool hovering : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -108,12 +110,14 @@ DesktopToolBox::DesktopToolBox(QGraphicsItem *parent)
|
|||||||
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()));
|
||||||
|
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
|
||||||
|
this, SLOT(assignColors()));
|
||||||
setZValue(10000000);
|
setZValue(10000000);
|
||||||
setFlag(ItemClipsToShape, true);
|
setFlag(ItemClipsToShape, true);
|
||||||
setFlag(ItemClipsChildrenToShape, false);
|
setFlag(ItemClipsChildrenToShape, false);
|
||||||
setFlag(ItemIgnoresTransformations, true);
|
setFlag(ItemIgnoresTransformations, true);
|
||||||
setIsMovable(true);
|
setIsMovable(true);
|
||||||
|
assignColors();
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopToolBox::~DesktopToolBox()
|
DesktopToolBox::~DesktopToolBox()
|
||||||
@ -123,100 +127,75 @@ DesktopToolBox::~DesktopToolBox()
|
|||||||
|
|
||||||
QRectF DesktopToolBox::boundingRect() const
|
QRectF DesktopToolBox::boundingRect() const
|
||||||
{
|
{
|
||||||
Corner c = corner();
|
return QRectF(0, 0, size(), size());
|
||||||
qreal width;
|
|
||||||
qreal height;
|
|
||||||
|
|
||||||
if (c == Left || c == Right) {
|
|
||||||
height = size() * 4;
|
|
||||||
} else {
|
|
||||||
height = size() * 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == Bottom || c == BottomRight || c == BottomLeft) {
|
|
||||||
height = -height;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == Top || c == Bottom) {
|
|
||||||
width = size() * 4;
|
|
||||||
} else {
|
|
||||||
width = size() * 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == Right || c == TopRight || c == BottomRight) {
|
|
||||||
width = -width;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QRectF(0, 0, width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopToolBox::paint(QPainter *painter,
|
void DesktopToolBox::assignColors()
|
||||||
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
{
|
||||||
|
d->bgColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor);
|
||||||
|
d->fgColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DesktopToolBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
Q_UNUSED(option)
|
Q_UNUSED(option)
|
||||||
Q_UNUSED(widget)
|
Q_UNUSED(widget)
|
||||||
|
|
||||||
painter->save();
|
|
||||||
painter->translate(boundingRect().topLeft());
|
|
||||||
|
|
||||||
QColor color1 = KColorScheme(QPalette::Active, KColorScheme::Window,
|
|
||||||
Plasma::Theme::defaultTheme()->colorScheme()).background().color();
|
|
||||||
color1.setAlpha(64);
|
|
||||||
|
|
||||||
QColor color2 = KColorScheme(QPalette::Active, KColorScheme::Window,
|
|
||||||
Plasma::Theme::defaultTheme()->colorScheme()).foreground().color();
|
|
||||||
color2.setAlpha(64);
|
|
||||||
|
|
||||||
QPainterPath p = shape();
|
QPainterPath p = shape();
|
||||||
|
|
||||||
QPoint iconPos;
|
QPoint iconPos;
|
||||||
QPointF gradientCenter;
|
QPointF gradientCenter;
|
||||||
|
const QRectF rect = boundingRect();
|
||||||
|
const QSize icons = iconSize();
|
||||||
|
|
||||||
switch (corner()) {
|
switch (corner()) {
|
||||||
case TopRight:
|
case TopRight:
|
||||||
iconPos = QPoint((int)boundingRect().left() - iconSize().width() + 2, 2);
|
iconPos = QPoint((int)rect.right() - icons.width() + 2, 2);
|
||||||
gradientCenter = boundingRect().topLeft();
|
gradientCenter = rect.topRight();
|
||||||
break;
|
break;
|
||||||
case Top:
|
case Top:
|
||||||
iconPos = QPoint(boundingRect().center().x() - iconSize().width() / 2, 2);
|
iconPos = QPoint(rect.center().x() - icons.width() / 2, 2);
|
||||||
gradientCenter = QPoint(boundingRect().center().x(), boundingRect().y());
|
gradientCenter = QPoint(rect.center().x(), rect.y());
|
||||||
break;
|
break;
|
||||||
case TopLeft:
|
case TopLeft:
|
||||||
iconPos = QPoint(2, 2);
|
iconPos = QPoint(2, 2);
|
||||||
gradientCenter = boundingRect().topLeft();
|
gradientCenter = rect.topLeft();
|
||||||
break;
|
break;
|
||||||
case Left:
|
case Left:
|
||||||
iconPos = QPoint(2, boundingRect().center().y() - iconSize().height() / 2);
|
iconPos = QPoint(2, rect.center().y() - icons.height() / 2);
|
||||||
gradientCenter = QPointF(boundingRect().left(), boundingRect().center().y());
|
gradientCenter = QPointF(rect.left(), rect.center().y());
|
||||||
break;
|
break;
|
||||||
case Right:
|
case Right:
|
||||||
iconPos = QPoint((int)boundingRect().left() - iconSize().width() + 2,
|
iconPos = QPoint((int)rect.right() - icons.width() + 2,
|
||||||
boundingRect().center().y() - iconSize().height() / 2);
|
rect.center().y() - icons.height() / 2);
|
||||||
gradientCenter = QPointF(boundingRect().left(), boundingRect().center().y());
|
gradientCenter = QPointF(rect.right(), rect.center().y());
|
||||||
break;
|
break;
|
||||||
case BottomLeft:
|
case BottomLeft:
|
||||||
iconPos = QPoint(2, boundingRect().top() - iconSize().height() - 2);
|
iconPos = QPoint(2, rect.bottom() - icons.height() - 2);
|
||||||
gradientCenter = boundingRect().topLeft();
|
gradientCenter = rect.bottomLeft();
|
||||||
break;
|
break;
|
||||||
case Bottom:
|
case Bottom:
|
||||||
iconPos = QPoint(boundingRect().center().x() - iconSize().width() / 2,
|
iconPos = QPoint(rect.center().x() - icons.width() / 2,
|
||||||
boundingRect().top() - iconSize().height() - 2);
|
rect.bottom() - icons.height() - 2);
|
||||||
gradientCenter = QPointF(boundingRect().center().x(), boundingRect().top());
|
gradientCenter = QPointF(rect.center().x(), rect.bottom());
|
||||||
break;
|
break;
|
||||||
case BottomRight:
|
case BottomRight:
|
||||||
default:
|
default:
|
||||||
iconPos = QPoint((int)boundingRect().left() - iconSize().width() - 2,
|
iconPos = QPoint((int)rect.right() - icons.width() + 2,
|
||||||
(int)boundingRect().top() - iconSize().height() - 2);
|
(int)rect.bottom() - icons.height() - 2);
|
||||||
gradientCenter = boundingRect().topLeft();
|
gradientCenter = rect.bottomRight();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d->bgColor.setAlpha(64);
|
||||||
|
d->fgColor.setAlpha(64);
|
||||||
QRadialGradient gradient(gradientCenter, size() + d->animCircleFrame);
|
QRadialGradient gradient(gradientCenter, size() + d->animCircleFrame);
|
||||||
gradient.setFocalPoint(gradientCenter);
|
gradient.setFocalPoint(gradientCenter);
|
||||||
gradient.setColorAt(0, color1);
|
gradient.setColorAt(0, d->bgColor);
|
||||||
gradient.setColorAt(.87, color1);
|
gradient.setColorAt(.87, d->bgColor);
|
||||||
gradient.setColorAt(.97, color2);
|
gradient.setColorAt(.97, d->fgColor);
|
||||||
color2.setAlpha(0);
|
d->fgColor.setAlpha(0);
|
||||||
gradient.setColorAt(1, color2);
|
gradient.setColorAt(1, d->fgColor);
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->setPen(Qt::NoPen);
|
painter->setPen(Qt::NoPen);
|
||||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||||
@ -239,55 +218,33 @@ void DesktopToolBox::paint(QPainter *painter,
|
|||||||
d->icon.pixmap(iconSize()), progress);
|
d->icon.pixmap(iconSize()), progress);
|
||||||
painter->drawPixmap(QRect(iconPos, iconSize()), result);
|
painter->drawPixmap(QRect(iconPos, iconSize()), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->restore();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPainterPath DesktopToolBox::shape() const
|
QPainterPath DesktopToolBox::shape() const
|
||||||
{
|
{
|
||||||
QPainterPath path;
|
const QRectF rect = boundingRect();
|
||||||
int toolSize = size() + (int)d->animCircleFrame;
|
const int w = rect.width();
|
||||||
|
const int h = rect.height();
|
||||||
|
|
||||||
|
QPainterPath path;
|
||||||
switch (corner()) {
|
switch (corner()) {
|
||||||
case TopRight:
|
|
||||||
path.arcTo(QRectF(boundingRect().left() - toolSize, boundingRect().top() - toolSize,
|
|
||||||
toolSize * 2, toolSize * 2), 180, 90);
|
|
||||||
break;
|
|
||||||
case Top:
|
|
||||||
path.arcTo(QRectF(boundingRect().center().x() - toolSize,
|
|
||||||
boundingRect().top() - toolSize,
|
|
||||||
toolSize * 2, toolSize * 2), 180, 180);
|
|
||||||
break;
|
|
||||||
case TopLeft:
|
|
||||||
path.arcTo(QRectF(boundingRect().left() - toolSize,
|
|
||||||
boundingRect().top() - toolSize,
|
|
||||||
toolSize * 2, toolSize * 2), 270, 90);
|
|
||||||
break;
|
|
||||||
case Left:
|
|
||||||
path.arcTo(QRectF(boundingRect().left() - toolSize,
|
|
||||||
boundingRect().center().y() - toolSize,
|
|
||||||
toolSize * 2, toolSize * 2), 270, 180);
|
|
||||||
break;
|
|
||||||
case Right:
|
|
||||||
path.arcTo(QRectF(boundingRect().left() - toolSize,
|
|
||||||
boundingRect().center().y() - toolSize,
|
|
||||||
toolSize * 2, toolSize * 2), 90, 180);
|
|
||||||
break;
|
|
||||||
case BottomLeft:
|
case BottomLeft:
|
||||||
path.arcTo(QRectF(boundingRect().left() - toolSize,
|
path.moveTo(rect.bottomLeft());
|
||||||
boundingRect().top() - toolSize,
|
path.arcTo(QRectF(rect.left() - w, rect.top(), w * 2, h * 2), 0, 90);
|
||||||
toolSize * 2, toolSize * 2), 0, 90);
|
|
||||||
break;
|
|
||||||
case Bottom:
|
|
||||||
path.arcTo(QRectF(boundingRect().center().x() - toolSize,
|
|
||||||
boundingRect().top() - toolSize,
|
|
||||||
toolSize * 2, toolSize * 2), 0, 180);
|
|
||||||
break;
|
break;
|
||||||
case BottomRight:
|
case BottomRight:
|
||||||
|
path.moveTo(rect.bottomRight());
|
||||||
|
path.arcTo(QRectF(rect.left(), rect.top(), w * 2, h * 2), 90, 90);
|
||||||
|
break;
|
||||||
|
case TopRight:
|
||||||
|
path.moveTo(rect.topRight());
|
||||||
|
path.arcTo(QRectF(rect.left(), rect.top() - h, w * 2, h * 2), 180, 90);
|
||||||
|
break;
|
||||||
|
case TopLeft:
|
||||||
|
path.arcTo(QRectF(rect.left() - w, rect.top() - h, w * 2, h * 2), 270, 90);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
path.arcTo(QRectF(boundingRect().left() - toolSize,
|
path.addRect(rect);
|
||||||
boundingRect().top() - toolSize,
|
|
||||||
toolSize * 2, toolSize * 2), 90, 90);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,10 +355,6 @@ void DesktopToolBox::showToolBox()
|
|||||||
}
|
}
|
||||||
|
|
||||||
setShowing(true);
|
setShowing(true);
|
||||||
// TODO: 10 and 200 shouldn't be hardcoded here. There needs to be a way to
|
|
||||||
// match whatever the time is that moveItem() takes. Same in hoverLeaveEvent().
|
|
||||||
d->animCircleId =
|
|
||||||
animdriver->customAnimation(10, 240, Plasma::Animator::EaseInCurve, this, "animateCircle");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopToolBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
void DesktopToolBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
@ -447,29 +400,12 @@ void DesktopToolBox::hideToolBox()
|
|||||||
}
|
}
|
||||||
|
|
||||||
setShowing(false);
|
setShowing(false);
|
||||||
d->animCircleId =
|
|
||||||
animdriver->customAnimation(10, 240, Plasma::Animator::EaseOutCurve, this, "animateCircle");
|
|
||||||
|
|
||||||
if (d->toolBacker) {
|
if (d->toolBacker) {
|
||||||
d->toolBacker->hide();
|
d->toolBacker->hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopToolBox::animateCircle(qreal progress)
|
|
||||||
{
|
|
||||||
if (showing()) {
|
|
||||||
d->animCircleFrame = size() * progress;
|
|
||||||
} else {
|
|
||||||
d->animCircleFrame = size() * (1.0 - progress);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (progress >= 1) {
|
|
||||||
d->animCircleId = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DesktopToolBox::animateHighlight(qreal progress)
|
void DesktopToolBox::animateHighlight(qreal progress)
|
||||||
{
|
{
|
||||||
if (d->hovering) {
|
if (d->hovering) {
|
||||||
|
@ -57,9 +57,9 @@ protected:
|
|||||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void animateCircle(qreal progress);
|
|
||||||
void animateHighlight(qreal progress);
|
void animateHighlight(qreal progress);
|
||||||
void toolMoved(QGraphicsItem*);
|
void toolMoved(QGraphicsItem*);
|
||||||
|
void assignColors();
|
||||||
/**
|
/**
|
||||||
* show/hide the toolbox
|
* show/hide the toolbox
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user