From a166f48ccce0d624aed6a633053963f8f8db19f8 Mon Sep 17 00:00:00 2001 From: Percy Leonhardt Date: Fri, 23 Nov 2007 08:01:29 +0000 Subject: [PATCH] Support resizing of applet while handle is visible. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=740406 --- applethandle.cpp | 59 ++++++++++++++++++++++++++++-------------------- applethandle_p.h | 2 ++ containment.cpp | 2 ++ 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/applethandle.cpp b/applethandle.cpp index 3c0d7b925..0455d05f4 100644 --- a/applethandle.cpp +++ b/applethandle.cpp @@ -50,32 +50,9 @@ AppletHandle::AppletHandle(Containment *parent, Applet *applet) { KColorScheme colors(QPalette::Active, KColorScheme::View, Theme::self()->colors()); m_gradientColor = colors.background(KColorScheme::NormalBackground).color(); - m_originalMatrix = m_applet->transform(); - m_rect = m_applet->boundingRect(); - m_rect = m_applet->mapToParent(m_rect).boundingRect(); - - const int requiredHeight = (HANDLE_WIDTH * 2) + m_applet->hasConfigurationInterface() - ? ((ICON_SIZE + ICON_MARGIN) * 4) - : ((ICON_SIZE + ICON_MARGIN) * 3) - + ICON_MARGIN; // that last margin is blank space before the close button - if (m_rect.height() < requiredHeight) { - float delta = requiredHeight - m_rect.height(); - delta = delta/2.0; - if (delta > 0.0) { - m_rect.adjust(0.0, -delta, 0.0, delta); - } - } - - m_rect.adjust(-HANDLE_WIDTH, -HANDLE_WIDTH, HANDLE_WIDTH, HANDLE_WIDTH); - - if (m_applet->pos().x() <= ((HANDLE_WIDTH * 2) + ICON_SIZE)) { - m_rect.adjust(0.0, 0.0, ICON_SIZE, 0.0); - m_buttonsOnRight = true; - } else { - m_rect.adjust(- ICON_SIZE, 0.0, 0.0, 0.0); - } + calculateSize(); m_applet->setParentItem(this); connect(m_applet, SIGNAL(destroyed(QObject*)), this, SLOT(appletDestroyed())); setAcceptsHoverEvents(true); @@ -332,6 +309,13 @@ void AppletHandle::appletDestroyed() deleteLater(); } +void AppletHandle::appletResized() +{ + prepareGeometryChange(); + calculateSize(); + update(); +} + void AppletHandle::startFading(FadeType anim) { if (m_animId!=0) { @@ -358,6 +342,33 @@ void AppletHandle::forceDisappear() startFading(FadeOut); } +void AppletHandle::calculateSize() +{ + m_rect = m_applet->boundingRect(); + m_rect = m_applet->mapToParent(m_rect).boundingRect(); + + const int requiredHeight = (HANDLE_WIDTH * 2) + m_applet->hasConfigurationInterface() + ? ((ICON_SIZE + ICON_MARGIN) * 4) + : ((ICON_SIZE + ICON_MARGIN) * 3) + + ICON_MARGIN; // that last margin is blank space before the close button + if (m_rect.height() < requiredHeight) { + float delta = requiredHeight - m_rect.height(); + delta = delta/2.0; + if (delta > 0.0) { + m_rect.adjust(0.0, -delta, 0.0, delta); + } + } + + m_rect.adjust(-HANDLE_WIDTH, -HANDLE_WIDTH, HANDLE_WIDTH, HANDLE_WIDTH); + + if (m_applet->pos().x() <= ((HANDLE_WIDTH * 2) + ICON_SIZE)) { + m_rect.adjust(0.0, 0.0, ICON_SIZE, 0.0); + m_buttonsOnRight = true; + } else { + m_rect.adjust(- ICON_SIZE, 0.0, 0.0, 0.0); + } +} + } #include "applethandle_p.moc" diff --git a/applethandle_p.h b/applethandle_p.h index 6e0021b8b..e6ca2a167 100644 --- a/applethandle_p.h +++ b/applethandle_p.h @@ -59,6 +59,7 @@ class AppletHandle : public QObject, public QGraphicsItem private Q_SLOTS: void fadeAnimation(qreal progress); void appletDestroyed(); + void appletResized(); private: static const int HANDLE_WIDTH = 5; @@ -67,6 +68,7 @@ class AppletHandle : public QObject, public QGraphicsItem void startFading(FadeType anim); void forceDisappear(); + void calculateSize(); ButtonType mapToButton(const QPointF &point) const; QRectF m_rect; diff --git a/containment.cpp b/containment.cpp index fc1199d00..6eca42b00 100644 --- a/containment.cpp +++ b/containment.cpp @@ -613,6 +613,8 @@ bool Containment::sceneEventFilter(QGraphicsItem *watched, QEvent *event) d->handles[applet] = handle; connect(handle, SIGNAL(disappearDone(AppletHandle*)), this, SLOT(handleDisappeared(AppletHandle*))); + connect(applet, SIGNAL(geometryChanged()), + handle, SLOT(appletResized())); } break; default: