File: widget.cpp

package info (click to toggle)
ares 134%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 34,680 kB
  • sloc: cpp: 338,717; ansic: 89,036; sh: 52; makefile: 27
file content (94 lines) | stat: -rw-r--r-- 2,506 bytes parent folder | download | duplicates (2)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#if defined(Hiro_Widget)

namespace hiro {

static auto ParentContainer(mObject& object) -> QWidget* {
  if(auto frame = object.parentFrame()) {
    if(auto self = frame->self()) return self->qtFrame;
  }
  if(auto tabFrameItem = object.parentTabFrameItem()) {
    if(auto self = tabFrameItem->self()) return self->qtTabFrameItem;
  }
  if(auto window = object.parentWindow()) {
    if(auto self = window->self()) return self->qtContainer;
  }
  if(auto parent = object.parent()) {
    return ParentContainer(*parent);
  }
  return nullptr;
}

auto pWidget::construct() -> void {
  if(!qtWidget) return;

  if(auto container = ParentContainer(self())) {
    qtWidget->setParent(container);
  }

  setDroppable(self().droppable());
  setEnabled(self().enabled(true));
  setFocusable(self().focusable());
  setFont(self().font(true));
  setMouseCursor(self().mouseCursor());
  setToolTip(self().toolTip());
  setVisible(self().visible(true));
}

auto pWidget::destruct() -> void {
}

auto pWidget::focused() const -> bool {
  if(!qtWidget) return false;
  return qtWidget->hasFocus();
}

auto pWidget::setDroppable(bool droppable) -> void {
  //virtual overload, implemented on a per-widget basis
}

auto pWidget::setEnabled(bool enabled) -> void {
  if(!qtWidget) return;
  qtWidget->setEnabled(enabled);
}

auto pWidget::setFocusable(bool focusable) -> void {
  //virtual overload, implemented on a per-widget basis
}

auto pWidget::setFocused() -> void {
  if(!qtWidget) return;
  qtWidget->setFocus(Qt::OtherFocusReason);
}

auto pWidget::setFont(const Font& font) -> void {
  if(!qtWidget) return;
  qtWidget->setFont(pFont::create(font));
}

auto pWidget::setGeometry(Geometry geometry) -> void {
  if(!qtWidget) return;
  qtWidget->setGeometry(geometry.x(), geometry.y(), geometry.width(), geometry.height());
  pSizable::setGeometry(geometry);
}

auto pWidget::setMouseCursor(const MouseCursor& mouseCursor) -> void {
  auto cursorID = Qt::ArrowCursor;
  if(mouseCursor.name() == MouseCursor::Hand) cursorID = Qt::PointingHandCursor;
  if(mouseCursor.name() == MouseCursor::HorizontalResize) cursorID = Qt::SizeHorCursor;
  if(mouseCursor.name() == MouseCursor::VerticalResize) cursorID = Qt::SizeVerCursor;
  qtWidget->setCursor(cursorID);
}

auto pWidget::setToolTip(const string& toolTip) -> void {
  if(!qtWidget) return;
  qtWidget->setToolTip(QString::fromUtf8(toolTip));
}

auto pWidget::setVisible(bool visible) -> void {
  if(!qtWidget) return;
  qtWidget->setVisible(visible);
}

}

#endif