annotate widgets/KeyReference.cpp @ 283:86a112b5b319

* Make it possible to "measure" a feature on the spectrogram by double- clicking in measure mode * Make shift-click-drag (for zoom to region) work in measure mode as well as navigate mode. It would be nice to be able to shift-doubleclick to zoom on a feature directly using a combination of these last two features, but that isn't possible yet. * Make Del delete the measurement under the mouse pointer.
author Chris Cannam
date Thu, 05 Jul 2007 15:36:37 +0000
parents 4edaff85875d
children 3801289761a1
rev   line source
Chris@281 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@281 2
Chris@281 3 /*
Chris@281 4 Sonic Visualiser
Chris@281 5 An audio file viewer and annotation editor.
Chris@281 6 Centre for Digital Music, Queen Mary, University of London.
Chris@281 7 This file copyright 2007 QMUL.
Chris@281 8
Chris@281 9 This program is free software; you can redistribute it and/or
Chris@281 10 modify it under the terms of the GNU General Public License as
Chris@281 11 published by the Free Software Foundation; either version 2 of the
Chris@281 12 License, or (at your option) any later version. See the file
Chris@281 13 COPYING included with this distribution for more information.
Chris@281 14 */
Chris@281 15
Chris@281 16 #include "KeyReference.h"
Chris@281 17
Chris@281 18 #include <QAction>
Chris@281 19 #include <QTextEdit>
Chris@282 20 #include <QDialog>
Chris@282 21 #include <QVBoxLayout>
Chris@282 22 #include <QDialogButtonBox>
Chris@282 23 #include <QApplication>
Chris@282 24 #include <QDesktopWidget>
Chris@281 25
Chris@281 26 KeyReference::KeyReference() :
Chris@282 27 m_dialog(0)
Chris@281 28 {
Chris@281 29 }
Chris@281 30
Chris@281 31 KeyReference::~KeyReference()
Chris@281 32 {
Chris@282 33 delete m_dialog;
Chris@281 34 }
Chris@281 35
Chris@281 36 void
Chris@281 37 KeyReference::setCategory(QString category)
Chris@281 38 {
Chris@281 39 if (m_map.find(category) == m_map.end()) {
Chris@281 40 m_categoryOrder.push_back(category);
Chris@282 41 m_map[category] = KeyList();
Chris@281 42 }
Chris@281 43 m_currentCategory = category;
Chris@281 44 }
Chris@281 45
Chris@281 46 void
Chris@281 47 KeyReference::registerShortcut(QAction *action, QString overrideName)
Chris@281 48 {
Chris@281 49 QString name = action->text();
Chris@281 50 if (overrideName != "") name = overrideName;
Chris@281 51
Chris@281 52 QString shortcut = action->shortcut();
Chris@281 53 QString tip = action->statusTip();
Chris@281 54
Chris@281 55 registerShortcut(name, shortcut, tip);
Chris@281 56 }
Chris@281 57
Chris@281 58 void
Chris@281 59 KeyReference::registerShortcut(QString name, QString shortcut, QString tip)
Chris@281 60 {
Chris@282 61 name.replace(tr("&"), "");
Chris@282 62
Chris@281 63 KeyList &list = m_map[m_currentCategory];
Chris@281 64
Chris@281 65 for (KeyList::iterator i = list.begin(); i != list.end(); ++i) {
Chris@281 66 if (i->actionName == name) {
Chris@281 67 i->shortcut = shortcut;
Chris@281 68 i->tip = tip;
Chris@281 69 i->alternatives.clear();
Chris@281 70 return;
Chris@281 71 }
Chris@281 72 }
Chris@281 73
Chris@281 74 KeyDetails details;
Chris@281 75 details.actionName = name;
Chris@281 76 details.shortcut = shortcut;
Chris@281 77 details.tip = tip;
Chris@281 78
Chris@281 79 list.push_back(details);
Chris@281 80 }
Chris@281 81
Chris@281 82 void
Chris@281 83 KeyReference::registerAlternativeShortcut(QAction *action, QString alternative)
Chris@281 84 {
Chris@281 85 QString name = action->text();
Chris@281 86 registerAlternativeShortcut(name, alternative);
Chris@281 87 }
Chris@281 88
Chris@281 89 void
Chris@281 90 KeyReference::registerAlternativeShortcut(QString name, QString alternative)
Chris@281 91 {
Chris@282 92 name.replace(tr("&"), "");
Chris@282 93
Chris@281 94 KeyList &list = m_map[m_currentCategory];
Chris@281 95
Chris@281 96 for (KeyList::iterator i = list.begin(); i != list.end(); ++i) {
Chris@281 97 if (i->actionName == name) {
Chris@281 98 i->alternatives.push_back(alternative);
Chris@281 99 return;
Chris@281 100 }
Chris@281 101 }
Chris@281 102 }
Chris@281 103
Chris@281 104 void
Chris@281 105 KeyReference::show()
Chris@281 106 {
Chris@282 107 if (m_dialog) {
Chris@282 108 m_dialog->show();
Chris@282 109 m_dialog->raise();
Chris@281 110 return;
Chris@281 111 }
Chris@281 112
Chris@281 113 QString text;
Chris@281 114
Chris@281 115 text += "<center><table bgcolor=\"#e8e8e8\">";
Chris@281 116
Chris@281 117 for (CategoryList::iterator i = m_categoryOrder.begin();
Chris@281 118 i != m_categoryOrder.end(); ++i) {
Chris@281 119
Chris@281 120 QString category = *i;
Chris@281 121 KeyList &list = m_map[category];
Chris@281 122
Chris@282 123 text += QString("<tr><td bgcolor=\"#d0d0d0\" colspan=3 align=\"center\"><br><b>%1</b><br></td></tr>\n").arg(category);
Chris@281 124
Chris@281 125 for (KeyList::iterator j = list.begin(); j != list.end(); ++j) {
Chris@281 126
Chris@281 127 QString actionName = j->actionName;
Chris@282 128
Chris@282 129 QString shortcut = j->shortcut;
Chris@282 130 shortcut.replace(" ", "&nbsp;");
Chris@281 131
Chris@281 132 QString tip = j->tip;
Chris@281 133 if (tip != "") tip = QString("<i>%1</i>").arg(tip);
Chris@281 134
Chris@281 135 QString altdesc;
Chris@281 136 if (!j->alternatives.empty()) {
Chris@281 137 for (std::vector<QString>::iterator k = j->alternatives.begin();
Chris@281 138 k != j->alternatives.end(); ++k) {
Chris@282 139 QString alt = *k;
Chris@282 140 alt.replace(" ", "&nbsp;");
Chris@282 141 altdesc += tr("<i>or</i>&nbsp;<b>%1</b>").arg(alt);
Chris@281 142 }
Chris@281 143 altdesc = tr("</b>&nbsp;(%1)<b>").arg(altdesc);
Chris@281 144 }
Chris@281 145
Chris@281 146 text += QString("<tr><td>&nbsp;<b>%1%2</b></td><td>&nbsp;%3</td><td>%4</td></tr>\n")
Chris@282 147 .arg(shortcut).arg(altdesc).arg(actionName).arg(tip);
Chris@281 148 }
Chris@281 149 }
Chris@281 150
Chris@281 151 text += "</table></center>\n";
Chris@281 152
Chris@281 153 m_text = new QTextEdit;
Chris@281 154 m_text->setHtml(text);
Chris@281 155 m_text->setReadOnly(true);
Chris@282 156
Chris@282 157 m_dialog = new QDialog;
Chris@282 158 m_dialog->setWindowTitle(tr("Sonic Visualiser: Key and Mouse Reference"));
Chris@282 159
Chris@282 160 QVBoxLayout *layout = new QVBoxLayout;
Chris@282 161 m_dialog->setLayout(layout);
Chris@282 162 layout->addWidget(m_text);
Chris@282 163
Chris@282 164 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
Chris@282 165 connect(bb, SIGNAL(clicked(QAbstractButton *)), this, SLOT(dialogButtonClicked(QAbstractButton *)));
Chris@282 166 layout->addWidget(bb);
Chris@282 167
Chris@282 168 m_dialog->show();
Chris@282 169
Chris@282 170 QDesktopWidget *desktop = QApplication::desktop();
Chris@282 171 QRect available = desktop->availableGeometry();
Chris@282 172
Chris@282 173 int width = available.width() * 3 / 5;
Chris@282 174 int height = available.height() * 2 / 3;
Chris@282 175 if (height < 450) {
Chris@282 176 if (available.height() > 500) height = 450;
Chris@282 177 }
Chris@282 178 if (width < 600) {
Chris@282 179 if (available.width() > 650) width = 600;
Chris@282 180 }
Chris@282 181
Chris@282 182 m_dialog->resize(width, height);
Chris@282 183 m_dialog->raise();
Chris@281 184 }
Chris@281 185
Chris@282 186 void
Chris@282 187 KeyReference::dialogButtonClicked(QAbstractButton *)
Chris@282 188 {
Chris@282 189 // only button is Close
Chris@282 190 m_dialog->hide();
Chris@282 191 }
Chris@282 192