framelessbase.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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();
  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. settingsButton->setMaximumWidth(35);
  148. QObject::connect(settingsButton, &QAbstractButton::clicked, this, []() {
  149. static QPointer<ThemeSettingsWidget> s_settings;
  150. if (!s_settings) {
  151. s_settings = new ThemeSettingsWidget();
  152. s_settings->setAttribute(Qt::WA_DeleteOnClose);
  153. s_settings->setWindowTitle(tr("设置"));
  154. s_settings->resize(520, 480);
  155. }
  156. s_settings->show();
  157. s_settings->raise();
  158. s_settings->activateWindow();
  159. });
  160. // 将按钮加入到 titleLabel 内部的水平布局(右对齐)
  161. {
  162. auto labelLayout = new QHBoxLayout(titleLabel);
  163. labelLayout->setContentsMargins(0, 0, 0, 0);
  164. labelLayout->addStretch();
  165. labelLayout->addWidget(settingsButton);
  166. }
  167. #endif
  168. windowAgent->setTitleBar(windowBar);
  169. #ifndef Q_OS_MAC
  170. windowAgent->setHitTestVisible(pinButton, true);
  171. windowAgent->setHitTestVisible(settingsButton, true);
  172. windowAgent->setSystemButton(QWK::WindowAgentBase::WindowIcon, iconButton);
  173. windowAgent->setSystemButton(QWK::WindowAgentBase::Minimize, minButton);
  174. windowAgent->setSystemButton(QWK::WindowAgentBase::Maximize, maxButton);
  175. windowAgent->setSystemButton(QWK::WindowAgentBase::Close, closeButton);
  176. #endif
  177. #ifdef Q_OS_MAC
  178. windowAgent->setSystemButtonAreaCallback([](const QSize &size) {
  179. static constexpr const int width = 75;
  180. return QRect(QPoint(size.width() - width, 0), QSize(width, size.height())); //
  181. });
  182. #endif
  183. setMenuWidget(windowBar);
  184. #ifndef Q_OS_MAC
  185. connect(this, &QMainWindow::windowTitleChanged, this, [titleLabel](const QString &title) {
  186. titleLabel->setText(title);
  187. });
  188. connect(windowBar, &QWK::WindowBar::pinRequested, this, [this, pinButton](bool pin) {
  189. if (isHidden() || isMinimized() || isMaximized() || isFullScreen()) {
  190. return;
  191. }
  192. setWindowFlag(Qt::WindowStaysOnTopHint, pin);
  193. show();
  194. pinButton->setChecked(pin);
  195. });
  196. connect(windowBar, &QWK::WindowBar::minimizeRequested, this, &QWidget::showMinimized);
  197. connect(windowBar, &QWK::WindowBar::maximizeRequested, this, [this, maxButton](bool max) {
  198. if (max) {
  199. showMaximized();
  200. } else {
  201. showNormal();
  202. }
  203. // It's a Qt issue that if a QAbstractButton::clicked triggers a window's maximization,
  204. // the button remains to be hovered until the mouse move. As a result, we need to
  205. // manually send leave events to the button.
  206. emulateLeaveEvent(maxButton);
  207. });
  208. connect(windowBar, &QWK::WindowBar::closeRequested, this, &QWidget::close);
  209. #endif
  210. }
  211. TWidget::TWidget(QWidget *parent)
  212. : QWidget(parent)
  213. , m_menuWidget(nullptr)
  214. , m_mainLayout(nullptr)
  215. {
  216. m_mainLayout = new QVBoxLayout(this);
  217. m_mainLayout->setContentsMargins(0, 0, 0, 0);
  218. m_mainLayout->setSpacing(0);
  219. setLayout(m_mainLayout);
  220. setAttribute(Qt::WA_DontCreateNativeAncestors);
  221. installWindowAgent();
  222. }
  223. QWidget *TWidget::menuWidget() const
  224. {
  225. return m_menuWidget;
  226. }
  227. void TWidget::setMenuWidget(QWidget *widget)
  228. {
  229. if (m_menuWidget) {
  230. m_mainLayout->removeWidget(m_menuWidget);
  231. delete m_menuWidget;
  232. }
  233. // 添加新标题栏到布局顶部
  234. m_menuWidget = widget;
  235. if (m_menuWidget) {
  236. m_mainLayout->insertWidget(0, m_menuWidget); // 插入到第一个位置
  237. }
  238. }
  239. bool TWidget::event(QEvent *event)
  240. {
  241. switch (event->type()) {
  242. case QEvent::WindowActivate: {
  243. auto menu = menuWidget();
  244. if (menu) {
  245. menu->setProperty("bar-active", true);
  246. style()->polish(menu);
  247. }
  248. break;
  249. }
  250. case QEvent::WindowDeactivate: {
  251. auto menu = menuWidget();
  252. if (menu) {
  253. menu->setProperty("bar-active", false);
  254. style()->polish(menu);
  255. }
  256. break;
  257. }
  258. default:
  259. break;
  260. }
  261. return QWidget::event(event);
  262. }
  263. void TWidget::installWindowAgent()
  264. {
  265. // 1. Setup window agent
  266. windowAgent = new QWK::WidgetWindowAgent(this);
  267. windowAgent->setup(this);
  268. auto titleLabel = new QLabel();
  269. titleLabel->setAlignment(Qt::AlignCenter);
  270. titleLabel->setObjectName(QStringLiteral("win-title-label"));
  271. #ifndef Q_OS_MAC
  272. auto iconButton = new QWK::WindowButton();
  273. iconButton->setObjectName(QStringLiteral("icon-button"));
  274. iconButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  275. auto pinButton = new QWK::WindowButton();
  276. pinButton->setCheckable(true);
  277. pinButton->setObjectName(QStringLiteral("pin-button"));
  278. pinButton->setProperty("system-button", true);
  279. pinButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  280. auto minButton = new QWK::WindowButton();
  281. minButton->setObjectName(QStringLiteral("min-button"));
  282. minButton->setProperty("system-button", true);
  283. minButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  284. auto maxButton = new QWK::WindowButton();
  285. maxButton->setCheckable(true);
  286. maxButton->setObjectName(QStringLiteral("max-button"));
  287. maxButton->setProperty("system-button", true);
  288. maxButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  289. auto closeButton = new QWK::WindowButton();
  290. closeButton->setObjectName(QStringLiteral("close-button"));
  291. closeButton->setProperty("system-button", true);
  292. closeButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  293. #endif
  294. auto windowBar = new QWK::WindowBar();
  295. #ifndef Q_OS_MAC
  296. windowBar->setIconButton(iconButton);
  297. windowBar->setPinButton(pinButton);
  298. windowBar->setMinButton(minButton);
  299. windowBar->setMaxButton(maxButton);
  300. windowBar->setCloseButton(closeButton);
  301. #endif
  302. windowBar->setTitleLabel(titleLabel);
  303. windowBar->setHostWidget(this);
  304. #ifndef Q_OS_MAC
  305. // 创建一个“设置”按钮,放在标题文本区域的最右侧,使其位于置顶按钮的左侧
  306. auto settingsButton = new QWK::WindowButton(windowBar);
  307. settingsButton->setObjectName(QStringLiteral("settings-button"));
  308. settingsButton->setProperty("system-button", true);
  309. settingsButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  310. settingsButton->setIconNormal(QIcon(QStringLiteral(":/window-bar/more-line.svg")));
  311. QObject::connect(settingsButton, &QAbstractButton::clicked, this, [this]() {
  312. static QPointer<ThemeSettingsWidget> s_settings;
  313. if (!s_settings) {
  314. s_settings = new ThemeSettingsWidget();
  315. s_settings->setAttribute(Qt::WA_DeleteOnClose);
  316. s_settings->setWindowTitle(tr("设置"));
  317. s_settings->resize(520, 480);
  318. }
  319. s_settings->show();
  320. s_settings->raise();
  321. s_settings->activateWindow();
  322. });
  323. // 将按钮加入到 titleLabel 内部的水平布局(右对齐)
  324. {
  325. auto labelLayout = new QHBoxLayout(titleLabel);
  326. labelLayout->setContentsMargins(0, 0, 0, 0);
  327. labelLayout->addStretch();
  328. labelLayout->addWidget(settingsButton);
  329. }
  330. #endif
  331. windowAgent->setTitleBar(windowBar);
  332. #ifndef Q_OS_MAC
  333. windowAgent->setHitTestVisible(pinButton, true);
  334. windowAgent->setHitTestVisible(settingsButton, true);
  335. windowAgent->setSystemButton(QWK::WindowAgentBase::WindowIcon, iconButton);
  336. windowAgent->setSystemButton(QWK::WindowAgentBase::Minimize, minButton);
  337. windowAgent->setSystemButton(QWK::WindowAgentBase::Maximize, maxButton);
  338. windowAgent->setSystemButton(QWK::WindowAgentBase::Close, closeButton);
  339. #endif
  340. #ifdef Q_OS_MAC
  341. windowAgent->setSystemButtonAreaCallback([](const QSize &size) {
  342. static constexpr const int width = 75;
  343. return QRect(QPoint(size.width() - width, 0), QSize(width, size.height())); //
  344. });
  345. #endif
  346. setMenuWidget(windowBar);
  347. #ifndef Q_OS_MAC
  348. connect(windowBar, &QWK::WindowBar::pinRequested, this, [this, pinButton](bool pin) {
  349. if (isHidden() || isMinimized() || isMaximized() || isFullScreen()) {
  350. return;
  351. }
  352. setWindowFlag(Qt::WindowStaysOnTopHint, pin);
  353. show();
  354. pinButton->setChecked(pin);
  355. });
  356. connect(windowBar, &QWK::WindowBar::minimizeRequested, this, &QWidget::showMinimized);
  357. connect(windowBar, &QWK::WindowBar::maximizeRequested, this, [this, maxButton](bool max) {
  358. if (max) {
  359. showMaximized();
  360. } else {
  361. showNormal();
  362. }
  363. // It's a Qt issue that if a QAbstractButton::clicked triggers a window's maximization,
  364. // the button remains to be hovered until the mouse move. As a result, we need to
  365. // manually send leave events to the button.
  366. emulateLeaveEvent(maxButton);
  367. });
  368. connect(windowBar, &QWK::WindowBar::closeRequested, this, &QWidget::close);
  369. #endif
  370. }
  371. // ---------------- TDialog (QDialog-based) ----------------
  372. TDialog::TDialog(QWidget *parent)
  373. : QDialog(parent)
  374. , m_menuWidget(nullptr)
  375. , m_mainLayout(nullptr)
  376. {
  377. // QDialog 默认是 Qt::Dialog 窗口类型
  378. setAttribute(Qt::WA_DontCreateNativeAncestors);
  379. m_mainLayout = new QVBoxLayout(this);
  380. m_mainLayout->setContentsMargins(0, 0, 0, 0);
  381. m_mainLayout->setSpacing(0);
  382. setLayout(m_mainLayout);
  383. // 启用与 TWidget 一致的自定义无边框标题栏/按钮
  384. installWindowAgent();
  385. }
  386. QWidget *TDialog::menuWidget() const
  387. {
  388. return m_menuWidget;
  389. }
  390. void TDialog::setMenuWidget(QWidget *widget)
  391. {
  392. if (m_menuWidget) {
  393. m_mainLayout->removeWidget(m_menuWidget);
  394. delete m_menuWidget;
  395. }
  396. m_menuWidget = widget;
  397. if (m_menuWidget) {
  398. m_mainLayout->insertWidget(0, m_menuWidget);
  399. }
  400. }
  401. bool TDialog::event(QEvent *event)
  402. {
  403. switch (event->type()) {
  404. case QEvent::WindowActivate: {
  405. auto menu = menuWidget();
  406. if (menu) {
  407. menu->setProperty("bar-active", true);
  408. style()->polish(menu);
  409. }
  410. break;
  411. }
  412. case QEvent::WindowDeactivate: {
  413. auto menu = menuWidget();
  414. if (menu) {
  415. menu->setProperty("bar-active", false);
  416. style()->polish(menu);
  417. }
  418. break;
  419. }
  420. default:
  421. break;
  422. }
  423. return QDialog::event(event);
  424. }
  425. void TDialog::installWindowAgent()
  426. {
  427. // 1. Setup window agent
  428. windowAgent = new QWK::WidgetWindowAgent(this);
  429. windowAgent->setup(this);
  430. auto titleLabel = new QLabel(windowTitle());
  431. titleLabel->setAlignment(Qt::AlignCenter);
  432. titleLabel->setObjectName(QStringLiteral("win-title-label"));
  433. #ifndef Q_OS_MAC
  434. auto iconButton = new QWK::WindowButton();
  435. iconButton->setObjectName(QStringLiteral("icon-button"));
  436. iconButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  437. auto pinButton = new QWK::WindowButton();
  438. pinButton->setCheckable(true);
  439. pinButton->setObjectName(QStringLiteral("pin-button"));
  440. pinButton->setProperty("system-button", true);
  441. pinButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  442. auto minButton = new QWK::WindowButton();
  443. minButton->setObjectName(QStringLiteral("min-button"));
  444. minButton->setProperty("system-button", true);
  445. minButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  446. auto maxButton = new QWK::WindowButton();
  447. maxButton->setCheckable(true);
  448. maxButton->setObjectName(QStringLiteral("max-button"));
  449. maxButton->setProperty("system-button", true);
  450. maxButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  451. auto closeButton = new QWK::WindowButton();
  452. closeButton->setObjectName(QStringLiteral("close-button"));
  453. closeButton->setProperty("system-button", true);
  454. closeButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  455. #endif
  456. auto windowBar = new QWK::WindowBar();
  457. #ifndef Q_OS_MAC
  458. windowBar->setIconButton(iconButton);
  459. windowBar->setPinButton(pinButton);
  460. windowBar->setMinButton(minButton);
  461. windowBar->setMaxButton(maxButton);
  462. windowBar->setCloseButton(closeButton);
  463. #endif
  464. windowBar->setTitleLabel(titleLabel);
  465. windowBar->setHostWidget(this);
  466. #ifndef Q_OS_MAC
  467. // 创建一个“设置”按钮,放在标题文本区域的最右侧,使其位于置顶按钮的左侧
  468. auto settingsButton = new QWK::WindowButton(windowBar);
  469. settingsButton->setObjectName(QStringLiteral("settings-button"));
  470. settingsButton->setProperty("system-button", true);
  471. settingsButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  472. settingsButton->setIconNormal(QIcon(QStringLiteral(":/window-bar/more-line.svg")));
  473. QObject::connect(settingsButton, &QAbstractButton::clicked, this, [this]() {
  474. static QPointer<ThemeSettingsWidget> s_settings;
  475. if (!s_settings) {
  476. s_settings = new ThemeSettingsWidget();
  477. s_settings->setAttribute(Qt::WA_DeleteOnClose);
  478. s_settings->setWindowTitle(tr("设置"));
  479. s_settings->resize(520, 480);
  480. }
  481. s_settings->show();
  482. s_settings->raise();
  483. s_settings->activateWindow();
  484. });
  485. // 将按钮加入到 titleLabel 内部的水平布局(右对齐)
  486. {
  487. auto labelLayout = new QHBoxLayout(titleLabel);
  488. labelLayout->setContentsMargins(0, 0, 0, 0);
  489. labelLayout->addStretch();
  490. labelLayout->addWidget(settingsButton);
  491. }
  492. #endif
  493. windowAgent->setTitleBar(windowBar);
  494. #ifndef Q_OS_MAC
  495. windowAgent->setHitTestVisible(pinButton, true);
  496. windowAgent->setHitTestVisible(settingsButton, true);
  497. windowAgent->setSystemButton(QWK::WindowAgentBase::WindowIcon, iconButton);
  498. windowAgent->setSystemButton(QWK::WindowAgentBase::Minimize, minButton);
  499. windowAgent->setSystemButton(QWK::WindowAgentBase::Maximize, maxButton);
  500. windowAgent->setSystemButton(QWK::WindowAgentBase::Close, closeButton);
  501. #endif
  502. #ifdef Q_OS_MAC
  503. windowAgent->setSystemButtonAreaCallback([](const QSize &size) {
  504. static constexpr const int width = 75;
  505. return QRect(QPoint(size.width() - width, 0), QSize(width, size.height())); //
  506. });
  507. #endif
  508. setMenuWidget(windowBar);
  509. #ifndef Q_OS_MAC
  510. connect(this, &QDialog::windowTitleChanged, this, [titleLabel](const QString &title) {
  511. titleLabel->setText(title);
  512. });
  513. connect(windowBar, &QWK::WindowBar::pinRequested, this, [this, pinButton](bool pin) {
  514. if (isHidden() || isMinimized() || isMaximized() || isFullScreen()) {
  515. return;
  516. }
  517. setWindowFlag(Qt::WindowStaysOnTopHint, pin);
  518. show();
  519. pinButton->setChecked(pin);
  520. });
  521. connect(windowBar, &QWK::WindowBar::minimizeRequested, this, &QWidget::showMinimized);
  522. connect(windowBar, &QWK::WindowBar::maximizeRequested, this, [this, maxButton](bool max) {
  523. if (max) {
  524. showMaximized();
  525. } else {
  526. showNormal();
  527. }
  528. emulateLeaveEvent(maxButton);
  529. });
  530. connect(windowBar, &QWK::WindowBar::closeRequested, this, &QWidget::close);
  531. #endif
  532. }
  533. void TDialog::accept()
  534. {
  535. QDialog::accept();
  536. }
  537. void TDialog::reject()
  538. {
  539. QDialog::reject();
  540. }