Removed unnecessary mouseMoveEvent reimplementation from IndicatorButton class.
authorPekka Nissinen <pekka.nissinen@ixonos.com>
Fri, 20 Aug 2010 13:36:48 +0000 (16:36 +0300)
committerPekka Nissinen <pekka.nissinen@ixonos.com>
Fri, 20 Aug 2010 13:36:48 +0000 (16:36 +0300)
Simplified ImageButton class implementation and now the button is drawed correctly in toggled and disabled state.
Made small changes to ZoomButton & ZoomButtonPanel to reflect changes in ImageButton.

Reviewed by: Jussi Laitinen

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

index cade417..84fbb16 100644 (file)
@@ -20,6 +20,7 @@
 */
 
 #include <QDebug>
+#include <QMouseEvent>
 #include <QPainter>
 
 #include "imagebutton.h"
@@ -27,8 +28,7 @@
 ImageButton::ImageButton(const QString &normalIconPictureFileName,
                          const QString &selectedIconPictureFileName,
                          const QString &disabledIconPictureFileName, QWidget *parent)
-    : QPushButton(parent),
-      m_buttonMode(QIcon::Normal)
+    : QPushButton(parent)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -60,32 +60,6 @@ void ImageButton::setButtonIcon(const QPixmap &image)
     initButton(buttonSize, icon);
 }
 
-void ImageButton::mousePressEvent(QMouseEvent *event)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if(m_buttonMode != QIcon::Disabled) {
-        QPushButton::mousePressEvent(event);
-        setMode(QIcon::Selected);
-    } else {
-        setDown(true);
-        emit pressed();
-    }
-}
-
-void ImageButton::mouseReleaseEvent(QMouseEvent *event)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if(m_buttonMode != QIcon::Disabled) {
-        QPushButton::mouseReleaseEvent(event);
-        setMode(QIcon::Normal);
-    } else {
-        setDown(false);
-        emit released();
-    }
-}
-
 void ImageButton::paintEvent(QPaintEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -93,22 +67,17 @@ void ImageButton::paintEvent(QPaintEvent *event)
     Q_UNUSED(event);
 
     QPainter painter(this);
-    icon().paint(&painter, this->rect(), NULL, m_buttonMode);
-}
-
-void ImageButton::setMode(QIcon::Mode mode)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_buttonMode = mode;
-    update();
-}
-
-QIcon::Mode ImageButton::mode()
-{
-    qDebug() << __PRETTY_FUNCTION__;
 
-    return m_buttonMode;
+    if (isEnabled()) {
+        if (isChecked())
+            icon().paint(&painter, rect(), NULL, QIcon::Selected);
+        else if (isDown())
+            icon().paint(&painter, rect(), NULL, QIcon::Selected);
+        else
+            icon().paint(&painter, rect(), NULL, QIcon::Normal);
+    } else {
+        icon().paint(&painter, rect(), NULL, QIcon::Disabled);
+    }
 }
 
 void ImageButton::initButton(const QSize &size, const QIcon &icon)
index 1627e46..224532f 100644 (file)
@@ -51,20 +51,6 @@ public:
  ******************************************************************************/
 protected:
     /**
-     * @brief Event handler for mouse press events
-     *
-     * @param event Mouse event
-     */
-    void mousePressEvent(QMouseEvent *event);
-
-    /**
-     * @brief Event handler for mouse release events
-     *
-     * @param event Mouse event
-     */
-    void mouseReleaseEvent(QMouseEvent *event);
-
-    /**
      * @brief Event handler for paint events
      *
      * Paints the button and its icon
@@ -83,20 +69,6 @@ public:
      */
     void setButtonIcon(const QPixmap &image);
 
-    /**
-     * @brief Sets the button icon mode
-     *
-     * @param mode Button icon mode
-     */
-    void setMode(QIcon::Mode mode);
-
-    /**
-     * @brief Returns the current button icon mode
-     *
-     * @return Button icon mode
-     */
-    QIcon::Mode mode();
-
 private:
     /**
      * @brief Initializes the button by setting graphics and alpha mask
@@ -105,12 +77,6 @@ private:
      * @param icon Image icon
      */
     void initButton(const QSize &size, const QIcon &icon);
-
-/*******************************************************************************
- * DATA MEMBERS
- ******************************************************************************/
-protected:
-    QIcon::Mode m_buttonMode; ///< Button mode (Normal, Selected etc...)
 };
 
 #endif // IMAGEBUTTON_H
index d2a5fed..81bc7b2 100644 (file)
@@ -82,15 +82,6 @@ const QPoint& IndicatorButton::eventPosition()
     return m_eventPosition;
 }
 
