From 1901460fa93050b30af56a2d3965c64a55f900f4 Mon Sep 17 00:00:00 2001 From: likehomedream Date: Fri, 22 Sep 2023 16:32:24 +0800 Subject: [PATCH] add update historywidget and fix some bugs --- src/fileProcess/historyinfoload.cpp | 7 ++-- src/fileProcess/historyinfoload.h | 1 + src/mainwindow.cpp | 53 +++++++++++++++++------------ src/mainwindow.h | 3 ++ src/module/historywidget.cpp | 1 - 5 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/fileProcess/historyinfoload.cpp b/src/fileProcess/historyinfoload.cpp index dc509f6..f760a94 100644 --- a/src/fileProcess/historyinfoload.cpp +++ b/src/fileProcess/historyinfoload.cpp @@ -5,11 +5,12 @@ HistoryInfoLoad::HistoryInfoLoad(const QString &date, QObject *parent) { m_historytime = date; + m_filepath = QDir::homePath() + "/.cache/theme-build/" + m_historytime; } QString HistoryInfoLoad::getCover() { - QString filePath = QDir::homePath() + "/.cache/theme-build/" + m_historytime + "/config/preview"; + QString filePath = m_filepath + "/config/preview"; QString previewFilePath; QFileInfo pngFileInfo(filePath + ".png"); @@ -29,7 +30,7 @@ QString HistoryInfoLoad::getCover() QString HistoryInfoLoad::getThemeName() { - QString filePath = QDir::homePath() + "/.cache/theme-build/" + m_historytime + "/debian/control"; + QString filePath = m_filepath + "/debian/control"; QFile file(filePath); if (file.exists() && file.open(QIODevice::ReadOnly)) { @@ -56,7 +57,7 @@ QString HistoryInfoLoad::getThemeName() QString HistoryInfoLoad::getThemeType() { - QString filePath = QDir::homePath() + "/.cache/theme-build/" + m_historytime; + QString filePath = m_filepath; QDir themeDir(filePath); if (themeDir.exists("globalTheme")) { diff --git a/src/fileProcess/historyinfoload.h b/src/fileProcess/historyinfoload.h index d8d4671..bbcdc2e 100644 --- a/src/fileProcess/historyinfoload.h +++ b/src/fileProcess/historyinfoload.h @@ -13,6 +13,7 @@ public: signals: private: + QString m_filepath = nullptr; QString m_historytime = nullptr; QString m_coverpath = nullptr; QString m_themename = nullptr; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 735f441..665a6b0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,5 +1,6 @@ #include "mainwindow.h" - +#include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { @@ -59,36 +60,25 @@ void MainWindow::initUI() layout->addWidget(m_cursorbtn); - QWidget *guideWidget = new QWidget(); + m_guideWidget = new QWidget(); QHBoxLayout *labellayout = new QHBoxLayout(); - QLabel *Label = new QLabel(guideWidget); + QLabel *Label = new QLabel(m_guideWidget); Label->setText("主题打包上传工具 "); - QLabel *guideLabel = new QLabel(guideWidget); - QString str = ""+tr("使用指南") + ""; +// QPushButton *guideLabel = new QPushButton(m_guideWidget); + QLabel *guideLabel = new QLabel(m_guideWidget); + QString str = "" + tr("使用指南") + ""; guideLabel->setText(str); guideLabel->setTextFormat(Qt::RichText); guideLabel->setCursor(Qt::PointingHandCursor); - guideLabel->setOpenExternalLinks(false); - + guideLabel->setOpenExternalLinks(true); // 将此属性设置为 true labellayout->addStretch(1); labellayout->addWidget(Label); labellayout->addWidget(guideLabel); labellayout->addStretch(1); - guideWidget->setLayout(labellayout); - - connect(guideLabel, &QLabel::linkActivated,this, [=]() { - QDialog* helpDialog = new QDialog(this); - helpDialog->setWindowTitle("帮助"); - QLabel* helpText = new QLabel(helpDialog); - helpText->setText("这是帮助信息"); - QVBoxLayout* layout = new QVBoxLayout(helpDialog); - layout->addWidget(helpText); - helpDialog->setLayout(layout); - helpDialog->show(); - }); + m_guideWidget->setLayout(labellayout); m_historywidget = new HistoryWidget(); m_historywidget->setMinimumHeight(2000); @@ -98,13 +88,13 @@ void MainWindow::initUI() alllayout->addStretch(1); alllayout->addLayout(layout); alllayout->addStretch(1); - alllayout->addWidget(guideWidget); + alllayout->addWidget(m_guideWidget); alllayout->addStretch(1); }else{ alllayout->addStretch(1); alllayout->addLayout(layout); alllayout->addStretch(1); - alllayout->addWidget(guideWidget); + alllayout->addWidget(m_guideWidget); alllayout->addWidget(m_historywidget); } @@ -153,8 +143,29 @@ void MainWindow::initUI() m_infoCreateWidget->show(); m_bridge->createFileManager(FileProcess::g_date); } + if (m_historywidget == nullptr) { + m_historywidget = new HistoryWidget(); + m_historywidget->setMinimumHeight(2000); + alllayout->removeWidget(m_guideWidget); + alllayout->addWidget(m_guideWidget); + alllayout->addWidget(m_historywidget); + } m_historywidget->updateHistoryDir(); }); + + QFileSystemWatcher* watcher = new QFileSystemWatcher(this); + watcher->addPath(builderDir.absolutePath()); + connect(watcher, &QFileSystemWatcher::directoryChanged, this, [=](const QString& path) { + if (!builderDir.exists() || builderDir.isEmpty()) { + alllayout->removeWidget(m_guideWidget); + alllayout->removeItem(alllayout->itemAt(alllayout->count()-1)); + delete m_historywidget; + m_historywidget = nullptr; + alllayout->addStretch(1); + alllayout->addWidget(m_guideWidget); + alllayout->addStretch(1); + } + }); } void MainWindow::onGoHomeClicked() diff --git a/src/mainwindow.h b/src/mainwindow.h index 94af2c1..5f896df 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -77,5 +77,8 @@ private: TitleBar*m_titlebar; QPoint m_dragStartPosition; QPoint m_dragPosition; + + QWidget *m_guideWidget; + bool m_isHistoryDirUpdated = false; }; #endif // MAINWINDOW_H diff --git a/src/module/historywidget.cpp b/src/module/historywidget.cpp index e52432a..885273b 100644 --- a/src/module/historywidget.cpp +++ b/src/module/historywidget.cpp @@ -206,7 +206,6 @@ void HistoryButton::initUI() connect(btn_menu, &QPushButton::clicked, this, [=]() { m_menu->exec(btn_menu->mapToGlobal(btn_menu->rect().bottomLeft())); - qDebug()<<"aaaaaaaaaaaaa"; }); // 连接菜单选项的槽函数 connect(action1, &QAction::triggered, this, [=]() {