chengxr преди 1 година
родител
ревизия
bcc27b273f
променени са 6 файла, в които са добавени 99 реда и са изтрити 30 реда
  1. 22 0
      QFD/dbService/ClassSet.cpp
  2. 4 0
      QFD/dbService/ClassSet.h
  3. 21 11
      QFD/view/AboutView.cpp
  4. 12 3
      QFD/view/AboutView.h
  5. 30 13
      QFD/view/UserView.cpp
  6. 10 3
      QFD/view/UserView.h

+ 22 - 0
QFD/dbService/ClassSet.cpp

@@ -114,6 +114,23 @@ ClassSet::ClassSet()
 
 static QFUser *m_currentUser = nullptr;
 
+QString QFUser::nameOfRole(QFUser::Role role)
+{
+    switch (role) {
+    case QFUser::SuperAdmin: {
+        return "超级管理员";
+    }
+    case QFUser::GerneralAdmin: {
+        return "普通管理员";
+    }
+    case QFUser::Expert: {
+        return "专家";
+    }
+    default:
+        return "未知";
+    }
+}
+
 QFUser::QFUser() { }
 
 QFUser::QFUser(const QString userId, const QString password) : userNo(userId), rawPassword(password) { }
@@ -123,6 +140,11 @@ QFUser *QFUser::currentUser()
     return m_currentUser;
 }
 
+QString QFUser::roleName() const
+{
+    return nameOfRole(role);
+}
+
 int QFUser::logout()
 {
     if (m_currentUser == nullptr) {

+ 4 - 0
QFD/dbService/ClassSet.h

@@ -84,6 +84,8 @@ public:
         Expert
     };
 
+    static QString nameOfRole(Role role);
+
     int id = -1;              // id
     QString userName;         //用户名称
     QString userNo;           //用户账号
@@ -104,6 +106,8 @@ public:
 
     static QFUser *currentUser();
 
+    QString roleName() const;
+
     int login();  // 登录
 
     static int logout();  // 退出

+ 21 - 11
QFD/view/AboutView.cpp

@@ -5,32 +5,42 @@
 #include <QBoxLayout>
 #include <QApplication>
 #include <QPainter>
+#include <QLabel>
+#include <QResizeEvent>
 
 #include <QDebug>
 
 AboutView::AboutView(QWidget *parent) : QWidget(parent)
 {
-    initialize();
-    initLayout();
     setWindowTitle("关于");
 }
 
-void AboutView::paintEvent(QPaintEvent *event)
+void AboutView::showEvent(QShowEvent *event)
+{
+    QWidget::showEvent(event);
+    initialize();
+}
+
+void AboutView::resizeEvent(QResizeEvent *event)
 {
-    QWidget::paintEvent(event);
-    QPainter painter(this);
-    QPixmap pixmap(":/resource/background/1.jpg");
-    painter.drawPixmap(0, 0,
-                       pixmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
+    QWidget::resizeEvent(event);
+    initialize();
+    m_bgLabel->resize(event->size());
+    m_bgLabel->setPixmap(pixmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
 }
 
 void AboutView::initialize()
 {
+    if (m_initilized == true) {
+        return;
+    }
+
+    m_bgLabel       = new QLabel(this);
+    pixmap          = QPixmap(":/resource/background/1.jpg");
     m_vBoxLayout    = new QVBoxLayout(this);
     m_appInfoWidget = new AppInfoWidget(this);
-}
 
-void AboutView::initLayout()
-{
     m_vBoxLayout->addWidget(m_appInfoWidget);
+
+    m_initilized = true;
 }

+ 12 - 3
QFD/view/AboutView.h

@@ -3,9 +3,11 @@
 
 #include <QWidget>
 
-class QVBoxLayout;
 class AppInfoWidget;
 
+class QVBoxLayout;
+class QLabel;
+
 ///
 /// \brief The AboutView class
 /// 关于页面
@@ -15,16 +17,23 @@ class AboutView : public QWidget
 public:
     explicit AboutView(QWidget *parent = nullptr);
 
-    void paintEvent(QPaintEvent *event) override;
+private:
+    void showEvent(QShowEvent *event) override;
+
+    void resizeEvent(QResizeEvent *event) override;
 
     void initialize();
-    void initLayout();
 
 signals:
 
 private:
+    bool m_initilized = false;
+
     QVBoxLayout *m_vBoxLayout      = nullptr;
     AppInfoWidget *m_appInfoWidget = nullptr;
+
+    QLabel *m_bgLabel = nullptr;
+    QPixmap pixmap;
 };
 
 #endif  // ABOUTVIEW_H

+ 30 - 13
QFD/view/UserView.cpp

@@ -12,30 +12,47 @@
 #include <QLabel>
 #include <QApplication>
 #include <QPixmap>
+#include <QResizeEvent>
 
 #include <QPainter>
 
-UserView::UserView(QWidget *parent) : QWidget(parent)
+UserView::UserView(QWidget *parent) : QWidget(parent) { }
+
+void UserView::showEvent(QShowEvent *event)
 {
-    initilaize();
-    initLayout();
-    connectSignalsAndSlots();
+    QWidget::showEvent(event);
+    init();
     refresh();
 }
 
-void UserView::paintEvent(QPaintEvent *event)
+void UserView::resizeEvent(QResizeEvent *event)
+{
+    QWidget::resizeEvent(event);
+    init();
+    m_bgLabel->resize(event->size());
+    m_bgLabel->setPixmap(pixmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
+}
+
+void UserView::init()
 {
-    QWidget::paintEvent(event);
-    QPainter painter(this);
-    QPixmap pixmap(":/resource/background/1.jpg");
-    painter.drawPixmap(0, 0,
-                       pixmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
+    if (m_initilized == true) {
+        return;
+    }
+
+    initilaize();
+    initLayout();
+    connectSignalsAndSlots();
+
+    m_initilized = true;
 }
 
 void UserView::initilaize()
 {
     m_vBoxLayout = new QVBoxLayout(this);
 
+    m_bgLabel = new QLabel(this);
+    pixmap    = QPixmap(":/resource/background/1.jpg");
+
     m_iconLabel = new QLabel(this);
     m_iconLabel->setFixedSize(QSize(50, 50));
     m_iconLabel->setScaledContents(true);
@@ -94,9 +111,9 @@ void UserView::connectSignalsAndSlots()
 
 void UserView::refresh()
 {
-    m_accValueLabel->setText("admin");
-    m_idValueLabel->setText("100001");
-    m_typeValueLabel->setText("超级管理员");
+    m_accValueLabel->setText(QFUser::currentUser()->userName);
+    m_idValueLabel->setText(QFUser::currentUser()->userNo);
+    m_typeValueLabel->setText(QFUser::currentUser()->roleName());
 }
 
 void UserView::slotLogout()

+ 10 - 3
QFD/view/UserView.h

@@ -15,12 +15,16 @@ class UserView : public QWidget
 public:
     explicit UserView(QWidget *parent = nullptr);
 
-    void paintEvent(QPaintEvent *event) override;
-
 signals:
     void signalLogout();
 
 private:
+    void showEvent(QShowEvent *event) override;
+
+    void resizeEvent(QResizeEvent *event) override;
+
+    void init();
+
     void initilaize();
     void initLayout();
     void connectSignalsAndSlots();
@@ -30,7 +34,10 @@ private slots:
     void slotLogout();
 
 private:
-    /// 图标,版本号,更新内容,构建时间,当前环境,版权声明
+    bool m_initilized = false;
+
+    QLabel *m_bgLabel = nullptr;
+    QPixmap pixmap;
 
     QVBoxLayout *m_vBoxLayout = nullptr;