#include "stadfx.h"
#include "CGetFilesView.h"
#include "CTableView.h"
#include "CTableModel.h"
#include "ItemDelegate.h"
#include "CScanThread.h"
CGetFilesView::CGetFilesView( QWidget *parent /*= 0*/ )
{
this->setFixedSize(600,500);
m_pScanThread = NULL;
m_findFilesModel = NULL;
m_bIsScanning = false;
iniWidgetContents();
QColor color(255,255,255);
m_Palette.setColor(QPalette::Text,color);
//m_theme = CreateThemes("SuperG");
}
CGetFilesView::~CGetFilesView()
{
}
void CGetFilesView::iniWidgetContents()
{
m_selectFrame = new QFrame(this);
m_selectFrame->setGeometry(0,0,600,500);
//m_selectFrame->setStyleSheet("QFrame{background-color: #2F2F2F}");
//m_selectFrame->setHidden(true);
QVBoxLayout *vSeleLayout = new QVBoxLayout(m_selectFrame);
vSeleLayout->setSpacing(0);
vSeleLayout->setContentsMargins(10,10,10,10);
QLabel *title = new QLabel("请选择要扫描的文件夹:");
title->setPalette(m_Palette);
m_pFileModel = new QFileSystemModel;
m_pFileModel->setRootPath(QDir::currentPath());
m_pFileModel->setFilter(QDir::NoDotAndDotDot | QDir::Dirs);
m_pFileTree = new QTreeView();
m_pFileTree->setPalette(m_Palette);
m_pFileTree->header()->setHidden(true);
m_pFileTree->setModel(m_pFileModel);
m_pFileTree->setColumnHidden(1,true);
m_pFileTree->setColumnHidden(2,true);
m_pFileTree->setColumnHidden(3,true);
QPushButton *btnScan = new QPushButton("Scan");
btnScan->setFixedSize(100,40);
connect(btnScan,SIGNAL(clicked()),this,SLOT(slotStartScan()));
vSeleLayout->addWidget(title,0);
vSeleLayout->addSpacing(10);
vSeleLayout->addWidget(m_pFileTree,0);
vSeleLayout->addSpacing(10);
vSeleLayout->addWidget(btnScan,0);
vSeleLayout->setAlignment(btnScan,Qt::AlignRight);
m_scanFrame = new QFrame(this);
m_scanFrame->setGeometry(0,0,600,500);
m_scanFrame->setHidden(true);
//m_scanFrame->setStyleSheet("QFrame{background-color: #2F2F2F}");
QVBoxLayout *vScanLayout = new QVBoxLayout(m_scanFrame);
vScanLayout->setSpacing(0);
vScanLayout->setContentsMargins(10,10,10,10);
m_labShowMessage = new QLabel;
m_labShowMessage->setFixedSize(510,30);
m_labShowMessage->setWordWrap(true);
m_findFilesModel = new CTableModel(m_scanFrame);
m_tableDelegate = new ItemDelegate();
connect(m_tableDelegate,SIGNAL(checkStateChanged(bool,QModelIndex)),m_findFilesModel,SLOT(slotDataChange(bool,QModelIndex)));
m_btnStop = new QPushButton("停止");
m_btnStop->setFixedSize(70,30);
connect(m_btnStop,SIGNAL(clicked()),this,SLOT(slotStopScan()));
QHBoxLayout *hTopLayout = new QHBoxLayout(m_scanFrame);
hTopLayout->setSpacing(0);
hTopLayout->addWidget(m_labShowMessage);
hTopLayout->addStretch();
hTopLayout->addWidget(m_btnStop);
hTopLayout->setAlignment(m_btnStop,Qt::AlignRight);
m_findFilesView = new CTableView();
m_findFilesView->setModel(m_findFilesModel);
m_findFilesView->setItemDelegate(m_tableDelegate);
m_findFilesView->iniHeaderSection();
connect(m_findFilesView,SIGNAL(currentRowChanged(int)),this,SLOT(slotRowChanged(int)));
m_btnCheckAll = new QCheckBox(m_findFilesView);
m_btnCheckAll->setGeometry(10,12,16,16);
connect(m_btnCheckAll,SIGNAL(stateChanged(int)),m_findFilesModel,SLOT(slotAllStateChange(int)));
m_btnImport = new QPushButton("导入");
m_btnImport->setEnabled(false);
m_btnImport->setFixedSize(70,30);
m_btnCancel = new QPushButton("返回");
m_btnCancel->setEnabled(false);
m_btnCancel->setFixedSize(70,30);
connect(m_btnCancel,SIGNAL(clicked()),this,SLOT(slotRescan()));
QHBoxLayout *hBottomLayout = new QHBoxLayout;
hBottomLayout->setSpacing(0);
hBottomLayout->addStretch();
hBottomLayout->addWidget(m_btnImport);
hBottomLayout->addSpacing(20);
hBottomLayout->addWidget(m_btnCancel);
vScanLayout->addLayout(hTopLayout);
vScanLayout->addSpacing(10);
vScanLayout->addWidget(m_findFilesView);
vScanLayout->addSpacing(10);
vScanLayout->addLayout(hBottomLayout);
}
void CGetFilesView::slotStartScan()
{
QModelIndex index = m_pFileTree->currentIndex();
QString strDirPath = m_pFileModel->filePath(index);
if (strDirPath != "")
{
SAFE_DELETE(m_pScanThread);
m_pScanThread = new ScanThread();
connect(m_pScanThread,SIGNAL(currentFile(QString)),this,SLOT(slotShowCurrentFile(QString)));
connect(m_pScanThread,SIGNAL(newFileFind()),this,SLOT(slotAddFile()));
connect(m_pScanThread,SIGNAL(finishScan()),this,SLOT(slotFinishScan()));
m_pScanThread->setScanDir(strDirPath);
m_pScanThread->start();
}
m_selectFrame->setHidden(true);
m_scanFrame->setHidden(false);
m_bIsScanning = true;
m_btnStop->setHidden(false);
m_btnCheckAll->setEnabled(false);
m_btnImport->setEnabled(false);
m_btnCancel->setEnabled(false);
}
void CGetFilesView::slotShowCurrentFile( QString name )
{
m_labShowMessage->setText(name);
}
void CGetFilesView::slotAddFile( )
{
QFileInfo tempInfo = m_pScanThread->getNewFile();
m_findFilesModel->AddFile(tempInfo);
int rowCount = m_findFilesModel->rowCount();
m_findFilesView->setRowsHeight(rowCount);
}
void CGetFilesView::slotFinishScan()
{
QModelIndex index = m_pFileTree->currentIndex();
QString strDirPath = m_pFileModel->filePath(index);
strDirPath = "扫描路径:" + strDirPath;
m_labShowMessage->setText("扫描完成," + strDirPath);
int nRowCount = m_findFilesModel->rowCount();
if (nRowCount == 0)
{
QMessageBox::information(this,"提示","该目录下没有找到符合条件的文件。");
}
m_btnStop->setHidden(true);
m_bIsScanning = false;
m_btnCheckAll->setEnabled(true);
m_btnImport->setEnabled(true);
m_btnCancel->setEnabled(true);
}
void CGetFilesView::slotRowChanged( int row)
{
m_tableDelegate->setCurrentRow(row);
}
void CGetFilesView::slotRescan()
{
if (m_findFilesModel->rowCount() > 0)
{
QMessageBox *messageBox = new QMessageBox(this);
messageBox->setIcon(QMessageBox::Question);
messageBox->setText("已经找到相关文件。你是否要清除当前结果重新扫描?");
/*messageBox->setInformativeText("你是否要清除当前结果重新扫描?");*/
messageBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
messageBox->setDefaultButton(QMessageBox::Yes);
messageBox->setButtonText(QMessageBox::Yes,"是");
messageBox->setButtonText(QMessageBox::No,"否");
messageBox->setFixedSize(300,200);
int ret = messageBox->exec();
if (ret == QMessageBox::No)
{
return;
}
}
disconnect(m_btnCheckAll,SIGNAL(stateChanged(int)),m_findFilesModel,SLOT(slotAllStateChange(int)));
m_tableDelegate->setCurrentRow(-1);
m_scanFrame->setHidden(true);
m_selectFrame->setHidden(false);
m_btnCheckAll->setCheckState(Qt::Unchecked);
SAFE_DELETE(m_findFilesModel);
m_findFilesModel = new CTableModel(m_findFilesView);
connect(m_btnCheckAll,SIGNAL(stateChanged(int)),m_findFilesModel,SLOT(slotAllStateChange(int)));
m_findFilesView->setModel(m_findFilesModel);
}
void CGetFilesView::slotStopScan()
{
m_pScanThread->stop();
}
void CGetFilesView::closeEvent ( QCloseEvent * event )
{
if (m_findFilesModel)
{
if (m_findFilesModel->rowCount() > 0)
{
QMessageBox *messageBox = new QMessageBox(this);
messageBox->setIcon(QMessageBox::Question);
messageBox->setText("已经找到相关文件。你是否要清除当前结果退出程序?");
/*messageBox->setInformativeText("你是否要清除当前结果重新扫描?");*/
messageBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
messageBox->setDefaultButton(QMessageBox::Yes);
messageBox->setButtonText(QMessageBox::Yes,"是");
messageBox->setButtonText(QMessageBox::No,"否");
messageBox->setFixedSize(300,200);
int ret = messageBox->exec();
if (ret == QMessageBox::No)
{
event->ignore();
}
else
{
event->accept();
}
}
}
}
- 1
- 2
- 3
前往页