comparison widgets/KeyReference.cpp @ 282:4edaff85875d

* Add mouse actions to key and mouse reference dialog * Use QDialogButtonBox in all dialogs, for proper button ordering across platforms (requires Qt 4.2) * Fix #1733610 program does not exit if preferences dialog visible on close
author Chris Cannam
date Thu, 05 Jul 2007 11:07:01 +0000
parents ac58acbd7482
children 3801289761a1
comparison
equal deleted inserted replaced
281:ac58acbd7482 282:4edaff85875d
15 15
16 #include "KeyReference.h" 16 #include "KeyReference.h"
17 17
18 #include <QAction> 18 #include <QAction>
19 #include <QTextEdit> 19 #include <QTextEdit>
20 #include <QDialog>
21 #include <QVBoxLayout>
22 #include <QDialogButtonBox>
23 #include <QApplication>
24 #include <QDesktopWidget>
20 25
21 KeyReference::KeyReference() : 26 KeyReference::KeyReference() :
22 m_text(0) 27 m_dialog(0)
23 { 28 {
24 } 29 }
25 30
26 KeyReference::~KeyReference() 31 KeyReference::~KeyReference()
27 { 32 {
28 delete m_text; 33 delete m_dialog;
29 } 34 }
30 35
31 void 36 void
32 KeyReference::setCategory(QString category) 37 KeyReference::setCategory(QString category)
33 { 38 {
34 if (m_map.find(category) == m_map.end()) { 39 if (m_map.find(category) == m_map.end()) {
35 m_categoryOrder.push_back(category); 40 m_categoryOrder.push_back(category);
41 m_map[category] = KeyList();
36 } 42 }
37 m_currentCategory = category; 43 m_currentCategory = category;
38 m_map[category] = KeyList();
39 } 44 }
40 45
41 void 46 void
42 KeyReference::registerShortcut(QAction *action, QString overrideName) 47 KeyReference::registerShortcut(QAction *action, QString overrideName)
43 { 48 {
51 } 56 }
52 57
53 void 58 void
54 KeyReference::registerShortcut(QString name, QString shortcut, QString tip) 59 KeyReference::registerShortcut(QString name, QString shortcut, QString tip)
55 { 60 {
61 name.replace(tr("&"), "");
62
56 KeyList &list = m_map[m_currentCategory]; 63 KeyList &list = m_map[m_currentCategory];
57 64
58 for (KeyList::iterator i = list.begin(); i != list.end(); ++i) { 65 for (KeyList::iterator i = list.begin(); i != list.end(); ++i) {
59 if (i->actionName == name) { 66 if (i->actionName == name) {
60 i->shortcut = shortcut; 67 i->shortcut = shortcut;
80 } 87 }
81 88
82 void 89 void
83 KeyReference::registerAlternativeShortcut(QString name, QString alternative) 90 KeyReference::registerAlternativeShortcut(QString name, QString alternative)
84 { 91 {
92 name.replace(tr("&"), "");
93
85 KeyList &list = m_map[m_currentCategory]; 94 KeyList &list = m_map[m_currentCategory];
86 95
87 for (KeyList::iterator i = list.begin(); i != list.end(); ++i) { 96 for (KeyList::iterator i = list.begin(); i != list.end(); ++i) {
88 if (i->actionName == name) { 97 if (i->actionName == name) {
89 i->alternatives.push_back(alternative); 98 i->alternatives.push_back(alternative);
93 } 102 }
94 103
95 void 104 void
96 KeyReference::show() 105 KeyReference::show()
97 { 106 {
98 if (m_text) { 107 if (m_dialog) {
99 m_text->show(); 108 m_dialog->show();
100 m_text->raise(); 109 m_dialog->raise();
101 return; 110 return;
102 } 111 }
103 112
104 QString text; 113 QString text;
105 114
109 i != m_categoryOrder.end(); ++i) { 118 i != m_categoryOrder.end(); ++i) {
110 119
111 QString category = *i; 120 QString category = *i;
112 KeyList &list = m_map[category]; 121 KeyList &list = m_map[category];
113 122
114 text += QString("<tr><td bgcolor=\"#d0d0d0\" colspan=3><br>&nbsp;<b>%1</b><br></td></tr>\n").arg(category); 123 text += QString("<tr><td bgcolor=\"#d0d0d0\" colspan=3 align=\"center\"><br><b>%1</b><br></td></tr>\n").arg(category);
115 124
116 for (KeyList::iterator j = list.begin(); j != list.end(); ++j) { 125 for (KeyList::iterator j = list.begin(); j != list.end(); ++j) {
117 126
118 QString actionName = j->actionName; 127 QString actionName = j->actionName;
119 actionName.replace(tr("&"), ""); 128
129 QString shortcut = j->shortcut;
130 shortcut.replace(" ", "&nbsp;");
120 131
121 QString tip = j->tip; 132 QString tip = j->tip;
122 if (tip != "") tip = QString("<i>%1</i>").arg(tip); 133 if (tip != "") tip = QString("<i>%1</i>").arg(tip);
123 134
124 QString altdesc; 135 QString altdesc;
125 if (!j->alternatives.empty()) { 136 if (!j->alternatives.empty()) {
126 for (std::vector<QString>::iterator k = j->alternatives.begin(); 137 for (std::vector<QString>::iterator k = j->alternatives.begin();
127 k != j->alternatives.end(); ++k) { 138 k != j->alternatives.end(); ++k) {
128 altdesc += tr("<i>or</i>&nbsp;<b>%1</b>").arg(*k); 139 QString alt = *k;
140 alt.replace(" ", "&nbsp;");
141 altdesc += tr("<i>or</i>&nbsp;<b>%1</b>").arg(alt);
129 } 142 }
130 altdesc = tr("</b>&nbsp;(%1)<b>").arg(altdesc); 143 altdesc = tr("</b>&nbsp;(%1)<b>").arg(altdesc);
131 } 144 }
132 145
133 text += QString("<tr><td>&nbsp;<b>%1%2</b></td><td>&nbsp;%3</td><td>%4</td></tr>\n") 146 text += QString("<tr><td>&nbsp;<b>%1%2</b></td><td>&nbsp;%3</td><td>%4</td></tr>\n")
134 .arg(j->shortcut).arg(altdesc).arg(actionName).arg(tip); 147 .arg(shortcut).arg(altdesc).arg(actionName).arg(tip);
135 } 148 }
136 } 149 }
137 150
138 text += "</table></center>\n"; 151 text += "</table></center>\n";
139 152
140 m_text = new QTextEdit; 153 m_text = new QTextEdit;
141 m_text->setHtml(text); 154 m_text->setHtml(text);
142 m_text->setReadOnly(true); 155 m_text->setReadOnly(true);
143 m_text->setObjectName(tr("Key Reference")); 156
144 m_text->show(); 157 m_dialog = new QDialog;
145 m_text->resize(600, 450); 158 m_dialog->setWindowTitle(tr("Sonic Visualiser: Key and Mouse Reference"));
146 m_text->raise(); 159
160 QVBoxLayout *layout = new QVBoxLayout;
161 m_dialog->setLayout(layout);
162 layout->addWidget(m_text);
163
164 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
165 connect(bb, SIGNAL(clicked(QAbstractButton *)), this, SLOT(dialogButtonClicked(QAbstractButton *)));
166 layout->addWidget(bb);
167
168 m_dialog->show();
169
170 QDesktopWidget *desktop = QApplication::desktop();
171 QRect available = desktop->availableGeometry();
172
173 int width = available.width() * 3 / 5;
174 int height = available.height() * 2 / 3;
175 if (height < 450) {
176 if (available.height() > 500) height = 450;
177 }
178 if (width < 600) {
179 if (available.width() > 650) width = 600;
180 }
181
182 m_dialog->resize(width, height);
183 m_dialog->raise();
147 } 184 }
148 185
186 void
187 KeyReference::dialogButtonClicked(QAbstractButton *)
188 {
189 // only button is Close
190 m_dialog->hide();
191 }
192