From 76f5e2671f3a61225a730e3d9699833ae3bec6f2 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Mon, 5 Nov 2012 17:21:22 -0600 Subject: Fix mask transforms Use full TQt3 progress bar drawing code --- tdegtk/tdegtk-draw.cpp | 250 ++++++++++++++++++++++++++++++------------------- 1 file changed, 152 insertions(+), 98 deletions(-) (limited to 'tdegtk/tdegtk-draw.cpp') diff --git a/tdegtk/tdegtk-draw.cpp b/tdegtk/tdegtk-draw.cpp index 36244e6..50e8eb3 100644 --- a/tdegtk/tdegtk-draw.cpp +++ b/tdegtk/tdegtk-draw.cpp @@ -301,6 +301,116 @@ void gtkScaleToSliderCeData(GtkScale* scaleWidget, TQStyleControlElementData &ce // } } +static void +draw_combobox_frame(DRAW_ARGS, const GtkWidgetPath* path, GtkStateFlags state, GtkWidget* widget) { + cairo_save(cr); + + cairo_matrix_t gtk_matrix; + cairo_get_matrix(cr, >k_matrix); + gtk_matrix.x0 = 0; + gtk_matrix.y0 = 0; + cairo_set_matrix(cr, >k_matrix); + + GtkWidget* parent(widget?gtk_widget_get_parent(widget):0L); + if (GTK_IS_COMBO_BOX(parent)) { + const GtkAllocation allocation = Gtk::gtk_widget_get_allocation(parent); + TQRect boundingRect(0, 0, allocation.width, allocation.height); + TQt3CairoPaintDevice pd2(NULL, allocation.x, allocation.y, allocation.width, allocation.height, cr); + TQPainter p2(&pd2); + + TQStringList objectTypes; + objectTypes.append(TQCOMBOBOX_OBJECT_NAME_STRING); + TQPalette objectPalette = tqApp->palette(objectTypes); + + TQStyleControlElementData ceData; + TQStyle::ControlElementFlags elementFlags; + ceData.widgetObjectTypes = objectTypes; + ceData.orientation = (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_VERTICAL))?TQt::Vertical:TQt::Horizontal; + + if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_ENTRY)) { + elementFlags = elementFlags | TQStyle::CEF_IsEditable; + } + + ceData.rect = boundingRect; + + // Draw item + tqApp->style().drawComplexControl(TQStyle::CC_ComboBox, &p2, ceData, elementFlags, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE), TQStyle::SC_ComboBoxFrame, TQStyle::SC_None); + } + + cairo_restore(cr); +} + +static void +draw_progressbar_frame(DRAW_ARGS, const GtkWidgetPath* path, GtkStateFlags state, GtkWidget* widget) { + cairo_save(cr); + + cairo_matrix_t gtk_matrix; + cairo_get_matrix(cr, >k_matrix); + gtk_matrix.x0 = 0; + gtk_matrix.y0 = 0; + cairo_set_matrix(cr, >k_matrix); + + if (GTK_IS_PROGRESS_BAR(widget)) { + const GtkAllocation allocation = Gtk::gtk_widget_get_allocation(widget); + TQRect boundingRect(0, 0, allocation.width, allocation.height); + TQt3CairoPaintDevice pd2(NULL, allocation.x, allocation.y, allocation.width, allocation.height, cr); + TQPainter p2(&pd2); + + TQStringList objectTypes; + objectTypes.append(TQPROGRESSBAR_OBJECT_NAME_STRING); + TQPalette objectPalette = tqApp->palette(objectTypes); + + 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; + + GtkProgressBar* progressBar = GTK_PROGRESS_BAR(widget); + gdouble gtkProgressBarFraction = gtk_progress_bar_get_fraction(progressBar); + ceData.totalSteps = 8192; + ceData.currentStep = gtkProgressBarFraction*8192; + + TQStyle::SFlags sflags = gtkToTQtStyleFlags(engine, state, TQT3WT_NONE); + sflags = sflags | ((ceData.orientation == TQt::Horizontal)?TQStyle::Style_Horizontal:TQStyle::Style_Default); + + if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_VERTICAL)) { + // If vertical, apply a 90 degree rotation matrix to the painter + // This is required to make TQt draw a vertical progress bar + + TQWMatrix m; + +// // Upside down +// m.rotate(90.0); +// m.translate(0, (allocation.width)*(-1.0)); + + // Right side up + m.rotate(-90.0); + m.translate((allocation.height)*(-1.0), 0); + + p2.setWorldMatrix(m, TRUE); + + boundingRect = TQRect(0, 0, allocation.height, allocation.width); + ceData.rect = boundingRect; + } + + TQRect progressBarGrooveRect = TQStyle::visualRect(tqApp->style().subRect(TQStyle::SR_ProgressBarGroove, ceData, elementFlags, NULL), ceData, elementFlags); + TQRect progressBarContentsRect = TQStyle::visualRect(tqApp->style().subRect(TQStyle::SR_ProgressBarContents, ceData, elementFlags, NULL), ceData, elementFlags); + + // Draw background + TQBrush brush = objectPalette.brush(gtkToTQPaletteColorGroup(engine, state), TQColorGroup::Base); + DRAW_FILLED_RECTANGLE_OVER_ENTIRE_AREA(p2, brush) + + // Draw frame + tqApp->style().drawControl(TQStyle::CE_ProgressBarGroove, &p2, ceData, elementFlags, progressBarGrooveRect, ((state & GTK_STATE_FLAG_INSENSITIVE)?objectPalette.disabled():objectPalette.active()), sflags); + + // Draw contents + tqApp->style().drawControl(TQStyle::CE_ProgressBarContents, &p2, ceData, elementFlags, progressBarContentsRect, ((state & GTK_STATE_FLAG_INSENSITIVE)?objectPalette.disabled():objectPalette.active()), sflags); + } + + cairo_restore(cr); +} + /* draw a texture placed on the centroid */ static gboolean draw_centroid_texture (GtkThemingEngine *engine, @@ -364,6 +474,7 @@ tdegtk_draw_activity (DRAW_ARGS) widget = m_widgetLookup.find(cr, path); if (gtk_widget_path_is_type(path, GTK_TYPE_PROGRESS_BAR)) { +#if 0 TQStringList objectTypes; objectTypes.append(TQPROGRESSBAR_OBJECT_NAME_STRING); TQPalette objectPalette = tqApp->palette(objectTypes); @@ -381,6 +492,9 @@ tdegtk_draw_activity (DRAW_ARGS) // Draw item tqApp->style().drawControl(TQStyle::CE_ProgressBarContents, &p, ceData, elementFlags, progressBarRect, ((state & GTK_STATE_FLAG_INSENSITIVE)?objectPalette.disabled():objectPalette.active()), sflags); +#else + // Do nothing +#endif } else { @@ -509,6 +623,11 @@ tdegtk_draw_arrow (GtkThemingEngine *engine, } tqApp->style().drawPrimitive((subline)?TQStyle::PE_ScrollBarSubLine:TQStyle::PE_ScrollBarAddLine, p, scrollpagerect, gtkToTQtColorGroup(engine, state), sflags); } + + else if (Gtk::gtk_widget_path_has_type(path, GTK_TYPE_COMBO_BOX)) { + // Do nothing + } + else { pd = new TQt3CairoPaintDevice(NULL, x, y, size, size, cr); p = new TQPainter(pd); @@ -583,6 +702,10 @@ tdegtk_draw_cell_background (DRAW_ARGS, tqApp->style().drawComplexControl(TQStyle::CC_ListView, &p, ceData, elementFlags, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE), TQStyle::SC_ListView, TQStyle::SC_All, listViewItemOpt); } + // FIXME + // GtkCellRenderer backgrounds should be drawn here, however GTK3 does not provide any means for a GtkCellRenderer to call style engine methods! + // See upstream GTK bug #687677 + else { DEBUG_FILL_BACKGROUND_WITH_COLOR(p,255,128,64); printf("[WARNING] tdegtk_draw_cell_background() nonfunctional for widget with path '%s'\n\r", gtk_widget_path_to_string (gtk_theming_engine_get_path(engine))); fflush(stdout); @@ -699,22 +822,7 @@ tdegtk_draw_common_background (DRAW_ARGS) state = gtk_theming_engine_get_state(engine); widget = m_widgetLookup.find(cr, path); - if ((gtk_widget_path_is_type(path, GTK_TYPE_ENTRY)) - || (gtk_widget_path_is_type(path, GTK_TYPE_TEXT_VIEW)) - || (gtk_widget_path_is_type(path, GTK_TYPE_TEXT_BUFFER)) - || (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_ENTRY)) - || (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_COMBOBOX_ENTRY)) - ) { - TQStringList objectTypes; - objectTypes.append(TQLINEEDIT_OBJECT_NAME_STRING); - TQPalette objectPalette = tqApp->palette(objectTypes); - - // Draw background - TQBrush brush = objectPalette.brush(gtkToTQPaletteColorGroup(engine, state), TQColorGroup::Base); - DRAW_FILLED_RECTANGLE_OVER_ENTIRE_AREA(p, brush) - } - - else if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_SCROLLBAR)) { + if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_SCROLLBAR)) { TQStringList objectTypes; objectTypes.append(TQSCROLLBAR_OBJECT_NAME_STRING); TQPalette objectPalette = tqApp->palette(objectTypes); @@ -733,6 +841,25 @@ tdegtk_draw_common_background (DRAW_ARGS) 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)); } + else if ((gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_FRAME) || gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_ENTRY) || gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_BUTTON)) && (Gtk::gtk_widget_path_has_type(path, GTK_TYPE_COMBO_BOX))) { + draw_combobox_frame(engine, cr, x, y, width, height, path, state, widget); + } + + else if ((gtk_widget_path_is_type(path, GTK_TYPE_ENTRY)) + || (gtk_widget_path_is_type(path, GTK_TYPE_TEXT_VIEW)) + || (gtk_widget_path_is_type(path, GTK_TYPE_TEXT_BUFFER)) + || (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_ENTRY)) + || (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_COMBOBOX_ENTRY)) + ) { + TQStringList objectTypes; + objectTypes.append(TQLINEEDIT_OBJECT_NAME_STRING); + TQPalette objectPalette = tqApp->palette(objectTypes); + + // Draw background + TQBrush brush = objectPalette.brush(gtkToTQPaletteColorGroup(engine, state), TQColorGroup::Base); + DRAW_FILLED_RECTANGLE_OVER_ENTIRE_AREA(p, brush) + } + #if 0 else if (Gtk::gtk_widget_path_has_type(path, GTK_TYPE_COMBO_BOX)) { bool mousedown = (state & GTK_STATE_FLAG_ACTIVE) != 0; @@ -995,29 +1122,11 @@ tdegtk_draw_common_frame (DRAW_ARGS) tqApp->style().drawPrimitive(TQStyle::PE_ScrollBarAddPage, &p, scrollpagerect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE)); } } -#if 0 - else if (Gtk::gtk_widget_path_has_type(path, GTK_TYPE_COMBO_BOX)) { - bool mousedown = (state & GTK_STATE_FLAG_ACTIVE) != 0; - TQStringList objectTypes; - objectTypes.append(TQCOMBOBOX_OBJECT_NAME_STRING); - TQPalette objectPalette = tqApp->palette(objectTypes); - - TQStyleControlElementData ceData; - TQStyle::ControlElementFlags elementFlags; - ceData.widgetObjectTypes = objectTypes; - ceData.orientation = (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_VERTICAL))?TQt::Vertical:TQt::Horizontal; - - if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_ENTRY)) { - elementFlags = elementFlags | TQStyle::CEF_IsEditable; - } - - ceData.rect = boundingRect; - - // Draw item - tqApp->style().drawComplexControl(TQStyle::CC_ComboBox, &p, ceData, elementFlags, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE), TQStyle::SC_ComboBoxFrame, TQStyle::SC_None); + else if ((gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_FRAME) || gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_ENTRY) || gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_BUTTON)) && (Gtk::gtk_widget_path_has_type(path, GTK_TYPE_COMBO_BOX))) { + draw_combobox_frame(engine, cr, x, y, width, height, path, state, widget); } -#endif + else { if (gtk_widget_path_is_type(path, GTK_TYPE_BUTTON)) { if (Gtk::gtk_widget_path_has_type(path, GTK_TYPE_TOOLBAR)) { @@ -1125,29 +1234,7 @@ tdegtk_draw_common_frame (DRAW_ARGS) } else if (gtk_widget_path_is_type(path, GTK_TYPE_PROGRESS_BAR)) { - TQStringList objectTypes; - objectTypes.append(TQPROGRESSBAR_OBJECT_NAME_STRING); - TQPalette objectPalette = tqApp->palette(objectTypes); - - 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; - - GtkProgressBar* progressBar = GTK_PROGRESS_BAR(widget); - gdouble gtkProgressBarFraction = gtk_progress_bar_get_fraction(progressBar); - ceData.totalSteps = 8192; - ceData.currentStep = gtkProgressBarFraction*8192; - - TQRect progressBarRect = TQStyle::visualRect(tqApp->style().subRect(TQStyle::SR_ProgressBarGroove, ceData, elementFlags, NULL), ceData, elementFlags); - - // Draw background - TQBrush brush = objectPalette.brush(gtkToTQPaletteColorGroup(engine, state), TQColorGroup::Base); - DRAW_FILLED_RECTANGLE_OVER_ENTIRE_AREA(p, brush) - - // Draw item - tqApp->style().drawControl(TQStyle::CE_ProgressBarGroove, &p, ceData, elementFlags, progressBarRect, ((state & GTK_STATE_FLAG_INSENSITIVE)?objectPalette.disabled():objectPalette.active()), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE) | ((ceData.orientation == TQt::Horizontal)?TQStyle::Style_Horizontal:TQStyle::Style_Default)); + draw_progressbar_frame(engine, cr, x, y, width, height, path, state, widget); } else if (gtk_widget_path_is_type(path, GTK_TYPE_IMAGE)) { @@ -1365,7 +1452,11 @@ tdegtk_draw_focus (DRAW_ARGS) state = gtk_theming_engine_get_state(engine); widget = m_widgetLookup.find(cr, path); - if ((gtk_widget_path_is_type(path, GTK_TYPE_ENTRY)) + if ((gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_FRAME) || gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_ENTRY) || gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_BUTTON)) && (Gtk::gtk_widget_path_has_type(path, GTK_TYPE_COMBO_BOX))) { + // Draw nothing! + } + + else if ((gtk_widget_path_is_type(path, GTK_TYPE_ENTRY)) || (gtk_widget_path_is_type(path, GTK_TYPE_TEXT_VIEW)) || (gtk_widget_path_is_type(path, GTK_TYPE_TEXT_BUFFER)) || (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_ENTRY)) @@ -1756,43 +1847,6 @@ tdegtk_draw_separator (DRAW_ARGS) } p.end(); - - return; - - gdouble line_width; - - tdegtk_get_line_width (engine, &line_width); - - if (line_width == 0) - return; - - /* FIXME right code should be - * if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_VERTICAL)) - * but doesn't work for separator tool item. */ - if (width > height) - { - cairo_move_to (cr, x, y + (gint) (height / 2) + line_width / 2); - cairo_line_to (cr, x + width, y + (gint) (height / 2) + line_width / 2); - tdegtk_cairo_set_source_inner_stroke (engine, cr, width, line_width); - cairo_stroke (cr); - - cairo_move_to (cr, x, y + (gint) (height / 2) - line_width / 2); - cairo_line_to (cr, x + width, y + (gint) (height / 2) - line_width / 2); - tdegtk_cairo_set_source_border (engine, cr, width, line_width); - cairo_stroke (cr); - } - else - { - cairo_move_to (cr, x + (gint) (width / 2) + line_width / 2, y); - cairo_line_to (cr, x + (gint) (width / 2) + line_width / 2, y + height); - tdegtk_cairo_set_source_inner_stroke (engine, cr, line_width, height); - cairo_stroke (cr); - - cairo_move_to (cr, x + (gint) (width / 2) - line_width / 2, y); - cairo_line_to (cr, x + (gint) (width / 2) - line_width / 2, y + height); - tdegtk_cairo_set_source_border (engine, cr, line_width, height); - cairo_stroke (cr); - } } static void -- cgit v1.2.1