diff options
author | deva <deva> | 2009-12-01 09:08:45 +0000 |
---|---|---|
committer | deva <deva> | 2009-12-01 09:08:45 +0000 |
commit | 40294e22bd61cf7cf851ec6d6c7a41fd78cbdcad (patch) | |
tree | 19825db91a456419cee653d8e72b2fc4289348ec /dgedit | |
parent | 373de0f137e4b7f7e8b348cabd6151573bd80a74 (diff) |
Added context menu to filelist. Remove file from list is now possible.
Diffstat (limited to 'dgedit')
-rw-r--r-- | dgedit/audioextractor.cc | 4 | ||||
-rw-r--r-- | dgedit/audioextractor.h | 5 | ||||
-rw-r--r-- | dgedit/filelist.cc | 66 | ||||
-rw-r--r-- | dgedit/filelist.h | 18 | ||||
-rw-r--r-- | dgedit/mainwindow.cc | 1 |
5 files changed, 87 insertions, 7 deletions
diff --git a/dgedit/audioextractor.cc b/dgedit/audioextractor.cc index 8a08135..92ed4d6 100644 --- a/dgedit/audioextractor.cc +++ b/dgedit/audioextractor.cc @@ -129,11 +129,11 @@ void AudioExtractor::addFile(QString file, QString name) audiofiles.push_back(pair); } -void AudioExtractor::removeFile(QString file) +void AudioExtractor::removeFile(QString file, QString name) { QVector< QPair<QString, QString> >::iterator j = audiofiles.begin(); while(j != audiofiles.end()) { - if(file == j->first) { + if(file == j->first && name == j->second) { audiofiles.erase(j); return; } diff --git a/dgedit/audioextractor.h b/dgedit/audioextractor.h index 5254aa4..75d3553 100644 --- a/dgedit/audioextractor.h +++ b/dgedit/audioextractor.h @@ -39,10 +39,9 @@ Q_OBJECT public: AudioExtractor(QObject *parent); - void addFile(QString file, QString name); - void removeFile(QString file); - public slots: + void addFile(QString file, QString name); + void removeFile(QString file, QString name); void exportSelections(Selections selections); void setExportPath(const QString &path); void setOutputPrefix(const QString &prefix); diff --git a/dgedit/filelist.cc b/dgedit/filelist.cc index 5326eef..c9798ef 100644 --- a/dgedit/filelist.cc +++ b/dgedit/filelist.cc @@ -28,11 +28,19 @@ #include <QFileDialog> #include <QFileInfo> +#include <QMenu> FileList::FileList() { + setContextMenuPolicy(Qt::CustomContextMenu); + + connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), + this, SLOT(popupMenu(const QPoint &))); + connect(this, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(selectionChanged(QListWidgetItem *))); + + createMenus(); } void FileList::addFiles() @@ -57,13 +65,67 @@ void FileList::addFiles() } } -void FileList::selectionChanged(QListWidgetItem *i) +void FileList::setMasterFile(QListWidgetItem *i) { QString filename = i->text(); - for(int idx = 0; idx < count(); idx++) + for(int idx = 0; idx < count(); idx++) { item(idx)->setIcon(QPixmap("icons/file.png")); + } i->setIcon(QPixmap("icons/master.png")); emit masterFileChanged(filename); } + +void FileList::selectionChanged(QListWidgetItem *i) +{ + setMasterFile(i); +} + + +void FileList::createMenus() +{ + menu = new QMenu(); + + setMasterAction = new QAction("Set as Master (dbl-click)", this); + connect(setMasterAction, SIGNAL(triggered()), this, SLOT(setMaster())); + + editAction = new QAction("Edit name", this); + connect(editAction, SIGNAL(triggered()), this, SLOT(editName())); + + removeAction = new QAction("Remove", this); + connect(removeAction, SIGNAL(triggered()), this, SLOT(removeFile())); + + menu->addAction(setMasterAction); + menu->addAction(editAction); + menu->addAction(removeAction); +} + +void FileList::popupMenu(const QPoint & pos) +{ + activeItem = itemAt(pos); + if(!activeItem) return; + menu->popup(mapToGlobal(pos)); +} + +void FileList::setMaster() +{ + setMasterFile(activeItem); +} + +void FileList::removeFile() +{ + QString file = activeItem->text(); + QString name = activeItem->data(Qt::UserRole).toString(); + + printf("Removing: %s\n", file.toStdString().c_str()); + delete activeItem;//takeItem(row(activeItem)); + activeItem = NULL; + setCurrentRow(-1); + + emit fileRemoved(file, name); +} + +void FileList::editName() +{ +} diff --git a/dgedit/filelist.h b/dgedit/filelist.h index e148203..c43fde6 100644 --- a/dgedit/filelist.h +++ b/dgedit/filelist.h @@ -28,6 +28,9 @@ #define __DRUMGIZMO_FILELIST_H__ #include <QListWidget> +#include <QListWidgetItem> +#include <QAction> +#include <QMenu> class FileList : public QListWidget { Q_OBJECT @@ -41,9 +44,24 @@ signals: public slots: void addFiles(); + void popupMenu(const QPoint &pos); private slots: void selectionChanged(QListWidgetItem *item); + void setMaster(); + void removeFile(); + void editName(); + +private: + void setMasterFile(QListWidgetItem *i); + void createMenus(); + + QMenu *menu; + QAction *setMasterAction; + QAction *editAction; + QAction *removeAction; + + QListWidgetItem *activeItem; }; diff --git a/dgedit/mainwindow.cc b/dgedit/mainwindow.cc index e125dec..9b78968 100644 --- a/dgedit/mainwindow.cc +++ b/dgedit/mainwindow.cc @@ -136,6 +136,7 @@ MainWindow::MainWindow() connect(filelist, SIGNAL(masterFileChanged(QString)), this, SLOT(loadFile(QString))); connect(loadbtn, SIGNAL(clicked()), filelist, SLOT(addFiles())); connect(filelist, SIGNAL(fileAdded(QString, QString)), extractor, SLOT(addFile(QString, QString))); + connect(filelist, SIGNAL(fileRemoved(QString, QString)), extractor, SLOT(removeFile(QString, QString))); configs->addWidget(filelist); QDockWidget *dockWidget = new QDockWidget(tr("Dock Widget"), this); |