Mercurial > hg > svgui
diff 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 |
line wrap: on
line diff
--- a/widgets/KeyReference.cpp Wed Jul 04 17:22:12 2007 +0000 +++ b/widgets/KeyReference.cpp Thu Jul 05 11:07:01 2007 +0000 @@ -17,15 +17,20 @@ #include <QAction> #include <QTextEdit> +#include <QDialog> +#include <QVBoxLayout> +#include <QDialogButtonBox> +#include <QApplication> +#include <QDesktopWidget> KeyReference::KeyReference() : - m_text(0) + m_dialog(0) { } KeyReference::~KeyReference() { - delete m_text; + delete m_dialog; } void @@ -33,9 +38,9 @@ { if (m_map.find(category) == m_map.end()) { m_categoryOrder.push_back(category); + m_map[category] = KeyList(); } m_currentCategory = category; - m_map[category] = KeyList(); } void @@ -53,6 +58,8 @@ void KeyReference::registerShortcut(QString name, QString shortcut, QString tip) { + name.replace(tr("&"), ""); + KeyList &list = m_map[m_currentCategory]; for (KeyList::iterator i = list.begin(); i != list.end(); ++i) { @@ -82,6 +89,8 @@ void KeyReference::registerAlternativeShortcut(QString name, QString alternative) { + name.replace(tr("&"), ""); + KeyList &list = m_map[m_currentCategory]; for (KeyList::iterator i = list.begin(); i != list.end(); ++i) { @@ -95,9 +104,9 @@ void KeyReference::show() { - if (m_text) { - m_text->show(); - m_text->raise(); + if (m_dialog) { + m_dialog->show(); + m_dialog->raise(); return; } @@ -111,12 +120,14 @@ QString category = *i; KeyList &list = m_map[category]; - text += QString("<tr><td bgcolor=\"#d0d0d0\" colspan=3><br> <b>%1</b><br></td></tr>\n").arg(category); + text += QString("<tr><td bgcolor=\"#d0d0d0\" colspan=3 align=\"center\"><br><b>%1</b><br></td></tr>\n").arg(category); for (KeyList::iterator j = list.begin(); j != list.end(); ++j) { QString actionName = j->actionName; - actionName.replace(tr("&"), ""); + + QString shortcut = j->shortcut; + shortcut.replace(" ", " "); QString tip = j->tip; if (tip != "") tip = QString("<i>%1</i>").arg(tip); @@ -125,13 +136,15 @@ if (!j->alternatives.empty()) { for (std::vector<QString>::iterator k = j->alternatives.begin(); k != j->alternatives.end(); ++k) { - altdesc += tr("<i>or</i> <b>%1</b>").arg(*k); + QString alt = *k; + alt.replace(" ", " "); + altdesc += tr("<i>or</i> <b>%1</b>").arg(alt); } altdesc = tr("</b> (%1)<b>").arg(altdesc); } text += QString("<tr><td> <b>%1%2</b></td><td> %3</td><td>%4</td></tr>\n") - .arg(j->shortcut).arg(altdesc).arg(actionName).arg(tip); + .arg(shortcut).arg(altdesc).arg(actionName).arg(tip); } } @@ -140,9 +153,40 @@ m_text = new QTextEdit; m_text->setHtml(text); m_text->setReadOnly(true); - m_text->setObjectName(tr("Key Reference")); - m_text->show(); - m_text->resize(600, 450); - m_text->raise(); + + m_dialog = new QDialog; + m_dialog->setWindowTitle(tr("Sonic Visualiser: Key and Mouse Reference")); + + QVBoxLayout *layout = new QVBoxLayout; + m_dialog->setLayout(layout); + layout->addWidget(m_text); + + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close); + connect(bb, SIGNAL(clicked(QAbstractButton *)), this, SLOT(dialogButtonClicked(QAbstractButton *))); + layout->addWidget(bb); + + m_dialog->show(); + + QDesktopWidget *desktop = QApplication::desktop(); + QRect available = desktop->availableGeometry(); + + int width = available.width() * 3 / 5; + int height = available.height() * 2 / 3; + if (height < 450) { + if (available.height() > 500) height = 450; + } + if (width < 600) { + if (available.width() > 650) width = 600; + } + + m_dialog->resize(width, height); + m_dialog->raise(); } +void +KeyReference::dialogButtonClicked(QAbstractButton *) +{ + // only button is Close + m_dialog->hide(); +} +