]> git.sven.stormbind.net Git - sven/vym.git/blob - shortcuts.cpp
ae8b4a4802afe99962939b3a28e4fa032f324827
[sven/vym.git] / shortcuts.cpp
1 #include <QDebug>
2 #include <QMultiMap>
3
4 #include <iostream>
5 using namespace std;
6
7 #include "shortcuts.h"
8
9 /////////////////////////////////////////////////////////////////
10 // KeySwitch
11 /////////////////////////////////////////////////////////////////
12 KeySwitch::KeySwitch (
13         const QString &kIdentifier,
14         const QString &kName,
15         const QString &kGroup,
16         const QString &kTag,
17         const QKeySequence &kseq)
18 {
19     identifier = kIdentifier;
20     name = kName;
21     group = kGroup;
22     tag = kTag;
23     keySequence = kseq;
24 }
25
26 /////////////////////////////////////////////////////////////////
27 // Switchboard
28 /////////////////////////////////////////////////////////////////
29 Switchboard::Switchboard ()
30 {
31 }
32
33 void Switchboard::addGroup( QString gIdentifier, QString gName)
34 {
35     if (groups.contains(gIdentifier))
36     {
37         qDebug() << "Warning switchboard: Shortcut group " << gIdentifier << " already exists";
38         return;
39     }
40     groups.insert(gIdentifier, gName); 
41 }
42
43 void Switchboard::addSwitch( QString identifier, QString scope, QAction *action, QString tag)
44 {
45     if (!switches.contains(identifier))
46     {
47         KeySwitch ksw(identifier, action->text(), scope, tag, action->shortcut());
48         switches.insert(scope, ksw);
49     } else
50         qDebug() << "Warning switchboard::addSwitch warning: Existing idenifier " << identifier;
51 }
52
53 QString Switchboard::getASCII()  
54 {
55     QString s;
56     QString g;
57     foreach (g, switches.uniqueKeys())
58     {
59         s += "Scope " + g +":\n";
60         QList <KeySwitch> values=switches.values(g);
61         for (int i=0; i<values.size(); ++i)
62         {
63             QString desc=values.at(i).name;
64             QString   sc=values.at(i).keySequence.toString();
65             desc=desc.remove('&');
66             desc=desc.remove("...");
67             s += QString(" %1: %2\n").arg(sc,12).arg(desc);
68         }
69         s += "\n";
70     }
71
72     /*
73     foreach (g, actions.uniqueKeys())
74     {
75         s += g +"\n";
76         QList <QAction*> values=actions.values(g);
77         for (int i=0;i<values.size();++i)
78         {
79             QString desc=values.at(i)->text();
80             QString   sc=values.at(i)->shortcut().toString();
81             desc=desc.remove('&');
82             desc=desc.remove("...");
83             s+= QString(" %1: %2\n").arg(sc,12).arg(desc);
84         }
85     }
86     */
87     return s;
88 }
89
90 void Switchboard::printASCII () 
91 {
92     cout <<qPrintable(getASCII() );
93 }
94
95 void Switchboard::printLaTeX () 
96 {
97     QString g;
98     foreach (g,actions.uniqueKeys())
99     {
100         cout <<"Group: "<<qPrintable(g)<<"\\\\ \\hline"<<endl;
101         QList <QAction*> values=actions.values(g);
102         for (int i=0;i<values.size();++i)
103             if (!values.at(i)->shortcut().toString().isEmpty())
104             {
105                 QString desc=values.at(i)->text();
106                 QString   sc=values.at(i)->shortcut().toString();
107                 desc=desc.remove('&');
108                 desc=desc.remove("...");
109                 cout << qPrintable( QString(" %1& %2").arg(sc,12).arg(desc) )<<endl;
110             }
111         cout <<endl;
112     }
113 }