2014-08-23 08:57:22 +04:00
|
|
|
#pragma once
|
2014-06-07 19:19:38 +04:00
|
|
|
|
2014-09-05 02:31:09 +04:00
|
|
|
#include <QMap>
|
2014-06-07 19:19:38 +04:00
|
|
|
#include <QObject>
|
2014-09-05 02:31:09 +04:00
|
|
|
#include <QString>
|
2014-06-07 19:19:38 +04:00
|
|
|
#include <QWidget>
|
2014-06-07 19:22:14 +04:00
|
|
|
#include <QVBoxLayout>
|
2014-06-07 19:19:38 +04:00
|
|
|
#include <Qsci/qsciscintilla.h>
|
2014-06-07 04:52:38 +04:00
|
|
|
#include <QVBoxLayout>
|
2014-06-07 19:19:38 +04:00
|
|
|
#include "editor.h"
|
2014-06-19 21:23:00 +04:00
|
|
|
#include "scadlexer.h"
|
2014-09-04 22:05:26 +04:00
|
|
|
#include "parsersettings.h"
|
|
|
|
|
2014-09-05 02:31:09 +04:00
|
|
|
#include <boost/shared_ptr.hpp>
|
2014-09-04 22:05:26 +04:00
|
|
|
#include <boost/property_tree/ptree.hpp>
|
|
|
|
#include <boost/property_tree/json_parser.hpp>
|
2014-06-07 19:19:38 +04:00
|
|
|
|
2014-09-05 02:31:09 +04:00
|
|
|
class EditorColorScheme
|
2014-06-07 19:19:38 +04:00
|
|
|
{
|
2014-09-05 02:31:09 +04:00
|
|
|
private:
|
|
|
|
const fs::path path;
|
|
|
|
|
|
|
|
boost::property_tree::ptree pt;
|
|
|
|
QString _name;
|
|
|
|
int _index;
|
|
|
|
|
|
|
|
public:
|
|
|
|
EditorColorScheme(const fs::path path);
|
|
|
|
virtual ~EditorColorScheme();
|
|
|
|
|
|
|
|
const QString & name() const;
|
|
|
|
int index() const;
|
|
|
|
bool valid() const;
|
|
|
|
const boost::property_tree::ptree & propertyTree() const;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class ScintillaEditor : public EditorInterface
|
|
|
|
{
|
2014-08-23 02:54:09 +04:00
|
|
|
Q_OBJECT;
|
2014-09-05 02:31:09 +04:00
|
|
|
|
|
|
|
typedef std::multimap<int, boost::shared_ptr<EditorColorScheme>, std::less<int> > colorscheme_set_t;
|
|
|
|
|
2014-06-07 19:19:38 +04:00
|
|
|
public:
|
2014-08-22 21:42:23 +04:00
|
|
|
ScintillaEditor(QWidget *parent);
|
2014-08-22 22:17:24 +04:00
|
|
|
virtual ~ScintillaEditor() {}
|
2014-08-22 21:42:23 +04:00
|
|
|
QsciScintilla *qsci;
|
|
|
|
QString toPlainText();
|
2014-06-11 14:29:05 +04:00
|
|
|
void initMargin();
|
|
|
|
void initLexer();
|
2014-06-20 10:37:40 +04:00
|
|
|
void noColor();
|
2014-08-23 09:25:29 +04:00
|
|
|
QString selectedText();
|
2014-08-14 02:52:01 +04:00
|
|
|
bool find(const QString &, bool findNext = false, bool findBackwards = false);
|
2014-08-23 02:10:58 +04:00
|
|
|
void replaceSelectedText(const QString&);
|
2015-03-23 19:51:25 +03:00
|
|
|
void replaceAll(const QString &findText, const QString &replaceText);
|
2014-11-01 01:30:52 +03:00
|
|
|
QStringList colorSchemes();
|
2014-08-25 01:46:26 +04:00
|
|
|
|
|
|
|
private:
|
2014-09-05 02:31:09 +04:00
|
|
|
void getRange(int *lineFrom, int *lineTo);
|
|
|
|
void setColormap(const EditorColorScheme *colorScheme);
|
|
|
|
int readInt(const boost::property_tree::ptree &pt, const std::string name, const int defaultValue);
|
2014-12-20 19:27:18 +03:00
|
|
|
std::string readString(const boost::property_tree::ptree &pt, const std::string name, const std::string defaultValue);
|
2014-09-05 02:31:09 +04:00
|
|
|
QColor readColor(const boost::property_tree::ptree &pt, const std::string name, const QColor defaultColor);
|
2014-11-02 01:06:36 +03:00
|
|
|
void enumerateColorSchemesInPath(colorscheme_set_t &result_set, const fs::path path);
|
2014-09-05 02:31:09 +04:00
|
|
|
colorscheme_set_t enumerateColorSchemes();
|
2014-08-07 06:04:37 +04:00
|
|
|
|
2014-06-07 19:22:14 +04:00
|
|
|
public slots:
|
2014-08-13 19:59:56 +04:00
|
|
|
void zoomIn();
|
2014-08-22 21:42:23 +04:00
|
|
|
void zoomOut();
|
|
|
|
void setPlainText(const QString&);
|
2014-08-23 02:39:12 +04:00
|
|
|
void setContentModified(bool);
|
2014-08-13 19:59:56 +04:00
|
|
|
bool isContentModified();
|
2014-08-22 21:42:23 +04:00
|
|
|
void highlightError(int);
|
|
|
|
void unhighlightLastError();
|
|
|
|
void setHighlightScheme(const QString&);
|
2014-08-23 02:39:12 +04:00
|
|
|
void indentSelection();
|
|
|
|
void unindentSelection();
|
|
|
|
void commentSelection();
|
|
|
|
void uncommentSelection();
|
2014-08-22 22:17:24 +04:00
|
|
|
void insert(const QString&);
|
2015-03-23 19:51:25 +03:00
|
|
|
void setText(const QString&);
|
2014-08-13 19:59:56 +04:00
|
|
|
void undo();
|
2014-08-22 21:42:23 +04:00
|
|
|
void redo();
|
|
|
|
void cut();
|
|
|
|
void copy();
|
|
|
|
void paste();
|
2014-08-15 12:43:58 +04:00
|
|
|
void initFont(const QString&, uint);
|
|
|
|
|
2014-08-23 02:54:09 +04:00
|
|
|
private slots:
|
|
|
|
void onTextChanged();
|
2014-12-27 04:17:15 +03:00
|
|
|
void applySettings();
|
2014-08-23 02:54:09 +04:00
|
|
|
|
2014-06-07 19:22:14 +04:00
|
|
|
private:
|
2014-08-22 21:42:23 +04:00
|
|
|
QVBoxLayout *scintillaLayout;
|
2015-02-25 22:14:29 +03:00
|
|
|
static const int indicatorNumber = 8; // first 8 are used by lexers
|
2014-08-22 23:10:08 +04:00
|
|
|
static const int markerNumber = 2;
|
2014-06-19 21:23:00 +04:00
|
|
|
ScadLexer *lexer;
|
2015-03-02 21:11:34 +03:00
|
|
|
QFont currentFont;
|
2014-06-07 19:19:38 +04:00
|
|
|
};
|