folderview.cpp
96 lines
| 3.0 KiB
| text/x-c
|
CppLexer
/ src / folderview.cpp
r0 | /*------------------------------------------------------------------------------ | |||
-- This file is a part of the QLop Software | ||||
-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | ||||
-- | ||||
-- This program is free software; you can redistribute it and/or modify | ||||
-- it under the terms of the GNU General Public License as published by | ||||
-- the Free Software Foundation; either version 2 of the License, or | ||||
-- (at your option) any later version. | ||||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
-------------------------------------------------------------------------------*/ | ||||
/*-- Author : Alexis Jeandet | ||||
-- Mail : alexis.jeandet@member.fsf.org | ||||
----------------------------------------------------------------------------*/ | ||||
#include "folderview.h" | ||||
#include "ui_folderview.h" | ||||
#include <QFileDialog> | ||||
#include <QLabel> | ||||
FolderView::FolderView(QWidget *parent) : | ||||
QDockWidget(parent), | ||||
ui(new Ui::FolderView) | ||||
{ | ||||
ui->setupUi(this); | ||||
this->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); | ||||
this->setAllowedAreas(Qt::AllDockWidgetAreas); | ||||
this->setWidget(this->ui->groupBox); | ||||
connect(this->ui->setFolderQpb,SIGNAL(clicked()),this,SLOT(openFolder())); | ||||
connect(this->ui->refreshQpb,SIGNAL(clicked()),this,SLOT(refreshFolder())); | ||||
connect(this->ui->listWidget,SIGNAL(itemActivated(QListWidgetItem*)),this,SLOT(itemActivated(QListWidgetItem*))); | ||||
} | ||||
FolderView::~FolderView() | ||||
{ | ||||
delete ui; | ||||
} | ||||
bool FolderView::contains(const QString &fileName) | ||||
{ | ||||
for(int i=0;i<this->ui->listWidget->count();i++) | ||||
{ | ||||
if(this->ui->listWidget->item(i)->text()==fileName) | ||||
{ | ||||
return true; | ||||
} | ||||
} | ||||
return false; | ||||
} | ||||
void FolderView::openFolder() | ||||
{ | ||||
currentFolder = QFileDialog::getExistingDirectory(this, tr("Open Directory"),NULL,QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); | ||||
refreshFolder(); | ||||
} | ||||
void FolderView::refreshFolder() | ||||
{ | ||||
QDir dir; | ||||
dir.setPath(currentFolder); | ||||
this->ui->listWidget->clear(); | ||||
dir.setFilter(QDir::Files | QDir::NoSymLinks); | ||||
dir.setSorting(QDir::Name); | ||||
QFileInfoList list = dir.entryInfoList(); | ||||
for (int i = 0; i < list.size(); ++i) | ||||
{ | ||||
if(!list.at(i).completeSuffix().compare("TAB")) | ||||
{ | ||||
this->ui->listWidget->addItem(list.at(i).fileName()); | ||||
} | ||||
} | ||||
this->ui->groupBox->setTitle(currentFolder); | ||||
} | ||||
void FolderView::itemActivated(QListWidgetItem *item) | ||||
{ | ||||
emit itemActivated(currentFolder+'/'+item->text()); | ||||
} | ||||
void FolderView::changeEvent(QEvent *e) | ||||
{ | ||||
QWidget::changeEvent(e); | ||||
switch (e->type()) { | ||||
case QEvent::LanguageChange: | ||||
ui->retranslateUi(this); | ||||
break; | ||||
default: | ||||
break; | ||||
} | ||||
} | ||||