WSL/SLF GitLab Repository

PreviewEdit.h 2.46 KB
Newer Older
Mathias Bavay's avatar
Mathias Bavay committed
1
//SPDX-License-Identifier: GPL-3.0-or-later
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*****************************************************************************/
/*  Copyright 2020 WSL Institute for Snow and Avalanche Research  SLF-DAVOS  */
/*****************************************************************************/
/* This file is part of INIshell.
   INIshell 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.

   INIshell 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 INIshell.  If not, see <http://www.gnu.org/licenses/>.
18
19
*/

20
21
22
23
24
25
26
27
/*
 * The PreviewWindow uses this PreviewEdit for INI text editor features.
 * 2020-03
 */

#ifndef PREVIEWEDIT_H
#define PREVIEWEDIT_H

28
#include <src/main/SyntaxHighlighter.h>
29

30
31
32
33
#include <QAction>
#include <QString>
#include <QTextDocument>
#include <QPlainTextEdit>
34
#include <QWidget>
35

36
37
38
39
40
class PreviewEdit : public QPlainTextEdit
{
	Q_OBJECT

	public:
41
		PreviewEdit(const bool& monospace, QWidget *parent);
42
43
44

		void repaintSidePanel(QPaintEvent *event);
		int getSidePanelWidth();
45
46
47
48
		QString getFileName() const noexcept { return file_name_; }
		QString getFilePath() const noexcept { return file_path_; }
		QString getFullFilePath() const;
		void setFile(const QString &file_path); //call with full file path
49
50

	protected:
51
		void setMonospacedFont();
52
53
		void resizeEvent(QResizeEvent *event) override;
		void dragMoveEvent(QDragMoveEvent *event) override;
54
55
56
57
58
59

	private slots:
		void updateSidePanelWidth();
		void updateSidePanel(const QRect &, int);

	private:
60
		QWidget *sidePanel = nullptr;
61
62
		QString file_path_; //file path without name
		QString file_name_;
63
		INISyntaxHighlighter *highlighter_ = nullptr;
Mathias Bavay's avatar
Mathias Bavay committed
64
		const int margin_width = fontMetrics().boundingRect(QLatin1Char('M')).width();
65
66
67
68
69
};


class PreviewSidePanel : public QWidget
{
Michael Reisecker's avatar
Michael Reisecker committed
70
71
	Q_OBJECT

72
73
74
	public:
		PreviewSidePanel(PreviewEdit *editor) : QWidget(editor), textEdit(editor) {}

75
		QSize sizeHint() const { return QSize(textEdit->getSidePanelWidth(), 0); }
76
77

	protected:
78
		void paintEvent(QPaintEvent *event) { textEdit->repaintSidePanel(event); }
79
80
81
82

	private:
		PreviewEdit *textEdit;
};
83
84

#endif //PREVIEWEDIT_H