/*************directoryViewer.cpp*********************/
#include <QtGui>
#include "directoryviewer.h"
DirectoryViewer::DirectoryViewer(QWidget *parent)
: QTreeView(parent)
{
model = new QDirModel;
model->setReadOnly(false);
model->setSorting(QDir::DirsFirst | QDir::IgnoreCase | QDir::Name);
treeView = new QTreeView;
this->setModel(model);
this->header()->setStretchLastSection(true);
this->header()->setSortIndicator(0, Qt::AscendingOrder);
this->header()->setSortIndicatorShown(true);
this->header()->setClickable(true);
QModelIndex index = model->index(QDir::homePath());
this->expand(index);
this->scrollTo(index);
this->resizeColumnToContents(0);
//connect(index,SIGNAL(clicked),)
/*
buttonBox = new QDialogButtonBox(Qt::Horizontal);
QPushButton *mkdirButton = buttonBox->addButton(
tr("&Create Directory..."), QDialogButtonBox::ActionRole);
QPushButton *removeButton = buttonBox->addButton(tr("&Remove"),
QDialogButtonBox::ActionRole);
buttonBox->addButton(tr("&Quit"), QDialogButtonBox::AcceptRole);
connect(mkdirButton, SIGNAL(clicked()),
this, SLOT(createDirectory()));
connect(removeButton, SIGNAL(clicked()), this, SLOT(remove()));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
*/
// QVBoxLayout *mainLayout = new QVBoxLayout;
//mainLayout->addWidget(treeView);
//mainLayout->addWidget(buttonBox);
//setLayout(mainLayout);
//setWindowTitle(tr("Directory Viewer"));
}
/*
void DirectoryViewer::createDirectory()
{
QModelIndex index = treeView->currentIndex();
if (!index.isValid())
return;
QString dirName = QInputDialog::getText(this,
tr("Create Directory"),
tr("Directory name"));
if (!dirName.isEmpty()) {
if (!model->mkdir(index, dirName).isValid())
QMessageBox::information(this, tr("Create Directory"),
tr("Failed to create the directory"));
}
}
void DirectoryViewer::remove()
{
QModelIndex index = treeView->currentIndex();
if (!index.isValid())
return;
bool ok;
if (model->fileInfo(index).isDir()) {
ok = model->rmdir(index);
} else {
ok = model->remove(index);
}
if (!ok)
QMessageBox::information(this, tr("Remove"),
tr("Failed to remove %1").arg(model->fileName(index)));
}
*/
/*
void DirectoryViewer::mousePressEvent(QMouseEvent *event)
{
bool ok;
if (event->button() == Qt::LeftButton) {
QModelIndex index = this->currentIndex();
if (model->fileInfo(index).isDir()) {
this->expand(index);
ok = true;
} else {
model->remove(index);
ok = true;
}
if (!ok)
QMessageBox::information(this, tr("Remove"),
tr("Failed to remove %1").arg(model->fileName(index)));
} else {
QTreeView::mousePressEvent(event);
}
//QTreeView::mousePressEvent(event);
}
*/
void DirectoryViewer::isClicked(QModelIndex index)
{
index = this->currentIndex();
}