-void IndicatorButton::mouseMoveEvent(QMouseEvent *event)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    QToolButton::mouseMoveEvent(event);
-
-    event->ignore();
-}
-
 void IndicatorButton::mousePressEvent(QMouseEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__;
index 4397aec..743370e 100644 (file)
@@ -57,13 +57,6 @@ public:
  ******************************************************************************/
 protected:
     /**
-     * @brief Event handler for mouse move events
-     *
-     * @param event Mouse event
-     */
-    void mouseMoveEvent(QMouseEvent *event);
-
-    /**
      * @brief Event handler for mouse press events
      *
      * @param event Mouse event
index addc02a..e5dfab9 100644 (file)
@@ -46,9 +46,9 @@ void ZoomButton::mousePressEvent(QMouseEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    ImageButton::mousePressEvent(event);
-
     m_eventPosition = mapToParent(event->pos());
+
+    ImageButton::mousePressEvent(event);
 }
 
 const QPoint& ZoomButton::eventPosition()
index 970b3cd..67dfba7 100644 (file)
@@ -160,14 +160,14 @@ void ZoomButtonPanel::paintEvent(QPaintEvent *event)
     }
 }
 
-const ZoomButton* ZoomButtonPanel::zoomInButton()
+const ZoomButton* ZoomButtonPanel::zoomInButton() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     return m_zoomInButton;
 }
 
-const ZoomButton* ZoomButtonPanel::zoomOutButton()
+const ZoomButton* ZoomButtonPanel::zoomOutButton() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -178,22 +178,22 @@ void ZoomButtonPanel::disableZoomInButton()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_zoomInButton->setMode(QIcon::Disabled);
+    m_zoomInButton->setEnabled(false);
 }
 
 void ZoomButtonPanel::disableZoomOutButton()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_zoomOutButton->setMode(QIcon::Disabled);
+    m_zoomOutButton->setEnabled(false);
 }
 
 void ZoomButtonPanel::resetButtons()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_zoomInButton->setMode(QIcon::Normal);
-    m_zoomOutButton->setMode(QIcon::Normal);
+    m_zoomInButton->setEnabled(true);
+    m_zoomOutButton->setEnabled(true);
 }
 
 void ZoomButtonPanel::setDraggable(bool mode, QPoint eventPosition)
@@ -205,29 +205,24 @@ void ZoomButtonPanel::setDraggable(bool mode, QPoint eventPosition)
     if(mode) {
         emit draggingModeTriggered();
 
-        m_zoomInMode = m_zoomInButton->mode();
-        m_zoomOutMode = m_zoomOutButton->mode();
-        m_zoomInButton->setMode(QIcon::Disabled);
-        m_zoomOutButton->setMode(QIcon::Disabled);
+        m_zoomInMode = m_zoomInButton->isEnabled();
+        m_zoomOutMode = m_zoomOutButton->isEnabled();
+
+        m_zoomInButton->setEnabled(false);
+        m_zoomOutButton->setEnabled(false);
 
         grabMouse();
 
         m_forceReleaseTimer->start();
         m_dragPosition = eventPosition;
     } else {
-        if(m_zoomInMode == QIcon::Selected)
-            m_zoomInButton->setMode(QIcon::Normal);
-        else
-            m_zoomInButton->setMode(m_zoomInMode);
-
-        if(m_zoomOutMode == QIcon::Selected)
-            m_zoomOutButton->setMode(QIcon::Normal);
-        else
-            m_zoomOutButton->setMode(m_zoomOutMode);
+        m_zoomInButton->setEnabled(m_zoomInMode);
+        m_zoomOutButton->setEnabled(m_zoomOutMode);
 
         releaseMouse();
 
         m_forceReleaseTimer->stop();
+
         m_zoomInButton->setDown(false);
         m_zoomOutButton->setDown(false);
     }
index 8165751..71fde69 100644 (file)
@@ -90,14 +90,14 @@ public:
      *
      * @return Pointer to the zoomInButton
      */
-    const ZoomButton* zoomInButton();
+    const ZoomButton* zoomInButton() const;
 
     /**
      * @brief Getter for the zoom out button
      *
      * @return Pointer to the zoomOutButton
      */
-    const ZoomButton* zoomOutButton();
+    const ZoomButton* zoomOutButton() const;
 
 public slots:
     /**
@@ -152,14 +152,13 @@ signals:
  ******************************************************************************/
 private:
     bool m_isDraggable;             ///< Boolean for tracking the draggability state
+    bool m_zoomInMode;              ///< Boolean for storing zoom in button mode before dragging
+    bool m_zoomOutMode;             ///< Boolean for storing zoom out button mode before dragging
 
     QGridLayout m_panelLayout;      ///< Panel layout
 
     QPoint m_dragPosition;          ///< Location from where the widget is grabbed
 
-    QIcon::Mode m_zoomInMode;       ///< Store for zoom in button mode before dragging
-    QIcon::Mode m_zoomOutMode;      ///< Store for zoom out button mode before dragging
-
     QSize m_screenSize;             ///< Store for the screen size
 
     QTimer *m_dragStartTimer;       ///< Timer to init draggability of the zoom panel