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

List:       kde-commits
Subject:    koffice/lib/kofficeui
From:       Martin Ellis <martin.ellis () kdemail ! net>
Date:       2005-08-28 16:38:16
Message-ID: 1125247096.459399.30335.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 454339 by martin:

Allow mouse wheel movement to select the next/previous
sheet in KSpread.

Unlike the buttons on the left of the sheet tabs, the
wheel movement actually changes the current sheet, rather
than just scroll the tab display.  This makes its behaviour
consistent with e.g. the tab bars in Konqueror, 
KDevelop, etc.



 M  +61 -2     kotabbar.cpp  
 M  +2 -1      kotabbar.h  


--- trunk/koffice/lib/kofficeui/kotabbar.cpp #454338:454339
@@ -83,12 +83,16 @@
     // this is the target position, it's 0 if no tab is dragged
     int targetTab;
 
+    // wheel movement since selected tab was last changed by the
+    // mouse wheel
+    int wheelDelta;
+
     // true if autoscroll is active
     bool autoScroll;
 
     // calculate the bounding rectangle for each visible tab
     void layoutTabs();
-    
+
     // reposition scroll buttons
     void layoutButtons();
 
@@ -104,6 +108,7 @@
 
     // update the enable/disable status of scroll buttons
     void updateButtons();
+
 };
 
 // built-in pixmap for scroll-first button
@@ -338,6 +343,7 @@
     d->lastTab = 0;
     d->activeTab = 0;
     d->targetTab = 0;
+    d->wheelDelta = 0;
     d->autoScroll = false;
     d->offset = 64;
 
@@ -712,7 +718,7 @@
 
     QPoint pos = ev->pos();
     if( !d->reverseLayout ) pos = pos - QPoint( d->offset,0 );
-    
+
     int tab = d->tabAt( pos ) + 1;
     if( ( tab > 0 ) && ( tab != d->activeTab ) )
     {
@@ -813,5 +819,58 @@
         emit doubleClicked();
 }
 
+void KoTabBar::wheelEvent( QWheelEvent * e )
+{
+  if ( d->tabs.count() == 0 )
+  {
+    erase();
+    return;
+  }
 
+  // Currently one wheel movement is a delta of 120.
+  // The 'unused' delta is stored for devices that allow
+  // a higher scrolling resolution.
+  // The delta required to move one tab is one wheel movement:
+  const int deltaRequired = 120;
+
+  d->wheelDelta += e->delta();
+  int tabDelta = - (d->wheelDelta / deltaRequired);
+  d->wheelDelta = d->wheelDelta % deltaRequired;
+  int numTabs = d->tabs.size();
+
+  if(d->activeTab + tabDelta > numTabs)
+  {
+    // Would take us past the last tab
+    d->activeTab = numTabs;
+  }
+  else if (d->activeTab + tabDelta < 1)
+  {
+    // Would take us before the first tab
+    d->activeTab = 1;
+  }
+  else
+  {
+    d->activeTab = d->activeTab + tabDelta;
+  }
+
+  // Find the left and right edge of the new tab.  If we're
+  // going forward, and the right of the new tab isn't visible
+  // then scroll forward.  Likewise, if going back, and the 
+  // left of the new tab isn't visible, then scroll back.
+  int activeTabRight = d->tabRects[ d->activeTab-1 ].right();
+  int activeTabLeft  = d->tabRects[ d->activeTab-1 ].left();
+  if(tabDelta > 0 && activeTabRight > width() - d->offset )
+  {
+    scrollForward();
+  }
+  else if(tabDelta < 0 && activeTabLeft < width() - d->offset )
+  {
+    scrollBack();
+  }
+
+  update();
+  emit tabChanged( d->tabs[ d->activeTab-1] );
+}
+
+
 #include "kotabbar.moc"
--- trunk/koffice/lib/kofficeui/kotabbar.h #454338:454339
@@ -255,7 +255,8 @@
     virtual void mousePressEvent ( QMouseEvent* ev );
     virtual void mouseReleaseEvent ( QMouseEvent* ev );
     virtual void mouseDoubleClickEvent ( QMouseEvent* ev );
-    virtual void mouseMoveEvent( QMouseEvent* ev );
+    virtual void mouseMoveEvent ( QMouseEvent* ev );
+    virtual void wheelEvent ( QWheelEvent * e );
 
 private:
     KoTabBarPrivate *d;
[prev in list] [next in list] [prev in thread] [next in thread] 

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