/* constructor */
connect(this, SIGNAL(cursorPositionChanged(int,int)),this, SLOT(CursorAtIndex(int,int)));
baseram
= QApplication::clipboard();
/* capture word on clipboard & keyPressEvent */ completerbase->setModel(modelFromFile(":/img/_htmlwordslist.txt"));
completerbase
->setModelSorting
(QCompleter::CaseInsensitivelySortedModel);
completerbase->setCaseSensitivity(Qt::CaseInsensitive);
setCompleter(completerbase);
/* constructor */
/* completer from qt4 make it */
void QViScintilla::CursorAtIndex(int line ,int cool )
{
/* start from connect(this, SIGNAL(cursorPositionChanged(int,int)),this, SLOT(CursorAtIndex(int,int))); */
setAutoCompletionFillupsEnabled(false);
int newPos = SendScintilla(SCI_GETCURRENTPOS);
posX = SendScintilla(SCI_POINTXFROMPOSITION, 0, newPos);
posY = SendScintilla(SCI_POINTYFROMPOSITION, 0, newPos);
CURRENTWORD = TextUnderCursor(newPos); /* bring getWord(int position) to public !!!!! */
///////////qDebug() << "### word " << CURRENTWORD; /* word piece on cursor */
}
void QViScintilla
::setCompleter(QCompleter *completer
) {
if (c)
QObject::disconnect(c,
0,
this,
0);
c = completer;
if (!c) {
return;
}
c->setWidget(this);
c
->setCompletionMode
(QCompleter::PopupCompletion);
c->setCaseSensitivity(Qt::CaseSensitive);
connect(c, SIGNAL(activated(const QString&)), this, SLOT(insertCompletion(const QString&)));
}
void QViScintilla
::keyPressEvent(QKeyEvent *e
) {
if (c && c->popup()->isVisible()) {
// The following keys are forwarded by the completer to the widget
switch (e->key()) {
case Qt::Key_Enter:
case Qt::Key_Return:
case Qt::Key_Escape:
case Qt::Key_Backtab:
e->ignore();
return; // let the completer do default behavior
default:
break;
}
}
bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E); // CTRL+E
if (!c || !isShortcut) {
QsciScintillaBase::keyPressEvent(e);
}
const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
if (!c || (ctrlOrShift && CURRENTWORD.isEmpty())) {
return;
}
static QString eow
("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-=");
// end of word bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
if (!isShortcut && (hasModifier || CURRENTWORD.isEmpty()|| completionPrefix.length() < 2 || eow.contains(CURRENTWORD.right(1)))) {
c->popup()->hide();
return;
}
if (CURRENTWORD != c->completionPrefix()) {
c->setCompletionPrefix(CURRENTWORD);
c->popup()->setCurrentIndex(c->completionModel()->index(0, 0));
}
cr.setWidth(c->popup()->sizeHintForColumn(0) + c->popup()->verticalScrollBar()->sizeHint().width());
c->complete(cr); // popup it up!
}
{
if (!file.
open(QFile::ReadOnly))
while (!file.atEnd()) {
if (!line.isEmpty())
words << line.trimmed();
}
}
/*
on class QSCINTILLA_EXPORT QsciScintilla : public QsciScintillaBase
append on public ! && rebuild lib.. static
inline QString TextUnderCursor(int &pos) {
return getWord(pos);
}
*/
/* constructor */
connect(this, SIGNAL(cursorPositionChanged(int,int)),this, SLOT(CursorAtIndex(int,int)));
baseram = QApplication::clipboard(); /* capture word on clipboard & keyPressEvent */
completerbase = new QCompleter();
completerbase->setModel(modelFromFile(":/img/_htmlwordslist.txt"));
completerbase->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
completerbase->setCaseSensitivity(Qt::CaseInsensitive);
setCompleter(completerbase);
/* constructor */
/* completer from qt4 make it */
void QViScintilla::CursorAtIndex(int line ,int cool )
{
/* start from connect(this, SIGNAL(cursorPositionChanged(int,int)),this, SLOT(CursorAtIndex(int,int))); */
setAutoCompletionFillupsEnabled(false);
int newPos = SendScintilla(SCI_GETCURRENTPOS);
posX = SendScintilla(SCI_POINTXFROMPOSITION, 0, newPos);
posY = SendScintilla(SCI_POINTYFROMPOSITION, 0, newPos);
CURRENTWORD = TextUnderCursor(newPos); /* bring getWord(int position) to public !!!!! */
///////////qDebug() << "### word " << CURRENTWORD; /* word piece on cursor */
}
void QViScintilla::setCompleter(QCompleter *completer)
{
if (c)
QObject::disconnect(c, 0, this, 0);
c = completer;
if (!c) {
return;
}
c->setWidget(this);
c->setCompletionMode(QCompleter::PopupCompletion);
c->setCaseSensitivity(Qt::CaseSensitive);
connect(c, SIGNAL(activated(const QString&)), this, SLOT(insertCompletion(const QString&)));
}
void QViScintilla::keyPressEvent(QKeyEvent *e)
{
if (c && c->popup()->isVisible()) {
// The following keys are forwarded by the completer to the widget
switch (e->key()) {
case Qt::Key_Enter:
case Qt::Key_Return:
case Qt::Key_Escape:
case Qt::Key_Backtab:
e->ignore();
return; // let the completer do default behavior
default:
break;
}
}
bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E); // CTRL+E
if (!c || !isShortcut) {
QsciScintillaBase::keyPressEvent(e);
}
const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
if (!c || (ctrlOrShift && CURRENTWORD.isEmpty())) {
return;
}
static QString eow("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-="); // end of word
bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
if (!isShortcut && (hasModifier || CURRENTWORD.isEmpty()|| completionPrefix.length() < 2 || eow.contains(CURRENTWORD.right(1)))) {
c->popup()->hide();
return;
}
if (CURRENTWORD != c->completionPrefix()) {
c->setCompletionPrefix(CURRENTWORD);
c->popup()->setCurrentIndex(c->completionModel()->index(0, 0));
}
QRect cr = QRect (posX, posY ,20,20);
cr.setWidth(c->popup()->sizeHintForColumn(0) + c->popup()->verticalScrollBar()->sizeHint().width());
c->complete(cr); // popup it up!
}
QAbstractItemModel *QViScintilla::modelFromFile(const QString& fileName)
{
QFile file(fileName);
if (!file.open(QFile::ReadOnly))
return new QStringListModel(completer);
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
QStringList words;
while (!file.atEnd()) {
QByteArray line = file.readLine();
if (!line.isEmpty())
words << line.trimmed();
}
QApplication::restoreOverrideCursor();
return new QStringListModel(words, completer);
}
/*
on class QSCINTILLA_EXPORT QsciScintilla : public QsciScintillaBase
append on public ! && rebuild lib.. static
inline QString TextUnderCursor(int &pos) {
return getWord(pos);
}
*/
To copy to clipboard, switch view to plain text mode
Bookmarks