File indexing completed on 2024-11-24 03:56:28

0001 /*
0002  * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #include "clearable_keysequence_edit.hpp"
0008 #include "ui_clearable_keysequence_edit.h"
0009 #include <QEvent>
0010 
0011 class ClearableKeysequenceEdit::Private
0012 {
0013 public:
0014     Ui::ClearableKeysequenceEdit ui;
0015     QKeySequence default_ks;
0016 };
0017 
0018 ClearableKeysequenceEdit::ClearableKeysequenceEdit(QWidget* parent)
0019     : QWidget(parent), d(std::make_unique<Private>())
0020 {
0021     d->ui.setupUi(this);
0022 }
0023 
0024 ClearableKeysequenceEdit::~ClearableKeysequenceEdit() = default;
0025 
0026 void ClearableKeysequenceEdit::changeEvent ( QEvent* e )
0027 {
0028     QWidget::changeEvent(e);
0029 
0030     if ( e->type() == QEvent::LanguageChange)
0031     {
0032         d->ui.retranslateUi(this);
0033     }
0034 }
0035 
0036 void ClearableKeysequenceEdit::set_key_sequence(const QKeySequence& ks)
0037 {
0038     d->ui.sequence_edit->setKeySequence(ks);
0039 }
0040 
0041 void ClearableKeysequenceEdit::set_default_key_sequence(const QKeySequence& ks)
0042 {
0043     d->default_ks = ks;
0044 }
0045 
0046 QKeySequence ClearableKeysequenceEdit::key_sequence() const
0047 {
0048     return d->ui.sequence_edit->keySequence();
0049 }
0050 
0051 void ClearableKeysequenceEdit::use_default()
0052 {
0053     d->ui.sequence_edit->setKeySequence(d->default_ks);
0054 }
0055 
0056 void ClearableKeysequenceEdit::use_nothing()
0057 {
0058     d->ui.sequence_edit->setKeySequence({});
0059 }