widget.cpp 2.4 KB

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