Mimic the behaviour and style of the sugar GTK+ 2 sub-toolbars in GTK+ 3
This draws the grey line around the toolbutton icon with a gap at the bottom and a grey line at the top of the subtoolbar. Furthermore it gets the highlightning of the button correct, in the pressed and hover state. This patch depends on the sugar-artwork patch with the id 7464b808eb12b1df650952e3c8214acff1d1360f. Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org> Signed-off-by: Manuel Quiñones <manuq@laptop.org> Acked-by: Simon Schampijer <simon@laptop.org>
This commit is contained in:
parent
7344db525d
commit
e04043dc0b
@ -66,7 +66,7 @@ class ToolbarButton(ToolButton):
|
|||||||
if page is None:
|
if page is None:
|
||||||
self.page_widget = None
|
self.page_widget = None
|
||||||
return
|
return
|
||||||
self.page_widget, alignment_ = _embed_page(_Box, page)
|
self.page_widget, alignment_ = _embed_page(_Box(self), page)
|
||||||
self.page_widget.set_size_request(-1, style.GRID_CELL_SIZE)
|
self.page_widget.set_size_request(-1, style.GRID_CELL_SIZE)
|
||||||
page.show()
|
page.show()
|
||||||
if self.props.palette is None:
|
if self.props.palette is None:
|
||||||
@ -126,21 +126,31 @@ class ToolbarButton(ToolButton):
|
|||||||
page_parent.remove(self.page_widget)
|
page_parent.remove(self.page_widget)
|
||||||
|
|
||||||
def do_draw(self, cr):
|
def do_draw(self, cr):
|
||||||
if not self.is_expanded() or self.props.palette is not None and \
|
|
||||||
self.props.palette.is_up():
|
|
||||||
Gtk.ToolButton.do_draw(self, cr)
|
|
||||||
_paint_arrow(self, cr, math.pi)
|
|
||||||
return
|
|
||||||
|
|
||||||
alloc = self.get_allocation()
|
alloc = self.get_allocation()
|
||||||
|
|
||||||
context = self.get_style_context()
|
context = self.get_style_context()
|
||||||
context.add_class('toolitem')
|
context.add_class('toolitem')
|
||||||
|
|
||||||
|
arrow_direction = 0
|
||||||
|
if not self.is_expanded() or self.props.palette is not None and \
|
||||||
|
self.props.palette.is_up():
|
||||||
|
arrow_direction = math.pi
|
||||||
|
|
||||||
|
if not self.is_expanded() and self.props.palette is not None and \
|
||||||
|
self.props.palette.is_up():
|
||||||
|
# draw a black background
|
||||||
|
cr.set_source_rgba(*style.COLOR_BLACK.get_rgba())
|
||||||
|
cr.rectangle(0, 0, alloc.width, alloc.height)
|
||||||
|
cr.fill()
|
||||||
|
|
||||||
|
Gtk.ToolButton.do_draw(self, cr)
|
||||||
|
|
||||||
|
if self.is_expanded() or self.props.palette is not None and \
|
||||||
|
self.props.palette.is_up():
|
||||||
Gtk.render_frame_gap(context, cr, 0, 0, alloc.width, alloc.height,
|
Gtk.render_frame_gap(context, cr, 0, 0, alloc.width, alloc.height,
|
||||||
Gtk.PositionType.BOTTOM, 0, alloc.width)
|
Gtk.PositionType.BOTTOM, 0, alloc.width)
|
||||||
Gtk.ToolButton.do_draw(self, cr)
|
|
||||||
_paint_arrow(self, cr, 0)
|
_paint_arrow(self, cr, arrow_direction)
|
||||||
|
|
||||||
|
|
||||||
class ToolbarBox(Gtk.VBox):
|
class ToolbarBox(Gtk.VBox):
|
||||||
@ -155,7 +165,7 @@ class ToolbarBox(Gtk.VBox):
|
|||||||
self._toolbar.connect('remove', self.__remove_cb)
|
self._toolbar.connect('remove', self.__remove_cb)
|
||||||
|
|
||||||
self._toolbar_widget, self._toolbar_alignment = \
|
self._toolbar_widget, self._toolbar_alignment = \
|
||||||
_embed_page(Gtk.EventBox, self._toolbar)
|
_embed_page(Gtk.EventBox(), self._toolbar)
|
||||||
self.pack_start(self._toolbar_widget, True, True, 0)
|
self.pack_start(self._toolbar_widget, True, True, 0)
|
||||||
|
|
||||||
self.props.padding = padding
|
self.props.padding = padding
|
||||||
@ -269,26 +279,23 @@ class _ToolbarPalette(PaletteWindow):
|
|||||||
|
|
||||||
class _Box(Gtk.EventBox):
|
class _Box(Gtk.EventBox):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, toolbar_button):
|
||||||
GObject.GObject.__init__(self)
|
GObject.GObject.__init__(self)
|
||||||
self.set_app_paintable(True)
|
self.set_app_paintable(True)
|
||||||
|
self._toolbar_button = toolbar_button
|
||||||
|
|
||||||
def do_expose_event(self, widget, event):
|
def do_draw(self, cr):
|
||||||
# TODO: reimplement this in the theme
|
button_alloc = self._toolbar_button.get_allocation()
|
||||||
expanded_button = self.get_parent().expanded_button
|
|
||||||
if expanded_button is None:
|
cr.set_line_width(style.FOCUS_LINE_WIDTH * 2)
|
||||||
return
|
cr.set_source_rgba(*style.COLOR_BUTTON_GREY.get_rgba())
|
||||||
alloc = expanded_button.allocation
|
cr.move_to(0, 0)
|
||||||
self.get_style().paint_box(event.window,
|
cr.line_to(button_alloc.x + style.FOCUS_LINE_WIDTH, 0)
|
||||||
Gtk.StateType.NORMAL, Gtk.ShadowType.IN, event.area, self,
|
cr.move_to(button_alloc.x + button_alloc.width - style.FOCUS_LINE_WIDTH, 0)
|
||||||
'palette-invoker', -style.FOCUS_LINE_WIDTH, 0,
|
cr.line_to(self.get_allocation().width, 0)
|
||||||
self.allocation.width + style.FOCUS_LINE_WIDTH * 2,
|
cr.stroke()
|
||||||
self.allocation.height + style.FOCUS_LINE_WIDTH)
|
|
||||||
self.get_style().paint_box(event.window,
|
Gtk.EventBox.do_draw(self, cr)
|
||||||
Gtk.StateType.NORMAL, Gtk.ShadowType.NONE, event.area, self, None,
|
|
||||||
alloc.x + style.FOCUS_LINE_WIDTH, 0,
|
|
||||||
alloc.width - style.FOCUS_LINE_WIDTH * 2,
|
|
||||||
style.FOCUS_LINE_WIDTH)
|
|
||||||
|
|
||||||
|
|
||||||
def _setup_page(page_widget, color, hpad):
|
def _setup_page(page_widget, color, hpad):
|
||||||
@ -305,14 +312,13 @@ def _setup_page(page_widget, color, hpad):
|
|||||||
page_widget.modify_bg(Gtk.StateType.PRELIGHT, color)
|
page_widget.modify_bg(Gtk.StateType.PRELIGHT, color)
|
||||||
|
|
||||||
|
|
||||||
def _embed_page(box_class, page):
|
def _embed_page(page_widget, page):
|
||||||
page.show()
|
page.show()
|
||||||
|
|
||||||
alignment = Gtk.Alignment(xscale=1.0, yscale=1.0)
|
alignment = Gtk.Alignment(xscale=1.0, yscale=1.0)
|
||||||
alignment.add(page)
|
alignment.add(page)
|
||||||
alignment.show()
|
alignment.show()
|
||||||
|
|
||||||
page_widget = box_class()
|
|
||||||
page_widget.modify_bg(Gtk.StateType.ACTIVE,
|
page_widget.modify_bg(Gtk.StateType.ACTIVE,
|
||||||
style.COLOR_BUTTON_GREY.get_gdk_color())
|
style.COLOR_BUTTON_GREY.get_gdk_color())
|
||||||
page_widget.add(alignment)
|
page_widget.add(alignment)
|
||||||
|
Loading…
Reference in New Issue
Block a user