/**
 * UGENE - Integrated Bioinformatics Tools.
 * Copyright (C) 2008-2023 UniPro <ugene@unipro.ru>
 * http://ugene.net
 *
 * 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 2
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 */

#pragma once

#include <QWidget>

#include <U2Core/Msa.h>

namespace U2 {

class MaEditor;
class MaEditorWgt;
class MSAEditorOffsetsViewWidget;
class MaEditorSequenceArea;
class MaModificationInfo;
class MsaObject;

class U2VIEW_EXPORT MSAEditorOffsetsViewController : public QObject {
    Q_OBJECT
public:
    MSAEditorOffsetsViewController(MaEditorWgt* maEditorUi, MaEditor* editor, MaEditorSequenceArea* seqArea);

    bool eventFilter(QObject* o, QEvent* e) override;

private slots:
    void sl_updateOffsets();
    void sl_showOffsets(bool);

private:
    void updateOffsets(bool show);

    MaEditorSequenceArea* seqArea;
    MaEditor* editor;
    MaEditorWgt* ui = nullptr;

public:
    MSAEditorOffsetsViewWidget* leftWidget;
    MSAEditorOffsetsViewWidget* rightWidget;
    QAction* toggleColumnsViewAction;
};

class MSAEditorOffsetsViewWidget : public QWidget {
    Q_OBJECT
    friend class MSAEditorOffsetsViewController;

public:
    MSAEditorOffsetsViewWidget(MaEditorWgt* maEditorUi, MaEditor* editor, MaEditorSequenceArea* seqArea, bool showStartPos);

    /** Returns number of characters needed to draw offsets. */
    int getWidthInBases() const;

private slots:
    void sl_completeRedraw();

protected:
    void paintEvent(QPaintEvent* e) override;
    void updateView();
    void drawAll(QPainter& p);
    QFont getOffsetsFont();
    void drawRefSequence(QPainter& p, const QRect& r);

private:
    int getBaseCounts(int seqNum, int aliPos, bool inclAliPos) const;

    MaEditorSequenceArea* seqArea;
    MaEditor* editor;
    MaEditorWgt* ui = nullptr;
    bool showStartPos;
    bool completeRedraw;
    QPixmap cachedView;
};

}  // namespace U2
