MuseScore/mscore/shortcutcapturedialog.cpp

171 lines
5.5 KiB
C++
Raw Normal View History

2012-05-26 14:49:10 +02:00
//=============================================================================
// 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"
2013-05-13 18:49:17 +02:00
namespace Ms {
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
// ShortcutCaptureDialog
//---------------------------------------------------------
ShortcutCaptureDialog::ShortcutCaptureDialog(Shortcut* _s, QMap<QString, Shortcut*> ls, QWidget* parent)
: QDialog(parent)
{
setupUi(this);
setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
2012-05-26 14:49:10 +02:00
localShortcuts = ls;
s = _s;
addButton->setEnabled(false);
replaceButton->setEnabled(false);
oshrtLabel->setText(s->keysToString());
oshrtLabel->setEnabled(false);
2012-05-26 14:49:10 +02:00
connect(clearButton, SIGNAL(clicked()), SLOT(clearClicked()));
connect(addButton, SIGNAL(clicked()), SLOT(addClicked()));
connect(replaceButton, SIGNAL(clicked()), SLOT(replaceClicked()));
clearClicked();
nshrtLabel->installEventFilter(this);
2012-05-26 14:49:10 +02:00
}
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
// addClicked
//---------------------------------------------------------
void ShortcutCaptureDialog::addClicked()
{
done(1);
}
//---------------------------------------------------------
// replaceClicked
//---------------------------------------------------------
void ShortcutCaptureDialog::replaceClicked()
{
done(2);
}
//---------------------------------------------------------
// ShortcutCaptureDialog
//---------------------------------------------------------
ShortcutCaptureDialog::~ShortcutCaptureDialog()
{
nshrtLabel->removeEventFilter(this);
2012-05-26 14:49:10 +02:00
releaseKeyboard();
}
//---------------------------------------------------------
// eventFilter
//---------------------------------------------------------
bool ShortcutCaptureDialog::eventFilter(QObject* /*o*/, QEvent* e)
{
if (e->type() == QEvent::KeyPress) {
keyPress(static_cast<QKeyEvent*>(e));
return true;
2012-08-14 16:38:28 +02:00
}
return false;
2012-08-14 16:38:28 +02:00
}
2012-05-26 14:49:10 +02:00
//---------------------------------------------------------
// keyPressEvent
//---------------------------------------------------------
void ShortcutCaptureDialog::keyPress(QKeyEvent* e)
2012-05-26 14:49:10 +02:00
{
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();
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");
2012-05-26 14:49:10 +02:00
break;
}
// Check against conflicting shortcuts
bool conflict = false;
QString msgString;
foreach (Shortcut* ss, localShortcuts) {
if (s == ss)
continue;
2012-08-18 10:57:16 +02:00
if (! (s->state() & ss->state())) // no conflict if states do not overlap
continue;
2012-05-26 14:49:10 +02:00
foreach(const QKeySequence& ks, ss->keys()) {
if (ks == key) {
msgString = tr("Shortcut conflicts with ") + ss->descr();
conflict = true;
break;
}
}
if (conflict)
break;
}
messageLabel->setText(msgString);
addButton->setEnabled(conflict == false);
replaceButton->setEnabled(conflict == false);
// nshrtLabel->setText(key.toString(QKeySequence::NativeText));
QString keyStr = Shortcut::keySeqToString(key, QKeySequence::NativeText);
nshrtLabel->setText(keyStr);
2012-05-26 14:49:10 +02:00
// 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>",
2012-05-26 14:49:10 +02:00
k,
int(e->modifiers()),
int(e->nativeVirtualKey()),
int(e->nativeScanCode()),
qPrintable(A),
qPrintable(B)
);
}
//---------------------------------------------------------
// clearClicked
//---------------------------------------------------------
void ShortcutCaptureDialog::clearClicked()
{
2014-01-17 15:37:06 +01:00
nshrtLabel->setText("");
2012-05-26 14:49:10 +02:00
key = 0;
}
2013-05-13 18:49:17 +02:00
}
2012-05-26 14:49:10 +02:00