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
|
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2009 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
#include "btshortcutsdialog.h"
#include <QVBoxLayout>
#include <QGridLayout>
#include <QRadioButton>
#include <QLabel>
#include <QDialogButtonBox>
#include <QKeyEvent>
// *************** BtShortcutsDialog ***************************************************************************
// A dialog to allow the user to input a shortcut for a primary and alternate key
// dialog constructor
BtShortcutsDialog::BtShortcutsDialog(QWidget* parent)
: QDialog(parent), m_primaryLabel(0), m_alternateLabel(0), m_primaryButton(0), m_alternateButton(0)
{
setWindowTitle(tr("Configure shortcuts"));
setMinimumWidth(350);
QVBoxLayout* vLayout = new QVBoxLayout(this);
setLayout(vLayout);
QGridLayout* gridLayout = new QGridLayout();
vLayout->addLayout(gridLayout);
m_primaryButton = new QRadioButton(tr("First shortcut"));
m_primaryButton->setChecked(true);
gridLayout->addWidget(m_primaryButton, 0, 0);
m_alternateButton = new QRadioButton(tr("Second shortcut"));
gridLayout->addWidget(m_alternateButton, 1, 0);
m_primaryLabel = new QLabel();
m_primaryLabel->setMinimumWidth(100);
m_primaryLabel->setFrameShape(QFrame::Panel);
gridLayout->addWidget(m_primaryLabel, 0, 1);
m_alternateLabel = new QLabel();
m_alternateLabel->setMinimumWidth(100);
m_alternateLabel->setFrameShape(QFrame::Panel);
gridLayout->addWidget(m_alternateLabel, 1, 1);
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
vLayout->addWidget(buttons);
connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
}
// get new primary key from dialog
QString BtShortcutsDialog::getFirstKeys()
{
return m_primaryLabel->text();
}
// set the initial value of the primary key
void BtShortcutsDialog::setFirstKeys(const QString& keys)
{
m_primaryLabel->setText(keys);
}
// get new second keys from dialog
QString BtShortcutsDialog::getSecondKeys()
{
return m_alternateLabel->text();
}
// set the initial value of the second keys
void BtShortcutsDialog::setSecondKeys(const QString& keys)
{
m_alternateLabel->setText(keys);
}
// get key from users input, put into primary or alternate label for display to user
void BtShortcutsDialog::keyReleaseEvent(QKeyEvent* event)
{
int key = event->key();
if ( (key == Qt::Key_Shift) || (key == Qt::Key_Control) || (key == Qt::Key_Meta) || (key == Qt::Key_Alt) )
return;
QKeySequence keys(key);
QString keyStr = keys.toString();
if ( (event->modifiers() & Qt::AltModifier) == Qt::AltModifier)
keyStr = "Alt+" + keyStr;
if ( (event->modifiers() & Qt::ShiftModifier) == Qt::ShiftModifier)
keyStr = "Shift+" + keyStr;
if ( (event->modifiers() & Qt::ControlModifier) == Qt::ControlModifier)
keyStr = "Ctrl+" + keyStr;
QKeySequence completeKeys(keyStr);
QString completeStr = completeKeys.toString();
keyChangeRequest(completeStr);
}
// complete the keyChangeRequest
void BtShortcutsDialog::changeSelectedShortcut(const QString& keys)
{
if (m_primaryButton->isChecked())
m_primaryLabel->setText(keys);
if (m_alternateButton->isChecked())
m_alternateLabel->setText(keys);
}
|