Skip to content

Commit

Permalink
GUI: Allow deleting video files with the Delete key
Browse files Browse the repository at this point in the history
  • Loading branch information
cantabile committed Jul 31, 2016
1 parent a31f414 commit cb87b1b
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ moc_%.cpp : %.h
bin_PROGRAMS = d2vwitch

moc_files = src/moc_GUIWindow.cpp \
src/moc_ListWidget.cpp \
src/moc_ScrollArea.cpp

MOSTLYCLEANFILES = $(moc_files)
Expand All @@ -34,6 +35,8 @@ d2vwitch_SOURCES = src/Bullshit.cpp \
src/FFMPEG.h \
src/GUIWindow.cpp \
src/GUIWindow.h \
src/ListWidget.cpp \
src/ListWidget.h \
src/MPEGParser.cpp \
src/MPEGParser.h \
src/ScrollArea.cpp \
Expand Down
4 changes: 3 additions & 1 deletion src/GUIWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ GUIWindow::GUIWindow(QWidget *parent)
setWindowTitle("D2V Witch v" PACKAGE_VERSION);


input_list = new QListWidget(this);
input_list = new ListWidget(this);
input_list->setSelectionMode(QAbstractItemView::ExtendedSelection);
QPushButton *add_button = new QPushButton("&Add files", this);
QPushButton *remove_button = new QPushButton("&Remove files", this);
Expand Down Expand Up @@ -472,6 +472,8 @@ GUIWindow::GUIWindow(QWidget *parent)
container_widget = new QStackedWidget(this);


connect(input_list, &ListWidget::deletePressed, remove_button, &QPushButton::click);

connect(add_button, &QPushButton::clicked, [this] () {
QStringList file_names = QFileDialog::getOpenFileNames(this, "Open video files", "", "", nullptr, QFileDialog::DontUseNativeDialog);

Expand Down
3 changes: 2 additions & 1 deletion src/GUIWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SOFTWARE.
#include "D2V.h"
#include "FakeFile.h"
#include "FFMPEG.h"
#include "ListWidget.h"


class GUIWindow : public QMainWindow {
Expand Down Expand Up @@ -61,7 +62,7 @@ class GUIWindow : public QMainWindow {

// Widgets

QListWidget *input_list;
ListWidget *input_list;
QLineEdit *d2v_edit;
QListWidget *video_list;
QButtonGroup *video_group;
Expand Down
47 changes: 47 additions & 0 deletions src/ListWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright (c) 2015, John Smith
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
*/


#include <QKeyEvent>

#include "ListWidget.h"

void ListWidget::keyPressEvent(QKeyEvent *event) {
auto mod = event->modifiers();
int key = event->key();

if (mod == Qt::NoModifier && key == Qt::Key_Delete) {
emit deletePressed();
return;
}

QListWidget::keyPressEvent(event);
}


QList<QListWidgetItem *> ListWidget::selectedItems() const {
auto selection = QListWidget::selectedItems();

auto cmp = [this] (const QListWidgetItem *a, const QListWidgetItem *b) -> bool {
return row(a) < row(b);
};
std::sort(selection.begin(), selection.end(), cmp);

return selection;
}
41 changes: 41 additions & 0 deletions src/ListWidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright (c) 2015, John Smith
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
*/


#ifndef D2V_WITCH_LISTWIDGET_H
#define D2V_WITCH_LISTWIDGET_H

#include <QListWidget>

class ListWidget : public QListWidget {
Q_OBJECT

signals:
void deletePressed();

private:
void keyPressEvent(QKeyEvent *event);

public:
using QListWidget::QListWidget;

QList<QListWidgetItem *> selectedItems() const;
};

#endif // D2V_WITCH_LISTWIDGET_H

0 comments on commit cb87b1b

Please sign in to comment.