diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 57edd07..180acf1 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -23,6 +23,7 @@ set(MOBILE_COMMON_SOURCES generatetools.h generatetools.cpp highlight-effect.h + publicattributes.hpp serverstatus.h serverstatus.cpp util.h diff --git a/ui/publicattributes.hpp b/common/publicattributes.hpp similarity index 100% rename from ui/publicattributes.hpp rename to common/publicattributes.hpp diff --git a/pcscreenmanage/CMakeLists.txt b/pcscreenmanage/CMakeLists.txt index b9c3091..72c7074 100644 --- a/pcscreenmanage/CMakeLists.txt +++ b/pcscreenmanage/CMakeLists.txt @@ -2,8 +2,6 @@ set(MOBILE_CURTAIN_SOURCES curtain/curtain.h curtain/curtain.cpp - curtain/fullscreenwindow.h - curtain/fullscreenwindow.cpp ) source_group(curtain FILES ${MOBILE_CURTAIN_SOURCES}) @@ -25,11 +23,19 @@ set(MOBILE_SOURCES ${CONTROL_SOURCES} pcscreenmanage.h pcscreenmanage.cpp + suspendtabbar.cpp + suspendtabbar.h screenmanagemsg.pb.h screenmanagemsg.pb.cc ) add_library(pcscreenmanage ${MOBILE_SOURCES}) +find_package(PkgConfig REQUIRED) +pkg_check_modules(KYSDK_QTWIDGETS kysdk-qtwidgets) +target_include_directories(pcscreenmanage PUBLIC ${KYSDK_QTWIDGETS_INCLUDE_DIRS}) +target_link_directories(pcscreenmanage PUBLIC ${KYSDK_QTWIDGETS_LIBRARY_DIRS}) +target_link_libraries(pcscreenmanage PUBLIC ${KYSDK_QTWIDGETS_LIBRARIES}) + target_include_directories(pcscreenmanage PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/curtain) target_include_directories(pcscreenmanage PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/pcscreen) target_include_directories(pcscreenmanage PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/control) @@ -40,6 +46,7 @@ find_package(Qt5WebEngineWidgets COMPONENTS WebEngineWidgets REQUIRED) target_link_libraries(pcscreenmanage PUBLIC Qt${QT_VERSION_MAJOR}::Widgets ${Qt5WebEngineWidgets_LIBRARIES} + mobile_common ) diff --git a/pcscreenmanage/curtain/curtain.cpp b/pcscreenmanage/curtain/curtain.cpp index 67d3d87..8805073 100644 --- a/pcscreenmanage/curtain/curtain.cpp +++ b/pcscreenmanage/curtain/curtain.cpp @@ -53,14 +53,18 @@ #include #include #include +#include #include #include #include #include #include +#include +#include #include #include #include +#include Curtain::Curtain(QWidget *parent) : QWidget(parent), m_view(new QWebEngineView(this)) { @@ -70,6 +74,7 @@ Curtain::Curtain(QWidget *parent) : QWidget(parent), m_view(new QWebEngineView(t layout->setMargin(0); layout->setSpacing(0); setLayout(layout); + m_view->settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true); m_view->setContextMenuPolicy(Qt::NoContextMenu); connect(m_view->page(), &QWebEnginePage::fullScreenRequested, this, &Curtain::fullScreenRequested); @@ -79,27 +84,81 @@ Curtain::Curtain(QWidget *parent) : QWidget(parent), m_view(new QWebEngineView(t system(common.toUtf8().constData()); qApp->setOverrideCursor(QCursor(Qt::ArrowCursor)); }); + + m_suspendTabBar = new SuspendTabBar(SuspendTabBar::Display::Whole, false, this); + connect(m_suspendTabBar, &SuspendTabBar::sigBtnClicked, this, &Curtain::slotTabBtnClicked); + m_view->stackUnder(m_suspendTabBar); + + auto exitAction = new QAction(this); + exitAction->setShortcut(Qt::Key_Escape); + addAction(exitAction); + connect(exitAction, &QAction::triggered, [this]() { + Q_EMIT sigStateChange(Curtain::States::ReturnDesktop); + hideView(); + }); } -Curtain::~Curtain() {} +Curtain::~Curtain() +{ + if (m_suspendTabBar1 != nullptr) { + delete m_suspendTabBar1; + } +} + +void Curtain::setTheme(PublicAttributes::Theme theme) +{ + m_theme = theme; + if (m_suspendTabBar) { + m_suspendTabBar->setTheme(m_theme); + } + if (m_suspendTabBar1 != nullptr) { + m_suspendTabBar1->setTheme(m_theme); + } +} void Curtain::showView() { - if (m_fullScreenWindow && m_fullScreenWindow->isHidden()) { - m_fullScreenWindow->show(); - m_fullScreenWindow->showFullScreen(); - m_fullScreenWindow->activateWindow(); - m_fullScreenWindow->setFocus(); + if (m_suspendTabBar1 != nullptr) { + m_suspendTabBar1->hideTabBar(); } show(); + showMaximized(); + showFullScreen(); } void Curtain::hideView() { - if (m_fullScreenWindow && !m_fullScreenWindow->isHidden()) { - m_fullScreenWindow->hide(); - } hide(); + if (m_suspendTabBar1 == nullptr) { + m_suspendTabBar1 = new SuspendTabBar(SuspendTabBar::Display::Whole, true); + connect(m_suspendTabBar1, &SuspendTabBar::sigBtnClicked, this, &Curtain::slotTabBtnClicked); + } + m_suspendTabBar1->setTheme(m_theme); + m_suspendTabBar1->setDeskBtnState(true); + m_suspendTabBar1->showTabBar(); +} + +void Curtain::hideTabBar() +{ + if (m_suspendTabBar != nullptr) { + m_suspendTabBar->hideTabBar(); + } +} + +void Curtain::showTabBar() +{ + if (m_suspendTabBar != nullptr) { + m_suspendTabBar->showTabBar(); + } +} + +void Curtain::resizeEvent(QResizeEvent *event) +{ + QRect viewGeometry(QPoint(0, 0), size()); + m_view->setGeometry(viewGeometry); + m_suspendTabBar->showTabBar(); + + QWidget::resizeEvent(event); } void Curtain::loadUrl(QString &url) @@ -107,24 +166,39 @@ void Curtain::loadUrl(QString &url) qInfo() << "Sending request to projection service."; m_url = url; m_view->setUrl(QUrl(m_url)); + showMaximized(); + showFullScreen(); } void Curtain::fullScreenRequested(QWebEngineFullScreenRequest request) { - if (request.toggleOn()) { - if (m_fullScreenWindow) - return; - request.accept(); - FullScreenWindow *fullScreenWindow = new FullScreenWindow(m_view); - connect(fullScreenWindow, &FullScreenWindow::sigHideView, this, [=]() { - hideView(); - Q_EMIT sigHideView(); - }); - m_fullScreenWindow.reset(fullScreenWindow); - } else { - if (!m_fullScreenWindow) - return; - request.accept(); - m_fullScreenWindow.reset(); + request.accept(); + showMaximized(); + showFullScreen(); +} + +void Curtain::slotTabBtnClicked(SuspendTabBar::BtnType type) +{ + switch (type) { + case SuspendTabBar::BtnType::ControlBtn: { + // 暂时先模拟键盘进入反控 + showView(); + hideTabBar(); + QString common = "xdotool key ctrl+h"; + system(common.toUtf8().constData()); + Q_EMIT sigStateChange(Curtain::States::Control); + } break; + case SuspendTabBar::BtnType::ReturnDesktopBtn: { + hideView(); + Q_EMIT sigStateChange(Curtain::States::ReturnDesktop); + } break; + case SuspendTabBar::BtnType::ScreenShareBtn: { + showView(); + Q_EMIT sigStateChange(Curtain::States::ScreenShare); + } break; + case SuspendTabBar::BtnType::ExitBtn: { + hideView(); + Q_EMIT sigStateChange(Curtain::States::Exit); + } break; } } \ No newline at end of file diff --git a/pcscreenmanage/curtain/curtain.h b/pcscreenmanage/curtain/curtain.h index 0e662ad..14c1c15 100644 --- a/pcscreenmanage/curtain/curtain.h +++ b/pcscreenmanage/curtain/curtain.h @@ -51,12 +51,14 @@ #ifndef CURTAIN_H #define CURTAIN_H -#include "fullscreenwindow.h" - #include #include #include +#include +#include #include +#include "suspendtabbar.h" +#include "publicattributes.hpp" class Curtain : public QWidget { @@ -64,22 +66,39 @@ class Curtain : public QWidget public: explicit Curtain(QWidget *parent = nullptr); ~Curtain(); + enum States { + Control = 0, // 反控 + ControlClose, // 取消反控 + ReturnDesktop, // 返回桌面 + ScreenShare, // 投屏 + Exit, // 退出 + }; + Q_ENUM(States) + void setTheme(PublicAttributes::Theme theme); void showView(); void hideView(); + void hideTabBar(); + void showTabBar(); + +protected: + void resizeEvent(QResizeEvent *event) override; public: void loadUrl(QString &url); Q_SIGNALS: - void sigHideView(); + void sigStateChange(Curtain::States); private Q_SLOTS: void fullScreenRequested(QWebEngineFullScreenRequest request); + void slotTabBtnClicked(SuspendTabBar::BtnType type); private: QWebEngineView *m_view; - QScopedPointer m_fullScreenWindow; QString m_url = ""; + PublicAttributes::Theme m_theme = PublicAttributes::Theme::Light; // 主题 + SuspendTabBar *m_suspendTabBar = nullptr; + SuspendTabBar *m_suspendTabBar1 = nullptr; }; #endif // CURTAIN_H diff --git a/pcscreenmanage/curtain/curtain.pri b/pcscreenmanage/curtain/curtain.pri deleted file mode 100644 index bd57c84..0000000 --- a/pcscreenmanage/curtain/curtain.pri +++ /dev/null @@ -1,12 +0,0 @@ -QT += webenginewidgets - -HEADERS += $$PWD/curtain.h \ - $$PWD/fullscreenwindow.h \ - $$PWD/fullscreennotification.h - -SOURCES += $$PWD/curtain.cpp \ - $$PWD/fullscreenwindow.cpp \ - $$PWD/fullscreennotification.cpp - - - diff --git a/pcscreenmanage/curtain/fullscreenwindow.cpp b/pcscreenmanage/curtain/fullscreenwindow.cpp deleted file mode 100644 index 0af12a1..0000000 --- a/pcscreenmanage/curtain/fullscreenwindow.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "fullscreenwindow.h" - -#include -#include -#include -#include -#include - -FullScreenWindow::FullScreenWindow(QWebEngineView *oldView, QWidget *parent) - : QWidget(parent), m_view(new QWebEngineView(this)), m_oldView(oldView), - m_oldGeometry(oldView->window()->geometry()) -{ - setWindowFlags(Qt::FramelessWindowHint); //无边框 - m_view->setContextMenuPolicy(Qt::NoContextMenu); - - // this->setWindowState(Qt::WindowFullScreen); - // QRect rect = qApp->desktop()->geometry(); - // rect.setY(-1); - // rect.setHeight(rect.height()); - // this->setGeometry(rect); - - auto exitAction = new QAction(this); - exitAction->setShortcut(Qt::Key_Escape); - connect(exitAction, &QAction::triggered, [this]() { - // m_view->triggerPageAction(QWebEnginePage::ExitFullScreen); - Q_EMIT sigHideView(); - }); - // auto ctrlhAction = new QAction(this); - // ctrlhAction->setShortcut(QKeySequence(QLatin1String("Ctrl+H"))); - // connect(ctrlhAction, &QAction::triggered, [this]() { - // //qInfo() << "HHHHHHHHHHHHHHHH"; - // Q_EMIT sigControlState(true); - // }); - // auto ctrlgAction = new QAction(this); - // ctrlgAction->setShortcut(QKeySequence(QLatin1String("Ctrl+G"))); - // connect(ctrlgAction, &QAction::triggered, [this]() { - // //qInfo() << "GGGGGGGGGGGGGGGGGGGGG"; - // Q_EMIT sigControlState(false); - // }); - addAction(exitAction); - // addAction(ctrlhAction); - // addAction(ctrlgAction); - - m_view->setPage(m_oldView->page()); - setGeometry(m_oldGeometry); - showFullScreen(); - m_oldView->window()->hide(); -} - -FullScreenWindow::~FullScreenWindow() -{ - m_oldView->setPage(m_view->page()); - m_oldView->window()->setGeometry(m_oldGeometry); - m_oldView->window()->show(); - hide(); -} - -void FullScreenWindow::resizeEvent(QResizeEvent *event) -{ - QWindowsWindowFunctions::setHasBorderInFullScreen(this->windowHandle(), true); - QRect viewGeometry(QPoint(0, 0), size()); - m_view->setGeometry(viewGeometry); - - QWidget::resizeEvent(event); -} - -// void FullScreenWindow::showEvent(QShowEvent *event) -// { -// QWindowsWindowFunctions::setHasBorderInFullScreen(this->windowHandle(), true); -// // qInfo() << "111111111111111111111111111111111"; -// } diff --git a/pcscreenmanage/curtain/fullscreenwindow.h b/pcscreenmanage/curtain/fullscreenwindow.h deleted file mode 100644 index 6c961f9..0000000 --- a/pcscreenmanage/curtain/fullscreenwindow.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef FULLSCREENWINDOW_H -#define FULLSCREENWINDOW_H - -#include -#include -#include -#include - - -QT_BEGIN_NAMESPACE -class QWebEngineView; -QT_END_NAMESPACE - -class FullScreenWindow : public QWidget -{ - Q_OBJECT -public: - explicit FullScreenWindow(QWebEngineView *oldView, QWidget *parent = nullptr); - ~FullScreenWindow(); - -protected: - void resizeEvent(QResizeEvent *event) override; - // void showEvent(QShowEvent *event) override; -Q_SIGNALS: - // void sigControlState(bool); - void sigHideView(); - -private: - QWebEngineView *m_view; - QWebEngineView *m_oldView; - QRect m_oldGeometry; -}; - -#endif // FULLSCREENWINDOW_H diff --git a/pcscreenmanage/pcscreen/pcscreen.cpp b/pcscreenmanage/pcscreen/pcscreen.cpp index 58457e6..3a758ad 100644 --- a/pcscreenmanage/pcscreen/pcscreen.cpp +++ b/pcscreenmanage/pcscreen/pcscreen.cpp @@ -32,12 +32,12 @@ void PCScreen::startService() QThread::msleep(8000); Q_EMIT sigStartedScreen(m_roomid); }); - // connect(m_process, &QProcess::errorOccurred, [&](QProcess::ProcessError error) { - // if (!isNormalExit) { - // qInfo() << "Screen projection service error:" << error; - // Q_EMIT sigStartError(); - // } - // }); + connect(m_process, &QProcess::errorOccurred, [&](QProcess::ProcessError error) { + if (!isNormalExit) { + qInfo() << "Screen projection service error:" << error; + Q_EMIT sigStartError(); + } + }); getRoomId(); m_process->start(COMMON, QStringList() << m_roomid); } else { diff --git a/pcscreenmanage/pcscreenmanage.cpp b/pcscreenmanage/pcscreenmanage.cpp index 9397604..e36a4d9 100644 --- a/pcscreenmanage/pcscreenmanage.cpp +++ b/pcscreenmanage/pcscreenmanage.cpp @@ -4,6 +4,10 @@ #include #include +// #define KYLIN_CONNECTIVITY_TOOLS_PATH "/" +// #define KYLIN_CONNECTIVITY_TOOLS_SERVICE "com.kylinos.connectivity.tools" +// #define KYLIN_CONNECTIVITY_TOOLS_INTERFACE "com.kylinos.connectivity.tools" + const int LISTEN_PORT = 27192; QString LOAD_URL = "http://%1:27190/%2"; @@ -30,6 +34,17 @@ PcScreenManage::~PcScreenManage() } } +void PcScreenManage::setTheme(PublicAttributes::Theme theme) +{ + m_theme = theme; + if (m_curtain != nullptr) { + m_curtain->setTheme(m_theme); + } + if (m_suspendTabBar != nullptr) { + m_suspendTabBar->setTheme(m_theme); + } +} + void PcScreenManage::disconnected() { m_isService = true; @@ -104,21 +119,24 @@ void PcScreenManage::startPcService() void PcScreenManage::startCurtain(QString roomid) { + // 服务端 + // m_dbusInterface = new QDBusInterface(KYLIN_CONNECTIVITY_TOOLS_SERVICE, KYLIN_CONNECTIVITY_TOOLS_PATH, + // KYLIN_CONNECTIVITY_TOOLS_INTERFACE, QDBusConnection::sessionBus()); + // QObject::connect(m_dbusInterface, SIGNAL(enterClient(bool)), this, SLOT(slotEnterControl(bool))); + if (m_curtain == nullptr) { m_curtain = new Curtain; - connect(m_curtain, &Curtain::sigHideView, this, [=]() { - Q_EMIT sigRequestReceived(ScreenMsg::HideView); - }); - QRect geometry = QGuiApplication::primaryScreen()->availableGeometry(); - m_curtain->setGeometry(geometry); - m_curtain->showMaximized(); + connect(m_curtain, &Curtain::sigStateChange, this, &PcScreenManage::slotStateChange); } QString targetUrl; if (!roomid.isEmpty()) { targetUrl = LOAD_URL.arg(m_address).arg(roomid); qInfo() << "targetUrl = " << targetUrl; } + m_curtain->showFullScreen(); + m_curtain->showMaximized(); m_curtain->loadUrl(targetUrl); + m_curtain->setTheme(m_theme); } void PcScreenManage::startControl() @@ -151,20 +169,6 @@ void PcScreenManage::startControl() } } -void PcScreenManage::showCurtain() -{ - if (m_curtain != nullptr) { - m_curtain->showView(); - } -} - -void PcScreenManage::hideCurtain() -{ - if (m_curtain != nullptr) { - m_curtain->hideView(); - } -} - void PcScreenManage::startedControl() { ScreenManageMsg message; @@ -179,6 +183,13 @@ void PcScreenManage::exitControl() sendMessage(message); } +void PcScreenManage::showView() +{ + if (m_curtain != nullptr) { + m_curtain->showView(); + } +} + void PcScreenManage::closePcScreenService() { qInfo() << "Closing the projection service..."; @@ -200,6 +211,11 @@ void PcScreenManage::closePcScreenService() void PcScreenManage::closeCurtain() { qInfo() << "Closing curtain..."; + if (m_suspendTabBar != nullptr) { + m_suspendTabBar->hideTabBar(); + delete m_suspendTabBar; + m_suspendTabBar = nullptr; + } if (m_curtain != nullptr) { ScreenManageMsg message; message.set_msg(ScreenManageMsg::CURTAINEXIT); @@ -292,11 +308,24 @@ void PcScreenManage::onMessageReadyRead() } break; case ScreenManageMsg::STARTEDCONTROL: { qInfo() << "Enter anti control."; - Q_EMIT sigRequestReceived(ScreenMsg::StartedControl); + m_suspendTabBar = new SuspendTabBar(SuspendTabBar::Display::Part, true); + connect(m_suspendTabBar, &SuspendTabBar::sigBtnClicked, this, &PcScreenManage::slotTabBtnClicked); + m_suspendTabBar->setTheme(m_theme); + m_suspendTabBar->showTabBar(); } break; case ScreenManageMsg::EXITCONTROL: { qInfo() << "Exit anti control."; - Q_EMIT sigRequestReceived(ScreenMsg::ExitControl); + if (m_isService) { + QString common = "xdotool key ctrl+g"; + system(common.toUtf8().constData()); + m_curtain->showTabBar(); + } else { + if (m_suspendTabBar != nullptr) { + m_suspendTabBar->hideTabBar(); + delete m_suspendTabBar; + m_suspendTabBar = nullptr; + } + } } break; } } @@ -341,6 +370,62 @@ void PcScreenManage::slotSocketDisconnect() // Q_EMIT sigRequestReceived(ScreenMsg::Disconnect); } +void PcScreenManage::slotStateChange(Curtain::States state) +{ + switch (state) { + case Curtain::States::Control: { + // 进入反控 + m_curtain->hideTabBar(); + startedControl(); + } break; + case Curtain::States::ReturnDesktop: { + Q_EMIT sigRequestReceived(ScreenMsg::HideView); + } break; + case Curtain::States::ScreenShare: { + Q_EMIT sigRequestReceived(ScreenMsg::ShowView); + } break; + case Curtain::States::Exit: { + disconnected(); + Q_EMIT sigRequestReceived(ScreenMsg::HideView); + } break; + } +} + +void PcScreenManage::slotTabBtnClicked(SuspendTabBar::BtnType type) +{ + switch (type) { + case SuspendTabBar::BtnType::ControlBtn: { + // 退出反控 + exitControl(); + if (m_suspendTabBar != nullptr) { + m_suspendTabBar->hideTabBar(); + delete m_suspendTabBar; + m_suspendTabBar = nullptr; + } + } break; + case SuspendTabBar::BtnType::ExitBtn: { + if (m_suspendTabBar != nullptr) { + m_suspendTabBar->hideTabBar(); + delete m_suspendTabBar; + m_suspendTabBar = nullptr; + } + disconnected(); + } break; + } +} + +// void PcScreenManage::slotEnterControl(bool isControl) +// { +// qInfo() << "Receive anti control message, current status: " << isControl; +// if (isControl) { +// m_curtain->showView(); +// m_curtain->hideTabBar(); +// startedControl(); +// } else { +// exitControl(); +// } +// } + int PcScreenManage::sendMessage(const ScreenManageMsg &message) { if (m_messageTcpSocket == nullptr) { diff --git a/pcscreenmanage/pcscreenmanage.h b/pcscreenmanage/pcscreenmanage.h index f69bfaf..6ae3a66 100644 --- a/pcscreenmanage/pcscreenmanage.h +++ b/pcscreenmanage/pcscreenmanage.h @@ -6,10 +6,14 @@ #include #include #include +//#include +//#include #include "screenmanagemsg.pb.h" #include "pcscreen.h" #include "curtain.h" #include "control.h" +#include "suspendtabbar.h" +#include "publicattributes.hpp" class PcScreenManage : public QObject { @@ -28,26 +32,26 @@ public: Successfully = 6, // 投屏请求成功 StartedControl = 7, // 启动反控 ExitControl = 8, // 退出反控 - HideView = 9, //隐藏投屏 + HideView = 9, // 隐藏投屏 + ShowView = 10, // 显示投屏 }; Q_ENUM(ScreenMsg) + void setTheme(PublicAttributes::Theme theme); + // 断开通信通道 void disconnected(); // 连接服务端 void connectService(const QString host); // 设置验证结果 void setConnectionRespond(bool isAgree); - // 显示幕布 - void showCurtain(); - // 隐藏幕布 - void hideCurtain(); // 通知对端进入反控 void startedControl(); // 通知对端退出反控 void exitControl(); -public: + void showView(); + private: // 获取投屏服务 void startPcService(); @@ -72,6 +76,9 @@ private Q_SLOTS: void onMessageReadyRead(); void handleStateChange(QAbstractSocket::SocketState state); void slotSocketDisconnect(); + void slotStateChange(Curtain::States state); + void slotTabBtnClicked(SuspendTabBar::BtnType type); + // void slotEnterControl(bool isControl); private: QTcpServer *m_tcpServer = nullptr; // Tcp服务 @@ -80,12 +87,15 @@ private: QThread *m_pcScreenThread = nullptr; //投屏服务线程 Curtain *m_curtain = nullptr; // 投屏幕布 Control *m_control = nullptr; // 反控 + SuspendTabBar *m_suspendTabBar = nullptr; + // QDBusInterface *m_dbusInterface = nullptr; // 反控dbus - QString m_address = ""; // 客服端ip - qint64 m_dataSize = 0; // 接收的数据大小 - QByteArray m_data; // 需要发送的数据 - bool m_isHead = true; // 是否为消息头 - bool m_isService = true; // 是否为服务端 + QString m_address = ""; // 客服端ip + qint64 m_dataSize = 0; // 接收的数据大小 + QByteArray m_data; // 需要发送的数据 + bool m_isHead = true; // 是否为消息头 + bool m_isService = true; // 是否为服务端 + PublicAttributes::Theme m_theme = PublicAttributes::Theme::Light; // 主题 }; #endif // PCSCREENMANAGE_H \ No newline at end of file diff --git a/ui/view/suspendtabbar.cpp b/pcscreenmanage/suspendtabbar.cpp similarity index 84% rename from ui/view/suspendtabbar.cpp rename to pcscreenmanage/suspendtabbar.cpp index b74276e..210fb01 100644 --- a/ui/view/suspendtabbar.cpp +++ b/pcscreenmanage/suspendtabbar.cpp @@ -17,31 +17,36 @@ const int WINTHREE_W = 168; const int WINTHREE_H = 56; const double TRANSPARENCY = 0.75; -SuspendTabBar::SuspendTabBar(SuspendTabBar::Display mode, QWidget *parent) : QWidget(parent) +SuspendTabBar::SuspendTabBar(SuspendTabBar::Display mode, bool isTool, QWidget *parent) : QWidget(parent) { setProperty("useStyleWindowManager", false); setProperty("useSystemStyleBlur", true); setAttribute(Qt::WA_TranslucentBackground, true); - setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool); + if (isTool) { + setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::Tool); + } else { + setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); + } + m_openBtn = new OpenBtn(isTool, parent); + connect(m_openBtn, &OpenBtn::sigClicked, this, &SuspendTabBar::onOpenClicked); + m_openBtn->setFixedHeight(1); if (mode == SuspendTabBar::Display::Whole) { initWholeUI(); } else { initPartUI(); } - m_openBtn = new OpenBtn(this); - connect(m_openBtn, &OpenBtn::sigClicked, this, &SuspendTabBar::onOpenClicked); - m_openBtn->show(); initAnimation(); activateWindow(); setFocus(); + QRect availableGeometry = qApp->primaryScreen()->availableGeometry(); - setGeometry(availableGeometry.width() / 2 - width() / 2, 0, width(), height()); + move(availableGeometry.width() / 2 - width() / 2, 0); } SuspendTabBar::~SuspendTabBar() { if (m_openBtn != nullptr) { - m_openBtn->deleteLater(); + delete m_openBtn; m_openBtn = nullptr; } } @@ -73,17 +78,6 @@ void SuspendTabBar::setTheme(PublicAttributes::Theme theme) update(); } -void SuspendTabBar::setControlState(bool isControl) -{ - if (isControl) { - m_ctrlBtnState = false; - m_controlBtn->setIcon(QIcon(":/tabbaricon/controlclose.svg")); - } else { - m_ctrlBtnState = true; - m_controlBtn->setIcon(QIcon(":/tabbaricon/control.svg")); - } -} - void SuspendTabBar::hideTabBar() { hide(); @@ -94,6 +88,8 @@ void SuspendTabBar::showTabBar() { show(); m_openBtn->show(); + activateWindow(); + setFocus(); } void SuspendTabBar::setDeskBtnState(bool isDesktop) @@ -197,11 +193,8 @@ void SuspendTabBar::initPartUI() setFixedSize(WINTWO_W, WINTWO_H); m_controlBtn = new kdk::KToolButton(this); m_exitBtn = new QPushButton(this); - m_openBtn = new OpenBtn; - m_openBtn->show(); connect(m_controlBtn, &kdk::KToolButton::clicked, this, &SuspendTabBar::onClicked); - connect(m_openBtn, &OpenBtn::sigClicked, this, &SuspendTabBar::onOpenClicked); connect(m_exitBtn, &QPushButton::clicked, this, &SuspendTabBar::onExitClicked); m_controlBtn->setType(kdk::KToolButtonType::Flat); @@ -209,7 +202,7 @@ void SuspendTabBar::initPartUI() m_controlBtn->setFocusPolicy(Qt::NoFocus); m_exitBtn->setFocusPolicy(Qt::NoFocus); - m_controlBtn->setIcon(QIcon(":/tabbaricon/control.svg")); + m_controlBtn->setIcon(QIcon(":/tabbaricon/controlclose.svg")); m_controlBtn->setToolTip(tr("Counter control (activate Ctrl+H, cancel Ctrl+G)")); m_exitBtn->setToolTip(tr("End screen projection")); @@ -251,25 +244,11 @@ void SuspendTabBar::onClicked() kdk::KToolButton *btn = qobject_cast(sender()); if (btn == m_controlBtn) { - if (m_ctrlBtnState) { - m_ctrlBtnState = false; - m_controlBtn->setIcon(QIcon(":/tabbaricon/controlclose.svg")); - Q_EMIT sigBtnClicked(SuspendTabBar::BtnType::ControlBtn); - } else { - m_ctrlBtnState = true; - m_controlBtn->setIcon(QIcon(":/tabbaricon/control.svg")); - Q_EMIT sigBtnClicked(SuspendTabBar::BtnType::ControlCloseBtn); - } + Q_EMIT sigBtnClicked(SuspendTabBar::BtnType::ControlBtn); } else if (btn == m_switchDeskBtn) { if (m_deskBtnState) { - m_deskBtnState = false; - m_switchDeskBtn->setIcon(QIcon(":/tabbaricon/screenshare.svg")); - m_switchDeskBtn->setToolTip(tr("Back to the desktop")); Q_EMIT sigBtnClicked(SuspendTabBar::BtnType::ReturnDesktopBtn); } else { - m_deskBtnState = true; - m_switchDeskBtn->setIcon(QIcon(":/tabbaricon/desktop.svg")); - m_switchDeskBtn->setToolTip(tr("Resume screen projection")); Q_EMIT sigBtnClicked(SuspendTabBar::BtnType::ScreenShareBtn); } } @@ -289,11 +268,15 @@ void SuspendTabBar::onExitClicked() Q_EMIT sigBtnClicked(SuspendTabBar::BtnType::ExitBtn); } -OpenBtn::OpenBtn(QWidget *parent) : QWidget(parent) +OpenBtn::OpenBtn(bool isTool, QWidget *parent) : QWidget(parent) { setProperty("useStyleWindowManager", false); setAttribute(Qt::WA_TranslucentBackground, true); - setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus | Qt::Tool); + if (isTool) { + setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus | Qt::Tool); + } else { + setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus); + } m_openBtn = new kdk::KToolButton(this); connect(m_openBtn, &kdk::KToolButton::clicked, this, &OpenBtn::sigClicked); diff --git a/ui/view/suspendtabbar.h b/pcscreenmanage/suspendtabbar.h similarity index 92% rename from ui/view/suspendtabbar.h rename to pcscreenmanage/suspendtabbar.h index b75c62d..03cd881 100644 --- a/ui/view/suspendtabbar.h +++ b/pcscreenmanage/suspendtabbar.h @@ -19,12 +19,12 @@ public: }; Q_ENUM(Display) - SuspendTabBar(SuspendTabBar::Display mode = SuspendTabBar::Display::Whole, QWidget *parent = nullptr); + SuspendTabBar(SuspendTabBar::Display mode = SuspendTabBar::Display::Whole, bool isTool = false, + QWidget *parent = nullptr); ~SuspendTabBar(); enum BtnType { ControlBtn = 0, // 反控按钮 - ControlCloseBtn, // 取消反控 ReturnDesktopBtn, // 返回桌面 ScreenShareBtn, // 投屏 ExitBtn, // 退出 @@ -32,7 +32,6 @@ public: Q_ENUM(BtnType) void setTheme(PublicAttributes::Theme theme); - void setControlState(bool isControl); void hideTabBar(); void showTabBar(); void setDeskBtnState(bool isDesktop); @@ -72,7 +71,7 @@ class OpenBtn : public QWidget { Q_OBJECT public: - OpenBtn(QWidget *parent = nullptr); + OpenBtn(bool isTool = false, QWidget *parent = nullptr); void setTheme(PublicAttributes::Theme theme); diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index bb8bc6e..cf99728 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -74,8 +74,6 @@ set(MOBILE_UI_VIEW_SOURCES view/searchedit.h view/backgroundwin.cpp view/backgroundwin.h - view/suspendtabbar.cpp - view/suspendtabbar.h view/levitationbutton.cpp view/levitationbutton.h ) @@ -86,7 +84,6 @@ set(MOBILE_UI_SOURCES ${MOBILE_UI_INITCONNECTWIN_SOURCES} ${MOBILE_UI_STORAGELIST_SOURCES} ${MOBILE_UI_VIEW_SOURCES} - publicattributes.hpp mainwindow.h mainwindow.cpp) diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 361e666..f4a6c3f 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -82,15 +82,6 @@ void MainWindow::keyPressEvent(QKeyEvent *event) if (event->key() == Qt::Key_F1) { m_titlebar->initHelp(); } - // else if (event->key() == Qt::Key_H && event->modifiers() == Qt::ControlModifier) { - // m_suspendTabBar->setControlState(true); - // m_pcScreen->startedControl(); - // m_suspendTabBar->hide(); - // } else if (event->key() == Qt::Key_G && event->modifiers() == Qt::ControlModifier) { - // m_suspendTabBar->setControlState(false); - // m_pcScreen->exitControl(); - // m_suspendTabBar->show(); - // } QWidget::keyPressEvent(event); } @@ -105,7 +96,6 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) void MainWindow::resizeEvent(QResizeEvent *event) { - qDebug() << this->x() << " " << this->y(); Q_UNUSED(event); if (m_listItemWidget) { m_listItemWidget->setViewHeight(); @@ -334,8 +324,8 @@ void MainWindow::changeLightTheme() if (m_connectedWin != nullptr) { m_connectedWin->setTheme(m_theme); } - if (m_suspendTabBar != nullptr) { - m_suspendTabBar->setTheme(m_theme); + if (m_pcScreen != nullptr) { + m_pcScreen->setTheme(m_theme); } } @@ -352,8 +342,8 @@ void MainWindow::changeDarkTheme() if (m_connectedWin != nullptr) { m_connectedWin->setTheme(m_theme); } - if (m_suspendTabBar != nullptr) { - m_suspendTabBar->setTheme(m_theme); + if (m_pcScreen != nullptr) { + m_pcScreen->setTheme(m_theme); } } @@ -364,9 +354,6 @@ void MainWindow::initUI() m_titlebar = new Titlebar(this); connect(m_titlebar, &Titlebar::sigAboutWinShow, this, &MainWindow::slotAboutWinShow); - connect(m_titlebar, &Titlebar::sigSearchResult, this, &MainWindow::onRecvSearchResult); - connect(m_titlebar, &Titlebar::sigSearchInitFail, this, &MainWindow::slotSearchInitFail); - connect(this, &MainWindow::sigClearSearchLine, m_titlebar, &Titlebar::onBackButtonClick); m_homepage = new HomePage; m_homepage->setDeviceCode(m_wifiIp); @@ -797,7 +784,6 @@ void MainWindow::slotDisconnect() deleteStackedWidget(); deleteMobileListWidget(); deleteTransmissionDialog(); - deleteSuspendTab(); stopLoadUI(); slotContinueSearch(); if (m_isServerConnect) { @@ -941,6 +927,8 @@ void MainWindow::slotDownTempFileFinish(QString filePath) stopLoadUI(); if (m_isPcSearchInfo) { m_isPcSearchInfo = false; + m_isUpdated = true; + m_searchInfoPath = filePath; } else if (!filePath.isEmpty()) { FileInfo::fileOpen(filePath); } else { @@ -974,7 +962,7 @@ void MainWindow::slotMountError(bool isMount, QString error) { qInfo() << "mountFtpError:" << error; if (isMount) { - QMessageBox::warning(this, tr("Warning"), tr("Peony access can be error-prone"), QMessageBox::Ok); + setToolTipWin(tr("Peony access can be error-prone"), kdk::TipType::Warning); } else { setToolTipWin(tr("Umount failed"), kdk::TipType::Warning); } @@ -1062,15 +1050,10 @@ void MainWindow::slotRequestReceived(PcScreenManage::ScreenMsg msg) stopLoadUI(); if (m_connectInfo.deviceRole == ConnectionService::DeviceRole::INITIATOR) { hide(); - m_suspendTabBar = new SuspendTabBar(SuspendTabBar::Display::Whole); - connect(m_suspendTabBar, &SuspendTabBar::sigBtnClicked, this, &MainWindow::slotTabBtnClicked); - m_suspendTabBar->setTheme(m_theme); - m_suspendTabBar->showTabBar(); } } break; case PcScreenManage::ScreenMsg::ScreenExit: { // 投屏退出 - deleteSuspendTab(); show(); if (m_connectInfo.deviceRole == ConnectionService::DeviceRole::RECIPIENT && m_connectedWin != nullptr) { m_connectedWin->restoreScreenButton(); @@ -1096,7 +1079,6 @@ void MainWindow::slotRequestReceived(PcScreenManage::ScreenMsg msg) } break; case PcScreenManage::ScreenMsg::Disconnect: { // 投屏断开 - deleteSuspendTab(); disconnectScreen(); show(); QString str1 = QString(tr("End of screen projection")); @@ -1107,34 +1089,12 @@ void MainWindow::slotRequestReceived(PcScreenManage::ScreenMsg msg) m_messageBox->addButton(QString(tr("OK")), QMessageBox::AcceptRole); m_messageBox->show(); } break; - case PcScreenManage::ScreenMsg::StartedControl: { - // 进入反控 - // if (m_connectInfo.deviceRole == ConnectionService::DeviceRole::INITIATOR && m_suspendTabBar == nullptr) { - // m_suspendTabBar = new SuspendTabBar(SuspendTabBar::Display::Part); - // connect(m_suspendTabBar, &SuspendTabBar::sigBtnClicked, this, &MainWindow::slotTabBtnClicked); - // m_suspendTabBar->setTheme(m_theme); - // m_suspendTabBar->setControlState(true); - // m_suspendTabBar->showTabBar(); - // } - } break; - case PcScreenManage::ScreenMsg::ExitControl: { - // if (m_connectInfo.deviceRole == ConnectionService::DeviceRole::RECIPIENT && m_suspendTabBar != nullptr) { - // // 暂时先模拟键盘退出 - // QString common = "xdotool key ctrl+g"; - // system(common.toUtf8().constData()); - // // 退出反控 - // m_suspendTabBar->setControlState(false); - // m_suspendTabBar->showTabBar(); - // } else if (m_connectInfo.deviceRole == ConnectionService::DeviceRole::INITIATOR && m_suspendTabBar != - // nullptr) { - // m_suspendTabBar->setControlState(false); - // m_suspendTabBar->hideTabBar(); - // } - } break; case PcScreenManage::ScreenMsg::HideView: { - m_suspendTabBar->setDeskBtnState(true); show(); } break; + case PcScreenManage::ScreenMsg::ShowView: { + hide(); + } break; } } @@ -1259,7 +1219,6 @@ void MainWindow::initPcSearchInfo() // m_fileSyncManage->setSearchPath(FileSyncManage::SEARCH_TYPE::TYPE_PC, m_connectInfo.deviceName); // connect(m_fileSyncManage, SIGNAL(sigDownFileFail(QString, QString)), this, // SLOT(slotDownFileFail(QString, QString))); - // connect(m_fileSyncManage, &FileSyncManage::sigSearchInfoFinsh, m_titlebar, &Titlebar::onSearchInstalled); // connect(m_fileSyncManage, &FileSyncManage::sigTempFileDownFinish, this, &MainWindow::slotDownTempFileFinish); // m_fileSyncManage->downloadSearch(); } @@ -1695,52 +1654,11 @@ void MainWindow::slotExitPcScreen() if (m_connectedWin != nullptr) { m_connectedWin->restoreScreenButton(); } - deleteSuspendTab(); if (m_pcScreen != nullptr) { m_pcScreen->disconnected(); } } -void MainWindow::slotTabBtnClicked(SuspendTabBar::BtnType type) -{ - switch (type) { - case SuspendTabBar::BtnType::ControlBtn: { - // if (m_suspendTabBar != nullptr) { - // m_suspendTabBar->hideTabBar(); - // } - // 暂时先模拟键盘进入反控 - m_pcScreen->showCurtain(); - QString common = "xdotool key ctrl+h"; - system(common.toUtf8().constData()); - m_suspendTabBar->setDeskBtnState(false); - // m_pcScreen->startedControl(); - } break; - case SuspendTabBar::BtnType::ControlCloseBtn: { - m_pcScreen->exitControl(); - } break; - case SuspendTabBar::BtnType::ReturnDesktopBtn: { - m_pcScreen->hideCurtain(); - show(); - } break; - case SuspendTabBar::BtnType::ScreenShareBtn: { - m_pcScreen->showCurtain(); - hide(); - } break; - case SuspendTabBar::BtnType::ExitBtn: { - slotExitPcScreen(); - show(); - } break; - } -} - -void MainWindow::deleteSuspendTab() -{ - if (m_suspendTabBar != nullptr) { - delete m_suspendTabBar; - m_suspendTabBar = nullptr; - } -} - void MainWindow::slotMobileFileListSearchClicked() { qInfo() << "show null search widget"; @@ -1755,7 +1673,7 @@ void MainWindow::slotMobileFileListSearchClicked() m_stackedMobileFileListWin->addWidget(m_mobileStorageWidget); m_stackedMobileFileListWin->setCurrentIndex(1); m_mobileStorageWidget->setEditFocus(true); -// m_mobileStorageWidget->setLineEditText(m_searchKeyword); + // m_mobileStorageWidget->setLineEditText(m_searchKeyword); m_mobileStorageWidget->setMode(m_storageMode); connectMobileStorage(); } @@ -1766,7 +1684,6 @@ void MainWindow::slotSearchUpdateClicked() Q_EMIT sigSearchUpdate(); } - void MainWindow::connectMobileFileList() { connect(m_mobileFileList, &MobileFileList::sigPictureClicked, this, &MainWindow::slotItemButtonClicked); @@ -1777,7 +1694,8 @@ void MainWindow::connectMobileFileList() connect(m_mobileFileList, &MobileFileList::sigQQClicked, this, &MainWindow::slotItemButtonClicked); connect(m_mobileFileList, &MobileFileList::sigMobileStorageClicked, this, &MainWindow::slotCdMobileStorageDirectory); - connect(m_mobileFileList, &MobileFileList::sigMobileFileListSearchClicked, this, &MainWindow::slotMobileFileListSearchClicked); + connect(m_mobileFileList, &MobileFileList::sigMobileFileListSearchClicked, this, + &MainWindow::slotMobileFileListSearchClicked); } void MainWindow::connectMobileStorage() @@ -1802,5 +1720,16 @@ void MainWindow::connectMobileStorage() connect(m_mobileStorageWidget, &MobileStorageWidget::sigSearchResult, this, &MainWindow::onRecvSearchResult); connect(m_mobileStorageWidget, &MobileStorageWidget::sigSearchInitFail, this, &MainWindow::slotSearchInitFail); connect(this, &MainWindow::sigSearchUpdate, m_mobileStorageWidget, &MobileStorageWidget::onReturnPressed); + connect(m_mobileStorageWidget, &MobileStorageWidget::sigForwardButtonEnabled, this, [=](QString indexPath) { + m_saveListPath << indexPath; + }); + + connect(m_mobileStorageWidget, &MobileStorageWidget::sigForwardButtonClicked, this, [=]() { + if (m_saveListPath.size() > 0) { + QString lastPath = m_saveListPath.last(); + slotCdMobileStorageDirectory(lastPath); + m_saveListPath.removeLast(); + } + }); m_mobileStorageWidget->setMode(m_storageMode); } diff --git a/ui/mainwindow.h b/ui/mainwindow.h index e06cb38..8d2a21c 100644 --- a/ui/mainwindow.h +++ b/ui/mainwindow.h @@ -135,7 +135,6 @@ private: void initPcSearchInfo(); void discInit(); void deInitDisc(); - void deleteSuspendTab(); void connectMobileFileList(); void connectMobileStorage(); @@ -183,7 +182,6 @@ private: LoadDialog *m_loadDialog = nullptr; //加载动画 LoadAnimation *m_loadAnimation = nullptr; // 打开/更新加载界面 QTimer *m_timer = nullptr; // 连接加载定时器,连接超时处理 - SuspendTabBar *m_suspendTabBar = nullptr; // 投屏控制Tab int m_fileSyncIndex = 2; // 手机文件同步堆栈窗口索引 QListView::ViewMode m_classificationMode = QListView::IconMode; // 分类列表当前视图模式 @@ -201,6 +199,7 @@ private: bool m_isUpdated; QString m_searchInfoPath; QString m_searchKeyword; + QStringList m_saveListPath; Q_SIGNALS: // 提供dbus服务 void sigConnected(QString); @@ -260,7 +259,6 @@ public Q_SLOTS: void slotConnectedWinBtnClicked(ConnectedWin::BtnType type); void slotExitMobileScreen(); void slotExitPcScreen(); - void slotTabBtnClicked(SuspendTabBar::BtnType type); void slotSetSearchInfoFinish(bool isUpdated, QString searchInfoPath); void slotMobileFileListSearchClicked(); void slotSearchKeyword(QString query); diff --git a/ui/storagelist/mobilestoragewidget.cpp b/ui/storagelist/mobilestoragewidget.cpp index f6cb04e..9b40544 100644 --- a/ui/storagelist/mobilestoragewidget.cpp +++ b/ui/storagelist/mobilestoragewidget.cpp @@ -76,11 +76,11 @@ void MobileStorageWidget::initUI() retreatButton->setFlat(true); retreatButton->setCursor(Qt::PointingHandCursor); - // QPushButton *forwardButton = new QPushButton(this); - // forwardButton->setIcon(QIcon::fromTheme("go-next-symbolic")); - // forwardButton->setFixedSize(16, 16); - // forwardButton->setFlat(true); - // forwardButton->setCursor(Qt::PointingHandCursor); + QPushButton *forwardButton = new QPushButton(this); + forwardButton->setIcon(QIcon::fromTheme("go-next-symbolic")); + forwardButton->setFixedSize(16, 16); + forwardButton->setFlat(true); + forwardButton->setCursor(Qt::PointingHandCursor); QFont font; font.setBold(true); @@ -143,7 +143,7 @@ void MobileStorageWidget::initUI() refreshButton->setFlat(true); fileListHLayout->addWidget(retreatButton); - // fileListHLayout->addWidget(forwardButton); + fileListHLayout->addWidget(forwardButton); // fileListHLayout->addSpacing(28); fileListHLayout->addWidget(crumb); fileListHLayout->addStretch(); @@ -195,12 +195,22 @@ void MobileStorageWidget::initUI() this->setBackgroundRole(QPalette::Base); connect(retreatButton, &QPushButton::clicked, this, [=]() { + QString indexPath; + for (int i = 2; i < crumb->currentIndex() + 1; i++) { + indexPath += "/" + crumb->tabText(i); + } + Q_EMIT sigForwardButtonEnabled(indexPath); + int currentIndex = crumb->currentIndex(); if (currentIndex > 0) { crumb->setCurrentIndex(currentIndex - 1); } }); + connect(forwardButton, &QPushButton::clicked, this, [=]() { + Q_EMIT sigForwardButtonClicked(); + }); + connect(refreshButton, &QPushButton::clicked, this, [=]() { for (int i = 2; i < crumb->currentIndex() + 1; i++) { m_currentIndexPath += "/" + crumb->tabText(i); @@ -250,7 +260,6 @@ void MobileStorageWidget::initUI() } slotHideCopyToComputerWidget(); - //当前索引路径 刷新界面 Q_EMIT sigCurrentIndexPath(m_currentIndexPath); } @@ -279,11 +288,11 @@ void MobileStorageWidget::initPcUI() retreatButton->setFlat(true); retreatButton->setCursor(Qt::PointingHandCursor); - // QPushButton *forwardButton = new QPushButton(this); - // forwardButton->setIcon(QIcon::fromTheme("go-next-symbolic")); - // forwardButton->setFixedSize(16, 16); - // forwardButton->setFlat(true); - // forwardButton->setCursor(Qt::PointingHandCursor); + QPushButton *forwardButton = new QPushButton(this); + forwardButton->setIcon(QIcon::fromTheme("go-next-symbolic")); + forwardButton->setFixedSize(16, 16); + forwardButton->setFlat(true); + forwardButton->setCursor(Qt::PointingHandCursor); QFont font; font.setBold(true); @@ -339,7 +348,7 @@ void MobileStorageWidget::initPcUI() fileListHLayout->addWidget(retreatButton); fileListHLayout->addSpacing(20); - // fileListHLayout->addWidget(forwardButton); + fileListHLayout->addWidget(forwardButton); // fileListHLayout->addSpacing(28); fileListHLayout->addWidget(crumb); fileListHLayout->addStretch(); @@ -387,16 +396,27 @@ void MobileStorageWidget::initPcUI() this->setBackgroundRole(QPalette::Base); connect(retreatButton, &QPushButton::clicked, this, [=]() { + QString indexPath; + for (int i = 0; i < crumb->currentIndex() + 1; i++) { + indexPath += "/" + crumb->tabText(i); + } + Q_EMIT sigForwardButtonEnabled(indexPath); + int currentIndex = crumb->currentIndex(); if (currentIndex > 0) { crumb->setCurrentIndex(currentIndex - 1); } }); + connect(forwardButton, &QPushButton::clicked, this, [=]() { + Q_EMIT sigForwardButtonClicked(); + }); + connect(refreshButton, &QPushButton::clicked, this, [=]() { - for (int i = 2; i < crumb->currentIndex() + 1; i++) { - m_currentIndexPath += "/" + crumb->tabText(i); + for (int i = 0; i < crumb->currentIndex() + 1; i++) { + m_currentIndexPath += crumb->tabText(i); } + Q_EMIT sigUpdateClicked(m_currentIndexPath); }); diff --git a/ui/storagelist/mobilestoragewidget.h b/ui/storagelist/mobilestoragewidget.h index 1416d8f..05b5104 100644 --- a/ui/storagelist/mobilestoragewidget.h +++ b/ui/storagelist/mobilestoragewidget.h @@ -64,6 +64,8 @@ Q_SIGNALS: void sigSearchInitFail(); void sigSearchInstalled(bool isUpdated, QString searchInfoPath); void sigSearchKeyword(QString query); + void sigForwardButtonEnabled(QString indexPath); + void sigForwardButtonClicked(); private: MobileStorageViewWidget *m_mobileStorageViewWidget = nullptr; diff --git a/ui/view/titlebar.cpp b/ui/view/titlebar.cpp index d4ec1ec..4d9c65e 100644 --- a/ui/view/titlebar.cpp +++ b/ui/view/titlebar.cpp @@ -2,6 +2,8 @@ #include #include +#include +#include #include Titlebar::Titlebar(QWidget *parent) : QWidget(parent) @@ -11,17 +13,7 @@ Titlebar::Titlebar(QWidget *parent) : QWidget(parent) connectInit(); } -Titlebar::~Titlebar() -{ - if (m_menu != nullptr) { - delete m_menu; - m_menu = nullptr; - } - if (m_searchServer != nullptr) { - delete m_searchServer; - m_searchServer = nullptr; - } -} +Titlebar::~Titlebar() {} void Titlebar::initUI() { @@ -38,14 +30,6 @@ void Titlebar::initUI() m_titleIcon->setIcon(QIcon::fromTheme("kylin-multi-collaboration")); m_titleIcon->setContentsMargins(8, 8, 8, 8); - m_searchLine = new kdk::KSearchLineEdit(this); - m_searchLine->setClearButtonEnabled(true); - m_searchLine->setPlaceholderText(tr("Search")); - m_searchLine->setFocusPolicy(Qt::ClickFocus); - m_searchLine->setContextMenuPolicy(Qt::DefaultContextMenu); - m_searchLine->hide(); - - m_searchLine->setFixedSize(230, 32); m_menuBtn = new QToolButton(this); m_menu = new QMenu(); m_menuBtn->setToolTip(tr("Menu")); @@ -94,8 +78,6 @@ void Titlebar::initUI() layout->addWidget(m_titleIcon); layout->addWidget(m_titleNameLab); layout->addStretch(); - layout->addWidget(m_searchLine); - layout->addStretch(); layout->addWidget(m_menuBtn); layout->addWidget(m_minBtn); layout->addWidget(m_maxBtn); @@ -104,6 +86,7 @@ void Titlebar::initUI() layout->setContentsMargins(0, 4, 0, 0); setLayout(layout); + m_maxBtn->hide(); } void Titlebar::hideButton() @@ -148,6 +131,17 @@ void Titlebar::setBackground(bool isDefault) } } +void Titlebar::mouseDoubleClickEvent(QMouseEvent *event) +{ + if (window()->isMaximized()) { + window()->showNormal(); + m_maxBtn->setIcon(QIcon::fromTheme("window-maximize-symbolic")); + } else { + window()->showMaximized(); + m_maxBtn->setIcon(QIcon::fromTheme("window-restore-symbolic")); + } +} + // 连接槽 void Titlebar::connectInit() { @@ -157,11 +151,6 @@ void Titlebar::connectInit() connect(m_closeBtn, &QPushButton::clicked, this, &Titlebar::onClicked); // 连接菜单信号槽 connect(m_menu, &QMenu::triggered, this, &Titlebar::triggerMenu); - connect(m_searchLine, &kdk::KSearchLineEdit::textChanged, this, &Titlebar::onTextChanged); - connect(m_searchLine, &kdk::KSearchLineEdit::returnPressed, this, &Titlebar::onReturnPressed); - connect(this, &Titlebar::sigSearchLineShow, this, [this]() { - // m_searchLine->show(); - }); } // 设置菜单按钮 @@ -236,99 +225,4 @@ void Titlebar::initHelp() msg << "kylin-mobile-assistant"; if (QDBusConnection::sessionBus().isConnected()) QDBusConnection::sessionBus().call(msg); -} - -void Titlebar::onTextChanged() -{ - if (!m_mutex.try_lock()) { - return; - } - if (m_searchServer == nullptr) { - qWarning() << "search server is not ready!"; - return; - } - m_query = m_searchLine->text().trimmed(); - m_mutex.unlock(); - if (m_query.isEmpty()) { - return; - } - - auto search = [this]() { - if (!m_mutex.try_lock()) { - return; - } - Q_EMIT sigStartSearch(); - m_resultMap.clear(); - m_searchServer->search(m_resultMap, m_query); - Q_EMIT sigSearchResult(m_resultMap); - m_mutex.unlock(); - }; - std::thread searchThread(search); - searchThread.detach(); -} - -void Titlebar::onReturnPressed() -{ - onTextChanged(); -} - -void Titlebar::onSearchInstalled(bool isUpdated, QString searchInfoPath) -{ - qInfo() << "searchInfo installed"; - - if (!m_mutex.try_lock()) { - return; - } - if (m_searchServer != nullptr) { - m_searchLine->clear(); - delete m_searchServer; - m_searchServer = nullptr; - } - m_searchServer = new SearchServer(); - m_searchServer->setSearchDbPath(searchInfoPath); - if (m_searchServer) { - if (m_searchServer->init() < 0) { - qWarning() << "load search server fail"; - Q_EMIT sigSearchInitFail(); - return; - } - } - m_mutex.unlock(); - - if (!isUpdated) { - qInfo() << "use old searchInfo"; - Q_EMIT sigSearchLineShow(); - } else { - if (m_searchServer) { - qInfo() << "use new searchInfo"; - auto searchInit = [this]() { - m_mutex.lock(); - if (m_searchServer->createIndex() >= 0) { - Q_EMIT sigSearchLineShow(); - } else { - qWarning() << "search server init fail"; - Q_EMIT sigSearchInitFail(); - } - m_mutex.unlock(); - }; - std::thread searchInitThread(searchInit); - searchInitThread.detach(); - } - } -} - -void Titlebar::hideSearchLine() -{ - qInfo() << "searchLine hide"; - m_searchLine->hide(); - m_searchLine->clear(); - if (m_searchServer != nullptr) { - delete m_searchServer; - m_searchServer = nullptr; - } -} - -void Titlebar::onBackButtonClick() -{ - m_searchLine->clear(); -} +} \ No newline at end of file diff --git a/ui/view/titlebar.h b/ui/view/titlebar.h index c374daa..c3bf4aa 100644 --- a/ui/view/titlebar.h +++ b/ui/view/titlebar.h @@ -13,11 +13,7 @@ #include #include #include -#include #include - -#include "searchserver.h" -#include "fileinfo.h" #include "publicattributes.hpp" class Titlebar : public QWidget @@ -27,27 +23,18 @@ public: Titlebar(QWidget *parent = nullptr); ~Titlebar(); void hideButton(); - void hideSearchLine(); void initHelp(); // 设置帮助Action void setTheme(PublicAttributes::Theme theme); void setBackground(bool isDefault = true); +protected: + void mouseDoubleClickEvent(QMouseEvent *event); + Q_SIGNALS: void sigAboutWinShow(); - void sigSearchResult(const QMap &searchResult); - void sigSearchLineShow(); - void sigSearchInitFail(); - void sigStartSearch(); - public Q_SLOTS: void onClicked(void); void triggerMenu(QAction *); - void onSearchInstalled(bool isUpdated, QString searchInfoPath); - void onBackButtonClick(); - -private Q_SLOTS: - void onTextChanged(); - void onReturnPressed(); private: void initUI(); @@ -58,7 +45,6 @@ private: private: QPushButton *m_titleIcon = nullptr; QLabel *m_titleNameLab = nullptr; - kdk::KSearchLineEdit *m_searchLine = nullptr; QToolButton *m_menuBtn = nullptr; // 菜单按钮 QMenu *m_menu = nullptr; // 菜单 QList m_actions; // action组 @@ -67,11 +53,6 @@ private: QPushButton *m_closeBtn = nullptr; // 关闭按钮 PublicAttributes::Theme m_theme = PublicAttributes::Theme::Light; // 主题 bool m_isDefault = true; - - SearchServer *m_searchServer = nullptr; - QString m_query = ""; - QMap m_resultMap; - QMutex m_mutex; }; #endif // TITLEBAR_H