Browse Source

Logout
登录页和主页面切换方式需要修改
不能使用 setCentralWidget,这会销毁之前的 CentralWidget
可以考虑使用 QStackedWidget

chengxr 1 year ago
parent
commit
65b49b84f1

+ 2 - 0
QFD/common/QFDIcon.cpp

@@ -11,6 +11,8 @@ QString QFDIcon::iconName(QFDIcon::IconType type)
         return "Detail";
     case Expert:
         return "Expert";
+    case Logout:
+        return "Logout";
     case Project:
         return "Project";
     case User:

+ 1 - 0
QFD/common/QFDIcon.h

@@ -13,6 +13,7 @@ public:
         Data,
         Detail,
         Expert,
+        Logout,
         Project,
         User,
     };

+ 2 - 0
QFD/resource.qrc

@@ -372,5 +372,7 @@
         <file>resource/i18n/qfluentwidgets_hk.ts</file>
         <file>resource/i18n/qfluentwidgets_zh.qm</file>
         <file>resource/i18n/qfluentwidgets_zh.ts</file>
+        <file>resource/svg/Logout_black.svg</file>
+        <file>resource/svg/Logout_white.svg</file>
     </qresource>
 </RCC>

+ 1 - 0
QFD/resource/svg/Logout_black.svg

@@ -0,0 +1 @@
+<svg t="1690282938215" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3722" width="16" height="16"><path d="M512.213333 42.666667a42.666667 42.666667 0 0 1 42.666667 42.666666v426.666667a42.666667 42.666667 0 0 1-85.333333 0V85.333333a42.666667 42.666667 0 0 1 42.666666-42.666666zM210.261333 253.141333a42.624 42.624 0 1 1 60.330667 60.330667 341.333333 341.333333 0 1 0 482.773333 0 42.666667 42.666667 0 0 1 60.330667-60.330667c166.570667 166.656 166.570667 436.778667-0.085333 603.349334-166.613333 166.613333-436.736 166.613333-603.349334 0s-166.613333-436.693333 0-603.349334z" fill="#b45353" p-id="3723"></path></svg>

+ 1 - 0
QFD/resource/svg/Logout_white.svg

@@ -0,0 +1 @@
+<svg t="1690282938215" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3722" width="16" height="16"><path d="M512.213333 42.666667a42.666667 42.666667 0 0 1 42.666667 42.666666v426.666667a42.666667 42.666667 0 0 1-85.333333 0V85.333333a42.666667 42.666667 0 0 1 42.666666-42.666666zM210.261333 253.141333a42.624 42.624 0 1 1 60.330667 60.330667 341.333333 341.333333 0 1 0 482.773333 0 42.666667 42.666667 0 0 1 60.330667-60.330667c166.570667 166.656 166.570667 436.778667-0.085333 603.349334-166.613333 166.613333-436.736 166.613333-603.349334 0s-166.613333-436.693333 0-603.349334z" fill="#b45353" p-id="3723"></path></svg>

+ 0 - 1
QFD/view/AboutView.cpp

@@ -32,6 +32,5 @@ void AboutView::initialize()
 
 void AboutView::initLayout()
 {
-    //    m_vBoxLayout->setAlignment(Qt::AlignCenter);
     m_vBoxLayout->addWidget(m_appInfoWidget);
 }

+ 11 - 0
QFD/view/MainWindow.cpp

@@ -180,6 +180,7 @@ void MainWindow::connectSignalsAndSlots()
     connect(m_loginView, &LoginView::signalLogin, this, &MainWindow::slotLogin);
     connect(m_loginView, &LoginView::signalCancelLogin, this, &MainWindow::slotCancelLogin);
     connect(m_naviInterface, &NavigationInterface::displayModeChanged, m_titleBar, &StandardTitleBar::raise);
+    connect(m_userView, &UserView::signalLogout, this, &MainWindow::slotLogout);
 }
 
 void MainWindow::setNaviInterfaceHidden(bool hidden)
@@ -209,10 +210,20 @@ void MainWindow::switchTo(QWidget *widget, bool triggerByUser)
 
 void MainWindow::slotLogin()
 {
+    qDebug() << __FUNCTION__ << __LINE__ << (m_mainWidget == nullptr);
     setCentralWidget(m_mainWidget);
     m_titleBar->setHidden(false);
 }
 
