From 3af857e26546c0709cad37b72b11d28b66debd98 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Sun, 18 Nov 2007 01:16:47 +0000 Subject: [PATCH] aseigo's first run over this code; * don't use magic pixel values, use static const ints and it makes everything so easy to play with * make the borders and icons much smaller * allow dragging using any area that isn't the applet. really, we ought to be able to drag on the applet border as well, but ce la vis? svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=738128 --- applethandle.cpp | 53 ++++++++++++++++++++++++------------------------ applethandle_p.h | 4 ++++ 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/applethandle.cpp b/applethandle.cpp index 9e9455cbe..3d533e836 100644 --- a/applethandle.cpp +++ b/applethandle.cpp @@ -43,22 +43,22 @@ AppletHandle::AppletHandle(Containment *parent, Applet *applet) m_rect = m_applet->boundingRect(); m_rect = m_applet->mapToParent(m_rect).boundingRect(); - const int requiredHeight = m_applet->hasConfigurationInterface() ? 158 : 116; - if (m_rect.height()hasConfigurationInterface() ? + (ICON_SIZE * 4) : (ICON_SIZE * 3); + if (m_rect.height() < requiredHeight) { + float delta = requiredHeight - m_rect.height(); delta = delta/2.0; - if (delta>0.0) { + if (delta > 0.0) { m_rect.adjust(0.0, -delta, 0.0, delta); } } - m_rect.adjust(-20.0, -20.0, 20.0, 20.0); + m_rect.adjust(-HANDLE_WIDTH, -HANDLE_WIDTH, HANDLE_WIDTH, HANDLE_WIDTH); - if (m_applet->pos().x()<=60.0) { - m_rect.adjust(0.0, 0.0, 40.0, 0.0); + if (m_applet->pos().x() <= ((HANDLE_WIDTH * 2) + ICON_SIZE + ICON_MARGIN)) { + m_rect.adjust(0.0, 0.0, ICON_MARGIN + ICON_SIZE, 0.0); m_buttonsOnRight = true; } else { - m_rect.adjust(-40.0, 0.0, 0.0, 0.0); + m_rect.adjust(- ICON_MARGIN - ICON_SIZE, 0.0, 0.0, 0.0); } m_applet->setParentItem(this); @@ -110,9 +110,9 @@ void AppletHandle::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti QPointF point = m_rect.topLeft(); if (m_buttonsOnRight) { - point+= QPointF(m_rect.width()-52.0, 20.0); + point += QPointF(m_rect.width() - ICON_SIZE - ICON_MARGIN, HANDLE_WIDTH); } else { - point+= QPointF(20.0, 20.0); + point+= QPointF(HANDLE_WIDTH, HANDLE_WIDTH); } QPointF shiftM; @@ -138,15 +138,15 @@ void AppletHandle::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti break; } - painter->drawPixmap(point+shiftM, KIcon("exec").pixmap(32,32)); // FIXME: I'd like a "transform-move" here + painter->drawPixmap(point+shiftM, KIcon("exec").pixmap(ICON_SIZE, ICON_SIZE)); // FIXME: I'd like a "transform-move" here if (m_applet->hasConfigurationInterface()) { - point+=QPointF(0.0, 42.0); - painter->drawPixmap(point+shiftC, KIcon("configure").pixmap(32,32)); + point+=QPointF(0.0, ICON_SIZE + ICON_MARGIN); + painter->drawPixmap(point+shiftC, KIcon("configure").pixmap(ICON_SIZE, ICON_SIZE)); } - point+=QPointF(0.0, 42.0); - painter->drawPixmap(point+shiftD, KIcon("edit-delete").pixmap(32,32)); - point+=QPointF(0.0, 42.0); - painter->drawPixmap(point+shiftR, KIcon("transform-rotate").pixmap(32,32)); + point+=QPointF(0.0, ICON_SIZE + ICON_MARGIN); + painter->drawPixmap(point+shiftD, KIcon("edit-delete").pixmap(ICON_SIZE, ICON_SIZE)); + point+=QPointF(0.0, ICON_SIZE + ICON_MARGIN); + painter->drawPixmap(point+shiftR, KIcon("transform-rotate").pixmap(ICON_SIZE, ICON_SIZE)); painter->restore(); } @@ -156,35 +156,36 @@ AppletHandle::ButtonType AppletHandle::mapToButton(const QPointF &point) const QPointF basePoint = m_rect.topLeft(); if (m_buttonsOnRight) { - basePoint+= QPointF(m_rect.width()-52.0, 20.0); + basePoint+= QPointF(m_rect.width() - ICON_SIZE - ICON_MARGIN, HANDLE_WIDTH); } else { - basePoint+= QPointF(20.0, 20.0); + basePoint+= QPointF(HANDLE_WIDTH, HANDLE_WIDTH); } - QPolygonF activeArea = QPolygonF(QRectF(basePoint, QSizeF(32.0, 32.0))); + QPolygonF activeArea = QPolygonF(QRectF(basePoint, QSizeF(ICON_SIZE, ICON_SIZE))); if (activeArea.containsPoint(point, Qt::OddEvenFill)) { return MoveButton; } - if( m_applet->hasConfigurationInterface() ) { - activeArea.translate(QPointF(0.0, 42.0)); + if (m_applet->hasConfigurationInterface()) { + activeArea.translate(QPointF(0.0, ICON_SIZE + ICON_MARGIN)); if (activeArea.containsPoint(point, Qt::OddEvenFill)) { return ConfigureButton; } } - activeArea.translate(QPointF(0.0, 42.0)); + activeArea.translate(QPointF(0.0, ICON_SIZE + ICON_MARGIN)); if (activeArea.containsPoint(point, Qt::OddEvenFill)) { return RemoveButton; } - activeArea.translate(QPointF(0.0, 42.0)); + activeArea.translate(QPointF(0.0, ICON_SIZE + ICON_MARGIN)); if (activeArea.containsPoint(point, Qt::OddEvenFill)) { return RotateButton; } - return NoButton; + kDebug() << "base point is" << basePoint << "and applet is" << m_applet->mapToParent(m_applet->boundingRect()); + return m_applet->mapToParent(m_applet->shape()).contains(point) ? NoButton : MoveButton; } void AppletHandle::mousePressEvent(QGraphicsSceneMouseEvent *event) @@ -293,7 +294,7 @@ void AppletHandle::startFading(FadeType anim) Phase::self()->stopCustomAnimation(m_animId); } - qreal time = 500; + qreal time = 250; if (anim==FadeIn) { time *= 1.0-m_opacity; diff --git a/applethandle_p.h b/applethandle_p.h index 6342aa593..615536d4a 100644 --- a/applethandle_p.h +++ b/applethandle_p.h @@ -60,6 +60,10 @@ class AppletHandle : public QObject, public QGraphicsItem void fadeAnimation(qreal progress); private: + static const int HANDLE_WIDTH = 10; + static const int ICON_SIZE = 12; + static const int ICON_MARGIN = 6; + void startFading(FadeType anim); void forceDisappear(); ButtonType mapToButton(const QPointF &point) const;