/***
   This file is part of fly-ocr.

   Copyright (C) 2016-2020 Sandro Mani <manisandro@gmail.com>
   Copyright (C) 2021 LLC "RusBITech-Astra" (https://astralinux.ru)

    Based on gImageReader source code by Sandro Mani under the GNU
    General Public License (GPL) version 3 or later

   Foobar 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.

   Foobar 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 fly-ocr. If not, see <https://www.gnu.org/licenses/>.
***/

#ifndef OUTPUTEDITORHOCR_UI_H
#define OUTPUTEDITORHOCR_UI_H

#include "common.h"
#include "outputtextedit.h"
#include "searchreplaceframe.h"
#include <QCheckBox>
#include <QComboBox>
#include <QDoubleSpinBox>
#include <QHeaderView>
#include <QMenu>
#include <QPushButton>
#include <QToolBar>
#include <QToolButton>
#include <QSplitter>
#include <QTableWidget>
#include <QTreeWidget>
#include <QVBoxLayout>
#include <QWidgetAction>

class OutputEditorHOCRUi
{
public:
    QAction* actionOutputClear;
    QAction* actionOutputReplace;
    QAction* actionToggleWConf;
    QAction* actionPreview;
    QAction* actionNavigateNext;
    QAction* actionNavigatePrev;
    QAction* actionExpandAll;
    QAction* actionCollapseAll;
    QComboBox* comboBoxNavigate;

    QToolBar* toolBarOutput;
    QToolBar* toolBarNavigate;
    QTabWidget* tabWidgetProps;

    QSplitter* splitter;
    QTreeView* treeViewHOCR;
    QTableWidget* tableWidgetProperties;
    OutputTextEdit* plainTextEditOutput;
    SearchReplaceFrame* searchFrame;

    void setupUi(QWidget* widget)
    {
        widget->setLayout(new QVBoxLayout());
        widget->layout()->setContentsMargins(0, 0, 0, 0);
        widget->layout()->setSpacing(0);

        // Output toolbar
        actionOutputClear = new QAction(QIcon::fromTheme("edit-clear"), QApplication::translate("OutputEditorHOCR", "Clear output"), widget);
        actionOutputClear->setToolTip(QApplication::translate("OutputEditorHOCR", "Clear output"));
        actionOutputReplace = new QAction(QIcon::fromTheme("edit-find-replace"), QApplication::translate("OutputEditorHOCR", "Find and Replace"), widget);
        actionOutputReplace->setToolTip(QApplication::translate("OutputEditorHOCR", "Find and replace"));
        actionOutputReplace->setCheckable(true);
        actionToggleWConf = new QAction(QIcon(":/icons/wconf"), QApplication::translate("OutputEditorHOCR", "Show confidence values"), widget);
        actionToggleWConf->setToolTip(QApplication::translate("OutputEditorHOCR", "Show confidence values"));
        actionToggleWConf->setCheckable(true);
        actionPreview = new QAction(QIcon::fromTheme("document-preview"), QApplication::translate("OutputEditorHOCR", "Show preview"), widget);
        actionPreview->setToolTip(QApplication::translate("OutputEditorHOCR", "Show preview"));
        actionPreview->setCheckable(true);

        toolBarOutput = new QToolBar(widget);
        toolBarOutput->setToolButtonStyle(Qt::ToolButtonIconOnly);
        toolBarOutput->setIconSize(QSize(1, 1) * toolBarOutput->style()->pixelMetric(QStyle::PM_SmallIconSize));
        toolBarOutput->addAction(actionOutputClear);
        toolBarOutput->addSeparator();
        toolBarOutput->addAction(actionOutputReplace);
        toolBarOutput->addAction(actionToggleWConf);
        toolBarOutput->addAction(actionPreview);

        widget->layout()->addWidget(toolBarOutput);

        searchFrame = new SearchReplaceFrame(widget);
        searchFrame->setVisible(false);
        widget->layout()->addWidget(searchFrame);

        splitter = new QSplitter(Qt::Vertical, widget);
        widget->layout()->addWidget(splitter);

        QWidget* treeContainer = new QWidget(widget);
        treeContainer->setLayout(new QVBoxLayout());
        treeContainer->layout()->setSpacing(0);
        treeContainer->layout()->setContentsMargins(0, 0, 0, 0);
        splitter->addWidget(treeContainer);

        treeViewHOCR = new QTreeView(widget);
        treeViewHOCR->setHeaderHidden(true);
        treeViewHOCR->setSelectionMode(QTreeWidget::ExtendedSelection);
        treeContainer->layout()->addWidget(treeViewHOCR);

        actionNavigateNext = new QAction(QIcon::fromTheme("go-down"), QApplication::translate("OutputEditorHOCR", "Next (F3)"), widget);
        actionNavigatePrev = new QAction(QIcon::fromTheme("go-up"), QApplication::translate("OutputEditorHOCR", "Previous (Shift+F3)"), widget);
        comboBoxNavigate = new QComboBox();
        comboBoxNavigate->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
        comboBoxNavigate->setMinimumContentsLength(10);
        actionExpandAll = new QAction(QIcon(":/icons/expand"), QApplication::translate("OutputEditorHOCR", "Expand all"), widget);
        actionCollapseAll = new QAction(QIcon(":/icons/collapse"), QApplication::translate("OutputEditorHOCR", "Collapse all"), widget);

        toolBarNavigate = new QToolBar(widget);
        toolBarNavigate->setToolButtonStyle(Qt::ToolButtonIconOnly);
        toolBarNavigate->setIconSize(QSize(1, 1) * toolBarOutput->style()->pixelMetric(QStyle::PM_SmallIconSize));
        toolBarNavigate->addWidget(comboBoxNavigate);
        toolBarNavigate->addSeparator();
        toolBarNavigate->addAction(actionNavigateNext);
        toolBarNavigate->addAction(actionNavigatePrev);
        toolBarNavigate->addSeparator();
        toolBarNavigate->addAction(actionExpandAll);
        toolBarNavigate->addAction(actionCollapseAll);
        treeContainer->layout()->addWidget(toolBarNavigate);

        tabWidgetProps = new QTabWidget(widget);

        tableWidgetProperties = new QTableWidget(widget);
        tableWidgetProperties->setColumnCount(2);
        tableWidgetProperties->horizontalHeader()->setVisible(false);
        tableWidgetProperties->verticalHeader()->setVisible(false);
        tableWidgetProperties->horizontalHeader()->setStretchLastSection(true);
        tabWidgetProps->addTab(tableWidgetProperties, QApplication::translate("OutputEditorHOCR", "Properties"));

        plainTextEditOutput = new OutputTextEdit(widget);
        plainTextEditOutput->setReadOnly(true);
        tabWidgetProps->addTab(plainTextEditOutput, QApplication::translate("OutputEditorHOCR", "Source"));

        splitter->addWidget(tabWidgetProps);
    }
};

#endif // OUTPUTEDITORHOCR_UI_H
