main111.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #include <QApplication>
  2. #include <QMainWindow>
  3. #include <QVBoxLayout>
  4. #include <QHBoxLayout>
  5. #include <QPushButton>
  6. #include <QLabel>
  7. #include <QStatusBar>
  8. #include <QMenuBar>
  9. #include <QAction>
  10. #include <QMessageBox>
  11. #include <QTimer>
  12. #include <QDebug>
  13. #include "screenwall_widget.h"
  14. class ScreenWallMainWindow : public QMainWindow
  15. {
  16. public:
  17. explicit ScreenWallMainWindow(QWidget *parent = nullptr)
  18. : QMainWindow(parent)
  19. , m_screenWall(nullptr)
  20. , m_startButton(nullptr)
  21. , m_stopButton(nullptr)
  22. , m_refreshButton(nullptr)
  23. , m_statusLabel(nullptr)
  24. {
  25. setupUI();
  26. setupConnections();
  27. setupMenus();
  28. setWindowTitle("屏幕墙 - 实时窗口预览系统");
  29. setMinimumSize(1000, 700);
  30. resize(1400, 1000);
  31. }
  32. private slots:
  33. void startScreenWall()
  34. {
  35. if (m_screenWall) {
  36. m_screenWall->startScreenWall();
  37. m_startButton->setEnabled(false);
  38. m_stopButton->setEnabled(true);
  39. m_refreshButton->setEnabled(true);
  40. m_statusLabel->setText("状态: 运行中");
  41. statusBar()->showMessage("屏幕墙已启动", 3000);
  42. }
  43. }
  44. void stopScreenWall()
  45. {
  46. if (m_screenWall) {
  47. m_screenWall->stopScreenWall();
  48. m_startButton->setEnabled(true);
  49. m_stopButton->setEnabled(false);
  50. m_refreshButton->setEnabled(false);
  51. m_statusLabel->setText("状态: 已停止");
  52. statusBar()->showMessage("屏幕墙已停止", 3000);
  53. }
  54. }
  55. void refreshWindows()
  56. {
  57. if (m_screenWall) {
  58. m_screenWall->refreshWindowList();
  59. statusBar()->showMessage("窗口列表已刷新", 2000);
  60. }
  61. }
  62. void onWindowSelected(HWND hwnd, const QString& title)
  63. {
  64. statusBar()->showMessage(QString("已选择窗口: %1").arg(title), 5000);
  65. qDebug() << "Window selected:" << title << "HWND:" << hwnd;
  66. }
  67. void onDesktopSelected()
  68. {
  69. statusBar()->showMessage("已选择桌面预览", 3000);
  70. qDebug() << "Desktop selected";
  71. }
  72. void showAbout()
  73. {
  74. QMessageBox::about(this, "关于屏幕墙",
  75. "<h3>屏幕墙 v1.0</h3>"
  76. "<p>实时窗口预览系统</p>"
  77. "<p><b>功能特性:</b></p>"
  78. "<ul>"
  79. "<li>实时桌面预览</li>"
  80. "<li>窗口图标列表</li>"
  81. "<li>实时窗口内容预览</li>"
  82. "<li>最小化窗口支持</li>"
  83. "<li>性能优化</li>"
  84. "</ul>"
  85. "<p>基于 Qt + AvRecorder 开发</p>"
  86. );
  87. }
  88. void showSettings()
  89. {
  90. // 这里可以添加设置对话框
  91. QMessageBox::information(this, "设置", "设置功能开发中...");
  92. }
  93. private:
  94. void setupUI()
  95. {
  96. // 创建中央部件
  97. auto* centralWidget = new QWidget;
  98. setCentralWidget(centralWidget);
  99. auto* mainLayout = new QVBoxLayout(centralWidget);
  100. mainLayout->setContentsMargins(5, 5, 5, 5);
  101. mainLayout->setSpacing(5);
  102. // 控制面板
  103. auto* controlPanel = createControlPanel();
  104. mainLayout->addWidget(controlPanel);
  105. // 屏幕墙组件
  106. m_screenWall = new ScreenWallWidget;
  107. mainLayout->addWidget(m_screenWall, 1);
  108. // 状态栏
  109. m_statusLabel = new QLabel("状态: 已停止");
  110. statusBar()->addWidget(m_statusLabel);
  111. statusBar()->showMessage("就绪");
  112. }
  113. QWidget* createControlPanel()
  114. {
  115. auto* panel = new QWidget;
  116. panel->setMaximumHeight(60);
  117. panel->setStyleSheet(
  118. "QWidget { "
  119. " background-color: #34495e; "
  120. " border-radius: 5px; "
  121. "}"
  122. "QPushButton { "
  123. " background-color: #3498db; "
  124. " color: white; "
  125. " border: none; "
  126. " padding: 8px 16px; "
  127. " border-radius: 4px; "
  128. " font-weight: bold; "
  129. "}"
  130. "QPushButton:hover { "
  131. " background-color: #2980b9; "
  132. "}"
  133. "QPushButton:pressed { "
  134. " background-color: #21618c; "
  135. "}"
  136. "QPushButton:disabled { "
  137. " background-color: #7f8c8d; "
  138. "}"
  139. );
  140. auto* layout = new QHBoxLayout(panel);
  141. layout->setContentsMargins(10, 10, 10, 10);
  142. layout->setSpacing(10);
  143. // 标题
  144. auto* titleLabel = new QLabel("屏幕墙控制面板");
  145. titleLabel->setStyleSheet("color: white; font-size: 14px; font-weight: bold;");
  146. layout->addWidget(titleLabel);
  147. layout->addStretch();
  148. // 控制按钮
  149. m_startButton = new QPushButton("启动");
  150. m_startButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaPlay));
  151. layout->addWidget(m_startButton);
  152. m_stopButton = new QPushButton("停止");
  153. m_stopButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaStop));
  154. m_stopButton->setEnabled(false);
  155. layout->addWidget(m_stopButton);
  156. m_refreshButton = new QPushButton("刷新");
  157. m_refreshButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_BrowserReload));
  158. m_refreshButton->setEnabled(false);
  159. layout->addWidget(m_refreshButton);
  160. return panel;
  161. }
  162. void setupConnections()
  163. {
  164. // 控制按钮
  165. connect(m_startButton, &QPushButton::clicked, this, &ScreenWallMainWindow::startScreenWall);
  166. connect(m_stopButton, &QPushButton::clicked, this, &ScreenWallMainWindow::stopScreenWall);
  167. connect(m_refreshButton, &QPushButton::clicked, this, &ScreenWallMainWindow::refreshWindows);
  168. // 屏幕墙事件
  169. connect(m_screenWall, &ScreenWallWidget::windowSelected,
  170. this, &ScreenWallMainWindow::onWindowSelected);
  171. connect(m_screenWall, &ScreenWallWidget::desktopSelected,
  172. this, &ScreenWallMainWindow::onDesktopSelected);
  173. }
  174. void setupMenus()
  175. {
  176. // 文件菜单
  177. auto* fileMenu = menuBar()->addMenu("文件(&F)");
  178. auto* exitAction = new QAction("退出(&X)", this);
  179. exitAction->setShortcut(QKeySequence::Quit);
  180. exitAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogCloseButton));
  181. connect(exitAction, &QAction::triggered, this, &QWidget::close);
  182. fileMenu->addAction(exitAction);
  183. // 视图菜单
  184. auto* viewMenu = menuBar()->addMenu("视图(&V)");
  185. auto* refreshAction = new QAction("刷新窗口列表(&R)", this);
  186. refreshAction->setShortcut(QKeySequence::Refresh);
  187. refreshAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_BrowserReload));
  188. connect(refreshAction, &QAction::triggered, this, &ScreenWallMainWindow::refreshWindows);
  189. viewMenu->addAction(refreshAction);
  190. // 工具菜单
  191. auto* toolsMenu = menuBar()->addMenu("工具(&T)");
  192. auto* settingsAction = new QAction("设置(&S)", this);
  193. settingsAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_ComputerIcon));
  194. connect(settingsAction, &QAction::triggered, this, &ScreenWallMainWindow::showSettings);
  195. toolsMenu->addAction(settingsAction);
  196. // 帮助菜单
  197. auto* helpMenu = menuBar()->addMenu("帮助(&H)");
  198. auto* aboutAction = new QAction("关于(&A)", this);
  199. aboutAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation));
  200. connect(aboutAction, &QAction::triggered, this, &ScreenWallMainWindow::showAbout);
  201. helpMenu->addAction(aboutAction);
  202. }
  203. protected:
  204. void closeEvent(QCloseEvent* event) override
  205. {
  206. if (m_screenWall) {
  207. m_screenWall->stopScreenWall();
  208. }
  209. QMainWindow::closeEvent(event);
  210. }
  211. private:
  212. ScreenWallWidget* m_screenWall;
  213. QPushButton* m_startButton;
  214. QPushButton* m_stopButton;
  215. QPushButton* m_refreshButton;
  216. QLabel* m_statusLabel;
  217. };
  218. int main(int argc, char *argv[])
  219. {
  220. QApplication app(argc, argv);
  221. // 设置应用程序信息
  222. app.setApplicationName("ScreenWall");
  223. app.setApplicationVersion("1.0");
  224. app.setOrganizationName("ScreenWall Team");
  225. // 设置应用程序样式
  226. app.setStyle("Fusion");
  227. // 创建并显示主窗口
  228. ScreenWallMainWindow window;
  229. window.show();
  230. qDebug() << "ScreenWall application started";
  231. return app.exec();
  232. }