Multiple shortcuts for next/previous view
authorDmitriy Morozov <dmitriy@mrzv.org>
Sun, 14 Apr 2013 13:27:26 -0700
changeset 15 bd0ebb02adbb
parent 14 f29d75686e95
child 16 18267210c228
Multiple shortcuts for next/previous view
canvasview.cpp
canvasview.h
mainwindow.cpp
--- a/canvasview.cpp	Fri Mar 01 13:34:50 2013 -0800
+++ b/canvasview.cpp	Sun Apr 14 13:27:26 2013 -0700
@@ -38,7 +38,7 @@
 // --------------------------------------------------------------------
 
 IpeAction::IpeAction(int cmd, const QString &text, const char *shortcut,
-		             QObject *parent): 
+                     QObject *parent):
     QAction(text, parent)
 {
     iCommand = cmd;
@@ -48,6 +48,22 @@
         setShortcut(QKeySequence(shortcut));
 }
 
+IpeAction::IpeAction(int cmd, const QString &text, const std::vector<std::string>& shortcuts,
+                     QObject *parent):
+    QAction(text, parent)
+{
+    iCommand = cmd;
+    connect(this, SIGNAL(triggered()), SLOT(forwardTrigger()));
+    connect(this, SIGNAL(triggered(int)), parent, SLOT(cmd(int)));
+    if (!shortcuts.empty())
+    {
+        QList<QKeySequence> shortcut_keys;
+        for (unsigned i = 0; i < shortcuts.size(); ++i)
+            shortcut_keys.push_back(QKeySequence(shortcuts[i].c_str()));
+        setShortcuts(shortcut_keys);
+    }
+}
+
 void IpeAction::forwardTrigger()
 {
     emit triggered(iCommand);
@@ -55,7 +71,7 @@
 
 // --------------------------------------------------------------------
 
-CanvasView::CanvasView(Qt::WFlags f): 
+CanvasView::CanvasView(Qt::WFlags f):
     QMainWindow(0, f)
 {
     iDoc = 0;
@@ -92,7 +108,7 @@
 
     return true;
 }
-  
+
 void CanvasView::fitBox(const Rect &box)
 {
     if (box.isEmpty())
--- a/canvasview.h	Fri Mar 01 13:34:50 2013 -0800
+++ b/canvasview.h	Sun Apr 14 13:27:26 2013 -0700
@@ -43,27 +43,29 @@
 
 // --------------------------------------------------------------------
 
-class IpeAction: public QAction 
+class IpeAction: public QAction
 {
     Q_OBJECT
 
     public:
                     IpeAction(int cmd, const QString &text,
                               const char *shortcut, QObject *parent);
-    
+                    IpeAction(int cmd, const QString &text,
+                              const std::vector<std::string>& shortcuts, QObject *parent);
+
     signals:
         void        triggered(int cmd);
-    
+
     private slots:
         void        forwardTrigger();
-    
+
     private:
         int         iCommand;
 };
 
 // --------------------------------------------------------------------
 
-class CanvasView: public QMainWindow 
+class CanvasView: public QMainWindow
 {
     Q_OBJECT
 
--- a/mainwindow.cpp	Fri Mar 01 13:34:50 2013 -0800
+++ b/mainwindow.cpp	Sun Apr 14 13:27:26 2013 -0700
@@ -66,8 +66,11 @@
     iViewMenu->addAction(iToggleTime);
     iViewMenu->addAction(new IpeAction(EShowPresentation, "Show presentation", "", this));
 
-    iMoveMenu->addAction(new IpeAction(ENextView, "Next view", "PgDown", this));
-    iMoveMenu->addAction(new IpeAction(EPreviousView, "Previous view", "PgUp", this));
+    std::vector<std::string> next,prev;
+    next.push_back("Right"); next.push_back("PgDown");
+    prev.push_back("Left");  prev.push_back("PgUp");
+    iMoveMenu->addAction(new IpeAction(ENextView, "Next view", next, this));
+    iMoveMenu->addAction(new IpeAction(EPreviousView, "Previous view", prev, this));
     iMoveMenu->addAction(new IpeAction(ENextPage, "Next page", "N", this));
     iMoveMenu->addAction(new IpeAction(EPreviousPage, "Previous ", "P", this));
     iMoveMenu->addAction(new IpeAction(EFirstView, "First view", "Home", this));