Files

991 lines
36 KiB
C++
Raw Permalink Normal View History

2020-02-02 20:13:31 +08:00
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
2020-01-17 10:20:22 +08:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
2020-06-30 09:07:40 +08:00
#include "utils/keyvalueconverter.h"
#include "utils/functionselect.h"
2020-11-09 03:02:33 -06:00
#include "utils/utils.h"
#include "../commonComponent/ImageUtil/imageutil.h"
2021-01-07 10:16:32 +08:00
#include "ukccabout.h"
2021-01-08 14:57:54 +08:00
#include "devicesmonitor.h"
2020-01-17 10:20:22 +08:00
#include <libmatemixer/matemixer.h>
2020-01-17 10:20:22 +08:00
#include <QLabel>
2020-08-18 09:03:28 +08:00
#include <QLocale>
2020-01-17 10:20:22 +08:00
#include <QPushButton>
#include <QButtonGroup>
#include <QHBoxLayout>
#include <QPluginLoader>
2020-03-20 19:04:19 +08:00
#include <QPainter>
2020-06-11 14:25:06 +08:00
#include <QPainterPath>
#include <QProcess>
2020-01-17 10:20:22 +08:00
#include <QDebug>
#include <QMessageBox>
#include <QGSettings>
2021-01-07 10:16:32 +08:00
#include <QMenu>
2021-02-05 15:37:02 +08:00
#include <QShortcut>
#include <QMouseEvent>
2021-08-05 18:43:01 +08:00
#include <KWindowSystem>
2020-09-29 20:33:42 +08:00
#define STYLE_FONT_SCHEMA "org.ukui.style"
2021-05-21 14:43:26 +08:00
#ifdef WITHKYSEC
#include <kysec/libkysec.h>
#include <kysec/status.h>
#endif
2020-09-29 20:33:42 +08:00
const QByteArray kVinoSchemas = "org.gnome.Vino";
2020-02-13 14:45:49 +08:00
/* qt会将glib里的signals成员识别为宏,所以取消该宏
* 后面如果用到signals时,使用Q_SIGNALS代替即可
**/
#ifdef signals
#undef signals
#endif
extern "C" {
#include <glib.h>
#include <gio/gio.h>
}
2020-07-16 15:51:09 +08:00
const int dbWitdth = 50;
2020-04-20 21:17:22 +08:00
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
2020-02-13 14:45:49 +08:00
2020-01-17 10:20:22 +08:00
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
2020-08-18 09:03:28 +08:00
ui(new Ui::MainWindow),
m_searchWidget(nullptr)
2020-01-17 10:20:22 +08:00
{
mate_mixer_init();
qApp->installEventFilter(this);
2021-01-13 09:07:23 +08:00
initUI();
2020-01-17 10:20:22 +08:00
}
MainWindow::~MainWindow()
{
delete ui;
ui = nullptr;
2020-01-17 10:20:22 +08:00
}
void MainWindow::bootOptionsFilter(QString opt) {
if (opt == "--display" || opt == "-m") {
bootOptionsSwitch(SYSTEM, DISPLAY);
2021-01-03 15:03:46 +08:00
}if (opt == "--touchscreen") {
2020-12-28 13:52:37 +08:00
bootOptionsSwitch(SYSTEM, TOUCHSCREEN);
2020-10-22 16:44:46 +08:00
} else if (opt == "--defaultapp") {
bootOptionsSwitch(SYSTEM, DEFAULTAPP);
} else if (opt == "--power" || opt == "-p") {
bootOptionsSwitch(SYSTEM, POWER);
2020-10-22 16:44:46 +08:00
} else if (opt == "--autoboot") {
bootOptionsSwitch(SYSTEM, AUTOBOOT);
} else if (opt == "--printer") {
bootOptionsSwitch(DEVICES, PRINTER);
} else if (opt == "--projection") {
bootOptionsSwitch(DEVICES, PROJECTION);
2020-10-22 16:44:46 +08:00
} else if (opt == "--mouse") {
bootOptionsSwitch(DEVICES, MOUSE);
} else if (opt == "--touchpad") {
bootOptionsSwitch(DEVICES, TOUCHPAD);
} else if (opt == "--keyboard") {
2020-10-22 20:17:33 +08:00
bootOptionsSwitch(DEVICES, KEYBOARD);
2020-10-22 16:44:46 +08:00
} else if (opt == "--shortcut") {
bootOptionsSwitch(DEVICES, SHORTCUT);
} else if (opt == "--audio" || opt == "-s") {
2020-10-22 16:44:46 +08:00
bootOptionsSwitch(DEVICES, AUDIO);
2020-11-26 20:22:49 +08:00
} else if (opt == "--bluetooth") {
bootOptionsSwitch(DEVICES, BLUETOOTH);
} else if (opt == "--background" || opt == "-b") {
2020-10-22 16:44:46 +08:00
bootOptionsSwitch(PERSONALIZED, BACKGROUND);
} else if (opt == "--theme") {
bootOptionsSwitch(PERSONALIZED, THEME);
} else if (opt == "--screenlock") {
bootOptionsSwitch(PERSONALIZED, SCREENLOCK);
} else if (opt == "--screensaver") {
bootOptionsSwitch(PERSONALIZED, SCREENSAVER);
} else if (opt == "--fonts") {
bootOptionsSwitch(PERSONALIZED, FONTS);
2020-10-30 16:59:30 +08:00
} else if (opt == "--desktop" || opt == "-d") {
2020-10-22 16:44:46 +08:00
bootOptionsSwitch(PERSONALIZED, DESKTOP);
} else if (opt == "--netconnect") {
bootOptionsSwitch(NETWORK, NETCONNECT);
2021-11-26 12:43:42 +08:00
} else if (opt == "--wlanconnect") {
bootOptionsSwitch(NETWORK, WLANCONNECT);
} else if (opt == "--netconnect-icbc") {
bootOptionsSwitch(NETWORK, NETCONNECT_ICBC);
} else if (opt == "--vpn" || opt == "-g") {
2020-10-22 16:44:46 +08:00
bootOptionsSwitch(NETWORK, VPN);
} else if (opt == "--proxy") {
bootOptionsSwitch(NETWORK, PROXY);
} else if (opt == "--userinfo" || opt == "-u") {
2020-10-22 16:44:46 +08:00
bootOptionsSwitch(ACCOUNT, USERINFO);
} else if (opt == "--cloudaccount") {
bootOptionsSwitch(ACCOUNT, NETWORKACCOUNT);
} else if (opt == "--datetime" || opt == "-t") {
2020-10-22 16:44:46 +08:00
bootOptionsSwitch(DATETIME, DAT);
} else if (opt == "--area") {
bootOptionsSwitch(DATETIME, AREA);
2020-12-29 10:09:23 +08:00
} else if (opt == "--upgrade") {
bootOptionsSwitch(UPDATE, UPGRADE);
2021-01-03 15:03:46 +08:00
} else if (opt == "--backup") {
2020-10-22 16:44:46 +08:00
bootOptionsSwitch(UPDATE, BACKUP);
} else if (opt == "--notice" || opt == "-n") {
2020-10-22 16:44:46 +08:00
bootOptionsSwitch(NOTICEANDTASKS, NOTICE);
} else if (opt == "--about" || opt == "-a") {
2020-10-22 16:44:46 +08:00
bootOptionsSwitch(NOTICEANDTASKS, ABOUT);
2021-04-21 15:58:15 +08:00
} else if (opt == "--search") {
bootOptionsSwitch(NOTICEANDTASKS, SEARCH);
}
}
void MainWindow::bootOptionsSwitch(int moduleNum, int funcNum){
QList<FuncInfo> pFuncStructList = FunctionSelect::funcinfoList[moduleNum];
QString funcStr = pFuncStructList.at(funcNum).namei18nString;
2020-08-18 09:03:28 +08:00
qDebug() << "moduleNum is" << moduleNum << " " << funcNum << " " << funcStr << endl;
QMap<QString, QObject *> pluginsObjMap = modulesList.at(moduleNum);
if (pluginsObjMap.keys().contains(funcStr)){
//开始跳转
ui->stackedWidget->setCurrentIndex(1);
modulepageWidget->switchPage(pluginsObjMap.value(funcStr));
}
}
2020-05-25 16:38:41 +08:00
bool MainWindow::eventFilter(QObject *watched, QEvent *event) {
/* clear m_searchWidget's focus
* MouseButtonPress event happened but not in m_searchWidget
*/
2021-05-04 17:35:24 +08:00
if (event->type() == QEvent::MouseButtonPress) {
QMouseEvent *mEvent = static_cast<QMouseEvent*>(event);
QWidget *searchParentWid = static_cast<QWidget*>(m_searchWidget->parent());
QPoint searchPoint = searchParentWid->mapFromGlobal(mEvent->globalPos());
//qDebug()<<m_searchWidget->geometry()<< mWindowGlobalPoint << mouseGlobalPoint << tPoint;
if (!m_searchWidget->geometry().contains(searchPoint)) {
if (m_isSearching == true) {
m_searchWidget->setFocus();
m_searchWidget->clearFocus();
}
}
}
2020-05-25 16:38:41 +08:00
if (this == watched) {
if (event->type() == QEvent::WindowStateChange) {
if (this->windowState() == Qt::WindowMaximized) {
maxBtn->setIcon(QIcon::fromTheme("window-restore-symbolic"));
2020-05-25 16:38:41 +08:00
} else {
maxBtn->setIcon(QIcon::fromTheme("window-maximize-symbolic"));
2020-05-25 16:38:41 +08:00
}
2020-07-16 15:51:09 +08:00
} else if (event->type() == QEvent::MouseButtonDblClick) {
bool res = dblOnEdge(dynamic_cast<QMouseEvent*>(event));
if (res) {
if (this->windowState() == Qt::WindowMaximized) {
this->showNormal();
} else {
this->showMaximized();
}
}
2020-05-25 16:38:41 +08:00
}
}
if (watched == m_searchWidget) {
if (event->type() == QEvent::FocusIn) {
2020-11-03 16:41:56 +08:00
if (m_searchWidget->text().isEmpty()) {
2020-09-11 14:31:50 +08:00
m_animation->stop();
2020-11-03 16:41:56 +08:00
m_animation->setStartValue(QRect((m_searchWidget->width()-(m_queryIcon->width()+m_queryText->width()+10))/2,0,
m_queryIcon->width()+m_queryText->width()+30,(m_searchWidget->height()+32)/2));
2021-08-18 17:30:59 +08:00
m_animation->setEndValue(QRect(8, 0, m_queryIcon->width() + 5,(m_searchWidget->height()+32)/2));
2020-09-11 14:31:50 +08:00
m_animation->setEasingCurve(QEasingCurve::OutQuad);
m_animation->start();
m_searchWidget->setTextMargins(30, 1, 0, 1);
2020-09-11 14:31:50 +08:00
}
m_isSearching = true;
} else if (event->type() == QEvent::FocusOut) {
2020-09-11 14:31:50 +08:00
m_searchKeyWords.clear();
2020-11-03 16:41:56 +08:00
if (m_searchWidget->text().isEmpty()) {
if (m_isSearching) {
2020-09-11 14:31:50 +08:00
m_queryText->adjustSize();
m_animation->setStartValue(QRect(0, 0,
m_queryIcon->width()+5,(m_searchWidget->height()+36)/2));
2020-11-03 16:41:56 +08:00
m_animation->setEndValue(QRect((m_searchWidget->width() - (m_queryIcon->width()+m_queryText->width()+10))/2,0,
m_queryIcon->width()+m_queryText->width()+30,(m_searchWidget->height()+36)/2));
2020-09-11 14:31:50 +08:00
m_animation->setEasingCurve(QEasingCurve::InQuad);
m_animation->start();
}
}
m_isSearching=false;
}
}
2020-05-25 16:38:41 +08:00
return QObject::eventFilter(watched, event);
}
2020-08-19 19:02:49 +08:00
void MainWindow::initUI() {
2021-06-15 16:19:57 +08:00
QRect screenSize = Utils::sizeOnCursor();
if (screenSize.width() <= 1440) {
this->setMinimumSize(978, 630);
} else {
this->setMinimumSize(1160, 720);
}
2020-08-19 19:02:49 +08:00
ui->setupUi(this);
2020-11-28 10:37:39 +08:00
ui->centralWidget->setStyleSheet("QWidget#centralWidget{background: palette(base); border-radius: 6px;}");
2020-08-19 19:02:49 +08:00
2020-11-09 03:02:33 -06:00
m_ModuleMap = Utils::getModuleHideStatus();
2020-08-19 19:02:49 +08:00
const QByteArray id("org.ukui.style");
m_fontSetting = new QGSettings(id, QByteArray(), this);
connect(m_fontSetting, &QGSettings::changed, this, [=](QString key) {
2020-08-19 19:02:49 +08:00
if ("systemFont" == key || "systemFontSize" ==key) {
changeSearchSlot();
2020-08-19 19:02:49 +08:00
QFont font = this->font();
int width = font.pointSize();
for (auto widget : qApp->allWidgets()) {
2021-05-31 11:32:06 +08:00
QString className(widget->metaObject()->className());
2021-04-25 15:07:03 +08:00
if (widget->objectName() == "timeClockLable") {
QFont fontTime;
2021-05-31 11:32:06 +08:00
font.setWeight(QFont::Medium);
fontTime.setPixelSize(font.pointSize() * 23 / 11);
2021-04-25 15:07:03 +08:00
widget->setFont(fontTime);
2021-05-31 11:32:06 +08:00
} else if(className.contains("TitleLabel")) {
QFont fontTitle;
fontTitle.setPixelSize(font.pointSize() * 18 / 11);
fontTitle.setWeight(QFont::Medium);
widget->setFont(fontTitle);
} else {
2021-05-31 16:08:27 +08:00
font.setWeight(QFont::Normal);
2021-04-25 15:07:03 +08:00
widget->setFont(font);
}
2020-08-19 19:02:49 +08:00
}
2021-05-31 16:08:27 +08:00
ui->leftsidebarWidget->setMaximumWidth(width * 10 + 20);
2020-08-19 19:02:49 +08:00
}
});
2021-11-29 14:10:08 +08:00
initNMIcbc();
2020-08-19 19:02:49 +08:00
initTileBar();
2020-11-03 16:41:56 +08:00
m_queryWid->setGeometry(QRect((m_searchWidget->width() - (m_queryIcon->width()+m_queryText->width()+10))/2,0,
m_queryIcon->width()+m_queryText->width()+10,(m_searchWidget->height()+36)/2));
2020-09-11 14:31:50 +08:00
m_queryWid->show();
2020-08-19 19:02:49 +08:00
initStyleSheet();
//初始化功能列表数据
FunctionSelect::initValue();
//构建枚举键值转换对象
kvConverter = new KeyValueConverter(); //继承QObject,No Delete
//加载插件
loadPlugins();
connect(minBtn, SIGNAL(clicked()), this, SLOT(showMinimized()));
connect(maxBtn, &QPushButton::clicked, this, [=] {
if (isMaximized()) {
2020-08-19 19:02:49 +08:00
showNormal();
maxBtn->setIcon(QIcon::fromTheme("window-maximize-symbolic"));
} else {
showMaximized();
maxBtn->setIcon(QIcon::fromTheme("window-restore-symbolic"));
}
});
connect(closeBtn, &QPushButton::clicked, this, [=] {
2020-08-19 19:02:49 +08:00
close();
exit(0);
2020-08-19 19:02:49 +08:00
});
connect(ui->stackedWidget, &QStackedWidget::currentChanged, this, [=](int index){
ui->centralWidget->setVisible(false); //避免出现明显的卡顿现象,在选择进入屏保界面之后这个问题比较明显,这种做法只是优化
2020-08-19 19:02:49 +08:00
if (index){ //首页部分组件样式
2021-03-04 20:50:53 +08:00
titleLabel->setHidden(true);
mTitleIcon->setHidden(true);
ui->leftsidebarWidget->setVisible(true);
//左上角显示字符/返回按钮
backBtn->setVisible(true);
2020-11-25 12:51:54 +08:00
ui->stackedWidget->setStyleSheet("QStackedWidget#stackedWidget{background: palette(base); border-bottom-right-radius: 6px;}");
2020-08-19 19:02:49 +08:00
} else { //次页部分组件样式
2021-03-04 20:50:53 +08:00
//左侧边栏显示/不显示
ui->leftsidebarWidget->setHidden(true);
titleLabel->setVisible(true);
mTitleIcon->setVisible(true);
//左上角显示字符/返回按钮
backBtn->setHidden(true);
if (modulepageWidget) {
modulepageWidget->pluginLeave();
}
2020-08-19 19:02:49 +08:00
//中部内容区域
2020-11-25 12:51:54 +08:00
ui->stackedWidget->setStyleSheet("QStackedWidget#stackedWidget{background: palette(base); border-bottom-left-radius: 6px; border-bottom-right-radius: 6px;}");
2020-08-19 19:02:49 +08:00
}
ui->centralWidget->setVisible(true);
2020-08-19 19:02:49 +08:00
});
//加载左侧边栏一级菜单
initLeftsideBar();
//加载首页Widget
homepageWidget = new HomePageWidget(this);
ui->stackedWidget->addWidget(homepageWidget);
//加载功能页Widget
modulepageWidget = new ModulePageWidget(this);
ui->stackedWidget->addWidget(modulepageWidget);
//top left return button
connect(backBtn, &QPushButton::clicked, this, [=]{
FunctionSelect::popRecordValue();
//if recordFuncStack is empty, it means there is no history record. So return to homepage
if (FunctionSelect::recordFuncStack.length() < 1) {
ui->stackedWidget->setCurrentIndex(0);
} else {
QMap<QString, QObject *> pluginsObjMap = modulesList.at(FunctionSelect::recordFuncStack.last().type);
modulepageWidget->switchPage(pluginsObjMap.value(FunctionSelect::recordFuncStack.last().namei18nString), false);
}
});
// 快捷参数
if (QApplication::arguments().length() > 1) {
2020-08-19 19:02:49 +08:00
bootOptionsFilter(QApplication::arguments().at(1));
}
2021-02-05 15:37:02 +08:00
//快捷键
new QShortcut(QKeySequence(Qt::Key_F1), this, SLOT(onF1ButtonClicked()));
2020-08-19 19:02:49 +08:00
}
2020-08-18 09:03:28 +08:00
void MainWindow::initTileBar() {
2021-05-21 14:43:26 +08:00
titleLayout = new QHBoxLayout(ui->titleWidget);
ui->titleWidget->setLayout(titleLayout);
ui->titleWidget->setObjectName("titleWidget");
ui->titleWidget->setStyleSheet("QWidget#titleWidget{background-color:palette(base)}");
titleLayout->setContentsMargins(8, 4, 4, 0);
titleLayout->setSpacing(0);
2020-08-18 09:03:28 +08:00
m_searchWidget = new SearchWidget(this);
2021-05-21 14:43:26 +08:00
m_searchWidget->setStyleSheet("background-color:palette(windowtext)");
2020-08-18 09:03:28 +08:00
m_searchWidget->setFocusPolicy(Qt::ClickFocus);
2021-05-21 14:43:26 +08:00
m_queryWid = new QWidget;
2020-09-11 14:31:50 +08:00
m_queryWid->setParent(m_searchWidget);
m_queryWid->setFocusPolicy(Qt::NoFocus);
QHBoxLayout* queryWidLayout = new QHBoxLayout;
2020-12-19 17:01:02 +08:00
queryWidLayout->setContentsMargins(0, 0, 0, 0);
2020-09-11 14:31:50 +08:00
queryWidLayout->setAlignment(Qt::AlignJustify);
queryWidLayout->setSpacing(0);
m_queryWid->setLayout(queryWidLayout);
QIcon searchIcon = QIcon::fromTheme("edit-find-symbolic");
m_queryIcon = new QLabel(this);
m_queryIcon->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(16, 16))));
2021-05-15 20:46:58 +08:00
m_queryIcon->setProperty("useIconHighlightEffect",0x10);
2020-09-11 14:31:50 +08:00
m_queryText = new QLabel(this);
2020-09-11 14:31:50 +08:00
m_queryText->setText(tr("Search"));
m_queryText->setStyleSheet("background:transparent;color:#626c6e;");
queryWidLayout->addWidget(m_queryIcon);
queryWidLayout->addWidget(m_queryText);
2020-08-18 09:03:28 +08:00
2020-09-11 14:31:50 +08:00
m_searchWidget->setContextMenuPolicy(Qt::NoContextMenu);
2020-11-03 16:41:56 +08:00
m_animation= new QPropertyAnimation(m_queryWid, "geometry", this);
2020-09-11 14:31:50 +08:00
m_animation->setDuration(100);
2021-05-21 14:43:26 +08:00
titleLayout->addWidget(m_searchWidget,Qt::AlignCenter);
2020-09-11 14:31:50 +08:00
connect(m_animation,&QPropertyAnimation::finished,this,&MainWindow::animationFinishedSlot);
2020-08-18 09:03:28 +08:00
connect(m_searchWidget, &SearchWidget::notifyModuleSearch, this, &MainWindow::switchPage);
backBtn = new QPushButton(this);
2021-06-24 14:57:25 +08:00
mOptionBtn = new QToolButton(this);
2020-08-18 09:03:28 +08:00
minBtn = new QPushButton(this);
maxBtn = new QPushButton(this);
2020-12-19 17:01:02 +08:00
closeBtn = new QPushButton(this);
mTitleIcon = new QLabel(this);
2021-01-27 16:13:36 +08:00
titleLabel = new QLabel(tr("Settings"), this);
2020-08-18 09:03:28 +08:00
2020-12-19 17:01:02 +08:00
backBtn->setFixedSize(30, 30);
2021-01-07 10:16:32 +08:00
mOptionBtn->setFixedSize(30, 30);
2020-12-19 17:01:02 +08:00
minBtn->setFixedSize(30, 30);
maxBtn->setFixedSize(30, 30);
closeBtn->setFixedSize(30, 30);
mTitleIcon->setFixedSize(24, 24);
2020-08-18 09:03:28 +08:00
2021-01-27 14:41:09 +08:00
mOptionBtn->setToolTip(tr("Main menu"));
minBtn->setToolTip(tr("Minimize"));
maxBtn->setToolTip(tr("Maximize/Normal"));
closeBtn->setToolTip(tr("Close"));
2020-12-19 17:01:02 +08:00
QIcon titleIcon = QIcon::fromTheme("ukui-control-center");
mTitleIcon->setPixmap(titleIcon.pixmap(titleIcon.actualSize(QSize(24, 24))));
titleLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
changeSearchSlot();
m_searchWidget->setFixedWidth(350);
2020-12-19 17:01:02 +08:00
2021-05-21 14:43:26 +08:00
titleLayout->addWidget(mTitleIcon);
titleLayout->addSpacing(8);
titleLayout->addWidget(titleLabel);
titleLayout->addWidget(backBtn);
titleLayout->addStretch();
titleLayout->addWidget(m_searchWidget);
titleLayout->addStretch();
titleLayout->addWidget(mOptionBtn);
titleLayout->addSpacing(4);
titleLayout->addWidget(minBtn);
titleLayout->addSpacing(4);
titleLayout->addWidget(maxBtn);
titleLayout->addSpacing(4);
titleLayout->addWidget(closeBtn);
2021-06-24 14:57:25 +08:00
initUkccAbout();
2020-08-18 09:03:28 +08:00
}
2020-09-11 14:31:50 +08:00
void MainWindow::animationFinishedSlot()
{
if (m_isSearching) {
2020-09-11 14:31:50 +08:00
m_queryWid->layout()->removeWidget(m_queryText);
m_queryText->setParent(nullptr);
m_searchWidget->setTextMargins(30, 1, 0, 1);
2020-09-11 14:31:50 +08:00
if(!m_searchKeyWords.isEmpty()) {
m_searchWidget->setText(m_searchKeyWords);
m_searchKeyWords.clear();
}
} else {
m_queryWid->layout()->addWidget(m_queryText);
}
}
2021-01-07 10:16:32 +08:00
2021-02-05 15:37:02 +08:00
void MainWindow::onF1ButtonClicked() {
qDebug() << "onF1ButtonClicked";
QString command = "kylin-user-guide";
QProcess p(0);
QStringList args;
args.append("-A");
args.append("ukui-control-center");
2021-03-01 20:21:33 +08:00
p.startDetached(command,args);//command是要执行的命令,args是参数
2021-02-05 15:37:02 +08:00
p.waitForFinished(-1);
}
2021-06-24 14:57:25 +08:00
void MainWindow::initUkccAbout() {
mOptionBtn->setStyleSheet("background-color: palette(base);");
mOptionBtn->setPopupMode(QToolButton::InstantPopup);
2021-01-07 10:16:32 +08:00
QMenu* ukccMain = new QMenu(this);
ukccMain->setObjectName("mainMenu");
2021-06-24 14:57:25 +08:00
mOptionBtn->setMenu(ukccMain);
2021-01-07 10:16:32 +08:00
QAction* ukccHelp = new QAction(tr("Help"),this);
ukccMain->addAction(ukccHelp);
QAction* ukccAbout = new QAction(tr("About"),this);
ukccMain->addAction(ukccAbout);
QAction* ukccExit = new QAction(tr("Exit"),this);
ukccMain->addAction(ukccExit);
connect(ukccExit, SIGNAL(triggered()), this, SLOT(close()));
connect(ukccAbout, &QAction::triggered, this, [=] {
UkccAbout *ukcc = new UkccAbout(this);
ukcc->exec();
});
connect(ukccHelp, &QAction::triggered, this, [=] {
QProcess process(this);
2021-01-13 14:38:01 +08:00
process.startDetached("kylin-user-guide -A ukui-control-center");
2021-01-07 10:16:32 +08:00
});
}
2021-01-21 11:09:06 +08:00
void MainWindow::setBtnLayout(QPushButton * &pBtn) {
2020-01-17 10:20:22 +08:00
QLabel * imgLabel = new QLabel(pBtn);
QSizePolicy imgLabelPolicy = imgLabel->sizePolicy();
imgLabelPolicy.setHorizontalPolicy(QSizePolicy::Fixed);
imgLabelPolicy.setVerticalPolicy(QSizePolicy::Fixed);
imgLabel->setSizePolicy(imgLabelPolicy);
imgLabel->setScaledContents(true);
QVBoxLayout * baseVerLayout = new QVBoxLayout(pBtn);
QHBoxLayout * contentHorLayout = new QHBoxLayout();
contentHorLayout->addStretch();
contentHorLayout->addWidget(imgLabel);
contentHorLayout->addStretch();
baseVerLayout->addStretch();
baseVerLayout->addLayout(contentHorLayout);
baseVerLayout->addStretch();
pBtn->setLayout(baseVerLayout);
}
void MainWindow::loadPlugins(){
2020-02-27 20:58:54 +08:00
for (int index = 0; index < TOTALMODULES; index++){
2020-01-17 10:20:22 +08:00
QMap<QString, QObject *> pluginsMaps;
modulesList.append(pluginsMaps);
}
static bool installed = (QCoreApplication::applicationDirPath() == QDir(("/usr/bin")).canonicalPath());
if (installed)
2020-07-12 18:21:00 +08:00
pluginsDir = QDir(PLUGIN_INSTALL_DIRS);
2020-01-17 10:20:22 +08:00
else {
2020-07-12 18:21:00 +08:00
pluginsDir = QDir(qApp->applicationDirPath() + "/plugins");
2020-01-17 10:20:22 +08:00
}
foreach (QString fileName, pluginsDir.entryList(QDir::Files)){
//三权分立开启
#ifdef WITHKYSEC
if (!kysec_is_disabled() && kysec_get_3adm_status() && (getuid() || geteuid())){
2021-09-07 19:05:27 +08:00
//时间和日期 | 用户帐户 | 电源管理 |网络连接 |网络代理
if (fileName.contains("datetime") || fileName.contains("userinfo") || fileName.contains("power") || \
2020-12-31 14:23:31 +08:00
fileName.contains("netconnect") || fileName.contains("proxy") || fileName.contains("update") || \
2021-01-14 14:28:35 +08:00
fileName.contains("upgrade") || fileName.contains("backup"))
continue;
}
#endif
if (!fileName.endsWith(".so")
|| (fileName == "libexperienceplan.so")
|| ("libnetworkaccount.so" == fileName && !isExitsCloudAccount())
|| (!QGSettings::isSchemaInstalled(kVinoSchemas) && "libvino.so" == fileName)
|| ("libbluetooth.so" == fileName && !isExitBluetooth())
2021-08-12 20:25:13 +08:00
|| ("libpower.so" == fileName && !isExitsPower())
2021-09-06 17:02:18 +08:00
|| ("libupdate.so" == fileName && !Utils::isCommunity())
2021-11-29 14:10:08 +08:00
|| ("libnetconnect-icbc.so" == fileName && !mIsNmIcbc)
|| ("libwlanconnect-icbc.so" == fileName && !mIsNmIcbc)
2022-05-13 09:29:33 +08:00
|| ("libnetconnect.so" == fileName && mIsNmIcbc)
|| ("libtouchpad.so" == fileName && !isfindSynaptics())) {
2021-01-08 14:57:54 +08:00
continue;
2020-11-23 14:51:40 +08:00
}
2020-03-20 16:26:07 +08:00
qDebug() << "Scan Plugin: " << fileName;
//ukui-session-manager
2020-02-29 11:44:28 +08:00
const char * sessionFile = "/usr/share/glib-2.0/schemas/org.ukui.session.gschema.xml";
//ukui-screensaver
2020-02-29 11:44:28 +08:00
const char * screensaverFile = "/usr/share/glib-2.0/schemas/org.ukui.screensaver.gschema.xml";
//屏保功能依赖ukui-session-manager
if ((!g_file_test(screensaverFile, G_FILE_TEST_EXISTS) ||
2020-09-11 14:31:50 +08:00
!g_file_test(sessionFile, G_FILE_TEST_EXISTS)) &&
(fileName == "libscreensaver.so" || fileName == "libscreenlock.so"))
continue;
2021-05-06 20:20:00 +08:00
#ifdef __sw_64__
if ("libpower.so" == fileName) {
continue;
}
#endif
const char * securityCmd = "/usr/sbin/ksc-defender";
2020-06-08 13:33:33 +08:00
if ((!g_file_test(securityCmd, G_FILE_TEST_EXISTS)) && (fileName == "libsecuritycenter.so"))
continue;
2020-01-17 10:20:22 +08:00
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
QObject * plugin = loader.instance();
if (plugin) {
2020-01-17 10:20:22 +08:00
CommonInterface * pluginInstance = qobject_cast<CommonInterface *>(plugin);
modulesList[pluginInstance->get_plugin_type()].insert(pluginInstance->get_plugin_name(), plugin);
2020-02-01 15:25:42 +08:00
qDebug() << "Load Plugin :" << kvConverter->keycodeTokeyi18nstring(pluginInstance->get_plugin_type()) << "->" << pluginInstance->get_plugin_name() ;
2020-01-17 10:20:22 +08:00
2020-08-18 09:03:28 +08:00
m_searchWidget->addModulesName(pluginInstance->name(), pluginInstance->get_plugin_name(), pluginInstance->translationPath());
2020-01-17 10:20:22 +08:00
int moduletypeInt = pluginInstance->get_plugin_type();
if (!moduleIndexList.contains(moduletypeInt))
moduleIndexList.append(moduletypeInt);
} else {
2020-01-17 10:20:22 +08:00
//如果加载错误且文件后缀为so,输出错误
if (fileName.endsWith(".so"))
qDebug() << fileName << "Load Failed: " << loader.errorString() << "\n";
}
}
2020-08-18 09:03:28 +08:00
m_searchWidget->setLanguage(QLocale::system().name());
2020-01-17 10:20:22 +08:00
}
void MainWindow::initLeftsideBar(){
leftBtnGroup = new QButtonGroup();
2020-02-01 13:06:16 +08:00
leftMicBtnGroup = new QButtonGroup();
2020-01-17 10:20:22 +08:00
2021-05-21 14:43:26 +08:00
QHBoxLayout *setLayout = new QHBoxLayout(this);
QLabel *logoSetLabel = new QLabel(this);
QLabel *textSetLable = new QLabel(this);
QWidget *setWidget = new QWidget(this);
ui->leftsidebarVerLayout->setSpacing(5);
ui->leftsidebarVerLayout->setContentsMargins(7,0,9,0);
ui->leftsidebarVerLayout->addWidget(setWidget);
setWidget->setLayout(setLayout);
setLayout->addWidget(logoSetLabel);
setLayout->addWidget(textSetLable);
logoSetLabel->setFixedSize(24,24);
logoSetLabel->setPixmap(QPixmap::fromImage(QIcon::fromTheme("ukui-control-center").pixmap(24,24).toImage()));
textSetLable->setText(tr("Settings"));
textSetLable->setAlignment(Qt::AlignLeft);
2021-05-31 16:08:27 +08:00
ui->leftsidebarVerLayout->addSpacing(8);
2020-01-17 10:20:22 +08:00
//构建左侧边栏返回首页按钮
QPushButton * hBtn = buildLeftsideBtn("homepage",tr("Home"));
2020-02-01 13:06:16 +08:00
hBtn->setObjectName("homepage");
2020-01-17 10:20:22 +08:00
connect(hBtn, &QPushButton::clicked, this, [=]{
ui->stackedWidget->setCurrentIndex(0);
});
2021-05-21 14:43:26 +08:00
hBtn->setStyleSheet("QPushButton#homepage{border-radius: 4px;}");
2020-01-17 10:20:22 +08:00
ui->leftsidebarVerLayout->addWidget(hBtn);
2020-11-03 16:41:56 +08:00
for(int type = 0; type < TOTALMODULES; type++) {
2020-02-29 11:44:28 +08:00
//循环构建左侧边栏一级菜单按钮
2020-01-17 10:20:22 +08:00
if (moduleIndexList.contains(type)){
QString mnameString = kvConverter->keycodeTokeystring(type);
QString mnamei18nString = kvConverter->keycodeTokeyi18nstring(type); //设置TEXT
2020-06-01 19:38:29 +08:00
2020-11-09 03:02:33 -06:00
if (m_ModuleMap.keys().contains(mnameString.toLower())) {
if (!m_ModuleMap[mnameString.toLower()].toBool()) {
continue;
}
}
2020-06-01 19:38:29 +08:00
QPushButton * button;
QString btnName = "btn" + QString::number(type + 1);
button = buildLeftsideBtn(mnameString,mnamei18nString);
button->setToolTip(mnamei18nString);
2020-06-01 19:38:29 +08:00
button->setObjectName(btnName);
2020-01-17 10:20:22 +08:00
button->setCheckable(true);
leftBtnGroup->addButton(button, type);
2020-06-01 19:38:29 +08:00
2021-05-21 14:43:26 +08:00
button->setStyleSheet("QPushButton:hover{background-color: rgba(55,144,250,0.30);border-radius: 4px;}"
"QPushButton:checked{background-color: palette(highlight);border-radius: 4px;}"
"QPushButton:!checked{border: none;}");
2020-01-17 10:20:22 +08:00
connect(button, &QPushButton::clicked, this, [=]{
QPushButton * btn = dynamic_cast<QPushButton *>(QObject::sender());
int selectedInt = leftBtnGroup->id(btn);
2020-02-29 11:44:28 +08:00
//获取一级菜单列表的第一项
2020-01-17 10:20:22 +08:00
QList<FuncInfo> tmpList = FunctionSelect::funcinfoList[selectedInt];
QMap<QString, QObject *> currentFuncMap = modulesList[selectedInt];
for (FuncInfo tmpStruct : tmpList){
2021-01-21 18:49:17 +08:00
if (currentFuncMap.keys().contains(tmpStruct.namei18nString)) {
if (m_ModuleMap.isEmpty() || m_ModuleMap[tmpStruct.nameString.toLower()].toBool()) {
modulepageWidget->switchPage(currentFuncMap.value(tmpStruct.namei18nString));
break;
}
2020-01-17 10:20:22 +08:00
}
}
});
ui->leftsidebarVerLayout->addWidget(button);
}
}
ui->leftsidebarVerLayout->addStretch();
}
2020-11-03 16:41:56 +08:00
QPushButton * MainWindow::buildLeftsideBtn(QString bname,QString tipName) {
2020-02-01 13:06:16 +08:00
QString iname = bname.toLower();
int itype = kvConverter->keystringTokeycode(bname);
2020-01-17 10:20:22 +08:00
QPushButton * leftsidebarBtn = new QPushButton();
leftsidebarBtn->setAttribute(Qt::WA_DeleteOnClose);
2020-02-01 13:06:16 +08:00
leftsidebarBtn->setCheckable(true);
2020-09-11 14:31:50 +08:00
// leftsidebarBtn->setFixedSize(QSize(60, 56)); //Widget Width 60
2021-06-10 21:59:19 +08:00
leftsidebarBtn->setFixedSize(155,40); //一级菜单按钮显示的宽度
2020-01-17 10:20:22 +08:00
2020-02-01 13:06:16 +08:00
QPushButton * iconBtn = new QPushButton(leftsidebarBtn);
iconBtn->setCheckable(true);
iconBtn->setFixedSize(QSize(24, 24));
2020-03-13 21:39:04 +08:00
iconBtn->setFocusPolicy(Qt::NoFocus);
2020-02-01 13:06:16 +08:00
2021-05-22 20:13:24 +08:00
QString iconHomePageBtnQss = QString("QPushButton{border: none;}");
QString iconBtnQss = QString("QPushButton:checked{border: none;}"
"QPushButton:!checked{border: none;}");
QString path = QString("://img/primaryleftmenu/%1.svg").arg(iname);
QPixmap pix = ImageUtil::loadSvg(path, "default");
2020-02-01 13:06:16 +08:00
//单独设置HomePage按钮样式
if (iname == "homepage") {
iconBtn->setFlat(true);
2020-02-01 13:06:16 +08:00
iconBtn->setStyleSheet(iconHomePageBtnQss);
} else {
2020-02-01 13:06:16 +08:00
iconBtn->setStyleSheet(iconBtnQss);
}
iconBtn->setIcon(pix);
2020-02-01 13:06:16 +08:00
2021-05-21 14:43:26 +08:00
QLabel * textLabel = new QLabel(leftsidebarBtn);
textLabel->setFixedWidth(leftsidebarBtn->width()-40);
QFontMetrics fontMetrics(textLabel->font());
int fontSize = fontMetrics.width(tipName);
if (fontSize > textLabel->width()) {
textLabel->setText(fontMetrics.elidedText(tipName, Qt::ElideRight, textLabel->width()));
} else {
textLabel->setText(tipName);
}
const QByteArray styleID(STYLE_FONT_SCHEMA);
QGSettings *stylesettings = new QGSettings(styleID, QByteArray(), this);
connect(stylesettings,&QGSettings::changed,[=](QString key)
{
if("systemFont" == key || "systemFontSize" == key)
{
QFontMetrics fontMetrics_1(textLabel->font());
int fontSize_1 = fontMetrics_1.width(tipName);
if (fontSize_1 > textLabel->width()) {
qDebug()<<textLabel->width();
textLabel->setText(fontMetrics_1.elidedText(tipName, Qt::ElideRight, textLabel->width()));
} else {
textLabel->setText(tipName);
}
}
});
2021-05-21 14:43:26 +08:00
QSizePolicy textLabelPolicy = textLabel->sizePolicy();
textLabelPolicy.setHorizontalPolicy(QSizePolicy::Fixed);
textLabelPolicy.setVerticalPolicy(QSizePolicy::Fixed);
textLabel->setSizePolicy(textLabelPolicy);
textLabel->setScaledContents(true);
2020-02-01 13:06:16 +08:00
leftMicBtnGroup->addButton(iconBtn, itype);
2020-11-03 16:41:56 +08:00
connect(iconBtn, &QPushButton::toggled, this, [=] (bool checked) {
2020-09-11 14:31:50 +08:00
QString path = QString("://img/primaryleftmenu/%1.svg").arg(iname);
QPixmap pix;
if (checked) {
2021-05-21 14:43:26 +08:00
pix = ImageUtil::loadSvg(path, "white");
textLabel->setStyleSheet("color:white");
2020-09-11 14:31:50 +08:00
} else {
pix = ImageUtil::loadSvg(path, "default");
2021-05-21 14:43:26 +08:00
textLabel->setStyleSheet("color:palette(windowText)");
2020-09-11 14:31:50 +08:00
}
iconBtn->setIcon(pix);
});
2020-02-01 13:06:16 +08:00
connect(iconBtn, &QPushButton::clicked, leftsidebarBtn, &QPushButton::click);
2020-11-03 16:41:56 +08:00
connect(leftsidebarBtn, &QPushButton::toggled, this, [=](bool checked) {
2020-02-01 13:06:16 +08:00
iconBtn->setChecked(checked);
QString path = QString("://img/primaryleftmenu/%1.svg").arg(iname);
QPixmap pix;
if (checked) {
2021-05-21 14:43:26 +08:00
pix = ImageUtil::loadSvg(path, "white");
textLabel->setStyleSheet("color:white");
} else {
2021-05-26 15:43:59 +08:00
pix = ImageUtil::loadSvg(path, "default");
2021-05-21 14:43:26 +08:00
textLabel->setStyleSheet("color:palette(windowText)");
}
iconBtn->setIcon(pix);
2020-02-01 13:06:16 +08:00
});
2020-01-17 10:20:22 +08:00
QHBoxLayout * btnHorLayout = new QHBoxLayout();
2021-08-31 18:00:58 +08:00
btnHorLayout->setContentsMargins(8, 0, 0, 0);
2020-02-01 13:06:16 +08:00
btnHorLayout->addWidget(iconBtn, Qt::AlignCenter);
2020-01-17 10:20:22 +08:00
btnHorLayout->addWidget(textLabel);
btnHorLayout->addStretch();
btnHorLayout->setSpacing(10);
leftsidebarBtn->setLayout(btnHorLayout);
return leftsidebarBtn;
}
bool MainWindow::isExitsCloudAccount() {
QProcess *wifiPro = new QProcess();
QString shellOutput = "";
wifiPro->start("dpkg -l | grep kylin-sso-client");
wifiPro->waitForFinished();
QString output = wifiPro->readAll();
shellOutput += output;
QStringList slist = shellOutput.split("\n");
for (QString res : slist) {
if (res.contains("kylin-sso-client")) {
return true;
}
}
return false;
}
2021-08-12 20:25:13 +08:00
bool MainWindow::isExitsPower()
{
2021-08-13 16:28:17 +08:00
QProcess *process = new QProcess;
process->start("dpkg -l ukui-power-manager");
process->waitForFinished();
QByteArray ba = process->readAllStandardOutput();
delete process;
QString mOutput = QString(ba.data());
return mOutput.contains("ii", Qt::CaseSensitive) ? true : false;
2021-08-12 20:25:13 +08:00
}
2020-11-03 16:41:56 +08:00
bool MainWindow::dblOnEdge(QMouseEvent *event) {
2020-07-16 15:51:09 +08:00
QPoint pos = event->globalPos();
int globalMouseY = pos.y();
int frameY = this->y();
bool onTopEdges = (globalMouseY >= frameY &&
2020-09-11 14:31:50 +08:00
globalMouseY <= frameY + dbWitdth);
2020-07-16 15:51:09 +08:00
return onTopEdges;
}
2020-08-18 09:03:28 +08:00
void MainWindow::initStyleSheet() {
// 设置panel图标
QIcon panelicon;
if (QIcon::hasThemeIcon("ukui-control-center"))
panelicon = QIcon::fromTheme("ukui-control-center");
2021-05-12 17:15:13 +08:00
qApp->setWindowIcon(panelicon);
2021-03-18 16:04:20 +08:00
this->setWindowTitle(tr("Settings"));
2020-08-18 09:03:28 +08:00
// 中部内容区域
2020-11-25 12:51:54 +08:00
ui->stackedWidget->setStyleSheet("QStackedWidget#stackedWidget{background: palette(base); border-bottom-left-radius: 6px; border-bottom-right-radius: 6px;}");
2020-08-18 09:03:28 +08:00
// 左上角返回按钮
backBtn->setProperty("useIconHighlightEffect", true);
backBtn->setProperty("iconHighlightEffectMode", 1);
backBtn->setFlat(true);
2021-01-07 10:16:32 +08:00
mOptionBtn->setProperty("useIconHighlightEffect", 0x2);
mOptionBtn->setProperty("isWindowButton", 0x01);
2021-06-24 14:57:25 +08:00
2021-01-07 10:16:32 +08:00
2020-11-18 17:19:16 +08:00
minBtn->setProperty("useIconHighlightEffect", 0x2);
minBtn->setProperty("isWindowButton", 0x01);
2020-08-18 09:03:28 +08:00
minBtn->setFlat(true);
2021-01-07 10:16:32 +08:00
2020-11-18 17:19:16 +08:00
maxBtn->setProperty("useIconHighlightEffect", 0x2);
maxBtn->setProperty("isWindowButton", 0x1);
2020-08-18 09:03:28 +08:00
maxBtn->setFlat(true);
2020-11-18 17:19:16 +08:00
closeBtn->setProperty("isWindowButton", 0x02);
closeBtn->setProperty("useIconHighlightEffect", 0x08);
closeBtn->setFlat(true);
2021-04-27 10:37:50 +08:00
ui->leftsidebarWidget->setMinimumWidth(153);
2020-08-18 09:03:28 +08:00
2021-05-21 14:43:26 +08:00
ui->centralWidget->setAttribute(Qt::WA_TranslucentBackground);
2021-06-10 21:59:19 +08:00
ui->leftsidebarWidget->setMinimumWidth(176); //一级菜单宽度
2021-05-21 14:43:26 +08:00
2021-06-08 15:00:16 +08:00
2021-05-21 14:43:26 +08:00
2020-08-18 09:03:28 +08:00
// 设置左上角按钮图标
backBtn->setIcon(QIcon("://img/titlebar/back.svg"));
// 设置右上角按钮图标
2021-01-07 10:16:32 +08:00
mOptionBtn->setIcon(QIcon::fromTheme("open-menu-symbolic"));
2020-08-18 09:03:28 +08:00
minBtn->setIcon(QIcon::fromTheme("window-minimize-symbolic"));
maxBtn->setIcon(QIcon::fromTheme("window-maximize-symbolic"));
2020-11-18 17:19:16 +08:00
closeBtn->setIcon(QIcon::fromTheme("window-close-symbolic"));
2020-08-18 09:03:28 +08:00
}
bool MainWindow::isExitBluetooth() {
QProcess process;
process.start("rfkill list");
process.waitForFinished();
QByteArray output = process.readAllStandardOutput();
QString str_output = output;
2021-01-18 15:29:06 +08:00
bool isDevice = str_output.contains(QString("bluetooth"), Qt::CaseInsensitive);
bool isAddress = true;
QByteArray bluetoothId("org.ukui.bluetooth");
if (QGSettings::isSchemaInstalled(bluetoothId)) {
QGSettings bluetoothGSetting(bluetoothId);
isAddress = bluetoothGSetting.get("adapter-address").toString().isEmpty() ? false : true;
} else
isAddress = false;
2021-01-18 15:29:06 +08:00
return isDevice && isAddress;
}
void MainWindow::changeSearchSlot() {
int fontSize = m_fontSetting->get("system-font-size").toInt();
m_searchWidget->setFixedHeight((fontSize - 11) * 2 + 32);
}
2021-11-29 14:10:08 +08:00
void MainWindow::initNMIcbc()
{
QDBusInterface nmIfc("com.kylin.network",
"/com/kylin/network",
"com.kylin.network",
QDBusConnection::sessionBus());
QDBusMessage msg = nmIfc.call("requestRefreshWifiList");
mIsNmIcbc = !msg.errorMessage().isEmpty();
2021-11-29 14:10:08 +08:00
}
2020-08-18 09:03:28 +08:00
void MainWindow::setModuleBtnHightLight(int id) {
2020-01-17 10:20:22 +08:00
leftBtnGroup->button(id)->setChecked(true);
2020-02-01 13:06:16 +08:00
leftMicBtnGroup->button(id)->setChecked(true);
2020-01-17 10:20:22 +08:00
}
2020-11-03 16:41:56 +08:00
QMap<QString, QObject *> MainWindow::exportModule(int type) {
2020-01-17 10:20:22 +08:00
QMap<QString, QObject *> emptyMaps;
if (type < modulesList.length())
return modulesList[type];
else
return emptyMaps;
}
2020-11-03 16:41:56 +08:00
void MainWindow::functionBtnClicked(QObject *plugin) {
2020-01-17 10:20:22 +08:00
ui->stackedWidget->setCurrentIndex(1);
modulepageWidget->switchPage(plugin);
}
void MainWindow::sltMessageReceived(const QString &msg) {
2021-08-05 18:43:01 +08:00
// if (!this->isActiveWindow()) {
// this->hide();
// this->show();
// showNormal();
// }
KWindowSystem::forceActiveWindow(this->winId());
this->show();
bootOptionsFilter(msg);
//Qt::WindowFlags flags = windowFlags();
//flags |= Qt::WindowStaysOnTopHint;
//setWindowFlags(flags);
//flags &= ~Qt::WindowStaysOnTopHint;
//setWindowFlags(flags);
}
2021-01-21 11:09:06 +08:00
void MainWindow::switchPage(QString moduleName, QString jumpMoudle) {
2020-08-18 09:03:28 +08:00
for (int i = 0; i < modulesList.length(); i++) {
auto modules = modulesList.at(i);
//开始跳转
if (modules.keys().contains(moduleName)) {
2021-01-21 11:09:06 +08:00
if (m_ModuleMap.isEmpty() || m_ModuleMap[jumpMoudle.toLower()].toBool()) {
ui->stackedWidget->setCurrentIndex(1);
modulepageWidget->switchPage(modules.value(moduleName));
return ;
}
2020-08-18 09:03:28 +08:00
}
}
2021-06-28 19:50:08 +08:00
QMessageBox::information(this, tr("Warning"), tr("This function has been controlled"));
2021-01-21 11:09:06 +08:00
return;
2020-08-18 09:03:28 +08:00
}
2021-05-20 15:33:35 +08:00
void MainWindow::moveEvent(QMoveEvent *event)
{
Q_UNUSED(event);
Q_EMIT posChanged();
}
void MainWindow::resizeEvent(QResizeEvent *event)
{
QMainWindow::resizeEvent(event);
Q_EMIT posChanged();
}