refactoring qad widgets part 2

c++ cast, nullptr, forward declaration, agregate ui, connect to member functions, order and clear includes
This commit is contained in:
2022-12-12 10:18:34 +03:00
parent 728c132f2b
commit 4497123421
23 changed files with 837 additions and 500 deletions

View File

@@ -20,19 +20,19 @@
#ifndef QCODEEDIT_H
#define QCODEEDIT_H
#include <QPlainTextEdit>
#include <QTreeWidget>
#include <QScrollBar>
#include <QUrl>
#include "iconedlabel.h"
#include "qad_widgets_export.h"
#include <QTextEdit>
#include <QUrl>
#include <QIcon>
namespace Ui {
class QCodeEdit;
}
class QPlainTextEdit;
class QCodeEditCompleter;
class IconedLabel;
class _QCE_Viewport;
@@ -50,7 +50,7 @@ class QAD_WIDGETS_EXPORT QCodeEdit: public QWidget
public:
QCodeEdit(QWidget * parent = nullptr);
~QCodeEdit();
~QCodeEdit() override;
enum ACClassType {
Keyword,
@@ -99,7 +99,6 @@ public:
QPlainTextEdit * textEdit() const;
void registerAutoCompletitionClass(int id, ACClassType ac_class, const QString & name, const QIcon & icon = QIcon());
bool wordCompletitionEnabled() const {return word_complete;}
protected:
@@ -118,71 +117,11 @@ protected:
void raiseHelp(QTextCursor tc, int arg = -1);
QTextCursor functionStart(QTextCursor tc, int * arg);
ACList wordsCompletitionList(const QString & written) const;
QPair<QStringList, QString> getScope(QTextCursor tc, bool * ok = 0);
QPair<QStringList, QString> getScope(QTextCursor tc, bool * ok = nullptr);
static int skipRange(const QString & s, int pos, QChar oc, QChar cc, QChar sc = QChar());
static int skipCWord(const QString & s, int pos);
static bool matchWritten(QString s, QString w);
static QChar pairChar(QChar c);
Ui::QCodeEdit * ui;
private:
struct QAD_WIDGETS_EXPORT ACClass {
ACClass(int i = -2, ACClassType c = QCodeEdit::Keyword, const QString & n = QString(), const QIcon & ic = QIcon()): id(i), class_(c), name(n), icon(ic) {}
int id;
ACClassType class_;
QString name;
QIcon icon;
};
enum LabelHelpType {
lhMain,
lhHint,
lhF1,
lh_last
};
QCodeEditCompleter * completer;
IconedLabel * lbl_help[3];
QFrame * widget_help;
_QCE_Viewport * overlay;
QTextEdit::ExtraSelection es_line, es_cursor, es_bracket, es_range, es_search, es_link;
QList<QTextEdit::ExtraSelection> es_selected, es_custom, es_brackets, es_search_list, es_blockselection;
QMap<int, ACClass> ac_classes;
QStringList cursor_scope;
QString comment_text;
ACEntry link_entry, help_entry;
QTextCursor block_start_cursor, drag_cursor;
int prev_lc, auto_comp_pl, timer_parse, timer_blink, cur_search_ind, pos_press, pos_el_press;
int cursor_width;
bool spaces_, _ignore_focus_out, _first, _destructor, _replacing;
bool word_complete, help_visible, cursor_state, block_sel_state;
bool eventFilter(QObject * o, QEvent * e) override;
void showEvent(QShowEvent * ) override;
void timerEvent(QTimerEvent * ) override;
void leaveEvent(QEvent * ) override;
void changeEvent(QEvent * e) override;
bool codeKeyEvent(QKeyEvent * ke);
void toggleComment();
void highlightBrackets();
void applyExtraSelection();
void clearSearch();
void moveToSearch();
int searchIndFromCursor();
QRect cursorRect();
QRect blockSelectionRect();
QVector<QTextCursor> blockSelectionCursors(QRect bsr);
void repaintCursor();
void drawCursor();
bool hasBlockSelection() const;
void startBlockSelection();
void cancelBlockSelection();
void switchBlockSelection(QKeyEvent * ke = nullptr);
bool removeBlockSelection(bool is_del);
void insertBlockSelection(QString text);
void createBlockSelection();
void cancelDragCursor();
ACEntry findEntryOnCursor(QTextCursor tc, int arg = -1, ACClass * acc = 0, QPair<QStringList, QString> * scope = 0);
private slots:
void _activateLink(QCodeEdit::ACEntry e) {linkClicked(e);}
@@ -236,6 +175,64 @@ signals:
void textChanged();
void parseRequest();
private:
struct QAD_WIDGETS_EXPORT ACClass {
ACClass(int i = -2, ACClassType c = QCodeEdit::Keyword, const QString & n = QString(), const QIcon & ic = QIcon()): id(i), class_(c), name(n), icon(ic) {}
int id;
ACClassType class_;
QString name;
QIcon icon;
};
enum LabelHelpType {
lhMain,
lhHint,
lhF1,
lh_last
};
bool eventFilter(QObject * o, QEvent * e) override;
void showEvent(QShowEvent * ) override;
void timerEvent(QTimerEvent * ) override;
void leaveEvent(QEvent * ) override;
void changeEvent(QEvent * e) override;
bool codeKeyEvent(QKeyEvent * ke);
void toggleComment();
void highlightBrackets();
void applyExtraSelection();
void clearSearch();
void moveToSearch();
int searchIndFromCursor();
QRect cursorRect();
QRect blockSelectionRect();
QVector<QTextCursor> blockSelectionCursors(QRect bsr);
void repaintCursor();
void drawCursor();
bool hasBlockSelection() const;
void startBlockSelection();
void cancelBlockSelection();
void switchBlockSelection(QKeyEvent * ke = nullptr);
bool removeBlockSelection(bool is_del);
void insertBlockSelection(QString text);
void createBlockSelection();
void cancelDragCursor();
ACEntry findEntryOnCursor(QTextCursor tc, int arg = -1, ACClass * acc = nullptr, QPair<QStringList, QString> * scope = nullptr);
Ui::QCodeEdit * ui;
QCodeEditCompleter * completer;
IconedLabel * lbl_help[3];
QFrame * widget_help;
_QCE_Viewport * overlay;
QTextEdit::ExtraSelection es_line, es_cursor, es_bracket, es_range, es_search, es_link;
QList<QTextEdit::ExtraSelection> es_selected, es_custom, es_brackets, es_search_list, es_blockselection;
QMap<int, ACClass> ac_classes;
QStringList cursor_scope;
QString comment_text;
ACEntry link_entry, help_entry;
QTextCursor block_start_cursor, drag_cursor;
int prev_lc, auto_comp_pl, timer_parse, timer_blink, cur_search_ind, pos_press, pos_el_press;
int cursor_width;
bool spaces_, _ignore_focus_out, _first, _destructor, _replacing;
bool word_complete, help_visible, cursor_state, block_sel_state;
};