| 88 | } |
| 89 | |
| 90 | void MainWindow::windowInit(const QString& title, const QIcon& icon) |
| 91 | { |
| 92 | setObjectName(QStringLiteral("mainwindow")); |
| 93 | |
| 94 | // set the window agent |
| 95 | _window_agent = new QWK::WidgetWindowAgent(this); |
| 96 | _window_agent->setup(this); |
| 97 | |
| 98 | QLabel* titlebar_label = new QLabel(); |
| 99 | titlebar_label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); |
| 100 | titlebar_label->setObjectName(QStringLiteral("titlebar-label")); |
| 101 | titlebar_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); |
| 102 | |
| 103 | QWK::WindowButton* icon_btn = new QWK::WindowButton(); |
| 104 | icon_btn->setObjectName(QStringLiteral("titlebar-icon-button")); |
| 105 | icon_btn->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
| 106 | icon_btn->setIconNormal(icon); |
| 107 | |
| 108 | QWK::WindowButton* min_btn = new QWK::WindowButton(); |
| 109 | min_btn->setObjectName(QStringLiteral("titlebar-min-button")); |
| 110 | min_btn->setProperty("system-button", true); |
| 111 | min_btn->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
| 112 | |
| 113 | QWK::WindowButton* max_btn = new QWK::WindowButton(); |
| 114 | max_btn->setCheckable(true); |
| 115 | max_btn->setObjectName(QStringLiteral("titlebar-max-button")); |
| 116 | max_btn->setProperty("system-button", true); |
| 117 | max_btn->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
| 118 | |
| 119 | QWK::WindowButton* close_btn = new QWK::WindowButton(); |
| 120 | close_btn->setObjectName(QStringLiteral("titlebar-close-button")); |
| 121 | close_btn->setProperty("system-button", true); |
| 122 | close_btn->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); |
| 123 | |
| 124 | QWK::WindowBar* titlebar = new QWK::WindowBar(); |
| 125 | titlebar->setIconButton(icon_btn); |
| 126 | titlebar->setMinButton(min_btn); |
| 127 | titlebar->setMaxButton(max_btn); |
| 128 | titlebar->setCloseButton(close_btn); |
| 129 | titlebar->setTitleLabel(titlebar_label); |
| 130 | titlebar->setHostWidget(this); |
| 131 | |
| 132 | _window_agent->setTitleBar(titlebar); |
| 133 | _window_agent->setSystemButton(QWK::WindowAgentBase::WindowIcon, icon_btn); |
| 134 | _window_agent->setSystemButton(QWK::WindowAgentBase::Minimize, min_btn); |
| 135 | _window_agent->setSystemButton(QWK::WindowAgentBase::Maximize, max_btn); |
| 136 | _window_agent->setSystemButton(QWK::WindowAgentBase::Close, close_btn); |
| 137 | |
| 138 | setMenuWidget(titlebar); |
| 139 | |
| 140 | // Adds simulated mouse events to the title bar buttons |
| 141 | connect(icon_btn, &QAbstractButton::clicked, _window_agent, [this, icon_btn]() { |
| 142 | icon_btn->setProperty("double-click-close", false); |
| 143 | |
| 144 | QTimer::singleShot(80, _window_agent, [this, icon_btn]() { |
| 145 | if (icon_btn->property("double-click-close").toBool()) |
| 146 | return; |
| 147 | _window_agent->showSystemMenu(icon_btn->mapToGlobal(QPoint{0, icon_btn->height()})); |
nothing calls this directly
no test coverage detected