box_content_divider.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #include "ui/widgets/box_content_divider.h"
  8. #include "styles/style_layers.h"
  9. #include "styles/palette.h"
  10. #include <QtGui/QPainter>
  11. #include <QtGui/QtEvents>
  12. namespace Ui {
  13. BoxContentDivider::BoxContentDivider(QWidget *parent)
  14. : BoxContentDivider(parent, st::boxDividerHeight) {
  15. }
  16. BoxContentDivider::BoxContentDivider(QWidget *parent, int height)
  17. : BoxContentDivider(parent, height, st::boxDividerBg) {
  18. }
  19. BoxContentDivider::BoxContentDivider(
  20. QWidget *parent,
  21. int height,
  22. const style::color &bg,
  23. RectParts parts)
  24. : RpWidget(parent)
  25. , _bg(bg)
  26. , _parts(parts) {
  27. resize(width(), height);
  28. }
  29. void BoxContentDivider::paintEvent(QPaintEvent *e) {
  30. QPainter p(this);
  31. p.fillRect(e->rect(), _bg);
  32. if (_parts & RectPart::Top) {
  33. paintTop(p);
  34. }
  35. if (_parts & RectPart::Bottom) {
  36. paintBottom(p);
  37. }
  38. }
  39. void BoxContentDivider::paintTop(QPainter &p, int skip) {
  40. const auto dividerFillTop = QRect(
  41. 0,
  42. skip,
  43. width(),
  44. st::boxDividerTop.height());
  45. st::boxDividerTop.fill(p, dividerFillTop);
  46. }
  47. void BoxContentDivider::paintBottom(QPainter &p, int skip) {
  48. const auto dividerFillBottom = myrtlrect(
  49. 0,
  50. height() - skip - st::boxDividerBottom.height(),
  51. width(),
  52. st::boxDividerBottom.height());
  53. st::boxDividerBottom.fill(p, dividerFillBottom);
  54. }
  55. const style::color &BoxContentDivider::color() const {
  56. return _bg;
  57. }
  58. } // namespace Ui