Fix scrollbars and buttons

pull/1/head
Timothy Pearson 12 years ago
parent e363fd4cf8
commit 469e7d600f

@ -56,6 +56,8 @@
p.setPen(TQt::NoPen); \
p.drawRect(x, y, w, h);
extern int m_scrollBarSubLineWidth;
WidgetLookup m_widgetLookup;
Animations m_animations;
@ -265,8 +267,8 @@ static TQColorGroup::ColorRole backgroundModeToColorRole(TQt::BackgroundMode mod
return ret;
}
void gtkScaleToSliderCeData(GtkScale* scaleWidget, TQStyleControlElementData &ceData) {
GtkAdjustment* adjustment = gtk_range_get_adjustment(GTK_RANGE(scaleWidget));
void gtkRangeToCeData(GtkRange* rangeWidget, TQStyleControlElementData &ceData) {
GtkAdjustment* adjustment = gtk_range_get_adjustment(rangeWidget);
ceData.minSteps = gtk_adjustment_get_lower(adjustment);
ceData.maxSteps = gtk_adjustment_get_upper(adjustment);
@ -276,6 +278,10 @@ void gtkScaleToSliderCeData(GtkScale* scaleWidget, TQStyleControlElementData &ce
// ceData.startStep =
ceData.lineStep = gtk_adjustment_get_step_increment(adjustment);
ceData.pageStep = gtk_adjustment_get_page_increment(adjustment);
}
void gtkScaleToSliderCeData(GtkScale* scaleWidget, TQStyleControlElementData &ceData) {
gtkRangeToCeData(GTK_RANGE(scaleWidget), ceData);
// GtkPositionType valuePosition = gtk_scale_get_value_pos(scaleWidget);
// if (valuePosition == GTK_POS_LEFT) {
@ -390,12 +396,20 @@ tdegtk_draw_arrow (GtkThemingEngine *engine,
gdouble y,
gdouble size)
{
cairo_save(cr);
cairo_reset_clip(cr);
TQRect boundingRect(0, 0, size, size);
TQt3CairoPaintDevice pd(NULL, x, y, size, size, cr);
TQPainter p(&pd);
TQt3CairoPaintDevice *pd = NULL;
TQPainter *p = NULL;
const GtkWidgetPath* path;
GtkStateFlags state;
GtkWidget* widget;
path = gtk_theming_engine_get_path(engine);
state = gtk_theming_engine_get_state(engine);
widget = m_widgetLookup.find(cr, path);
GtkArrowType arrow_direction;
@ -417,16 +431,64 @@ tdegtk_draw_arrow (GtkThemingEngine *engine,
objectTypes.append(TQSCROLLBAR_OBJECT_NAME_STRING);
TQPalette objectPalette = tqApp->palette(objectTypes);
GtkRange* rangeWidget = GTK_RANGE(widget);
TQStyleControlElementData ceData;
TQStyle::ControlElementFlags elementFlags;
ceData.widgetObjectTypes = objectTypes;
ceData.rect = boundingRect;
ceData.orientation = ((arrow_direction == GTK_ARROW_UP) || (arrow_direction == GTK_ARROW_DOWN))?TQt::Vertical:TQt::Horizontal;
bool subline = ((arrow_direction == GTK_ARROW_DOWN) || (arrow_direction == GTK_ARROW_RIGHT))?false:true;
bool combine_addlineregion_drawing_areas = tqApp->style().styleHint(TQStyle::SH_ScrollBar_CombineAddLineRegionDrawingAreas);
const GtkAllocation allocation = Gtk::gtk_widget_get_allocation(widget);
TQStyle::SFlags sflags = gtkToTQtStyleFlags(engine, state, TQT3WT_NONE);
sflags = sflags | ((ceData.orientation == TQt::Horizontal)?TQStyle::Style_Horizontal:TQStyle::Style_Default);
if (combine_addlineregion_drawing_areas) {
int newx = x;
int newy = y;
int neww = size;
int newh = size;
if (!subline) {
if (ceData.orientation == TQt::Horizontal) {
if ((x+m_scrollBarSubLineWidth) == allocation.width) {
newx = x-m_scrollBarSubLineWidth;
}
boundingRect.setWidth(m_scrollBarSubLineWidth*2);
neww = m_scrollBarSubLineWidth*2;
}
else {
if ((y+m_scrollBarSubLineWidth) == allocation.height) {
newy = y-m_scrollBarSubLineWidth;
}
boundingRect.setHeight(m_scrollBarSubLineWidth*2);
newh = m_scrollBarSubLineWidth*2;
}
}
pd = new TQt3CairoPaintDevice(NULL, newx, newy, neww, newh, cr);
p = new TQPainter(pd);
if (!subline) {
if (ceData.orientation == TQt::Horizontal) {
p->setClipRect(TQRect(0+m_scrollBarSubLineWidth, 0, m_scrollBarSubLineWidth, newh));
}
else {
p->setClipRect(TQRect(0, 0+m_scrollBarSubLineWidth, neww, m_scrollBarSubLineWidth));
}
}
}
else {
pd = new TQt3CairoPaintDevice(NULL, x, y, size, size, cr);
p = new TQPainter(pd);
}
ceData.rect = boundingRect;
gtkRangeToCeData(rangeWidget, ceData);
// Draw slider arrow buttons
TQRect scrollpagerect = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, ceData, elementFlags, (subline)?TQStyle::SC_ScrollBarSubLine:TQStyle::SC_ScrollBarAddLine, gtkToTQtStyleFlags(engine, state, TQT3WT_NONE));
TQRect scrollpagerect = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, ceData, elementFlags, (subline)?TQStyle::SC_ScrollBarSubLine:TQStyle::SC_ScrollBarAddLine, sflags);
if (ceData.orientation == TQt::Vertical) {
scrollpagerect.setY(ceData.rect.y());
scrollpagerect.setHeight(ceData.rect.height());
@ -435,9 +497,12 @@ tdegtk_draw_arrow (GtkThemingEngine *engine,
scrollpagerect.setX(ceData.rect.x());
scrollpagerect.setWidth(ceData.rect.width());
}
tqApp->style().drawPrimitive((subline)?TQStyle::PE_ScrollBarSubLine:TQStyle::PE_ScrollBarAddLine, &p, scrollpagerect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE) | ((ceData.orientation == TQt::Horizontal)?TQStyle::Style_Horizontal:TQStyle::Style_Default));
tqApp->style().drawPrimitive((subline)?TQStyle::PE_ScrollBarSubLine:TQStyle::PE_ScrollBarAddLine, p, scrollpagerect, gtkToTQtColorGroup(engine, state), sflags);
}
else {
pd = new TQt3CairoPaintDevice(NULL, x, y, size, size, cr);
p = new TQPainter(pd);
// Draw arrow
TQStyle::PrimitiveElement pe;
if (arrow_direction == GTK_ARROW_UP) {
@ -452,10 +517,18 @@ tdegtk_draw_arrow (GtkThemingEngine *engine,
else {
pe = TQStyle::PE_ArrowRight;
}
tqApp->style().drawPrimitive(pe, &p, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE));
tqApp->style().drawPrimitive(pe, p, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE));
}
p.end();
if (p) {
p->end();
delete p;
}
if (pd) {
delete pd;
}
cairo_restore(cr);
return;
@ -634,6 +707,9 @@ tdegtk_draw_common (DRAW_ARGS)
static void
tdegtk_draw_common_background (DRAW_ARGS)
{
cairo_save(cr);
cairo_reset_clip(cr);
TQRect boundingRect(0, 0, width, height);
TQt3CairoPaintDevice pd(NULL, x, y, width, height, cr);
TQPainter p(&pd);
@ -666,12 +742,16 @@ tdegtk_draw_common_background (DRAW_ARGS)
objectTypes.append(TQSCROLLBAR_OBJECT_NAME_STRING);
TQPalette objectPalette = tqApp->palette(objectTypes);
GtkRange* rangeWidget = GTK_RANGE(widget);
TQStyleControlElementData ceData;
TQStyle::ControlElementFlags elementFlags;
ceData.widgetObjectTypes = objectTypes;
ceData.rect = boundingRect;
ceData.orientation = (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_VERTICAL))?TQt::Vertical:TQt::Horizontal;
gtkRangeToCeData(rangeWidget, ceData);
// Draw frame
tqApp->style().drawPrimitive(TQStyle::PE_PanelLineEdit, &p, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE) | ((ceData.orientation == TQt::Horizontal)?TQStyle::Style_Horizontal:TQStyle::Style_Default));
}
@ -813,12 +893,12 @@ tdegtk_draw_common_background (DRAW_ARGS)
//bool mousedown = (state & GTK_STATE_FLAG_SELECTED) != 0;
bool mousedown = (state & GTK_STATE_FLAG_ACTIVE) != 0;
GtkScale* scaleWidget = GTK_SCALE(widget);
TQStringList objectTypes;
objectTypes.append(TQSLIDER_OBJECT_NAME_STRING);
TQPalette objectPalette = tqApp->palette(objectTypes);
GtkScale* scaleWidget = GTK_SCALE(widget);
TQStyleControlElementData ceData;
TQStyle::ControlElementFlags elementFlags;
ceData.widgetObjectTypes = objectTypes;
@ -857,6 +937,8 @@ tdegtk_draw_common_background (DRAW_ARGS)
}
p.end();
cairo_restore(cr);
}
static void
@ -885,12 +967,16 @@ tdegtk_draw_common_frame (DRAW_ARGS)
TQStringList objectTypes;
objectTypes.append(TQSCROLLBAR_OBJECT_NAME_STRING);
TQPalette objectPalette = tqApp->palette(objectTypes);
GtkRange* rangeWidget = GTK_RANGE(widget);
TQStyleControlElementData ceData;
TQStyle::ControlElementFlags elementFlags;
ceData.widgetObjectTypes = objectTypes;
ceData.rect = boundingRect;
ceData.orientation = ((gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_VERTICAL))?TQt::Vertical:TQt::Horizontal);
gtkRangeToCeData(rangeWidget, ceData);
// Draw background
// HACK
@ -910,8 +996,24 @@ tdegtk_draw_common_frame (DRAW_ARGS)
}
else {
if (gtk_widget_path_is_type(path, GTK_TYPE_BUTTON)) {
// Draw frame
tqApp->style().drawPrimitive(TQStyle::PE_ButtonBevel, &p, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_TQPushButton));
if (Gtk::gtk_widget_path_has_type(path, GTK_TYPE_TOOLBAR)) {
// Draw frame
tqApp->style().drawPrimitive(TQStyle::PE_ButtonTool, &p, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_TQPushButton));
}
else if (Gtk::gtk_widget_path_has_type(path, GTK_TYPE_TREE_VIEW)) {
// Draw frame
tqApp->style().drawPrimitive(TQStyle::PE_HeaderSection, &p, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE));
}
else {
if (gtk_widget_has_default(widget)) {
// Draw frame
tqApp->style().drawPrimitive(TQStyle::PE_ButtonDefault, &p, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_TQPushButton));
}
else {
// Draw frame
tqApp->style().drawPrimitive(TQStyle::PE_ButtonCommand, &p, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_TQPushButton));
}
}
}
else if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_MENUITEM)) {
@ -984,9 +1086,6 @@ tdegtk_draw_common_frame (DRAW_ARGS)
}
else if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_TOOLTIP)) {
GtkFrame* frame = GTK_FRAME(widget);
GtkShadowType gtkShadowType = gtk_frame_get_shadow_type(frame);
TQStringList objectTypes;
objectTypes.append(TQTOOLTIP_OBJECT_NAME_STRING);
TQPalette objectPalette = tqApp->palette(objectTypes);
@ -1664,6 +1763,9 @@ static void
tdegtk_draw_slider (DRAW_ARGS,
GtkOrientation orientation)
{
cairo_save(cr);
cairo_reset_clip(cr);
TQRect boundingRect(0, 0, width, height);
TQt3CairoPaintDevice pd(NULL, x, y, width, height, cr);
TQPainter p(&pd);
@ -1681,12 +1783,16 @@ tdegtk_draw_slider (DRAW_ARGS,
objectTypes.append(TQSCROLLBAR_OBJECT_NAME_STRING);
TQPalette objectPalette = tqApp->palette(objectTypes);
GtkRange* rangeWidget = GTK_RANGE(widget);
TQStyleControlElementData ceData;
TQStyle::ControlElementFlags elementFlags;
ceData.widgetObjectTypes = objectTypes;
ceData.rect = boundingRect;
ceData.orientation = (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_VERTICAL))?TQt::Vertical:TQt::Horizontal;
gtkRangeToCeData(rangeWidget, ceData);
// Draw slider
TQRect scrollpagerect = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, ceData, elementFlags, TQStyle::SC_ScrollBarSlider, gtkToTQtStyleFlags(engine, state, TQT3WT_NONE));
if (ceData.orientation == TQt::Vertical) {
@ -1701,7 +1807,6 @@ tdegtk_draw_slider (DRAW_ARGS,
}
else if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_SCALE)) {
//bool mousedown = (state & GTK_STATE_FLAG_SELECTED) != 0;
bool mousedown = (state & GTK_STATE_FLAG_ACTIVE) != 0;
TQStringList objectTypes;
@ -1713,13 +1818,20 @@ tdegtk_draw_slider (DRAW_ARGS,
TQStyleControlElementData ceData;
TQStyle::ControlElementFlags elementFlags;
ceData.widgetObjectTypes = objectTypes;
ceData.rect = boundingRect;
ceData.orientation = (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_VERTICAL))?TQt::Vertical:TQt::Horizontal;
// HACK
// GTK3 or TQt3 (not sure which) does not draw the slider in the correct location!
boundingRect = TQRect((ceData.orientation == TQt::Horizontal)?2:0, (ceData.orientation == TQt::Horizontal)?0:2, width, height);
TQt3CairoPaintDevice pd2(NULL, x, y, width, height, cr);
TQPainter p2(&pd2);
ceData.rect = boundingRect;
gtkScaleToSliderCeData(scaleWidget, ceData);
// Draw item
tqApp->style().drawComplexControl(TQStyle::CC_Slider, &p, ceData, elementFlags, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_TQSlider) | ((ceData.orientation == TQt::Horizontal)?TQStyle::Style_Horizontal:TQStyle::Style_Default), TQStyle::SC_SliderHandle, ((mousedown)?TQStyle::SC_SliderHandle:TQStyle::SC_None));
tqApp->style().drawComplexControl(TQStyle::CC_Slider, &p2, ceData, elementFlags, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_TQSlider) | ((ceData.orientation == TQt::Horizontal)?TQStyle::Style_Horizontal:TQStyle::Style_Default), TQStyle::SC_SliderHandle, ((mousedown)?TQStyle::SC_SliderHandle:TQStyle::SC_None));
}
else {
@ -1728,6 +1840,8 @@ tdegtk_draw_slider (DRAW_ARGS,
}
p.end();
cairo_restore(cr);
}
static void

