Fix SpinBox widget drawing

The theme engine is now almost usable under simple Qt4 apps such as vlc
r14.0.x
Timothy Pearson 13 years ago
parent 6aa698b857
commit 5374f02e91

@ -35,9 +35,15 @@
#include <qtitlebar_p.h> #include <qtitlebar_p.h>
#undef Qt #undef Qt
// HACK to gain access to QSpinBox QLineEdit object
#define protected public
#include <QtGui/QtGui> #include <QtGui/QtGui>
#include <QtGui/QX11Info> #include <QtGui/QX11Info>
// HACK
#undef protected
#include "simplestyle.h" #include "simplestyle.h"
#include "tdeqt4painter.h" #include "tdeqt4painter.h"
@ -605,6 +611,7 @@ SimpleStyle::SimpleStyle()
m_tqt3slider_widget = new TQSlider(m_tqt3parent_widget); m_tqt3slider_widget = new TQSlider(m_tqt3parent_widget);
m_tqt3scrollbar_widget = new TQScrollBar(m_tqt3parent_widget); m_tqt3scrollbar_widget = new TQScrollBar(m_tqt3parent_widget);
m_tqt3spinbox_widget = new TQSpinBox(m_tqt3parent_widget); m_tqt3spinbox_widget = new TQSpinBox(m_tqt3parent_widget);
m_tqt3spinwidget_widget = new TQSpinWidget(m_tqt3parent_widget);
m_tqt3window_widget = new TQWidget(m_tqt3parent_widget); m_tqt3window_widget = new TQWidget(m_tqt3parent_widget);
m_tqt3titlebar_widget = new TQTitleBar(m_tqt3window_widget, m_tqt3parent_widget); m_tqt3titlebar_widget = new TQTitleBar(m_tqt3window_widget, m_tqt3parent_widget);
m_tqt3menubar_widget = new TQMenuBar(m_tqt3parent_widget); m_tqt3menubar_widget = new TQMenuBar(m_tqt3parent_widget);
@ -625,6 +632,7 @@ SimpleStyle::~SimpleStyle()
// delete m_tqt3slider_widget; // delete m_tqt3slider_widget;
// delete m_tqt3scrollbar_widget; // delete m_tqt3scrollbar_widget;
// delete m_tqt3spinbox_widget; // delete m_tqt3spinbox_widget;
// delete m_tqt3spinwidget_widget;
// delete m_tqt3window_widget; // delete m_tqt3window_widget;
// delete m_tqt3titlebar_widget; // delete m_tqt3titlebar_widget;
// delete m_tqt3menubar_widget; // delete m_tqt3menubar_widget;
@ -1125,6 +1133,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
// Copy over all widget attributes // Copy over all widget attributes
qt4progressbar_widget = dynamic_cast<const QProgressBar*>(w); qt4progressbar_widget = dynamic_cast<const QProgressBar*>(w);
m_tqt3progressbar_widget->setGeometry(0, 0, qt4progressbar_widget->width(), qt4progressbar_widget->height()); m_tqt3progressbar_widget->setGeometry(0, 0, qt4progressbar_widget->width(), qt4progressbar_widget->height());
m_tqt3progressbar_widget->setEnabled(qt4progressbar_widget->isEnabled());
m_tqt3progressbar_widget->setProgress(qt4progressbar_widget->value()-qt4progressbar_widget->minimum(),qt4progressbar_widget->maximum()-qt4progressbar_widget->minimum()); m_tqt3progressbar_widget->setProgress(qt4progressbar_widget->value()-qt4progressbar_widget->minimum(),qt4progressbar_widget->maximum()-qt4progressbar_widget->minimum());
if (qt4progressbar_widget->orientation() != Qt::Horizontal) { if (qt4progressbar_widget->orientation() != Qt::Horizontal) {
// Qt3 cannot draw vertical progress bars // Qt3 cannot draw vertical progress bars
@ -1140,6 +1149,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
qt4tabbar_widget = dynamic_cast<const QTabBar*>(w); qt4tabbar_widget = dynamic_cast<const QTabBar*>(w);
if (qt4tabbar_widget) { if (qt4tabbar_widget) {
m_tqt3tabbar_widget->setGeometry(0, 0, qt4tabbar_widget->width(), qt4tabbar_widget->height()); m_tqt3tabbar_widget->setGeometry(0, 0, qt4tabbar_widget->width(), qt4tabbar_widget->height());
m_tqt3tabbar_widget->setEnabled(qt4tabbar_widget->isEnabled());
// Clear out tabbar // Clear out tabbar
for (i=0;i<m_tqt3tabbar_widget->count();i++) { for (i=0;i<m_tqt3tabbar_widget->count();i++) {
m_tqt3tabbar_widget->removeTab(m_tqt3tabbar_widget->tabAt(i)); m_tqt3tabbar_widget->removeTab(m_tqt3tabbar_widget->tabAt(i));
@ -1192,6 +1202,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
// Copy over all widget attributes // Copy over all widget attributes
qt4radiobutton_widget = dynamic_cast<const QRadioButton*>(w); qt4radiobutton_widget = dynamic_cast<const QRadioButton*>(w);
m_tqt3radiobutton_widget->setGeometry(0, 0, qt4radiobutton_widget->width(), qt4radiobutton_widget->height()); m_tqt3radiobutton_widget->setGeometry(0, 0, qt4radiobutton_widget->width(), qt4radiobutton_widget->height());
m_tqt3radiobutton_widget->setEnabled(qt4radiobutton_widget->isEnabled());
m_tqt3radiobutton_widget->setText(convertQt4ToTQt3String(qt4radiobutton_widget->text())); m_tqt3radiobutton_widget->setText(convertQt4ToTQt3String(qt4radiobutton_widget->text()));
m_tqt3radiobutton_widget->setDown(qt4radiobutton_widget->isDown()); m_tqt3radiobutton_widget->setDown(qt4radiobutton_widget->isDown());
break; break;
@ -1200,6 +1211,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
// Copy over all widget attributes // Copy over all widget attributes
qt4combobox_widget = dynamic_cast<const QComboBox*>(w); qt4combobox_widget = dynamic_cast<const QComboBox*>(w);
m_tqt3combobox_widget->setGeometry(0, 0, qt4combobox_widget->width(), qt4combobox_widget->height()); m_tqt3combobox_widget->setGeometry(0, 0, qt4combobox_widget->width(), qt4combobox_widget->height());
m_tqt3combobox_widget->setEnabled(qt4combobox_widget->isEnabled());
// Clear out all combobox items // Clear out all combobox items
m_tqt3combobox_widget->clear(); m_tqt3combobox_widget->clear();
@ -1218,6 +1230,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
// Copy over all widget attributes // Copy over all widget attributes
qt4menu_widget = dynamic_cast<const QMenu*>(w); qt4menu_widget = dynamic_cast<const QMenu*>(w);
m_tqt3popupmenu_widget->setGeometry(0, 0, qt4menu_widget->width(), qt4menu_widget->height()); m_tqt3popupmenu_widget->setGeometry(0, 0, qt4menu_widget->width(), qt4menu_widget->height());
m_tqt3popupmenu_widget->setEnabled(qt4menu_widget->isEnabled());
// Clear out menu // Clear out menu
m_tqt3popupmenu_widget->clear(); m_tqt3popupmenu_widget->clear();
m_tqt3popupmenu_widget->setCheckable(false); m_tqt3popupmenu_widget->setCheckable(false);
@ -1254,6 +1267,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
// Copy over all widget attributes // Copy over all widget attributes
qt4menubar_widget = dynamic_cast<const QMenuBar*>(w); qt4menubar_widget = dynamic_cast<const QMenuBar*>(w);
m_tqt3menubar_widget->setGeometry(0, 0, qt4menubar_widget->width(), qt4menubar_widget->height()); m_tqt3menubar_widget->setGeometry(0, 0, qt4menubar_widget->width(), qt4menubar_widget->height());
m_tqt3menubar_widget->setEnabled(qt4menubar_widget->isEnabled());
// Clear out menu // Clear out menu
m_tqt3menubar_widget->clear(); m_tqt3menubar_widget->clear();
// Copy over all menu items // Copy over all menu items
@ -1287,6 +1301,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
qt4slider_widget = dynamic_cast<const QSlider*>(w); qt4slider_widget = dynamic_cast<const QSlider*>(w);
if (qt4slider_widget) { if (qt4slider_widget) {
m_tqt3slider_widget->setGeometry(0, 0, qt4slider_widget->width(), qt4slider_widget->height()); m_tqt3slider_widget->setGeometry(0, 0, qt4slider_widget->width(), qt4slider_widget->height());
m_tqt3slider_widget->setEnabled(qt4slider_widget->isEnabled());
m_tqt3slider_widget->setOrientation(convertQt4ToTQt3Orientation(qt4slider_widget->orientation())); m_tqt3slider_widget->setOrientation(convertQt4ToTQt3Orientation(qt4slider_widget->orientation()));
m_tqt3slider_widget->setTracking(qt4slider_widget->hasTracking()); m_tqt3slider_widget->setTracking(qt4slider_widget->hasTracking());
// m_tqt3slider_widget->setPalette(); // FIXME // m_tqt3slider_widget->setPalette(); // FIXME
@ -1311,6 +1326,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
qt4scrollbar_widget = dynamic_cast<const QScrollBar*>(w); qt4scrollbar_widget = dynamic_cast<const QScrollBar*>(w);
if (qt4scrollbar_widget) { if (qt4scrollbar_widget) {
m_tqt3scrollbar_widget->setGeometry(0, 0, qt4scrollbar_widget->width(), qt4scrollbar_widget->height()); m_tqt3scrollbar_widget->setGeometry(0, 0, qt4scrollbar_widget->width(), qt4scrollbar_widget->height());
m_tqt3scrollbar_widget->setEnabled(qt4scrollbar_widget->isEnabled());
m_tqt3scrollbar_widget->setOrientation(convertQt4ToTQt3Orientation(qt4scrollbar_widget->orientation())); m_tqt3scrollbar_widget->setOrientation(convertQt4ToTQt3Orientation(qt4scrollbar_widget->orientation()));
m_tqt3scrollbar_widget->setTracking(qt4scrollbar_widget->hasTracking()); m_tqt3scrollbar_widget->setTracking(qt4scrollbar_widget->hasTracking());
m_tqt3scrollbar_widget->setMinValue(qt4scrollbar_widget->minimum()); m_tqt3scrollbar_widget->setMinValue(qt4scrollbar_widget->minimum());
@ -1332,6 +1348,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
qt4spinbox_widget = dynamic_cast<const QSpinBox*>(w); qt4spinbox_widget = dynamic_cast<const QSpinBox*>(w);
if (qt4spinbox_widget) { if (qt4spinbox_widget) {
m_tqt3spinbox_widget->setGeometry(0, 0, qt4spinbox_widget->width(), qt4spinbox_widget->height()); m_tqt3spinbox_widget->setGeometry(0, 0, qt4spinbox_widget->width(), qt4spinbox_widget->height());
m_tqt3spinbox_widget->setEnabled(qt4spinbox_widget->isEnabled());
m_tqt3spinbox_widget->setMinValue(qt4spinbox_widget->minimum()); m_tqt3spinbox_widget->setMinValue(qt4spinbox_widget->minimum());
m_tqt3spinbox_widget->setMaxValue(qt4spinbox_widget->maximum()); m_tqt3spinbox_widget->setMaxValue(qt4spinbox_widget->maximum());
m_tqt3spinbox_widget->setLineStep(qt4spinbox_widget->singleStep()); m_tqt3spinbox_widget->setLineStep(qt4spinbox_widget->singleStep());
@ -1341,6 +1358,26 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
#ifdef DEBUG_WARNINGS #ifdef DEBUG_WARNINGS
printf("Unable to draw Qt4 spinbox with no Qt4 object available\n\r"); fflush(stdout); printf("Unable to draw Qt4 spinbox with no Qt4 object available\n\r"); fflush(stdout);
interfaceWidget = 0; interfaceWidget = 0;
#endif
}
break;
case TQT3WT_TQSpinWidget:
interfaceWidget = m_tqt3spinwidget_widget;
// Copy over all widget attributes
qt4spinbox_widget = dynamic_cast<const QSpinBox*>(w);
if (qt4spinbox_widget) {
m_tqt3spinbox_widget->setGeometry(0, 0, qt4spinbox_widget->width(), qt4spinbox_widget->height());
m_tqt3spinbox_widget->setEnabled(qt4spinbox_widget->isEnabled());
// FIXME
// m_tqt3spinbox_widget->setMinValue(qt4spinbox_widget->minimum());
// m_tqt3spinbox_widget->setMaxValue(qt4spinbox_widget->maximum());
// m_tqt3spinbox_widget->setLineStep(qt4spinbox_widget->singleStep());
// m_tqt3spinbox_widget->setValue(qt4spinbox_widget->value());
}
else {
#ifdef DEBUG_WARNINGS
printf("Unable to draw Qt4 spinbox with no Qt4 object available\n\r"); fflush(stdout);
interfaceWidget = 0;
#endif #endif
} }
break; break;
@ -1406,6 +1443,7 @@ void SimpleStyle::drawComplexControl(ComplexControl control, const QStyleOptionC
bool can_override = true; bool can_override = true;
TQStyle::ComplexControl tqtCC; TQStyle::ComplexControl tqtCC;
TQStyle::SCFlags subControl = TQStyle::SC_All; TQStyle::SCFlags subControl = TQStyle::SC_All;
TQStyle::SCFlags subControlActive = TQStyle::SC_None; TQStyle::SCFlags subControlActive = TQStyle::SC_None;
@ -1461,17 +1499,13 @@ void SimpleStyle::drawComplexControl(ComplexControl control, const QStyleOptionC
can_override = false; can_override = false;
} }
break; break;
// case CC_SpinBox: case CC_SpinBox:
// // FIXME FIXME FIXME tqtCC = TQStyle::CC_SpinWidget;
// // This is more complex to interface with interfaceWidget = initializeInterfaceWidget(TQT3WT_TQSpinWidget, w);
// // Under TQt3 there is an internal SpinWidget, and the SpinBox draws the editor through another call if (interfaceWidget == 0) {
// // Under Qt4 there is only the SpinBox, and we would need to draw both the SpinWidget and the editor can_override = false;
// tqtCC = TQStyle::CC_SpinWidget; }
// interfaceWidget = initializeInterfaceWidget(TQT3WT_TQSpinBox, w); break;
// if (interfaceWidget == 0) {
// can_override = false;
// }
// break;
case CC_TitleBar: case CC_TitleBar:
tqtCC = TQStyle::CC_TitleBar; tqtCC = TQStyle::CC_TitleBar;
interfaceWidget = initializeInterfaceWidget(TQT3WT_TQTitleBar, w, opt); interfaceWidget = initializeInterfaceWidget(TQT3WT_TQTitleBar, w, opt);
@ -1574,6 +1608,15 @@ void SimpleStyle::drawComplexControl(ComplexControl control, const QStyleOptionC
TQPainter tqtPainter(&qt4pd); TQPainter tqtPainter(&qt4pd);
if (tqtCC == TQStyle::CC_ComboBox) {
// TQt3 expects the Style_MouseOver flag to be cleared if the certain widgets have been disabled
if (interfaceWidget) {
if (interfaceWidget->isEnabled() == false) {
sflags = sflags & (~TQStyle::Style_MouseOver);
}
}
}
if (tqtCC == TQStyle::CC_TitleBar) { if (tqtCC == TQStyle::CC_TitleBar) {
// TQt3 is expecting to see a rect() from the titlebar that excludes the window frame, // TQt3 is expecting to see a rect() from the titlebar that excludes the window frame,
// while Qt4 provides the entire rectangle (including the frame) via the widget/QStyleOptionTitleBar // while Qt4 provides the entire rectangle (including the frame) via the widget/QStyleOptionTitleBar
@ -1586,9 +1629,35 @@ void SimpleStyle::drawComplexControl(ComplexControl control, const QStyleOptionC
} }
} }
if (tqtCC == TQStyle::CC_SpinWidget) {
// Qt4 expects both the lineedit and the spinbox outside frame to be drawn
// Draw the outside frame before the spinbox buttons are drawn
tqApp->style().drawPrimitive(TQStyle::PE_PanelLineEdit, &tqtPainter, tqt3rect, tqt3colorgroup, sflags, tqt3opt);
}
// Instruct TQt3 to draw the complex control // Instruct TQt3 to draw the complex control
tqApp->style().drawComplexControl(tqtCC, &tqtPainter, interfaceWidget, tqt3rect, tqt3colorgroup, sflags, subControl, subControlActive, tqt3opt); tqApp->style().drawComplexControl(tqtCC, &tqtPainter, interfaceWidget, tqt3rect, tqt3colorgroup, sflags, subControl, subControlActive, tqt3opt);
if (tqtCC == TQStyle::CC_SpinWidget) {
// Paint the spinbox's editor widget over the outside frame (outside the spinbutton area)
const QSpinBox* sbWidget = dynamic_cast<const QSpinBox*>(w);
if (sbWidget) {
QLineEdit* sbLineEdit = sbWidget->lineEdit();
QRect sbleRect = sbLineEdit->geometry();
tqtPainter.setClipRect(tqt3rect.x(),tqt3rect.y(),sbleRect.x()+sbleRect.width(),tqt3rect.height());
p->fillRect(sbleRect,convertTQt3ToQt4Color(tqt3colorgroup.base()));
}
#ifdef DEBUG_WARNINGS
else {
printf("Unable to draw Qt4 spinbox with no Qt4 object available\n\r"); fflush(stdout);
}
#endif
// Now draw the outside frame again, but clipped to the editor widget side of the spinwidget this time
// This fixes drawing glitches inside of the editor widget while leaving the spinbutton area untouched
tqApp->style().drawPrimitive(TQStyle::PE_PanelLineEdit, &tqtPainter, tqt3rect, tqt3colorgroup, sflags, tqt3opt);
}
tqtPainter.end(); tqtPainter.end();
#ifdef DEBUG_WARNINGS #ifdef DEBUG_WARNINGS
@ -1882,6 +1951,7 @@ void SimpleStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QP
bool can_override = true; bool can_override = true;
bool do_not_draw = false; bool do_not_draw = false;
bool draw_transparent_background = false;
TQStyle::PrimitiveElement tqtPE; TQStyle::PrimitiveElement tqtPE;
TQStyleOption tqt3opt(TQStyleOption::Default); TQStyleOption tqt3opt(TQStyleOption::Default);
@ -1987,7 +2057,15 @@ void SimpleStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QP
NO_QT3_EQUIVALENT NO_QT3_EQUIVALENT
break; break;
case QStyle::PE_PanelLineEdit: case QStyle::PE_PanelLineEdit:
NO_QT3_EQUIVALENT // Under Qt4 this draws both the panel and the frame
// Under TQt3 it only draws the frame
// See resultant background fill routine directly before drawPrimitive below
// Also, the given rectangle is only valid for LineEdit widgets without a parent QSpinBox, QComboBox, or similar widget
// For those widgets we must draw a transparent background
tqtPE = TQStyle::PE_PanelLineEdit;
if (dynamic_cast<QSpinBox*>(w->parent()) || dynamic_cast<QComboBox*>(w->parent())) {
draw_transparent_background = true;
}
break; break;
// Qt3 support elements // Qt3 support elements
case QStyle::PE_Q3Separator: case QStyle::PE_Q3Separator:
@ -2018,15 +2096,28 @@ void SimpleStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QP
tqt3colorgroup = tqt3palette.disabled(); tqt3colorgroup = tqt3palette.disabled();
} }
if (can_override) { if (can_override) {
// Construct a Qt3 paint device on the Qt4 painter // Construct a Qt3 paint device on the Qt4 painter
TDEQt4PaintDevice qt4pd(p); TDEQt4PaintDevice qt4pd(p);
TQPainter tqtPainter(&qt4pd); TQPainter tqtPainter(&qt4pd);
// Certain primitives require additional drawing operations that Qt4 now expects
if (tqtPE == TQStyle::PE_PanelLineEdit) {
if (draw_transparent_background == false) {
// Tell Qt4 to draw the background
QCommonStyle::drawPrimitive(pe, opt, p, w);
}
else {
p->fillRect(opt->rect, Qt::transparent);
}
}
// Instruct TQt3 to draw the primitive // Instruct TQt3 to draw the primitive
tqApp->style().drawPrimitive(tqtPE, &tqtPainter, tqt3paintrect, tqt3colorgroup, sflags, tqt3opt); if (!((tqtPE == TQStyle::PE_PanelLineEdit) && (draw_transparent_background == true))) {
tqApp->style().drawPrimitive(tqtPE, &tqtPainter, tqt3paintrect, tqt3colorgroup, sflags, tqt3opt);
}
tqtPainter.end(); tqtPainter.end();
#ifdef DEBUG_WARNINGS #ifdef DEBUG_WARNINGS

@ -34,6 +34,7 @@ class TQComboBox;
class TQSlider; class TQSlider;
class TQScrollBar; class TQScrollBar;
class TQSpinBox; class TQSpinBox;
class TQSpinWidget;
class TQTitleBar; class TQTitleBar;
class TQMenuBar; class TQMenuBar;
@ -47,6 +48,7 @@ enum TQt3WidgetType {
TQT3WT_TQSlider, TQT3WT_TQSlider,
TQT3WT_TQScrollBar, TQT3WT_TQScrollBar,
TQT3WT_TQSpinBox, TQT3WT_TQSpinBox,
TQT3WT_TQSpinWidget,
TQT3WT_TQTitleBar, TQT3WT_TQTitleBar,
TQT3WT_TQMenuBar TQT3WT_TQMenuBar
}; };
@ -84,6 +86,7 @@ private:
TQSlider* m_tqt3slider_widget; TQSlider* m_tqt3slider_widget;
TQScrollBar* m_tqt3scrollbar_widget; TQScrollBar* m_tqt3scrollbar_widget;
TQSpinBox* m_tqt3spinbox_widget; TQSpinBox* m_tqt3spinbox_widget;
TQSpinWidget* m_tqt3spinwidget_widget;
TQWidget* m_tqt3window_widget; TQWidget* m_tqt3window_widget;
TQTitleBar* m_tqt3titlebar_widget; TQTitleBar* m_tqt3titlebar_widget;
TQMenuBar* m_tqt3menubar_widget; TQMenuBar* m_tqt3menubar_widget;

Loading…
Cancel
Save