* @brief Creates and configures the title bar. */
| 1045 | * @brief Creates and configures the title bar. |
| 1046 | */ |
| 1047 | void Window::setupTitleBar() |
| 1048 | { |
| 1049 | auto* quickWindow = qobject_cast<QQuickWindow*>(m_window.data()); |
| 1050 | if (!quickWindow) |
| 1051 | return; |
| 1052 | |
| 1053 | m_titleBar = new Titlebar(quickWindow->contentItem()); |
| 1054 | m_titleBar->setZ(999999); |
| 1055 | |
| 1056 | connect(m_titleBar, &Titlebar::closeClicked, this, [this]() { |
| 1057 | if (m_window) |
| 1058 | m_window->close(); |
| 1059 | }); |
| 1060 | connect(m_titleBar, &Titlebar::minimizeClicked, this, [this]() { |
| 1061 | if (m_window) |
| 1062 | m_window->showMinimized(); |
| 1063 | }); |
| 1064 | connect(m_titleBar, &Titlebar::maximizeClicked, this, [this]() { |
| 1065 | if (!m_window) |
| 1066 | return; |
| 1067 | |
| 1068 | if (m_window->windowStates() & Qt::WindowMaximized) |
| 1069 | m_window->showNormal(); |
| 1070 | else |
| 1071 | m_window->showMaximized(); |
| 1072 | }); |
| 1073 | |
| 1074 | connect(m_window, &QWindow::activeChanged, this, [this]() { |
| 1075 | if (m_window && m_titleBar) |
| 1076 | m_titleBar->setWindowActive(m_window->isActive()); |
| 1077 | }); |
| 1078 | |
| 1079 | m_titleBar->setTitle(m_window->title()); |
| 1080 | connect(m_window, &QWindow::windowTitleChanged, m_titleBar, &Titlebar::setTitle); |
| 1081 | connect(quickWindow, &QQuickWindow::widthChanged, this, &Window::updateTitleBarGeometry); |
| 1082 | updateTitleBarGeometry(); |
| 1083 | } |
| 1084 | |
| 1085 | /** |
| 1086 | * @brief Updates the window minimum size to account for CSD decorations. |