Diff of /trunk/KDE/kdebase/apps/konsole/src/TerminalDisplay.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 786779 by knight, Sun Mar 9 15:28:19 2008 UTC Revision 786780 by knight, Mon Mar 17 22:21:34 2008 UTC
# Line 2101  void TerminalDisplay::mouseDoubleClickEv Line 2101  void TerminalDisplay::mouseDoubleClickEv
2101                       SLOT(tripleClickTimeout()));                       SLOT(tripleClickTimeout()));
2102  }  }
2103    
2104    bool TerminalDisplay::canScroll() const
2105    {
2106            bool sliderAtTop = _scrollBar->value() == 0;
2107            bool sliderAtBottom = _scrollBar->value() + _scrollBar->pageStep() >= _scrollBar->maximum();
2108    
2109            return !(sliderAtTop && sliderAtBottom);
2110    }
2111  void TerminalDisplay::wheelEvent( QWheelEvent* ev )  void TerminalDisplay::wheelEvent( QWheelEvent* ev )
2112  {  {
2113    if (ev->orientation() != Qt::Vertical)    if (ev->orientation() != Qt::Vertical)
2114      return;      return;
2115    
2116      // if the terminal program is not interested mouse events
2117      // then send the event to the scrollbar if the slider has room to move
2118      // or otherwise send simulated up / down key presses to the terminal program
2119      // for the benefit of programs such as 'less'
2120    if ( _mouseMarks )    if ( _mouseMarks )
2121      _scrollBar->event(ev);    {
2122            if (canScroll())
2123            _scrollBar->event(ev);
2124            else
2125            {
2126                    // assume that each Up / Down key event will cause the terminal application
2127                    // to scroll by one line.  
2128                    //
2129                    // to get a reasonable scrolling speed, scroll by one line for every 5 degrees
2130                    // of mouse wheel rotation.  Mouse wheels typically move in steps of 15 degrees,
2131                    // giving a scroll of 3 lines
2132                    int key = ev->delta() > 0 ? Qt::Key_Up : Qt::Key_Down;
2133    
2134                    // QWheelEvent::delta() gives rotation in eighths of a degree
2135                    int wheelDegrees = ev->delta() / 8;
2136                    int linesToScroll = abs(wheelDegrees) / 5;
2137    
2138                    QKeyEvent keyScrollEvent(QEvent::KeyPress,key,Qt::NoModifier);
2139    
2140                    for (int i=0;i<linesToScroll;i++)
2141                            emit keyPressedSignal(&keyScrollEvent);
2142            }
2143      }
2144    else    else
2145    {    {
2146            // terminal program wants notification of mouse activity
2147            
2148      int charLine;      int charLine;
2149      int charColumn;      int charColumn;
2150      getCharacterPosition( ev->pos() , charLine , charColumn );      getCharacterPosition( ev->pos() , charLine , charColumn );


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters