Skip to content

Commit de950da

Browse files
committed
Add KeyboardInfo class
1 parent b8945b6 commit de950da

File tree

6 files changed

+88
-3
lines changed

6 files changed

+88
-3
lines changed

src/keyboard/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ set(MODULE_URI Keyboard)
33
set(MODULE_SRC
44
keyboardmodule.cpp
55
keyboardmodule.h
6+
ikeyboardinfo.h
7+
internal/keyboardinfo.cpp
8+
internal/keyboardinfo.h
69
)
710

811
include(${PROJECT_SOURCE_DIR}/build/module.cmake)

src/keyboard/ikeyboardinfo.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
#pragma once
4+
5+
#include <modularity/ioc.h>
6+
#include <Qt>
7+
8+
namespace scratchcpp::keyboard
9+
{
10+
11+
class IKeyboardInfo : MODULE_EXPORT_INTERFACE
12+
{
13+
public:
14+
virtual ~IKeyboardInfo() { }
15+
16+
virtual Qt::KeyboardModifiers keyboardModifiers() const = 0;
17+
};
18+
19+
} // namespace scratchcpp::keyboard
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
#include <QGuiApplication>
4+
5+
#include "keyboardinfo.h"
6+
7+
using namespace scratchcpp::keyboard;
8+
9+
KeyboardInfo::KeyboardInfo(QObject *parent) :
10+
QObject(parent)
11+
{
12+
}
13+
14+
Qt::KeyboardModifiers KeyboardInfo::keyboardModifiers() const
15+
{
16+
return QGuiApplication::keyboardModifiers();
17+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
#pragma once
4+
5+
#include <QObject>
6+
7+
#include "ikeyboardinfo.h"
8+
9+
namespace scratchcpp::keyboard
10+
{
11+
12+
class KeyboardInfo
13+
: public QObject
14+
, public IKeyboardInfo
15+
{
16+
Q_OBJECT
17+
18+
public:
19+
explicit KeyboardInfo(QObject *parent = nullptr);
20+
21+
Q_INVOKABLE Qt::KeyboardModifiers keyboardModifiers() const override;
22+
};
23+
24+
} // namespace scratchcpp::keyboard

src/keyboard/keyboardmodule.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
22

3+
#include <QQmlEngine>
4+
5+
#include "modularity/ioc.h"
36
#include "keyboardmodule.h"
7+
#include "internal/keyboardinfo.h"
48

5-
using namespace scratchcpp;
9+
using namespace scratchcpp::keyboard;
610

711
std::string KeyboardModule::moduleName() const
812
{
913
return "keyboard";
1014
}
15+
16+
void KeyboardModule::registerExports()
17+
{
18+
m_keyboardInfo = std::make_shared<KeyboardInfo>();
19+
20+
QQmlEngine::setObjectOwnership(m_keyboardInfo.get(), QQmlEngine::CppOwnership);
21+
qmlRegisterSingletonInstance<KeyboardInfo>("ScratchCPP.Keyboard", 1, 0, "KeyboardInfo", m_keyboardInfo.get());
22+
modularity::ioc()->registerExport<IKeyboardInfo>(m_keyboardInfo);
23+
}

src/keyboard/keyboardmodule.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@
22

33
#pragma once
44

5+
#include <memory>
6+
57
#include "modularity/imodulesetup.h"
68

7-
namespace scratchcpp
9+
namespace scratchcpp::keyboard
810
{
911

12+
class KeyboardInfo;
13+
1014
class KeyboardModule : public modularity::IModuleSetup
1115
{
1216
public:
1317
std::string moduleName() const override;
18+
19+
void registerExports() override;
20+
21+
private:
22+
std::shared_ptr<KeyboardInfo> m_keyboardInfo;
1423
};
1524

16-
} // namespace scratchcpp
25+
} // namespace scratchcpp::keyboard

0 commit comments

Comments
 (0)