Skip to content

Commit

Permalink
code style
Browse files Browse the repository at this point in the history
Signed-off-by: mohamedsayed18 <[email protected]>
  • Loading branch information
mohamedsayed18 committed Jun 17, 2020
1 parent 7342c8c commit 2edd280
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 26 deletions.
23 changes: 17 additions & 6 deletions include/ignition/gui/plugins/KeyPublisher.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Open Source Robotics Foundation
* 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.
Expand All @@ -15,28 +15,39 @@
*
*/

#ifndef IGNITION_GUI_KEYPUBLISHER_HH_
#define IGNITION_GUI_KEYPUBLISHER_HH_
#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 //inherited from Qobject
{
Q_OBJECT

public: KeyPublisher(); //constructor
public: virtual ~KeyPublisher(); //destructor
/// \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
Expand Down
17 changes: 17 additions & 0 deletions include/ignition/gui/plugins/KeyPublisher.qml
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* 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

Expand Down
35 changes: 15 additions & 20 deletions src/plugins/KeyPublisher.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Open Source Robotics Foundation
* 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.
Expand Down Expand Up @@ -29,9 +29,17 @@ 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 *key_press)
{
ignition::msgs::Int32 Msg;
Expand All @@ -45,33 +53,31 @@ namespace gui
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 *)
{
//it loads the XML file which contains the UI file of Qt
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)
{
//dataPtr(new KeyPublisherPrivate)
if (_event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(_event);
Expand All @@ -80,17 +86,6 @@ bool KeyPublisher::eventFilter(QObject *_obj, QEvent *_event)
return QObject::eventFilter(_obj, _event);
}

/*
void KeyPublisher::KeyPub(QKeyEvent *key_press)
{
https://doc.qt.io/archives/qtjambi-4.5.2_01/com/trolltech/qt/core/Qt.Key.html
ignition::msgs::Int32 Msg;
Msg.set_data(key_press->key());
this->dataPtr->pub.Publish(Msg);
}
*/
// Register this plugin
IGNITION_ADD_PLUGIN(ignition::gui::KeyPublisher,
ignition::gui::Plugin)

0 comments on commit 2edd280

Please sign in to comment.