diff options
author | Timothy Pearson <[email protected]> | 2012-11-10 23:48:33 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2012-11-10 23:48:33 -0600 |
commit | ec156de9735a1b6183a0bede86986e132d080594 (patch) | |
tree | 4ed7d668b2d38024484288b172622cc976fc991d /tdegtk/tdegtk-draw.cpp | |
parent | cf8d4ef895903edde76148ebf4ca9876bcf42d26 (diff) | |
download | gtk3-tqt-engine-ec156de9735a1b6183a0bede86986e132d080594.tar.gz gtk3-tqt-engine-ec156de9735a1b6183a0bede86986e132d080594.zip |
Draw sliders with TQt3 methods
Diffstat (limited to 'tdegtk/tdegtk-draw.cpp')
-rw-r--r-- | tdegtk/tdegtk-draw.cpp | 263 |
1 files changed, 235 insertions, 28 deletions
diff --git a/tdegtk/tdegtk-draw.cpp b/tdegtk/tdegtk-draw.cpp index 79f9d47..169c2f7 100644 --- a/tdegtk/tdegtk-draw.cpp +++ b/tdegtk/tdegtk-draw.cpp @@ -64,6 +64,8 @@ extern int m_scrollBarSubLineWidth; WidgetLookup m_widgetLookup; Animations m_animations; +//#define DRAW_SCROLLBAR_PIECES_INSTEAD_OF_ENTIRE_BAR 1 + // Keep this in sync with gtkToTQPaletteColorGroup() below static TQColorGroup gtkToTQtColorGroup(GtkThemingEngine* engine, GtkStateFlags state) { // GdkRGBA *background_color; @@ -122,7 +124,8 @@ static TQStyle::SFlags gtkToTQtStyleFlags(GtkThemingEngine* engine, GtkStateFlag has_focus = gtk_widget_has_visible_focus(widget); if ((wt == TQT3WT_TQRadioButton) || (wt == TQT3WT_TQCheckBox) || (wt == TQT3WT_TQPushButton)) { - if (!inconsistent) { + GtkCheckButton* checkButton = (widget)?((GTK_IS_CHECK_BUTTON(widget))?GTK_CHECK_BUTTON(widget):0L):0L; + if ((!inconsistent) && (!mousedown)) { if (active) { sflags |= TQStyle::Style_On; } @@ -132,6 +135,9 @@ static TQStyle::SFlags gtkToTQtStyleFlags(GtkThemingEngine* engine, GtkStateFlag } if (mousedown) { sflags |= TQStyle::Style_Down; + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkButton))) { + sflags |= TQStyle::Style_On; + } } if (prelight) { sflags |= TQStyle::Style_MouseOver; @@ -223,7 +229,7 @@ static TQStyle::SFlags gtkToTQtStyleFlags(GtkThemingEngine* engine, GtkStateFlag } } else if (wt == TQT3WT_TQSlider) { - if (mousedown) { + if (active) { sflags |= TQStyle::Style_Active; } if (prelight) { @@ -239,6 +245,41 @@ static TQStyle::SFlags gtkToTQtStyleFlags(GtkThemingEngine* engine, GtkStateFlag sflags |= TQStyle::Style_HasFocus; } } + else if (wt == TQT3WT_TQScrollBar) { + if (active) { + sflags |= TQStyle::Style_Active; + } + if (prelight) { + sflags |= TQStyle::Style_MouseOver; + } + if (focused) { + sflags |= TQStyle::Style_HasFocus; + } + if (!disabled) { + sflags |= TQStyle::Style_Enabled; + } + if (has_focus) { + sflags |= TQStyle::Style_HasFocus; + } + } + else if (wt == TQT3WT_TQLineEdit) { + if (active) { + sflags |= TQStyle::Style_Down; + } + if (prelight) { + sflags |= TQStyle::Style_MouseOver; + } + if (focused) { + sflags |= TQStyle::Style_HasFocus; + } + if (!disabled) { + sflags |= TQStyle::Style_Enabled; + } + if (has_focus) { + sflags |= TQStyle::Style_HasFocus; + } + sflags |= TQStyle::Style_Sunken; + } else { if (active) { sflags |= TQStyle::Style_Down; @@ -352,6 +393,32 @@ void gtkScaleToSliderCeData(GtkScale* scaleWidget, TQStyleControlElementData &ce // } } +void gtkScrollbarToScrollbarCeData(GtkScrollbar* scrollbarWidget, TQStyleControlElementData &ceData) { + GtkRange* rangeWidget = GTK_RANGE(scrollbarWidget); + gtkRangeToCeData(rangeWidget, ceData); + + gint slider_start_pos; + gint slider_end_pos; + GtkAdjustment* adjustment = gtk_range_get_adjustment(rangeWidget); + gtk_range_get_slider_range(rangeWidget, &slider_start_pos, &slider_end_pos); + + ceData.minSteps = gtk_adjustment_get_lower(adjustment); + ceData.maxSteps = (gtk_adjustment_get_upper(adjustment)-(gtk_adjustment_get_page_increment(adjustment)+gtk_adjustment_get_step_increment(adjustment))); + ceData.currentStep = gtk_adjustment_get_value(adjustment); + ceData.startStep = slider_start_pos; + ceData.lineStep = gtk_adjustment_get_step_increment(adjustment); + ceData.pageStep = gtk_adjustment_get_page_increment(adjustment); + + // Convert the GTK slider length into a correct pagestep that TQt3 can use to obtain the same slider length value + TQStyle::ControlElementFlags elementFlags = TQStyle::CEF_None; + int gtkSliderLength = slider_end_pos - slider_start_pos; + uint range = ceData.maxSteps - ceData.minSteps; + int sbextent = tqApp->style().pixelMetric(TQStyle::PM_ScrollBarExtent, ceData, elementFlags, NULL); + int maxlen = ((ceData.orientation == TQt::Horizontal) ? ceData.rect.width() : ceData.rect.height()) - (sbextent * 2); + int gtkPageStep=ceil((-1.0)*(range*gtkSliderLength)/(gtkSliderLength-maxlen)); + ceData.pageStep = gtkPageStep; +} + static void draw_combobox_frame(DRAW_ARGS, const GtkWidgetPath* path, GtkStateFlags state, GtkWidget* widget) { cairo_save(cr); @@ -426,6 +493,7 @@ draw_progressbar_frame(DRAW_ARGS, const GtkWidgetPath* path, GtkStateFlags state gdouble gtkProgressBarFraction = gtk_progress_bar_get_fraction(progressBar); ceData.totalSteps = 8192; ceData.currentStep = gtkProgressBarFraction*8192; + ceData.percentageVisible = false; TQStyle::SFlags sflags = gtkToTQtStyleFlags(engine, state, TQT3WT_NONE, widget); sflags = sflags | ((ceData.orientation == TQt::Horizontal)?TQStyle::Style_Horizontal:TQStyle::Style_Default); @@ -492,12 +560,12 @@ draw_slider_frame(DRAW_ARGS, const GtkWidgetPath* path, GtkStateFlags state, Gtk GdkRectangle rangeRect; gtk_range_get_range_rect(GTK_RANGE(widget), &rangeRect); - TQRect boundingRect(0, 0, allocation.width, allocation.height); + TQRect boundingRect(0, 0, rangeRect.width, rangeRect.height); TQt3CairoPaintDevice pd2(NULL, allocation.x + rangeRect.x, allocation.y + rangeRect.y, rangeRect.width, rangeRect.height, cr); TQPainter p2(&pd2); - //bool mousedown = (state & GTK_STATE_FLAG_SELECTED) != 0; bool mousedown = (state & GTK_STATE_FLAG_ACTIVE) != 0; + bool prelight = (state & GTK_STATE_FLAG_PRELIGHT) != 0; GtkScale* scaleWidget = GTK_SCALE(widget); @@ -517,6 +585,14 @@ draw_slider_frame(DRAW_ARGS, const GtkWidgetPath* path, GtkStateFlags state, Gtk elementFlags = elementFlags | TQStyle::CEF_HasFocus; } + if (mousedown) { + elementFlags = elementFlags | TQStyle::CEF_IsActive; + } + + if (prelight) { + elementFlags = elementFlags | TQStyle::CEF_HasMouse; + } + // Draw item tqApp->style().drawComplexControl(TQStyle::CC_Slider, &p2, ceData, elementFlags, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_TQSlider, widget) | ((ceData.orientation == TQt::Horizontal)?TQStyle::Style_Horizontal:TQStyle::Style_Default), TQStyle::SC_All, ((mousedown)?TQStyle::SC_All:TQStyle::SC_None)); } @@ -525,6 +601,123 @@ draw_slider_frame(DRAW_ARGS, const GtkWidgetPath* path, GtkStateFlags state, Gtk } static void +draw_scrollbar_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_SCROLLBAR(widget)) { + const GtkAllocation allocation = Gtk::gtk_widget_get_allocation(widget); + + GdkRectangle rangeRect; + gtk_range_get_range_rect(GTK_RANGE(widget), &rangeRect); + + TQRect boundingRect(0, 0, rangeRect.width, rangeRect.height); + TQt3CairoPaintDevice pd2(NULL, allocation.x + rangeRect.x, allocation.y + rangeRect.y, rangeRect.width, rangeRect.height, cr); + TQPainter p2(&pd2); + + GtkStateFlags widgetStateFlags = gtk_widget_get_state_flags(widget); + + bool prelight = (state & GTK_STATE_FLAG_PRELIGHT) != 0; + + GtkScrollbar* scrollbarWidget = GTK_SCROLLBAR(widget); + + TQStringList objectTypes; + objectTypes.append(TQSLIDER_OBJECT_NAME_STRING); + TQPalette objectPalette = tqApp->palette(objectTypes); + + TQStyleControlElementData ceData; + TQStyle::ControlElementFlags elementFlags = TQStyle::CEF_None; + ceData.widgetObjectTypes = objectTypes; + ceData.rect = boundingRect; + ceData.orientation = (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_VERTICAL))?TQt::Vertical:TQt::Horizontal; + + gtkScrollbarToScrollbarCeData(scrollbarWidget, ceData); + + if (gtk_widget_has_visible_focus(widget)) { + elementFlags = elementFlags | TQStyle::CEF_HasFocus; + } + + if (prelight) { + elementFlags = elementFlags | TQStyle::CEF_HasMouse; + } + + TQStyle::SFlags sflags = gtkToTQtStyleFlags(engine, state, TQT3WT_TQScrollBar, widget); + sflags = sflags | ((ceData.orientation == TQt::Horizontal)?TQStyle::Style_Horizontal:TQStyle::Style_Default); + + if (gtk_widget_get_sensitive(widget)) { + sflags |= TQStyle::Style_Enabled; + state = (GtkStateFlags)(state & (~GTK_STATE_FLAG_INSENSITIVE)); + } + else { + sflags &= ~TQStyle::Style_Enabled; + state = (GtkStateFlags)(state | GTK_STATE_FLAG_INSENSITIVE); + } + + // Determine active subcontrols + gint cursor_x = -1; + gint cursor_y = -1; + TQStyle::SubControl activeSubControl = TQStyle::SC_None; + if (gtk_widget_get_realized(widget)) { + GdkDevice *device; + device = gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gtk_widget_get_display(widget))); + gdk_window_get_device_position(gtk_widget_get_window(widget), device, &cursor_x, &cursor_y, NULL); + cursor_x = cursor_x - allocation.x; + cursor_y = cursor_y - allocation.y; + + TQPoint cursor_pos(cursor_x, cursor_y); + TQRect addline, subline, addpage, subpage, slider, first, last; + subline = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, ceData, elementFlags, TQStyle::SC_ScrollBarSubLine); + addline = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, ceData, elementFlags, TQStyle::SC_ScrollBarAddLine); + subpage = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, ceData, elementFlags, TQStyle::SC_ScrollBarSubPage); + addpage = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, ceData, elementFlags, TQStyle::SC_ScrollBarAddPage); + slider = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, ceData, elementFlags, TQStyle::SC_ScrollBarSlider); + first = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, ceData, elementFlags, TQStyle::SC_ScrollBarFirst); + last = tqApp->style().querySubControlMetrics(TQStyle::CC_ScrollBar, ceData, elementFlags, TQStyle::SC_ScrollBarLast); + + // HACK + // This may not be 100% reliable, and it has the side effect of triggering the page step activity effect when the slider is dragged quickly and the mouse cursor momentarily pops out of the slider rectangle. + GdkModifierType mouseStateFlags; + gdk_device_get_state (device, gtk_widget_get_window(widget), NULL, &mouseStateFlags); + bool mousedown = (mouseStateFlags & GDK_BUTTON1_MASK); + + if (mousedown) { + if (subline.contains(cursor_pos)) { + activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarSubLine); + } + if (addline.contains(cursor_pos)) { + activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarAddLine); + } + if (subpage.contains(cursor_pos)) { + activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarSubPage); + } + if (addpage.contains(cursor_pos)) { + activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarAddPage); + } + if (slider.contains(cursor_pos)) { + activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarSlider); + } + if (first.contains(cursor_pos)) { + activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarFirst); + } + if (last.contains(cursor_pos)) { + activeSubControl = (TQStyle::SubControl)(activeSubControl | TQStyle::SC_ScrollBarLast); + } + } + } + + // Draw item + tqApp->style().drawComplexControl(TQStyle::CC_ScrollBar, &p2, ceData, elementFlags, boundingRect, gtkToTQtColorGroup(engine, state), sflags, TQStyle::SC_All, activeSubControl); + } + + cairo_restore(cr); +} + +static void draw_checkbox(DRAW_ARGS, const GtkWidgetPath* path, GtkStateFlags state, GtkWidget* widget, TQt3WidgetType tqt3WidgetType) { TQStringList objectTypes; objectTypes.append(TQCHECKBOX_OBJECT_NAME_STRING); @@ -774,6 +967,7 @@ tdegtk_draw_arrow (GtkThemingEngine *engine, else #endif if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_SCROLLBAR)) { +#ifdef DRAW_SCROLLBAR_PIECES_INSTEAD_OF_ENTIRE_BAR TQStringList objectTypes; objectTypes.append(TQSCROLLBAR_OBJECT_NAME_STRING); TQPalette objectPalette = tqApp->palette(objectTypes); @@ -845,6 +1039,9 @@ tdegtk_draw_arrow (GtkThemingEngine *engine, scrollpagerect.setWidth(ceData.rect.width()); } tqApp->style().drawPrimitive((subline)?TQStyle::PE_ScrollBarSubLine:TQStyle::PE_ScrollBarAddLine, p, scrollpagerect, gtkToTQtColorGroup(engine, state), sflags); +#else + // Draw nothing +#endif } else if (Gtk::gtk_widget_path_has_type(path, GTK_TYPE_COMBO_BOX) && (!(GTK_IS_MENU_ITEM(widget) || GTK_IS_MENU_ITEM(parent) || (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_MENUITEM))))) { @@ -1050,6 +1247,7 @@ tdegtk_draw_common_background (DRAW_ARGS) widget = m_widgetLookup.find(cr, path); if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_SCROLLBAR)) { +#ifdef DRAW_SCROLLBAR_PIECES_INSTEAD_OF_ENTIRE_BAR TQStringList objectTypes; objectTypes.append(TQSCROLLBAR_OBJECT_NAME_STRING); TQPalette objectPalette = tqApp->palette(objectTypes); @@ -1066,6 +1264,9 @@ tdegtk_draw_common_background (DRAW_ARGS) // Draw frame tqApp->style().drawPrimitive(TQStyle::PE_PanelLineEdit, &p, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE, widget) | ((ceData.orientation == TQt::Horizontal)?TQStyle::Style_Horizontal:TQStyle::Style_Default)); +#else + draw_scrollbar_frame(engine, cr, x, y, width, height, path, state, widget); +#endif } 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))) { @@ -1310,7 +1511,10 @@ tdegtk_draw_common_frame (DRAW_ARGS) state = gtk_theming_engine_get_state(engine); widget = m_widgetLookup.find(cr, path); + TQString widgetPath(Gtk::gtk_widget_path(widget)); + if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_SCROLLBAR)) { +#ifdef DRAW_SCROLLBAR_PIECES_INSTEAD_OF_ENTIRE_BAR if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_BUTTON)) { // Scrollbar buttons are drawn in the arrow handler } @@ -1344,6 +1548,9 @@ tdegtk_draw_common_frame (DRAW_ARGS) } tqApp->style().drawPrimitive(TQStyle::PE_ScrollBarAddPage, &p, scrollpagerect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE, widget)); } +#else + // Do nothing... +#endif } 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))) { @@ -1386,14 +1593,32 @@ tdegtk_draw_common_frame (DRAW_ARGS) tqApp->style().drawPrimitive(TQStyle::PE_ButtonDropDown, &p, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_TQMenuItem, widget) | ((ceData.orientation == TQt::Horizontal)?TQStyle::Style_Horizontal:TQStyle::Style_Default) | ((pressed)?TQStyle::Style_Down:TQStyle::Style_Default) | ((prelight)?TQStyle::Style_MouseOver:TQStyle::Style_Default)); } } + +#if 0 + // FIXME + // Certain styles (highcolor) paint over the color swatches if this is enabled, rendering the picker useless + else if (widgetPath.endsWith(".GtkColorSwatch")) { + TQStringList objectTypes; + objectTypes.append(TQLINEEDIT_OBJECT_NAME_STRING); + TQPalette objectPalette = tqApp->palette(objectTypes); + // Draw frame + tqApp->style().drawPrimitive(TQStyle::PE_PanelLineEdit, &p, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_TQLineEdit, widget)); + } +#endif + + else if (widgetPath.endsWith(".add-color-button")) { + // Draw frame + tqApp->style().drawPrimitive(TQStyle::PE_ButtonBevel, &p, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE, widget)); + } + else if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_ENTRY)) { TQStringList objectTypes; objectTypes.append(TQLINEEDIT_OBJECT_NAME_STRING); TQPalette objectPalette = tqApp->palette(objectTypes); // Draw frame - tqApp->style().drawPrimitive(TQStyle::PE_PanelLineEdit, &p, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE, widget)); + tqApp->style().drawPrimitive(TQStyle::PE_PanelLineEdit, &p, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_TQLineEdit, widget)); } else if (gtk_widget_path_is_type(path, GTK_TYPE_SPIN_BUTTON)) { @@ -2098,6 +2323,7 @@ tdegtk_draw_slider (DRAW_ARGS, widget = m_widgetLookup.find(cr, path); if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_SCROLLBAR)) { +#ifdef DRAW_SCROLLBAR_PIECES_INSTEAD_OF_ENTIRE_BAR TQStringList objectTypes; objectTypes.append(TQSCROLLBAR_OBJECT_NAME_STRING); TQPalette objectPalette = tqApp->palette(objectTypes); @@ -2123,32 +2349,13 @@ tdegtk_draw_slider (DRAW_ARGS, scrollpagerect.setWidth(ceData.rect.width()); } tqApp->style().drawPrimitive(TQStyle::PE_ScrollBarSlider, &p, scrollpagerect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_NONE, widget) | ((ceData.orientation == TQt::Horizontal)?TQStyle::Style_Horizontal:TQStyle::Style_Default)); +#else +// draw_scrollbar_frame(engine, cr, x, y, width, height, path, state, widget); +#endif } else if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_SCALE)) { -// bool mousedown = (state & GTK_STATE_FLAG_ACTIVE) != 0; -// -// TQStringList objectTypes; -// objectTypes.append(TQSLIDER_OBJECT_NAME_STRING); -// TQPalette objectPalette = tqApp->palette(objectTypes); -// -// GtkScale* scaleWidget = GTK_SCALE(widget); -// -// TQStyleControlElementData ceData; -// TQStyle::ControlElementFlags elementFlags = TQStyle::CEF_None; -// ceData.widgetObjectTypes = objectTypes; -// ceData.orientation = (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_VERTICAL))?TQt::Vertical:TQt::Horizontal; -// -// boundingRect = TQRect(0, 0, width, height); -// TQt3CairoPaintDevice pd2(NULL, x, y, width+4, height+4, cr); -// TQPainter p2(&pd2); -// -// ceData.rect = boundingRect; -// -// gtkScaleToSliderCeData(scaleWidget, ceData); -// -// // Draw item -// tqApp->style().drawComplexControl(TQStyle::CC_Slider, &p2, ceData, elementFlags, boundingRect, gtkToTQtColorGroup(engine, state), gtkToTQtStyleFlags(engine, state, TQT3WT_TQSlider, widget) | ((ceData.orientation == TQt::Horizontal)?TQStyle::Style_Horizontal:TQStyle::Style_Default), TQStyle::SC_SliderHandle, ((mousedown)?TQStyle::SC_SliderHandle:TQStyle::SC_None)); + draw_slider_frame(engine, cr, x, y, width, height, path, state, widget); } else { |