@ -76,14 +76,5 @@ tdegtk_trim_scale_allocation (GtkThemingEngine *engine,
gdouble *width,
gdouble *height)
{
if (!gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_VERTICAL))
{
*y += (gint) (*height / 2.0) - 2.0;
*height = 5;
}
else
{
*x += (gint) (*width / 2.0) - 2.0;
*width = 5;
}
// Do nothing!
}

@ -41,6 +41,8 @@ bool tde_showIconsOnPushButtons = false;
void initTDESettings();
void writeGtkThemeControlFile(int forceRecreate);
int m_scrollBarSubLineWidth = -1;
extern "C" {
#include <gmodule.h>
#include <gtk/gtk.h>
@ -603,26 +605,28 @@ void writeGtkThemeControlFile(int forceRecreate) {
stream << parse_rc_string(TQString("-GtkScrollbar-has-secondary-forward-stepper: ") + (forward1 ? "1" : "0"), "*");
stream << parse_rc_string(TQString("-GtkScrollbar-has-secondary-backward-stepper: ") + (back2 ? "1" : "0"), "*");
stream << parse_rc_string("-GtkScrollbar-stepper-size: " + TQString::number(tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, &sbar, TQStyle::SC_ScrollBarSubLine).width() - 1), "*");
m_scrollBarSubLineWidth = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, &sbar, TQStyle::SC_ScrollBarSubLine).width() - 1;
stream << parse_rc_string("-GtkScrollbar-min-slider-length: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ScrollBarSliderMin)), "*");
stream << parse_rc_string("-GtkRange-stepper-size: " + TQString::number(m_scrollBarSubLineWidth), "GtkScrollbar");
stream << parse_rc_string("-GtkRange-slider-width: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ScrollBarExtent)), "GtkScrollbar");
stream << parse_rc_string("-GtkRange-stepper-size: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ScrollBarExtent)), "GtkScrollbar");
stream << parse_rc_string("-GtkRange-trough-border: 0", "GtkScrollbar");
stream << parse_rc_string("-GtkRange-trough-under-steppers: 1", "GtkScrollbar");
stream << parse_rc_string("-GtkScrollbar-min-slider-length: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ScrollBarSliderMin)), "*");
{
//stream << parse_rc_string("-GtkRange-slider-width: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_SliderControlThickness, ceData, elementFlags)), "GtkScale");
//stream << parse_rc_string("-GtkRange-stepper-size: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_SliderControlThickness)), "GtkScale");
// FIXME
// This is currently set to the scrollbar stepper button size, as TQt3 does not have the concept of a stepper for a TQSlider
stream << parse_rc_string("-GtkRange-stepper-size: " + TQString::number(m_scrollBarSubLineWidth), "GtkScale");
// FIXME
// These are hardcoded for now as TQt3 does not easily give up its slider sizes
// We need to read the Gtk slider width for this to make any sense!
// Also, GTK does not seem to be able to set a minimum slider length at this time
stream << parse_rc_string("-GtkRange-slider-width: " + TQString::number(20), "GtkScale");
}
TQSlider slider(NULL); // To keep BlueCurve happy
stream << parse_rc_string("-GtkRange-slider-width: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_SliderThickness, &slider)), "GtkScale");
stream << parse_rc_string("-GtkScale-slider-length: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_SliderLength, &slider)), "*");
stream << parse_rc_string("-GtkButton-child-displacement-x: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ButtonShiftHorizontal)), "*");
stream << parse_rc_string("-GtkButton-child-displacement-y: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ButtonShiftVertical)), "*");
stream << parse_rc_string("-GtkRange-arrow-displacement-x: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ButtonShiftHorizontal)), "*");
stream << parse_rc_string("-GtkRange-arrow-displacement-y: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_ButtonShiftVertical)), "*");
stream << parse_rc_string("-GtkRange-arrow-displacement-x: " + TQString::number(0), "GtkScrollbar");
stream << parse_rc_string("-GtkRange-arrow-displacement-y: " + TQString::number(0), "GtkScrollbar");
stream << parse_rc_string("-GtkButton-default-border: 0 0 0 0", "*");
stream << parse_rc_string("-GtkButton-default-outside-border: 0 0 0 0", "*");
#ifdef USE_NATIVE_GTK_BUTTON_DRAWING
@ -640,9 +644,6 @@ void writeGtkThemeControlFile(int forceRecreate) {
stream << parse_rc_string("-GtkButtonBox-child_internal_pad_x: 0", "*");
stream << parse_rc_string("-GtkButtonBox-child_internal_pad_y: 0", "*");
TQSlider slider(NULL); // To keep BlueCurve happy
stream << parse_rc_string("-GtkScale-slider-length: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_SliderLength, &slider)), "*");
stream << parse_rc_string("-GtkRange-arrow-scaling: 1.0", "GtkScrollbar");
stream << parse_rc_string("-xthickness: " + TQString::number(tqApp->style().pixelMetric(TQStyle::PM_DefaultFrameWidth)), "*.GtkMenu");
@ -704,6 +705,11 @@ void writeGtkThemeControlFile(int forceRecreate) {
stream << parse_rc_string("padding: " + TQString::number(0) + "px " + TQString::number(0) + "px", "GtkList>*>GtkButton");
stream << parse_rc_string("border-width: " + TQString::number(0) + "px " + TQString::number(0) + "px", "GtkList>*>GtkButton");
// Ensure group boxes are not cut off by their labels
// FIXME
// Where do these 2px values actually come from?
stream << parse_rc_string("padding: " + TQString::number(2) + "px " + TQString::number(2) + "px", "GtkFrame");
// Separators appear to be hardcoded to 1px high in TQt3
// Anything else will cause a silent drawing failure!
stream << parse_rc_string("-GtkWidget-separator-height: " + TQString::number(1), "*");

Loading…
Cancel
Save