/*******************************************************************************
 Copyright 2016-17 Daniel Neuwirth
 This program is distributed under the terms of the GNU General Public License.
*******************************************************************************/

#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H

// user interface for MainWindow class


#include "compute.h"

#include <QAction>
#include <QFont>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QIcon>
#include <QLabel>
#include <QLineEdit>
#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
#include <QPushButton>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QWidget>

class BigButton: public QPushButton {

    public:
        BigButton(const QString & text, QWidget * parent = Q_NULLPTR):
            QPushButton(text, parent) {

            setIconSize(QSize(32,32));
            setFont(QFont("Times", 16));
            setStyleSheet("padding: 3px 10px;");
        }
};

class Ui_MainWindow {

    public:
        QIcon * mainIcon;

        QAction * action_Exit;
        QAction * action_License;
        QAction * action_About;

        QMenuBar * menubar;
        QMenu * menuFile;
        QMenu * menuHelp;

        QWidget * centralWidget;

        QVBoxLayout * verticalLayout_win;
        QVBoxLayout * verticalLayout_ib;
        QHBoxLayout * horizontalLayout_1;
        QHBoxLayout * horizontalLayout_2;
        QHBoxLayout * horizontalLayout_3;
        QHBoxLayout * horizontalLayout_4;
        QHBoxLayout * horizontalLayout_5;

        QGroupBox * insertBox;

        QLineEdit * lineEdit_EquationLeftSide;
        QPushButton * pushButton_InsertDiff;
        QIcon * iconDiff;
        QLabel * label_EqualSign;
        QLineEdit * lineEdit_EquationRightSide;
        QLineEdit * lineEdit_DiffSign;

        QLineEdit * lineEdit_EquationType;

        QPushButton * pushButton_AddConditions;
        QIcon * iconAddCondition;
        QPushButton * pushButton_RemoveConditions;
        QIcon * iconRemoveCondition;
        QLineEdit * lineEdit_InitialConditionsState;
        QPushButton * pushButton_ApplyConditions;

        BigButton * pushButton_SubmitEquation;
        QIcon * iconSubmit;
        BigButton * pushButton_ClearEquation;
        QIcon * iconClear;

        QGroupBox * resultBox;

        QTextEdit * textEdit_Result;

        QPushButton * pushButton_ShowSteps;
        QIcon * iconSteps;

    private:
        void initialConditionsUIArrangement() {

            pushButton_AddConditions = new QPushButton();
            iconAddCondition = new QIcon();
            iconAddCondition->addFile(QStringLiteral(":/icons/icons/add.ico"),
                                      QSize(), QIcon::Normal, QIcon::Off);
            pushButton_AddConditions->setIcon(*iconAddCondition);
            pushButton_AddConditions->setEnabled(false);
            pushButton_AddConditions->setToolTip(
                QStringLiteral("set initial conditions"));
            pushButton_RemoveConditions = new QPushButton();
            iconRemoveCondition = new QIcon();
            iconRemoveCondition->addFile(QStringLiteral(":/icons/icons/remove.ico"),
                                         QSize(), QIcon::Normal, QIcon::Off);
            pushButton_RemoveConditions->setIcon(*iconRemoveCondition);
            pushButton_RemoveConditions->setEnabled(false);
            pushButton_RemoveConditions->setToolTip(
                QStringLiteral("reset initial conditions"));
            lineEdit_InitialConditionsState = new QLineEdit(
                QStringLiteral("initial conditions are not set"));
            lineEdit_InitialConditionsState->setEnabled(false);
            format::setElementWidth(lineEdit_InitialConditionsState);
            lineEdit_InitialConditionsState->setAlignment(Qt::AlignCenter);
            pushButton_ApplyConditions = new QPushButton(QStringLiteral("&Apply"));
            pushButton_ApplyConditions->setCheckable(true);
            pushButton_ApplyConditions->setEnabled(false);

            return;
        }

