add update historydir function

This commit is contained in:
likehomedream 2023-09-19 17:30:32 +08:00
parent 62c489e827
commit 497b195037
4 changed files with 88 additions and 24 deletions

View File

@ -90,8 +90,8 @@ void MainWindow::initUI()
helpDialog->show();
});
HistoryWidget *historyWidget = new HistoryWidget();
historyWidget->setMinimumHeight(2000);
m_historywidget = new HistoryWidget();
m_historywidget->setMinimumHeight(2000);
QDir builderDir = QDir::homePath()+"/.cache/theme-build/";
if(!builderDir.exists()|| builderDir.isEmpty()){
@ -105,7 +105,7 @@ void MainWindow::initUI()
alllayout->addLayout(layout);
alllayout->addStretch(1);
alllayout->addWidget(guideWidget);
alllayout->addWidget(historyWidget);
alllayout->addWidget(m_historywidget);
}
QIcon icon = QIcon(QPixmap(":/resource/background/homepage-global.png"));
@ -130,29 +130,31 @@ void MainWindow::initUI()
mainWidget = new QWidget;
mainWidget->setLayout(mainLayout);
QButtonGroup* buttonGroup = new QButtonGroup(this);
buttonGroup->addButton(m_globalbtn);
buttonGroup->addButton(m_iconbtn);
buttonGroup->addButton(m_cursorbtn);
connect(buttonGroup, QOverload<QAbstractButton*>::of(&QButtonGroup::buttonClicked), [=](QAbstractButton* button) {
m_stackedWidget->setCurrentWidget(m_maininterface);
connect(m_globalbtn, &QPushButton::clicked, [=]() {
m_stackedWidget->setCurrentWidget(m_maininterface);
m_maininterface->setGlobalTheme();
InfoCreateWidget *m_infoCreateWidget = new InfoCreateWidget(nullptr,m_fileProcess.FileCreate("globalTheme"),"recognise");
m_infoCreateWidget->show();
m_bridge->createFileManager(FileProcess::g_date);
if (button == m_globalbtn) {
m_maininterface->setGlobalTheme();
InfoCreateWidget* m_infoCreateWidget = new InfoCreateWidget(nullptr, m_fileProcess.FileCreate("globalTheme"), "recognise");
m_infoCreateWidget->show();
m_bridge->createFileManager(FileProcess::g_date);
} else if (button == m_iconbtn) {
m_maininterface->setIconTheme();
InfoCreateWidget* m_infoCreateWidget = new InfoCreateWidget(nullptr, m_fileProcess.FileCreate("iconTheme"), "recognise");
m_infoCreateWidget->show();
m_bridge->createFileManager(FileProcess::g_date);
} else if (button == m_cursorbtn) {
m_maininterface->setCursorTheme();
InfoCreateWidget* m_infoCreateWidget = new InfoCreateWidget(nullptr, m_fileProcess.FileCreate("cursorTheme"), "recognise");
m_infoCreateWidget->show();
m_bridge->createFileManager(FileProcess::g_date);
}
m_historywidget->updateHistoryDir();
});
connect(m_iconbtn, &QPushButton::clicked, [=]() {
m_stackedWidget->setCurrentWidget(m_maininterface);
m_maininterface->setIconTheme();
InfoCreateWidget *m_infoCreateWidget = new InfoCreateWidget(nullptr,m_fileProcess.FileCreate("iconTheme"),"recognise");
m_infoCreateWidget->show();
m_bridge->createFileManager(FileProcess::g_date);
});
connect(m_cursorbtn, &QPushButton::clicked, [=]() {
m_stackedWidget->setCurrentWidget(m_maininterface);
m_maininterface->setCursorTheme();
InfoCreateWidget *m_infoCreateWidget = new InfoCreateWidget(nullptr,m_fileProcess.FileCreate("cursorTheme"),"recognise");
m_infoCreateWidget->show();
m_bridge->createFileManager(FileProcess::g_date);
});
}
void MainWindow::onGoHomeClicked()

View File

@ -53,6 +53,7 @@ public slots:
void onGoHomeClicked();
private:
HistoryWidget *m_historywidget;
void setResizeCursor(ResizeRegion region);
ResizeRegion getResizeRegion(QPoint clientPos);
void handleMove(QPoint pt);

View File

@ -66,10 +66,70 @@ HistoryWidget::HistoryWidget(QWidget *parent) : QWidget(parent)
this->setLayout(alllayout);
}
void HistoryWidget::updateHistoryDir()
{
QDir builderDir = QDir(QDir::homePath() + "/.cache/theme-build/");
QStringList folders = builderDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
QList<QString> validFolders;
QDateTime currentDate = QDateTime::currentDateTime();
foreach (QString folder, folders) {
QString yearStr = folder.mid(0, 4);
QString monthStr = folder.mid(4, 2);
QString dayStr = folder.mid(6, 2);
QString hourStr = folder.mid(8, 2);
QString minuteStr = folder.mid(10, 2);
QString secondStr = folder.mid(12, 2);
QDateTime folderDateTime = QDateTime::fromString(yearStr + monthStr + dayStr + hourStr + minuteStr + secondStr, "yyyyMMddhhmmss");
if (folderDateTime.isValid() && folderDateTime.daysTo(currentDate) <= 30) {
qDebug() << "Processing folder222: " << folder;
validFolders.append(folder);
}
}
QGridLayout *layout = new QGridLayout;
int row = 0;
int col = 0;
foreach (QString folder, validFolders) {
HistoryButton *button = new HistoryButton(this);
button->setHistoryTime(folder);
button->setCover();
button->setThemeName();
button->setThemeType();
button->initUI();
layout->addWidget(button, row, col);
col++;
if (col == 4) {
col = 0;
row++;
}
}
QWidget *widget = new QWidget(this);
widget->setLayout(layout);
QVBoxLayout *alllayout = qobject_cast<QVBoxLayout*>(this->layout());
if (alllayout) {
// 删除原来的widget
while (QWidget* w = alllayout->takeAt(1)->widget()) { // 从索引1开始因为索引0是textWidget
delete w;
}
alllayout->addWidget(widget);
alllayout->addStretch(1);
}
}
HistoryButton::HistoryButton(QWidget* parent): QPushButton(parent)
{
this->setFixedSize(240, 280);
}
void HistoryButton::setHistoryTime(const QString &text)
{
m_historytime = text;

View File

@ -33,6 +33,7 @@ class HistoryWidget : public QWidget
Q_OBJECT
public:
explicit HistoryWidget(QWidget *parent = nullptr);
void updateHistoryDir();
signals: