summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-10-16 15:39:47 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-10-16 15:39:47 -0500
commitf209ff4b488f2ea3fa39bbed57dbbb8fe0162a3b (patch)
treeb046beab59eda48afdbdb4ee3e9ae60881114b87
parent4f8eb0410d666d41ccbc39b2bf5dea336af5c26c (diff)
downloadqt3-f209ff4b.tar.gz
qt3-f209ff4b.zip
Move hover widget code into the Qt core instead of the styles
This more closely matches other widget toolkits such as GTK
-rw-r--r--src/kernel/qapplication.cpp37
-rw-r--r--src/kernel/qstyle.h35
-rw-r--r--src/styles/qcommonstyle.cpp1
-rw-r--r--src/styles/qmotifplusstyle.cpp31
-rw-r--r--src/widgets/qcombobox.cpp2
-rw-r--r--src/widgets/qprogressbar.cpp2
-rw-r--r--src/widgets/qpushbutton.cpp2
-rw-r--r--src/widgets/qscrollbar.cpp2
-rw-r--r--src/widgets/qslider.cpp5
-rw-r--r--src/widgets/qspinwidget.cpp2
-rw-r--r--src/widgets/qsplitter.cpp8
-rw-r--r--src/widgets/qtabbar.cpp237
-rw-r--r--src/widgets/qtabbar.h10
-rw-r--r--src/widgets/qtextedit.cpp2
-rw-r--r--src/widgets/qtoolbutton.cpp2
15 files changed, 239 insertions, 139 deletions
diff --git a/src/kernel/qapplication.cpp b/src/kernel/qapplication.cpp
index 7296f4c..0478cf1 100644
--- a/src/kernel/qapplication.cpp
+++ b/src/kernel/qapplication.cpp
@@ -2557,6 +2557,21 @@ bool QApplication::event( QEvent *e )
return QObject::event(e);
}
+#define HOVER_SENSITIVE_WIDGET_SELECT if ( widget->inherits("QPushButton") \
+ || widget->inherits("QComboBox") \
+ || widget->inherits("QSpinWidget") \
+ || widget->inherits("QCheckBox") \
+ || widget->inherits("QRadioButton") \
+ || widget->inherits("QToolButton") \
+ || widget->inherits("QSlider") \
+ || widget->inherits("QScrollBar") \
+ || widget->inherits("QTabBar") \
+ || widget->inherits("QDockWindowHandle") \
+ || widget->inherits("QSplitterHandle") )
+
+#define FOCUS_SENSITIVE_WIDGET_SELECT if ( widget->inherits("QLineEdit") )
+#define FOCUS_SENSITIVE_PARENT_WIDGET_SELECT if ( widget->parentWidget() && widget->parentWidget()->inherits("QSpinWidget") )
+
/*!\internal
Helper function called by notify()
@@ -2579,10 +2594,28 @@ bool QApplication::internalNotify( QObject *receiver, QEvent * e)
QWidget *widget = (QWidget*)receiver;
// toggle HasMouse widget state on enter and leave
- if ( e->type() == QEvent::Enter || e->type() == QEvent::DragEnter )
+ if ( e->type() == QEvent::Enter || e->type() == QEvent::DragEnter ) {
widget->setWState( WState_HasMouse );
- else if ( e->type() == QEvent::Leave || e->type() == QEvent::DragLeave )
+ HOVER_SENSITIVE_WIDGET_SELECT {
+ widget->repaint(false);
+ }
+ }
+ else if ( e->type() == QEvent::Leave || e->type() == QEvent::DragLeave ) {
widget->clearWState( WState_HasMouse );
+ HOVER_SENSITIVE_WIDGET_SELECT {
+ widget->repaint(false);
+ }
+ }
+
+ // repaint information entry widgets on focus set/unset
+ if ( e->type() == QEvent::FocusIn || e->type() == QEvent::FocusOut ) {
+ FOCUS_SENSITIVE_WIDGET_SELECT {
+ widget->repaint(false);
+ }
+ FOCUS_SENSITIVE_PARENT_WIDGET_SELECT {
+ widget->parentWidget()->repaint(false);
+ }
+ }
// throw away any mouse-tracking-only mouse events
if ( e->type() == QEvent::MouseMove &&
diff --git a/src/kernel/qstyle.h b/src/kernel/qstyle.h
index 1690786..324b987 100644
--- a/src/kernel/qstyle.h
+++ b/src/kernel/qstyle.h
@@ -63,26 +63,26 @@ class QStyleOption {
public:
enum StyleOptionDefault { Default };
- QStyleOption(StyleOptionDefault=Default) : def(TRUE), tb(NULL), cli(NULL) {}
+ QStyleOption(StyleOptionDefault=Default) : def(TRUE), tb(NULL), cli(NULL), tbh(NULL) {}
// Note: we don't use default arguments since that is unnecessary
// initialization.
QStyleOption(int in1) :
- def(FALSE), tb(NULL), i1(in1), cli(NULL) {}
+ def(FALSE), tb(NULL), i1(in1), cli(NULL), tbh(NULL) {}
QStyleOption(int in1, int in2) :
- def(FALSE), tb(NULL), i1(in1), i2(in2), cli(NULL) {}
+ def(FALSE), tb(NULL), i1(in1), i2(in2), cli(NULL), tbh(NULL) {}
QStyleOption(int in1, int in2, int in3, int in4) :
- def(FALSE), tb(NULL), i1(in1), i2(in2), i3(in3), i4(in4), cli(NULL) {}
- QStyleOption(QMenuItem* m) : def(FALSE), mi(m), tb(NULL), cli(NULL) {}
- QStyleOption(QMenuItem* m, int in1) : def(FALSE), mi(m), tb(NULL), i1(in1), cli(NULL) {}
- QStyleOption(QMenuItem* m, int in1, int in2) : def(FALSE), mi(m), tb(NULL), i1(in1), i2(in2), cli(NULL) {}
- QStyleOption(const QColor& c) : def(FALSE), tb(NULL), cl(&c), cli(NULL) {}
- QStyleOption(QTab* t) : def(FALSE), tb(t), cli(NULL) {}
- QStyleOption(QListViewItem* i) : def(FALSE), tb(NULL), li(i), cli(NULL) {}
- QStyleOption(QCheckListItem* i) : def(FALSE), tb(NULL), cli(i) {}
- QStyleOption(Qt::ArrowType a) : def(FALSE), tb(NULL), i1((int)a), cli(NULL) {}
- QStyleOption(const QRect& r) : def(FALSE), tb(NULL), i1(r.x()), i2(r.y()), i3(r.width()), i4(r.height()), cli(NULL) {}
- QStyleOption(QWidget *w) : def(FALSE), tb(NULL), cli(NULL), p1((void*)w) {}
+ def(FALSE), tb(NULL), i1(in1), i2(in2), i3(in3), i4(in4), cli(NULL), tbh(NULL) {}
+ QStyleOption(QMenuItem* m) : def(FALSE), mi(m), tb(NULL), cli(NULL), tbh(NULL) {}
+ QStyleOption(QMenuItem* m, int in1) : def(FALSE), mi(m), tb(NULL), i1(in1), cli(NULL), tbh(NULL) {}
+ QStyleOption(QMenuItem* m, int in1, int in2) : def(FALSE), mi(m), tb(NULL), i1(in1), i2(in2), cli(NULL), tbh(NULL) {}
+ QStyleOption(const QColor& c) : def(FALSE), tb(NULL), cl(&c), cli(NULL), tbh(NULL) {}
+ QStyleOption(QTab* t) : def(FALSE), tb(t), cli(NULL), tbh(NULL) {}
+ QStyleOption(QListViewItem* i) : def(FALSE), tb(NULL), li(i), cli(NULL), tbh(NULL) {}
+ QStyleOption(QCheckListItem* i) : def(FALSE), tb(NULL), cli(i), tbh(NULL) {}
+ QStyleOption(Qt::ArrowType a) : def(FALSE), tb(NULL), i1((int)a), cli(NULL), tbh(NULL) {}
+ QStyleOption(const QRect& r) : def(FALSE), tb(NULL), i1(r.x()), i2(r.y()), i3(r.width()), i4(r.height()), cli(NULL), tbh(NULL) {}
+ QStyleOption(QWidget *w) : def(FALSE), tb(NULL), cli(NULL), p1((void*)w), tbh(NULL) {}
bool isDefault() const { return def; }
@@ -109,6 +109,9 @@ public:
QRect rect() const { return QRect( i1, i2, i3, i4 ); }
QWidget* widget() const { return (QWidget*)p1; }
+ QStyleOption(QTab* t, QTab* h) : def(FALSE), tb(t), cli(NULL), tbh(h) {}
+ QTab* hoverTab() const { return tbh; }
+
private:
// NOTE: none of these components have constructors.
bool def;
@@ -121,6 +124,7 @@ private:
int i5, i6; // reserved
QCheckListItem* cli;
void *p1, *p2, *p3, *p4; // reserved
+ QTab* tbh;
// (padded to 64 bytes on some architectures)
};
@@ -200,7 +204,7 @@ class QStyleControlElementGenericWidgetData {
QFont font;
};
-class QStyleControlElementData {
+class Q_EXPORT QStyleControlElementData {
public:
QStringList widgetObjectTypes;
bool allDataPopulated;
@@ -315,6 +319,7 @@ public:
CEF_IsActiveWindow = 0x00200000,
CEF_IsTopLevel = 0x00400000,
CEF_IsVisible = 0x00800000,
+ CEF_HasMouse = 0x01000000
};
// New QStyle API - most of these should probably be pure virtual
diff --git a/src/styles/qcommonstyle.cpp b/src/styles/qcommonstyle.cpp
index 3e61282..8293285 100644
--- a/src/styles/qcommonstyle.cpp
+++ b/src/styles/qcommonstyle.cpp
@@ -226,6 +226,7 @@ QStyle::ControlElementFlags getControlElementFlagsForObject(const QObject* objec
if (widget->parentWidget()) cef = cef | QStyle::CEF_HasParentWidget;
if (widget->focusProxy()) cef = cef | QStyle::CEF_HasFocusProxy;
if (widget->hasFocus()) cef = cef | QStyle::CEF_HasFocus;
+ if (widget->hasMouse()) cef = cef | QStyle::CEF_HasMouse;
if (populateReliantFields) {
if (widget->isActiveWindow()) cef = cef | QStyle::CEF_IsActiveWindow;
if (widget->isTopLevel()) cef = cef | QStyle::CEF_IsTopLevel;
diff --git a/src/styles/qmotifplusstyle.cpp b/src/styles/qmotifplusstyle.cpp
index 86a2558..72e28a8 100644
--- a/src/styles/qmotifplusstyle.cpp
+++ b/src/styles/qmotifplusstyle.cpp
@@ -65,13 +65,10 @@
struct QMotifPlusStylePrivate
{
QMotifPlusStylePrivate()
- : hoverWidget(0), hovering(FALSE), sliderActive(FALSE), mousePressed(FALSE),
+ : hovering(FALSE), sliderActive(FALSE), mousePressed(FALSE),
scrollbarElement(0), lastElement(0), ref(1)
{ ; }
- void* hoverWidget;
- QStyleControlElementData hoverWidgetData;
- QStyle::ControlElementFlags hoverWidgetFlags;
bool hovering, sliderActive, mousePressed;
int scrollbarElement, lastElement, ref;
QPoint mousePos;
@@ -660,9 +657,6 @@ void QMotifPlusStyle::drawControl( ControlElement element,
const QStyleOption& opt,
const QWidget *widget) const
{
- if (widget == singleton->hoverWidget)
- flags |= Style_MouseOver;
-
switch (element) {
case CE_PushButton:
{
@@ -1108,9 +1102,6 @@ void QMotifPlusStyle::drawComplexControl(ComplexControl control,
const QStyleOption& opt,
const QWidget *widget ) const
{
- if (widget == singleton->hoverWidget)
- flags |= Style_MouseOver;
-
switch (control) {
case CC_ScrollBar:
{
@@ -1516,30 +1507,22 @@ bool QMotifPlusStyle::objectEventHandler( QStyleControlElementData ceData, Contr
if (!ceData.widgetObjectTypes.contains("QWidget"))
break;
- singleton->hoverWidget = source;
- singleton->hoverWidgetData = ceData;
- singleton->hoverWidgetFlags = elementFlags;
- if (!(singleton->hoverWidgetFlags & CEF_IsEnabled)) {
- singleton->hoverWidget = 0;
- break;
- }
- widgetActionRequest(singleton->hoverWidgetData, singleton->hoverWidgetFlags, singleton->hoverWidget, WAR_Repaint);
+ widgetActionRequest(ceData, elementFlags, source, WAR_Repaint);
break;
}
case QEvent::Leave:
{
- if (source != singleton->hoverWidget)
+ if (!ceData.widgetObjectTypes.contains("QWidget"))
break;
- void *w = singleton->hoverWidget;
- singleton->hoverWidget = 0;
- widgetActionRequest(singleton->hoverWidgetData, singleton->hoverWidgetFlags, w, WAR_Repaint);
+
+ widgetActionRequest(ceData, elementFlags, source, WAR_Repaint);
break;
}
case QEvent::MouseMove:
{
- if ((!ceData.widgetObjectTypes.contains("QWidget")) || source != singleton->hoverWidget)
+ if ((!ceData.widgetObjectTypes.contains("QWidget")))
break;
if ((!ceData.widgetObjectTypes.contains("QScrollBar")) && (!ceData.widgetObjectTypes.contains("QSlider")))
@@ -1548,7 +1531,7 @@ bool QMotifPlusStyle::objectEventHandler( QStyleControlElementData ceData, Contr
singleton->mousePos = ((QMouseEvent *) event)->pos();
if (! singleton->mousePressed) {
singleton->hovering = TRUE;
- widgetActionRequest(singleton->hoverWidgetData, singleton->hoverWidgetFlags, singleton->hoverWidget, WAR_Repaint);
+ widgetActionRequest(ceData, elementFlags, source, WAR_Repaint);
singleton->hovering = FALSE;
}
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 e45e42d..3ea5a9b 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()) {