    public:
        void setupUi(QMainWindow * MainWindow) {

            // set window icon
            mainIcon = new QIcon(QStringLiteral(":/icons/icons/app.ico"));
            MainWindow->setWindowIcon(*mainIcon);

            // properties of main window
            MainWindow->setMinimumSize(800, 300);
            MainWindow->resize(800, 300);
            MainWindow->setWindowTitle(
                QStringLiteral("Differential Equation Solver"));

            // actions
            action_Exit = new QAction(QStringLiteral("&Exit"), MainWindow);
            action_License = new QAction(QStringLiteral("&License"), MainWindow);
            action_About = new QAction(QStringLiteral("&About"), MainWindow);

            // menubar
            menubar = new QMenuBar(MainWindow);
            MainWindow->setMenuBar(menubar);

            // menus
            menuFile = new QMenu();
            menuFile = menubar->addMenu("&File");
            menuFile->addAction(action_Exit);
            menuHelp = new QMenu();
            menuHelp = menubar->addMenu("&Help");
            menuHelp->addAction(action_License);
            menuHelp->addAction(action_About);

            // central widget
            centralWidget = new QWidget(MainWindow);
            centralWidget->setSizePolicy(QSizePolicy::Maximum,
                                         QSizePolicy::Maximum);
            MainWindow->setCentralWidget(centralWidget);

            // insert box
            insertBox = new QGroupBox(QStringLiteral("&Insert equation"));

            // first row - contents
            lineEdit_EquationLeftSide = new QLineEdit();
            pushButton_InsertDiff = new QPushButton();
            iconDiff = new QIcon();
            iconDiff->addFile(QStringLiteral(":/icons/icons/diff.ico"),
                              QSize(), QIcon::Normal, QIcon::Off);
            pushButton_InsertDiff->setIcon(*iconDiff);
            pushButton_InsertDiff->setMaximumWidth(40);
            pushButton_InsertDiff->setToolTip(
                QStringLiteral("insert (symbol of) derivative"));
            label_EqualSign = new QLabel(QStringLiteral("="));
            label_EqualSign->setMaximumWidth(30);
            lineEdit_EquationRightSide = new QLineEdit();
            lineEdit_DiffSign = new QLineEdit();
            lineEdit_DiffSign->setMaximumWidth(50);
            lineEdit_DiffSign->setToolTip(
                QStringLiteral("differentiate with respect to"));
            lineEdit_DiffSign->setStyleSheet(
                QStringLiteral("background-color: rgb(255, 255, 0);"));
            lineEdit_DiffSign->setAlignment(Qt::AlignCenter);
            lineEdit_DiffSign->setReadOnly(true);

            // first row - horizontal layout
            horizontalLayout_1 = new QHBoxLayout();
            horizontalLayout_1->addWidget(lineEdit_EquationLeftSide);
            horizontalLayout_1->addWidget(pushButton_InsertDiff);
            horizontalLayout_1->addWidget(label_EqualSign);
            horizontalLayout_1->addWidget(lineEdit_EquationRightSide);
            horizontalLayout_1->addWidget(lineEdit_DiffSign);
            horizontalLayout_1->setStretch(0, 4);
            horizontalLayout_1->setStretch(3, 2);

            // second row - contents
            lineEdit_EquationType = new QLineEdit();
            lineEdit_EquationType->setEnabled(false);
            lineEdit_EquationType->setReadOnly(true);

            // second row - horizontal layout
            horizontalLayout_2 = new QHBoxLayout();
            horizontalLayout_2->addWidget(lineEdit_EquationType);

            // insert box - horizontal layout
            verticalLayout_ib = new QVBoxLayout();
            verticalLayout_ib->addLayout(horizontalLayout_1);
            verticalLayout_ib->addLayout(horizontalLayout_2);
            insertBox->setLayout(verticalLayout_ib);

            // third row - contents
            initialConditionsUIArrangement();
            pushButton_SubmitEquation = new BigButton(QStringLiteral("&Submit"));
            iconSubmit = new QIcon();
            iconSubmit->addFile(QStringLiteral(":/icons/icons/submit.ico"),
                                QSize(), QIcon::Normal, QIcon::Off);
            pushButton_SubmitEquation->setIcon(*iconSubmit);
            pushButton_SubmitEquation->setEnabled(false);
            pushButton_ClearEquation = new BigButton(QStringLiteral("&Clear"));
            iconClear = new QIcon();
            iconClear->addFile(QStringLiteral(":/icons/icons/clear.ico"),
                               QSize(), QIcon::Normal, QIcon::Off);
            pushButton_ClearEquation->setIcon(*iconClear);

            // third row - layout
            horizontalLayout_3 = new QHBoxLayout();
            horizontalLayout_3->addWidget(pushButton_AddConditions);
            horizontalLayout_3->addWidget(pushButton_RemoveConditions);
            horizontalLayout_3->addWidget(lineEdit_InitialConditionsState);
            horizontalLayout_3->addWidget(pushButton_ApplyConditions);
            horizontalLayout_3->addWidget(pushButton_SubmitEquation);
            horizontalLayout_3->addWidget(pushButton_ClearEquation);
            horizontalLayout_3->insertStretch(4,0);

            // fourth row - contents
            resultBox = new QGroupBox(QStringLiteral("&Result"));
            resultBox->setMaximumHeight(100);
            textEdit_Result = new QTextEdit();
            textEdit_Result->setReadOnly(true);

            // fourth row - horizontal layout
            horizontalLayout_4 = new QHBoxLayout();
            horizontalLayout_4->addWidget(textEdit_Result);
            resultBox->setLayout(horizontalLayout_4);

            // fifth row - contents
            pushButton_ShowSteps = new QPushButton(
                QStringLiteral("Step-by-step solution"));
            iconSteps = new QIcon();
            iconSteps->addFile(QStringLiteral(":/icons/icons/steps.ico"),
                               QSize(), QIcon::Normal, QIcon::Off);
            pushButton_ShowSteps->setIcon(*iconSteps);
            pushButton_ShowSteps->setEnabled(false);

            // fifth row - horizontal layout
            horizontalLayout_5 = new QHBoxLayout();
            horizontalLayout_5->insertStretch(0,0);
            horizontalLayout_5->addWidget(pushButton_ShowSteps);

            // vertical layout
            verticalLayout_win = new QVBoxLayout(centralWidget);
            verticalLayout_win->addWidget(insertBox);
            verticalLayout_win->addLayout(horizontalLayout_3);
            verticalLayout_win->addWidget(resultBox);
            verticalLayout_win->addLayout(horizontalLayout_5);

            QMetaObject::connectSlotsByName(MainWindow);
    }
};

#endif // UI_MAINWINDOW_H
