| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #include "capture_source_widget.h"
- #include <capturer/finder.h>
- CaptureSourceWidget::CaptureSourceWidget(QWidget* parent)
- : QWidget(parent)
- , m_captureComboBox(nullptr)
- , m_updateListBtn(nullptr)
- , m_captureGroup(nullptr)
- , m_layout(nullptr)
- {
- setupUi();
- updateCaptureList();
- }
- void CaptureSourceWidget::setupUi()
- {
- // 创建控件
- m_captureComboBox = new QComboBox(this);
- m_updateListBtn = new QPushButton("刷新窗口列表", this);
- m_captureGroup = new QGroupBox("捕获源", this);
-
- // 设置ComboBox属性
- m_captureComboBox->setMinimumWidth(20);
-
- // 创建布局
- m_layout = new QHBoxLayout();
- m_layout->addWidget(m_captureComboBox);
- m_layout->addWidget(m_updateListBtn);
- m_captureGroup->setLayout(m_layout);
-
- // 设置主布局
- QHBoxLayout* mainLayout = new QHBoxLayout(this);
- mainLayout->setContentsMargins(0, 0, 0, 0);
- mainLayout->addWidget(m_captureGroup);
- setLayout(mainLayout);
-
- // 连接信号槽
- connect(m_captureComboBox, &QComboBox::currentTextChanged,
- this, &CaptureSourceWidget::onComboBoxTextChanged);
- connect(m_captureComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
- this, &CaptureSourceWidget::onComboBoxIndexChanged);
- connect(m_updateListBtn, &QPushButton::clicked,
- this, &CaptureSourceWidget::onRefreshButtonClicked);
- }
- int CaptureSourceWidget::getCurrentIndex() const
- {
- return m_captureComboBox ? m_captureComboBox->currentIndex() : -1;
- }
- QVariant CaptureSourceWidget::getCurrentData() const
- {
- return m_captureComboBox ? m_captureComboBox->currentData() : QVariant();
- }
- QString CaptureSourceWidget::getCurrentText() const
- {
- return m_captureComboBox ? m_captureComboBox->currentText() : QString();
- }
- void CaptureSourceWidget::setEnabled(bool enabled)
- {
- QWidget::setEnabled(enabled);
- if (m_captureComboBox) {
- m_captureComboBox->setEnabled(enabled);
- }
- if (m_updateListBtn) {
- m_updateListBtn->setEnabled(enabled);
- }
- }
- void CaptureSourceWidget::updateCaptureList()
- {
- if (!m_captureComboBox) {
- return;
- }
-
- m_captureComboBox->clear();
-
- // 添加屏幕列表
- auto&& monitorList = MonitorFinder::GetList(true);
- for (auto&& monitor : monitorList) {
- QString text = "屏幕: " + QString::fromStdWString(monitor.title);
- m_captureComboBox->addItem(text, QVariant::fromValue(qintptr(monitor.monitor)));
- }
-
- // 添加窗口列表
- auto&& windowList = WindowFinder::GetList(true);
- for (auto&& window : windowList) {
- QString text = "窗口: " + QString::fromStdWString(window.title);
- m_captureComboBox->addItem(text, QVariant::fromValue(qintptr(window.hwnd)));
- }
- }
- void CaptureSourceWidget::onComboBoxTextChanged(const QString& text)
- {
- emit captureSourceTextChanged(text);
- }
- void CaptureSourceWidget::onComboBoxIndexChanged(int index)
- {
- emit captureSourceIndexChanged(index);
- }
- void CaptureSourceWidget::onRefreshButtonClicked()
- {
- updateCaptureList();
- emit refreshRequested();
- }
|