diff --git a/plugin/simplestyle.cpp b/plugin/simplestyle.cpp index f752f85..a77ec37 100644 --- a/plugin/simplestyle.cpp +++ b/plugin/simplestyle.cpp @@ -143,7 +143,7 @@ static QString TDEFileDialogSelectDirectory(QWidget *parent, const QString &capt #define NO_QT3_EQUIVALENT can_override = false; #define DO_NOT_DRAW can_override = true; do_not_draw = true; -Qt4TDEStyle::Qt4TDEStyle() : m_aboutData(NULL), m_tqApplication(NULL), m_tdeApplication(NULL) +Qt4TDEStyle::Qt4TDEStyle() : m_aboutData(NULL), m_tqApplication(NULL), m_tdeApplication(NULL), hoverTab(-1) { enable_debug_warnings = (getenv("DEBUG_TDEQT4_THEME_ENGINE") != NULL); @@ -310,6 +310,21 @@ void Qt4TDEStyle::unpolish(QWidget *widget) widget->removeEventFilter(this); } +#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") ) + bool Qt4TDEStyle::eventFilter(QObject *obj, QEvent *ev) { // HACK @@ -320,37 +335,40 @@ bool Qt4TDEStyle::eventFilter(QObject *obj, QEvent *ev) QWidget* widget = dynamic_cast(obj); - if ((ev->type() == QEvent::FocusIn) || (ev->type() == QEvent::FocusOut) - || (ev->type() == QEvent::Enter) || (ev->type() == QEvent::Leave) || (ev->type() == QEvent::Wheel)) { - widget->repaint(); + if ((ev->type() == QEvent::FocusIn) || (ev->type() == QEvent::FocusOut)) { + FOCUS_SENSITIVE_WIDGET_SELECT { + widget->repaint(); + } + FOCUS_SENSITIVE_PARENT_WIDGET_SELECT { + widget->parentWidget()->repaint(); + } + } + + if ((ev->type() == QEvent::Enter) || (ev->type() == QEvent::Leave) || (ev->type() == QEvent::Wheel)) { + HOVER_SENSITIVE_WIDGET_SELECT { + widget->repaint(); + } } else { -// if (dynamic_cast(obj)) { - if (ev->type() == QEvent::MouseMove) { - QTabBar *tabbar = dynamic_cast(obj); - QMouseEvent *me = dynamic_cast(ev); - if (tabbar && me) { - // FIXME - // Avoid unnecessary repaints (which otherwise would occour on every - // MouseMove event causing high cpu load). - // FIXME - // Tab highlighting won't work unless we keep the same tabbar object, - // and specifically tab objects, while the mouse is being moved within - // the tabbar...also the eventFilter method of the style needs to be called... - - bool repaint = true; - -// QTab *tab = tabbar->selectTab(me->pos() ); -// if (hoverTab == tab) -// repaint = false; -// hoverTab = tab; - - if (repaint) { - tabbar->repaint(); - } + if (ev->type() == QEvent::MouseMove) { + QTabBar *tabbar = dynamic_cast(obj); + QMouseEvent *me = dynamic_cast(ev); + if (tabbar && me) { + // FIXME + // Avoid unnecessary repaints (which otherwise would occur on every MouseMove event causing high cpu load). + // Qt4 should really be handling tab mouseover repaint calls instead of relying on this hack... + bool repaint = true; + int tab = tabbar->tabAt(me->pos()); + if (hoverTab == tab) { + repaint = false; + } + hoverTab = tab; + + if (repaint) { + tabbar->repaint(); } } -// } + } } // Transparently pass the event on to any other handlers @@ -2600,11 +2618,16 @@ void Qt4TDEStyle::drawControl(ControlElement element, const QStyleOption *opt, Q // I have to guess based on the Qt4 position of the tab in the tab bar, which may or may not work 100% in all cases drawingTab = 0; estimated_tab_index = dynamic_cast(w)->tabAt(QPoint(opt->rect.x(), opt->rect.y())); + QRect estimated_tab_rect = dynamic_cast(w)->tabRect(estimated_tab_index); TQTabBar* tabBarWidget = dynamic_cast(interfaceWidget); drawingTab = tabBarWidget->tabAt(estimated_tab_index); + if (estimated_tab_rect.contains(w->mapFromGlobal(QCursor::pos()))) { + sflags |= TQStyle::Style_MouseOver; + } + if (drawingTab) { - tqt3opt = TQStyleOption(drawingTab); + tqt3opt = TQStyleOption(drawingTab, (sflags & TQStyle::Style_MouseOver)?drawingTab:NULL); tqt3opt_element2 = TQStyleOption(drawingTab); } diff --git a/plugin/simplestyle.h b/plugin/simplestyle.h index e8799ce..bfe98ed 100644 --- a/plugin/simplestyle.h +++ b/plugin/simplestyle.h @@ -113,6 +113,8 @@ private: TQPixmapCache* m_internalTQt3PixmapCache; TQWidgetCache* m_internalTQt3WidgetCache; + + int hoverTab; }; #endif