Debian Codegraph @

hiro/qt/widget/widget.cpp

raw
1 #if defined(Hiro_Widget)
2
3 namespace hiro {
4
5 static auto ParentContainer(mObject& object) -> QWidget* {
6 if(auto frame = object.parentFrame()) {
7 if(auto self = frame->self()) return self->qtFrame;
8 }
9 if(auto tabFrameItem = object.parentTabFrameItem()) {
10 if(auto self = tabFrameItem->self()) return self->qtTabFrameItem;
11 }
12 if(auto window = object.parentWindow()) {
13 if(auto self = window->self()) return self->qtContainer;
14 }
15 if(auto parent = object.parent()) {
16 return ParentContainer(*parent);
17 }
18 return nullptr;
19 }
20
21 auto pWidget::construct() -> void {
22 if(!qtWidget) return;
23
24 if(auto container = ParentContainer(self())) {
25 qtWidget->setParent(container);
26 }
27
28 setDroppable(self().droppable());
29 setEnabled(self().enabled(true));
30 setFocusable(self().focusable());
31 setFont(self().font(true));
32 setMouseCursor(self().mouseCursor());
33 setToolTip(self().toolTip());
34 setVisible(self().visible(true));
35 }
36
37 auto pWidget::destruct() -> void {
38 }
39
40 auto pWidget::focused() const -> bool {
41 if(!qtWidget) return false;
42 return qtWidget->hasFocus();
43 }
44
45 auto pWidget::setDroppable(bool droppable) -> void {
46 //virtual overload, implemented on a per-widget basis
47 }
48
49 auto pWidget::setEnabled(bool enabled) -> void {
50 if(!qtWidget) return;
51 qtWidget->setEnabled(enabled);
52 }
53
54 auto pWidget::setFocusable(bool focusable) -> void {
55 //virtual overload, implemented on a per-widget basis
56 }
57
58 auto pWidget::setFocused() -> void {
59 if(!qtWidget) return;
60 qtWidget->setFocus(Qt::OtherFocusReason);
61 }
62
63 auto pWidget::setFont(const Font& font) -> void {
64 if(!qtWidget) return;
65 qtWidget->setFont(pFont::create(font));
66 }
67
68 auto pWidget::setGeometry(Geometry geometry) -> void {
69 if(!qtWidget) return;
70 qtWidget->setGeometry(geometry.x(), geometry.y(), geometry.width(), geometry.height());
71 pSizable::setGeometry(geometry);
72 }
73
74 auto pWidget::setMouseCursor(const MouseCursor& mouseCursor) -> void {
75 auto cursorID = Qt::ArrowCursor;
76 if(mouseCursor.name() == MouseCursor::Hand) cursorID = Qt::PointingHandCursor;
77 if(mouseCursor.name() == MouseCursor::HorizontalResize) cursorID = Qt::SizeHorCursor;
78 if(mouseCursor.name() == MouseCursor::VerticalResize) cursorID = Qt::SizeVerCursor;
79 qtWidget->setCursor(cursorID);
80 }
81
82 auto pWidget::setToolTip(const string& toolTip) -> void {
83 if(!qtWidget) return;
84 qtWidget->setToolTip(QString::fromUtf8(toolTip));
85 }
86
87 auto pWidget::setVisible(bool visible) -> void {
88 if(!qtWidget) return;
89 qtWidget->setVisible(visible);
90 }
91
92 }
93
94 #endif