1 #include "common/common_pch.h"
2
3 #include <QCheckBox>
4 #include <QComboBox>
5
6 #include "common/qt.h"
7 #include "mkvtoolnix-gui/header_editor/bool_value_page.h"
8
9 namespace mtx::gui::HeaderEditor {
10
11 using namespace mtx::gui;
12
BoolValuePage(Tab & parent,PageBase & topLevelPage,EbmlMaster & master,EbmlCallbacks const & callbacks,translatable_string_c const & title,translatable_string_c const & description)13 BoolValuePage::BoolValuePage(Tab &parent,
14 PageBase &topLevelPage,
15 EbmlMaster &master,
16 EbmlCallbacks const &callbacks,
17 translatable_string_c const &title,
18 translatable_string_c const &description)
19 : ValuePage{parent, topLevelPage, master, callbacks, ValueType::Bool, title, description}
20 {
21 }
22
~BoolValuePage()23 BoolValuePage::~BoolValuePage() {
24 }
25
26 QWidget *
createInputControl()27 BoolValuePage::createInputControl() {
28 m_cbValue = new QComboBox{this};
29 m_cbValue->addItem(QY("No"));
30 m_cbValue->addItem(QY("Yes"));
31
32 if (m_element)
33 m_originalValue = std::min<uint64_t>(static_cast<EbmlUInteger *>(m_element)->GetValue(), 1);
34
35 m_cbValue->setCurrentIndex(m_originalValue);
36
37 return m_cbValue;
38 }
39
40 QString
originalValueAsString() const41 BoolValuePage::originalValueAsString()
42 const {
43 return m_originalValue ? QY("Yes") : QY("No");
44 }
45
46 QString
currentValueAsString() const47 BoolValuePage::currentValueAsString()
48 const {
49 return m_cbValue->currentText();
50 }
51
52 void
resetValue()53 BoolValuePage::resetValue() {
54 m_cbValue->setCurrentIndex(m_originalValue);
55 }
56
57 bool
validateValue() const58 BoolValuePage::validateValue()
59 const {
60 return true;
61 }
62
63 void
copyValueToElement()64 BoolValuePage::copyValueToElement() {
65 static_cast<EbmlUInteger *>(m_element)->SetValue(m_cbValue->currentIndex());
66 }
67
68 void
toggleFlag()69 BoolValuePage::toggleFlag() {
70 if (!m_present && !m_cbAddOrRemove->isChecked())
71 m_cbAddOrRemove->setChecked(true);
72
73 m_cbValue->setCurrentIndex(1 - m_cbValue->currentIndex());
74 }
75
76 }
77