diff options
author | Darrell Anderson <humanreadable@yahoo.com> | 2012-10-19 22:51:12 -0500 |
---|---|---|
committer | Darrell Anderson <humanreadable@yahoo.com> | 2012-10-19 22:51:12 -0500 |
commit | f175db0cdb14fe5e62b3fbdc785cd3b09576ef1d (patch) | |
tree | 8b690a0a04d4143e087324a425621cd12b38d8f1 /src/widgets | |
parent | 41e5b784ee48d2cb403bb551bcbe7cbd322c4336 (diff) | |
parent | 4037eb7e84eda2b72a456cf7ff19182c2d4a1f7a (diff) | |
download | qt3-f175db0cdb14fe5e62b3fbdc785cd3b09576ef1d.tar.gz qt3-f175db0cdb14fe5e62b3fbdc785cd3b09576ef1d.zip |
Merge branch 'master' of http://scm.trinitydesktop.org/scm/git/qt3
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/qcombobox.cpp | 2 | ||||
-rw-r--r-- | src/widgets/qprogressbar.cpp | 2 | ||||
-rw-r--r-- | src/widgets/qpushbutton.cpp | 2 | ||||
-rw-r--r-- | src/widgets/qscrollbar.cpp | 2 | ||||
-rw-r--r-- | src/widgets/qslider.cpp | 5 | ||||
-rw-r--r-- | src/widgets/qspinwidget.cpp | 2 | ||||
-rw-r--r-- | src/widgets/qsplitter.cpp | 8 | ||||
-rw-r--r-- | src/widgets/qtabbar.cpp | 237 | ||||
-rw-r--r-- | src/widgets/qtabbar.h | 10 | ||||
-rw-r--r-- | src/widgets/qtextedit.cpp | 2 | ||||
-rw-r--r-- | src/widgets/qtoolbutton.cpp | 2 |
11 files changed, 176 insertions, 98 deletions
diff --git a/src/widgets/qcombobox.cpp b/src/widgets/qcombobox.cpp index 1da559c..2e5d56d 100644 --- a/src/widgets/qcombobox.cpp +++ b/src/widgets/qcombobox.cpp @@ -1244,6 +1244,8 @@ void QComboBox::paintEvent( QPaintEvent * ) flags |= QStyle::Style_Enabled; if (hasFocus()) flags |= QStyle::Style_HasFocus; + if (hasMouse()) + flags |= QStyle::Style_MouseOver; if ( width() < 5 || height() < 5 ) { qDrawShadePanel( &p, rect(), g, FALSE, 2, diff --git a/src/widgets/qprogressbar.cpp b/src/widgets/qprogressbar.cpp index a64ea8c..3d0f403 100644 --- a/src/widgets/qprogressbar.cpp +++ b/src/widgets/qprogressbar.cpp @@ -390,6 +390,8 @@ void QProgressBar::drawContents( QPainter *p ) flags |= QStyle::Style_Enabled; if (hasFocus()) flags |= QStyle::Style_HasFocus; + if (hasMouse()) + flags |= QStyle::Style_MouseOver; style().drawControl(QStyle::CE_ProgressBarGroove, buffer.painter(), this, QStyle::visualRect(style().subRect(QStyle::SR_ProgressBarGroove, this), this ), diff --git a/src/widgets/qpushbutton.cpp b/src/widgets/qpushbutton.cpp index e3db3f7..36e0ace 100644 --- a/src/widgets/qpushbutton.cpp +++ b/src/widgets/qpushbutton.cpp @@ -555,6 +555,8 @@ void QPushButton::drawButton( QPainter *paint ) flags |= QStyle::Style_Raised; if (isDefault()) flags |= QStyle::Style_ButtonDefault; + if (hasMouse()) + flags |= QStyle::Style_MouseOver; style().drawControl(QStyle::CE_PushButton, paint, this, rect(), colorGroup(), flags); drawButtonLabel( paint ); diff --git a/src/widgets/qscrollbar.cpp b/src/widgets/qscrollbar.cpp index 5ffe7e9..23abedd 100644 --- a/src/widgets/qscrollbar.cpp +++ b/src/widgets/qscrollbar.cpp @@ -940,6 +940,8 @@ void QScrollBar::drawControls( uint controls, uint activeControl, flags |= QStyle::Style_Enabled; if (hasFocus()) flags |= QStyle::Style_HasFocus; + if (hasMouse()) + flags |= QStyle::Style_MouseOver; if ( orientation() == Horizontal ) flags |= QStyle::Style_Horizontal; diff --git a/src/widgets/qslider.cpp b/src/widgets/qslider.cpp index f190f4f..6e92de4 100644 --- a/src/widgets/qslider.cpp +++ b/src/widgets/qslider.cpp @@ -415,10 +415,13 @@ void QSlider::paintEvent( QPaintEvent * ) flags |= QStyle::Style_Enabled; if (hasFocus()) flags |= QStyle::Style_HasFocus; + if (hasMouse()) + flags |= QStyle::Style_MouseOver; QStyle::SCFlags sub = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle; - if ( tickmarks() != NoMarks ) + if ( tickmarks() != NoMarks ) { sub |= QStyle::SC_SliderTickmarks; + } style().drawComplexControl( QStyle::CC_Slider, &p, this, rect(), colorGroup(), flags, sub, state == Dragging ? QStyle::SC_SliderHandle : QStyle::SC_None ); diff --git a/src/widgets/qspinwidget.cpp b/src/widgets/qspinwidget.cpp index 30cf05e..864a76c 100644 --- a/src/widgets/qspinwidget.cpp +++ b/src/widgets/qspinwidget.cpp @@ -323,6 +323,8 @@ void QSpinWidget::paintEvent( QPaintEvent * ) QStyle::SFlags flags = QStyle::Style_Default; if (isEnabled()) flags |= QStyle::Style_Enabled; + if (hasMouse()) + flags |= QStyle::Style_MouseOver; if (hasFocus() || (focusProxy() && focusProxy()->hasFocus())) flags |= QStyle::Style_HasFocus; diff --git a/src/widgets/qsplitter.cpp b/src/widgets/qsplitter.cpp index 407441f..f97393c 100644 --- a/src/widgets/qsplitter.cpp +++ b/src/widgets/qsplitter.cpp @@ -141,11 +141,15 @@ void QSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) void QSplitterHandle::paintEvent( QPaintEvent * ) { + QStyle::SFlags flags = (orientation() == Horizontal ? QStyle::Style_Horizontal : 0); + if (hasMouse()) { + flags |= QStyle::Style_MouseOver; + } + QPainter p( this ); parentWidget()->style().drawPrimitive( QStyle::PE_Splitter, &p, rect(), colorGroup(), - (orientation() == Horizontal ? - QStyle::Style_Horizontal : 0) ); + flags ); } QCOORD QSplitterLayoutStruct::getSizer( Orientation orient ) diff --git a/src/widgets/qtabbar.cpp b/src/widgets/qtabbar.cpp index 383285d..ab4d33b 100644 --- a/src/widgets/qtabbar.cpp +++ b/src/widgets/qtabbar.cpp @@ -335,7 +335,7 @@ private: */ QTabBar::QTabBar( QWidget * parent, const char *name ) - : QWidget( parent, name, WNoAutoErase | WNoMousePropagation ), l(NULL) + : QWidget( parent, name, WNoAutoErase | WNoMousePropagation ), l(NULL), hoverTab( 0 ) { d = new QTabPrivate; d->pressed = 0; @@ -581,45 +581,49 @@ QSize QTabBar::minimumSizeHint() const void QTabBar::paint( QPainter * p, QTab * t, bool selected ) const { - QStyle::SFlags flags = QStyle::Style_Default; - - if (isEnabled() && t->isEnabled()) - flags |= QStyle::Style_Enabled; - if (topLevelWidget() == qApp->activeWindow()) - flags |= QStyle::Style_Active; - if ( selected ) - flags |= QStyle::Style_Selected; - else if(t == d->pressed) - flags |= QStyle::Style_Sunken; - //selection flags - if(t->rect().contains(mapFromGlobal(QCursor::pos()))) - flags |= QStyle::Style_MouseOver; - style().drawControl( QStyle::CE_TabBarTab, p, this, t->rect(), - colorGroup(), flags, QStyleOption(t) ); - - QRect r( t->r ); - p->setFont( font() ); - - int iw = 0; - int ih = 0; - if ( t->iconset != 0 ) { - iw = t->iconset->pixmap( QIconSet::Small, QIconSet::Normal ).width() + 4; - ih = t->iconset->pixmap( QIconSet::Small, QIconSet::Normal ).height(); - } - QFontMetrics fm = p->fontMetrics(); - int fw = fm.width( t->label ); - fw -= t->label.contains('&') * fm.width('&'); - fw += t->label.contains("&&") * fm.width('&'); - int w = iw + fw + 4; - int h = QMAX(fm.height() + 4, ih ); - int offset = 3; + QStyle::SFlags flags = QStyle::Style_Default; + + if (isEnabled() && t->isEnabled()) { + flags |= QStyle::Style_Enabled; + } + if (topLevelWidget() == qApp->activeWindow()) { + flags |= QStyle::Style_Active; + } + if ( selected ) { + flags |= QStyle::Style_Selected; + } + else if (t == d->pressed) { + flags |= QStyle::Style_Sunken; + } + + //selection flags + if (t->rect().contains(mapFromGlobal(QCursor::pos()))) { + flags |= QStyle::Style_MouseOver; + } + style().drawControl( QStyle::CE_TabBarTab, p, this, t->rect(), colorGroup(), flags, QStyleOption(t, hoverTab) ); + + QRect r( t->r ); + p->setFont( font() ); + + int iw = 0; + int ih = 0; + if ( t->iconset != 0 ) { + iw = t->iconset->pixmap( QIconSet::Small, QIconSet::Normal ).width() + 4; + ih = t->iconset->pixmap( QIconSet::Small, QIconSet::Normal ).height(); + } + QFontMetrics fm = p->fontMetrics(); + int fw = fm.width( t->label ); + fw -= t->label.contains('&') * fm.width('&'); + fw += t->label.contains("&&") * fm.width('&'); + int w = iw + fw + 4; + int h = QMAX(fm.height() + 4, ih ); + int offset = 3; #ifdef Q_WS_MAC - if (::qt_cast<QMacStyle *>(&style())) - offset = 0; + if (::qt_cast<QMacStyle *>(&style())) { + offset = 0; + } #endif - paintLabel( p, QRect( r.left() + (r.width()-w)/2 - offset, - r.top() + (r.height()-h)/2, - w, h ), t, t->id == keyboardFocusTab() ); + paintLabel( p, QRect( r.left() + (r.width()-w)/2 - offset, r.top() + (r.height()-h)/2, w, h ), t, t->id == keyboardFocusTab() ); } /*! @@ -630,43 +634,48 @@ void QTabBar::paint( QPainter * p, QTab * t, bool selected ) const void QTabBar::paintLabel( QPainter* p, const QRect& br, QTab* t, bool has_focus ) const { - QRect r = br; - bool selected = currentTab() == t->id; - if ( t->iconset) { - // the tab has an iconset, draw it in the right mode - QIconSet::Mode mode = (t->enabled && isEnabled()) - ? QIconSet::Normal : QIconSet::Disabled; - if ( mode == QIconSet::Normal && has_focus ) - mode = QIconSet::Active; - QPixmap pixmap = t->iconset->pixmap( QIconSet::Small, mode ); - int pixw = pixmap.width(); - int pixh = pixmap.height(); - r.setLeft( r.left() + pixw + 4 ); - r.setRight( r.right() + 2 ); - - int xoff = 0, yoff = 0; - if(!selected) { - xoff = style().pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, this); - yoff = style().pixelMetric(QStyle::PM_TabBarTabShiftVertical, this); + QRect r = br; + bool selected = currentTab() == t->id; + if ( t->iconset) { + // the tab has an iconset, draw it in the right mode + QIconSet::Mode mode = (t->enabled && isEnabled()) + ? QIconSet::Normal : QIconSet::Disabled; + if ( mode == QIconSet::Normal && has_focus ) + mode = QIconSet::Active; + QPixmap pixmap = t->iconset->pixmap( QIconSet::Small, mode ); + int pixw = pixmap.width(); + int pixh = pixmap.height(); + r.setLeft( r.left() + pixw + 4 ); + r.setRight( r.right() + 2 ); + + int xoff = 0, yoff = 0; + if(!selected) { + xoff = style().pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, this); + yoff = style().pixelMetric(QStyle::PM_TabBarTabShiftVertical, this); + } + p->drawPixmap( br.left() + 2 + xoff, br.center().y()-pixh/2 + yoff, pixmap ); } - p->drawPixmap( br.left() + 2 + xoff, br.center().y()-pixh/2 + yoff, pixmap ); - } - QStyle::SFlags flags = QStyle::Style_Default; - - if (isEnabled() && t->isEnabled()) - flags |= QStyle::Style_Enabled; - if (has_focus) - flags |= QStyle::Style_HasFocus; - if ( selected ) - flags |= QStyle::Style_Selected; - else if(t == d->pressed) - flags |= QStyle::Style_Sunken; - if(t->rect().contains(mapFromGlobal(QCursor::pos()))) - flags |= QStyle::Style_MouseOver; - style().drawControl( QStyle::CE_TabBarLabel, p, this, r, - t->isEnabled() ? colorGroup(): palette().disabled(), - flags, QStyleOption(t) ); + QStyle::SFlags flags = QStyle::Style_Default; + + if (isEnabled() && t->isEnabled()) { + flags |= QStyle::Style_Enabled; + } + if (has_focus) { + flags |= QStyle::Style_HasFocus; + } + if ( selected ) { + flags |= QStyle::Style_Selected; + } + else if(t == d->pressed) { + flags |= QStyle::Style_Sunken; + } + if(t->rect().contains(mapFromGlobal(QCursor::pos()))) { + flags |= QStyle::Style_MouseOver; + } + style().drawControl( QStyle::CE_TabBarLabel, p, this, r, + t->isEnabled() ? colorGroup(): palette().disabled(), + flags, QStyleOption(t, hoverTab) ); } @@ -689,8 +698,9 @@ void QTabBar::paintEvent( QPaintEvent * e ) t = l->first(); do { QTab * n = l->next(); - if ( t && t->r.intersects( e->rect() ) ) + if ( t && t->r.intersects( e->rect() ) ) { paint( buffer.painter(), t, n == 0 ); + } t = n; } while ( t != 0 ); @@ -776,19 +786,38 @@ void QTabBar::mousePressEvent( QMouseEvent * e ) void QTabBar::mouseMoveEvent ( QMouseEvent *e ) { - if ( e->state() != LeftButton ) { - e->ignore(); - return; - } - if(style().styleHint( QStyle::SH_TabBar_SelectMouseType, this ) == QEvent::MouseButtonRelease) { QTab *t = selectTab( e->pos() ); - if(t != d->pressed) { - if(d->pressed) - repaint(d->pressed->rect(), FALSE); - if((d->pressed = t)) - repaint(t->rect(), FALSE); + + // Repaint hover indicator(s) + // Also, avoid unnecessary repaints which otherwise would occour on every MouseMove event causing high cpu load + bool forceRepaint = true; + if (hoverTab == t) { + forceRepaint = false; + } + hoverTab = t; + if (forceRepaint) { + repaint(false); + } + + if ( e->state() != LeftButton ) { + e->ignore(); + return; + } + + if(style().styleHint( QStyle::SH_TabBar_SelectMouseType, this ) == QEvent::MouseButtonRelease) { + if(t != d->pressed) { + if (d->pressed) { + if (!forceRepaint) { + repaint(d->pressed->rect(), FALSE); + } + } + if ((d->pressed = t)) { + if (!forceRepaint) { + repaint(t->rect(), FALSE); + } + } + } } - } } /*! @@ -797,16 +826,28 @@ void QTabBar::mouseMoveEvent ( QMouseEvent *e ) void QTabBar::mouseReleaseEvent( QMouseEvent *e ) { - if ( e->button() != LeftButton ) - e->ignore(); - if(d->pressed) { - QTab *t = selectTab( e->pos() ) == d->pressed ? d->pressed : 0; - d->pressed = 0; - if(t && t->enabled && e->type() == style().styleHint( QStyle::SH_TabBar_SelectMouseType, this )) - setCurrentTab( t ); - } + if (e->button() != LeftButton) { + e->ignore(); + } + + if (d->pressed) { + QTab *t = selectTab( e->pos() ) == d->pressed ? d->pressed : 0; + d->pressed = 0; + if(t && t->enabled && e->type() == style().styleHint( QStyle::SH_TabBar_SelectMouseType, this )) { + setCurrentTab( t ); + } + } } +void QTabBar::enterEvent( QEvent * ) +{ + hoverTab = 0; +} + +void QTabBar::leaveEvent( QEvent * ) +{ + hoverTab = 0; +} /*! \reimp @@ -1119,7 +1160,7 @@ void QTabBar::layoutTabs() h += vframe; t->r = QRect(QPoint(x, 0), style().sizeFromContents(QStyle::CT_TabBarTab, this, QSize( QMAX( lw + hframe + iw, QApplication::globalStrut().width() ), h ), - QStyleOption(t) )); + QStyleOption(t, hoverTab) )); x += t->r.width() - overlap; r = r.unite( t->r ); if ( reverse ) @@ -1375,4 +1416,12 @@ void QTabBar::fontChange( const QFont & oldFont ) QWidget::fontChange( oldFont ); } +/*! + Returns the tab currently under the mouse pointer, or NULL if no tab is under the cursor +*/ +QTab *QTabBar::mouseHoverTab() const +{ + return hoverTab; +} + #endif diff --git a/src/widgets/qtabbar.h b/src/widgets/qtabbar.h index 063f34a..b87d13b 100644 --- a/src/widgets/qtabbar.h +++ b/src/widgets/qtabbar.h @@ -178,6 +178,16 @@ private: // Disabled copy constructor and operator= QTabBar( const QTabBar & ); QTabBar& operator=( const QTabBar & ); #endif + +protected: + void enterEvent ( QEvent * ); + void leaveEvent ( QEvent * ); + +private: + QTab *hoverTab; + +public: + QTab *mouseHoverTab() const; }; diff --git a/src/widgets/qtextedit.cpp b/src/widgets/qtextedit.cpp index 8559bf1..2171e75 100644 --- a/src/widgets/qtextedit.cpp +++ b/src/widgets/qtextedit.cpp @@ -1123,7 +1123,7 @@ bool QTextEdit::event( QEvent *e ) { if ( e->type() == QEvent::AccelOverride && !isReadOnly() ) { QKeyEvent* ke = (QKeyEvent*) e; - switch(ke->state()) { + switch((int)(ke->state())) { case NoButton: case Keypad: case ShiftButton: diff --git a/src/widgets/qtoolbutton.cpp b/src/widgets/qtoolbutton.cpp index f11b613..d121d61 100644 --- a/src/widgets/qtoolbutton.cpp +++ b/src/widgets/qtoolbutton.cpp @@ -484,6 +484,8 @@ void QToolButton::drawButton( QPainter * p ) flags |= QStyle::Style_Down; if (isOn()) flags |= QStyle::Style_On; + if (hasMouse()) + flags |= QStyle::Style_MouseOver; if (autoRaise()) { flags |= QStyle::Style_AutoRaise; if (uses3D()) { |