# HG changeset patch # User Chris Cannam # Date 1183633621 0 # Node ID 4edaff85875d4fed29ff34cc7ef7cfbfd4c36862 # Parent ac58acbd74820698b2d6e3db6ca4ec6dadf7f5a8 * 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 diff -r ac58acbd7482 -r 4edaff85875d layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Wed Jul 04 17:22:12 2007 +0000 +++ b/layer/SpectrogramLayer.cpp Thu Jul 05 11:07:01 2007 +0000 @@ -2502,6 +2502,11 @@ QPoint cursorPos) const { paint.save(); + QFont fn = paint.font(); + if (fn.pointSize() > 8) { + fn.setPointSize(fn.pointSize() - 1); + paint.setFont(fn); + } paint.setPen(m_crosshairColour); paint.drawLine(0, cursorPos.y(), cursorPos.x() - 1, cursorPos.y()); diff -r ac58acbd7482 -r 4edaff85875d layer/SpectrumLayer.cpp --- a/layer/SpectrumLayer.cpp Wed Jul 04 17:22:12 2007 +0000 +++ b/layer/SpectrumLayer.cpp Thu Jul 05 11:07:01 2007 +0000 @@ -440,6 +440,11 @@ if (!m_sliceableModel) return; paint.save(); + QFont fn = paint.font(); + if (fn.pointSize() > 8) { + fn.setPointSize(fn.pointSize() - 1); + paint.setFont(fn); + } ColourMapper mapper(m_colourMap, 0, 1); paint.setPen(mapper.getContrastingColour()); diff -r ac58acbd7482 -r 4edaff85875d view/Pane.cpp --- a/view/Pane.cpp Wed Jul 04 17:22:12 2007 +0000 +++ b/view/Pane.cpp Thu Jul 05 11:07:01 2007 +0000 @@ -39,6 +39,8 @@ #include "widgets/RangeInputDialog.h" #include "widgets/NotifyingPushButton.h" +#include "widgets/KeyReference.h" //!!! should probably split KeyReference into a data class in base and another that shows the widget + using std::cerr; using std::endl; @@ -1004,6 +1006,64 @@ } void +Pane::registerShortcuts(KeyReference &kr) +{ + kr.setCategory(tr("Zoom")); + kr.registerAlternativeShortcut(tr("Zoom In"), tr("Wheel Up")); + kr.registerAlternativeShortcut(tr("Zoom Out"), tr("Wheel Down")); + + kr.setCategory(tr("General Pane Mouse Actions")); + + kr.registerShortcut(tr("Zoom"), tr("Wheel"), + tr("Zoom in or out in time axis")); + kr.registerShortcut(tr("Ctrl+Wheel"), tr("Scroll"), + tr("Scroll rapidly left or right in time axis")); + kr.registerShortcut(tr("Zoom Vertically"), tr("Shift+Wheel"), + tr("Zoom in or out in the vertical axis")); + kr.registerShortcut(tr("Scroll Vertically"), tr("Alt+Wheel"), + tr("Scroll up or down in the vertical axis")); + kr.registerShortcut(tr("Navigate"), tr("Middle"), + tr("Click middle button and drag to navigate with any tool")); + kr.registerShortcut(tr("Relocate"), tr("Double-Click Middle"), + tr("Double-click middle button to relocate with any tool")); + kr.registerShortcut(tr("Menu"), tr("Right"), + tr("Show pane context menu")); + + kr.setCategory(tr("Navigate Tool Mouse Actions")); + + kr.registerShortcut(tr("Navigate"), tr("Left"), + tr("Click left button and drag to move around")); + kr.registerShortcut(tr("Zoom to Area"), tr("Shift+Left"), + tr("Shift-click left button and drag to zoom to a rectangular area")); + kr.registerShortcut(tr("Relocate"), tr("Double-Click Left"), + tr("Double-click left button to jump to clicked location")); + kr.registerShortcut(tr("Edit"), tr("Double-Click Left"), + tr("Double-click left button on an item to edit it")); + + kr.setCategory(tr("Select Tool Mouse Actions")); + kr.registerShortcut(tr("Select"), tr("Left"), + tr("Click left button and drag to select region; drag region edge to resize")); + kr.registerShortcut(tr("Multi Select"), tr("Ctrl+Left"), + tr("Ctrl-click left button and drag to select an additional region")); + + kr.setCategory(tr("Edit Tool Mouse Actions")); + kr.registerShortcut(tr("Move"), tr("Left"), + tr("Click left button on an item or selected region and drag to move")); + kr.registerShortcut(tr("Edit"), tr("Double-Click Left"), + tr("Double-click left button on an item to edit it")); + + kr.setCategory(tr("Draw Tool Mouse Actions")); + kr.registerShortcut(tr("Draw"), tr("Left"), + tr("Click left button and drag to create new item")); + + kr.setCategory(tr("Measure Tool Mouse Actions")); + kr.registerShortcut(tr("Measure Area"), tr("Left"), + tr("Click left button and drag to measure a rectangular area")); + kr.registerShortcut(tr("Measure Item"), tr("Double-Click Left"), + tr("Click left button and drag to measure extents of an item or shape")); +} + +void Pane::mousePressEvent(QMouseEvent *e) { if (e->buttons() & Qt::RightButton) { diff -r ac58acbd7482 -r 4edaff85875d view/Pane.h --- a/view/Pane.h Wed Jul 04 17:22:12 2007 +0000 +++ b/view/Pane.h Thu Jul 05 11:07:01 2007 +0000 @@ -30,6 +30,7 @@ class Thumbwheel; class Panner; class NotifyingPushButton; +class KeyReference; class Pane : public View { @@ -60,6 +61,8 @@ virtual QString toXmlString(QString indent = "", QString extraAttributes = "") const; + static void registerShortcuts(KeyReference &kr); + signals: void paneInteractedWith(); void rightButtonMenuRequested(QPoint position); diff -r ac58acbd7482 -r 4edaff85875d widgets/ItemEditDialog.cpp --- a/widgets/ItemEditDialog.cpp Wed Jul 04 17:22:12 2007 +0000 +++ b/widgets/ItemEditDialog.cpp Thu Jul 05 11:07:01 2007 +0000 @@ -23,6 +23,7 @@ #include #include #include +#include #include // for FLT_MIN/MAX @@ -172,18 +173,16 @@ } else if (options & ShowValue) { m_valueSpinBox->setFocus(Qt::OtherFocusReason); } - - QHBoxLayout *hbox = new QHBoxLayout; - grid->addLayout(hbox, row, 0, 1, 2); + + QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal); + grid->addWidget(bb, row, 0, 1, 2); QPushButton *ok = new QPushButton(tr("OK")); m_resetButton = new QPushButton(tr("Reset")); QPushButton *cancel = new QPushButton(tr("Cancel")); - hbox->addStretch(10); - hbox->addWidget(ok); - hbox->addWidget(m_resetButton); - hbox->addWidget(cancel); - ok->setDefault(true); + bb->addButton(ok, QDialogButtonBox::AcceptRole); + bb->addButton(m_resetButton, QDialogButtonBox::ResetRole); + bb->addButton(cancel, QDialogButtonBox::RejectRole); connect(ok, SIGNAL(clicked()), this, SLOT(accept())); connect(m_resetButton, SIGNAL(clicked()), this, SLOT(reset())); connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); diff -r ac58acbd7482 -r 4edaff85875d widgets/KeyReference.cpp --- 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 #include +#include +#include +#include +#include +#include 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("
 %1
