Skip to content

Commit 08cc78a

Browse files
committed
Add missing files.
1 parent 5234a5c commit 08cc78a

File tree

6 files changed

+226
-13
lines changed

6 files changed

+226
-13
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* Key Binding Option
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#include "Common/Cpp/Json/JsonValue.h"
8+
#include "Common/Cpp/Containers/Pimpl.tpp"
9+
#include "Common/Cpp/Concurrency/SpinLock.h"
10+
#include "KeyBindingOption.h"
11+
12+
namespace PokemonAutomation{
13+
14+
15+
16+
struct KeyBindingCell::Data{
17+
const uint32_t m_default;
18+
19+
mutable SpinLock m_lock;
20+
uint32_t m_current;
21+
std::string m_current_text;
22+
23+
Data(uint32_t default_value)
24+
: m_default(default_value)
25+
, m_current(default_value)
26+
{}
27+
};
28+
29+
30+
31+
KeyBindingCell::~KeyBindingCell(){
32+
33+
}
34+
KeyBindingCell::KeyBindingCell(LockMode lock_while_program_is_running)
35+
: ConfigOption(lock_while_program_is_running)
36+
, m_data(CONSTRUCT_TOKEN, 0)
37+
{}
38+
39+
40+
KeyBindingCell::operator uint32_t() const{
41+
ReadSpinLock lg(m_data->m_lock);
42+
return m_data->m_current;
43+
}
44+
KeyBindingCell::operator std::string() const{
45+
ReadSpinLock lg(m_data->m_lock);
46+
return m_data->m_current_text;
47+
}
48+
void KeyBindingCell::set(uint32_t key){
49+
{
50+
ReadSpinLock lg(m_data->m_lock);
51+
m_data->m_current = key;
52+
}
53+
report_value_changed(this);
54+
}
55+
void KeyBindingCell::set(std::string text){
56+
ReadSpinLock lg(m_data->m_lock);
57+
m_data->m_current_text = std::move(text);
58+
}
59+
60+
61+
62+
void KeyBindingCell::load_json(const JsonValue& json){
63+
set((uint32_t)json.to_integer_default(0));
64+
}
65+
JsonValue KeyBindingCell::to_json() const{
66+
ReadSpinLock lg(m_data->m_lock);
67+
return m_data->m_current;
68+
}
69+
70+
void KeyBindingCell::restore_defaults(){
71+
set(m_data->m_default);
72+
}
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
}

Common/Cpp/Options/KeyBindingOption.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Key Binding Option
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_Options_KeyBindingOption_H
8+
#define PokemonAutomation_Options_KeyBindingOption_H
9+
10+
#include "Common/Cpp/Containers/Pimpl.h"
11+
#include "Common/Cpp/Options/ConfigOption.h"
12+
13+
namespace PokemonAutomation{
14+
15+
16+
17+
class KeyBindingCell : public ConfigOption{
18+
public:
19+
~KeyBindingCell();
20+
KeyBindingCell(LockMode lock_while_program_is_running);
21+
22+
operator uint32_t() const;
23+
operator std::string() const;
24+
void set(uint32_t key);
25+
26+
virtual void load_json(const JsonValue& json) override;
27+
virtual JsonValue to_json() const override;
28+
29+
virtual void restore_defaults() override;
30+
31+
virtual ConfigWidget* make_QtWidget(QWidget& parent) override;
32+
33+
34+
public:
35+
// UI Functions
36+
void set(std::string text);
37+
38+
39+
private:
40+
struct Data;
41+
Pimpl<Data> m_data;
42+
};
43+
44+
45+
46+
47+
}
48+
#endif

Common/Cpp/Options/StringOption.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ StringCell::StringCell(
4343
: ConfigOption(lock_while_program_is_running)
4444
, m_data(CONSTRUCT_TOKEN, is_password, std::move(default_value), std::move(placeholder_text))
4545
{}
46-
#if 0
47-
std::unique_ptr<ConfigOption> StringCell::clone() const{
48-
std::unique_ptr<StringCell> ret(new StringCell(
49-
m_is_password,
50-
m_label,
51-
m_default,
52-
m_placeholder_text
53-
));
54-
ret->m_current = m_current;
55-
return ret;
56-
}
57-
#endif
5846

5947
bool StringCell::is_password() const{
6048
return m_data->m_is_password;

Common/Cpp/Options/StringOption.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class StringCell : public ConfigOption{
2222
std::string default_value,
2323
std::string placeholder_text
2424
);
25-
// virtual std::unique_ptr<ConfigOption> clone() const override;
2625

2726
bool is_password() const;
2827
const std::string& placeholder_text() const;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* Key Binding Widget
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#include <QKeyEvent>
8+
#include "KeyBindingWidget.h"
9+
10+
//#include <iostream>
11+
//using std::cout;
12+
//using std::endl;
13+
14+
namespace PokemonAutomation{
15+
16+
17+
18+
ConfigWidget* KeyBindingCell::make_QtWidget(QWidget& parent){
19+
return new KeyBindingCellWidget(parent, *this);
20+
}
21+
22+
23+
24+
KeyBindingCellWidget::~KeyBindingCellWidget(){
25+
m_value.remove_listener(*this);
26+
}
27+
KeyBindingCellWidget::KeyBindingCellWidget(QWidget& parent, KeyBindingCell& value)
28+
: QLineEdit(&parent)
29+
, ConfigWidget(value, *this)
30+
, m_value(value)
31+
{
32+
KeyBindingCellWidget::update_value();
33+
m_value.add_listener(*this);
34+
}
35+
36+
37+
void KeyBindingCellWidget::keyPressEvent(QKeyEvent* event){
38+
m_value.set(event->key());
39+
}
40+
41+
42+
void KeyBindingCellWidget::update_value(){
43+
QKeySequence seq((Qt::Key)(uint32_t)m_value);
44+
// cout << (uint32_t)m_value << endl;
45+
this->setText(seq.toString());
46+
}
47+
void KeyBindingCellWidget::value_changed(void* object){
48+
QMetaObject::invokeMethod(this, [this]{
49+
update_value();
50+
}, Qt::QueuedConnection);
51+
}
52+
53+
54+
55+
56+
57+
58+
59+
60+
}

Common/Qt/Options/KeyBindingWidget.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* Key Binding Widget
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_Options_KeyBindingWidget_H
8+
#define PokemonAutomation_Options_KeyBindingWidget_H
9+
10+
#include <QLineEdit>
11+
#include "Common/Cpp/Options/KeyBindingOption.h"
12+
#include "ConfigWidget.h"
13+
14+
namespace PokemonAutomation{
15+
16+
17+
18+
class KeyBindingCellWidget : public QLineEdit, public ConfigWidget{
19+
public:
20+
~KeyBindingCellWidget();
21+
KeyBindingCellWidget(QWidget& parent, KeyBindingCell& value);
22+
23+
virtual void update_value() override;
24+
virtual void value_changed(void* object) override;
25+
26+
virtual void keyPressEvent(QKeyEvent* event) override;
27+
28+
private:
29+
KeyBindingCell& m_value;
30+
};
31+
32+
33+
34+
35+
}
36+
#endif

0 commit comments

Comments
 (0)