#ifndef tabDoc_H
#define tabDoc_H

#include <QTextEdit>
#include <QtWidgets>
#include "text_lighter.h"

class tabDoc : public QPlainTextEdit
{
Q_OBJECT

private:
QString directory;
QString name_;
QString ext_;
bool flag;
Lighter_class* selector;

public:
void linesHelp();

tabDoc(QWidget* p_parent = 0);

QString getFileExt() const
{return ext_;}

void setFileName(const QString& p_name)
{name_ = p_name;}

QString getFileDirectory() const
{return directory;}

QString getFileName() const
{return name_;}

bool wasChanged() const
{return flag;}

signals:
void changeWidTitle(const QString&, const QString&);
void fileChanded(const QString&);

public slots:
QString sltLoad();
QString sltLoad(const QString&);
void sltSaveAs(const QString&);
void sltLoadHighlight();
void sltDocChanged();
void sltSetChanged(bool);
void sltIsCodeDoc();
void sltSave();

void linePaintEvent(QPaintEvent *event);
int lineNumberAreaWidth();

protected:
void resizeEvent(QResizeEvent *event) override;

private slots:
void updateLineNumberAreaWidth(int newBlockCount);
void highlightCurrentLine();
void updateLineNumberArea(const QRect &rect, int dy);

private:
QWidget *lineNumberArea;
};

class LineNumberArea : public QWidget
{
public:
LineNumberArea(tabDoc *editor) : QWidget(editor), codeEditor(editor)
{}

QSize sizeHint() const override
{
  return QSize(codeEditor->lineNumberAreaWidth(), 0);
}

protected:
void paintEvent(QPaintEvent *event) override
{
  codeEditor->linePaintEvent(event);
}

private:
tabDoc *codeEditor;
};

#endif // tabDoc_H
