• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mcallegari / qlcplus / 9306117670

30 May 2024 04:38PM UTC coverage: 32.028% (+0.02%) from 32.013%
9306117670

push

github

mcallegari
Enter 4.13.1 release

14020 of 43774 relevant lines covered (32.03%)

23948.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.5
/ui/src/assignhotkey.cpp
1
/*
2
  Q Light Controller
3
  assignhotkey.cpp
4

5
  Copyright (C) Heikki Junnila
6

7
  Licensed under the Apache License, Version 2.0 (the "License");
8
  you may not use this file except in compliance with the License.
9
  You may obtain a copy of the License at
10

11
      http://www.apache.org/licenses/LICENSE-2.0.txt
12

13
  Unless required by applicable law or agreed to in writing, software
14
  distributed under the License is distributed on an "AS IS" BASIS,
15
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
  See the License for the specific language governing permissions and
17
  limitations under the License.
18
*/
19

20
#include <QKeySequence>
21
#include <QTextBrowser>
22
#include <QSettings>
23
#include <QLineEdit>
24
#include <QKeyEvent>
25
#include <QDebug>
26
#include <QSettings>
27

28
#include "assignhotkey.h"
29

30
#define SETTINGS_GEOMETRY "assignhotkey/geometry"
31
#define SETTINGS_AUTOCLOSE "assignhotkey/autoclose"
32

33
/*****************************************************************************
34
 * Initialization
35
 *****************************************************************************/
36
AssignHotKey::AssignHotKey(QWidget* parent, const QKeySequence& keySequence)
4✔
37
    : QDialog(parent)
4✔
38
{
39
    setupUi(this);
4✔
40

41
#if defined(__APPLE__) || defined(WIN32)
42
    QString shift(QKeySequence(Qt::Key_Shift).toString(QKeySequence::NativeText));
43
    QString alt(QKeySequence(Qt::Key_Alt).toString(QKeySequence::NativeText));
44
    QString meta(QKeySequence(Qt::Key_Meta).toString(QKeySequence::NativeText));
45
#else
46
    QString shift("Shift");
8✔
47
    QString alt("Alt");
8✔
48
    QString meta("Meta");
8✔
49
#endif
50

51
    QString str("<HTML><HEAD><TITLE></TITLE></HEAD><BODY><CENTER>");
8✔
52
    str += QString("<H1>") + tr("Assign Key") + QString("</H1>");
12✔
53
    str += tr("Hit the key combination that you wish to assign. "
×
54
              "You may hit either a single key or a combination "
55
              "using %1, %2, and %3.").arg(shift).arg(alt).arg(meta);
8✔
56
    str += QString("</CENTER></BODY></HTML>");
8✔
57

58
    m_infoText->setText(str);
4✔
59
    m_infoText->setFocusPolicy(Qt::NoFocus);
4✔
60
    m_buttonBox->setFocusPolicy(Qt::NoFocus);
4✔
61

62
    m_previewEdit->setReadOnly(true);
4✔
63
    m_previewEdit->setAlignment(Qt::AlignCenter);
4✔
64

65
    m_keySequence = QKeySequence(keySequence);
4✔
66
    m_previewEdit->setText(m_keySequence.toString(QKeySequence::NativeText));
4✔
67

68
    QSettings settings;
8✔
69
    m_autoCloseCheckBox->setChecked(settings.value(SETTINGS_AUTOCLOSE).toBool());
4✔
70

71
    QVariant geometrySettings = settings.value(SETTINGS_GEOMETRY);
11✔
72
    if (geometrySettings.isValid() == true)
4✔
73
        restoreGeometry(geometrySettings.toByteArray());
3✔
74
}
4✔
75

76
AssignHotKey::~AssignHotKey()
4✔
77
{
78
    QSettings settings;
4✔
79
    settings.setValue(SETTINGS_GEOMETRY, saveGeometry());
4✔
80
    settings.setValue(SETTINGS_AUTOCLOSE, m_autoCloseCheckBox->isChecked());
4✔
81
}
4✔
82

83
QKeySequence AssignHotKey::keySequence() const
7✔
84
{
85
    return m_keySequence;
7✔
86
}
87

88
void AssignHotKey::keyPressEvent(QKeyEvent* event)
6✔
89
{
90
    int key = event->key();
6✔
91
    if (event->key() == Qt::Key_Control || event->key() == Qt::Key_Alt ||
5✔
92
        event->key() == Qt::Key_Shift || event->key() == Qt::Key_Meta)
9✔
93
    {
94
        key = 0;
95
    }
96

97
    m_keySequence = QKeySequence(key | (event->modifiers() & ~Qt::ControlModifier));
6✔
98
    m_previewEdit->setText(m_keySequence.toString(QKeySequence::NativeText));
6✔
99

100
    if (m_autoCloseCheckBox->isChecked() == true && key != 0)
6✔
101
        accept();
1✔
102
}
6✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc