make panel toolboxes position and paint properly; essentially do what i did earlier for the desktop one by caching the colors from the theme and getting rid of the negative coordinates
svn path=/trunk/KDE/kdelibs/; revision=885840
This commit is contained in:
parent
185cf58d7f
commit
1b04d7b8b0
@ -113,17 +113,18 @@ DesktopToolBox::DesktopToolBox(Containment *parent)
|
|||||||
: ToolBox(parent),
|
: ToolBox(parent),
|
||||||
d(new DesktopToolBoxPrivate)
|
d(new DesktopToolBoxPrivate)
|
||||||
{
|
{
|
||||||
connect(Plasma::Animator::self(), SIGNAL(movementFinished(QGraphicsItem*)),
|
|
||||||
this, SLOT(toolMoved(QGraphicsItem*)));
|
|
||||||
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();
|
assignColors();
|
||||||
|
|
||||||
|
connect(Plasma::Animator::self(), SIGNAL(movementFinished(QGraphicsItem*)),
|
||||||
|
this, SLOT(toolMoved(QGraphicsItem*)));
|
||||||
|
connect(this, SIGNAL(toggled()), this, SLOT(toggle()));
|
||||||
|
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
|
||||||
|
this, SLOT(assignColors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopToolBox::~DesktopToolBox()
|
DesktopToolBox::~DesktopToolBox()
|
||||||
|
@ -35,64 +35,25 @@
|
|||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
class EmptyGraphicsItem : public QGraphicsItem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
EmptyGraphicsItem(QGraphicsItem *parent)
|
|
||||||
: QGraphicsItem(parent)
|
|
||||||
{
|
|
||||||
setAcceptsHoverEvents(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
QRectF boundingRect() const
|
|
||||||
{
|
|
||||||
return QRectF(QPointF(0, 0), m_rect.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
QRectF rect() const
|
|
||||||
{
|
|
||||||
return m_rect;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setRect(const QRectF &rect)
|
|
||||||
{
|
|
||||||
//kDebug() << "setting rect to" << rect;
|
|
||||||
prepareGeometryChange();
|
|
||||||
m_rect = rect;
|
|
||||||
setPos(rect.topLeft());
|
|
||||||
}
|
|
||||||
|
|
||||||
void paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
|
|
||||||
{
|
|
||||||
Q_UNUSED(p)
|
|
||||||
//p->setPen(Qt::red);
|
|
||||||
//p->drawRect(boundingRect());
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
QRectF m_rect;
|
|
||||||
};
|
|
||||||
|
|
||||||
// used with QGrahphicsItem::setData
|
|
||||||
static const int ToolName = 7001;
|
|
||||||
|
|
||||||
class PanelToolBoxPrivate
|
class PanelToolBoxPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PanelToolBoxPrivate()
|
PanelToolBoxPrivate()
|
||||||
: icon("plasma"),
|
: icon("plasma"),
|
||||||
toolBacker(0),
|
|
||||||
animId(0),
|
animId(0),
|
||||||
animFrame(0),
|
animFrame(0),
|
||||||
toggled(false)
|
toggled(false)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
KIcon icon;
|
KIcon icon;
|
||||||
EmptyGraphicsItem *toolBacker;
|
|
||||||
QTime stopwatch;
|
QTime stopwatch;
|
||||||
int animId;
|
int animId;
|
||||||
qreal animFrame;
|
qreal animFrame;
|
||||||
bool toggled;
|
bool toggled;
|
||||||
|
QColor fgColor;
|
||||||
|
QColor bgColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
PanelToolBox::PanelToolBox(Containment *parent)
|
PanelToolBox::PanelToolBox(Containment *parent)
|
||||||
@ -109,6 +70,9 @@ PanelToolBox::PanelToolBox(Containment *parent)
|
|||||||
//panel toolbox is allowed to zoom, otherwise a part of it will be displayed behind the desktop
|
//panel toolbox is allowed to zoom, otherwise a part of it will be displayed behind the desktop
|
||||||
//toolbox when the desktop is zoomed out
|
//toolbox when the desktop is zoomed out
|
||||||
setFlag(ItemIgnoresTransformations, false);
|
setFlag(ItemIgnoresTransformations, false);
|
||||||
|
assignColors();
|
||||||
|
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
|
||||||
|
this, SLOT(assignColors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
PanelToolBox::~PanelToolBox()
|
PanelToolBox::~PanelToolBox()
|
||||||
@ -116,17 +80,23 @@ PanelToolBox::~PanelToolBox()
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PanelToolBox::assignColors()
|
||||||
|
{
|
||||||
|
d->bgColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor);
|
||||||
|
d->fgColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
|
||||||
|
}
|
||||||
|
|
||||||
QRectF PanelToolBox::boundingRect() const
|
QRectF PanelToolBox::boundingRect() const
|
||||||
{
|
{
|
||||||
QRectF r;
|
QRectF r;
|
||||||
|
|
||||||
|
//Only Left,Right and Bottom supported, default to Right
|
||||||
if (corner() == ToolBox::Bottom) {
|
if (corner() == ToolBox::Bottom) {
|
||||||
r = QRectF(0, 0, size() * 2, -size());
|
r = QRectF(0, 0, size() * 2, size());
|
||||||
} else if (corner() == ToolBox::Left) {
|
} else if (corner() == ToolBox::Left) {
|
||||||
r = QRectF(0, 0, size(), size() * 2);
|
r = QRectF(0, 0, size(), size() * 2);
|
||||||
//Only Left,Right and Bottom supported, default to Right
|
|
||||||
} else {
|
} else {
|
||||||
r = QRectF(0, 0, -size(), size() * 2);
|
r = QRectF(0, 0, size(), size() * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parentItem()) {
|
if (parentItem()) {
|
||||||
@ -152,30 +122,23 @@ void PanelToolBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
|||||||
const qreal progress = d->animFrame / size();
|
const qreal progress = d->animFrame / size();
|
||||||
|
|
||||||
QPoint gradientCenter;
|
QPoint gradientCenter;
|
||||||
|
QRectF rect = boundingRect();
|
||||||
if (corner() == ToolBox::Bottom) {
|
if (corner() == ToolBox::Bottom) {
|
||||||
gradientCenter = QPoint(boundingRect().center().x(), boundingRect().top());
|
gradientCenter = QPoint(rect.center().x(), rect.bottom());
|
||||||
} else {
|
} else {
|
||||||
gradientCenter = QPoint(boundingRect().left(), boundingRect().center().y());
|
gradientCenter = QPoint(rect.right(), rect.center().y());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
painter->translate(boundingRect().topLeft());
|
|
||||||
|
|
||||||
KColorScheme colors(QPalette::Active, KColorScheme::Window,
|
|
||||||
Plasma::Theme::defaultTheme()->colorScheme());
|
|
||||||
QColor color1 = colors.background().color();
|
|
||||||
color1.setAlpha(64.0);
|
|
||||||
|
|
||||||
QColor color2 = colors.foreground().color();
|
|
||||||
color2.setAlpha(64.0);
|
|
||||||
|
|
||||||
QRadialGradient gradient(gradientCenter, size() - 2);
|
QRadialGradient gradient(gradientCenter, size() - 2);
|
||||||
gradient.setFocalPoint(gradientCenter);
|
gradient.setFocalPoint(gradientCenter);
|
||||||
gradient.setColorAt(0, color1);
|
d->bgColor.setAlpha(64);
|
||||||
gradient.setColorAt(.85, color1);
|
d->fgColor.setAlpha(64);
|
||||||
gradient.setColorAt(.95, color2);
|
gradient.setColorAt(0, d->bgColor);
|
||||||
color2.setAlpha(0);
|
gradient.setColorAt(.85, d->bgColor);
|
||||||
gradient.setColorAt(1, color2);
|
gradient.setColorAt(.95, d->fgColor);
|
||||||
|
d->fgColor.setAlpha(0);
|
||||||
|
gradient.setColorAt(1, d->fgColor);
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->setPen(Qt::NoPen);
|
painter->setPen(Qt::NoPen);
|
||||||
@ -188,14 +151,14 @@ void PanelToolBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
|||||||
|
|
||||||
QRect iconRect;
|
QRect iconRect;
|
||||||
|
|
||||||
|
//Only Left,Right and Bottom supported, default to Right
|
||||||
if (corner() == ToolBox::Bottom) {
|
if (corner() == ToolBox::Bottom) {
|
||||||
iconRect = QRect(QPoint(gradientCenter.x() - iconSize().width() / 2,
|
iconRect = QRect(QPoint(gradientCenter.x() - iconSize().width() / 2,
|
||||||
(int)boundingRect().top() - iconSize().height() - 2), iconSize());
|
(int)rect.bottom() - iconSize().height() - 2), iconSize());
|
||||||
} else if (corner() == ToolBox::Left) {
|
} else if (corner() == ToolBox::Left) {
|
||||||
iconRect = QRect(QPoint(2, gradientCenter.y() - iconSize().height() / 2), iconSize());
|
iconRect = QRect(QPoint(2, gradientCenter.y() - iconSize().height() / 2), iconSize());
|
||||||
//Only Left,Right and Bottom supported, default to Right
|
|
||||||
} else {
|
} else {
|
||||||
iconRect = QRect(QPoint((int)boundingRect().left() - iconSize().width() + 1,
|
iconRect = QRect(QPoint((int)rect.right() - iconSize().width() + 1,
|
||||||
gradientCenter.y() - iconSize().height() / 2), iconSize());
|
gradientCenter.y() - iconSize().height() / 2), iconSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,21 +180,24 @@ QPainterPath PanelToolBox::shape() const
|
|||||||
{
|
{
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
int toolSize = size();// + (int)d->animFrame;
|
int toolSize = size();// + (int)d->animFrame;
|
||||||
|
QRectF rect = boundingRect();
|
||||||
|
|
||||||
|
//Only Left,Right and Bottom supported, default to Right
|
||||||
if (corner() == ToolBox::Bottom) {
|
if (corner() == ToolBox::Bottom) {
|
||||||
path.arcTo(QRectF(boundingRect().center().x() - toolSize,
|
path.moveTo(rect.bottomLeft());
|
||||||
boundingRect().top() - toolSize,
|
path.arcTo(QRectF(rect.center().x() - toolSize,
|
||||||
|
rect.bottom() - toolSize,
|
||||||
toolSize * 2,
|
toolSize * 2,
|
||||||
toolSize * 2), 0, 180);
|
toolSize * 2), 0, 180);
|
||||||
} else if (corner() == ToolBox::Left) {
|
} else if (corner() == ToolBox::Left) {
|
||||||
path.arcTo(QRectF(boundingRect().left() - toolSize,
|
path.arcTo(QRectF(rect.left(),
|
||||||
boundingRect().center().y() - toolSize,
|
rect.center().y() - toolSize,
|
||||||
toolSize * 2,
|
toolSize * 2,
|
||||||
toolSize * 2), 90, -180);
|
toolSize * 2), 90, -180);
|
||||||
//Only Left,Right and Bottom supported, default to Right
|
|
||||||
} else {
|
} else {
|
||||||
path.arcTo(QRectF(boundingRect().left() - toolSize,
|
path.moveTo(rect.topRight());
|
||||||
boundingRect().center().y() - toolSize,
|
path.arcTo(QRectF(rect.left(),
|
||||||
|
rect.center().y() - toolSize,
|
||||||
toolSize * 2,
|
toolSize * 2,
|
||||||
toolSize * 2), 90, 180);
|
toolSize * 2), 90, 180);
|
||||||
}
|
}
|
||||||
@ -265,36 +231,7 @@ void PanelToolBox::showToolBox()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// put tools 5px from icon edge
|
// put tools 5px from icon edge
|
||||||
const int iconWidth = 32;
|
|
||||||
int x = size() * 2 - maxwidth - iconWidth - 5;
|
|
||||||
int y = 5; // pos().y();
|
|
||||||
Plasma::Animator *animdriver = Plasma::Animator::self();
|
Plasma::Animator *animdriver = Plasma::Animator::self();
|
||||||
foreach (QGraphicsItem *tool, QGraphicsItem::children()) {
|
|
||||||
if (tool == d->toolBacker) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tool->isEnabled()) {
|
|
||||||
if (tool->isVisible()) {
|
|
||||||
const int height = static_cast<int>(tool->boundingRect().height());
|
|
||||||
animdriver->moveItem(tool, Plasma::Animator::SlideOutMovement,
|
|
||||||
QPoint(size() * 2, -height));
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//kDebug() << "let's show and move" << tool << tool->boundingRect();
|
|
||||||
tool->show();
|
|
||||||
animdriver->moveItem(tool, Plasma::Animator::SlideInMovement, QPoint(x, y));
|
|
||||||
//x += 0;
|
|
||||||
y += static_cast<int>(tool->boundingRect().height()) + 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!d->toolBacker) {
|
|
||||||
d->toolBacker = new EmptyGraphicsItem(this);
|
|
||||||
}
|
|
||||||
d->toolBacker->setRect(QRectF(QPointF(x, 0), QSizeF(maxwidth, y - 10)));
|
|
||||||
d->toolBacker->show();
|
|
||||||
|
|
||||||
if (d->animId) {
|
if (d->animId) {
|
||||||
animdriver->stopCustomAnimation(d->animId);
|
animdriver->stopCustomAnimation(d->animId);
|
||||||
@ -311,9 +248,7 @@ void PanelToolBox::showToolBox()
|
|||||||
void PanelToolBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
void PanelToolBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
//kDebug() << event->pos() << event->scenePos()
|
//kDebug() << event->pos() << event->scenePos()
|
||||||
// << d->toolBacker->rect().contains(event->scenePos().toPoint());
|
if (d->stopwatch.elapsed() < 100 || d->toggled) {
|
||||||
if ((d->toolBacker && d->toolBacker->rect().contains(event->scenePos().toPoint())) ||
|
|
||||||
d->stopwatch.elapsed() < 100 || d->toggled) {
|
|
||||||
QGraphicsItem::hoverLeaveEvent(event);
|
QGraphicsItem::hoverLeaveEvent(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -329,17 +264,7 @@ void PanelToolBox::hideToolBox()
|
|||||||
}
|
}
|
||||||
|
|
||||||
d->toggled = false;
|
d->toggled = false;
|
||||||
int x = size() * 2;
|
|
||||||
int y = 0;
|
|
||||||
Plasma::Animator *animdriver = Plasma::Animator::self();
|
Plasma::Animator *animdriver = Plasma::Animator::self();
|
||||||
foreach (QGraphicsItem *tool, QGraphicsItem::children()) {
|
|
||||||
if (tool == d->toolBacker) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int height = static_cast<int>(tool->boundingRect().height());
|
|
||||||
animdriver->moveItem(tool, Plasma::Animator::SlideOutMovement, QPoint(x, y-height));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (d->animId) {
|
if (d->animId) {
|
||||||
animdriver->stopCustomAnimation(d->animId);
|
animdriver->stopCustomAnimation(d->animId);
|
||||||
@ -349,10 +274,6 @@ void PanelToolBox::hideToolBox()
|
|||||||
d->animId = animdriver->customAnimation(
|
d->animId = animdriver->customAnimation(
|
||||||
10, 240, Plasma::Animator::EaseOutCurve, this, "animate");
|
10, 240, Plasma::Animator::EaseOutCurve, this, "animate");
|
||||||
|
|
||||||
if (d->toolBacker) {
|
|
||||||
d->toolBacker->hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
d->stopwatch.restart();
|
d->stopwatch.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +60,7 @@ protected slots:
|
|||||||
void animate(qreal progress);
|
void animate(qreal progress);
|
||||||
void toolMoved(QGraphicsItem*);
|
void toolMoved(QGraphicsItem*);
|
||||||
void toggle();
|
void toggle();
|
||||||
|
void assignColors();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PanelToolBoxPrivate *d;
|
PanelToolBoxPrivate *d;
|
||||||
|
@ -373,22 +373,24 @@ void ToolBox::reposition()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (d->containment->containmentType() == Containment::PanelContainment) {
|
if (d->containment->containmentType() == Containment::PanelContainment) {
|
||||||
|
QRectF rect = boundingRect();
|
||||||
if (d->containment->formFactor() == Vertical) {
|
if (d->containment->formFactor() == Vertical) {
|
||||||
setCorner(ToolBox::Bottom);
|
setCorner(ToolBox::Bottom);
|
||||||
setPos(d->containment->geometry().width() / 2 - boundingRect().width() / 2,
|
setPos(d->containment->geometry().width() / 2 - rect.width() / 2,
|
||||||
d->containment->geometry().height());
|
d->containment->geometry().height() - rect.height());
|
||||||
} else {
|
} else {
|
||||||
//defaulting to Horizontal right now
|
//defaulting to Horizontal right now
|
||||||
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
||||||
setPos(d->containment->geometry().left(),
|
setPos(d->containment->geometry().left(),
|
||||||
d->containment->geometry().height() / 2 - boundingRect().height() / 2);
|
d->containment->geometry().height() / 2 - rect.height() / 2);
|
||||||
setCorner(ToolBox::Left);
|
setCorner(ToolBox::Left);
|
||||||
} else {
|
} else {
|
||||||
setPos(d->containment->geometry().width(),
|
setPos(d->containment->geometry().width() - rect.width(),
|
||||||
d->containment->geometry().height() / 2 - boundingRect().height() / 2);
|
d->containment->geometry().height() / 2 - rect.height() / 2);
|
||||||
setCorner(ToolBox::Right);
|
setCorner(ToolBox::Right);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//kDebug() << pos();
|
||||||
} else if (d->containment->corona()) {
|
} else if (d->containment->corona()) {
|
||||||
//kDebug() << "desktop";
|
//kDebug() << "desktop";
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user