/***
 * Warthog Robotics
 * University of Sao Paulo (USP) at Sao Carlos
 * http://www.warthog.sc.usp.br/
 *
 * This file is part of WRJoy project.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ***/

// Prevents multiple definitions
#ifndef WRJOY_MONITOR
#define WRJOY_MONITOR


// Includes WRJoy
#include <WRJoy/wrjoy.hh>


// Includes Qt library
#include <QtCore/QtCore>
#include <QtWidgets/QtWidgets>

// Includes SDL library
#include <SDL2/SDL.h>


// Selects WRJoy namespace
using namespace WRJoy;


class WRJoy::JoystickGUI::Monitor : public QMainWindow {
    private:
        Joystick* _joystick;

        QWidget*   _centralWidget;

        QGroupBox* _basicInfoBox;
        QLabel*    _basicInfoJoystickStatus;
        QLabel*    _basicInfoJoystickName;
        QLabel*    _basicInfoJoystickSDLIndex;
        QLabel*    _basicInfoJoystickNumAxes;
        QLabel*    _basicInfoJoystickNumButtons;

        QGroupBox*     _axesInfoBox;
        QList<QLabel*> _axesInfoAxes;

        QGroupBox*     _buttonsInfoBox;
        QList<QLabel*> _buttonsInfoButtons;

        QToolBar* _toolBar;
        QAction*  _startMonitorAction;
        QAction*  _pauseMonitorAction;
        QAction*  _stopMonitorAction;


    public:
        Monitor(Joystick* joystick);


    private:
        void configureMainWindow();
        void configureToolBar();
        void configureCentralWidget();
        void configureConnections();

        void configureActions(QToolBar* toolBar);


    private slots:
        void startMonitor();
        void pauseMonitor(bool checked);
        void stopMonitor();

        void joystickOpened();
        void joystickClosed();
        void joystickStarted();
        void joystickStoped();

        void updateStateForms();


    private:
        void createBoxes();
        void createBasicInformationBox();
        void createAxesInformationBox();
        void createButtonsInformationBox();

        void updateBoxes();

        void clearAllBoxes();
        void clearStateBoxes();
        void clearBasicInformationBox();
        void clearAxesInformationBox();
        void clearButtonsInformationBox();

        void createForms();
        void createBasicInformationForm();
        void createAxesInformationForm();
        void createButtonsInformationForm();

        void updateAllForms();
        void updateBasicInformationForm();
        void updateAxesInformationForm();
        void updateButtonsInformationForm();

        void clearAllForms();
        void clearStateForms();
        void clearBasicInformationForm();
        void clearAxesInformationForm();
        void clearButtonsInformationForm();
};


#endif
