|
| 1 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | + |
| 3 | +#include <QQuickItem> |
| 4 | + |
| 5 | +#include "dialogview.h" |
| 6 | + |
| 7 | +using namespace scratchcpp::uicomponents; |
| 8 | + |
| 9 | +DialogView::DialogView(QObject *parent) : |
| 10 | + QObject(parent) |
| 11 | +{ |
| 12 | + if (m_modal) |
| 13 | + m_window.setModality(Qt::ApplicationModal); |
| 14 | + else |
| 15 | + m_window.setModality(Qt::NonModal); |
| 16 | + |
| 17 | + m_window.setFlags(m_window.flags() | Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint); |
| 18 | + |
| 19 | + connect(&m_window, &QQuickWindow::visibleChanged, this, &DialogView::visibleChanged); |
| 20 | + connect(&m_window, &QQuickWindow::windowTitleChanged, this, &DialogView::titleChanged); |
| 21 | + connect(&m_window, &QQuickWindow::minimumWidthChanged, this, &DialogView::minimumWidthChanged); |
| 22 | + connect(&m_window, &QQuickWindow::minimumHeightChanged, this, &DialogView::minimumHeightChanged); |
| 23 | + connect(&m_window, &QQuickWindow::maximumWidthChanged, this, &DialogView::maximumWidthChanged); |
| 24 | + connect(&m_window, &QQuickWindow::maximumHeightChanged, this, &DialogView::maximumHeightChanged); |
| 25 | + connect(&m_window, &QuickWindow::autoCloseChanged, this, &DialogView::autoCloseChanged); |
| 26 | + connect(&m_window, &QuickWindow::closableChanged, this, &DialogView::closableChanged); |
| 27 | + connect(&m_window, &QQuickWindow::activeFocusItemChanged, this, &DialogView::activeFocusItemChanged); |
| 28 | +} |
| 29 | + |
| 30 | +QQuickItem *DialogView::contentItem() const |
| 31 | +{ |
| 32 | + return m_contentItem; |
| 33 | +} |
| 34 | + |
| 35 | +void DialogView::setContentItem(QQuickItem *newContentItem) |
| 36 | +{ |
| 37 | + if (m_contentItem == newContentItem) |
| 38 | + return; |
| 39 | + |
| 40 | + m_contentItem = newContentItem; |
| 41 | + m_contentItem->setParentItem(m_window.contentItem()); |
| 42 | + emit contentItemChanged(); |
| 43 | +} |
| 44 | + |
| 45 | +bool DialogView::visible() const |
| 46 | +{ |
| 47 | + return m_window.isVisible(); |
| 48 | +} |
| 49 | + |
| 50 | +void DialogView::setVisible(bool newVisible) |
| 51 | +{ |
| 52 | + m_window.setVisible(newVisible); |
| 53 | +} |
| 54 | + |
| 55 | +QString DialogView::title() const |
| 56 | +{ |
| 57 | + return m_window.title(); |
| 58 | +} |
| 59 | + |
| 60 | +void DialogView::setTitle(const QString &newTitle) |
| 61 | +{ |
| 62 | + m_window.setTitle(newTitle); |
| 63 | +} |
| 64 | + |
| 65 | +bool DialogView::modal() const |
| 66 | +{ |
| 67 | + return m_modal; |
| 68 | +} |
| 69 | + |
| 70 | +void DialogView::setModal(bool newModal) |
| 71 | +{ |
| 72 | + if (m_modal == newModal) |
| 73 | + return; |
| 74 | + |
| 75 | + m_modal = newModal; |
| 76 | + |
| 77 | + if (m_modal) |
| 78 | + m_window.setModality(Qt::ApplicationModal); |
| 79 | + else |
| 80 | + m_window.setModality(Qt::NonModal); |
| 81 | + |
| 82 | + emit modalChanged(); |
| 83 | +} |
| 84 | + |
| 85 | +int DialogView::minimumWidth() const |
| 86 | +{ |
| 87 | + return m_window.minimumWidth(); |
| 88 | +} |
| 89 | + |
| 90 | +void DialogView::setMinimumWidth(int newMinimumWidth) |
| 91 | +{ |
| 92 | + m_window.setMinimumWidth(newMinimumWidth); |
| 93 | +} |
| 94 | + |
| 95 | +int DialogView::minimumHeight() const |
| 96 | +{ |
| 97 | + return m_window.minimumHeight(); |
| 98 | +} |
| 99 | + |
| 100 | +void DialogView::setMinimumHeight(int newMinimumHeight) |
| 101 | +{ |
| 102 | + m_window.setMinimumHeight(newMinimumHeight); |
| 103 | +} |
| 104 | + |
| 105 | +int DialogView::maximumWidth() const |
| 106 | +{ |
| 107 | + return m_window.maximumWidth(); |
| 108 | +} |
| 109 | + |
| 110 | +void DialogView::setMaximumWidth(int newMaximumWidth) |
| 111 | +{ |
| 112 | + m_window.setMaximumWidth(newMaximumWidth); |
| 113 | +} |
| 114 | + |
| 115 | +int DialogView::maximumHeight() const |
| 116 | +{ |
| 117 | + return m_window.maximumHeight(); |
| 118 | +} |
| 119 | + |
| 120 | +void DialogView::setMaximumHeight(int newMaximumHeight) |
| 121 | +{ |
| 122 | + m_window.setMaximumHeight(newMaximumHeight); |
| 123 | +} |
| 124 | + |
| 125 | +void DialogView::setMaximizedState() |
| 126 | +{ |
| 127 | + m_window.setWindowStates(Qt::WindowMaximized); |
| 128 | +} |
| 129 | + |
| 130 | +void DialogView::setNormalState() |
| 131 | +{ |
| 132 | + m_window.setWindowState(Qt::WindowNoState); |
| 133 | +} |
| 134 | + |
| 135 | +void DialogView::showMaximized() |
| 136 | +{ |
| 137 | + m_window.showMaximized(); |
| 138 | +} |
| 139 | + |
| 140 | +void DialogView::showNormal() |
| 141 | +{ |
| 142 | + m_window.showNormal(); |
| 143 | +} |
| 144 | + |
| 145 | +bool DialogView::autoClose() const |
| 146 | +{ |
| 147 | + return m_window.autoClose(); |
| 148 | +} |
| 149 | + |
| 150 | +void DialogView::setAutoClose(bool newAutoClose) |
| 151 | +{ |
| 152 | + m_window.setAutoClose(newAutoClose); |
| 153 | +} |
| 154 | + |
| 155 | +bool DialogView::closable() const |
| 156 | +{ |
| 157 | + return m_window.closable(); |
| 158 | +} |
| 159 | + |
| 160 | +void DialogView::setClosable(bool newClosable) |
| 161 | +{ |
| 162 | + m_window.setClosable(newClosable); |
| 163 | +} |
| 164 | + |
| 165 | +QQuickItem *DialogView::activeFocusItem() const |
| 166 | +{ |
| 167 | + return m_window.activeFocusItem(); |
| 168 | +} |
0 commit comments