mirror of
https://github.com/fralx/LimeReport.git
synced 2025-10-04 12:07:24 +03:00
Highlighter has been added
This commit is contained in:
@@ -9,93 +9,6 @@
|
||||
|
||||
namespace LimeReport{
|
||||
|
||||
TextEditorWithCompleater::TextEditorWithCompleater(QWidget *parent)
|
||||
: QTextEdit(parent),m_compleater(0)
|
||||
{
|
||||
}
|
||||
|
||||
void TextEditorWithCompleater::setCompleter(QCompleter *value)
|
||||
{
|
||||
if (value) disconnect(value,0,this,0);
|
||||
m_compleater = value;
|
||||
if (!m_compleater) return;
|
||||
m_compleater->setWidget(this);
|
||||
m_compleater->setCompletionMode(QCompleter::PopupCompletion);
|
||||
m_compleater->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
connect(m_compleater,SIGNAL(activated(QString)),this,SLOT(insertCompletion(QString)));
|
||||
}
|
||||
|
||||
void TextEditorWithCompleater::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
if (m_compleater && m_compleater->popup()->isVisible()) {
|
||||
switch (e->key()) {
|
||||
case Qt::Key_Enter:
|
||||
case Qt::Key_Return:
|
||||
case Qt::Key_Escape:
|
||||
case Qt::Key_Tab:
|
||||
case Qt::Key_Backtab:
|
||||
e->ignore();
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_Space);
|
||||
if (!m_compleater || !isShortcut) QTextEdit::keyPressEvent(e);
|
||||
|
||||
const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
|
||||
if (!m_compleater || (ctrlOrShift && e->text().isEmpty()))
|
||||
return;
|
||||
|
||||
static QString eow("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-="); // end of word
|
||||
bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
|
||||
|
||||
QString completionPrefix = textUnderCursor();
|
||||
|
||||
if (!isShortcut && (hasModifier || e->text().isEmpty()|| completionPrefix.length() < 3
|
||||
|| eow.contains(e->text().right(1)))) {
|
||||
m_compleater->popup()->hide();
|
||||
return;
|
||||
}
|
||||
|
||||
if (completionPrefix != m_compleater->completionPrefix()) {
|
||||
m_compleater->setCompletionPrefix(completionPrefix);
|
||||
m_compleater->popup()->setCurrentIndex(m_compleater->completionModel()->index(0, 0));
|
||||
}
|
||||
|
||||
QRect cr = cursorRect();
|
||||
cr.setWidth(m_compleater->popup()->sizeHintForColumn(0)
|
||||
+ m_compleater->popup()->verticalScrollBar()->sizeHint().width());
|
||||
m_compleater->complete(cr);
|
||||
|
||||
}
|
||||
|
||||
void TextEditorWithCompleater::focusInEvent(QFocusEvent *e)
|
||||
{
|
||||
if (m_compleater) m_compleater->setWidget(this);
|
||||
QTextEdit::focusInEvent(e);
|
||||
}
|
||||
|
||||
QString TextEditorWithCompleater::textUnderCursor() const
|
||||
{
|
||||
QTextCursor tc = textCursor();
|
||||
tc.select(QTextCursor::WordUnderCursor);
|
||||
return tc.selectedText();
|
||||
}
|
||||
|
||||
void TextEditorWithCompleater::insertCompletion(const QString &completion)
|
||||
{
|
||||
if (m_compleater->widget() != this)
|
||||
return;
|
||||
QTextCursor tc = textCursor();
|
||||
int extra = completion.length() - m_compleater->completionPrefix().length();
|
||||
tc.movePosition(QTextCursor::Left);
|
||||
tc.movePosition(QTextCursor::EndOfWord);
|
||||
tc.insertText(completion.right(extra));
|
||||
setTextCursor(tc);
|
||||
}
|
||||
|
||||
ScriptEditor::ScriptEditor(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ScriptEditor)
|
||||
|
Reference in New Issue
Block a user