folderview.cpp
165 lines
| 4.5 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> | ||||
r1 | #include <QDebug> | |||
r0 | ||||
r1 | p_FolderView::p_FolderView(QWidget *parent) : | |||
QWidget(parent), | ||||
ui(new Ui::p_FolderView) | ||||
r0 | { | |||
ui->setupUi(this); | ||||
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*))); | ||||
r1 | //this->ui->listWidget->installEventFilter(this); | |||
connect(this->ui->listWidget,SIGNAL(askGlobalRescan()),this,SIGNAL(askGlobalRescan())); | ||||
r0 | } | |||
r1 | p_FolderView::~p_FolderView() | |||
r0 | { | |||
delete ui; | ||||
} | ||||
r1 | bool p_FolderView::contains(const QString &fileName) | |||
r0 | { | |||
for(int i=0;i<this->ui->listWidget->count();i++) | ||||
{ | ||||
if(this->ui->listWidget->item(i)->text()==fileName) | ||||
{ | ||||
return true; | ||||
} | ||||
} | ||||
return false; | ||||
} | ||||
r1 | bool p_FolderView::isDraging(const QString &name) | |||
{ | ||||
return this->ui->listWidget->isDraging(name); | ||||
} | ||||
void p_FolderView::setMainWindow(MainWindow *mw) | ||||
r0 | { | |||
r1 | this->ui->listWidget->setMainWindow(mw); | |||
} | ||||
QString p_FolderView::currentFolder() | ||||
{ | ||||
return p_currentFolder; | ||||
} | ||||
void p_FolderView::openFolder() | ||||
{ | ||||
p_currentFolder = QFileDialog::getExistingDirectory(this, tr("Open Directory"),NULL,QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); | ||||
r0 | refreshFolder(); | |||
} | ||||
r1 | void p_FolderView::refreshFolder() | |||
r0 | { | |||
QDir dir; | ||||
r1 | dir.setPath(p_currentFolder); | |||
r0 | 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()); | ||||
} | ||||
} | ||||
r1 | this->ui->listWidget->setPath(p_currentFolder); | |||
this->ui->groupBox->setTitle(p_currentFolder); | ||||
r0 | } | |||
r1 | void p_FolderView::itemActivated(QListWidgetItem *item) | |||
r0 | { | |||
r1 | emit itemActivated(p_currentFolder+'/'+item->text()); | |||
r0 | } | |||
r1 | void p_FolderView::changeEvent(QEvent *e) | |||
r0 | { | |||
QWidget::changeEvent(e); | ||||
switch (e->type()) { | ||||
case QEvent::LanguageChange: | ||||
ui->retranslateUi(this); | ||||
break; | ||||
default: | ||||
break; | ||||
} | ||||
} | ||||
r1 | ||||
bool p_FolderView::eventFilter(QObject *object, QEvent *event) | ||||
{ | ||||
if(object == this->ui->listWidget ) | ||||
{ | ||||
qDebug()<<event->type(); | ||||
if(event->type() == QEvent::Drop) | ||||
{ | ||||
QDropEvent *DropEvent = static_cast<QDropEvent *>(event); | ||||
qDebug()<< DropEvent->mimeData(); | ||||
} | ||||
} | ||||
return false; | ||||
} | ||||
FolderView::FolderView(MainWindow *parent) | ||||
:QDockWidget(parent) | ||||
{ | ||||
this->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); | ||||
this->setAllowedAreas(Qt::AllDockWidgetAreas); | ||||
this->ui = new p_FolderView(this); | ||||
this->setWidget(this->ui); | ||||
connect(this->ui,SIGNAL(itemActivated(QString)),this,SIGNAL(itemActivated(QString))); | ||||
connect(this->ui,SIGNAL(askGlobalRescan()),this,SIGNAL(askGlobalRescan())); | ||||
this->ui->setMainWindow(parent); | ||||
} | ||||
bool FolderView::contains(const QString &fileName) | ||||
{ | ||||
return ui->contains(fileName); | ||||
} | ||||
bool FolderView::isDraging(const QString &name) | ||||
{ | ||||
return this->ui->isDraging(name); | ||||
} | ||||
QString FolderView::currentFolder() | ||||
{ | ||||
return this->ui->currentFolder(); | ||||
} | ||||
void FolderView::openFolder() | ||||
{ | ||||
this->ui->openFolder(); | ||||
} | ||||
void FolderView::refreshFolder() | ||||
{ | ||||
this->ui->refreshFolder(); | ||||
} | ||||