+void MainWindow::slotLogout()
+{
+    qDebug() << __FUNCTION__ << __LINE__;
+    qDebug() << __FUNCTION__ << __LINE__ << (m_loginView == nullptr);
+    m_loginView = new LoginView(this);
+    setCentralWidget(m_loginView);
+    m_titleBar->setHidden(true);
+}
+
 void MainWindow::slotCancelLogin()
 {
     exit(0);

+ 2 - 0
QFD/view/MainWindow.h

@@ -68,6 +68,8 @@ private:
 
 private slots:
     void slotLogin();
+    void slotLogout();
+
     void slotCancelLogin();
     void homeViewClicked();
     void projectViewClicked();

+ 88 - 1
QFD/view/UserView.cpp

@@ -1,8 +1,23 @@
 #include "UserView.h"
 
+#include <Widgets/Button.h>
+#include <QFDIcon.h>
+
+#include <QBoxLayout>
+#include <QGridLayout>
+#include <QLabel>
+#include <QApplication>
+#include <QPixmap>
+
 #include <QPainter>
 
-UserView::UserView(QWidget *parent) : QWidget(parent) { }
+UserView::UserView(QWidget *parent) : QWidget(parent)
+{
+    initilaize();
+    initLayout();
+    connectSignalsAndSlots();
+    refresh();
+}
 
 void UserView::paintEvent(QPaintEvent *event)
 {
@@ -12,3 +27,75 @@ void UserView::paintEvent(QPaintEvent *event)
     painter.drawPixmap(0, 0,
                        pixmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
 }
+
+void UserView::initilaize()
+{
+    m_vBoxLayout = new QVBoxLayout(this);
+
+    m_iconLabel = new QLabel(this);
+    m_iconLabel->setFixedSize(QSize(50, 50));
+    m_iconLabel->setScaledContents(true);
+    QPixmap pixmap = QPixmap(":/resource/logo.png");
+    pixmap.scaled(m_iconLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
+    m_iconLabel->setPixmap(pixmap);
+
+    m_gridLayout = new QGridLayout();
+
+    m_accNameLabel  = new QLabel("用户名:", this);
+    m_accValueLabel = new QLabel(this);
+
+    m_idNameLabel    = new QLabel("账号id:", this);
+    m_idValueLabel   = new QLabel(this);
+    m_typeNameLabel  = new QLabel("账号类型:", this);
+    m_typeValueLabel = new QLabel(this);
+
+    m_hBoxLayout    = new QHBoxLayout();
+    m_confirmButton = new PushButton("退出", NEWFLICON(QFDIcon, Logout), this);
+
+    setStyleSheet("QLabel {font-size: 14px;font:Normal;font-family: 'Microsoft YaHei UI';}");
+}
+
+void UserView::initLayout()
+{
+    m_vBoxLayout->setContentsMargins(20, 20, 20, 20);
+
+    m_vBoxLayout->addStretch(1);
+
+    m_vBoxLayout->addWidget(m_iconLabel, 0, Qt::AlignHCenter);
+    m_vBoxLayout->addSpacing(50);
+
+    m_vBoxLayout->addLayout(m_gridLayout);
+    m_gridLayout->setAlignment(Qt::AlignHCenter);
+
+    m_gridLayout->addWidget(m_accNameLabel, 0, 0, 1, 1, Qt::AlignRight);
+    m_gridLayout->addWidget(m_accValueLabel, 0, 1, 1, 1, Qt::AlignLeft);
+
+    m_gridLayout->addWidget(m_idNameLabel, 1, 0, 1, 1, Qt::AlignRight);
+    m_gridLayout->addWidget(m_idValueLabel, 1, 1, 1, 1, Qt::AlignLeft);
+
+    m_gridLayout->addWidget(m_typeNameLabel, 2, 0, 1, 1, Qt::AlignRight);
+    m_gridLayout->addWidget(m_typeValueLabel, 2, 1, 1, 1, Qt::AlignLeft);
+
+    m_vBoxLayout->addStretch(2);
+
+    m_vBoxLayout->addLayout(m_hBoxLayout);
+    m_hBoxLayout->setAlignment(Qt::AlignRight);
+    m_hBoxLayout->addWidget(m_confirmButton);
+}
+
+void UserView::connectSignalsAndSlots()
+{
+    connect(m_confirmButton, &PushButton::clicked, this, &UserView::slotLogout);
+}
+
+void UserView::refresh()
+{
+    m_accValueLabel->setText("admin");
+    m_idValueLabel->setText("100001");
+    m_typeValueLabel->setText("超级管理员");
+}
+
+void UserView::slotLogout()
+{
+    emit signalLogout();
+}

+ 34 - 0
QFD/view/UserView.h

@@ -3,6 +3,12 @@
 
 #include <QWidget>
 
+class QVBoxLayout;
+class QGridLayout;
+class QHBoxLayout;
+class QLabel;
+class PushButton;
+
 class UserView : public QWidget
 {
     Q_OBJECT
@@ -12,6 +18,34 @@ public:
     void paintEvent(QPaintEvent *event) override;
 
 signals:
+    void signalLogout();
+
+private:
+    void initilaize();
+    void initLayout();
+    void connectSignalsAndSlots();
+    void refresh();
+
+private slots:
+    void slotLogout();
+
+private:
+    /// 图标,版本号,更新内容,构建时间,当前环境,版权声明
+
+    QVBoxLayout *m_vBoxLayout = nullptr;
+
+    QLabel *m_iconLabel = nullptr;
+
+    QGridLayout *m_gridLayout = nullptr;
+    QLabel *m_accNameLabel    = nullptr;
+    QLabel *m_accValueLabel   = nullptr;
+    QLabel *m_idNameLabel     = nullptr;
+    QLabel *m_idValueLabel    = nullptr;
+    QLabel *m_typeNameLabel   = nullptr;
+    QLabel *m_typeValueLabel  = nullptr;
+
+    QHBoxLayout *m_hBoxLayout   = nullptr;
+    PushButton *m_confirmButton = nullptr;
 };
 
 #endif  // USERVIEW_H

+ 3 - 2
QFD/widgets/AppInfoWidget.h

@@ -23,12 +23,13 @@ private:
     void refresh();
 
 private:
-    /// 图标,版本号,更新内容,构建时间,当前环境,版权声明
+    /// 用户名,账号id,账号类型
 
     QVBoxLayout *m_vBoxLayout = nullptr;
 
+    QLabel *m_iconLabel = nullptr;
+
     QGridLayout *m_gridLayout   = nullptr;
-    QLabel *m_iconLabel         = nullptr;
     QLabel *m_verNameLabel      = nullptr;
     QLabel *m_verValueLabel     = nullptr;
     QLabel *m_contentNameLabel  = nullptr;