edbee - Qt Editor Library v0.11.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
texteditorautocompletecomponent.h
Go to the documentation of this file.
1// edbee - Copyright (c) 2012-2025 by Rick Blommers and contributors
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
6#include "edbee/exports.h"
7
8#include <QModelIndex>
9#include <QWidget>
10#include <QLabel>
11#include <QAbstractItemDelegate>
12#include <QPainter>
13#include <QScrollBar>
14#include <QStylePainter>
15#include <QPointer>
16#include <QMenu>
17#include <QTextDocument>
18
19class QListWidget;
20class QListWidgetItem;
21
22namespace edbee {
23
24class TextDocument;
29class TextRange;
30
31class FakeToolTip : public QWidget
32{
33 Q_OBJECT
34
35public:
36 explicit FakeToolTip(TextEditorController *controller, QWidget *parent = 0);
37 void setText(const QString text);
38 QTextDocument* tipText;
40
41private:
42 TextEditorController* controllerRef_;
43
44protected:
45 void paintEvent(QPaintEvent *e);
46 void resizeEvent(QResizeEvent *e);
47};
48
49// inspiration:
50// http://doc.qt.io/qt-5/qtwidgets-tools-customcompleter-example.html
51
55{
56 Q_OBJECT
57public:
59
61
62 QSize sizeHint() const;
63protected:
64
65 bool shouldDisplayAutoComplete(TextRange& range, QString& word);
66 void hideInfoTip();
67 bool fillAutoCompleteList(TextDocument *document, const TextRange &range, const QString& word );
68
69 void positionWidgetForCaretOffset(int offset);
70 bool eventFilter(QObject* obj, QEvent* event);
71
72 void hideEvent(QHideEvent *event);
73 //void focusOutEvent(QFocusEvent *event);
74 //void moveEvent(QMoveEvent *event);
75
77signals:
78
79public slots:
80 void updateList();
81 void backspacePressed();
82 void textKeyPressed();
83 void listItemClicked(QListWidgetItem*item);
84 void listItemDoubleClicked(QListWidgetItem*item);
85 void selectItemOnHover(QModelIndex modelIndex);
86 void showInfoTip();
87
88private:
89 TextEditorController* controllerRef_;
90 QMenu* menuRef_;
91 QListWidget* listWidgetRef_;
92 TextEditorComponent* editorComponentRef_;
93 TextMarginComponent* marginComponentRef_;
94 bool eventBeingFiltered_;
95 QString currentWord_;
96 bool canceled_;
97 QPointer<FakeToolTip> infoTipRef_;
98};
99
100class AutoCompleteDelegate : public QAbstractItemDelegate
101{
102 Q_OBJECT
103
104public:
106
108
109 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
110
111 QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
112
113public slots:
114
115private:
116 TextEditorController* controllerRef_;
117 int pixelSize;
118};
119
120}
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition texteditorautocompletecomponent.cpp:512
AutoCompleteDelegate(TextEditorController *controller, QObject *parent=0)
Definition texteditorautocompletecomponent.cpp:454
TextEditorController * controller() const
Definition texteditorautocompletecomponent.cpp:460
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition texteditorautocompletecomponent.cpp:465
void setText(const QString text)
Definition texteditorautocompletecomponent.cpp:543
TextEditorController * controller()
Definition texteditorautocompletecomponent.cpp:551
QTextDocument * tipText
Definition texteditorautocompletecomponent.h:38
FakeToolTip(TextEditorController *controller, QWidget *parent=0)
Definition texteditorautocompletecomponent.cpp:519
void resizeEvent(QResizeEvent *e)
Definition texteditorautocompletecomponent.cpp:592
void paintEvent(QPaintEvent *e)
Definition texteditorautocompletecomponent.cpp:556
This is the base and abstract class of a text document A TextDocument is the model part of the editor...
Definition textdocument.h:42
void showInfoTip()
Definition texteditorautocompletecomponent.cpp:140
QSize sizeHint() const
Definition texteditorautocompletecomponent.cpp:102
bool eventFilter(QObject *obj, QEvent *event)
we need to intercept keypresses if the widget is visible
Definition texteditorautocompletecomponent.cpp:318
bool shouldDisplayAutoComplete(TextRange &range, QString &word)
This method check if the autocomplete should be shown this method ALSO sets the word that's display.
Definition texteditorautocompletecomponent.cpp:111
void selectItemOnHover(QModelIndex modelIndex)
Definition texteditorautocompletecomponent.cpp:449
void insertCurrentSelectedListItem()
inserts the currently selected list item
Definition texteditorautocompletecomponent.cpp:385
void textKeyPressed()
this event is called when a key pressed
Definition texteditorautocompletecomponent.cpp:426
void listItemDoubleClicked(QListWidgetItem *item)
Definition texteditorautocompletecomponent.cpp:443
void positionWidgetForCaretOffset(int offset)
positions the widget so it's visible.
Definition texteditorautocompletecomponent.cpp:270
bool fillAutoCompleteList(TextDocument *document, const TextRange &range, const QString &word)
Fills the autocomplete list.
Definition texteditorautocompletecomponent.cpp:234
void updateList()
Definition texteditorautocompletecomponent.cpp:394
void hideInfoTip()
Definition texteditorautocompletecomponent.cpp:227
void backspacePressed()
processes backspaces
Definition texteditorautocompletecomponent.cpp:432
TextEditorAutoCompleteComponent(TextEditorController *controller, TextEditorComponent *parent, TextMarginComponent *margin)
Definition texteditorautocompletecomponent.cpp:32
void listItemClicked(QListWidgetItem *item)
Definition texteditorautocompletecomponent.cpp:437
TextEditorController * controller() const
Returns the current text editor controller.
Definition texteditorautocompletecomponent.cpp:97
void hideEvent(QHideEvent *event)
intercepts hide() calls to inform the tooltip to hide as well
Definition texteditorautocompletecomponent.cpp:311
This is the main texteditor-component (which is the true editor) This is the QWidget that recieves th...
Definition texteditorcomponent.h:29
The texteditor works via the controller. The controller is the central point/mediator which maps/cont...
Definition texteditorcontroller.h:39
This is the general edbee widget The core functionality of this widget is divided in several separate...
Definition texteditorwidget.h:36
The margin/line-number component This class is used for rendering line-numbers etc.
Definition textmargincomponent.h:53
A single text region A region constists of an anchor and a caret: The anchor defines the 'start' of t...
Definition textrange.h:29
#define EDBEE_EXPORT
Definition exports.h:15
QT Acessibility has an issue with reporting blank lines between elements lines. defining 'WINDOWS_EMP...
Definition commentcommand.cpp:20