[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    [PATCH] Re: KToolbarButton popup delay (Re: Bug report and feature
From:       Waldo Bastian <bastian () kde ! org>
Date:       2003-05-17 11:37:23
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday 13 May 2003 10:22, Olaf Jan Schmidt wrote:
> Hi!
>
> There are even more bugs to ktoolbarbutton.cpp then the one analyzed by
> Gunnar.

The following patch removes most of the hairy bits and delegates them to  
QToolButton.

It also obsoletes the sticky/toggle flag for the popupmenu, I don't think it 
is needed anymore since the QToolButton implementation of popup-menus allows 
it automatically.

Please test.

Cheers,
Waldo
- -- 
SCO appears to have the same grasp of reality as the former 
Iraqi information minister (Matt Loney, ZDNet)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE+xh70N4pvrENfboIRAhEWAKCP54KIvuwszrKJd0PKNBbz3E0lDgCbB8no
zntMu+f09+qF/hx30tEhVaI=
=2BJ6
-----END PGP SIGNATURE-----

["ktoolbarbutton.patch" (text/x-diff)]

Index: ktoolbarbutton.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/ktoolbarbutton.cpp,v
retrieving revision 1.70
diff -u -r1.70 ktoolbarbutton.cpp
--- ktoolbarbutton.cpp	11 May 2003 23:54:36 -0000	1.70
+++ ktoolbarbutton.cpp	17 May 2003 11:32:50 -0000
@@ -57,8 +57,6 @@
   {
     m_noStyle     = false;
     m_isSeparator = false;
-    m_isPopup     = false;
-    m_isToggle    = false;
     m_isRadio     = false;
     m_highlight   = false;
     m_isRaised    = false;
@@ -67,21 +65,16 @@
     m_iconName    = QString::null;
     m_iconText    = KToolBar::IconOnly;
     m_iconSize    = 0;
-    m_delayTimer  = 0L;
-    m_popup       = 0L;
 
     m_instance = KGlobal::instance();
   }
   ~KToolBarButtonPrivate()
   {
-    delete m_delayTimer; m_delayTimer = 0;
   }
 
   int     m_id;
   bool    m_noStyle: 1;
   bool    m_isSeparator: 1;
-  bool    m_isPopup: 1;
-  bool    m_isToggle: 1;
   bool    m_isRadio: 1;
   bool    m_highlight: 1;
   bool    m_isRaised: 1;
@@ -93,10 +86,7 @@
   KToolBar::IconText m_iconText;
   int m_iconSize;
   QSize size;
-
-  QTimer     *m_delayTimer;
-  QPopupMenu *m_popup;
-
+  
   QPoint m_mousePressPos;
 
   KInstance  *m_instance;
@@ -349,30 +339,24 @@
   QToolButton::setIconSet( set );
 }
 
-void KToolBarButton::setPopup(QPopupMenu *p, bool toggle)
-{
-  d->m_popup = p;
-  d->m_isToggle  = toggle;
-  p->installEventFilter(this);
-}
-
 QPopupMenu *KToolBarButton::popup()
 {
-  return d->m_popup;
+  // obsolete
+  // KDE4: remove me
+  return QToolButton::popup();
 }
 
-void KToolBarButton::setDelayedPopup (QPopupMenu *p, bool toggle )
+void KToolBarButton::setPopup(QPopupMenu *p, bool)
 {
-  d->m_isPopup   = true;
+  QToolButton::setPopup(p);
+  QToolButton::setPopupDelay(0);
+}
 
-  if (!d->m_delayTimer)
-  {
-    d->m_delayTimer = new QTimer(this);
-    connect(d->m_delayTimer, SIGNAL(timeout()),
-           this,             SLOT(slotDelayTimeout()));
-  }
 
-  setPopup(p, toggle);
+void KToolBarButton::setDelayedPopup (QPopupMenu *p, bool)
+{
+  QToolButton::setPopup(p);
+  QToolButton::setPopupDelay(QApplication::startDragTime());
 }
 
 void KToolBarButton::leaveEvent(QEvent *)
@@ -384,9 +368,6 @@
     repaint(false);
   }
 
-  if (d->m_isPopup)
-    d->m_delayTimer->stop();
-
   emit highlighted(d->m_id, false);
 }
 
@@ -429,7 +410,7 @@
 
     // Popup the menu when the left mousebutton is pressed and the mouse
     // is moved by a small distance.
-    if (d->m_isPopup)
+    if (QToolButton::popup())
     {
       if (ev->type() == QEvent::MouseButtonPress)
       {
@@ -440,58 +421,16 @@
       if (ev->type() == QEvent::MouseMove)
       {
         QMouseEvent* mev = static_cast<QMouseEvent*>(ev);
-        if (d->m_delayTimer && d->m_delayTimer->isActive()
-         && (mev->pos() - d->m_mousePressPos).manhattanLength()
+        if ((mev->pos() - d->m_mousePressPos).manhattanLength()
               > KGlobalSettings::dndEventDelay())
-          slotDelayTimeout();
-      }
-    }
-  }
-
-  if ((QPopupMenu *) o != d->m_popup)
-    return false; // just in case
-
-  switch (ev->type())
-  {
-    case QEvent::MouseButtonDblClick:
-    case QEvent::MouseButtonPress:
-    {
-      // If I get this, it means that popup is visible
-      QRect r(geometry());
-      r.moveTopLeft(d->m_parent->mapToGlobal(pos()));
-      if (r.contains(QCursor::pos()))   // on button
-        return true; // ignore
-      break;
-    }
-
-    case QEvent::MouseButtonRelease:
-      if (!d->m_popup->geometry().contains(QCursor::pos())) // not in menu...
-      {
-        QRect r(geometry());
-        r.moveTopLeft(d->m_parent->mapToGlobal(pos()));
-
-        if (r.contains(QCursor::pos()))   // but on button
         {
-          if( !isToggleButton() )
-            d->m_popup->hide();        //Sven: proposed by Carsten Pfeiffer
-          // Make the button normal again :) Dawit A.
-          if( d->m_isToggle )
-            setToggle( false );
-          emit clicked( d->m_id );
-          return true;  // ignore release
+          openPopup();
+          return true;
         }
       }
-      if ( d->m_isToggle )
-        setToggle( false );  //Change the button to normal mode (DA)
-      break;
-
-    case QEvent::Hide:
-      on(false);
-      setDown(false);
-      return false;
-  default:
-      break;
+    }
   }
