framelessbase.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. #include "framelessbase.h"
  2. #include <QCoreApplication>
  3. #include <QGuiApplication>
  4. #include <QTimer>
  5. #include <QVBoxLayout>
  6. #include <QtCore/QDebug>
  7. #include <QtCore/QFile>
  8. #include <QtCore/QTime>
  9. #include <QtCore/QTimer>
  10. #include <QtGui/QPainter>
  11. #include <QtGui/QWindow>
  12. #include <QtWidgets/QApplication>
  13. #include <QtWidgets/QPushButton>
  14. #include <QtWidgets/QStyle>
  15. #include <QtWidgets/QMenuBar>
  16. #include <QtCore/QPointer>
  17. #include <QHBoxLayout>
  18. #include <QIcon>
  19. #include <QEventLoop>
  20. #include <QCloseEvent>
  21. #include "themesettingswidget.h"
  22. #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
  23. #include <QtGui/QActionGroup>
  24. #else
  25. #include <QtWidgets/QActionGroup>
  26. #endif
  27. #include "widgetframe/windowbar.h"
  28. #include "widgetframe/windowbutton.h"
  29. #include "widgets/widgetwindowagent.h"
  30. static inline void emulateLeaveEvent(QWidget *widget)
  31. {
  32. Q_ASSERT(widget);
  33. if (!widget) {
  34. return;
  35. }
  36. QTimer::singleShot(0, widget, [widget]() {
  37. #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
  38. const QScreen *screen = widget->screen();
  39. #else
  40. const QScreen *screen = widget->windowHandle()->screen();
  41. #endif
  42. const QPoint globalPos = QCursor::pos(screen);
  43. if (!QRect(widget->mapToGlobal(QPoint{0, 0}), widget->size()).contains(globalPos)) {
  44. QCoreApplication::postEvent(widget, new QEvent(QEvent::Leave));
  45. if (widget->testAttribute(Qt::WA_Hover)) {
  46. const QPoint localPos = widget->mapFromGlobal(globalPos);
  47. const QPoint scenePos = widget->window()->mapFromGlobal(globalPos);
  48. static constexpr const auto oldPos = QPoint{};
  49. const Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers();
  50. #if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0))
  51. const auto event = new QHoverEvent(QEvent::HoverLeave,
  52. scenePos,
  53. globalPos,
  54. oldPos,
  55. modifiers);
  56. Q_UNUSED(localPos);
  57. #elif (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0))
  58. const auto event = new QHoverEvent(QEvent::HoverLeave, localPos, globalPos, oldPos, modifiers);
  59. Q_UNUSED(scenePos);
  60. #else
  61. const auto event = new QHoverEvent(QEvent::HoverLeave, localPos, oldPos, modifiers);
  62. Q_UNUSED(scenePos);
  63. #endif
  64. QCoreApplication::postEvent(widget, event);
  65. }
  66. }
  67. });
  68. }
  69. TMainWindow::TMainWindow(QWidget *parent)
  70. : QMainWindow(parent)
  71. {
  72. setAttribute(Qt::WA_DontCreateNativeAncestors);
  73. installWindowAgent();
  74. }
  75. bool TMainWindow::event(QEvent *event)
  76. {
  77. switch (event->type()) {
  78. case QEvent::WindowActivate: {
  79. auto menu = menuWidget();
  80. if (menu) {
  81. menu->setProperty("bar-active", true);
  82. style()->polish(menu);
  83. }
  84. break;
  85. }
  86. case QEvent::WindowDeactivate: {
  87. auto menu = menuWidget();
  88. if (menu) {
  89. menu->setProperty("bar-active", false);
  90. style()->polish(menu);
  91. }
  92. break;
  93. }
  94. default:
  95. break;
  96. }
  97. return QMainWindow::event(event);
  98. }
  99. void TMainWindow::installWindowAgent()
  100. {
  101. // 1. Setup window agent
  102. windowAgent = new QWK::WidgetWindowAgent(this);
  103. windowAgent->setup(this);
  104. auto titleLabel = new QLabel(windowTitle());
  105. titleLabel->setAlignment(Qt::AlignCenter);
  106. titleLabel->setObjectName(QStringLiteral("win-title-label"));
  107. #ifndef Q_OS_MAC
  108. auto iconButton = new QWK::WindowButton();
  109. iconButton->setObjectName(QStringLiteral("icon-button"));
  110. iconButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  111. auto pinButton = new QWK::WindowButton();
  112. pinButton->setCheckable(true);
  113. pinButton->setObjectName(QStringLiteral("pin-button"));
  114. pinButton->setProperty("system-button", true);
  115. pinButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  116. auto minButton = new QWK::WindowButton();
  117. minButton->setObjectName(QStringLiteral("min-button"));
  118. minButton->setProperty("system-button", true);
  119. minButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  120. auto maxButton = new QWK::WindowButton();
  121. maxButton->setCheckable(true);
  122. maxButton->setObjectName(QStringLiteral("max-button"));
  123. maxButton->setProperty("system-button", true);
  124. maxButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  125. auto closeButton = new QWK::WindowButton();
  126. closeButton->setObjectName(QStringLiteral("close-button"));
  127. closeButton->setProperty("system-button", true);
  128. closeButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  129. #endif
  130. auto windowBar = new QWK::WindowBar();
  131. #ifndef Q_OS_MAC
  132. windowBar->setIconButton(iconButton);
  133. windowBar->setPinButton(pinButton);
  134. windowBar->setMinButton(minButton);
  135. windowBar->setMaxButton(maxButton);
  136. windowBar->setCloseButton(closeButton);
  137. #endif
  138. windowBar->setTitleLabel(titleLabel);
  139. windowBar->setHostWidget(this);
  140. #ifndef Q_OS_MAC
  141. // 创建一个“设置”按钮,放在标题文本区域的最右侧,使其位于置顶按钮的左侧
  142. auto settingsButton = new QWK::WindowButton(windowBar);
  143. settingsButton->setObjectName(QStringLiteral("settings-button"));
  144. settingsButton->setProperty("system-button", true);
  145. settingsButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  146. settingsButton->setIconNormal(QIcon(QStringLiteral(":/window-bar/more-line.svg")));
  147. QObject::connect(settingsButton, &QAbstractButton::clicked, this, [this]() {
  148. static QPointer<ThemeSettingsWidget> s_settings;
  149. if (!s_settings) {
  150. s_settings = new ThemeSettingsWidget();
  151. s_settings->setAttribute(Qt::WA_DeleteOnClose);
  152. s_settings->setWindowTitle(tr("设置"));
  153. s_settings->resize(520, 480);
  154. }
  155. s_settings->show();
  156. s_settings->raise();
  157. s_settings->activateWindow();
  158. });
  159. // 将按钮加入到 titleLabel 内部的水平布局(右对齐)
  160. {
  161. auto labelLayout = new QHBoxLayout(titleLabel);
  162. labelLayout->setContentsMargins(0, 0, 0, 0);
  163. labelLayout->addStretch();
  164. labelLayout->addWidget(settingsButton);
  165. }
  166. #endif
  167. windowAgent->setTitleBar(windowBar);
  168. #ifndef Q_OS_MAC
  169. windowAgent->setHitTestVisible(pinButton, true);
  170. windowAgent->setHitTestVisible(settingsButton, true);
  171. windowAgent->setSystemButton(QWK::WindowAgentBase::WindowIcon, iconButton);
  172. windowAgent->setSystemButton(QWK::WindowAgentBase::Minimize, minButton);
  173. windowAgent->setSystemButton(QWK::WindowAgentBase::Maximize, maxButton);
  174. windowAgent->setSystemButton(QWK::WindowAgentBase::Close, closeButton);
  175. #endif
  176. #ifdef Q_OS_MAC
  177. windowAgent->setSystemButtonAreaCallback([](const QSize &size) {
  178. static constexpr const int width = 75;
  179. return QRect(QPoint(size.width() - width, 0), QSize(width, size.height())); //
  180. });
  181. #endif
  182. setMenuWidget(windowBar);
  183. #ifndef Q_OS_MAC
  184. connect(this, &QMainWindow::windowTitleChanged, this, [titleLabel](const QString &title) {
  185. titleLabel->setText(title);
  186. });
  187. connect(windowBar, &QWK::WindowBar::pinRequested, this, [this, pinButton](bool pin) {
  188. if (isHidden() || isMinimized() || isMaximized() || isFullScreen()) {
  189. return;
  190. }
  191. setWindowFlag(Qt::WindowStaysOnTopHint, pin);
  192. show();
  193. pinButton->setChecked(pin);
  194. });
  195. connect(windowBar, &QWK::WindowBar::minimizeRequested, this, &QWidget::showMinimized);
  196. connect(windowBar, &QWK::WindowBar::maximizeRequested, this, [this, maxButton](bool max) {
  197. if (max) {
  198. showMaximized();
  199. } else {
  200. showNormal();
  201. }
  202. // It's a Qt issue that if a QAbstractButton::clicked triggers a window's maximization,
  203. // the button remains to be hovered until the mouse move. As a result, we need to
  204. // manually send leave events to the button.
  205. emulateLeaveEvent(maxButton);
  206. });
  207. connect(windowBar, &QWK::WindowBar::closeRequested, this, &QWidget::close);
  208. #endif
  209. }
  210. TWidget::TWidget(QWidget *parent)
  211. : QWidget(parent)
  212. , m_menuWidget(nullptr)
  213. , m_mainLayout(nullptr)
  214. {
  215. m_mainLayout = new QVBoxLayout(this);
  216. m_mainLayout->setContentsMargins(0, 0, 0, 0);
  217. m_mainLayout->setSpacing(0);
  218. setLayout(m_mainLayout);
  219. setAttribute(Qt::WA_DontCreateNativeAncestors);
  220. installWindowAgent();
  221. }
  222. QWidget *TWidget::menuWidget() const
  223. {
  224. return m_menuWidget;
  225. }
  226. void TWidget::setMenuWidget(QWidget *widget)
  227. {
  228. if (m_menuWidget) {
  229. m_mainLayout->removeWidget(m_menuWidget);
  230. delete m_menuWidget;
  231. }
  232. // 添加新标题栏到布局顶部
  233. m_menuWidget = widget;
  234. if (m_menuWidget) {
  235. m_mainLayout->insertWidget(0, m_menuWidget); // 插入到第一个位置
  236. }
  237. }
  238. bool TWidget::event(QEvent *event)
  239. {
  240. switch (event->type()) {
  241. case QEvent::WindowActivate: {
  242. auto menu = menuWidget();
  243. if (menu) {
  244. menu->setProperty("bar-active", true);
  245. style()->polish(menu);
  246. }
  247. break;
  248. }
  249. case QEvent::WindowDeactivate: {
  250. auto menu = menuWidget();
  251. if (menu) {
  252. menu->setProperty("bar-active", false);
  253. style()->polish(menu);
  254. }
  255. break;
  256. }
  257. default:
  258. break;
  259. }
  260. return QWidget::event(event);
  261. }
  262. void TWidget::installWindowAgent()
  263. {
  264. // 1. Setup window agent
  265. windowAgent = new QWK::WidgetWindowAgent(this);
  266. windowAgent->setup(this);
  267. auto titleLabel = new QLabel();
  268. titleLabel->setAlignment(Qt::AlignCenter);
  269. titleLabel->setObjectName(QStringLiteral("win-title-label"));
  270. #ifndef Q_OS_MAC
  271. auto iconButton = new QWK::WindowButton();
  272. iconButton->setObjectName(QStringLiteral("icon-button"));
  273. iconButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  274. auto pinButton = new QWK::WindowButton();
  275. pinButton->setCheckable(true);
  276. pinButton->setObjectName(QStringLiteral("pin-button"));
  277. pinButton->setProperty("system-button", true);
  278. pinButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  279. auto minButton = new QWK::WindowButton();
  280. minButton->setObjectName(QStringLiteral("min-button"));
  281. minButton->setProperty("system-button", true);
  282. minButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  283. auto maxButton = new QWK::WindowButton();
  284. maxButton->setCheckable(true);
  285. maxButton->setObjectName(QStringLiteral("max-button"));
  286. maxButton->setProperty("system-button", true);
  287. maxButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  288. auto closeButton = new QWK::WindowButton();
  289. closeButton->setObjectName(QStringLiteral("close-button"));
  290. closeButton->setProperty("system-button", true);
  291. closeButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  292. #endif
  293. auto windowBar = new QWK::WindowBar();
  294. #ifndef Q_OS_MAC
  295. windowBar->setIconButton(iconButton);
  296. windowBar->setPinButton(pinButton);
  297. windowBar->setMinButton(minButton);
  298. windowBar->setMaxButton(maxButton);
  299. windowBar->setCloseButton(closeButton);
  300. #endif
  301. windowBar->setTitleLabel(titleLabel);
  302. windowBar->setHostWidget(this);
  303. #ifndef Q_OS_MAC
  304. // 创建一个“设置”按钮,放在标题文本区域的最右侧,使其位于置顶按钮的左侧
  305. auto settingsButton = new QWK::WindowButton(windowBar);
  306. settingsButton->setObjectName(QStringLiteral("settings-button"));
  307. settingsButton->setProperty("system-button", true);
  308. settingsButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  309. settingsButton->setIconNormal(QIcon(QStringLiteral(":/window-bar/more-line.svg")));
  310. QObject::connect(settingsButton, &QAbstractButton::clicked, this, [this]() {
  311. static QPointer<ThemeSettingsWidget> s_settings;
  312. if (!s_settings) {
  313. s_settings = new ThemeSettingsWidget();
  314. s_settings->setAttribute(Qt::WA_DeleteOnClose);
  315. s_settings->setWindowTitle(tr("设置"));
  316. s_settings->resize(520, 480);
  317. }
  318. s_settings->show();
  319. s_settings->raise();
  320. s_settings->activateWindow();
  321. });
  322. // 将按钮加入到 titleLabel 内部的水平布局(右对齐)
  323. {
  324. auto labelLayout = new QHBoxLayout(titleLabel);
  325. labelLayout->setContentsMargins(0, 0, 0, 0);
  326. labelLayout->addStretch();
  327. labelLayout->addWidget(settingsButton);
  328. }
  329. #endif
  330. windowAgent->setTitleBar(windowBar);
  331. #ifndef Q_OS_MAC
  332. windowAgent->setHitTestVisible(pinButton, true);
  333. windowAgent->setHitTestVisible(settingsButton, true);
  334. windowAgent->setSystemButton(QWK::WindowAgentBase::WindowIcon, iconButton);
  335. windowAgent->setSystemButton(QWK::WindowAgentBase::Minimize, minButton);
  336. windowAgent->setSystemButton(QWK::WindowAgentBase::Maximize, maxButton);
  337. windowAgent->setSystemButton(QWK::WindowAgentBase::Close, closeButton);
  338. #endif
  339. #ifdef Q_OS_MAC
  340. windowAgent->setSystemButtonAreaCallback([](const QSize &size) {
  341. static constexpr const int width = 75;
  342. return QRect(QPoint(size.width() - width, 0), QSize(width, size.height())); //
  343. });
  344. #endif
  345. setMenuWidget(windowBar);
  346. #ifndef Q_OS_MAC
  347. connect(windowBar, &QWK::WindowBar::pinRequested, this, [this, pinButton](bool pin) {
  348. if (isHidden() || isMinimized() || isMaximized() || isFullScreen()) {
  349. return;
  350. }
  351. setWindowFlag(Qt::WindowStaysOnTopHint, pin);
  352. show();
  353. pinButton->setChecked(pin);
  354. });
  355. connect(windowBar, &QWK::WindowBar::minimizeRequested, this, &QWidget::showMinimized);
  356. connect(windowBar, &QWK::WindowBar::maximizeRequested, this, [this, maxButton](bool max) {
  357. if (max) {
  358. showMaximized();
  359. } else {
  360. showNormal();
  361. }
  362. // It's a Qt issue that if a QAbstractButton::clicked triggers a window's maximization,
  363. // the button remains to be hovered until the mouse move. As a result, we need to
  364. // manually send leave events to the button.
  365. emulateLeaveEvent(maxButton);
  366. });
  367. connect(windowBar, &QWK::WindowBar::closeRequested, this, &QWidget::close);
  368. #endif
  369. }
  370. // ---------------- TDialog (QDialog-based) ----------------
  371. TDialog::TDialog(QWidget *parent)
  372. : QDialog(parent)
  373. , m_menuWidget(nullptr)
  374. , m_mainLayout(nullptr)
  375. {
  376. // QDialog 默认是 Qt::Dialog 窗口类型
  377. setAttribute(Qt::WA_DontCreateNativeAncestors);
  378. m_mainLayout = new QVBoxLayout(this);
  379. m_mainLayout->setContentsMargins(0, 0, 0, 0);
  380. m_mainLayout->setSpacing(0);
  381. setLayout(m_mainLayout);
  382. // 启用与 TWidget 一致的自定义无边框标题栏/按钮
  383. installWindowAgent();
  384. }
  385. QWidget *TDialog::menuWidget() const
  386. {
  387. return m_menuWidget;
  388. }
  389. void TDialog::setMenuWidget(QWidget *widget)
  390. {
  391. if (m_menuWidget) {
  392. m_mainLayout->removeWidget(m_menuWidget);
  393. delete m_menuWidget;
  394. }
  395. m_menuWidget = widget;
  396. if (m_menuWidget) {
  397. m_mainLayout->insertWidget(0, m_menuWidget);
  398. }
  399. }
  400. bool TDialog::event(QEvent *event)
  401. {
  402. switch (event->type()) {
  403. case QEvent::WindowActivate: {
  404. auto menu = menuWidget();
  405. if (menu) {
  406. menu->setProperty("bar-active", true);
  407. style()->polish(menu);
  408. }
  409. break;
  410. }
  411. case QEvent::WindowDeactivate: {
  412. auto menu = menuWidget();
  413. if (menu) {
  414. menu->setProperty("bar-active", false);
  415. style()->polish(menu);
  416. }
  417. break;
  418. }
  419. default:
  420. break;
  421. }
  422. return QDialog::event(event);
  423. }
  424. void TDialog::installWindowAgent()
  425. {
  426. // 1. Setup window agent
  427. windowAgent = new QWK::WidgetWindowAgent(this);
  428. windowAgent->setup(this);
  429. auto titleLabel = new QLabel(windowTitle());
  430. titleLabel->setAlignment(Qt::AlignCenter);
  431. titleLabel->setObjectName(QStringLiteral("win-title-label"));
  432. #ifndef Q_OS_MAC
  433. auto iconButton = new QWK::WindowButton();
  434. iconButton->setObjectName(QStringLiteral("icon-button"));
  435. iconButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  436. auto pinButton = new QWK::WindowButton();
  437. pinButton->setCheckable(true);
  438. pinButton->setObjectName(QStringLiteral("pin-button"));
  439. pinButton->setProperty("system-button", true);
  440. pinButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  441. auto minButton = new QWK::WindowButton();
  442. minButton->setObjectName(QStringLiteral("min-button"));
  443. minButton->setProperty("system-button", true);
  444. minButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  445. auto maxButton = new QWK::WindowButton();
  446. maxButton->setCheckable(true);
  447. maxButton->setObjectName(QStringLiteral("max-button"));
  448. maxButton->setProperty("system-button", true);
  449. maxButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  450. auto closeButton = new QWK::WindowButton();
  451. closeButton->setObjectName(QStringLiteral("close-button"));
  452. closeButton->setProperty("system-button", true);
  453. closeButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  454. #endif
  455. auto windowBar = new QWK::WindowBar();
  456. #ifndef Q_OS_MAC
  457. windowBar->setIconButton(iconButton);
  458. windowBar->setPinButton(pinButton);
  459. windowBar->setMinButton(minButton);
  460. windowBar->setMaxButton(maxButton);
  461. windowBar->setCloseButton(closeButton);
  462. #endif
  463. windowBar->setTitleLabel(titleLabel);
  464. windowBar->setHostWidget(this);
  465. #ifndef Q_OS_MAC
  466. // 创建一个“设置”按钮,放在标题文本区域的最右侧,使其位于置顶按钮的左侧
  467. auto settingsButton = new QWK::WindowButton(windowBar);
  468. settingsButton->setObjectName(QStringLiteral("settings-button"));
  469. settingsButton->setProperty("system-button", true);
  470. settingsButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  471. settingsButton->setIconNormal(QIcon(QStringLiteral(":/window-bar/more-line.svg")));
  472. QObject::connect(settingsButton, &QAbstractButton::clicked, this, [this]() {
  473. static QPointer<ThemeSettingsWidget> s_settings;
  474. if (!s_settings) {
  475. s_settings = new ThemeSettingsWidget();
  476. s_settings->setAttribute(Qt::WA_DeleteOnClose);
  477. s_settings->setWindowTitle(tr("设置"));
  478. s_settings->resize(520, 480);
  479. }
  480. s_settings->show();
  481. s_settings->raise();
  482. s_settings->activateWindow();
  483. });
  484. // 将按钮加入到 titleLabel 内部的水平布局(右对齐)
  485. {
  486. auto labelLayout = new QHBoxLayout(titleLabel);
  487. labelLayout->setContentsMargins(0, 0, 0, 0);
  488. labelLayout->addStretch();
  489. labelLayout->addWidget(settingsButton);
  490. }
  491. #endif
  492. windowAgent->setTitleBar(windowBar);
  493. #ifndef Q_OS_MAC
  494. windowAgent->setHitTestVisible(pinButton, true);
  495. windowAgent->setHitTestVisible(settingsButton, true);
  496. windowAgent->setSystemButton(QWK::WindowAgentBase::WindowIcon, iconButton);
  497. windowAgent->setSystemButton(QWK::WindowAgentBase::Minimize, minButton);
  498. windowAgent->setSystemButton(QWK::WindowAgentBase::Maximize, maxButton);
  499. windowAgent->setSystemButton(QWK::WindowAgentBase::Close, closeButton);
  500. #endif
  501. #ifdef Q_OS_MAC
  502. windowAgent->setSystemButtonAreaCallback([](const QSize &size) {
  503. static constexpr const int width = 75;
  504. return QRect(QPoint(size.width() - width, 0), QSize(width, size.height())); //
  505. });
  506. #endif
  507. setMenuWidget(windowBar);
  508. #ifndef Q_OS_MAC
  509. connect(this, &QDialog::windowTitleChanged, this, [titleLabel](const QString &title) {
  510. titleLabel->setText(title);
  511. });
  512. connect(windowBar, &QWK::WindowBar::pinRequested, this, [this, pinButton](bool pin) {
  513. if (isHidden() || isMinimized() || isMaximized() || isFullScreen()) {
  514. return;
  515. }
  516. setWindowFlag(Qt::WindowStaysOnTopHint, pin);
  517. show();
  518. pinButton->setChecked(pin);
  519. });
  520. connect(windowBar, &QWK::WindowBar::minimizeRequested, this, &QWidget::showMinimized);
  521. connect(windowBar, &QWK::WindowBar::maximizeRequested, this, [this, maxButton](bool max) {
  522. if (max) {
  523. showMaximized();
  524. } else {
  525. showNormal();
  526. }
  527. emulateLeaveEvent(maxButton);
  528. });
  529. connect(windowBar, &QWK::WindowBar::closeRequested, this, &QWidget::close);
  530. #endif
  531. }
  532. void TDialog::accept()
  533. {
  534. QDialog::accept();
  535. }
  536. void TDialog::reject()
  537. {
  538. QDialog::reject();
  539. }