#ifndef Air_Ground_CEC_QNODE_HPP_
#define Air_Ground_CEC_QNODE_HPP_

#ifndef Q_MOC_RUN
#include <ros/ros.h>
#endif
#include <iostream>

#include <QImage>
#include <QThread>
#include <QStringListModel>
#include <QSettings>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <std_msgs/String.h>
#include <ros/network.h>
#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>
#include <geometry_msgs/Twist.h>
#include <sensor_msgs/BatteryState.h>
#include <nav_msgs/Odometry.h>
#include <std_msgs/Float64.h>
#include <std_msgs/Float32.h>

using namespace std;

class QNode : public QThread{
    Q_OBJECT

public:
    QNode(int argc, char **argv);
    virtual ~QNode();
    bool init();
    void SubAndPubTopic();
    void KeyboardMove(char key, float speed_linear, float speed_trun);
    void AutoMove(float speed_linear, float speed_turn,
                  float target_linear, float target_turn);
    //void subImage();
    QImage image;

    bool issaveImage = false;
    void setissaveImageTrue();
    void setissaveImageFalse();


Q_SIGNALS:
    void speed_x(double x);
    void speed_th(double th);
    //void power(float p);
    void batteryState(sensor_msgs::BatteryState);
    void show_image(QImage image);//发出设置相机图片信号



private:
    int init_argc;
    char **init_argv;
    ros::Publisher chatter_publisher;
    ros::Subscriber chatter_subscriber;
    ros::Publisher cmd_pub;
    ros::Publisher cmd_pub1;
    ros::Subscriber cmdVel_sub;
    ros::Subscriber battery_sub;
    ros::Subscriber image_sub0;
    QStringListModel logging_model;

    cv::Mat img;
    QString odom_topic;
    QString batteryState_topic;

    // image subscribe
    image_transport::Subscriber image_sub;


    void speedCallback(const nav_msgs::Odometry::ConstPtr& msg);
    void powerCallback(const std_msgs::Float32& message_holder);
    //void myCallback(const std_msgs::Float64& message_holder);
    void batteryCallback(const sensor_msgs::BatteryState &message);
    void imageCallback(const sensor_msgs::ImageConstPtr &msg);//camera callback function

    QImage  Mat2QImage(cv::Mat const &src);
    cv::Mat QImage2Mat(QImage &image);



};

#endif

