Skip to content

Commit

Permalink
FileBrowser: modify option menu
Browse files Browse the repository at this point in the history
  • Loading branch information
KangLin committed Sep 23, 2024
1 parent bf8b177 commit 5e90233
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 71 deletions.
130 changes: 60 additions & 70 deletions Src/FileBrowser/FileBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ CFileBrowser::CFileBrowser(QWidget *parent)
, m_pList(nullptr)
, m_pTable(nullptr)
, m_pTextEdit(nullptr)
, m_bAssociated(true)
, m_pHiddenFile(nullptr)
, m_pAssociated(nullptr)
, m_pOrientation(nullptr)
{
bool check = false;
setAttribute(Qt::WA_DeleteOnClose);
Expand Down Expand Up @@ -86,17 +88,18 @@ CFileBrowser::CFileBrowser(QWidget *parent)
});
pAction->setStatusTip(szTitle);
szTitle = tr("Delete folder");
pAction = pToolBar->addAction(QIcon::fromTheme("edit-delete"), szTitle,
this, [&](){
QString szDir;
QModelIndex index = m_pTree->currentIndex();
szDir = m_pModel->data(index).toString();
bool bRet = m_pModel->rmdir(index);
if(bRet)
qDebug(log) << "Delete folder:" << szDir;
else
qCritical(log) << "Delete folder fail" << szDir;
});
pAction = pToolBar->addAction(
QIcon::fromTheme("edit-delete"), szTitle,
this, [&](){
QString szDir;
QModelIndex index = m_pTree->currentIndex();
szDir = m_pModel->data(index).toString();
bool bRet = m_pModel->rmdir(index);
if(bRet)
qDebug(log) << "Delete folder:" << szDir;
else
qCritical(log) << "Delete folder fail" << szDir;
});
pAction->setStatusTip(szTitle);
szTitle = tr("Option");
QToolButton* pButtonOption = new QToolButton(pToolBar);
Expand All @@ -105,81 +108,68 @@ CFileBrowser::CFileBrowser(QWidget *parent)
QMenu* pMenuOption = new QMenu(szTitle, pButtonOption);
pButtonOption->setMenu(pMenuOption);
pToolBar->addWidget(pButtonOption);

szTitle = tr("Hidden file");
QCheckBox* pHiddenFile = new QCheckBox(szTitle);
m_pHiddenFile = pMenuOption->addAction(
szTitle, this,
[&]() {
bool checked = m_pHiddenFile->isChecked();
if(checked)
m_pModel->setFilter(m_pModel->filter() | QDir::Hidden);
else
m_pModel->setFilter(m_pModel->filter() & (~QDir::Hidden));
QSettings set(RabbitCommon::CDir::Instance()->GetFileUserConfigure(),
QSettings::IniFormat);
set.setValue("FileBrowser/HiddenFile", checked);
});
check = set.value("FileBrowser/HiddenFile", check).toBool();
pHiddenFile->setStatusTip(szTitle);
pHiddenFile->setToolTip(szTitle);
pHiddenFile->setCheckable(true);
pHiddenFile->setChecked(check);
m_pHiddenFile->setStatusTip(szTitle);
m_pHiddenFile->setToolTip(szTitle);
m_pHiddenFile->setCheckable(true);
m_pHiddenFile->setChecked(check);
if(check)
m_pModel->setFilter(m_pModel->filter() | QDir::Hidden);
else
m_pModel->setFilter(m_pModel->filter() & (~QDir::Hidden));
check = connect(pHiddenFile, &QCheckBox::clicked, this,
[&](bool checked){
if(checked)
m_pModel->setFilter(m_pModel->filter() | QDir::Hidden);
else
m_pModel->setFilter(m_pModel->filter() & (~QDir::Hidden));
QSettings set(RabbitCommon::CDir::Instance()->GetFileUserConfigure(),
QSettings::IniFormat);
set.setValue("FileBrowser/HiddenFile", checked);
});
Q_ASSERT(check);
QWidgetAction* pWidgetAction = new QWidgetAction(this);
pWidgetAction->setDefaultWidget(pHiddenFile);
pWidgetAction->setStatusTip(szTitle);
pMenuOption->addAction(qobject_cast<QAction*>(pWidgetAction));

