From: APTX Date: Sun, 3 Jun 2012 15:39:28 +0000 (+0200) Subject: More useful context menu. X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=f7b5981e716805fff50a9aeaef4db35ae249ad4c;p=localmylist.git More useful context menu. --- diff --git a/management-gui/mainwindow.cpp b/management-gui/mainwindow.cpp index d6b379b..9537b1c 100644 --- a/management-gui/mainwindow.cpp +++ b/management-gui/mainwindow.cpp @@ -114,7 +114,7 @@ void MainWindow::on_actionHandlePendingRequests_triggered() } -void MainWindow::on_myListView_doubleClicked(const QModelIndex &index) +void MainWindow::on_myListView_openFileRequested(const QModelIndex &index) { MyListModel::NodeType type = animeModel->type(index); int id = animeModel->id(index); diff --git a/management-gui/mainwindow.h b/management-gui/mainwindow.h index 73917ac..de85a11 100644 --- a/management-gui/mainwindow.h +++ b/management-gui/mainwindow.h @@ -37,8 +37,7 @@ private slots: void on_actionClearMyListData_triggered(); void on_actionClearAnimeTitleData_triggered(); void on_actionHandlePendingRequests_triggered(); - - void on_myListView_doubleClicked(const QModelIndex &index); + void on_myListView_openFileRequested(const QModelIndex &index); private: Ui::MainWindow *ui; diff --git a/management-gui/mylistview.cpp b/management-gui/mylistview.cpp index 27665a1..ae3860e 100644 --- a/management-gui/mylistview.cpp +++ b/management-gui/mylistview.cpp @@ -1,5 +1,6 @@ #include "mylistview.h" +#include "mylist.h" #include "mylistmodel.h" #include @@ -9,6 +10,13 @@ MyListView::MyListView(QWidget *parent) : { setContextMenuPolicy(Qt::CustomContextMenu); connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showCustomContextMenu(QPoint))); + + openAction = new QAction(tr("Open"), this); + connect(openAction, SIGNAL(triggered()), this, SLOT(requestOpenFile())); + openNextAction = new QAction(tr("Open next"), this); + connect(openNextAction, SIGNAL(triggered()), this, SLOT(requestOpenFile())); + markWatchedAction = new QAction(tr("Marked Watched"), this); + connect(markWatchedAction, SIGNAL(triggered()), this, SLOT(markWatched())); } LocalMyList::MyListModel *MyListView::myListModel() const @@ -24,11 +32,37 @@ void MyListView::showCustomContextMenu(const QPoint &pos) if (!idx.isValid()) return; - QAction a(tr("Dummyaction r=%1, c=%2").arg(idx.row()).arg(idx.column()), this); - MyListModel::NodeType t = myListModel()->type(idx); - QAction b(tr("%1 = %2").arg(t == MyListModel::Anime ? "aid" : t == MyListModel::Episode ? "eid" : t == MyListModel::File ? "fid" : "none").arg(myListModel()->id(idx)), this); + MyListModel::NodeType type = myListModel()->type(idx); + + //QAction a(tr("Dummyaction r=%1, c=%2").arg(idx.row()).arg(idx.column()), this); + + //QAction b(tr("%1 = %2").arg(type == MyListModel::Anime ? "aid" : type == MyListModel::Episode ? "eid" : type == MyListModel::File ? "fid" : "none").arg(myListModel()->id(idx)), this); QList actions; - actions << &a << &b; + + if (type == MyListModel::Anime) + actions << openNextAction; + else + actions << openAction; + if (type == MyListModel::File) + actions << markWatchedAction; + + if(actions.isEmpty()) + return; + + customContextMenuIndex = idx; QMenu::exec(actions, viewport()->mapToGlobal(pos)); + customContextMenuIndex = QModelIndex(); +} + +void MyListView::requestOpenFile() +{ + emit openFileRequested(customContextMenuIndex); +} + +void MyListView::markWatched() +{ + int id = myListModel()->id(customContextMenuIndex); + + LocalMyList::instance()->markWatched(id); } diff --git a/management-gui/mylistview.h b/management-gui/mylistview.h index c384aae..b4371b9 100644 --- a/management-gui/mylistview.h +++ b/management-gui/mylistview.h @@ -2,6 +2,7 @@ #define MYLISTVIEW_H #include +#include namespace LocalMyList { class MyListModel; @@ -13,10 +14,21 @@ class MyListView : public QTreeView public: explicit MyListView(QWidget *parent = 0); +signals: + void openFileRequested(const QModelIndex &index); + private slots: LocalMyList::MyListModel *myListModel() const; void showCustomContextMenu(const QPoint &pos); - + void requestOpenFile(); + void markWatched(); +private: + QModelIndex customContextMenuIndex; + + + QAction *openAction; + QAction *openNextAction; + QAction *markWatchedAction; }; #endif // MYLISTVIEW_H