-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: mohamedsayed18 <[email protected]> Co-authored-by: Louise Poubel <[email protected]>
- Loading branch information
1 parent
0f64650
commit 9ec2140
Showing
8 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0"?> | ||
|
||
<plugin filename="KeyPublisher"> | ||
</plugin> | ||
|
||
<plugin filename="TopicEcho"> | ||
</plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
ign_gui_add_plugin(KeyPublisher | ||
SOURCES | ||
KeyPublisher.cc | ||
QT_HEADERS | ||
KeyPublisher.hh | ||
TEST_SOURCES # todo | ||
# KeyPublisher_TEST.cc | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (C) 2020 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#include <ignition/msgs/int32.pb.h> | ||
#include <ignition/gui/Application.hh> | ||
#include <ignition/gui/MainWindow.hh> | ||
#include <ignition/plugin/Register.hh> | ||
|
||
#include "KeyPublisher.hh" | ||
|
||
namespace ignition | ||
{ | ||
namespace gui | ||
{ | ||
class KeyPublisherPrivate | ||
{ | ||
/// \brief Node for communication | ||
public: ignition::transport::Node node; | ||
|
||
/// \brief Publisher | ||
public: ignition::transport::Node::Publisher pub; | ||
|
||
/// \brief Topic | ||
public: std::string topic = "keyboard/keypress"; | ||
|
||
/// \brief Publish keyboard strokes | ||
/// \param[in] key_press Pointer to the keyevent | ||
public: void KeyPub(QKeyEvent *_keyPress) | ||
{ | ||
ignition::msgs::Int32 Msg; | ||
Msg.set_data(_keyPress->key()); | ||
pub.Publish(Msg); | ||
} | ||
}; | ||
} | ||
} | ||
|
||
using namespace ignition; | ||
using namespace gui; | ||
|
||
///////////////////////////////////////////////// | ||
KeyPublisher::KeyPublisher(): Plugin(), dataPtr(new KeyPublisherPrivate) | ||
{ | ||
// Advertise publisher node | ||
this->dataPtr->pub = this->dataPtr->node.Advertise<ignition::msgs::Int32> | ||
(this->dataPtr->topic); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
KeyPublisher::~KeyPublisher() | ||
{ | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
void KeyPublisher::LoadConfig(const tinyxml2::XMLElement *) | ||
{ | ||
if (this->title.empty()) | ||
this->title = "Key tool"; | ||
|
||
ignition::gui::App()->findChild | ||
<ignition::gui::MainWindow *>()->QuickWindow()->installEventFilter(this); | ||
} | ||
|
||
///////////////////////////////////////////////// | ||
bool KeyPublisher::eventFilter(QObject *_obj, QEvent *_event) | ||
{ | ||
if (_event->type() == QEvent::KeyPress) | ||
{ | ||
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(_event); | ||
this->dataPtr->KeyPub(keyEvent); | ||
} | ||
return QObject::eventFilter(_obj, _event); | ||
} | ||
|
||
// Register this plugin | ||
IGNITION_ADD_PLUGIN(ignition::gui::KeyPublisher, | ||
ignition::gui::Plugin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (C) 2020 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#ifndef IGNITION_GUI_PLUGINS_KEYPUBLISHER_HH_ | ||
#define IGNITION_GUI_PLUGINS_KEYPUBLISHER_HH_ | ||
|
||
#include <ignition/gui/qt.h> | ||
#include <ignition/gui/Plugin.hh> | ||
#include <ignition/transport/Node.hh> | ||
|
||
namespace ignition | ||
{ | ||
namespace gui | ||
{ | ||
class KeyPublisherPrivate; | ||
|
||
/// \brief Publish keyboard stokes to "keyboard/keypress" topic. | ||
/// | ||
/// ## Configuration | ||
/// This plugin doesn't accept any custom configuration. | ||
class KeyPublisher : public ignition::gui::Plugin | ||
{ | ||
Q_OBJECT | ||
|
||
/// \brief Constructor | ||
public: KeyPublisher(); | ||
|
||
/// \brief Destructor | ||
public: virtual ~KeyPublisher(); | ||
|
||
// Documentation inherited | ||
public: virtual void LoadConfig(const tinyxml2::XMLElement *) override; | ||
|
||
/// \brief Filter events in Qt | ||
/// \param[in] _obj The watched object | ||
/// \param[in] _event Event that happen in Qt | ||
protected: bool eventFilter(QObject *_obj, QEvent *_event) override; | ||
|
||
/// \internal | ||
/// \brief Pointer to private data. | ||
private: std::unique_ptr<KeyPublisherPrivate> dataPtr; | ||
}; | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (C) 2020 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import QtQuick 2.0 | ||
import QtQuick.Controls 2.0 | ||
|
||
Rectangle { | ||
visible: false | ||
width: 100 | ||
height: 100 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<!DOCTYPE RCC><RCC version="1.0"> | ||
<qresource prefix="KeyPublisher/"> | ||
<file>KeyPublisher.qml</file> | ||
</qresource> | ||
</RCC> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters