[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/workspace/plasma/containments/desktop
From: Aaron J. Seigo <aseigo () kde ! org>
Date: 2007-10-12 22:49:50
Message-ID: 1192229390.845692.10248.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 724655 by aseigo:
a bit more work on the desktop and toolbox. there is a very odd behaviour with \
children items being clipped, even though the clipping flag is off and, most oddly, \
events are still getting captured by the full item (e.g. where they SHOULD be). need \
to talk to andreas about this. i'm sure he can point out what i'm doing wrong in 2s.
CCMAIL:ahanssen@trolltech.com
M +87 -45 desktop.cpp
M +9 -5 desktop.h
--- trunk/KDE/kdebase/workspace/plasma/containments/desktop/desktop.cpp \
#724654:724655 @@ -46,28 +46,19 @@
ToolBox::ToolBox(QGraphicsItem *parent)
- : Plasma::Widget(parent),
- m_showTimeLine(new QTimeLine(250, this)),
+ : QGraphicsItem(parent),
m_icon("configure"),
m_size(50),
- m_hidden(true)
+ m_showing(false),
+ m_animId(0),
+ m_animFrame(0)
{
- m_showTimeLine->setCurveShape(QTimeLine::EaseInOutCurve);
- m_showTimeLine->setFrameRange(0, m_size);
- connect(m_showTimeLine, SIGNAL(frameChanged(int)), this, SLOT(animate(int)));
setAcceptsHoverEvents(true);
setZValue(10000);
+ setFlag(ItemClipsToShape, true);
+ setFlag(ItemClipsChildrenToShape, false);
- Plasma::PushButton *tool = new Plasma::PushButton("Add Widgets", this);
- tool->resize(tool->sizeHint());
- tool->setZValue(10001);
- m_tools.append(tool);
- tool = new Plasma::PushButton("Zoom Out", this);
- tool->resize(tool->sizeHint());
- tool->setZValue(10001);
- m_tools.append(tool);
-
- connect(Phase::self(), SIGNAL(movementComplete(QGraphicsItem*)), this, \
SLOT(toolMoved(QGraphicsItem*))); + connect(Plasma::Phase::self(), \
SIGNAL(movementComplete(QGraphicsItem*)), this, SLOT(toolMoved(QGraphicsItem*))); }
/*QRectF ToolBox::sizeHint() const
@@ -80,13 +71,16 @@
return QRectF(0, 0, m_size*2, m_size*2);
}
-void ToolBox::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, \
QWidget *widget) +void ToolBox::paint(QPainter *painter, const \
QStyleOptionGraphicsItem *option, QWidget *widget) {
+ Q_UNUSED(option)
+ Q_UNUSED(widget)
+
QPainterPath p = shape();
QRadialGradient gradient(QPoint(m_size*2, 0), m_size*3);
gradient.setFocalPoint(QPointF(m_size*2, 0));
gradient.setColorAt(0, QColor(255, 255, 255, 128));
- gradient.setColorAt(.8, QColor(128, 128, 128));
+ gradient.setColorAt(.9, QColor(128, 128, 128, 128));
painter->save();
painter->setPen(Qt::NoPen);
painter->setRenderHint(QPainter::Antialiasing, true);
@@ -99,7 +93,7 @@
QPainterPath ToolBox::shape() const
{
QPainterPath path;
- int size = m_size + m_showTimeLine->currentFrame();
+ int size = m_size + m_animFrame;
path.moveTo(m_size*2, 0);
path.arcTo(QRectF(m_size*2 - size, -size, size*2, size*2), 180, 90);
return path;
@@ -107,57 +101,85 @@
void ToolBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
-// Phase::self()->moveItem(this, Phase::SlideIn, QPoint(-25, -25));
- int x = -25; //pos().x();
- int y = 0; //pos().y();
- foreach (Plasma::Widget* tool, m_tools) {
+ Q_UNUSED(event)
+
+// Plasma::Phase::self()->moveItem(this, Phase::SlideIn, QPoint(-25, -25));
+ int x = -25; // pos().x();
+ int y = 0; // pos().y();
+ Plasma::Phase* phase = Plasma::Phase::self();
+ foreach (QGraphicsItem* tool, QGraphicsItem::children()) {
+// kDebug() << "let's show and move" << (QObject*)tool << \
tool->geometry().toRect(); tool->show();
- Phase::self()->moveItem(tool, Phase::SlideIn, QPoint(x, y));
- x += 0;
- y += tool->geometry().height() + 5;
+ phase->moveItem(tool, Plasma::Phase::SlideIn, QPoint(x, y));
+ //x += 0;
+ y += tool->boundingRect().height() + 5;
}
- m_showTimeLine->setDirection(QTimeLine::Forward);
- if (m_showTimeLine->state() != QTimeLine::Running) {
- m_showTimeLine->start();
+ if (m_animId) {
+ phase->stopCustomAnimation(m_animId);
}
+
+ m_showing = true;
+ m_animId = phase->customAnimation(m_size, 150, Plasma::Phase::EaseInCurve, this, \
"animate"); }
void ToolBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
-// Phase::self->moveItem(this, Phase::SlideOut, boundingRect()QPoint(-50, -50));
- int x = 0; //pos().x() + geometry().width();
+// Plasma::Phase::self->moveItem(this, Phase::SlideOut, boundingRect()QPoint(-50, \
-50)); + int x = 0; // pos().x() + geometry().width();
int y = 0;
- foreach (QGraphicsItem* tool, m_tools) {
- Phase::self()->moveItem(tool, Phase::SlideOut, QPoint(x, y));
+ Plasma::Phase* phase = Plasma::Phase::self();
+ foreach (QGraphicsItem* tool, QGraphicsItem::children()) {
+ phase->moveItem(tool, Plasma::Phase::SlideOut, QPoint(x, y));
}
- m_showTimeLine->setDirection(QTimeLine::Backward);
- if (m_showTimeLine->state() != QTimeLine::Running) {
- m_showTimeLine->start();
+ if (m_animId) {
+ phase->stopCustomAnimation(m_animId);
}
+
+ m_showing = false;
+ m_animId = phase->customAnimation(m_size, 150, Plasma::Phase::EaseOutCurve, \
this, "animate"); }
-void ToolBox::animate(int frame)
+void ToolBox::animate(qreal progress)
{
- Q_UNUSED(frame)
-/* qreal percentage
- foreach (Tool* tool, m_tools) {
- tool
- }*/
+ if (m_showing) {
+ m_animFrame = m_size * progress;
+ } else {
+ m_animFrame = m_size * (1 - progress);
+ }
+
+ //kDebug() << "animating at" << progress << "for" << m_animFrame;
+
+ if (progress >= 1) {
+ m_animId = 0;
+ }
+
update();
}
void ToolBox::toolMoved(QGraphicsItem *item)
{
//kDebug() << "geometry is now " << \
static_cast<Plasma::Widget*>(item)->geometry();
- if (m_showTimeLine->direction() == QTimeLine::Backward &&
- m_tools.indexOf(static_cast<Plasma::Widget*>(item)) != -1) {
+ if (!m_showing &&
+ QGraphicsItem::children().indexOf(static_cast<Plasma::Widget*>(item)) != -1) \
{ item->hide();
}
}
+void ToolBox::addTool(Plasma::Widget *tool)
+{
+ if (!tool) {
+ return;
+ }
+
+ tool->hide();
+ tool->setPos(pos());
+ tool->setZValue(zValue() + 1);
+ tool->setParentItem(this);
+}
+
DefaultDesktop::DefaultDesktop(QObject *parent, const QVariantList &args)
: Containment(parent, args),
m_engineExplorerAction(0),
@@ -179,8 +201,28 @@
{
Containment::init();
m_toolbox = new ToolBox(this);
- m_toolbox->updateGeometry();
+ //m_toolbox->updateGeometry();
m_toolbox->setPos(geometry().width() - m_toolbox->boundingRect().width(), 0);
+
+ Plasma::PushButton *tool = new Plasma::PushButton("Add Widgets", this);
+ tool->resize(tool->sizeHint());
+ m_toolbox->addTool(tool);
+ connect(tool, SIGNAL(clicked()), this, SLOT(launchAppletBrowser()));
+
+ tool = new Plasma::PushButton("Engine Explorer", this);
+ connect(tool, SIGNAL(clicked()), this, SLOT(launchExplorer()));
+ tool->resize(tool->sizeHint());
+ m_toolbox->addTool(tool);
+
+ tool = new Plasma::PushButton("Zoom In", this);
+ //connect(tool, SIGNAL(clicked()), this, SLOT(launchAppletBrowser()));
+ tool->resize(tool->sizeHint());
+ m_toolbox->addTool(tool);
+
+ tool = new Plasma::PushButton("Zoom Out", this);
+ //connect(tool, SIGNAL(clicked()), this, SLOT(launchAppletBrowser()));
+ tool->resize(tool->sizeHint());
+ m_toolbox->addTool(tool);
}
void DefaultDesktop::constraintsUpdated(Plasma::Constraints constraints)
--- trunk/KDE/kdebase/workspace/plasma/containments/desktop/desktop.h #724654:724655
@@ -26,6 +26,7 @@
#include <KIcon>
#include <plasma/containment.h>
+#include <plasma/phase.h>
#include <plasma/widgets/widget.h>
class QAction;
@@ -47,7 +48,7 @@
};*/
-class ToolBox : public Plasma::Widget
+class ToolBox : public QObject, public QGraphicsItem
{
Q_OBJECT
@@ -56,21 +57,24 @@
QRectF boundingRect() const;
QPainterPath shape() const;
+ void addTool(Plasma::Widget* tool);
+
protected:
- void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, \
QWidget *widget = 0); + void paint(QPainter *painter, const \
QStyleOptionGraphicsItem *option, QWidget *widget = 0); void \
hoverEnterEvent(QGraphicsSceneHoverEvent *event); void \
hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
protected slots:
- void animate(int frame);
+ void animate(qreal progress);
void toolMoved(QGraphicsItem*);
private:
- QList<Plasma::Widget*> m_tools;
- QTimeLine *m_showTimeLine;
KIcon m_icon;
int m_size;
bool m_hidden;
+ bool m_showing;
+ Plasma::Phase::AnimId m_animId;
+ int m_animFrame;
};
class DefaultDesktop : public Plasma::Containment
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic