This commit is contained in:
zhaominyong 2022-01-21 16:09:08 +08:00
parent a8fc6e7ea4
commit 7f70722321
2 changed files with 62 additions and 69 deletions

View File

@ -38,10 +38,12 @@ MainDialog::~MainDialog()
void MainDialog::initUI() void MainDialog::initUI()
{ {
m_totalHLayout = new QHBoxLayout(ui->centralwidget); // 总体布局为横向布局,分为左侧和右侧
m_totalHLayout = new QHBoxLayout;
m_totalHLayout->setSpacing(0); m_totalHLayout->setSpacing(0);
m_totalHLayout->setObjectName(QString::fromUtf8("m_totalHLayout")); m_totalHLayout->setObjectName(QString::fromUtf8("m_totalHLayout"));
m_totalHLayout->setContentsMargins(0, 0, 0, 0); m_totalHLayout->setContentsMargins(0, 0, 0, 0);
m_totalHLayout->setSpacing(0);
ui->centralwidget->setLayout(m_totalHLayout); ui->centralwidget->setLayout(m_totalHLayout);
if (GlobelBackupInfo::inst().isManager()) if (GlobelBackupInfo::inst().isManager())
@ -49,19 +51,23 @@ void MainDialog::initUI()
else else
m_leftSiderBarWidget = new LeftsiderbarWidget(ui->centralwidget, LeftsiderbarWidget::StartMode::std_user); m_leftSiderBarWidget = new LeftsiderbarWidget(ui->centralwidget, LeftsiderbarWidget::StartMode::std_user);
m_leftSiderBarWidget->setObjectName(QString::fromUtf8("m_leftSiderBarWidget")); m_leftSiderBarWidget->setObjectName(QString::fromUtf8("m_leftSiderBarWidget"));
m_leftSiderBarWidget->setGeometry(QRect(0, 0, 200, 640)); m_leftSiderBarWidget->setFixedSize(200, 640);
m_leftSiderBarWidget->setFixedSize(QSize(200, 640));
m_totalHLayout->addWidget(m_leftSiderBarWidget); m_totalHLayout->addWidget(m_leftSiderBarWidget);
m_rightVLayout = new QVBoxLayout(); m_rightWidget = new QWidget;
m_rightWidget->setFixedSize(760, 640);
m_rightVLayout = new QVBoxLayout;
m_rightVLayout->setObjectName(QString::fromUtf8("m_rightVLayout")); m_rightVLayout->setObjectName(QString::fromUtf8("m_rightVLayout"));
m_rightVLayout->setContentsMargins(0, 0, 0, 0); m_rightVLayout->setContentsMargins(0, 0, 0, 0);
m_rightVLayout->setSpacing(0);
m_titleWidget = new QWidget(ui->centralwidget); m_titleWidget = new QWidget;
m_titleWidget->setObjectName(QString::fromUtf8("m_titleWidget")); m_titleWidget->setObjectName(QString::fromUtf8("m_titleWidget"));
m_titleWidget->setGeometry(QRect(201, 0, 760, 40)); m_titleWidget->setFixedSize(760, 40);
m_rightVLayout->addWidget(m_titleWidget); m_rightVLayout->addWidget(m_titleWidget);
m_rightVLayout->addStretch();
if (!GlobelBackupInfo::inst().isManager()) if (!GlobelBackupInfo::inst().isManager())
selected(FuncTypeConverter::FunType::BACKUP_DATA); selected(FuncTypeConverter::FunType::BACKUP_DATA);
@ -70,7 +76,9 @@ void MainDialog::initUI()
else else
selected(FuncTypeConverter::FunType::BACKUP_SYSTEM); selected(FuncTypeConverter::FunType::BACKUP_SYSTEM);
m_totalHLayout->addLayout(m_rightVLayout); m_rightWidget->setLayout(m_rightVLayout);
m_totalHLayout->addWidget(m_rightWidget);
m_totalHLayout->addStretch();
initTileBar(); initTileBar();
initStyleSheet(); initStyleSheet();
@ -79,43 +87,60 @@ void MainDialog::initUI()
void MainDialog::initTileBar() void MainDialog::initTileBar()
{ {
m_titleLayout = new QHBoxLayout; m_titleLayout = new QHBoxLayout;
m_titleWidget->setLayout(m_titleLayout);
m_titleLayout->setContentsMargins(8, 4, 4, 0); m_titleLayout->setContentsMargins(8, 4, 4, 0);
m_titleLayout->setSpacing(0); m_titleLayout->setSpacing(0);
m_menuOptionBtn = new QToolButton(m_titleWidget); m_menuOptionBtn = new QToolButton;
m_minBtn = new QPushButton(m_titleWidget); m_minBtn = new QPushButton;
m_closeBtn = new QPushButton(m_titleWidget); m_closeBtn = new QPushButton;
m_menuOptionBtn->setToolTip(tr("Main menu")); m_menuOptionBtn->setToolTip(tr("Main menu"));
m_minBtn->setToolTip(tr("Minimize")); m_minBtn->setToolTip(tr("Minimize"));
m_closeBtn->setToolTip(tr("Close")); m_closeBtn->setToolTip(tr("Close"));
m_menuOptionBtn->setProperty("isWindowButton", 0x1);
m_menuOptionBtn->setProperty("useIconHighlightEffect", 0x2);
m_menuOptionBtn->setIcon(QIcon::fromTheme("open-menu-symbolic"));
m_menuOptionBtn->setFixedSize(30, 30); m_menuOptionBtn->setFixedSize(30, 30);
m_minBtn->setFixedSize(30, 30); m_menuOptionBtn->setAutoRaise(true);
m_closeBtn->setFixedSize(30, 30); m_menuOptionBtn->setPopupMode(QToolButton::InstantPopup);
// m_menuOptionBtn->setProperty("setIconHighlightEffectDefaultColor", m_closeBtn->palette().color(QPalette::Active, QPalette::Base));
QMenu* backupMain = new QMenu(this); m_minBtn->setProperty("isWindowButton", 0x1);
m_minBtn->setProperty("useIconHighlightEffect", 0x2);
m_minBtn->setFixedSize(30, 30);
m_minBtn->setFlat(true);
m_minBtn->setIcon(QIcon::fromTheme("window-minimize-symbolic"));
// m_minBtn->setProperty("setIconHighlightEffectDefaultColor", m_closeBtn->palette().color(QPalette::Active, QPalette::Base));
m_closeBtn->setProperty("isWindowButton", 0x2);
m_closeBtn->setProperty("useIconHighlightEffect", 0x8);
m_closeBtn->setFixedSize(30, 30);
m_closeBtn->setFlat(true);
m_closeBtn->setIcon(QIcon::fromTheme("window-close-symbolic"));
// m_closeBtn->setProperty("setIconHighlightEffectDefaultColor", m_closeBtn->palette().color(QPalette::Active, QPalette::Base));
QMenu* backupMain = new QMenu(m_titleWidget);
backupMain->setObjectName("mainMenu"); backupMain->setObjectName("mainMenu");
m_menuOptionBtn->setMenu(backupMain); m_menuOptionBtn->setMenu(backupMain);
QAction* backupTheme = new QAction(tr("Theme"),this); QAction* backupTheme = new QAction(tr("Theme"), m_titleWidget);
backupMain->addAction(backupTheme); backupMain->addAction(backupTheme);
QMenu* selectTheme = new QMenu(this); QMenu* selectTheme = new QMenu( m_titleWidget);
selectTheme->setObjectName("selectTheme"); selectTheme->setObjectName("selectTheme");
backupTheme->setMenu(selectTheme); backupTheme->setMenu(selectTheme);
QAction* defaultTheme = new QAction(tr("Auto"),this); QAction* defaultTheme = new QAction(tr("Auto"), m_titleWidget);
selectTheme->addAction(defaultTheme); selectTheme->addAction(defaultTheme);
QAction* darkTheme = new QAction(tr("Dark"),this); QAction* darkTheme = new QAction(tr("Dark"), m_titleWidget);
selectTheme->addAction(darkTheme); selectTheme->addAction(darkTheme);
QAction* lightTheme = new QAction(tr("Light"),this); QAction* lightTheme = new QAction(tr("Light"), m_titleWidget);
selectTheme->addAction(lightTheme); selectTheme->addAction(lightTheme);
m_backupHelp = new QAction(tr("Help"),this); m_backupHelp = new QAction(tr("Help"), m_titleWidget);
backupMain->addAction(m_backupHelp); backupMain->addAction(m_backupHelp);
m_backupAbout = new QAction(tr("About"),this); m_backupAbout = new QAction(tr("About"), m_titleWidget);
backupMain->addAction(m_backupAbout); backupMain->addAction(m_backupAbout);
m_backupExit = new QAction(tr("Exit"),this); m_backupExit = new QAction(tr("Exit"), m_titleWidget);
backupMain->addAction(m_backupExit); backupMain->addAction(m_backupExit);
m_titleLayout->addStretch(); m_titleLayout->addStretch();
@ -124,46 +149,19 @@ void MainDialog::initTileBar()
m_titleLayout->addWidget(m_minBtn); m_titleLayout->addWidget(m_minBtn);
m_titleLayout->addSpacing(4); m_titleLayout->addSpacing(4);
m_titleLayout->addWidget(m_closeBtn); m_titleLayout->addWidget(m_closeBtn);
m_titleWidget->setLayout(m_titleLayout);
} }
void MainDialog::initStyleSheet() void MainDialog::initStyleSheet()
{ {
// 主窗口 // 主窗口
// qApp->setWindowIcon(QIcon::fromTheme(THEME_YHKYLIN_BACKUP_TOOLS));
this->setWindowTitle(tr("Backup & Restore")); this->setWindowTitle(tr("Backup & Restore"));
// 工作区(此处代码加不加一个样,注释掉,留着学习,知道有这么回事)
//ui->centralwidget->setStyleSheet("QWidget#centralWidget{background: palette(base); border-radius: 6px;}");
//ui->centralwidget->setAttribute(Qt::WA_TranslucentBackground);
// 右侧title // 右侧title
// setStyleSheet方式設置樣式不能跟隨主題 m_rightWidget->setAutoFillBackground(true);
// m_titleWidget->setStyleSheet("QWidget#m_titleWidget{background-color:palette(base)}"); QPalette palette = m_rightWidget->palette();
m_titleWidget->setAutoFillBackground(true);
QPalette palette = m_titleWidget->palette();
palette.setColor(QPalette::Background, palette.color(QPalette::Base)); palette.setColor(QPalette::Background, palette.color(QPalette::Base));
m_titleWidget->setPalette(palette); m_rightWidget->setPalette(palette);
// m_menuOptionBtn->setStyleSheet("background-color: palette(base);");
m_menuOptionBtn->setProperty("isWindowButton", 0x1);
m_menuOptionBtn->setProperty("useIconHighlightEffect", 0x2);
m_menuOptionBtn->setIcon(QIcon::fromTheme("open-menu-symbolic"));
m_menuOptionBtn->setAutoRaise(true);
m_menuOptionBtn->setPopupMode(QToolButton::InstantPopup);
// m_menuOptionBtn->setProperty("setIconHighlightEffectDefaultColor", m_closeBtn->palette().color(QPalette::Active, QPalette::Base));
m_minBtn->setProperty("isWindowButton", 0x1);
m_minBtn->setProperty("useIconHighlightEffect", 0x2);
m_minBtn->setFlat(true);
m_minBtn->setIcon(QIcon::fromTheme("window-minimize-symbolic"));
// m_minBtn->setProperty("setIconHighlightEffectDefaultColor", m_closeBtn->palette().color(QPalette::Active, QPalette::Base));
m_closeBtn->setProperty("isWindowButton", 0x2);
m_closeBtn->setProperty("useIconHighlightEffect", 0x8);
m_closeBtn->setFlat(true);
m_closeBtn->setIcon(QIcon::fromTheme("window-close-symbolic"));
// m_closeBtn->setProperty("setIconHighlightEffectDefaultColor", m_closeBtn->palette().color(QPalette::Active, QPalette::Base));
} }
void MainDialog::initConnect() void MainDialog::initConnect()
@ -209,45 +207,38 @@ void MainDialog::selected(int func_type)
switch (func_type) { switch (func_type) {
case FuncTypeConverter::FunType::BACKUP_SYSTEM: case FuncTypeConverter::FunType::BACKUP_SYSTEM:
m_stackedWidget = new SystemBackup(ui->centralwidget); m_stackedWidget = new SystemBackup;
GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::BACKUP_SYSTEM); GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::BACKUP_SYSTEM);
break; break;
case FuncTypeConverter::FunType::RESTORE_SYSTEM: case FuncTypeConverter::FunType::RESTORE_SYSTEM:
m_stackedWidget = new SystemRestore(ui->centralwidget); m_stackedWidget = new SystemRestore;
GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::RESTORE_SYSTEM); GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::RESTORE_SYSTEM);
break; break;
case FuncTypeConverter::FunType::BACKUP_DATA: case FuncTypeConverter::FunType::BACKUP_DATA:
m_stackedWidget = new DataBackup(ui->centralwidget); m_stackedWidget = new DataBackup;
GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::BACKUP_DATA); GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::BACKUP_DATA);
break; break;
case FuncTypeConverter::FunType::RESTORE_DATA: case FuncTypeConverter::FunType::RESTORE_DATA:
m_stackedWidget = new DataRestore(ui->centralwidget); m_stackedWidget = new DataRestore;
GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::RESTORE_DATA); GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::RESTORE_DATA);
break; break;
case FuncTypeConverter::FunType::OPERATION_LOG: case FuncTypeConverter::FunType::OPERATION_LOG:
m_stackedWidget = new OperationLog(ui->centralwidget); m_stackedWidget = new OperationLog;
GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::OPERATION_LOG); GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::OPERATION_LOG);
break; break;
case FuncTypeConverter::FunType::GHOST_IMAGE: case FuncTypeConverter::FunType::GHOST_IMAGE:
m_stackedWidget = new GhostImage(ui->centralwidget); m_stackedWidget = new GhostImage;
GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::GHOST_IMAGE); GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::GHOST_IMAGE);
break; break;
default: default:
m_stackedWidget = new SystemBackup(ui->centralwidget); m_stackedWidget = new SystemBackup;
GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::BACKUP_SYSTEM); GlobelBackupInfo::inst().setFuncType(FuncTypeConverter::FunType::BACKUP_SYSTEM);
break; break;
} }
m_stackedWidget->setObjectName(QString::fromUtf8("m_stackedWidget")); m_stackedWidget->setObjectName(QString::fromUtf8("m_stackedWidget"));
m_stackedWidget->setGeometry(QRect(201, 40, 760, 600)); m_stackedWidget->setFixedSize(760, 600);
m_rightVLayout->addWidget(m_stackedWidget); m_rightVLayout->addWidget(m_stackedWidget);
// 右侧内容区域
// m_stackedWidget->setStyleSheet("QStackedWidget#m_stackedWidget{background: palette(base); border-bottom-left-radius: 6px; border-bottom-right-radius: 6px;}");
m_stackedWidget->setAutoFillBackground(true);
QPalette palette = m_stackedWidget->palette();
palette.setColor(QPalette::Background, palette.color(QPalette::Base));
m_stackedWidget->setPalette(palette);
} }
/** /**
@ -284,7 +275,8 @@ void MainDialog::mountBackupPartition()
QObject::tr("There's no backup partition, can only backup to removable device."), QObject::tr("There's no backup partition, can only backup to removable device."),
QObject::tr("Ok")); QObject::tr("Ok"));
GlobelBackupInfo::inst().setHasBackupPartition(false); // GlobelBackupInfo::inst().setHasBackupPartition(false);
closeBtn();
} else if (int(MountResult::MOUNTED) != reply.value()) { } else if (int(MountResult::MOUNTED) != reply.value()) {
// 挂载备份分区失败 // 挂载备份分区失败
MessageBoxUtils::QMESSAGE_BOX_WARNING(this, QObject::tr("Warning"), MessageBoxUtils::QMESSAGE_BOX_WARNING(this, QObject::tr("Warning"),

View File

@ -38,6 +38,7 @@ private:
// 总体布局部分 // 总体布局部分
QHBoxLayout *m_totalHLayout = nullptr; QHBoxLayout *m_totalHLayout = nullptr;
LeftsiderbarWidget *m_leftSiderBarWidget = nullptr; LeftsiderbarWidget *m_leftSiderBarWidget = nullptr;
QWidget *m_rightWidget = nullptr;
QVBoxLayout *m_rightVLayout = nullptr; QVBoxLayout *m_rightVLayout = nullptr;
QWidget *m_titleWidget = nullptr; QWidget *m_titleWidget = nullptr;
QStackedWidget *m_stackedWidget = nullptr; QStackedWidget *m_stackedWidget = nullptr;