* make mini buttons "click" on mouse release like a proper button
* don't click when moving (either the icon or the mini buttons) * only show the buttons on hovered states, allowing for proper button/hover/pressed painting * try and avoid unecessary if/else's and other codedamage * get rid of some dead code now it's about ready to be phased =) svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=676842
This commit is contained in:
parent
fab8953ccb
commit
60a844195e
@ -238,27 +238,28 @@ void Icon::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid
|
|||||||
if (!element.isEmpty()) {
|
if (!element.isEmpty()) {
|
||||||
//kDebug() << "painting " << element << endl;
|
//kDebug() << "painting " << element << endl;
|
||||||
d->svg.paint(painter, 0, 0, element);
|
d->svg.paint(painter, 0, 0, element);
|
||||||
|
element.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw top-left button
|
// Draw top-left button
|
||||||
QColor colorButton1;
|
if (d->state != Private::NoState) {
|
||||||
if (d->button1Hovered) {
|
if (d->button1Pressed) {
|
||||||
element = "button1-hover";
|
element = "button1-hover";
|
||||||
} else if (d->button1Pressed) {
|
} else if (d->button1Hovered) {
|
||||||
element = "button1-pressed";
|
element = "button1-pressed";
|
||||||
} else {
|
} else {
|
||||||
element = "button1";
|
element = "button1";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KIcon exec("exec");
|
KIcon exec("exec");
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
painter->setOpacity(d->stepMenu*0.2);
|
painter->setOpacity(d->stepMenu*0.2);
|
||||||
// painter->setBrush(colorButton1);
|
|
||||||
painter->setPen(Qt::NoPen);
|
painter->setPen(Qt::NoPen);
|
||||||
|
|
||||||
if (!element.isEmpty()) {
|
if (!element.isEmpty()) {
|
||||||
//kDebug() << "painting " << element << endl;
|
|
||||||
d->svg.paint(painter, QRect(6, 6, 32, 32), element);
|
d->svg.paint(painter, QRect(6, 6, 32, 32), element);
|
||||||
|
// painter->drawPixmap(6, 6, Phase::self()->paintElement(d->button1Id, this));
|
||||||
}
|
}
|
||||||
painter->drawPixmap(11, 11, exec.pixmap(22,22));
|
painter->drawPixmap(11, 11, exec.pixmap(22,22));
|
||||||
}
|
}
|
||||||
@ -335,12 +336,8 @@ bool Icon::isDown()
|
|||||||
void Icon::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void Icon::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
QRectF button1(6, 6, 32, 32); // The top-left circle
|
QRectF button1(6, 6, 32, 32); // The top-left circle
|
||||||
if (button1.contains(event->pos())) {
|
d->button1Pressed = button1.contains(event->pos());
|
||||||
if (d->url.isValid()) {
|
if (!d->button1Pressed) {
|
||||||
KRun::runUrl(d->url, KMimeType::findByUrl(d->url)->name(), 0);
|
|
||||||
}
|
|
||||||
d->button1Pressed = true;
|
|
||||||
} else {
|
|
||||||
d->state = Private::PressedState;
|
d->state = Private::PressedState;
|
||||||
QGraphicsItem::mousePressEvent(event);
|
QGraphicsItem::mousePressEvent(event);
|
||||||
update();
|
update();
|
||||||
@ -355,6 +352,14 @@ void Icon::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
|
|
||||||
if (inside) {
|
if (inside) {
|
||||||
d->state = Private::HoverState;
|
d->state = Private::HoverState;
|
||||||
|
|
||||||
|
QRectF button1(6, 6, 32, 32); // The top-left circle
|
||||||
|
d->button1Hovered = button1.contains(event->pos());
|
||||||
|
if (d->button1Hovered &&
|
||||||
|
d->button1Pressed && d->url.isValid()) {
|
||||||
|
KRun::runUrl(d->url, KMimeType::findByUrl(d->url)->name(), 0);
|
||||||
|
wasClicked == false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
d->state = Private::NoState;
|
d->state = Private::NoState;
|
||||||
}
|
}
|
||||||
@ -363,13 +368,8 @@ void Icon::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
emit pressed(false);
|
emit pressed(false);
|
||||||
emit clicked();
|
emit clicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
d->button1Pressed = false;
|
d->button1Pressed = false;
|
||||||
QRectF button1(6, 6, 32, 32); // The top-left circle
|
|
||||||
if (button1.contains(event->pos())) {
|
|
||||||
d->button1Hovered = true;
|
|
||||||
} else {
|
|
||||||
d->button1Hovered = false;
|
|
||||||
}
|
|
||||||
QGraphicsItem::mouseReleaseEvent(event);
|
QGraphicsItem::mouseReleaseEvent(event);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@ -378,12 +378,9 @@ void Icon::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|||||||
{
|
{
|
||||||
d->button1Pressed = false;
|
d->button1Pressed = false;
|
||||||
QRectF button1(6, 6, 32, 32); // The top-left circle
|
QRectF button1(6, 6, 32, 32); // The top-left circle
|
||||||
if (button1.contains(event->pos())) {
|
d->button1Hovered = button1.contains(event->pos());
|
||||||
d->button1Hovered = true;
|
|
||||||
} else {
|
|
||||||
d->button1Hovered = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//Phase::self()->elementAppears(this, button1);
|
||||||
d->timeline.setDirection(QTimeLine::Forward);
|
d->timeline.setDirection(QTimeLine::Forward);
|
||||||
d->state = Private::HoverState;
|
d->state = Private::HoverState;
|
||||||
QGraphicsItem::hoverEnterEvent(event);
|
QGraphicsItem::hoverEnterEvent(event);
|
||||||
@ -393,15 +390,28 @@ void Icon::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|||||||
void Icon::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
void Icon::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
d->timeline.setDirection(QTimeLine::Backward);
|
d->timeline.setDirection(QTimeLine::Backward);
|
||||||
|
//Phase::self()->elementDisappears(this, button1);
|
||||||
d->state = Private::HoverState;
|
|
||||||
QGraphicsItem::hoverEnterEvent(event);
|
|
||||||
|
|
||||||
d->timeline.start();
|
d->timeline.start();
|
||||||
d->state = Private::NoState;
|
d->state = Private::NoState;
|
||||||
|
d->button1Pressed = false;
|
||||||
|
d->button1Hovered = false;
|
||||||
QGraphicsItem::hoverLeaveEvent(event);
|
QGraphicsItem::hoverLeaveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Icon::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if (d->button1Pressed) {
|
||||||
|
d->button1Pressed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d->state == Private::PressedState) {
|
||||||
|
d->state == Private::HoverState;
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsItem::mouseMoveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
QSizeF Icon::sizeHint() const
|
QSizeF Icon::sizeHint() const
|
||||||
{
|
{
|
||||||
return d->size;
|
return d->size;
|
||||||
|
@ -90,8 +90,9 @@ class PLASMA_EXPORT Icon : public QObject,
|
|||||||
bool isDown();
|
bool isDown();
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void hoverEnterEvent (QGraphicsSceneHoverEvent * event);
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||||
void hoverLeaveEvent (QGraphicsSceneHoverEvent * event);
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void animateBubbles(int step);
|
void animateBubbles(int step);
|
||||||
|
Loading…
Reference in New Issue
Block a user