aboutsummaryrefslogtreecommitdiff
path: root/src/widgets/Decorations.cpp
blob: d5597760bfc23e4a75d7720b0975065503661a77 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <QWidget>
#include <QtCore>
#include <optional>
#include <qboxlayout.h>
#include <qlabel.h>
#include <qwidget.h>

#include "Decorations.hpp"
#include "widgets/EdgeDecoration.hpp"

Decorations::Decorations(QWidget *content_widget, QWebEngineProfile *profile, QWidget *parent)
    : QWidget(parent) {
  decoration_top = new EdgeDecoration(false, profile, this);
  decoration_bottom = new EdgeDecoration(false, profile, this);
  decoration_left = new EdgeDecoration(true, profile, this);
  decoration_right = new EdgeDecoration(true, profile, this);

  QString content = R"HTML(
    <div>
      Hello world testing testing
      <button>Btn 1</button><button>Btn 2</button>
    </div>
  )HTML";
  decoration_bottom->set_html(content);
  // decoration_bottom->set_enabled(true);

  auto *vbox = new QVBoxLayout();
  vbox->setContentsMargins(0, 0, 0, 0);
  vbox->setSpacing(0);
  setLayout(vbox);

  auto *container = new QWidget(this);
  auto *hbox = new QHBoxLayout();
  hbox->setContentsMargins(0, 0, 0, 0);
  hbox->setSpacing(0);
  container->setLayout(hbox);

  vbox->addWidget(decoration_top);
  vbox->addWidget(container);
  vbox->addWidget(decoration_bottom);

  hbox->addWidget(decoration_left);
  hbox->addWidget(content_widget);
  hbox->addWidget(decoration_right);
}

void Decorations::set_enabled(DecorationType type, bool enabled) {
  std::optional<EdgeDecoration *> decoration = get_decoration_widget(type);

  if (decoration.has_value())
    decoration.value()->set_enabled(enabled);
}

std::optional<EdgeDecoration *> Decorations::get_decoration_widget(DecorationType type) {
  switch (type) {
  case DecorationType::DecorationTop:
    return decoration_top;
  case DecorationType::DecorationBottom:
    return decoration_bottom;
  case DecorationType::DecorationLeft:
    return decoration_left;
  case DecorationType::DecorationRight:
    return decoration_right;
  }
  return nullptr;
}