--- /dev/null
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
+//
+// EmuFront 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 EmuFront. If not, see <http://www.gnu.org/licenses/>.
+
+#include "filesystembrowsedelegate.h"
+#include "filepathselectorwidget.h"
+
+FileSystemBrowseDelegate::FileSystemBrowseDelegate(QWidget *parent) :
+ QStyledItemDelegate(parent)
+{
+}
+
+QWidget* FileSystemBrowseDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ FilePathSelectorWidget *editor = new FilePathSelectorWidget(parent);
+ connect(editor, SIGNAL(filePathUpdated()), this, SLOT(commitAndCloseEditor()));
+ return editor;
+}
+
+void FileSystemBrowseDelegate::commitAndCloseEditor()
+{
+ FilePathSelectorWidget *editor = qobject_cast<FilePathSelectorWidget *>(sender());
+ emit commitData(editor);
+ emit closeEditor(editor);
+}
+
+void FileSystemBrowseDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
+{
+ FilePathSelectorWidget *wdg = qobject_cast<FilePathSelectorWidget *>(editor);
+ QString path = wdg->getFilePath();
+ model->setData(index, path);
+}
+
+void FileSystemBrowseDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
+{
+ QString path = index.model()->data(index, Qt::DisplayRole).toString();
+ FilePathSelectorWidget *fpwdg = qobject_cast<FilePathSelectorWidget *>(editor);
+ fpwdg->setFilePath(path);
+}
--- /dev/null
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
+//
+// EmuFront 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 EmuFront. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef FILESYSTEMBROWSEDELEGATE_H
+#define FILESYSTEMBROWSEDELEGATE_H
+
+#include <QStyledItemDelegate>
+
+class FileSystemBrowseDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+public:
+ explicit FileSystemBrowseDelegate(QWidget *parent = 0);
+ QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
+ void setEditorData(QWidget *editor, const QModelIndex &index) const;
+ void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
+
+private slots:
+ void commitAndCloseEditor();
+
+};
+
+#endif // FILESYSTEMBROWSEDELEGATE_H
delegates/comboboxdelegate.h \
delegates/stringlistdelegate.h \
models/filepathmodel.h \
- views/filepatheditview.h
+ views/filepatheditview.h \
+ delegates/filesystembrowsedelegate.h \
+ widgets/filepathselectorwidget.h
SOURCES += main.cpp \
mainwindow.cpp \
db/databasemanager.cpp \
delegates/comboboxdelegate.cpp \
delegates/stringlistdelegate.cpp \
models/filepathmodel.cpp \
- views/filepatheditview.cpp
+ views/filepatheditview.cpp \
+ delegates/filesystembrowsedelegate.cpp \
+ widgets/filepathselectorwidget.cpp
OTHER_FILES +=
CONFIG += mobility
#include "filepathmodel.h"
#include "setupmodel.h"
#include "comboboxdelegate.h"
+#include "filesystembrowsedelegate.h"
#include <QtGui>
FilePathEditView::FilePathEditView(QWidget *parent) :
this
);
objectList->setItemDelegateForColumn(FilePathModel::FilePath_SetupId, setupDelegate);
+ FileSystemBrowseDelegate *fsBrowseDelegate = new FileSystemBrowseDelegate(this);
+ objectList->setItemDelegateForColumn(FilePathModel::FilePath_Name, fsBrowseDelegate);
postInit();
}
--- /dev/null
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
+//
+// EmuFront 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 EmuFront. If not, see <http://www.gnu.org/licenses/>.
+
+#include <QtGui>
+#include "filepathselectorwidget.h"
+
+FilePathSelectorWidget::FilePathSelectorWidget(QWidget *parent) :
+ QWidget(parent)
+{
+ filePathLabel = new QLabel;
+ filePathButton = new QPushButton(tr("&Browse"));
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->addWidget(filePathButton);
+ layout->addWidget(filePathLabel);
+ setLayout(layout);
+ connectSignals();
+}
+
+void FilePathSelectorWidget::connectSignals()
+{
+ connect(filePathButton, SIGNAL(clicked()), this, SLOT(browseFilePath()));
+}
+
+void FilePathSelectorWidget::browseFilePath()
+{
+ qDebug() << "FilePathSelectorWidget::browseFilePath()";
+ QString startPath = filePathLabel->text().isEmpty() ?
+ QDir::homePath() : filePathLabel->text();
+
+ QString fpath = QFileDialog::getExistingDirectory(this,
+ tr("Select a directory"), startPath,
+ QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
+ QDir d(fpath);
+
+ if (d.exists() && d.isReadable()) {
+ filePathLabel->setText(d.path());
+ if (d.path() != startPath)
+ emit filePathUpdated();
+ }
+}
+
+void FilePathSelectorWidget::setFilePath(QString &path)
+{
+ filePathLabel->setText(path);
+}
+
+QString FilePathSelectorWidget::getFilePath() const
+{
+ return filePathLabel->text();
+}
--- /dev/null
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
+//
+// EmuFront 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 EmuFront. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef FILEPATHSELECTORWIDGET_H
+#define FILEPATHSELECTORWIDGET_H
+
+#include <QWidget>
+
+class QLabel;
+class QPushButton;
+
+class FilePathSelectorWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ FilePathSelectorWidget(QWidget *parent = 0);
+ void setFilePath(QString &path);
+ QString getFilePath() const;
+
+signals:
+ void filePathUpdated();
+
+protected slots:
+ void browseFilePath();
+
+protected:
+ void connectSignals();
+ QLabel *filePathLabel;
+ QPushButton *filePathButton;
+};
+
+#endif // FILEPATHSELECTORWIDGET_H