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