Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/source/common/uistruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define TEMPPATH DStandardPaths::writableLocation(QStandardPaths::TempLocation) // 临时路径(打开等操作)
#define MAINWINDOW_WIDTH_NAME "MainWindowWidthName" // 主界宽
#define MAINWINDOW_HEIGHT_NAME "MainWindowHeightName" // 主界面高
#define MAINWINDOW_STATE_NAME "MainWindowStateName" // 主界面窗口状态
#define ORDER_JSON "OrderJson" // 编辑json
#define ORDER_EDIT "edit" // 编辑权限
#define ORDER_RENAME "rename" // 重命名权限
Expand Down
54 changes: 47 additions & 7 deletions src/source/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@
#include <QThreadPool>
#include <QtConcurrent/QtConcurrent>
#include <QScreen>
#include <QFormLayout>

Check warning on line 49 in src/source/mainwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFormLayout> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QShortcut>

Check warning on line 50 in src/source/mainwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QShortcut> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QJsonObject>

Check warning on line 51 in src/source/mainwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTimer>

Check warning on line 52 in src/source/mainwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#ifdef DTKCORE_CLASS_DConfigFile
#include <DConfig>

Check warning on line 54 in src/source/mainwindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DConfig> not found. Please note: Cppcheck does not need standard library headers to get proper results.
DCORE_USE_NAMESPACE
#endif

Expand Down Expand Up @@ -90,7 +91,7 @@
MainWindow::~MainWindow()
{
// 保存窗口大小状态
saveConfigWinSize(width(), height());
saveConfigWinState();

ArchiveManager::get_instance()->destory_instance();

Expand Down Expand Up @@ -197,7 +198,7 @@
m_pSettings->setValue("dir", "");
}

resize(getConfigWinSize()); // 设置窗口尺寸
restoreConfigWinState(); // 恢复窗口状态(大小和最大化状态)
setMinimumSize(620, 300); // task 16309调整最小大小
}

Expand Down Expand Up @@ -2243,15 +2244,54 @@
return QSize(winWidth, winHeight);
}

void MainWindow::saveConfigWinSize(int w, int h)
void MainWindow::saveConfigWinState()
{
int winWidth = w > MAINWINDOW_DEFAULTW ? w : MAINWINDOW_DEFAULTW;
int winHeight = h > MAINWINDOW_DEFAULTH ? h : MAINWINDOW_DEFAULTH;
m_pSettings->setValue(MAINWINDOW_HEIGHT_NAME, winHeight);
m_pSettings->setValue(MAINWINDOW_WIDTH_NAME, winWidth);
// 如果窗口是最大化状态,保存最大化标志和正常尺寸
if (isMaximized()) {
m_pSettings->setValue(MAINWINDOW_STATE_NAME, Qt::WindowMaximized);
// 对于最大化窗口,我们需要保存正常尺寸而不是最大化尺寸
// 使用默认尺寸或之前保存的正常尺寸
QVariant tempWidth = m_pSettings->value(MAINWINDOW_WIDTH_NAME);
QVariant tempHeight = m_pSettings->value(MAINWINDOW_HEIGHT_NAME);

if (!tempWidth.isValid() || !tempHeight.isValid()) {
// 如果没有之前保存的尺寸,使用默认尺寸
m_pSettings->setValue(MAINWINDOW_WIDTH_NAME, MAINWINDOW_DEFAULTW);
m_pSettings->setValue(MAINWINDOW_HEIGHT_NAME, MAINWINDOW_DEFAULTH);
}
// 如果有之前保存的尺寸,保持不变(不更新为最大化尺寸)
} else {
// 正常状态,保存当前尺寸和状态
m_pSettings->setValue(MAINWINDOW_STATE_NAME, Qt::WindowNoState);
// 保存窗口尺寸
int w = width();
int h = height();
int winWidth = w > MAINWINDOW_DEFAULTW ? w : MAINWINDOW_DEFAULTW;
int winHeight = h > MAINWINDOW_DEFAULTH ? h : MAINWINDOW_DEFAULTH;
m_pSettings->setValue(MAINWINDOW_HEIGHT_NAME, winHeight);
m_pSettings->setValue(MAINWINDOW_WIDTH_NAME, winWidth);
}
m_pSettings->sync();
}

void MainWindow::restoreConfigWinState()
{
// 获取保存的窗口状态
Qt::WindowState savedState = static_cast<Qt::WindowState>(
m_pSettings->value(MAINWINDOW_STATE_NAME, Qt::WindowNoState).toInt());

// 先设置正常尺寸
resize(getConfigWinSize());

// 然后应用状态
if (savedState == Qt::WindowMaximized) {
// 使用QTimer延迟执行,确保窗口完全初始化后再最大化
QTimer::singleShot(0, this, [this]() {
showMaximized();
});
}
}

void MainWindow::convertArchive(const QString &convertType)
{
qInfo() << "对压缩包进行格式转换" << convertType;
Expand Down
17 changes: 10 additions & 7 deletions src/source/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ public :
*/
void handleQuit();

/**
* @brief saveConfigWinState 保存窗口状态(大小和最大化状态)
*/
void saveConfigWinState();

/**
* @brief restoreConfigWinState 恢复窗口状态(大小和最大化状态)
*/
void restoreConfigWinState();

private:
/**
* @brief initUI 初始化界面
Expand Down Expand Up @@ -223,13 +233,6 @@ public :
*/
QSize getConfigWinSize();

/**
* @brief saveConfigWinSize 保存窗口尺寸
* @param w 宽度
* @param h 高度
*/
void saveConfigWinSize(int w, int h);

/**
* @brief convertArchive 格式转换
* @param convertType 转换后的文件类型
Expand Down
6 changes: 0 additions & 6 deletions tests/UnitTest/src/source/ut_mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1555,12 +1555,6 @@ TEST_F(UT_MainWindow, test_getConfigWinSize)
EXPECT_NE(m_tester->getConfigWinSize().width(), 0);
}

TEST_F(UT_MainWindow, testsaveConfigWinSize)
{
m_tester->saveConfigWinSize(800, 600);
EXPECT_EQ(m_tester->m_pSettings->value(MAINWINDOW_WIDTH_NAME).toInt(), 800);
EXPECT_EQ(m_tester->m_pSettings->value(MAINWINDOW_HEIGHT_NAME).toInt(), 600);
}

TEST_F(UT_MainWindow, test_convertArchive)
{
Expand Down