/***
   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 OUTPUTEDITORTEXT_UI_H
#define OUTPUTEDITORTEXT_UI_H

#include "common.h"
#include "outputtextedit.h"
#include "searchreplaceframe.h"
#include <QCheckBox>
#include <QComboBox>
#include <QDoubleSpinBox>
#include <QLineEdit>
#include <QMenu>
#include <QPushButton>
#include <QToolBar>
#include <QToolButton>
#include <QVBoxLayout>
#include <QWidgetAction>

class OutputEditorTextUi
{
public:
    QAction* actionOutputClear;
    QAction* actionOutputRedo;
    QAction* actionOutputReplace;
    QAction* actionOutputPostprocTitle1;
    QAction* actionOutputPostprocKeepEndMark;
    QAction* actionOutputPostprocKeepQuote;
    QAction* actionOutputPostprocTitle2;
    QAction* actionOutputPostprocJoinHyphen;
    QAction* actionOutputPostprocCollapseSpaces;
    QAction* actionOutputPostprocKeepParagraphs;
    QAction* actionOutputPostprocTitle3;
    QAction* actionOutputPostprocDrawWhitespace;
    QAction* actionOutputUndo;
    QMenu* menuOutputPostproc;
    QToolBar* toolBarOutput;
    QToolButton* toolButtonOutputPostproc;

    OutputTextEdit* plainTextEditOutput;
    SearchReplaceFrame* searchFrame;

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

        // Output postprocessing
        actionOutputPostprocTitle1 = new QAction(QApplication::translate("OutputEditorText", "Keep line break if..."), widget);
        actionOutputPostprocTitle1->setEnabled(false);
        actionOutputPostprocKeepEndMark = new QAction(QApplication::translate("OutputEditorText", "Preceded by end mark (.?!)"), widget);
        actionOutputPostprocKeepEndMark->setCheckable(true);
        actionOutputPostprocKeepQuote = new QAction(QApplication::translate("OutputEditorText", "Preceded or succeeded by quote"), widget);
        actionOutputPostprocKeepQuote->setCheckable(true);
        actionOutputPostprocTitle2 = new QAction(QApplication::translate("OutputEditorText", "Other options"), widget);
        actionOutputPostprocTitle2->setEnabled(false);
        actionOutputPostprocJoinHyphen = new QAction(QApplication::translate("OutputEditorText", "Join hyphenated words"), widget);
        actionOutputPostprocJoinHyphen->setCheckable(true);
        actionOutputPostprocCollapseSpaces = new QAction(QApplication::translate("OutputEditorText", "Collapse whitespace"), widget);
        actionOutputPostprocCollapseSpaces->setCheckable(true);
        actionOutputPostprocKeepParagraphs = new QAction(QApplication::translate("OutputEditorText", "Preserve paragraphs"), widget);
        actionOutputPostprocKeepParagraphs->setCheckable(true);
        actionOutputPostprocTitle3 = new QAction(QApplication::translate("OutputEditorText", "Visual aids"), widget);
        actionOutputPostprocTitle3->setEnabled(false);
        actionOutputPostprocDrawWhitespace = new QAction(QApplication::translate("OutputEditorText", "Draw whitespace"), widget);
        actionOutputPostprocDrawWhitespace->setCheckable(true);

        menuOutputPostproc = new QMenu(widget);
        menuOutputPostproc->addAction(actionOutputPostprocTitle1);
        menuOutputPostproc->addAction(actionOutputPostprocKeepEndMark);
        menuOutputPostproc->addAction(actionOutputPostprocKeepQuote);
        menuOutputPostproc->addAction(actionOutputPostprocTitle2);
        menuOutputPostproc->addAction(actionOutputPostprocJoinHyphen);
        menuOutputPostproc->addAction(actionOutputPostprocCollapseSpaces);
        menuOutputPostproc->addAction(actionOutputPostprocKeepParagraphs);
        menuOutputPostproc->addAction(actionOutputPostprocTitle3);
        menuOutputPostproc->addAction(actionOutputPostprocDrawWhitespace);

        // Output toolbar
        toolButtonOutputPostproc = new QToolButton(widget);
        toolButtonOutputPostproc->setIcon(QIcon(":/icons/stripcrlf"));
        toolButtonOutputPostproc->setText(QApplication::translate("OutputEditorText", "Strip Line Breaks"));
        toolButtonOutputPostproc->setToolTip(QApplication::translate("OutputEditorText", "Strip line breaks on selected text"));
        toolButtonOutputPostproc->setPopupMode(QToolButton::MenuButtonPopup);
        toolButtonOutputPostproc->setMenu(menuOutputPostproc);

        actionOutputReplace = new QAction(QIcon::fromTheme("edit-find-replace"), QApplication::translate("OutputEditorText", "Find and Replace"), widget);
        actionOutputReplace->setToolTip(QApplication::translate("OutputEditorText", "Find and replace"));
        actionOutputReplace->setCheckable(true);
        actionOutputUndo = new QAction(QIcon::fromTheme("edit-undo"), QApplication::translate("OutputEditorText", "Undo"), widget);
        actionOutputUndo->setToolTip(QApplication::translate("OutputEditorText", "Undo"));
        actionOutputUndo->setEnabled(false);
        actionOutputRedo = new QAction(QIcon::fromTheme("edit-redo"), QApplication::translate("OutputEditorText", "Redo"), widget);
        actionOutputRedo->setToolTip(QApplication::translate("OutputEditorText", "Redo"));
        actionOutputRedo->setEnabled(false);
        actionOutputClear = new QAction(QIcon::fromTheme("edit-clear"), QApplication::translate("OutputEditorText", "Clear Output"), widget);
        actionOutputClear->setToolTip(QApplication::translate("OutputEditorText", "Clear output"));

        toolBarOutput = new QToolBar(widget);
        toolBarOutput->setToolButtonStyle(Qt::ToolButtonIconOnly);
        toolBarOutput->setIconSize(QSize(1, 1) * toolBarOutput->style()->pixelMetric(QStyle::PM_SmallIconSize));
        toolBarOutput->addWidget(toolButtonOutputPostproc);
        toolBarOutput->addAction(actionOutputReplace);
        toolBarOutput->addAction(actionOutputUndo);
        toolBarOutput->addAction(actionOutputRedo);
        toolBarOutput->addAction(actionOutputClear);

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

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

        plainTextEditOutput = new OutputTextEdit(widget);
        widget->layout()->addWidget(plainTextEditOutput);
    }
};

#endif // OUTPUTEDITORTEXT_UI_H