+
   return false;
 }
 
@@ -632,7 +571,7 @@
       _painter->drawText(textRect, textFlags, textLabel());
   }
 
-  if (d->m_popup)
+  if (QToolButton::popup())
   {
     QStyle::SFlags arrowFlags = QStyle::Style_Default;
 
@@ -656,67 +595,28 @@
 
 void KToolBarButton::showMenu()
 {
-  // calculate that position carefully!!
-  d->m_isRaised = true;
-  repaint (false);
-
-  QPoint p;
-  // Calculate position from the toolbar button, only if the button is in the toolbar !
-  // If we are in the overflow menu, use the mouse position (as Qt does)
-  bool bInToolbar = QRect( 0, 0, d->m_parent->width(), d->m_parent->height() ).intersects( \
                QRect( pos(), size() ) );
-  if (bInToolbar)
-  {
-    p = mapToGlobal( QPoint( 0, 0 ) );
-    if ( p.y() + height() + d->m_popup->sizeHint().height() > \
                KApplication::desktop()->height() )
-        p.setY( p.y() - d->m_popup->sizeHint().height() );
-    else
-        p.setY( p.y() + height( ));
-    if (QApplication::reverseLayout()) p.setX(p.x() -d->m_popup->sizeHint().width() + width() \
                );	
-  }
-  else
-    p = QCursor::pos();
-
-  if ( d->m_isToggle )
-      setToggle( true ); // Turns the button into a ToggleButton ...
-  d->m_popup->popup(p);
+  // obsolete
+  // KDE4: remove me
 }
 
 void KToolBarButton::slotDelayTimeout()
 {
-  d->m_delayTimer->stop();
-  showMenu();
+  // obsolete
+  // KDE4: remove me
 }
 
 void KToolBarButton::slotClicked()
 {
-  if (d->m_popup && !d->m_isPopup)
-    showMenu();
-  else
-    emit clicked( d->m_id );
+  emit clicked( d->m_id );
 }
 
 void KToolBarButton::slotPressed()
 {
-  if (d->m_popup)
-  {
-    if (d->m_isPopup)
-    {
-      d->m_delayTimer->stop(); // just in case?
-      d->m_delayTimer->start( QApplication::startDragTime() , true);
-      return;
-    }
-    else
-      showMenu();
-  }
-  else
-    emit pressed( d->m_id );
+  emit pressed( d->m_id );
 }
 
 void KToolBarButton::slotReleased()
 {
-  if (d->m_popup && d->m_isPopup)
-    d->m_delayTimer->stop();
-
   emit released( d->m_id );
 }
 
Index: ktoolbarbutton.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/ktoolbarbutton.h,v
retrieving revision 1.26
diff -u -r1.26 ktoolbarbutton.h
--- ktoolbarbutton.h	28 Sep 2002 15:16:22 -0000	1.26
+++ ktoolbarbutton.h	17 May 2003 11:32:50 -0000
@@ -211,32 +211,22 @@
   /**
    * Give this button a popup menu.  There will not be a delay when
    * you press the button.  Use @ref setDelayedPopup if you want that
-   * behavior. You can also make the popup-menu
-   * "sticky", i.e. visible until a selection is made or the mouse is
-   * clikced elsewhere, by simply setting the second argument to true.
-   * This "sticky" button feature allows you to make a selection without
-   * having to press and hold down the mouse while making a selection.
+   * behavior. 
    *
    * @param p The new popup menu
-   * @param toggle if true, makes the button "sticky" (toggled)
    */
-  void setPopup (QPopupMenu *p, bool toggle = false);
+  void setPopup (QPopupMenu *p, bool unused = false);
 
   /**
    * Gives this button a delayed popup menu.
    *
    * This function allows you to add a delayed popup menu to the button.
    * The popup menu is then only displayed when the button is pressed and
-   * held down for about half a second.  You can also make the popup-menu
-   * "sticky", i.e. visible until a selection is made or the mouse is
-   * clikced elsewhere, by simply setting the second argument to true.
-   * This "sticky" button feature allows you to make a selection without
-   * having to press and hold down the mouse while making a selection.
+   * held down for about half a second.
    *
    * @param p the new popup menu
-   * @param toggle if true, makes the button "sticky" (toggled)
    */
-  void setDelayedPopup(QPopupMenu *p, bool toggle = false);
+  void setDelayedPopup(QPopupMenu *p, bool unused = false);
 
   /**
    * Turn this button into a radio button



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic