| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654 |
- // #include "screenwall_simple.h"
- // #include <QApplication>
- // #include <QDesktopWidget>
- // #include <QScreen>
- // #include <QMouseEvent>
- // #include <QResizeEvent>
- // #include <QShowEvent>
- // #include <QHideEvent>
- // #include <QCloseEvent>
- // #include <QPainter>
- // #include <QDebug>
- // #include <QMessageBox>
- // #include <QToolTip>
- // #include <QStyle>
- // #include <QStyleOption>
- // #include <QFileInfo>
- // #include <QDir>
- // #include <QStandardPaths>
- // #include <QSettings>
- // #include <QJsonDocument>
- // #include <QJsonObject>
- // #include <QPushButton>
- // #include <QVBoxLayout>
- // #include <QHBoxLayout>
- // #include <QLabel>
- // #include <string>
- // // ============================================================================
- // // SimpleWindowFinder Implementation
- // // ============================================================================
- // struct EnumWindowsData {
- // QVector<SimpleWindowInfo>* windows;
- // bool includeMinimized;
- // };
- // BOOL CALLBACK SimpleWindowFinder::enumWindowsProc(HWND hwnd, LPARAM lParam)
- // {
- // auto* data = reinterpret_cast<EnumWindowsData*>(lParam);
- // if (!isValidWindow(hwnd)) {
- // return TRUE;
- // }
- // bool isMinimized = IsIconic(hwnd);
- // if (!data->includeMinimized && isMinimized) {
- // return TRUE;
- // }
- // SimpleWindowInfo info;
- // info.hwnd = hwnd;
- // info.title = getWindowTitle(hwnd);
- // info.processName = getProcessName(hwnd);
- // info.isMinimized = isMinimized;
- // info.isVisible = IsWindowVisible(hwnd);
- // RECT rect;
- // GetWindowRect(hwnd, &rect);
- // info.geometry = QRect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
- // GetWindowThreadProcessId(hwnd, &info.processId);
- // // 获取图标
- // info.icon = SimpleCacheManager::instance().getCachedIcon(hwnd);
- // if (info.icon.isNull()) {
- // info.icon = getWindowIcon(hwnd);
- // if (!info.icon.isNull()) {
- // SimpleCacheManager::instance().cacheIcon(hwnd, info.icon);
- // }
- // }
- // data->windows->append(info);
- // return TRUE;
- // }
- // QVector<SimpleWindowInfo> SimpleWindowFinder::getWindowList(bool includeMinimized)
- // {
- // QVector<SimpleWindowInfo> windows;
- // EnumWindowsData data;
- // data.windows = &windows;
- // data.includeMinimized = includeMinimized;
- // EnumWindows(enumWindowsProc, reinterpret_cast<LPARAM>(&data));
- // return windows;
- // }
- // QPixmap SimpleWindowFinder::captureWindow(HWND hwnd, const QSize& size)
- // {
- // if (!IsWindow(hwnd)) {
- // return QPixmap();
- // }
- // // 检查缓存
- // QPixmap cached = SimpleCacheManager::instance().getCachedThumbnail(hwnd);
- // if (!cached.isNull() && (size.isEmpty() || cached.size() == size)) {
- // return cached;
- // }
- // RECT rect;
- // GetWindowRect(hwnd, &rect);
- // int width = rect.right - rect.left;
- // int height = rect.bottom - rect.top;
- // if (width <= 0 || height <= 0) {
- // return QPixmap();
- // }
- // QPixmap pixmap;
- // // 简化的窗口捕获:直接使用屏幕截图方法
- // pixmap = captureScreenshot(hwnd, rect);
- // if (!pixmap.isNull()) {
- // qDebug() << "Captured window:" << hwnd << "size:" << width << "x" << height;
- // } else {
- // qDebug() << "Failed to capture window:" << hwnd;
- // // 如果截图失败,创建一个占位图像
- // pixmap = QPixmap(width > 0 ? width : 200, height > 0 ? height : 150);
- // pixmap.fill(QColor(64, 64, 64)); // 深灰色背景
- // QPainter painter(&pixmap);
- // painter.setPen(Qt::white);
- // painter.drawText(pixmap.rect(), Qt::AlignCenter, "无法捕获窗口");
- // }
- // // 缩放到指定尺寸
- // if (!pixmap.isNull()) {
- // if (!size.isEmpty() && pixmap.size() != size) {
- // pixmap = pixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
- // }
- // // 缓存结果
- // SimpleCacheManager::instance().cacheThumbnail(hwnd, pixmap);
- // }
- // return pixmap;
- // }
- // // DWM缩略图捕获方法
- // QPixmap SimpleWindowFinder::captureDWMThumbnail(HWND hwnd, int width, int height)
- // {
- // // 检查是否支持DWM
- // BOOL dwmEnabled = FALSE;
- // if (FAILED(DwmIsCompositionEnabled(&dwmEnabled)) || !dwmEnabled) {
- // return QPixmap();
- // }
- // // 创建临时窗口用于DWM缩略图
- // HWND tempWindow = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_LAYERED,
- // L"STATIC", L"TempThumbnail",
- // WS_POPUP,
- // -32000, -32000, width, height,
- // NULL, NULL, GetModuleHandle(NULL), NULL);
- // if (!tempWindow) {
- // return QPixmap();
- // }
- // HTHUMBNAIL thumbnail = NULL;
- // HRESULT hr = DwmRegisterThumbnail(tempWindow, hwnd, &thumbnail);
- // QPixmap result;
- // if (SUCCEEDED(hr) && thumbnail) {
- // // 设置缩略图属性
- // DWM_THUMBNAIL_PROPERTIES props = {0};
- // props.dwFlags = DWM_TNP_RECTDESTINATION | DWM_TNP_RECTSOURCE | DWM_TNP_OPACITY | DWM_TNP_VISIBLE;
- // props.rcDestination = {0, 0, width, height};
- // // 获取源窗口大小
- // RECT sourceRect;
- // GetWindowRect(hwnd, &sourceRect);
- // props.rcSource = {0, 0, sourceRect.right - sourceRect.left, sourceRect.bottom - sourceRect.top};
- // props.opacity = 255;
- // props.fVisible = TRUE;
- // hr = DwmUpdateThumbnailProperties(thumbnail, &props);
- // if (SUCCEEDED(hr)) {
- // // 显示临时窗口并截图
- // ShowWindow(tempWindow, SW_SHOW);
- // UpdateWindow(tempWindow);
- // // 等待一小段时间让缩略图渲染
- // Sleep(50);
- // // 截取临时窗口
- // HDC hdcWindow = GetDC(tempWindow);
- // HDC hdcMemDC = CreateCompatibleDC(hdcWindow);
- // HBITMAP hbmScreen = CreateCompatibleBitmap(hdcWindow, width, height);
- // HGDIOBJ oldBitmap = SelectObject(hdcMemDC, hbmScreen);
- // BitBlt(hdcMemDC, 0, 0, width, height, hdcWindow, 0, 0, SRCCOPY);
- // result = convertBitmapToPixmap(hbmScreen, width, height);
- // // 清理资源
- // SelectObject(hdcMemDC, oldBitmap);
- // DeleteObject(hbmScreen);
- // DeleteDC(hdcMemDC);
- // ReleaseDC(tempWindow, hdcWindow);
- // }
- // DwmUnregisterThumbnail(thumbnail);
- // }
- // DestroyWindow(tempWindow);
- // return result;
- // }
- // // PrintWindow捕获方法
- // QPixmap SimpleWindowFinder::capturePrintWindow(HWND hwnd, int width, int height)
- // {
- // HDC hdcWindow = GetDC(hwnd);
- // HDC hdcMemDC = CreateCompatibleDC(hdcWindow);
- // HBITMAP hbmScreen = CreateCompatibleBitmap(hdcWindow, width, height);
- // HGDIOBJ oldBitmap = SelectObject(hdcMemDC, hbmScreen);
- // QPixmap result;
- // // 尝试不同的PrintWindow标志
- // UINT flags[] = {
- // PW_RENDERFULLCONTENT,
- // PW_CLIENTONLY,
- // 0 // 默认标志
- // };
- // for (int i = 0; i < 3; i++) {
- // if (PrintWindow(hwnd, hdcMemDC, flags[i])) {
- // result = convertBitmapToPixmap(hbmScreen, width, height);
- // if (!result.isNull()) {
- // break;
- // }
- // }
- // }
- // // 清理资源
- // SelectObject(hdcMemDC, oldBitmap);
- // DeleteObject(hbmScreen);
- // DeleteDC(hdcMemDC);
- // ReleaseDC(hwnd, hdcWindow);
- // return result;
- // }
- // // 屏幕截图方法
- // QPixmap SimpleWindowFinder::captureScreenshot(HWND hwnd, const RECT& rect)
- // {
- // int width = rect.right - rect.left;
- // int height = rect.bottom - rect.top;
- // HDC hdcScreen = GetDC(NULL);
- // HDC hdcMemDC = CreateCompatibleDC(hdcScreen);
- // HBITMAP hbmScreen = CreateCompatibleBitmap(hdcScreen, width, height);
- // HGDIOBJ oldBitmap = SelectObject(hdcMemDC, hbmScreen);
- // // 使用BitBlt从屏幕复制
- // BOOL result = BitBlt(hdcMemDC, 0, 0, width, height, hdcScreen, rect.left, rect.top, SRCCOPY);
- // QPixmap pixmap;
- // if (result) {
- // pixmap = convertBitmapToPixmap(hbmScreen, width, height);
- // }
- // // 清理资源
- // SelectObject(hdcMemDC, oldBitmap);
- // DeleteObject(hbmScreen);
- // DeleteDC(hdcMemDC);
- // ReleaseDC(NULL, hdcScreen);
- // return pixmap;
- // }
- // // 位图转换为QPixmap的辅助方法
- // QPixmap SimpleWindowFinder::convertBitmapToPixmap(HBITMAP hBitmap, int width, int height)
- // {
- // if (!hBitmap || width <= 0 || height <= 0) {
- // return QPixmap();
- // }
- // // 手动转换HBITMAP到QPixmap (Qt5兼容)
- // HDC hdc = CreateCompatibleDC(NULL);
- // if (!hdc) {
- // return QPixmap();
- // }
- // BITMAPINFO bmi = {0};
- // bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- // bmi.bmiHeader.biWidth = width;
- // bmi.bmiHeader.biHeight = -height; // 负值表示自上而下
- // bmi.bmiHeader.biPlanes = 1;
- // bmi.bmiHeader.biBitCount = 32;
- // bmi.bmiHeader.biCompression = BI_RGB;
- // // 分配内存
- // int dataSize = width * height * 4;
- // uchar* data = new uchar[dataSize];
- // QPixmap pixmap;
- // if (GetDIBits(hdc, hBitmap, 0, height, data, &bmi, DIB_RGB_COLORS)) {
- // // 创建QImage并转换为QPixmap
- // QImage image(data, width, height, QImage::Format_RGB32);
- // pixmap = QPixmap::fromImage(image);
- // qDebug() << "Successfully converted HBITMAP to QPixmap, size:" << width << "x" << height;
- // } else {
- // qDebug() << "Failed to get DIB bits from HBITMAP";
- // }
- // delete[] data;
- // DeleteDC(hdc);
- // return pixmap;
- // }
- // QPixmap SimpleWindowFinder::captureDesktop(const QSize& size)
- // {
- // // 获取主屏幕
- // QScreen* screen = QApplication::primaryScreen();
- // if (!screen) {
- // return QPixmap();
- // }
- // QPixmap pixmap = screen->grabWindow(0);
- // if (!pixmap.isNull() && !size.isEmpty()) {
- // pixmap = pixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
- // }
- // return pixmap;
- // }
- // QIcon SimpleWindowFinder::getWindowIcon(HWND hwnd)
- // {
- // // 尝试多种方式获取图标
- // HICON hIcon = nullptr;
- // // 方法1: 发送消息获取大图标
- // hIcon = reinterpret_cast<HICON>(SendMessage(hwnd, WM_GETICON, ICON_BIG, 0));
- // if (!hIcon) {
- // // 方法2: 发送消息获取小图标
- // hIcon = reinterpret_cast<HICON>(SendMessage(hwnd, WM_GETICON, ICON_SMALL, 0));
- // }
- // if (!hIcon) {
- // // 方法3: 从窗口类获取图标
- // hIcon = reinterpret_cast<HICON>(GetClassLongPtr(hwnd, GCLP_HICON));
- // }
- // if (!hIcon) {
- // // 方法4: 从窗口类获取小图标
- // hIcon = reinterpret_cast<HICON>(GetClassLongPtr(hwnd, GCLP_HICONSM));
- // }
- // if (hIcon) {
- // // Qt5兼容的HICON转换
- // QPixmap pixmap;
- // ICONINFO iconInfo;
- // if (GetIconInfo(hIcon, &iconInfo)) {
- // // 获取位图信息
- // BITMAP bmp;
- // if (GetObject(iconInfo.hbmColor, sizeof(BITMAP), &bmp)) {
- // // 创建设备上下文
- // HDC hdc = CreateCompatibleDC(NULL);
- // if (hdc) {
- // // 准备位图信息头
- // BITMAPINFOHEADER bih = {0};
- // bih.biSize = sizeof(BITMAPINFOHEADER);
- // bih.biWidth = bmp.bmWidth;
- // bih.biHeight = -bmp.bmHeight;
- // bih.biPlanes = 1;
- // bih.biBitCount = 32;
- // bih.biCompression = BI_RGB;
- // // 分配内存
- // int dataSize = bmp.bmWidth * bmp.bmHeight * 4;
- // uchar* data = new uchar[dataSize];
- // // 获取位图数据
- // BITMAPINFO bi = {0};
- // bi.bmiHeader = bih;
- // if (GetDIBits(hdc, iconInfo.hbmColor, 0, bmp.bmHeight, data, &bi, DIB_RGB_COLORS)) {
- // // 创建QImage
- // QImage image(data, bmp.bmWidth, bmp.bmHeight, QImage::Format_ARGB32);
- // pixmap = QPixmap::fromImage(image.rgbSwapped());
- // }
- // delete[] data;
- // DeleteDC(hdc);
- // }
- // }
- // // 清理资源
- // if (iconInfo.hbmColor) DeleteObject(iconInfo.hbmColor);
- // if (iconInfo.hbmMask) DeleteObject(iconInfo.hbmMask);
- // }
- // if (!pixmap.isNull()) {
- // return QIcon(pixmap);
- // }
- // }
- // // 使用默认图标
- // return QApplication::style()->standardIcon(QStyle::SP_ComputerIcon);
- // }
- // QString SimpleWindowFinder::getWindowTitle(HWND hwnd)
- // {
- // wchar_t title[256];
- // int length = GetWindowTextW(hwnd, title, 256);
- // if (length > 0) {
- // return QString::fromWCharArray(title, length);
- // }
- // return QString();
- // }
- // QString SimpleWindowFinder::getProcessName(HWND hwnd)
- // {
- // DWORD processId;
- // GetWindowThreadProcessId(hwnd, &processId);
- // HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
- // if (!hProcess) {
- // return QString();
- // }
- // wchar_t processName[MAX_PATH];
- // DWORD size = MAX_PATH;
- // if (QueryFullProcessImageNameW(hProcess, 0, processName, &size)) {
- // CloseHandle(hProcess);
- // QString fullPath = QString::fromWCharArray(processName);
- // return QFileInfo(fullPath).baseName();
- // }
- // CloseHandle(hProcess);
- // return QString();
- // }
- // bool SimpleWindowFinder::isValidWindow(HWND hwnd)
- // {
- // if (!IsWindow(hwnd) || !IsWindowVisible(hwnd)) {
- // return false;
- // }
- // // 过滤掉没有标题的窗口
- // wchar_t title[256];
- // if (GetWindowTextW(hwnd, title, 256) == 0) {
- // return false;
- // }
- // // 过滤掉工具窗口
- // LONG exStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
- // if (exStyle & WS_EX_TOOLWINDOW) {
- // return false;
- // }
- // // 检查窗口是否有父窗口(排除子窗口)
- // if (GetParent(hwnd) != NULL) {
- // return false;
- // }
- // // 更严格的顶层窗口检查:必须是应用程序主窗口
- // LONG style = GetWindowLong(hwnd, GWL_STYLE);
- // // 检查是否是顶层窗口(必须有标题栏或是弹出窗口)
- // if (!(style & WS_CAPTION) && !(style & WS_POPUP)) {
- // return false;
- // }
- // // 排除子窗口:检查WS_CHILD样式
- // if (style & WS_CHILD) {
- // return false;
- // }
- // // 检查窗口是否在Alt+Tab列表中(更严格的检查)
- // HWND owner = GetWindow(hwnd, GW_OWNER);
- // if (owner != NULL) {
- // // 如果有所有者窗口且所有者可见,则不显示
- // if (IsWindowVisible(owner)) {
- // return false;
- // }
- // // 检查所有者是否是桌面窗口
- // HWND desktop = GetDesktopWindow();
- // if (owner != desktop) {
- // return false;
- // }
- // }
- // // 确保是应用程序窗口:检查窗口是否有应用程序图标
- // HICON icon = (HICON)SendMessage(hwnd, WM_GETICON, ICON_BIG, 0);
- // if (!icon) {
- // icon = (HICON)SendMessage(hwnd, WM_GETICON, ICON_SMALL, 0);
- // }
- // if (!icon) {
- // icon = (HICON)GetClassLongPtr(hwnd, GCLP_HICON);
- // }
- // // 如果没有图标,可能不是应用程序主窗口
- // if (!icon) {
- // return false;
- // }
- // // 过滤掉一些系统窗口类名
- // wchar_t className[256];
- // if (GetClassNameW(hwnd, className, 256) > 0) {
- // std::wstring classStr(className);
- // if (classStr == L"Shell_TrayWnd" || // 任务栏
- // classStr == L"DV2ControlHost" || // 桌面窗口
- // classStr == L"MsgrIMEWindowClass" || // 输入法窗口
- // classStr == L"SysShadow" || // 阴影窗口
- // classStr.find(L"IME") != std::wstring::npos) { // 输入法相关窗口
- // return false;
- // }
- // }
- // return true;
- // }
- // // ============================================================================
- // // SimpleDesktopPreview Implementation
- // // ============================================================================
- // SimpleDesktopPreview::SimpleDesktopPreview(QWidget* parent)
- // : QLabel(parent)
- // , m_updateTimer(new QTimer(this))
- // , m_previewSize(240, 180) // 程序预览的2倍 (120x90 * 2)
- // , m_isActive(false)
- // {
- // setMinimumSize(m_previewSize);
- // setScaledContents(false); // 不拉伸内容,保持1:1比例
- // setAlignment(Qt::AlignCenter); // 居中显示
- // setStyleSheet(
- // "QLabel { "
- // " border: 2px solid #3498db; "
- // " border-radius: 5px; "
- // " background-color: #ecf0f1; "
- // "}"
- // );
- // setCursor(Qt::PointingHandCursor);
- // connect(m_updateTimer, &QTimer::timeout, this, &SimpleDesktopPreview::updateDesktop);
- // setText("点击开始桌面预览");
- // setAlignment(Qt::AlignCenter);
- // }
- // SimpleDesktopPreview::~SimpleDesktopPreview()
- // {
- // stopPreview();
- // }
- // void SimpleDesktopPreview::startPreview()
- // {
- // if (m_isActive) {
- // return;
- // }
- // qDebug() << "Starting desktop preview";
- // m_isActive = true;
- // m_updateTimer->start(1000); // 1秒更新一次
- // updateDesktop();
- // }
- // void SimpleDesktopPreview::stopPreview()
- // {
- // if (!m_isActive) {
- // return;
- // }
- // qDebug() << "Stopping desktop preview";
- // m_isActive = false;
- // m_updateTimer->stop();
- // setText("桌面预览已停止");
- // setAlignment(Qt::AlignCenter);
- // }
- // void SimpleDesktopPreview::setUpdateInterval(int ms)
- // {
- // if (m_updateTimer->isActive()) {
- // m_updateTimer->setInterval(ms);
- // }
- // }
- // void SimpleDesktopPreview::updateDesktop()
- // {
- // if (!m_isActive) {
- // return;
- // }
- // QPixmap desktop = SimpleWindowFinder::captureDesktop(m_previewSize);
- // if (!desktop.isNull()) {
- // setPixmap(desktop);
- // }
- // }
- // void SimpleDesktopPreview::mousePressEvent(QMouseEvent* event)
- // {
- // if (event->button() == Qt::LeftButton) {
- // emit clicked();
- // }
- // QLabel::mousePressEvent(event);
- // }
- // void SimpleDesktopPreview::paintEvent(QPaintEvent* event)
- // {
- // QLabel::paintEvent(event);
- // if (m_isActive) {
- // QPainter painter(this);
- // painter.setRenderHint(QPainter::Antialiasing);
- // // 绘制录制指示器
- // painter.setPen(QPen(Qt::red, 2));
- // painter.setBrush(Qt::red);
- // painter.drawEllipse(width() - 20, 10, 10, 10);
- // painter.setPen(Qt::white);
- // painter.drawText(width() - 60, 25, "LIVE");
- // }
- // }
- // // ============================================================================
- // // SimpleWindowList Implementation
- // // ============================================================================
- // SimpleWindowList::SimpleWindowList(QWidget* parent)
- // : QScrollArea(parent)
- // , m_contentWidget(new QWidget)
- // , m_layout(new QGridLayout(m_contentWidget))
- // , m_thumbnailSize(120, 90)
- // , m_showMinimized(true)
- // , m_columnsCount(6)
- // {
- // setWidget(m_contentWidget);
- // setWidgetResizable(true);
- // setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
- // setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
- // m_layout->setSpacing(5);
- // m_layout->setContentsMargins(5, 5, 5, 5);
- // setStyleSheet(
- // "QScrollArea { "
- // " background-color: #f8f9fa; "
- // " border: 1px solid #bdc3c7; "
- // " border-radius: 3px; "
- // "}"
- // "QWidget { background-color: transparent; }"
- // );
- // }
- // SimpleWindowList::~SimpleWindowList()
- // {
- // clearLayout();
- // }
- // void SimpleWindowList::setThumbnailSize(const QSize& size)
- // {
- // if (m_thumbnailSize != size) {
- // m_thumbnailSize = size;
- // refreshWindowList();
- // }
- // }
- // void SimpleWindowList::setShowMinimized(bool show)
- // {
- // if (m_showMinimized != show) {
- // m_showMinimized = show;
- // refreshWindowList();
- // }
- // }
- // QWidget* SimpleWindowList::createDesktopPreviewItem()
- // {
- // auto* widget = new QWidget;
- // widget->setFixedSize(m_thumbnailSize + QSize(10, 30));
- // widget->setCursor(Qt::PointingHandCursor);
- // auto* layout = new QVBoxLayout(widget);
- // layout->setContentsMargins(2, 2, 2, 2);
- // layout->setSpacing(2);
- // // 桌面缩略图
- // auto* thumbnailLabel = new QLabel;
- // thumbnailLabel->setFixedSize(m_thumbnailSize);
- // thumbnailLabel->setScaledContents(false);
- // thumbnailLabel->setAlignment(Qt::AlignCenter);
- // thumbnailLabel->setStyleSheet(
- // "QLabel { "
- // " border: 2px solid #3498db; "
- // " border-radius: 3px; "
- // " background-color: #ecf0f1; "
- // "}"
- // );
- // // 获取桌面缩略图
- // QPixmap desktop = SimpleWindowFinder::captureDesktop(m_thumbnailSize);
- // if (!desktop.isNull()) {
- // thumbnailLabel->setPixmap(desktop);
- // } else {
- // thumbnailLabel->setText("桌面");
- // thumbnailLabel->setAlignment(Qt::AlignCenter);
- // }
- // layout->addWidget(thumbnailLabel);
- // // 标题
- // auto* titleLabel = new QLabel("桌面预览");
- // titleLabel->setAlignment(Qt::AlignCenter);
- // titleLabel->setWordWrap(true);
- // titleLabel->setMaximumHeight(20);
- // titleLabel->setStyleSheet("font-size: 10px; color: #2c3e50; font-weight: bold;");
- // layout->addWidget(titleLabel);
- // // 标记为桌面预览项
- // widget->setProperty("isDesktop", true);
- // // 连接点击事件
- // widget->installEventFilter(this);
- // return widget;
- // }
- // void SimpleWindowList::refreshWindowList()
- // {
- // qDebug() << "Refreshing window list...";
- // auto newWindows = SimpleWindowFinder::getWindowList(m_showMinimized);
- // // 检查是否有变化
- // bool hasChanges = (newWindows.size() != m_windows.size());
- // if (!hasChanges) {
- // for (int i = 0; i < newWindows.size(); ++i) {
- // if (newWindows[i].hwnd != m_windows[i].hwnd) {
- // hasChanges = true;
- // break;
- // }
- // }
- // }
- // if (hasChanges) {
- // m_windows = newWindows;
- // updateLayout();
- // qDebug() << "Window list updated:" << m_windows.size() << "windows";
- // }
- // }
- // void SimpleWindowList::updateLayout()
- // {
- // clearLayout();
- // // 计算列数
- // int availableWidth = viewport()->width() - 20;
- // m_columnsCount = qMax(1, availableWidth / (m_thumbnailSize.width() + 10));
- // int row = 0, col = 0;
- // // 首先添加桌面预览项
- // auto* desktopItem = createDesktopPreviewItem();
- // if (desktopItem) {
- // m_layout->addWidget(desktopItem, row, col);
- // col++;
- // if (col >= m_columnsCount) {
- // col = 0;
- // row++;
- // }
- // }
- // // 然后添加窗口项
- // for (const auto& window : m_windows) {
- // auto* item = createWindowItem(window);
- // if (item) {
- // m_layout->addWidget(item, row, col);
- // col++;
- // if (col >= m_columnsCount) {
- // col = 0;
- // row++;
- // }
- // }
- // }
- // // 添加弹性空间
- // m_layout->setRowStretch(row + 1, 1);
- // m_layout->setColumnStretch(m_columnsCount, 1);
- // }
- // QWidget* SimpleWindowList::createWindowItem(const SimpleWindowInfo& info)
- // {
- // auto* widget = new QWidget;
- // widget->setFixedSize(m_thumbnailSize + QSize(10, 30));
- // widget->setCursor(Qt::PointingHandCursor);
- // auto* layout = new QVBoxLayout(widget);
- // layout->setContentsMargins(2, 2, 2, 2);
- // layout->setSpacing(2);
- // // 缩略图
- // auto* thumbnailLabel = new QLabel;
- // thumbnailLabel->setFixedSize(m_thumbnailSize);
- // thumbnailLabel->setScaledContents(false); // 不拉伸内容,保持原比例
- // thumbnailLabel->setAlignment(Qt::AlignCenter); // 居中显示
- // thumbnailLabel->setStyleSheet(
- // "QLabel { "
- // " border: 1px solid #bdc3c7; "
- // " border-radius: 3px; "
- // " background-color: #ecf0f1; "
- // "}"
- // );
- // // 获取缩略图
- // QPixmap thumbnail = SimpleWindowFinder::captureWindow(info.hwnd, m_thumbnailSize);
- // if (!thumbnail.isNull()) {
- // thumbnailLabel->setPixmap(thumbnail);
- // } else {
- // // 使用图标作为占位符
- // QPixmap iconPixmap = info.icon.pixmap(64, 64);
- // thumbnailLabel->setPixmap(iconPixmap);
- // }
- // layout->addWidget(thumbnailLabel);
- // // 标题
- // auto* titleLabel = new QLabel(info.title);
- // titleLabel->setAlignment(Qt::AlignCenter);
- // titleLabel->setWordWrap(true);
- // titleLabel->setMaximumHeight(20);
- // titleLabel->setStyleSheet("font-size: 10px; color: #2c3e50;");
- // // 截断过长的标题
- // QString displayTitle = info.title;
- // if (displayTitle.length() > 20) {
- // displayTitle = displayTitle.left(17) + "...";
- // }
- // titleLabel->setText(displayTitle);
- // titleLabel->setToolTip(info.title);
- // layout->addWidget(titleLabel);
- // // 存储窗口句柄
- // widget->setProperty("hwnd", reinterpret_cast<qintptr>(info.hwnd));
- // // 连接点击事件
- // widget->installEventFilter(this);
- // // 最小化窗口的视觉提示
- // if (info.isMinimized) {
- // widget->setStyleSheet("QWidget { opacity: 0.7; }");
- // }
- // return widget;
- // }
- // void SimpleWindowList::clearLayout()
- // {
- // while (QLayoutItem* item = m_layout->takeAt(0)) {
- // if (QWidget* widget = item->widget()) {
- // widget->deleteLater();
- // }
- // delete item;
- // }
- // }
- // void SimpleWindowList::resizeEvent(QResizeEvent* event)
- // {
- // QScrollArea::resizeEvent(event);
- // QTimer::singleShot(100, this, &SimpleWindowList::updateLayout);
- // }
- // bool SimpleWindowList::eventFilter(QObject* obj, QEvent* event)
- // {
- // if (auto* widget = qobject_cast<QWidget*>(obj)) {
- // // 检查是否是桌面预览项
- // bool isDesktop = widget->property("isDesktop").toBool();
- // if (event->type() == QEvent::MouseButtonPress) {
- // auto* mouseEvent = static_cast<QMouseEvent*>(event);
- // if (mouseEvent->button() == Qt::LeftButton) {
- // if (isDesktop) {
- // emit desktopClicked();
- // return true;
- // } else {
- // QVariant hwndVariant = widget->property("hwnd");
- // if (hwndVariant.isValid()) {
- // HWND hwnd = reinterpret_cast<HWND>(hwndVariant.value<qintptr>());
- // if (hwnd) {
- // // 查找窗口标题
- // QString title;
- // for (const auto& window : m_windows) {
- // if (window.hwnd == hwnd) {
- // title = window.title;
- // break;
- // }
- // }
- // emit windowSelected(hwnd, title);
- // return true;
- // } else {
- // qDebug() << "Invalid hwnd in click event";
- // }
- // } else {
- // qDebug() << "No hwnd property found in click event";
- // }
- // }
- // }
- // } else if (event->type() == QEvent::MouseButtonDblClick) {
- // if (!isDesktop) {
- // QVariant hwndVariant = widget->property("hwnd");
- // if (hwndVariant.isValid()) {
- // HWND hwnd = reinterpret_cast<HWND>(hwndVariant.value<qintptr>());
- // if (hwnd) {
- // emit windowDoubleClicked(hwnd);
- // return true;
- // } else {
- // qDebug() << "Invalid hwnd in double click event";
- // }
- // } else {
- // qDebug() << "No hwnd property found in double click event";
- // }
- // }
- // }
- // }
- // return QScrollArea::eventFilter(obj, event);
- // }
- // // ============================================================================
- // // SimpleWindowPreview Implementation
- // // ============================================================================
- // SimpleWindowPreview::SimpleWindowPreview(QWidget* parent)
- // : QLabel(parent)
- // , m_updateTimer(new QTimer(this))
- // , m_stateTimer(new QTimer(this))
- // , m_targetHwnd(nullptr)
- // , m_isActive(false)
- // , m_isWindowMinimized(false)
- // {
- // setMinimumSize(400, 300);
- // setScaledContents(true);
- // setStyleSheet(
- // "QLabel { "
- // " border: 2px solid #e74c3c; "
- // " border-radius: 5px; "
- // " background-color: #ecf0f1; "
- // "}"
- // );
- // connect(m_updateTimer, &QTimer::timeout, this, &SimpleWindowPreview::updatePreview);
- // connect(m_stateTimer, &QTimer::timeout, this, &SimpleWindowPreview::checkWindowState);
- // setText("请选择要预览的窗口");
- // setAlignment(Qt::AlignCenter);
- // }
- // SimpleWindowPreview::~SimpleWindowPreview()
- // {
- // stopPreview();
- // }
- // void SimpleWindowPreview::setTargetWindow(HWND hwnd, const QString& title)
- // {
- // if (m_targetHwnd == hwnd) {
- // return;
- // }
- // stopPreview();
- // m_targetHwnd = hwnd;
- // m_windowTitle = title;
- // if (hwnd && IsWindow(hwnd)) {
- // setText(QString("准备预览: %1").arg(m_windowTitle));
- // } else {
- // setText("请选择要预览的窗口");
- // }
- // setAlignment(Qt::AlignCenter);
- // }
- // void SimpleWindowPreview::startPreview()
- // {
- // if (!m_targetHwnd || !IsWindow(m_targetHwnd) || m_isActive) {
- // return;
- // }
- // qDebug() << "Starting window preview for" << m_windowTitle;
- // m_isActive = true;
- // m_isWindowMinimized = IsIconic(m_targetHwnd);
- // m_updateTimer->start(500); // 0.5秒更新一次
- // m_stateTimer->start(1000); // 每秒检查窗口状态
- // updatePreview();
- // }
- // void SimpleWindowPreview::stopPreview()
- // {
- // if (!m_isActive) {
- // return;
- // }
- // qDebug() << "Stopping window preview";
- // m_updateTimer->stop();
- // m_stateTimer->stop();
- // m_isActive = false;
- // if (!m_windowTitle.isEmpty()) {
- // setText(QString("预览已停止: %1").arg(m_windowTitle));
- // } else {
- // setText("请选择要预览的窗口");
- // }
- // setAlignment(Qt::AlignCenter);
- // }
- // void SimpleWindowPreview::setUpdateInterval(int ms)
- // {
- // if (m_updateTimer->isActive()) {
- // m_updateTimer->setInterval(ms);
- // }
- // }
- // void SimpleWindowPreview::updatePreview()
- // {
- // if (!m_isActive || !m_targetHwnd || !IsWindow(m_targetHwnd)) {
- // return;
- // }
- // QPixmap frame = SimpleWindowFinder::captureWindow(m_targetHwnd, size());
- // if (!frame.isNull()) {
- // // 如果窗口未最小化,保存最后一帧
- // if (!m_isWindowMinimized) {
- // m_lastFrame = frame;
- // }
- // setPixmap(frame);
- // } else if (m_isWindowMinimized && !m_lastFrame.isNull()) {
- // // 显示最后一帧
- // setPixmap(m_lastFrame);
- // }
- // }
- // void SimpleWindowPreview::checkWindowState()
- // {
- // if (!m_targetHwnd || !IsWindow(m_targetHwnd)) {
- // stopPreview();
- // return;
- // }
- // bool isMinimized = IsIconic(m_targetHwnd);
- // if (isMinimized != m_isWindowMinimized) {
- // m_isWindowMinimized = isMinimized;
- // if (isMinimized) {
- // qDebug() << "Window minimized:" << m_windowTitle;
- // } else {
- // qDebug() << "Window restored:" << m_windowTitle;
- // }
- // }
- // }
- // void SimpleWindowPreview::paintEvent(QPaintEvent* event)
- // {
- // QLabel::paintEvent(event);
- // if (!m_windowTitle.isEmpty()) {
- // QPainter painter(this);
- // painter.setRenderHint(QPainter::Antialiasing);
- // // 绘制窗口标题
- // painter.setPen(Qt::white);
- // painter.drawText(10, height() - 10, m_windowTitle);
- // // 绘制状态指示器
- // if (m_isActive) {
- // painter.setPen(QPen(Qt::green, 2));
- // painter.setBrush(Qt::green);
- // painter.drawEllipse(width() - 20, 10, 10, 10);
- // }
- // if (m_isWindowMinimized) {
- // painter.setPen(Qt::yellow);
- // painter.drawText(width() - 100, 25, "MINIMIZED");
- // }
- // }
- // }
- // // ============================================================================
- // // SimpleScreenWall Implementation
- // // ============================================================================
- // SimpleScreenWall::SimpleScreenWall(QWidget* parent)
- // : QWidget(parent)
- // , m_mainLayout(nullptr)
- // , m_desktopPreview(nullptr)
- // , m_windowList(nullptr)
- // , m_isRunning(false)
- // , m_selectedWindow(nullptr)
- // , m_refreshTimer(new QTimer(this))
- // {
- // setupUI();
- // setupConnections();
- // setMinimumSize(800, 600);
- // resize(1200, 900);
- // }
- // SimpleScreenWall::~SimpleScreenWall()
- // {
- // stopScreenWall();
- // }
- // void SimpleScreenWall::setupUI()
- // {
- // m_mainLayout = new QVBoxLayout(this);
- // m_mainLayout->setContentsMargins(5, 5, 5, 5);
- // m_mainLayout->setSpacing(5);
- // // 统一的预览区域,包含桌面和程序预览
- // m_windowList = new SimpleWindowList(this);
- // m_mainLayout->addWidget(m_windowList, 1);
- // // 移除单独的桌面预览和窗口预览组件
- // m_desktopPreview = nullptr;
- // }
- // void SimpleScreenWall::setupConnections()
- // {
- // connect(m_windowList, &SimpleWindowList::desktopClicked,
- // this, &SimpleScreenWall::onDesktopClicked);
- // connect(m_windowList, &SimpleWindowList::windowSelected,
- // this, &SimpleScreenWall::onWindowSelected);
- // connect(m_windowList, &SimpleWindowList::windowDoubleClicked,
- // this, &SimpleScreenWall::onWindowDoubleClicked);
- // connect(m_refreshTimer, &QTimer::timeout,
- // this, &SimpleScreenWall::refreshWindowList);
- // }
- // void SimpleScreenWall::setConfig(const SimpleScreenWallConfig& config)
- // {
- // m_config = config;
- // if (m_windowList) {
- // m_windowList->setThumbnailSize(config.thumbnailSize);
- // m_windowList->setShowMinimized(config.showMinimizedWindows);
- // }
- // // 桌面预览现在集成在窗口列表中,不需要单独设置
- // SimpleCacheManager::instance().setMaxCacheSize(config.maxCachedThumbnails);
- // }
- // void SimpleScreenWall::startScreenWall()
- // {
- // if (m_isRunning) {
- // return;
- // }
- // qDebug() << "Starting SimpleScreenWall...";
- // m_isRunning = true;
- // // 桌面预览现在集成在窗口列表中
- // // 刷新窗口列表
- // refreshWindowList();
- // // 启动定时刷新
- // m_refreshTimer->start(m_config.windowUpdateInterval);
- // emit started();
- // qDebug() << "SimpleScreenWall started successfully";
- // }
- // void SimpleScreenWall::stopScreenWall()
- // {
- // if (!m_isRunning) {
- // return;
- // }
- // qDebug() << "Stopping SimpleScreenWall...";
- // m_isRunning = false;
- // // 停止定时器
- // m_refreshTimer->stop();
- // // 窗口预览功能已集成到窗口列表中
- // // 清理缓存
- // SimpleCacheManager::instance().clearCache();
- // m_selectedWindow = nullptr;
- // emit stopped();
- // qDebug() << "SimpleScreenWall stopped";
- // }
- // void SimpleScreenWall::refreshWindowList()
- // {
- // if (m_windowList) {
- // m_windowList->refreshWindowList();
- // }
- // }
- // void SimpleScreenWall::onWindowSelected(HWND hwnd, const QString& title)
- // {
- // if (m_selectedWindow == hwnd) {
- // return;
- // }
- // m_selectedWindow = hwnd;
- // if (hwnd && IsWindow(hwnd)) {
- // emit windowSelected(hwnd, title);
- // }
- // }
- // void SimpleScreenWall::onDesktopClicked()
- // {
- // // 取消窗口选择
- // if (m_selectedWindow) {
- // m_selectedWindow = nullptr;
- // }
- // emit desktopSelected();
- // }
- // void SimpleScreenWall::onWindowDoubleClicked(HWND hwnd)
- // {
- // // 检查窗口句柄是否有效
- // if (!hwnd || !IsWindow(hwnd)) {
- // qDebug() << "Invalid window handle in double click event";
- // return;
- // }
- // // 激活窗口
- // if (!SimpleScreenWallUtils::activateWindow(hwnd)) {
- // qDebug() << "Failed to activate window:" << hwnd;
- // }
- // }
- // void SimpleScreenWall::showEvent(QShowEvent* event)
- // {
- // QWidget::showEvent(event);
- // if (!m_isRunning) {
- // QTimer::singleShot(500, this, &SimpleScreenWall::startScreenWall);
- // }
- // }
- // void SimpleScreenWall::hideEvent(QHideEvent* event)
- // {
- // QWidget::hideEvent(event);
- // if (m_isRunning) {
- // stopScreenWall();
- // }
- // }
- // void SimpleScreenWall::resizeEvent(QResizeEvent* event)
- // {
- // QWidget::resizeEvent(event);
- // if (m_windowList) {
- // QTimer::singleShot(100, m_windowList, &SimpleWindowList::refreshWindowList);
- // }
- // }
- // void SimpleScreenWall::updateLayout()
- // {
- // // 根据窗口大小调整布局比例
- // int totalHeight = height();
- // int desktopHeight = totalHeight * 0.3;
- // int listHeight = totalHeight * 0.2;
- // int previewHeight = totalHeight * 0.5;
- // // 现在只有窗口列表,不需要复杂的布局分配
- // // m_windowList 会自动调整大小
- // }
- // // ============================================================================
- // // SimpleCacheManager Implementation
- // // ============================================================================
- // SimpleCacheManager& SimpleCacheManager::instance()
- // {
- // static SimpleCacheManager instance;
- // return instance;
- // }
- // void SimpleCacheManager::cacheThumbnail(HWND hwnd, const QPixmap& thumbnail)
- // {
- // m_thumbnailCache.insert(hwnd, new QPixmap(thumbnail));
- // }
- // QPixmap SimpleCacheManager::getCachedThumbnail(HWND hwnd) const
- // {
- // QPixmap* cached = m_thumbnailCache.object(hwnd);
- // return cached ? *cached : QPixmap();
- // }
- // void SimpleCacheManager::cacheIcon(HWND hwnd, const QIcon& icon)
- // {
- // m_iconCache.insert(hwnd, new QIcon(icon));
- // }
- // QIcon SimpleCacheManager::getCachedIcon(HWND hwnd) const
- // {
- // QIcon* cached = m_iconCache.object(hwnd);
- // return cached ? *cached : QIcon();
- // }
- // void SimpleCacheManager::clearCache()
- // {
- // m_thumbnailCache.clear();
- // m_iconCache.clear();
- // }
- // void SimpleCacheManager::setMaxCacheSize(int size)
- // {
- // m_thumbnailCache.setMaxCost(size);
- // m_iconCache.setMaxCost(size);
- // }
- // // ============================================================================
- // // SimpleScreenWallUtils Implementation
- // // ============================================================================
- // QPixmap SimpleScreenWallUtils::scalePixmap(const QPixmap& pixmap, const QSize& size, Qt::AspectRatioMode mode)
- // {
- // if (pixmap.isNull() || size.isEmpty()) {
- // return pixmap;
- // }
- // return pixmap.scaled(size, mode, Qt::SmoothTransformation);
- // }
- // QPixmap SimpleScreenWallUtils::addBorder(const QPixmap& pixmap, int borderWidth, const QColor& color)
- // {
- // if (pixmap.isNull() || borderWidth <= 0) {
- // return pixmap;
- // }
- // QPixmap result(pixmap.size() + QSize(borderWidth * 2, borderWidth * 2));
- // result.fill(color);
- // QPainter painter(&result);
- // painter.drawPixmap(borderWidth, borderWidth, pixmap);
- // return result;
- // }
- // QPixmap SimpleScreenWallUtils::addShadow(const QPixmap& pixmap, int shadowSize, const QColor& color)
- // {
- // if (pixmap.isNull() || shadowSize <= 0) {
- // return pixmap;
- // }
- // QPixmap result(pixmap.size() + QSize(shadowSize * 2, shadowSize * 2));
- // result.fill(Qt::transparent);
- // QPainter painter(&result);
- // painter.setRenderHint(QPainter::Antialiasing);
- // // 绘制阴影
- // painter.setBrush(color);
- // painter.setPen(Qt::NoPen);
- // painter.drawRoundedRect(shadowSize, shadowSize, pixmap.width(), pixmap.height(), 5, 5);
- // // 绘制原图
- // painter.drawPixmap(0, 0, pixmap);
- // return result;
- // }
- // QString SimpleScreenWallUtils::getSystemInfo()
- // {
- // QString info;
- // info += QString("OS: Windows\n");
- // info += QString("Qt Version: %1\n").arg(QT_VERSION_STR);
- // info += QString("Screen Count: %1\n").arg(QApplication::screens().count());
- // return info;
- // }
- // QStringList SimpleScreenWallUtils::getRunningProcesses()
- // {
- // QStringList processes;
- // DWORD processIds[1024], bytesReturned;
- // if (EnumProcesses(processIds, sizeof(processIds), &bytesReturned)) {
- // DWORD processCount = bytesReturned / sizeof(DWORD);
- // for (DWORD i = 0; i < processCount; i++) {
- // HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processIds[i]);
- // if (hProcess) {
- // wchar_t processName[MAX_PATH];
- // DWORD size = MAX_PATH;
- // if (QueryFullProcessImageNameW(hProcess, 0, processName, &size)) {
- // QString fullPath = QString::fromWCharArray(processName);
- // processes.append(QFileInfo(fullPath).baseName());
- // }
- // CloseHandle(hProcess);
- // }
- // }
- // }
- // return processes;
- // }
- // int SimpleScreenWallUtils::getSystemMemoryUsage()
- // {
- // MEMORYSTATUSEX memInfo;
- // memInfo.dwLength = sizeof(MEMORYSTATUSEX);
- // GlobalMemoryStatusEx(&memInfo);
- // return static_cast<int>(memInfo.dwMemoryLoad);
- // }
- // int SimpleScreenWallUtils::getCpuUsage()
- // {
- // // 简化实现,返回固定值
- // // 实际实现需要使用性能计数器
- // return 0;
- // }
- // void SimpleScreenWallUtils::saveConfig(const SimpleScreenWallConfig& config, const QString& filePath)
- // {
- // QString path = filePath;
- // if (path.isEmpty()) {
- // path = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/screenwall_config.json";
- // }
- // QJsonObject json;
- // json["desktopUpdateInterval"] = config.desktopUpdateInterval;
- // json["windowUpdateInterval"] = config.windowUpdateInterval;
- // json["previewUpdateInterval"] = config.previewUpdateInterval;
- // json["thumbnailWidth"] = config.thumbnailSize.width();
- // json["thumbnailHeight"] = config.thumbnailSize.height();
- // json["desktopPreviewWidth"] = config.desktopPreviewSize.width();
- // json["desktopPreviewHeight"] = config.desktopPreviewSize.height();
- // json["maxCachedThumbnails"] = config.maxCachedThumbnails;
- // json["enableDesktopPreview"] = config.enableDesktopPreview;
- // json["enableWindowPreview"] = config.enableWindowPreview;
- // json["showMinimizedWindows"] = config.showMinimizedWindows;
- // QJsonDocument doc(json);
- // QDir().mkpath(QFileInfo(path).absolutePath());
- // QFile file(path);
- // if (file.open(QIODevice::WriteOnly)) {
- // file.write(doc.toJson());
- // }
- // }
- // SimpleScreenWallConfig SimpleScreenWallUtils::loadConfig(const QString& filePath)
- // {
- // QString path = filePath;
- // if (path.isEmpty()) {
- // path = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/screenwall_config.json";
- // }
- // SimpleScreenWallConfig config; // 使用默认值
- // QFile file(path);
- // if (file.open(QIODevice::ReadOnly)) {
- // QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
- // QJsonObject json = doc.object();
- // if (json.contains("desktopUpdateInterval")) {
- // config.desktopUpdateInterval = json["desktopUpdateInterval"].toInt();
- // }
- // if (json.contains("windowUpdateInterval")) {
- // config.windowUpdateInterval = json["windowUpdateInterval"].toInt();
- // }
- // if (json.contains("previewUpdateInterval")) {
- // config.previewUpdateInterval = json["previewUpdateInterval"].toInt();
- // }
- // if (json.contains("thumbnailWidth") && json.contains("thumbnailHeight")) {
- // config.thumbnailSize = QSize(json["thumbnailWidth"].toInt(), json["thumbnailHeight"].toInt());
- // }
- // if (json.contains("desktopPreviewWidth") && json.contains("desktopPreviewHeight")) {
- // config.desktopPreviewSize = QSize(json["desktopPreviewWidth"].toInt(), json["desktopPreviewHeight"].toInt());
- // }
- // if (json.contains("maxCachedThumbnails")) {
- // config.maxCachedThumbnails = json["maxCachedThumbnails"].toInt();
- // }
- // if (json.contains("enableDesktopPreview")) {
- // config.enableDesktopPreview = json["enableDesktopPreview"].toBool();
- // }
- // if (json.contains("enableWindowPreview")) {
- // config.enableWindowPreview = json["enableWindowPreview"].toBool();
- // }
- // if (json.contains("showMinimizedWindows")) {
- // config.showMinimizedWindows = json["showMinimizedWindows"].toBool();
- // }
- // }
- // return config;
- // }
- // // ============================================================================
- // // SimpleScreenWallWindow Implementation
- // // ============================================================================
- // SimpleScreenWallWindow::SimpleScreenWallWindow(QWidget* parent)
- // : QWidget(parent)
- // , m_mainLayout(nullptr)
- // , m_controlPanel(nullptr)
- // , m_controlLayout(nullptr)
- // , m_startButton(nullptr)
- // , m_stopButton(nullptr)
- // , m_refreshButton(nullptr)
- // , m_settingsButton(nullptr)
- // , m_statusLabel(nullptr)
- // , m_screenWall(nullptr)
- // {
- // setupUI();
- // setupConnections();
- // setWindowTitle("简化版屏幕墙");
- // setMinimumSize(1000, 700);
- // resize(1200, 900);
- // }
- // SimpleScreenWallWindow::~SimpleScreenWallWindow()
- // {
- // if (m_screenWall && m_screenWall->isRunning()) {
- // m_screenWall->stopScreenWall();
- // }
- // }
- // void SimpleScreenWallWindow::setupUI()
- // {
- // m_mainLayout = new QVBoxLayout(this);
- // m_mainLayout->setContentsMargins(5, 5, 5, 5);
- // m_mainLayout->setSpacing(5);
- // // 控制面板
- // m_controlPanel = new QWidget(this);
- // m_controlLayout = new QHBoxLayout(m_controlPanel);
- // m_controlLayout->setContentsMargins(0, 0, 0, 0);
- // m_startButton = new QPushButton("启动屏幕墙", this);
- // m_stopButton = new QPushButton("停止屏幕墙", this);
- // m_refreshButton = new QPushButton("刷新窗口", this);
- // m_settingsButton = new QPushButton("设置", this);
- // m_statusLabel = new QLabel("状态: 已停止", this);
- // m_controlLayout->addWidget(m_startButton);
- // m_controlLayout->addWidget(m_stopButton);
- // m_controlLayout->addWidget(m_refreshButton);
- // m_controlLayout->addWidget(m_settingsButton);
- // m_controlLayout->addStretch();
- // m_controlLayout->addWidget(m_statusLabel);
- // m_mainLayout->addWidget(m_controlPanel);
- // // 屏幕墙组件
- // m_screenWall = new SimpleScreenWall(this);
- // m_mainLayout->addWidget(m_screenWall, 1);
- // updateControlButtons();
- // }
- // void SimpleScreenWallWindow::setupConnections()
- // {
- // connect(m_startButton, &QPushButton::clicked, this, &SimpleScreenWallWindow::startScreenWall);
- // connect(m_stopButton, &QPushButton::clicked, this, &SimpleScreenWallWindow::stopScreenWall);
- // connect(m_refreshButton, &QPushButton::clicked, this, &SimpleScreenWallWindow::refreshWindows);
- // connect(m_settingsButton, &QPushButton::clicked, this, &SimpleScreenWallWindow::showSettings);
- // if (m_screenWall) {
- // connect(m_screenWall, &SimpleScreenWall::windowSelected, this, &SimpleScreenWallWindow::onWindowSelected);
- // connect(m_screenWall, &SimpleScreenWall::desktopSelected, this, &SimpleScreenWallWindow::onDesktopSelected);
- // connect(m_screenWall, &SimpleScreenWall::started, this, &SimpleScreenWallWindow::onScreenWallStarted);
- // connect(m_screenWall, &SimpleScreenWall::stopped, this, &SimpleScreenWallWindow::onScreenWallStopped);
- // }
- // }
- // void SimpleScreenWallWindow::updateControlButtons()
- // {
- // bool isRunning = m_screenWall && m_screenWall->isRunning();
- // m_startButton->setEnabled(!isRunning);
- // m_stopButton->setEnabled(isRunning);
- // m_refreshButton->setEnabled(isRunning);
- // m_statusLabel->setText(isRunning ? "状态: 运行中" : "状态: 已停止");
- // }
- // void SimpleScreenWallWindow::closeEvent(QCloseEvent* event)
- // {
- // if (m_screenWall && m_screenWall->isRunning()) {
- // m_screenWall->stopScreenWall();
- // }
- // QWidget::closeEvent(event);
- // }
- // void SimpleScreenWallWindow::startScreenWall()
- // {
- // if (m_screenWall) {
- // m_screenWall->startScreenWall();
- // }
- // }
- // void SimpleScreenWallWindow::stopScreenWall()
- // {
- // if (m_screenWall) {
- // m_screenWall->stopScreenWall();
- // }
- // }
- // void SimpleScreenWallWindow::refreshWindows()
- // {
- // if (m_screenWall) {
- // m_screenWall->refreshWindowList();
- // }
- // }
- // void SimpleScreenWallWindow::showSettings()
- // {
- // QMessageBox::information(this, "设置", "设置功能尚未实现");
- // }
- // void SimpleScreenWallWindow::showAbout()
- // {
- // QMessageBox::about(this, "关于", "简化版屏幕墙\n版本: 1.0\n\n实时窗口预览系统");
- // }
- // void SimpleScreenWallWindow::onWindowSelected(HWND hwnd, const QString& title)
- // {
- // Q_UNUSED(hwnd)
- // m_statusLabel->setText(QString("已选择窗口: %1").arg(title));
- // }
- // void SimpleScreenWallWindow::onDesktopSelected()
- // {
- // m_statusLabel->setText("已选择桌面预览");
- // }
- // void SimpleScreenWallWindow::onScreenWallStarted()
- // {
- // updateControlButtons();
- // m_statusLabel->setText("状态: 运行中");
- // }
- // void SimpleScreenWallWindow::onScreenWallStopped()
- // {
- // updateControlButtons();
- // m_statusLabel->setText("状态: 已停止");
- // }
|