diff --git a/CMakeLists.txt b/CMakeLists.txt index 601f64d..e5f8a94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ if (NOT DEFINED UPDATE_TRANSLATIONS) set(UPDATE_TRANSLATIONS "No") endif() -# To create a new ts file: lupdate -recursive . -target-language en_US -ts translations/en_US.ts +# To create a new ts file: lupdate -recursive . -target-language en_US -ts translations/en_US.ts -no-ui-lines file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/translations/*.ts") # cmake -DUPDATE_TRANSLATIONS=yes diff --git a/data/images/hibernate.png b/data/images/hibernate.png deleted file mode 100644 index a6338b1..0000000 Binary files a/data/images/hibernate.png and /dev/null differ diff --git a/data/images/hibernate.svg b/data/images/hibernate.svg index 1693a24..6cfad35 100644 --- a/data/images/hibernate.svg +++ b/data/images/hibernate.svg @@ -1 +1 @@ -画板 6 \ No newline at end of file + \ No newline at end of file diff --git a/data/images/lockscreen.png b/data/images/lockscreen.png deleted file mode 100644 index 7985bba..0000000 Binary files a/data/images/lockscreen.png and /dev/null differ diff --git a/data/images/lockscreen.svg b/data/images/lockscreen.svg index 7c0ab9a..1f910ee 100644 --- a/data/images/lockscreen.svg +++ b/data/images/lockscreen.svg @@ -1 +1 @@ -画板 5 \ No newline at end of file + \ No newline at end of file diff --git a/data/images/logout.png b/data/images/logout.png deleted file mode 100644 index cec5de0..0000000 Binary files a/data/images/logout.png and /dev/null differ diff --git a/data/images/logout.svg b/data/images/logout.svg index 156f396..9659657 100644 --- a/data/images/logout.svg +++ b/data/images/logout.svg @@ -1 +1 @@ -画板 1 \ No newline at end of file + \ No newline at end of file diff --git a/data/images/reboot.png b/data/images/reboot.png deleted file mode 100644 index a78262e..0000000 Binary files a/data/images/reboot.png and /dev/null differ diff --git a/data/images/reboot.svg b/data/images/reboot.svg index d5dcb5d..4f55d46 100644 --- a/data/images/reboot.svg +++ b/data/images/reboot.svg @@ -1 +1 @@ -画板 3 \ No newline at end of file + \ No newline at end of file diff --git a/data/images/shutdown.png b/data/images/shutdown.png deleted file mode 100644 index 4b07a8b..0000000 Binary files a/data/images/shutdown.png and /dev/null differ diff --git a/data/images/shutdown.svg b/data/images/shutdown.svg index 8b8e659..d46725a 100644 --- a/data/images/shutdown.svg +++ b/data/images/shutdown.svg @@ -1 +1 @@ -画板 2 \ No newline at end of file + \ No newline at end of file diff --git a/data/images/suspend.png b/data/images/suspend.png deleted file mode 100644 index 63f2a32..0000000 Binary files a/data/images/suspend.png and /dev/null differ diff --git a/data/images/suspend.svg b/data/images/suspend.svg index 0f2bbac..a83bdfa 100644 --- a/data/images/suspend.svg +++ b/data/images/suspend.svg @@ -1,10 +1 @@ - - - - - + \ No newline at end of file diff --git a/data/images/switchuser.png b/data/images/switchuser.png deleted file mode 100644 index 7c40256..0000000 Binary files a/data/images/switchuser.png and /dev/null differ diff --git a/data/images/switchuser.svg b/data/images/switchuser.svg index 5d5f797..2d6bfae 100644 --- a/data/images/switchuser.svg +++ b/data/images/switchuser.svg @@ -1 +1 @@ -画板 4 \ No newline at end of file + \ No newline at end of file diff --git a/tools/mainwindow.cpp b/tools/mainwindow.cpp index 8846ea0..9bdf665 100644 --- a/tools/mainwindow.cpp +++ b/tools/mainwindow.cpp @@ -185,16 +185,15 @@ MainWindow::MainWindow(bool a, bool b, QWidget *parent) : QMainWindow(parent) inhibitShutdown = true; } - user = getenv("USER"); lockfile = a; lockuser = b; initialMessageWidget(); - int hideNum = 3; + int hideNum = 7; //Make a hash-map to store tableNum-to-lastWidget - if (m_power->canAction(UkuiPower::PowerHibernate)) {//m_power->canAction(UkuiPower::PowerHibernate) + if (m_power->canAction(UkuiPower::PowerHibernate)) { isHibernateHide = false; hideNum--; } @@ -204,7 +203,22 @@ MainWindow::MainWindow(bool a, bool b, QWidget *parent) : QMainWindow(parent) hideNum--; } - if (LockChecker::getCachedUsers() > 1) { + if (m_power->canAction(UkuiPower::PowerLogout)) { + isLogoutHide = false; + hideNum--; + } + + if (m_power->canAction(UkuiPower::PowerReboot)) { + isRebootHide = false; + hideNum--; + } + + if (m_power->canAction(UkuiPower::PowerShutdown)) { + isPowerOffHide = false; + hideNum--; + } + + if (LockChecker::getCachedUsers() > 1 && m_power->canAction(UkuiPower::PowerSwitchUser)) { isSwitchuserHide = false; hideNum--; } @@ -227,23 +241,40 @@ MainWindow::MainWindow(bool a, bool b, QWidget *parent) : QMainWindow(parent) ResizeEvent(); + //使按钮控件上下比例均衡 + QVBoxLayout *spaceLayout = new QVBoxLayout(); + QLabel spaceLabel1; + QLabel spaceLabel2; + spaceLabel1.setFont(QFont("Noto Sans CJK SC", 28, 50)); + spaceLabel2.setFont(QFont("Noto Sans CJK SC", 12, 50)); + spaceLabel1.setStyleSheet("color: white; font: 28pt"); + spaceLabel2.setStyleSheet("color: white; font: 12pt"); + spaceLabel1.setAlignment(Qt::AlignHCenter | Qt::AlignTop); + spaceLabel2.setAlignment(Qt::AlignHCenter | Qt::AlignBottom); + spaceLabel1.setObjectName("date_label"); + spaceLabel2.setObjectName("time_lable"); + spaceLayout->addStretch(); + spaceLayout->addWidget(&spaceLabel1); + spaceLayout->addSpacing(10); + spaceLayout->addWidget(&spaceLabel2); + setLayoutWidgetVisible(spaceLayout, false); + m_vBoxLayout->addStretch(20); - m_vBoxLayout->addLayout(m_dateTimeLayout, 60); - m_vBoxLayout->addStretch(); - m_vBoxLayout->addLayout(m_judgeWidgetVLayout, 140); - m_vBoxLayout->addWidget(m_scrollArea,632); - m_vBoxLayout->addStretch(174); - m_vBoxLayout->addLayout(m_messageVLayout, 80); - //m_vBoxLayout->addWidget(m_systemMonitorBtn,48,Qt::AlignHCenter); - m_vBoxLayout->addStretch(58); - //m_vBoxLayout->setContentsMargins(0,0,0,0); + m_vBoxLayout->addLayout(m_dateTimeLayout, 80); + m_vBoxLayout->addLayout(m_judgeWidgetVLayout, 120); + m_vBoxLayout->addWidget(m_scrollArea, 640); + m_vBoxLayout->addLayout(m_messageVLayout, 120); + m_vBoxLayout->addLayout(spaceLayout, 80); + m_vBoxLayout->addStretch(20); + m_vBoxLayout->setSpacing(0); + m_vBoxLayout->setContentsMargins((m_screen.width() - m_scrollArea->width() - 20)/2,0,(m_screen.width() - m_scrollArea->width() - 20)/2,0); qDebug() << "width..........." << m_judgeLabel->width() << m_scrollArea->width() << m_messageLabel1->width() << m_messageLabel2->width(); //根据屏幕分辨率与鼠标位置重设界面 //m_screen = QApplication::desktop()->screenGeometry(QCursor::pos()); - setFixedSize(QApplication::primaryScreen()->virtualSize()); - + //setFixedSize(QApplication::primaryScreen()->virtualSize()); + setGeometry(0, 0, QApplication::primaryScreen()->virtualSize().width(), QApplication::primaryScreen()->virtualSize().height()); move(0, 0);//设置初始位置的值 //设置窗体无边框,不可拖动拖拽拉伸;为顶层窗口,无法被切屏;不使用窗口管理器 @@ -373,13 +404,13 @@ void MainWindow::initialSystemMonitor() void MainWindow::initialBtn() { - m_switchUserBtn = new MyPushButton(m_btnImagesPath+"/switchuser.svg", QApplication::tr("Switch User"), "switchuser", m_scrollArea, !m_IsRoundBtn); - m_hibernateBtn = new MyPushButton(m_btnImagesPath+"/hibernate.svg", QApplication::tr("Hibernate"), "hibernate", m_scrollArea, !m_IsRoundBtn); - m_suspendBtn = new MyPushButton(m_btnImagesPath+"/suspend.svg", QApplication::tr("Suspend"), "suspend", m_scrollArea, !m_IsRoundBtn); - m_logoutBtn = new MyPushButton(m_btnImagesPath+"/logout.svg", QApplication::tr("Logout"), "logout", m_scrollArea, !m_IsRoundBtn); - m_rebootBtn = new MyPushButton(m_btnImagesPath+"/reboot.svg", QApplication::tr("Reboot"), "reboot", m_scrollArea, !m_IsRoundBtn); - m_shutDownBtn = new MyPushButton(m_btnImagesPath+"/shutdown.svg", QApplication::tr("Shut Down"), "shutdown", m_scrollArea, !m_IsRoundBtn); - m_lockScreenBtn = new MyPushButton(m_btnImagesPath+"/lockscreen.svg", QApplication::tr("Lock Screen"), "lockscreen", m_scrollArea, !m_IsRoundBtn); + m_switchUserBtn = new MyPushButton(m_btnImagesPath+"/switchuser.svg", QApplication::tr("Switch User"), "switchuser", m_scrollArea); + m_hibernateBtn = new MyPushButton(m_btnImagesPath+"/hibernate.svg", QApplication::tr("Hibernate"), "hibernate", m_scrollArea); + m_suspendBtn = new MyPushButton(m_btnImagesPath+"/suspend.svg", QApplication::tr("Suspend"), "suspend", m_scrollArea); + m_logoutBtn = new MyPushButton(m_btnImagesPath+"/logout.svg", QApplication::tr("Logout"), "logout", m_scrollArea); + m_rebootBtn = new MyPushButton(m_btnImagesPath+"/reboot.svg", QApplication::tr("Reboot"), "reboot", m_scrollArea); + m_shutDownBtn = new MyPushButton(m_btnImagesPath+"/shutdown.svg", QApplication::tr("Shut Down"), "shutdown", m_scrollArea); + m_lockScreenBtn = new MyPushButton(m_btnImagesPath+"/lockscreen.svg", QApplication::tr("Lock Screen"), "lockscreen", m_scrollArea); //ui->setupUi(this); m_switchUserBtn->installEventFilter(this); @@ -400,12 +431,6 @@ void MainWindow::initialBtn() void MainWindow::initialJudgeWidget() { - int margins = 0; - if (m_screen.width() > 1088) { - margins = (m_screen.width() - 60 * 6 - 140 * 7) / 2; - } else { - margins = (m_screen.width() - 60 * 2 - 140 * 3) / 2; - } // QStringList userlist = getLoginedUsers(); QStringList userlist = LockChecker::getLoginedUsers(); if (userlist.count() > 1) { @@ -416,11 +441,11 @@ void MainWindow::initialJudgeWidget() m_judgeLabel->setText(tips); m_judgeLabel->setStyleSheet("color:white;font:12pt;"); m_judgeLabel->setObjectName("label"); - m_judgeLabel->setGeometry(0,0,m_screen.width() - 2 * margins,50); + //m_judgeLabel->setGeometry(0,0,m_screen.width(),50); //m_judgeLabel->setFixedHeight(60); qDebug() << "m_judgeLabel width:" << m_judgeLabel->width() << m_judgeLabel->height(); - m_judgeLabel->setAlignment(Qt::AlignHCenter| Qt::AlignBottom); + m_judgeLabel->setAlignment(Qt::AlignCenter); m_judgeLabel->setWordWrap(true); m_cancelBtn = new QPushButton(QApplication::tr("cancel")); @@ -438,7 +463,7 @@ void MainWindow::initialJudgeWidget() m_judgeWidgetVLayout->addStretch(); m_judgeWidgetVLayout->addWidget(m_judgeLabel); - m_judgeWidgetVLayout->addSpacing(0); + m_judgeWidgetVLayout->addSpacing(10); m_judgeWidgetVLayout->addLayout(m_judgeBtnHLayout); m_judgeWidgetVLayout->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); @@ -458,8 +483,8 @@ void MainWindow::initialMessageWidget() margins = (m_screen.width() - 60 * 2 - 140 * 3) / 2; } - m_messageLabel1->setGeometry(QRect(0, 0, 700, 40)); - m_messageLabel2->setGeometry(QRect(0, 0, 700, 40)); + m_messageLabel1->setGeometry(0, 0, m_screen.width() - 160, 40); + m_messageLabel2->setGeometry(0, 0, m_screen.width() - 160, 40); m_messageLabel1->setStyleSheet("color:white;font:12pt;"); m_messageLabel2->setStyleSheet("color:white;font:12pt;"); m_messageLabel1->setObjectName("messagelabel1"); @@ -468,16 +493,19 @@ void MainWindow::initialMessageWidget() // m_messageLabel2->setFixedWidth(m_screen.width() - 20); m_messageLabel1->setWordWrap(true); m_messageLabel2->setWordWrap(true); - m_messageLabel2->setAlignment(Qt::AlignCenter); - m_messageLabel1->setAlignment(Qt::AlignCenter); + m_messageLabel2->setAlignment(Qt::AlignHCenter); + m_messageLabel1->setAlignment(Qt::AlignHCenter); m_messageLabel1->setMargin(0); m_messageLabel2->setMargin(0); + m_messageLabel1->setWordWrap(true); + m_messageLabel2->setWordWrap(true); + m_messageVLayout->addStretch(); m_messageVLayout->addWidget(m_messageLabel1); m_messageVLayout->addSpacing(10); m_messageVLayout->addWidget(m_messageLabel2); //m_messageVLayout->setAlignment(Qt::AlignHCenter); - m_messageVLayout->setContentsMargins(0,0,0,0); + //m_messageVLayout->setContentsMargins(0,0,0,0); if (lockfile) { QFile file_update("/tmp/lock/kylin-update.lock"); @@ -564,10 +592,12 @@ void MainWindow::initialDateTimeWidget() m_dateLabel->setObjectName("date_label"); m_timeLabel->setObjectName("time_lable"); + m_dateTimeLayout->addStretch(); m_dateTimeLayout->addWidget(m_timeLabel); - m_dateTimeLayout->setStretch(0,1); + m_messageVLayout->addSpacing(10); + //m_dateTimeLayout->setStretch(0,1); m_dateTimeLayout->addWidget(m_dateLabel); - m_dateTimeLayout->setStretch(1,2); + //m_dateTimeLayout->setStretch(1,2); } void MainWindow::initialBtnCfg() @@ -606,15 +636,18 @@ void MainWindow::initialBtnCfg() m_btnCfgSetting->setValue("btn/SwitchUserBtnHide", isSwitchuserHide); m_btnCfgSetting->setValue("btn/HibernateBtnHide", isHibernateHide); m_btnCfgSetting->setValue("btn/SuspendBtnHide", isSuspendHide); + m_btnCfgSetting->setValue("btn/LogoutBtnHide", isLogoutHide); + m_btnCfgSetting->setValue("btn/RebootBtnHide", isRebootHide); + m_btnCfgSetting->setValue("btn/ShutDownBtnHide", isPowerOffHide); qDebug() << "isHibernateHide..." << isHibernateHide; m_btnHideMap.insert(m_switchUserBtn, isSwitchuserHide); m_btnHideMap.insert(m_hibernateBtn, isHibernateHide); m_btnHideMap.insert(m_suspendBtn, isSuspendHide); m_btnHideMap.insert(m_lockScreenBtn, m_btnCfgSetting->value("btn/LockScreenBtnHide").toBool()); - m_btnHideMap.insert(m_logoutBtn, m_btnCfgSetting->value("btn/LogoutBtnHide").toBool()); - m_btnHideMap.insert(m_rebootBtn, m_btnCfgSetting->value("btn/RebootBtnHide").toBool()); - m_btnHideMap.insert(m_shutDownBtn, m_btnCfgSetting->value("btn/ShutDownBtnHide").toBool()); + m_btnHideMap.insert(m_logoutBtn, isLogoutHide); + m_btnHideMap.insert(m_rebootBtn, isRebootHide); + m_btnHideMap.insert(m_shutDownBtn, isPowerOffHide); } void MainWindow::setLayoutWidgetVisible(QLayout* layout, bool show) @@ -656,7 +689,7 @@ void MainWindow::mouseReleaseSlots(QEvent *event, QString objName) { for (auto iter = map.begin(); iter != map.end(); iter++) { if (iter.value()->getIconLabel()->objectName() == objName) { - changePoint(iter.value(), event, iter.key()); + changePoint(iter.value(), event); if (event->type() == QEvent::MouseButtonRelease) { qDebug() << "mouseReleaseSlots..." << objName; doEvent(objName, iter.key()); @@ -669,11 +702,12 @@ void MainWindow::mouseReleaseSlots(QEvent *event, QString objName) void MainWindow::screenCountChanged() { QDesktopWidget *desktop = QApplication::desktop(); - qDebug() << "inside screenCountChanged,screenCount = " << desktop->screenCount(); + qDebug() << "inside screenCountChanged,screenCount = " << desktop->screenCount() << QApplication::desktop()->screenGeometry(QCursor::pos()).width() << QApplication::desktop()->screenGeometry(QCursor::pos()).height(); //setGeometry(desktop->geometry()); //updateGeometry(); //move(0,0); - setFixedSize(QApplication::primaryScreen()->virtualSize()); + //setFixedSize(QApplication::primaryScreen()->virtualSize()); + setGeometry(0, 0, QApplication::primaryScreen()->virtualSize().width(), QApplication::primaryScreen()->virtualSize().height()); ResizeEvent(); update(); } @@ -701,7 +735,7 @@ void MainWindow::showNormalBtnWidget(int hideNum) int margins = 0; margins = (m_screen.width() -160 - 128 * (7 - hideNum))/(6-hideNum); - qDebug() << "margins:" << margins; + qDebug() << "showNormalBtnWidget hideNum:" << hideNum << "margins:" << margins; int btnWidgetWidth = 0; if(margins > 60) { @@ -714,16 +748,16 @@ void MainWindow::showNormalBtnWidget(int hideNum) btnWidgetWidth = 128 * (7 - hideNum) + margins * (6 - hideNum); m_buttonHLayout->setHorizontalSpacing(margins); } - m_btnWidget->setGeometry(QRect(0,0,btnWidgetWidth+ 24, 632)); - m_btnWidget->setContentsMargins(0,0,0,0); + m_btnWidget->setGeometry(QRect(0,0,btnWidgetWidth+ 24, 632 * m_screen.height()/1080)); + m_btnWidget->setContentsMargins(0,0,0,100 * m_screen.height()/1080); - m_scrollArea->setGeometry(QRect(0,0,btnWidgetWidth + 24, 632)); + m_scrollArea->setGeometry(QRect(0,0,btnWidgetWidth + 24, 632 * m_screen.height()/1080)); m_scrollArea->setContentsMargins(0,0,0,0); m_scrollArea->verticalScrollBar()->setVisible(false); m_scrollArea->verticalScrollBar()->setDisabled(true); - m_buttonHLayout->setContentsMargins(0,0,0,160); + //m_buttonHLayout->setContentsMargins(0,0,0,(m_scrollArea->height() - m_switchUserBtn->height()) * 3/5); for (int i = 0;i < m_buttonHLayout->count(); i++) { QLayoutItem*item = m_buttonHLayout->layout()->itemAt(i); @@ -751,7 +785,7 @@ void MainWindow::showHasScrollBarBtnWidget(int hideNum) int needHeight = (m_lineNum * 171 + (m_lineNum - 1) * 32); int btnWidgetHeight = 632; - qDebug() << "lineWidth:" << lineWidth << "lineMaxBtnNum:" << lineMaxBtnNum << "needHeight:" << needHeight << "lineNum:" << m_lineNum<< allBtnNum/lineMaxBtnNum << allBtnNum%lineMaxBtnNum; + qDebug() << "showHasScrollBarBtnWidget lineWidth:" << lineWidth << "lineMaxBtnNum:" << lineMaxBtnNum << "needHeight:" << needHeight << "lineNum:" << m_lineNum<< allBtnNum/lineMaxBtnNum << allBtnNum%lineMaxBtnNum; calculateBtnSpan(allBtnNum, lineMaxBtnNum, m_switchUserBtn, m_switchRow, m_switchColumn); calculateBtnSpan(allBtnNum, lineMaxBtnNum, m_hibernateBtn, m_hibernateRow, m_hibernateColumn); @@ -782,11 +816,11 @@ void MainWindow::showHasScrollBarBtnWidget(int hideNum) qDebug() << "set bar pos..."; //m_scrollArea->verticalScrollBar()->setGeometry(QRect(lineWidth + 20, 0, 6, 100)); m_scrollArea->setContentsMargins(0,0,0,0); - m_scrollArea->setGeometry(QRect(0,0,128 * lineMaxBtnNum + 60 * (lineMaxBtnNum-1) +6,btnWidgetHeight)); + m_scrollArea->setGeometry(QRect(0,0,128 * lineMaxBtnNum + 60 * (lineMaxBtnNum-1) + 6, btnWidgetHeight * m_screen.height()/1080)); m_buttonHLayout->setContentsMargins(0,0,0,0);// (needHeight > 632 ? 0 : (632 - needHeight)) * m_screen.height()/1080); - m_btnWidget->setGeometry(QRect(0,0,128 * lineMaxBtnNum + 60 * (lineMaxBtnNum-1),needHeight)); + m_btnWidget->setGeometry(QRect(0,0,128 * lineMaxBtnNum + 60 * (lineMaxBtnNum-1), needHeight)); m_btnWidget->setContentsMargins(6,0,12,0); qDebug() << "m_btnWidget FixedHeight:" << needHeight << btnWidgetHeight << m_btnWidget->width() << m_scrollArea->width(); qDebug() << "isSwitchuserHide:" << isSwitchuserHide << "isHibernateHide:" << isHibernateHide << "isSuspendHide:" << isSuspendHide; @@ -813,6 +847,7 @@ void MainWindow::showHasScrollBarBtnWidget(int hideNum) void MainWindow::ResizeEvent() { m_screen = QApplication::desktop()->screenGeometry(QCursor::pos()); + setGeometry(0, 0, QApplication::primaryScreen()->virtualSize().width(), QApplication::primaryScreen()->virtualSize().height()); if(m_showWarningMesg) { @@ -830,16 +865,15 @@ void MainWindow::ResizeEvent() } // Move the widget to the direction where they should be - int recWidth; - if (m_IsRoundBtn) { - recWidth = 128; - } else { - recWidth = 140; - } for (int i = 0; i <= 6; i++) { - if (m_btnHideMap.value(map.value(i))) { + if (m_btnHideMap.value(map.value(i))) + { map[i]->hide(); } + else + { + map[i]->show(); + } } if((m_screen.width() -160 - 128 * (7 - hideNum))/(6-hideNum) >= 16) { @@ -851,11 +885,18 @@ void MainWindow::ResizeEvent() } m_btnWidget->setStyleSheet("QWidget#btnWidget{background-color: transparent;}"); m_btnWidget->setLayout(m_buttonHLayout); + m_scrollArea->horizontalScrollBar()->setVisible(false); m_scrollArea->horizontalScrollBar()->setDisabled(true); m_scrollArea->setWidget(m_btnWidget); m_scrollArea->setStyleSheet("QScrollArea#scrollArea{background-color: transparent;}"); m_scrollArea->setAlignment(Qt::AlignHCenter); + qDebug() << "m_scrollArea geometry:" << m_scrollArea->geometry(); + qDebug() << "m_btnWidget geometry:" << m_btnWidget->geometry(); + qDebug() << "m_buttonHLayout geometry:" << m_buttonHLayout->geometry(); + + m_vBoxLayout->setContentsMargins((m_screen.width() - m_scrollArea->width() - 20)/2,0,(m_screen.width() - m_scrollArea->width() - 20)/2,0); + //m_scrollArea->adjustSize(); //m_scrollArea->setWidgetResizable(true); m_toolWidget->setGeometry(m_screen); @@ -942,7 +983,7 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event) return QWidget::eventFilter(obj, event); } -void MainWindow::changePoint(QWidget *widget, QEvent *event, int i) +void MainWindow::changePoint(QWidget *widget, QEvent *event) { if (event->type() == QEvent::Enter) { changeBtnState(widget->objectName()); @@ -1310,6 +1351,7 @@ void MainWindow::drawWarningWindow(QRect &rect) vBoxLayout->addWidget(tips); vBoxLayout->addWidget(applist, 0, Qt::AlignHCenter); + vBoxLayout->addSpacing(isEnoughBig ? 32 : 0); vBoxLayout->addLayout(hBoxLayout, Qt::AlignHCenter); //移动整个区域到指定的相对位置 @@ -1362,8 +1404,6 @@ void MainWindow::judgeboxShow() } m_scrollArea->verticalScrollBar()->setVisible(false); - int xx = m_screen.x(); - int yy = m_screen.y(); //取得当前鼠标所在屏幕的最左,上坐标 setLayoutWidgetVisible(m_dateTimeLayout, false); setLayoutWidgetVisible(m_judgeWidgetVLayout, true); setLayoutWidgetVisible(m_judgeBtnHLayout, true); diff --git a/tools/mainwindow.h b/tools/mainwindow.h index 8f886d5..e0b4e37 100644 --- a/tools/mainwindow.h +++ b/tools/mainwindow.h @@ -47,10 +47,33 @@ public: MainWindow(bool a , bool b ,QWidget *parent = nullptr); ~MainWindow(); + /** + * @brief 响应按钮事件 + * @param test2 按钮名字 + * @param i 按钮序号 + */ void doEvent(QString test2,int i); - void changePoint(QWidget *widget ,QEvent *event ,int i); + + /** + * @brief 响应鼠标事件后改变按钮状态 + * @param widget 指定按钮对象 + * @param widget 鼠标事件 + */ + void changePoint(QWidget *widget ,QEvent *event); + + /** + * @brief 调整界面显示的控件 + */ void judgeboxShow(); + + /** + * @brief 模拟按键 + */ void keyPressEmulate(); + + /** + * @brief 消息过滤 + */ virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override; //void closeEvent(QCloseEvent *event); @@ -97,30 +120,106 @@ public: void changeBtnState(QString btnName, bool isEnterKey = false); private: - QString getAppLocalName(QString desktopfp);//获取应用名 - void ResizeEvent(); - void showInhibitWarning();//当有inhibitor存在时显示提醒界面 - void drawWarningWindow(QRect &rect);//画出提醒界面 - QMap findNameAndIcon(QString &basename);//根据inhibitor的名称获取对应desktop文件中的应用名和icon路径 + /** + * @brief 获取应用名 + */ + QString getAppLocalName(QString desktopfp); - void calculateBtnSpan(int allNum, int lineMaxNum, MyPushButton*, int& row, int& colum); + /** + * @brief 重新计算界面大小及控件位置布局 + */ + void ResizeEvent(); + + /** + * @brief 当有inhibitor存在时显示提醒界面 + */ + void showInhibitWarning(); + + /** + * @brief 画出提醒界面 + */ + void drawWarningWindow(QRect &rect); + + /** + * @brief 根据inhibitor的名称获取对应desktop文件中的应用名和icon路径 + */ + QMap findNameAndIcon(QString &basename); + + /** + * @brief 根据inhibitor的名称获取对应desktop文件中的应用名和icon路径 + * @param allNum 共显示的按钮数 + * @param lineMaxNum 一行最多显示的按钮数 + * @param btn 指定按钮 + */ + void calculateBtnSpan(int allNum, int lineMaxNum, MyPushButton* btn, int& row, int& colum); + + /** + * @brief 计算键盘左右键对应的按钮 + * @param key 按键名字 + */ void calculateKeyBtn(const QString &key); + + /** + * @brief 按钮是否可用 + * @param index 按钮序号 + */ bool judgeBtnIsEnable(int index); + + /** + * @brief 打开监视器 + */ //void doSystemMonitor(); + /** + * @brief 显示常规的按钮界面 + * @param hideBtnNum 隐藏的按钮数 + */ void showNormalBtnWidget(int hideBtnNum); + + /** + * @brief 显示需要换行的按钮界面 + * @param hideBtnNum 隐藏的按钮数 + */ void showHasScrollBarBtnWidget(int hideBtnNum); void doLockscreen();//锁屏操作 Q_SIGNALS: + /** + * @brief 按钮点击后的事件信号 + */ void signalTostart(); + + /** + * @brief 点击提示界面的确认按钮信号 + */ void confirmButtonclicked(); private Q_SLOTS: + /** + * @brief 退出 + */ bool exitt(); + + /** + * @brief 按键按下事件 + * @param key 键名 + */ void onGlobalKeyPress(const QString &key); + + /** + * @brief 按键弹起事件 + * @param key 键名 + */ void onGlobalkeyRelease(const QString &key); + + /** + * @brief 屏幕变化 + */ void screenCountChanged(); + + /** + * @brief 点击按钮事件 + */ void mouseReleaseSlots(QEvent *event, QString objName); protected: @@ -150,9 +249,15 @@ private: XEventMonitor *xEventMonitor; int tableNum; bool flag = false; + + /// 各按钮是否隐藏 默认隐藏 bool isSwitchuserHide = true; bool isHibernateHide = true; bool isSuspendHide = true; + bool isLogoutHide = true; + bool isRebootHide = true; + bool isPowerOffHide = true; + bool lockfile = false; bool lockuser = false; bool click_blank_space_need_to_exit = true; @@ -160,10 +265,8 @@ private: bool inhibitSleep = false; bool inhibitShutdown = false; - QHash m_btnHideMap; - bool m_IsRoundBtn = true;//是否是圆形按钮 QString m_btnImagesPath = "/usr/share/ukui/ukui-session-manager/images"; MyPushButton *m_switchUserBtn = nullptr; MyPushButton *m_hibernateBtn = nullptr; @@ -201,6 +304,7 @@ private: //QLabel *m_systemMonitorLabel = nullptr; //QPixmap m_systemMonitorIcon; + /// 计算各按钮的行列位置 int m_switchRow = 0, m_switchColumn = 0; int m_hibernateRow = 0, m_hibernateColumn = 0; int m_suspendRow = 0, m_suspendColumn = 0; @@ -212,8 +316,8 @@ private: QSettings *m_btnCfgSetting = nullptr; QRect m_screen; - QWidget *m_showWarningArea = nullptr; - bool m_btnWidgetNeedScrollbar = false; - bool m_showWarningMesg = false; + QWidget *m_showWarningArea = nullptr; /// 阻止列表 + bool m_btnWidgetNeedScrollbar = false; /// 是否需要滑动条显示 + bool m_showWarningMesg = false; /// 是否显示阻止列表 }; #endif // MAINWINDOW_H diff --git a/tools/myiconlabel.cpp b/tools/myiconlabel.cpp index d1024ec..5e9e00f 100644 --- a/tools/myiconlabel.cpp +++ b/tools/myiconlabel.cpp @@ -27,8 +27,7 @@ #include #include -MyIconLabel::MyIconLabel(int labelWidth, int iconWidth, QString path, bool showBackColor, QWidget *parent) - :m_showBackColor(showBackColor) +MyIconLabel::MyIconLabel(int labelWidth, int iconWidth, QString path, QWidget *parent) { this->setFixedSize(labelWidth, labelWidth); this->setObjectName("iconlabel"); @@ -44,13 +43,10 @@ MyIconLabel::MyIconLabel(int labelWidth, int iconWidth, QString path, bool showB m_btnIcon->setChecked(false); m_btnIcon->setGeometry(QRect((width() - iconWidth)/2, (width() - iconWidth)/2, iconWidth, iconWidth)); m_btnIcon->setAttribute(Qt::WA_TransparentForMouseEvents,true); - if (m_showBackColor) { - //mask不要与控件一样大 锯齿明显 稍微大一点 - this->setMask(QRegion(this->x() - 1, this->y() - 1, this->width() + 2, this->height() + 2,QRegion::Ellipse)); - this->setStyleSheet("QLabel#"+ this->objectName() + "{background-color: rgb(255,255,255,40);border-radius:" + QString::number(this->width()/2) + "px;}"); - } else { - this->setStyleSheet("QLabel#"+ this->objectName() + "{background-color: transparent;}"); - } + + //mask不要与控件一样大 锯齿明显 稍微大一点 + this->setMask(QRegion(this->x() - 1, this->y() - 1, this->width() + 2, this->height() + 2,QRegion::Ellipse)); + this->setStyleSheet("QLabel#"+ this->objectName() + "{background-color: rgb(255,255,255,40);border-radius:" + QString::number(this->width()/2) + "px;}"); //this->setPixmap(m_pixMap); this->setAlignment(Qt::AlignCenter); @@ -62,44 +58,6 @@ MyIconLabel::~MyIconLabel() { } -/* -void MyIconLabel::paintEvent(QPaintEvent *event) -{ - return; - QPainter painter(this); - QColor color; - if(m_isNormal) - color = QColor(255,255,255,40); - else if(m_isHover) - color = QColor(255,255,255,80); - else if(m_isClicked) - color = QColor(255,255,255,100); - painter.setPen(QPen(color,0)); - painter.setBrush(color); - painter.drawEllipse(QRect(0,0,width(),height())); - painter.drawPixmap(QRect((width() - m_btnIcon.width())/2, (height() - m_btnIcon.height())/2, m_btnIcon.width(), m_btnIcon.height()), m_btnIcon); -} -*/ -void MyIconLabel::enterEvent(QEvent *event) -{ - if (!m_showBackColor) return; - emit mouseEventSignals(event); - - QString str = "QLabel{background-color: rgb(255,255,255,80);border-radius: " + QString::number(this->width()/2) + "px;}"; - - this->setStyleSheet(str); - this->setAttribute(Qt::WA_StyledBackground); -} - -void MyIconLabel::leaveEvent(QEvent *event) -{ - return; - if (!m_showBackColor) return; - QString str = "QLabel{background-color: rgb(255,255,255,40);border-radius: " + QString::number(this->width()/2) + "px;}"; - this->setStyleSheet(str); - this->setAttribute(Qt::WA_StyledBackground); -} - bool MyIconLabel::event(QEvent *event) { // qDebug() << m_showBackColor << "event..." << event->type(); @@ -121,31 +79,6 @@ bool MyIconLabel::event(QEvent *event) return QWidget::event(event); } -/* -void MyIconLabel::mouseMoveEvent(QMouseEvent *event) -{ - return; -// m_point = event->pos(); -// qDebug() << "MyIconLabel mouseMoveEvent..." << m_point; - -// if(!m_showBackColor) -// return; -// QRegion region(this->x(), this->y(), this->width(), this->height(),QRegion::Ellipse); -// qDebug() << "MyIconLabel mouseMoveEvent..." << m_point << region; - -// QString str; - -// if(!region.contains(m_point)) -// str = "QLabel{background-color: rgb(255,255,255,40);border-radius: " + QString::number(this->width()/2) + "px;}"; -// else -// str = "QLabel{background-color: rgb(255,255,255,80);border-radius: " + QString::number(this->width()/2) + "px;}"; - -// this->setStyleSheet(str); -// this->setAttribute(Qt::WA_StyledBackground); - -} -*/ - bool MyIconLabel::containsPoint(QPoint p) { QPainterPath path; @@ -153,32 +86,3 @@ bool MyIconLabel::containsPoint(QPoint p) //qDebug() << "containsPoint..." << width() << height() << p << QRect(0,0,width(),height()); return path.contains(p); } - -/* -void MyIconLabel::paintEvent(QPaintEvent *) -{ - QPainter painter(this); - painter.setPen(QPen(QColor(0,0,0),2)); - painter.setBrush(QColor(10,10,10)); - QPainterPath path; - QRect rect(10,50,100,48); - const qreal radius = 24; - path.moveTo(rect.topRight() - QPointF(radius, 0)); - path.lineTo(rect.topLeft() + QPointF(radius, 0)); - path.quadTo(rect.topLeft(), rect.topLeft() + QPointF(0, radius)); - path.lineTo(rect.bottomLeft() + QPointF(0, -radius)); - path.quadTo(rect.bottomLeft(), rect.bottomLeft() + QPointF(radius, 0)); - path.lineTo(rect.bottomRight() - QPointF(radius, 0)); - path.quadTo(rect.bottomRight(), rect.bottomRight() + QPointF(0, -radius)); - path.lineTo(rect.topRight() + QPointF(0, radius)); - path.quadTo(rect.topRight(), rect.topRight() + QPointF(-radius, -0)); - painter.drawPath(path); - qDebug() << "1111" << path.contains(QPoint(11,51)); -} - - -void MyIconLabel::mousePressEvent(QMouseEvent* event) -{ - qDebug() << "mousePressEvent..." << event->pos(); -} -*/ diff --git a/tools/myiconlabel.h b/tools/myiconlabel.h index 9546291..ad8b45d 100644 --- a/tools/myiconlabel.h +++ b/tools/myiconlabel.h @@ -36,24 +36,17 @@ class MyIconLabel : public QLabel Q_OBJECT public: - MyIconLabel(int labelWidth, int iconWidth, QString path, bool showBackClor, QWidget *parent = nullptr); + MyIconLabel(int labelWidth, int iconWidth, QString path, QWidget *parent = nullptr); ~MyIconLabel(); bool containsPoint(QPoint p); protected: - void enterEvent(QEvent *event); - void leaveEvent(QEvent *event); bool event(QEvent *); - //void paintEvent(QPaintEvent *event); - //void mouseMoveEvent(QMouseEvent *event); - //void mousePressEvent(QMouseEvent* event); + private: PushButton *m_btnIcon = nullptr; bool m_showBackColor = false; QPoint m_point; -// bool m_isNormal = true; -// bool m_isHover = false; -// bool m_isClicked = false; protected: public: diff --git a/tools/mypushbutton.cpp b/tools/mypushbutton.cpp index e54163f..72c9994 100644 --- a/tools/mypushbutton.cpp +++ b/tools/mypushbutton.cpp @@ -22,20 +22,16 @@ #include #include #include -MyPushButton::MyPushButton(QString iconPath, QString buttonLable, QString objName, QWidget *parent, bool isRecBtn, int x, int y, +MyPushButton::MyPushButton(QString iconPath, QString buttonLable, QString objName, QWidget *parent, int x, int y, int width, int height, int iconWidth, int labelWidth) - : m_isRecBtn(isRecBtn) - , QWidget(parent) + : QWidget(parent) { - if (m_isRecBtn) { - this->setFixedSize(width, width); - } else { - this->setFixedSize(labelWidth, height); - } + this->setFixedSize(labelWidth, height); + this->setObjectName(objName); QVBoxLayout *vBoxLayout = new QVBoxLayout(); vBoxLayout->setContentsMargins(0, 0, 0, 10); - m_iconLabel = new MyIconLabel(labelWidth, iconWidth, iconPath, !isRecBtn); + m_iconLabel = new MyIconLabel(labelWidth, iconWidth, iconPath); m_iconLabel->setObjectName(objName + "_button"); m_iconLabel->installEventFilter(this); @@ -46,10 +42,6 @@ MyPushButton::MyPushButton(QString iconPath, QString buttonLable, QString objNam m_buttonLabel->setStyleSheet("color: white; font: 12pt"); m_buttonLabel->setAlignment(Qt::AlignHCenter | Qt::AlignTop); - if (m_isRecBtn) { - this->setStyleSheet("QWidget#" + this->objectName() + "{background-color: transparent;border-radius: 6px;}"); - this->setAttribute(Qt::WA_StyledBackground); - } vBoxLayout->addWidget(m_iconLabel, 0, Qt::AlignHCenter); vBoxLayout->addWidget(m_buttonLabel, 0, Qt::AlignHCenter); this->setLayout(vBoxLayout); diff --git a/tools/mypushbutton.h b/tools/mypushbutton.h index 640c28b..988208d 100644 --- a/tools/mypushbutton.h +++ b/tools/mypushbutton.h @@ -35,9 +35,8 @@ class MyPushButton : public QWidget Q_OBJECT public: - MyPushButton(QString iconPath, QString buttonLable, QString objName, QWidget *parent = nullptr, bool isRecBtn=true, int x = 0, int y = 0, - int width = 140, int height = 180, int iconWidth = 48, - int labelWidth = 128); + MyPushButton(QString iconPath, QString buttonLable, QString objName, QWidget *parent = nullptr, int x = 0, int y = 0, + int width = 140, int height = 180, int iconWidth = 48, int labelWidth = 128); ~MyPushButton(); void changeIconBackColor(bool isChoose = true, bool isKeySelect = false); @@ -60,7 +59,6 @@ private: QFont m_buttonLabelFont; QPixmap m_pixMap; MyIconLabel *m_iconLabel = nullptr; - bool m_isRecBtn=true;//true 背景为整体 false表示背景只在ICON区域 bool m_isKeySelect = false;//是否通过键盘选中 bool m_isMouseSelect = false;//是否鼠标选中 protected: