Desktop toolbox should appear in less funny positions
AND beginning of a panel toolbox actually untested with the woc port for now svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=796873
This commit is contained in:
parent
940bb176b6
commit
e9e16e2a89
@ -48,6 +48,8 @@ set(plasma_LIB_SRCS
|
||||
svgpanel.cpp
|
||||
theme.cpp
|
||||
timer.cpp
|
||||
toolbox.cpp
|
||||
paneltoolbox.cpp
|
||||
desktoptoolbox.cpp
|
||||
uiloader.cpp
|
||||
view.cpp
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "corona.h"
|
||||
#include "phase.h"
|
||||
#include "desktoptoolbox_p.h"
|
||||
#include "paneltoolbox_p.h"
|
||||
#include "svg.h"
|
||||
|
||||
namespace Plasma
|
||||
@ -73,10 +74,18 @@ public:
|
||||
applets.clear();
|
||||
}
|
||||
|
||||
DesktopToolbox* createToolbox()
|
||||
Toolbox* createToolbox()
|
||||
{
|
||||
if (!toolbox) {
|
||||
toolbox = new DesktopToolbox(q);
|
||||
switch (type) {
|
||||
case PanelContainment:
|
||||
toolbox = new PanelToolbox(q);
|
||||
break;
|
||||
//defaults to DesktopContainment right now
|
||||
default:
|
||||
toolbox = new DesktopToolbox(q);
|
||||
break;
|
||||
}
|
||||
positionToolbox();
|
||||
}
|
||||
|
||||
@ -93,7 +102,7 @@ public:
|
||||
r = desktop->availableGeometry(screen);
|
||||
}
|
||||
|
||||
toolbox->setPos(QPointF(r.right() - toolbox->boundingRect().width(), r.y()));
|
||||
toolbox->setPos(QPointF(r.right(), r.y()));
|
||||
}
|
||||
|
||||
void setLockToolText();
|
||||
@ -104,7 +113,7 @@ public:
|
||||
Applet::List applets;
|
||||
QMap<Applet*, AppletHandle*> handles;
|
||||
int screen;
|
||||
DesktopToolbox *toolbox;
|
||||
Toolbox *toolbox;
|
||||
Containment::Type type;
|
||||
bool positioning;
|
||||
};
|
||||
@ -285,6 +294,10 @@ void Containment::setContainmentType(Containment::Type type)
|
||||
QGraphicsWidget *activityTool = addToolBoxTool("addSiblingContainment", "list-add", i18n("Add Activity"));
|
||||
connect(activityTool, SIGNAL(clicked()), this, SLOT(addSiblingContainment()));
|
||||
}
|
||||
} else if (isContainment() && type == PanelContainment){
|
||||
createToolbox();
|
||||
toolbox->setSize(24);
|
||||
toolbox->setIconSize(QSize(16, 16));
|
||||
} else {
|
||||
delete d->toolbox;
|
||||
d->toolbox = 0;
|
||||
|
@ -75,39 +75,38 @@ class EmptyGraphicsItem : public QGraphicsItem
|
||||
// used with QGrahphicsItem::setData
|
||||
static const int ToolName = 7001;
|
||||
|
||||
class DesktopToolbox::Private
|
||||
{
|
||||
public:
|
||||
Private()
|
||||
: icon("plasma"),
|
||||
toolBacker(0),
|
||||
animId(0),
|
||||
animFrame(0)
|
||||
{}
|
||||
|
||||
KIcon icon;
|
||||
EmptyGraphicsItem *toolBacker;
|
||||
QTime stopwatch;
|
||||
Plasma::Phase::AnimId animId;
|
||||
qreal animFrame;
|
||||
};
|
||||
|
||||
DesktopToolbox::DesktopToolbox(QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent),
|
||||
m_icon("plasma"),
|
||||
m_toolBacker(0),
|
||||
m_size(50),
|
||||
m_showing(false),
|
||||
m_animId(0),
|
||||
m_animFrame(0)
|
||||
: Toolbox(parent),
|
||||
d(new Private)
|
||||
{
|
||||
setAcceptsHoverEvents(true);
|
||||
setZValue(10000000);
|
||||
setFlag(ItemClipsToShape, true);
|
||||
setFlag(ItemClipsChildrenToShape, false);
|
||||
setFlag(ItemIgnoresTransformations, true);
|
||||
|
||||
connect(Plasma::Phase::self(), SIGNAL(movementComplete(QGraphicsItem*)), this, SLOT(toolMoved(QGraphicsItem*)));
|
||||
}
|
||||
|
||||
/*QRectF DesktopToolbox::sizeHint() const
|
||||
{
|
||||
return boundingRect();
|
||||
}*/
|
||||
|
||||
QRectF DesktopToolbox::boundingRect() const
|
||||
{
|
||||
return QRectF(0, 0, m_size*2, m_size*2);
|
||||
}
|
||||
|
||||
void DesktopToolbox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
|
||||
painter->save();
|
||||
painter->translate(boundingRect().topLeft());
|
||||
|
||||
QColor color1 = KColorScheme(QPalette::Active, KColorScheme::Window,
|
||||
Plasma::Theme::self()->colors()).background().color();
|
||||
color1.setAlpha(64);
|
||||
@ -117,8 +116,8 @@ void DesktopToolbox::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
|
||||
color2.setAlpha(64);
|
||||
|
||||
QPainterPath p = shape();
|
||||
QRadialGradient gradient(QPoint(m_size*2, 0), m_size + m_animFrame);
|
||||
gradient.setFocalPoint(QPointF(m_size*2, 0));
|
||||
QRadialGradient gradient(boundingRect().topLeft(), size() + d->animFrame);
|
||||
gradient.setFocalPoint(boundingRect().topLeft());
|
||||
gradient.setColorAt(0, color1);
|
||||
gradient.setColorAt(.87, color1);
|
||||
gradient.setColorAt(.97, color2);
|
||||
@ -131,41 +130,43 @@ void DesktopToolbox::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
|
||||
painter->drawPath(p);
|
||||
painter->restore();
|
||||
|
||||
const qreal progress = m_animFrame / m_size;
|
||||
const qreal progress = d->animFrame / size();
|
||||
|
||||
if (progress <= 0.9) {
|
||||
m_icon.paint(painter, QRect(m_size*2 - 34, 2, 32, 32), Qt::AlignCenter, QIcon::Disabled, QIcon::Off);
|
||||
d->icon.paint(painter, QRect(QPoint((int)boundingRect().left() - iconSize().width() + 2, 2), iconSize()), Qt::AlignCenter, QIcon::Disabled, QIcon::Off);
|
||||
}
|
||||
|
||||
if (progress > 0.1) {
|
||||
painter->save();
|
||||
painter->setOpacity(progress);
|
||||
m_icon.paint(painter, QRect(m_size*2 - 34, 2, 32, 32));
|
||||
d->icon.paint(painter, QRect(QPoint((int)boundingRect().left() - iconSize().width() + 2, 2), iconSize()));
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
QPainterPath DesktopToolbox::shape() const
|
||||
{
|
||||
QPainterPath path;
|
||||
int size = m_size + (int)m_animFrame;
|
||||
path.moveTo(m_size*2, 0);
|
||||
path.arcTo(QRectF(m_size*2 - size, -size, size*2, size*2), 180, 90);
|
||||
int toolSize = size() + (int)d->animFrame;
|
||||
path.arcTo(QRectF(boundingRect().left() - toolSize, boundingRect().top() - toolSize, toolSize*2, toolSize*2), 180, 90);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
void DesktopToolbox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
if (m_showing || m_stopwatch.elapsed() < 100) {
|
||||
if (showing() || d->stopwatch.elapsed() < 100) {
|
||||
QGraphicsItem::hoverEnterEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
QPainterPath path;
|
||||
int size = m_size + (int)m_animFrame - 15;
|
||||
path.moveTo(m_size*2, 0);
|
||||
path.arcTo(QRectF(m_size * 2 - size, -size, size*2, size*2), 180, 90);
|
||||
path.lineTo(m_size*2, 0);
|
||||
int toolSize = size() + (int)d->animFrame - 15;
|
||||
path.moveTo(size()*2, 0);
|
||||
path.arcTo(QRectF(size() * 2 - toolSize, -toolSize, toolSize*2, toolSize*2), 180, 90);
|
||||
path.lineTo(size()*2, 0);
|
||||
|
||||
if (path.contains(event->pos())) {
|
||||
QGraphicsItem::hoverEnterEvent(event);
|
||||
@ -178,7 +179,7 @@ void DesktopToolbox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
|
||||
void DesktopToolbox::showToolbox()
|
||||
{
|
||||
if (m_showing) {
|
||||
if (showing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -192,18 +193,18 @@ void DesktopToolbox::showToolbox()
|
||||
|
||||
// put tools 5px from icon edge
|
||||
const int iconWidth = 32;
|
||||
int x = m_size*2 - maxwidth - iconWidth - 5;
|
||||
int y = 5; // pos().y();
|
||||
int x = (int)boundingRect().left() - maxwidth - iconWidth - 5;
|
||||
int y = (int)boundingRect().top() + 5;
|
||||
Plasma::Phase* phase = Plasma::Phase::self();
|
||||
foreach (QGraphicsItem* tool, QGraphicsItem::children()) {
|
||||
if (tool == m_toolBacker) {
|
||||
if (tool == d->toolBacker) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!tool->isEnabled()) {
|
||||
if (tool->isVisible()) {
|
||||
const int height = static_cast<int>(tool->boundingRect().height());
|
||||
phase->moveItem(tool, Plasma::Phase::SlideOut, QPoint(m_size * 2, -height));
|
||||
phase->moveItem(tool, Plasma::Phase::SlideOut, QPoint(size() * 2, -height));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -215,28 +216,28 @@ void DesktopToolbox::showToolbox()
|
||||
y += static_cast<int>(tool->boundingRect().height()) + 5;
|
||||
}
|
||||
|
||||
if (!m_toolBacker) {
|
||||
m_toolBacker = new EmptyGraphicsItem(this);
|
||||
if (!d->toolBacker) {
|
||||
d->toolBacker = new EmptyGraphicsItem(this);
|
||||
}
|
||||
m_toolBacker->setRect(QRectF(QPointF(x, 0), QSizeF(maxwidth, y - 10)));
|
||||
m_toolBacker->show();
|
||||
d->toolBacker->setRect(QRectF(QPointF(x, 0), QSizeF(maxwidth, y - 10)));
|
||||
d->toolBacker->show();
|
||||
|
||||
if (m_animId) {
|
||||
phase->stopCustomAnimation(m_animId);
|
||||
if (d->animId) {
|
||||
phase->stopCustomAnimation(d->animId);
|
||||
}
|
||||
|
||||
m_showing = 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().
|
||||
m_animId = phase->customAnimation(10, 240, Plasma::Phase::EaseInCurve, this, "animate");
|
||||
m_stopwatch.restart();
|
||||
d->animId = phase->customAnimation(10, 240, Plasma::Phase::EaseInCurve, this, "animate");
|
||||
d->stopwatch.restart();
|
||||
}
|
||||
|
||||
void DesktopToolbox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
//kDebug() << event->pos() << event->scenePos() << m_toolBacker->rect().contains(event->scenePos().toPoint());
|
||||
if ((m_toolBacker && m_toolBacker->rect().contains(event->scenePos().toPoint())) ||
|
||||
m_stopwatch.elapsed() < 100) {
|
||||
//kDebug() << event->pos() << event->scenePos() << d->toolBacker->rect().contains(event->scenePos().toPoint());
|
||||
if ((d->toolBacker && d->toolBacker->rect().contains(event->scenePos().toPoint())) ||
|
||||
d->stopwatch.elapsed() < 100) {
|
||||
QGraphicsItem::hoverLeaveEvent(event);
|
||||
return;
|
||||
}
|
||||
@ -246,15 +247,15 @@ void DesktopToolbox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
|
||||
void DesktopToolbox::hideToolbox()
|
||||
{
|
||||
if (!m_showing) {
|
||||
if (!showing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int x = m_size * 2;
|
||||
int x = size() * 2;
|
||||
int y = 0;
|
||||
Plasma::Phase* phase = Plasma::Phase::self();
|
||||
foreach (QGraphicsItem* tool, QGraphicsItem::children()) {
|
||||
if (tool == m_toolBacker) {
|
||||
if (tool == d->toolBacker) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -262,32 +263,32 @@ void DesktopToolbox::hideToolbox()
|
||||
phase->moveItem(tool, Plasma::Phase::SlideOut, QPoint(x, y-height));
|
||||
}
|
||||
|
||||
if (m_animId) {
|
||||
phase->stopCustomAnimation(m_animId);
|
||||
if (d->animId) {
|
||||
phase->stopCustomAnimation(d->animId);
|
||||
}
|
||||
|
||||
m_showing = false;
|
||||
m_animId = phase->customAnimation(10, 240, Plasma::Phase::EaseOutCurve, this, "animate");
|
||||
setShowing(false);
|
||||
d->animId = phase->customAnimation(10, 240, Plasma::Phase::EaseOutCurve, this, "animate");
|
||||
|
||||
if (m_toolBacker) {
|
||||
m_toolBacker->hide();
|
||||
if (d->toolBacker) {
|
||||
d->toolBacker->hide();
|
||||
}
|
||||
|
||||
m_stopwatch.restart();
|
||||
d->stopwatch.restart();
|
||||
}
|
||||
|
||||
void DesktopToolbox::animate(qreal progress)
|
||||
{
|
||||
if (m_showing) {
|
||||
m_animFrame = m_size * progress;
|
||||
if (showing()) {
|
||||
d->animFrame = size() * progress;
|
||||
} else {
|
||||
m_animFrame = m_size * (1.0 - progress);
|
||||
d->animFrame = size() * (1.0 - progress);
|
||||
}
|
||||
|
||||
//kDebug() << "animating at" << progress << "for" << m_animFrame;
|
||||
//kDebug() << "animating at" << progress << "for" << d->animFrame;
|
||||
|
||||
if (progress >= 1) {
|
||||
m_animId = 0;
|
||||
d->animId = 0;
|
||||
}
|
||||
|
||||
update();
|
||||
@ -296,65 +297,12 @@ void DesktopToolbox::animate(qreal progress)
|
||||
void DesktopToolbox::toolMoved(QGraphicsItem *item)
|
||||
{
|
||||
//kDebug() << "geometry is now " << static_cast<Plasma::Widget*>(item)->geometry();
|
||||
if (!m_showing &&
|
||||
if (!showing() &&
|
||||
QGraphicsItem::children().indexOf(static_cast<Plasma::Applet*>(item)) != -1) {
|
||||
item->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void DesktopToolbox::addTool(QGraphicsItem *tool, const QString &name)
|
||||
{
|
||||
if (!tool) {
|
||||
return;
|
||||
}
|
||||
|
||||
tool->hide();
|
||||
const int height = static_cast<int>(tool->boundingRect().height());
|
||||
tool->setPos(QPoint(m_size*2,-height));
|
||||
tool->setZValue(zValue() + 1);
|
||||
tool->setParentItem(this);
|
||||
tool->setData(ToolName, name);
|
||||
}
|
||||
|
||||
void DesktopToolbox::enableTool(const QString &toolName, bool visible)
|
||||
{
|
||||
//kDebug() << (visible? "enabling" : "disabling") << "tool" << toolName;
|
||||
QGraphicsItem *t = tool(toolName);
|
||||
|
||||
if (t && t->isEnabled() != visible) {
|
||||
t->setEnabled(visible);
|
||||
// adjust the visible items
|
||||
if (m_showing) {
|
||||
m_showing = false;
|
||||
showToolbox();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool DesktopToolbox::isToolEnabled(const QString &toolName) const
|
||||
{
|
||||
QGraphicsItem *t = tool(toolName);
|
||||
|
||||
if (t) {
|
||||
return t->isEnabled();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QGraphicsItem* DesktopToolbox::tool(const QString &toolName) const
|
||||
{
|
||||
foreach (QGraphicsItem *child, QGraphicsItem::children()) {
|
||||
//kDebug() << "checking tool" << child << child->data(ToolName);
|
||||
if (child->data(ToolName).toString() == toolName) {
|
||||
//kDebug() << "tool found!";
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // plasma namespace
|
||||
|
||||
#include "desktoptoolbox_p.moc"
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2008 by Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
@ -26,6 +27,8 @@
|
||||
|
||||
#include <KIcon>
|
||||
|
||||
#include <plasma/toolbox_p.h>
|
||||
|
||||
#include "phase.h"
|
||||
|
||||
namespace Plasma
|
||||
@ -34,20 +37,14 @@ namespace Plasma
|
||||
class Widget;
|
||||
class EmptyGraphicsItem;
|
||||
|
||||
class DesktopToolbox : public QObject, public QGraphicsItem
|
||||
class DesktopToolbox : public Toolbox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DesktopToolbox(QGraphicsItem *parent = 0);
|
||||
QRectF boundingRect() const;
|
||||
QPainterPath shape() const;
|
||||
|
||||
void addTool(QGraphicsItem *tool, const QString &name);
|
||||
void enableTool(const QString &tool, bool enabled);
|
||||
bool isToolEnabled(const QString &tool) const;
|
||||
QGraphicsItem* tool(const QString &tool) const;
|
||||
|
||||
void showToolbox();
|
||||
void hideToolbox();
|
||||
|
||||
@ -59,16 +56,9 @@ protected:
|
||||
protected slots:
|
||||
void animate(qreal progress);
|
||||
void toolMoved(QGraphicsItem*);
|
||||
|
||||
private:
|
||||
KIcon m_icon;
|
||||
EmptyGraphicsItem *m_toolBacker;
|
||||
QTime m_stopwatch;
|
||||
const int m_size;
|
||||
bool m_hidden;
|
||||
bool m_showing;
|
||||
Plasma::Phase::AnimId m_animId;
|
||||
qreal m_animFrame;
|
||||
class Private;
|
||||
Private *d;
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
|
311
paneltoolbox.cpp
Normal file
311
paneltoolbox.cpp
Normal file
@ -0,0 +1,311 @@
|
||||
/*
|
||||
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2008 by Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "paneltoolbox_p.h"
|
||||
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QPainter>
|
||||
#include <QRadialGradient>
|
||||
|
||||
#include <plasma/theme.h>
|
||||
#include <KColorScheme>
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
#include "widgets/widget.h"
|
||||
|
||||
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 PanelToolbox::Private
|
||||
{
|
||||
public:
|
||||
Private()
|
||||
: icon("plasma"),
|
||||
toolBacker(0),
|
||||
animId(0),
|
||||
animFrame(0)
|
||||
{}
|
||||
|
||||
KIcon icon;
|
||||
EmptyGraphicsItem *toolBacker;
|
||||
QTime stopwatch;
|
||||
Plasma::Phase::AnimId animId;
|
||||
qreal animFrame;
|
||||
};
|
||||
|
||||
PanelToolbox::PanelToolbox(QGraphicsItem *parent)
|
||||
: Toolbox(parent),
|
||||
d(new Private)
|
||||
{
|
||||
connect(Plasma::Phase::self(), SIGNAL(movementComplete(QGraphicsItem*)), this, SLOT(toolMoved(QGraphicsItem*)));
|
||||
}
|
||||
|
||||
QRectF PanelToolbox::boundingRect() const
|
||||
{
|
||||
return QRectF(0, 0, size()*2, size()*2);
|
||||
}
|
||||
|
||||
void PanelToolbox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
|
||||
QColor color1 = KColorScheme(QPalette::Active, KColorScheme::Window,
|
||||
Plasma::Theme::self()->colors()).background().color();
|
||||
color1.setAlpha(64);
|
||||
|
||||
QColor color2 = KColorScheme(QPalette::Active, KColorScheme::Window,
|
||||
Plasma::Theme::self()->colors()).foreground().color();
|
||||
color2.setAlpha(64);
|
||||
|
||||
QPainterPath p = shape();
|
||||
QRadialGradient gradient(QPoint(size()*2, size()), size() + d->animFrame);
|
||||
gradient.setFocalPoint(QPointF(size()*2, size()));
|
||||
gradient.setColorAt(0, color1);
|
||||
gradient.setColorAt(.87, color1);
|
||||
gradient.setColorAt(.97, color2);
|
||||
color2.setAlpha(0);
|
||||
gradient.setColorAt(1, color2);
|
||||
painter->save();
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
painter->setBrush(gradient);
|
||||
painter->drawPath(p);
|
||||
painter->restore();
|
||||
|
||||
const qreal progress = d->animFrame / size();
|
||||
|
||||
if (progress <= 0.9) {
|
||||
d->icon.paint(painter, QRect(QPoint(size()*2 - iconSize().width() + 2, 2), iconSize()), Qt::AlignCenter, QIcon::Disabled, QIcon::Off);
|
||||
}
|
||||
|
||||
if (progress > 0.1) {
|
||||
painter->save();
|
||||
painter->setOpacity(progress);
|
||||
d->icon.paint(painter, QRect(QPoint(size()*2 - iconSize().width() + 2, 2), iconSize()));
|
||||
painter->restore();
|
||||
}
|
||||
}
|
||||
|
||||
QPainterPath PanelToolbox::shape() const
|
||||
{
|
||||
QPainterPath path;
|
||||
int toolSize = size() + (int)d->animFrame;
|
||||
path.moveTo(size()*2, 0);
|
||||
//path.arcTo(QRectF(size()*2 - toolSize, -toolSize, toolSize*2, toolSize*2), 180, 90);
|
||||
path.addRect(QRectF(0, 0, toolSize*2, toolSize*2));
|
||||
return path;
|
||||
}
|
||||
|
||||
void PanelToolbox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
if (showing() || d->stopwatch.elapsed() < 100) {
|
||||
QGraphicsItem::hoverEnterEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
QPainterPath path;
|
||||
int toolSize = size() + (int)d->animFrame - 15;
|
||||
path.moveTo(size()*2, 0);
|
||||
//path.arcTo(QRectF(size() * 2 - toolSize, -toolSize, toolSize*2, toolSize*2), 180, 90);
|
||||
path.addRect(QRectF(0, 0, toolSize*2, toolSize*2));
|
||||
path.lineTo(size()*2, 0);
|
||||
|
||||
if (path.contains(event->pos())) {
|
||||
QGraphicsItem::hoverEnterEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
showToolbox();
|
||||
QGraphicsItem::hoverEnterEvent(event);
|
||||
}
|
||||
|
||||
void PanelToolbox::showToolbox()
|
||||
{
|
||||
if (showing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int maxwidth = 0;
|
||||
foreach (QGraphicsItem* tool, QGraphicsItem::children()) {
|
||||
if (!tool->isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
maxwidth = qMax(static_cast<int>(tool->boundingRect().width()), maxwidth);
|
||||
}
|
||||
|
||||
// put tools 5px from icon edge
|
||||
const int iconWidth = 32;
|
||||
int x = size()*2 - maxwidth - iconWidth - 5;
|
||||
int y = 5; // pos().y();
|
||||
Plasma::Phase* phase = Plasma::Phase::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());
|
||||
phase->moveItem(tool, Plasma::Phase::SlideOut, QPoint(size() * 2, -height));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
//kDebug() << "let's show and move" << tool << tool->boundingRect();
|
||||
tool->show();
|
||||
phase->moveItem(tool, Plasma::Phase::SlideIn, 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) {
|
||||
phase->stopCustomAnimation(d->animId);
|
||||
}
|
||||
|
||||
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->animId = phase->customAnimation(10, 240, Plasma::Phase::EaseInCurve, this, "animate");
|
||||
d->stopwatch.restart();
|
||||
}
|
||||
|
||||
void PanelToolbox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
//kDebug() << event->pos() << event->scenePos() << d->toolBacker->rect().contains(event->scenePos().toPoint());
|
||||
if ((d->toolBacker && d->toolBacker->rect().contains(event->scenePos().toPoint())) ||
|
||||
d->stopwatch.elapsed() < 100) {
|
||||
QGraphicsItem::hoverLeaveEvent(event);
|
||||
return;
|
||||
}
|
||||
hideToolbox();
|
||||
QGraphicsItem::hoverLeaveEvent(event);
|
||||
}
|
||||
|
||||
void PanelToolbox::hideToolbox()
|
||||
{
|
||||
if (!showing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int x = size() * 2;
|
||||
int y = 0;
|
||||
Plasma::Phase* phase = Plasma::Phase::self();
|
||||
foreach (QGraphicsItem* tool, QGraphicsItem::children()) {
|
||||
if (tool == d->toolBacker) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const int height = static_cast<int>(tool->boundingRect().height());
|
||||
phase->moveItem(tool, Plasma::Phase::SlideOut, QPoint(x, y-height));
|
||||
}
|
||||
|
||||
if (d->animId) {
|
||||
phase->stopCustomAnimation(d->animId);
|
||||
}
|
||||
|
||||
setShowing(false);
|
||||
d->animId = phase->customAnimation(10, 240, Plasma::Phase::EaseOutCurve, this, "animate");
|
||||
|
||||
if (d->toolBacker) {
|
||||
d->toolBacker->hide();
|
||||
}
|
||||
|
||||
d->stopwatch.restart();
|
||||
}
|
||||
|
||||
void PanelToolbox::animate(qreal progress)
|
||||
{
|
||||
if (showing()) {
|
||||
d->animFrame = size() * progress;
|
||||
} else {
|
||||
d->animFrame = size() * (1.0 - progress);
|
||||
}
|
||||
|
||||
//kDebug() << "animating at" << progress << "for" << d->animFrame;
|
||||
|
||||
if (progress >= 1) {
|
||||
d->animId = 0;
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void PanelToolbox::toolMoved(QGraphicsItem *item)
|
||||
{
|
||||
//kDebug() << "geometry is now " << static_cast<Plasma::Widget*>(item)->geometry();
|
||||
if (!showing() &&
|
||||
QGraphicsItem::children().indexOf(static_cast<Plasma::Widget*>(item)) != -1) {
|
||||
item->hide();
|
||||
}
|
||||
}
|
||||
|
||||
} // plasma namespace
|
||||
|
||||
#include "paneltoolbox_p.moc"
|
||||
|
67
paneltoolbox_p.h
Normal file
67
paneltoolbox_p.h
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2008 by Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_PANELTOOLBOX_P_H
|
||||
#define PLASMA_PANELTOOLBOX_P_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
#include <QObject>
|
||||
#include <QTime>
|
||||
|
||||
#include <KIcon>
|
||||
|
||||
#include <plasma/toolbox_p.h>
|
||||
|
||||
#include "phase.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class Widget;
|
||||
class EmptyGraphicsItem;
|
||||
|
||||
class PanelToolbox : public Toolbox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PanelToolbox(QGraphicsItem *parent = 0);
|
||||
virtual QRectF boundingRect() const;
|
||||
QPainterPath shape() const;
|
||||
|
||||
void showToolbox();
|
||||
void hideToolbox();
|
||||
|
||||
protected:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||
|
||||
protected slots:
|
||||
void animate(qreal progress);
|
||||
void toolMoved(QGraphicsItem*);
|
||||
private:
|
||||
class Private;
|
||||
Private *d;
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
#endif // multiple inclusion guard
|
||||
|
159
toolbox.cpp
Normal file
159
toolbox.cpp
Normal file
@ -0,0 +1,159 @@
|
||||
|
||||
/*
|
||||
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2008 by Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "toolbox_p.h"
|
||||
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QPainter>
|
||||
#include <QRadialGradient>
|
||||
|
||||
#include <plasma/theme.h>
|
||||
#include <KColorScheme>
|
||||
|
||||
#include <KDebug>
|
||||
|
||||
#include "widgets/widget.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
// used with QGrahphicsItem::setData
|
||||
static const int ToolName = 7001;
|
||||
|
||||
class Toolbox::Private
|
||||
{
|
||||
public:
|
||||
Private()
|
||||
: size(50),
|
||||
iconSize(32, 32),
|
||||
hidden(false),
|
||||
showing(false)
|
||||
{}
|
||||
|
||||
int size;
|
||||
QSize iconSize;
|
||||
bool hidden;
|
||||
bool showing;
|
||||
};
|
||||
|
||||
Toolbox::Toolbox(QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent),
|
||||
d(new Private)
|
||||
{
|
||||
setAcceptsHoverEvents(true);
|
||||
setZValue(10000000);
|
||||
setFlag(ItemClipsToShape, true);
|
||||
setFlag(ItemClipsChildrenToShape, false);
|
||||
setFlag(ItemIgnoresTransformations, true);
|
||||
}
|
||||
|
||||
QRectF Toolbox::boundingRect() const
|
||||
{
|
||||
return QRectF(0, 0, -size()*2, size()*2);
|
||||
}
|
||||
|
||||
void Toolbox::addTool(QGraphicsItem *tool, const QString &name)
|
||||
{
|
||||
if (!tool) {
|
||||
return;
|
||||
}
|
||||
|
||||
tool->hide();
|
||||
const int height = static_cast<int>(tool->boundingRect().height());
|
||||
tool->setPos(QPoint( d->size*2,-height));
|
||||
tool->setZValue(zValue() + 1);
|
||||
tool->setParentItem(this);
|
||||
tool->setData(ToolName, name);
|
||||
}
|
||||
|
||||
void Toolbox::enableTool(const QString &toolName, bool visible)
|
||||
{
|
||||
//kDebug() << (visible? "enabling" : "disabling") << "tool" << toolName;
|
||||
QGraphicsItem *t = tool(toolName);
|
||||
|
||||
if (t && t->isEnabled() != visible) {
|
||||
t->setEnabled(visible);
|
||||
// adjust the visible items
|
||||
if ( d->showing) {
|
||||
d->showing = false;
|
||||
showToolbox();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Toolbox::isToolEnabled(const QString &toolName) const
|
||||
{
|
||||
QGraphicsItem *t = tool(toolName);
|
||||
|
||||
if (t) {
|
||||
return t->isEnabled();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QGraphicsItem* Toolbox::tool(const QString &toolName) const
|
||||
{
|
||||
foreach (QGraphicsItem *child, QGraphicsItem::children()) {
|
||||
//kDebug() << "checking tool" << child << child->data(ToolName);
|
||||
if (child->data(ToolName).toString() == toolName) {
|
||||
//kDebug() << "tool found!";
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Toolbox::size() const
|
||||
{
|
||||
return d->size;
|
||||
}
|
||||
|
||||
void Toolbox::setSize(const int newSize)
|
||||
{
|
||||
d->size = newSize;
|
||||
}
|
||||
|
||||
QSize Toolbox::iconSize() const
|
||||
{
|
||||
return d->iconSize;
|
||||
}
|
||||
|
||||
void Toolbox::setIconSize(const QSize newSize)
|
||||
{
|
||||
d->iconSize = newSize;
|
||||
}
|
||||
|
||||
bool Toolbox::showing() const
|
||||
{
|
||||
return d->showing;
|
||||
}
|
||||
|
||||
void Toolbox::setShowing(const bool show)
|
||||
{
|
||||
d->showing = show;
|
||||
}
|
||||
|
||||
} // plasma namespace
|
||||
|
||||
#include "toolbox_p.moc"
|
||||
|
68
toolbox_p.h
Normal file
68
toolbox_p.h
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2008 by Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_TOOLBOX_P_H
|
||||
#define PLASMA_TOOLBOX_P_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
#include <QObject>
|
||||
|
||||
#include "phase.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class Widget;
|
||||
class EmptyGraphicsItem;
|
||||
|
||||
class Toolbox : public QObject, public QGraphicsItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Toolbox(QGraphicsItem *parent = 0);
|
||||
virtual QRectF boundingRect() const;
|
||||
|
||||
void addTool(QGraphicsItem *tool, const QString &name);
|
||||
void enableTool(const QString &tool, bool enabled);
|
||||
bool isToolEnabled(const QString &tool) const;
|
||||
QGraphicsItem* tool(const QString &tool) const;
|
||||
int size() const;
|
||||
void setSize(const int newSize);
|
||||
QSize iconSize() const;
|
||||
void setIconSize(const QSize newSize);
|
||||
bool showing() const;
|
||||
void setShowing(const bool show);
|
||||
|
||||
virtual void showToolbox() = 0;
|
||||
virtual void hideToolbox() = 0;
|
||||
|
||||
protected:
|
||||
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) = 0;
|
||||
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) = 0;
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private *d;
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
#endif // multiple inclusion guard
|
||||
|
Loading…
x
Reference in New Issue
Block a user