\n").arg(category); + text += QString("
%1
\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("%1").arg(tip); @@ -125,13 +136,15 @@ if (!j->alternatives.empty()) { for (std::vector::iterator k = j->alternatives.begin(); k != j->alternatives.end(); ++k) { - altdesc += tr("or %1").arg(*k); + QString alt = *k; + alt.replace(" ", " "); + altdesc += tr("or %1").arg(alt); } altdesc = tr(" (%1)").arg(altdesc); } text += QString(" %1%2 %3%4\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(); +} + diff -r ac58acbd7482 -r 4edaff85875d widgets/KeyReference.h --- a/widgets/KeyReference.h Wed Jul 04 17:22:12 2007 +0000 +++ b/widgets/KeyReference.h Thu Jul 05 11:07:01 2007 +0000 @@ -23,6 +23,8 @@ class QAction; class QTextEdit; +class QDialog; +class QAbstractButton; class KeyReference : public QObject { @@ -42,6 +44,9 @@ void show(); +protected slots: + void dialogButtonClicked(QAbstractButton *); + protected: struct KeyDetails { QString actionName; @@ -59,6 +64,7 @@ CategoryList m_categoryOrder; QTextEdit *m_text; + QDialog *m_dialog; }; #endif diff -r ac58acbd7482 -r 4edaff85875d widgets/ListInputDialog.cpp --- a/widgets/ListInputDialog.cpp Wed Jul 04 17:22:12 2007 +0000 +++ b/widgets/ListInputDialog.cpp Thu Jul 05 11:07:01 2007 +0000 @@ -21,6 +21,7 @@ #include #include #include +#include ListInputDialog::ListInputDialog(QWidget *parent, const QString &title, const QString &labelText, const QStringList &list, @@ -49,25 +50,12 @@ m_footnote = new QLabel; vbox->addWidget(m_footnote); m_footnote->hide(); - - QHBoxLayout *hbox = new QHBoxLayout; - vbox->addLayout(hbox, Qt::AlignRight); - - QPushButton *ok = new QPushButton(tr("OK"), this); - ok->setDefault(true); - - QPushButton *cancel = new QPushButton(tr("Cancel"), this); - - QSize bs = ok->sizeHint().expandedTo(cancel->sizeHint()); - ok->setFixedSize(bs); - cancel->setFixedSize(bs); - - hbox->addStretch(); - hbox->addWidget(ok); - hbox->addWidget(cancel); - - QObject::connect(ok, SIGNAL(clicked()), this, SLOT(accept())); - QObject::connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); + + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | + QDialogButtonBox::Cancel); + vbox->addWidget(bb); + connect(bb, SIGNAL(accepted()), this, SLOT(accept())); + connect(bb, SIGNAL(rejected()), this, SLOT(reject())); } ListInputDialog::~ListInputDialog() diff -r ac58acbd7482 -r 4edaff85875d widgets/PluginParameterDialog.cpp --- a/widgets/PluginParameterDialog.cpp Wed Jul 04 17:22:12 2007 +0000 +++ b/widgets/PluginParameterDialog.cpp Thu Jul 05 11:07:01 2007 +0000 @@ -31,6 +31,7 @@ #include #include #include +#include PluginParameterDialog::PluginParameterDialog(Vamp::PluginBase *plugin, QWidget *parent) : @@ -224,14 +225,11 @@ hbox->addWidget(m_advancedButton); m_advancedButton->hide(); - QPushButton *ok = new QPushButton(tr("OK")); - QPushButton *cancel = new QPushButton(tr("Cancel")); - ok->setDefault(true); - hbox->addStretch(10); - hbox->addWidget(ok); - hbox->addWidget(cancel); - connect(ok, SIGNAL(clicked()), this, SLOT(accept())); - connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | + QDialogButtonBox::Cancel); + hbox->addWidget(bb); + connect(bb, SIGNAL(accepted()), this, SLOT(accept())); + connect(bb, SIGNAL(rejected()), this, SLOT(reject())); setAdvancedVisible(m_advancedVisible); } @@ -383,7 +381,7 @@ blockSizeCombo->addItem(QString("%1").arg(size)); blockSizeCombo->setCurrentIndex(blockSizeCombo->count() - 1); } - blockSizeCombo->setValidator(new QIntValidator(1, pow(2, 18), this)); + blockSizeCombo->setValidator(new QIntValidator(1, int(pow(2, 18)), this)); connect(blockSizeCombo, SIGNAL(editTextChanged(const QString &)), this, SLOT(blockSizeComboChanged(const QString &))); windowLayout->addWidget(blockSizeCombo, 0, 1); @@ -405,7 +403,7 @@ incrementCombo->addItem(QString("%1").arg(increment)); incrementCombo->setCurrentIndex(incrementCombo->count() - 1); } - incrementCombo->setValidator(new QIntValidator(1, pow(2, 18), this)); + incrementCombo->setValidator(new QIntValidator(1, int(pow(2, 18)), this)); connect(incrementCombo, SIGNAL(editTextChanged(const QString &)), this, SLOT(incrementComboChanged(const QString &))); windowLayout->addWidget(incrementCombo, 1, 1); diff -r ac58acbd7482 -r 4edaff85875d widgets/RangeInputDialog.cpp --- a/widgets/RangeInputDialog.cpp Wed Jul 04 17:22:12 2007 +0000 +++ b/widgets/RangeInputDialog.cpp Thu Jul 05 11:07:01 2007 +0000 @@ -19,6 +19,7 @@ #include #include #include +#include #include RangeInputDialog::RangeInputDialog(QString title, QString message, @@ -55,24 +56,11 @@ connect(m_rangeEnd, SIGNAL(valueChanged(double)), this, SLOT(rangeEndChanged(double))); - QHBoxLayout *hbox = new QHBoxLayout; - grid->addLayout(hbox, 2, 0, 1, 5); - - QPushButton *ok = new QPushButton(tr("OK"), this); - ok->setDefault(true); - - QPushButton *cancel = new QPushButton(tr("Cancel"), this); - - QSize bs = ok->sizeHint().expandedTo(cancel->sizeHint()); - ok->setFixedSize(bs); - cancel->setFixedSize(bs); - - hbox->addStretch(); - hbox->addWidget(ok); - hbox->addWidget(cancel); - - QObject::connect(ok, SIGNAL(clicked()), this, SLOT(accept())); - QObject::connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | + QDialogButtonBox::Cancel); + grid->addWidget(bb, 2, 0, 1, 5); + connect(bb, SIGNAL(accepted()), this, SLOT(accept())); + connect(bb, SIGNAL(rejected()), this, SLOT(reject())); } RangeInputDialog::~RangeInputDialog()