MCPcopy Create free account
hub / github.com/alpha-liu-01/SpeedyNote / KeyCaptureDialog

Method KeyCaptureDialog

source/ui/dialogs/KeyCaptureDialog.cpp:5–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include <QKeySequence>
4
5KeyCaptureDialog::KeyCaptureDialog(QWidget *parent) : QDialog(parent) {
6 setWindowTitle(tr("Capture Key Sequence"));
7 setFixedSize(350, 150);
8 setModal(true);
9
10 // Ensure we can capture all key events including Tab
11 setFocusPolicy(Qt::StrongFocus);
12
13 // Create UI elements
14 instructionLabel = new QLabel(tr("Press the key combination you want to use:"), this);
15 instructionLabel->setWordWrap(true);
16
17 capturedLabel = new QLabel(tr("(No key captured yet)"), this);
18 capturedLabel->setStyleSheet("QLabel { padding: 8px; border: 1px solid #ccc; }");
19 capturedLabel->setAlignment(Qt::AlignCenter);
20
21 // Buttons
22 clearButton = new QPushButton(tr("Clear"), this);
23 okButton = new QPushButton(tr("OK"), this);
24 cancelButton = new QPushButton(tr("Cancel"), this);
25
26 okButton->setDefault(true);
27 okButton->setEnabled(false); // Disabled until a key is captured
28
29 // Layout
30 QVBoxLayout *mainLayout = new QVBoxLayout(this);
31 mainLayout->addWidget(instructionLabel);
32 mainLayout->addWidget(capturedLabel);
33
34 QHBoxLayout *buttonLayout = new QHBoxLayout();
35 buttonLayout->addWidget(clearButton);
36 buttonLayout->addStretch();
37 buttonLayout->addWidget(okButton);
38 buttonLayout->addWidget(cancelButton);
39
40 mainLayout->addLayout(buttonLayout);
41
42 // Connections
43 connect(clearButton, &QPushButton::clicked, this, &KeyCaptureDialog::clearSequence);
44 connect(okButton, &QPushButton::clicked, this, &QDialog::accept);
45 connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);
46
47 // Set focus to capture keys immediately
48 setFocus();
49}
50
51void KeyCaptureDialog::keyPressEvent(QKeyEvent *event) {
52 // Ignore auto-repeat events (when user holds a key)

Callers

nothing calls this directly

Calls 4

connectFunction · 0.85
addWidgetMethod · 0.80
setEnabledMethod · 0.45
addStretchMethod · 0.45

Tested by

no test coverage detected