1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
//=============================================================================
// MusE Score
// Linux Music Score Editor
// $Id: shortcutcapturedialog.cpp 5537 2012-04-16 07:55:10Z wschweer $
//
// Copyright (C) 2002-2007 Werner Schweer and others
// Copyright (C) 2003 Mathias Lundgren (lunar_shuttle@users.sourceforge.net)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
#include "shortcutcapturedialog.h"
#include "musescore.h"
#include "shortcut.h"
namespace Ms {
//---------------------------------------------------------
// ShortcutCaptureDialog
//---------------------------------------------------------
ShortcutCaptureDialog::ShortcutCaptureDialog(Shortcut* _s, QMap<QString, Shortcut*> ls, QWidget* parent)
: QDialog(parent)
{
setObjectName("ShortcutCaptureDialog");
setupUi(this);
setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
localShortcuts = ls;
s = _s;
addButton->setEnabled(false);
replaceButton->setEnabled(false);
oshrtLabel->setText(s->keysToString());
oshrtTextLabel->setAccessibleDescription(s->keysToString());
oshrtLabel->setEnabled(false);
connect(clearButton, SIGNAL(clicked()), SLOT(clearClicked()));
connect(addButton, SIGNAL(clicked()), SLOT(addClicked()));
connect(replaceButton, SIGNAL(clicked()), SLOT(replaceClicked()));
clearClicked();
nshrtLabel->installEventFilter(this);
MuseScore::restoreGeometry(this);
}
//---------------------------------------------------------
// addClicked
//---------------------------------------------------------
void ShortcutCaptureDialog::addClicked()
{
done(1);
}
//---------------------------------------------------------
// replaceClicked
//---------------------------------------------------------
void ShortcutCaptureDialog::replaceClicked()
{
done(2);
}
//---------------------------------------------------------
// ShortcutCaptureDialog
//---------------------------------------------------------
ShortcutCaptureDialog::~ShortcutCaptureDialog()
{
nshrtLabel->removeEventFilter(this);
releaseKeyboard();
}
//---------------------------------------------------------
// eventFilter
//---------------------------------------------------------
bool ShortcutCaptureDialog::eventFilter(QObject* /*o*/, QEvent* e)
{
if (e->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(e);
if(keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Backtab){
QWidget::keyPressEvent(keyEvent);
return true;
}
keyPress(keyEvent);
return true;
}
return false;
}
//---------------------------------------------------------
// keyPressEvent
//---------------------------------------------------------
void ShortcutCaptureDialog::keyPress(QKeyEvent* e)
{
if (key.count() >= 4)
return;
int k = e->key();
if (k == 0 || k == Qt::Key_Shift || k == Qt::Key_Control ||
k == Qt::Key_Meta || k == Qt::Key_Alt || k == Qt::Key_AltGr
|| k == Qt::Key_CapsLock || k == Qt::Key_NumLock
|| k == Qt::Key_ScrollLock || k == Qt::Key_unknown)
return;
k += e->modifiers();
// remove shift-modifier for keys that don't need it: letters and special keys
if ((k & Qt::ShiftModifier) && ((e->key() < 0x41) || (e->key() > 0x5a) || (e->key() >= 0x01000000))) {
qDebug() << k;
k -= Qt::ShiftModifier;
qDebug() << k;
}
switch(key.count()) {
case 0: key = QKeySequence(k); break;
case 1: key = QKeySequence(key[0], k); break;
case 2: key = QKeySequence(key[0], key[1], k); break;
case 3: key = QKeySequence(key[0], key[1], key[2], k); break;
default:
qDebug("Internal error: bad key count");
break;
}
// Check against conflicting shortcuts
bool conflict = false;
QString msgString;
for (Shortcut* ss : localShortcuts) {
if (s == ss)
continue;
if (!(s->state() & ss->state())) // no conflict if states do not overlap
continue;
QList<QKeySequence> skeys = QKeySequence::keyBindings(ss->standardKey());
for (const QKeySequence& ks : skeys) {
if (ks == key) {
msgString = tr("Shortcut conflicts with %1").arg(ss->descr());
conflict = true;
break;
}
}
for (const QKeySequence& ks : ss->keys()) {
if (ks == key) {
msgString = tr("Shortcut conflicts with %1").arg(ss->descr());
conflict = true;
break;
}
}
if (conflict)
break;
}
messageLabel->setText(msgString);
if (conflict) {
if (!nshrtLabel->accessibleName().contains(tr("Shortcut conflicts with")))
nshrtLabel->setAccessibleName(msgString);
}
else {
if (!nshrtLabel->accessibleName().contains("New shortcut"))
nshrtLabel->setAccessibleName(tr("New shortcut"));
}
addButton->setEnabled(conflict == false);
replaceButton->setEnabled(conflict == false);
// nshrtLabel->setText(key.toString(QKeySequence::NativeText));
QString keyStr = Shortcut::keySeqToString(key, QKeySequence::NativeText);
nshrtLabel->setText(keyStr);
// QString A = key.toString(QKeySequence::NativeText);
QString A = keyStr;
QString B = Shortcut::keySeqToString(key, QKeySequence::PortableText);
qDebug("capture key 0x%x modifiers 0x%x virt 0x%x scan 0x%x <%s><%s>",
k,
int(e->modifiers()),
int(e->nativeVirtualKey()),
int(e->nativeScanCode()),
qPrintable(A),
qPrintable(B)
);
}
//---------------------------------------------------------
// clearClicked
//---------------------------------------------------------
void ShortcutCaptureDialog::clearClicked()
{
if (!nshrtLabel->accessibleName().contains("New shortcut"))
nshrtLabel->setAccessibleName(tr("New shortcut"));
nshrtLabel->setAccessibleName(tr("New shortcut"));
messageLabel->setText("");
addButton->setEnabled(false);
replaceButton->setEnabled(false);
nshrtLabel->setText("");
key = 0;
nshrtLabel->setFocus();
}
//---------------------------------------------------------
// hideEvent
//---------------------------------------------------------
void ShortcutCaptureDialog::hideEvent(QHideEvent* event)
{
MuseScore::saveGeometry(this);
QWidget::hideEvent(event);
}
}
|