ToolbarContainer.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGUI/BoxLayout.h>
  7. #include <LibGUI/Painter.h>
  8. #include <LibGUI/ToolbarContainer.h>
  9. #include <LibGfx/Palette.h>
  10. #include <LibGfx/StylePainter.h>
  11. REGISTER_WIDGET(GUI, ToolbarContainer)
  12. namespace GUI {
  13. ToolbarContainer::ToolbarContainer(Gfx::Orientation orientation)
  14. : m_orientation(orientation)
  15. {
  16. set_fill_with_background_color(true);
  17. set_frame_thickness(2);
  18. set_frame_shape(Gfx::FrameShape::Box);
  19. set_frame_shadow(Gfx::FrameShadow::Sunken);
  20. auto& layout = set_layout<VerticalBoxLayout>();
  21. layout.set_spacing(2);
  22. set_shrink_to_fit(true);
  23. }
  24. void ToolbarContainer::paint_event(GUI::PaintEvent& event)
  25. {
  26. Painter painter(*this);
  27. painter.add_clip_rect(event.rect());
  28. for_each_child_widget([&](auto& widget) {
  29. if (widget.is_visible()) {
  30. auto rect = widget.relative_rect();
  31. painter.draw_line(rect.top_left().translated(0, -1), rect.top_right().translated(0, -1), palette().threed_highlight());
  32. painter.draw_line(rect.bottom_left().translated(0, 1), rect.bottom_right().translated(0, 1), palette().threed_shadow1());
  33. }
  34. return IterationDecision::Continue;
  35. });
  36. Frame::paint_event(event);
  37. }
  38. }