Browse Source

Fix SpinBox widget drawing

The theme engine is now almost usable under simple Qt4 apps such as vlc
r14.0.x
Timothy Pearson 10 years ago
parent
commit
5374f02e91
  1. 119
      plugin/simplestyle.cpp
  2. 3
      plugin/simplestyle.h

119
plugin/simplestyle.cpp

@ -35,9 +35,15 @@
#include <qtitlebar_p.h>
#undef Qt
// HACK to gain access to QSpinBox QLineEdit object
#define protected public
#include <QtGui/QtGui>
#include <QtGui/QX11Info>
// HACK
#undef protected
#include "simplestyle.h"
#include "tdeqt4painter.h"
@ -605,6 +611,7 @@ SimpleStyle::SimpleStyle()
m_tqt3slider_widget = new TQSlider(m_tqt3parent_widget);
m_tqt3scrollbar_widget = new TQScrollBar(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_tqt3titlebar_widget = new TQTitleBar(m_tqt3window_widget, m_tqt3parent_widget);
m_tqt3menubar_widget = new TQMenuBar(m_tqt3parent_widget);
@ -625,6 +632,7 @@ SimpleStyle::~SimpleStyle()
// delete m_tqt3slider_widget;
// delete m_tqt3scrollbar_widget;
// delete m_tqt3spinbox_widget;
// delete m_tqt3spinwidget_widget;
// delete m_tqt3window_widget;
// delete m_tqt3titlebar_widget;
// delete m_tqt3menubar_widget;
@ -1125,6 +1133,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
// Copy over all widget attributes
qt4progressbar_widget = dynamic_cast<const QProgressBar*>(w);
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());
if (qt4progressbar_widget->orientation() != Qt::Horizontal) {
// Qt3 cannot draw vertical progress bars
@ -1140,6 +1149,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
qt4tabbar_widget = dynamic_cast<const QTabBar*>(w);
if (qt4tabbar_widget) {
m_tqt3tabbar_widget->setGeometry(0, 0, qt4tabbar_widget->width(), qt4tabbar_widget->height());
m_tqt3tabbar_widget->setEnabled(qt4tabbar_widget->isEnabled());
// Clear out tabbar
for (i=0;i<m_tqt3tabbar_widget->count();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
qt4radiobutton_widget = dynamic_cast<const QRadioButton*>(w);
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->setDown(qt4radiobutton_widget->isDown());
break;
@ -1200,6 +1211,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
// Copy over all widget attributes
qt4combobox_widget = dynamic_cast<const QComboBox*>(w);
m_tqt3combobox_widget->setGeometry(0, 0, qt4combobox_widget->width(), qt4combobox_widget->height());
m_tqt3combobox_widget->setEnabled(qt4combobox_widget->isEnabled());
// Clear out all combobox items
m_tqt3combobox_widget->clear();
@ -1218,6 +1230,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
// Copy over all widget attributes
qt4menu_widget = dynamic_cast<const QMenu*>(w);
m_tqt3popupmenu_widget->setGeometry(0, 0, qt4menu_widget->width(), qt4menu_widget->height());
m_tqt3popupmenu_widget->setEnabled(qt4menu_widget->isEnabled());
// Clear out menu
m_tqt3popupmenu_widget->clear();
m_tqt3popupmenu_widget->setCheckable(false);
@ -1254,6 +1267,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
// Copy over all widget attributes
qt4menubar_widget = dynamic_cast<const QMenuBar*>(w);
m_tqt3menubar_widget->setGeometry(0, 0, qt4menubar_widget->width(), qt4menubar_widget->height());
m_tqt3menubar_widget->setEnabled(qt4menubar_widget->isEnabled());
// Clear out menu
m_tqt3menubar_widget->clear();
// Copy over all menu items
@ -1287,6 +1301,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
qt4slider_widget = dynamic_cast<const QSlider*>(w);
if (qt4slider_widget) {
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->setTracking(qt4slider_widget->hasTracking());
// m_tqt3slider_widget->setPalette(); // FIXME
@ -1311,6 +1326,7 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
qt4scrollbar_widget = dynamic_cast<const QScrollBar*>(w);
if (qt4scrollbar_widget) {
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->setTracking(qt4scrollbar_widget->hasTracking());
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);
if (qt4spinbox_widget) {
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->setMaxValue(qt4spinbox_widget->maximum());
m_tqt3spinbox_widget->setLineStep(qt4spinbox_widget->singleStep());
@ -1341,6 +1358,26 @@ TQWidget* SimpleStyle::initializeInterfaceWidget(TQt3WidgetType wt, const QWidge
#ifdef DEBUG_WARNINGS
printf("Unable to draw Qt4 spinbox with no Qt4 object available\n\r"); fflush(stdout);
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
}
break;
@ -1406,6 +1443,7 @@ void SimpleStyle::drawComplexControl(ComplexControl control, const QStyleOptionC
bool can_override = true;
TQStyle::ComplexControl tqtCC;
TQStyle::SCFlags subControl = TQStyle::SC_All;
TQStyle::SCFlags subControlActive = TQStyle::SC_None;
@ -1461,17 +1499,13 @@ void SimpleStyle::drawComplexControl(ComplexControl control, const QStyleOptionC
can_override = false;
}
break;
// case CC_SpinBox:
// // FIXME FIXME FIXME
// // This is more complex to interface with
// // Under TQt3 there is an internal SpinWidget, and the SpinBox draws the editor through another call
// // Under Qt4 there is only the SpinBox, and we would need to draw both the SpinWidget and the editor
// tqtCC = TQStyle::CC_SpinWidget;
// interfaceWidget = initializeInterfaceWidget(TQT3WT_TQSpinBox, w);
// if (interfaceWidget == 0) {
// can_override = false;
// }
// break;
case CC_SpinBox:
tqtCC = TQStyle::CC_SpinWidget;
interfaceWidget = initializeInterfaceWidget(TQT3WT_TQSpinWidget, w);
if (interfaceWidget == 0) {
can_override = false;
}
break;
case CC_TitleBar:
tqtCC = TQStyle::CC_TitleBar;
interfaceWidget = initializeInterfaceWidget(TQT3WT_TQTitleBar, w, opt);
@ -1574,6 +1608,15 @@ void SimpleStyle::drawComplexControl(ComplexControl control, const QStyleOptionC
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) {
// 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
@ -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
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();
#ifdef DEBUG_WARNINGS
@ -1882,6 +1951,7 @@ void SimpleStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QP
bool can_override = true;
bool do_not_draw = false;
bool draw_transparent_background = false;
TQStyle::PrimitiveElement tqtPE;
TQStyleOption tqt3opt(TQStyleOption::Default);
@ -1987,7 +2057,15 @@ void SimpleStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QP
NO_QT3_EQUIVALENT
break;
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;
// Qt3 support elements
case QStyle::PE_Q3Separator:
@ -2018,15 +2096,28 @@ void SimpleStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QP
tqt3colorgroup = tqt3palette.disabled();
}
if (can_override) {
// Construct a Qt3 paint device on the Qt4 painter
TDEQt4PaintDevice qt4pd(p);
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
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();
#ifdef DEBUG_WARNINGS

3
plugin/simplestyle.h

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

Loading…
Cancel
Save