Fixed faulty release logic for ZoomButtonPanel
authorKaj Wallin <kaj.wallin@ixonos.com>
Wed, 26 May 2010 10:30:38 +0000 (13:30 +0300)
committerKaj Wallin <kaj.wallin@ixonos.com>
Wed, 26 May 2010 10:30:38 +0000 (13:30 +0300)
Reviewed by:

src/ui/zoombutton.cpp
src/ui/zoombuttonpanel.cpp
src/ui/zoombuttonpanel.h

index ee0e629..dbfc6b3 100644 (file)
@@ -33,6 +33,9 @@ ZoomButton::ZoomButton(QWidget *parent, QString normalIconPictureFileName,
 
 void ZoomButton::mouseMoveEvent(QMouseEvent *event)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+    //qWarning() << "ZB release";
+
     if(this->rect().contains(event->pos())) {
         m_eventPosition = mapToParent(event->pos());
         emit eventPosition(m_eventPosition);
@@ -49,7 +52,6 @@ void ZoomButton::mousePressEvent(QMouseEvent *event)
 
     ImageButton::mousePressEvent(event);
 
-
     m_eventPosition = mapToParent(event->pos());
 
     emit pressEvent();
index ab5aed0..c012710 100644 (file)
@@ -88,27 +88,34 @@ ZoomButtonPanel::ZoomButtonPanel(QWidget *parent, int x, int y)
 void ZoomButtonPanel::mouseMoveEvent(QMouseEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__;
-
-    if(m_isDraggable) {
-        if (event->buttons() & Qt::LeftButton) {
-            QPoint newLocation = mapToParent(event->pos()) - m_dragPosition;
-
-            if (newLocation.x() < SIDEBAR_WIDTH)
-                newLocation.rx() = SIDEBAR_WIDTH;
-            else if (newLocation.x() > m_screenSize.width() - m_eventBlocker->width())
-                newLocation.rx() =  m_screenSize.width() - m_eventBlocker->width();
-
-            if (newLocation.y() < 0)
-                newLocation.ry() = 0;
-            else if (newLocation.y() > m_screenSize.height() - m_eventBlocker->height())
-                newLocation.ry() = m_screenSize.height() - m_eventBlocker->height();
-
-            move(newLocation);
-            event->accept();
+    if(this->rect().contains(event->pos())) {
+        if(m_isDraggable) {
+            if (event->buttons() & Qt::LeftButton) {
+                QPoint newLocation = mapToParent(event->pos()) - m_dragPosition;
+
+                if (newLocation.x() < SIDEBAR_WIDTH)
+                    newLocation.rx() = SIDEBAR_WIDTH;
+                else if (newLocation.x() > m_screenSize.width() - m_eventBlocker->width())
+                    newLocation.rx() =  m_screenSize.width() - m_eventBlocker->width();
+
+                if (newLocation.y() < 0)
+                    newLocation.ry() = 0;
+                else if (newLocation.y() > m_screenSize.height() - m_eventBlocker->height())
+                    newLocation.ry() = m_screenSize.height() - m_eventBlocker->height();
+
+                move(newLocation);
+                event->accept();
+            }
+        }
+        else {
+            m_dragPosition = event->pos();
         }
     }
     else {
-        m_dragPosition = event->pos();
+        if(m_isDraggable)
+            mouseReleaseEvent(event);
+        else
+            m_dragStartTimer->stop();
     }
 
 }
@@ -126,22 +133,25 @@ void ZoomButtonPanel::mousePressEvent(QMouseEvent *event)
 
 void ZoomButtonPanel::mouseReleaseEvent(QMouseEvent *event)
 {
+    qDebug() << __PRETTY_FUNCTION__;
     Q_UNUSED(event);
-    setDraggable(false);
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
-    settings.setValue(ZOOMPANEL_POSITION, pos());
-    releaseMouse();
-    m_dragStartTimer->stop();
+    if(m_isDraggable) {
+        setDraggable(false);
+        QSettings settings(DIRECTORY_NAME, FILE_NAME);
+        settings.setValue(ZOOMPANEL_POSITION, pos());
+        releaseMouse();
+        m_dragStartTimer->stop();
+    }
 }
 
-const ImageButton* ZoomButtonPanel::zoomInButton()
+const ZoomButton* ZoomButtonPanel::zoomInButton()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     return m_zoomInButton;
 }
 
-const ImageButton* ZoomButtonPanel::zoomOutButton()
+const ZoomButton* ZoomButtonPanel::zoomOutButton()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -172,6 +182,8 @@ void ZoomButtonPanel::resetButtons()
 
 void ZoomButtonPanel::setDraggable(bool mode, QPoint eventPosition)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     if(mode == true) {
         m_eventBlocker->setAttribute(Qt::WA_TransparentForMouseEvents, false);
         m_isDraggable = mode;
@@ -205,15 +217,21 @@ void ZoomButtonPanel::setDraggable(bool mode, QPoint eventPosition)
 
 void ZoomButtonPanel::screenResized(const QSize &size)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     m_screenSize = size;
 }
 
 void ZoomButtonPanel::setDragPosition(QPoint eventPosition)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     m_dragPosition = eventPosition;
 }
 
 void ZoomButtonPanel::timerExpired()
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     setDraggable(true, m_dragPosition);
 }
index 715c231..962c4af 100644 (file)
@@ -83,14 +83,14 @@ public:
     *
     * @return Pointer to the zoomInButton
     */
-    const ImageButton* zoomInButton();
+    const ZoomButton* zoomInButton();
 
     /**
     * @brief Getter for the zoom out button
     *
     * @return Pointer to the zoomOutButton
     */
-    const ImageButton* zoomOutButton();
+    const ZoomButton* zoomOutButton();
 
 public slots:
     /**