]> Some of my projects - localmylist.git/commitdiff
More useful context menu.
authorAPTX <marek321@gmail.com>
Sun, 3 Jun 2012 15:39:28 +0000 (17:39 +0200)
committerAPTX <marek321@gmail.com>
Sun, 3 Jun 2012 15:39:28 +0000 (17:39 +0200)
management-gui/mainwindow.cpp
management-gui/mainwindow.h
management-gui/mylistview.cpp
management-gui/mylistview.h

index d6b379bcd7476ee5ee658f26ee289cd17c2a6cc2..9537b1c000c9b4c11bb862a607401c3c768dffd4 100644 (file)
@@ -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);
index 73917aca73891fde58bd4571ed6d08ad9aebbd67..de85a11b96a43e225f95f2ee1e55690092becb93 100644 (file)
@@ -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;
index 27665a1c03e7f75f43c058f47a1fc5b2256df475..ae3860e01981af0bfd7d5725fead3c0745615cc1 100644 (file)
@@ -1,5 +1,6 @@
 #include "mylistview.h"
 
+#include "mylist.h"
 #include "mylistmodel.h"
 
 #include <QMenu>
@@ -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<QAction *> 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);
 }
index c384aae64288c9b39a9c8357a7b1c58092d5c0c1..b4371b96e193ae4ae70a2c057a81aab7b9137e20 100644 (file)
@@ -2,6 +2,7 @@
 #define MYLISTVIEW_H
 
 #include <QTreeView>
+#include <QModelIndex>
 
 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