szTitle = tr("Open with the System Associated Program");
QCheckBox* pAssociated = new QCheckBox(szTitle);
pAssociated->setStatusTip(szTitle);
pAssociated->setToolTip(szTitle);
m_bAssociated = set.value("FileBrowser/SystemAssociatedProgram", m_bAssociated).toBool();
pAssociated->setCheckable(true);
pAssociated->setChecked(m_bAssociated);
check = connect(pAssociated, &QCheckBox::clicked, this,
[&](bool checked){
m_bAssociated = checked;
QSettings set(RabbitCommon::CDir::Instance()->GetFileUserConfigure(),
QSettings::IniFormat);
set.setValue("FileBrowser/SystemAssociatedProgram", checked);
});
Q_ASSERT(check);
pWidgetAction = new QWidgetAction(this);
pWidgetAction->setDefaultWidget(pAssociated);
pWidgetAction->setStatusTip(szTitle);
pMenuOption->addAction(qobject_cast<QAction*>(pWidgetAction));
m_pAssociated = pMenuOption->addAction(
szTitle, this, [&](){
QSettings set(RabbitCommon::CDir::Instance()->GetFileUserConfigure(),
QSettings::IniFormat);
set.setValue("FileBrowser/SystemAssociatedProgram", m_pAssociated->isChecked());
});
m_pAssociated->setStatusTip(szTitle);
m_pAssociated->setToolTip(szTitle);
m_pAssociated->setCheckable(true);
m_pAssociated->setChecked(set.value("FileBrowser/SystemAssociatedProgram", m_pAssociated->isChecked()).toBool());

szTitle = tr("Horizontal");
QCheckBox* pOrientation = new QCheckBox(szTitle);
pOrientation->setStatusTip(szTitle);
pOrientation->setToolTip(szTitle);
pOrientation->setCheckable(true);
m_pOrientation = pMenuOption->addAction(
szTitle, this, [&](){
bool checked = m_pOrientation->isChecked();
if(checked)
m_pSpliter->setOrientation(Qt::Horizontal);
else
m_pSpliter->setOrientation(Qt::Vertical);
QSettings set(RabbitCommon::CDir::Instance()->GetFileUserConfigure(),
QSettings::IniFormat);
set.setValue("FileBrowser/Spliter/Horizontal", checked);
});
m_pOrientation->setStatusTip(szTitle);
m_pOrientation->setToolTip(szTitle);
m_pOrientation->setCheckable(true);
#if defined(Q_OS_ANDROID)
check = false;
#else
check = true;
#endif
check = set.value("FileBrowser/Spliter/Horizontal", check).toBool();
pOrientation->setChecked(check);
m_pOrientation->setChecked(check);
if(check)
m_pSpliter->setOrientation(Qt::Horizontal);
else
m_pSpliter->setOrientation(Qt::Vertical);
check = connect(pOrientation, &QCheckBox::clicked, this,
[&](bool checked){
if(checked)
m_pSpliter->setOrientation(Qt::Horizontal);
else
m_pSpliter->setOrientation(Qt::Vertical);
QSettings set(RabbitCommon::CDir::Instance()->GetFileUserConfigure(),
QSettings::IniFormat);
set.setValue("FileBrowser/Spliter/Horizontal", checked);
});
pWidgetAction = new QWidgetAction(this);
pWidgetAction->setDefaultWidget(pOrientation);
pWidgetAction->setStatusTip(szTitle);
pMenuOption->addAction(qobject_cast<QAction*>(pWidgetAction));

pLayout->addWidget(pToolBar);
pLayout->addWidget(m_pSpliter);
Expand Down Expand Up @@ -345,7 +335,7 @@ QString CFileBrowser::readFile(const QString &filePath)

int CFileBrowser::ShowFile(const QString &szFile)
{
if(m_bAssociated) {
if(m_pAssociated->isChecked()) {
QUrl url = QUrl::fromLocalFile(szFile);
if(QDesktopServices::openUrl(url))
return 0;
Expand Down
6 changes: 5 additions & 1 deletion Src/FileBrowser/FileBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QTableView>
#include <QTextEdit>
#include <QSplitter>
#include <QAction>
#include "rabbitcommon_export.h"

class RABBITCOMMON_EXPORT CFileBrowser : public QWidget
Expand Down Expand Up @@ -43,7 +44,10 @@ class RABBITCOMMON_EXPORT CFileBrowser : public QWidget
QListView* m_pList;
QTableView* m_pTable;
QTextEdit* m_pTextEdit;
bool m_bAssociated;

QAction* m_pHiddenFile;
QAction* m_pAssociated;
QAction* m_pOrientation;
};

class RABBITCOMMON_EXPORT CDlgFileBrowser : public QDialog
Expand Down

0 comments on commit 5e90233

Please sign in to comment.