PDA

View Full Version : Code Completion in QScintilla



jpjimenez
12th July 2007, 05:27
Hi, I work on ubuntu and I am developing a simple IDE to edit ActionScript projects, I am new in this world of QScintilla but I have traying since some days ago how to implement the Code Completion with QScintilla but have no results yet. I don't know how to do it. So Please if somebody can help me with a little piece of code, some example, I will appreciate it very, very much. I'm going to put a little code that I have tried but isn't work. Please help me.

my useless code

I have a class CTextEdit inherit from QsciScintilla with this method

void CTextEdit::testTextModified(){

QString text = this->text();
if(text[text.length()-1] == '.')
{
QStringList list; list << "aaaa";
list << "bbb";
list << "cc";
this->showUserList(1,list);
}
}

and in other place I connect the CTextEdit*textEdit = new CTextEdit in this way

connect(textEdit, SIGNAL(textChanged()), this, SLOT(testTextModified()));

The connection works and testTextModified() run. But nothing about the completion. Please help me with some example.

fullmetalcoder
12th July 2007, 10:05
There are already code-completion facilities in QScintilla that can be turned on easily (read the docs....) but they won't work unless a lexer (i.e. syntax highlighter with more general purpose...) is set to the editor. For instance :

setLexer(new QsciLexerCPP);
If your language what are Action Script BTW?) is not supported by the available lexers you'll have to write one before being able to work with code completion...

Hope this helps. (Yet I don't recommend using QScintilla if you're looking for flexibility ;) )

jpjimenez
12th July 2007, 22:21
Hi, thanks for your reply, as I said I am a little new with QScintilla (and Scintilla), I would like to get the full code completion of QScintilla but is just that I don't know how, I don't have a good documentation, and examples to do that. I really don't understand it. That's why I tried a simple way, but doesn't work. If you could help me please, I really need it.

I get from my compiler all I need to put in the ListBox of the code completion, is just that I don't know how. I mean, my compiler, do all the work, and give me all I need, I just want to add to the code-completion. Anyway if you can help me with the full auto-completion. Tell me where I can get the information I need, anything will by useful. Thanks again.

fullmetalcoder
13th July 2007, 10:39
I get from my compiler all I need to put in the ListBox of the code completion
Then using QScintilla may not be needed... You can simply use a QCompleter on a QTextEdit (there's an example of such a combination in Qt)


Tell me where I can get the information I need, anything will by useful.
There should be some docs distributed along QScintilla... In case they are not there you could generate them with doxygen or consult the online docs (http://www.riverbankcomputing.com/Docs/QScintilla2/index.html).

jpjimenez
13th July 2007, 18:01
THanks again my friend, is just that I think that QScintilla can help me 'cause all the features it has like: code folding and zoom, (I don't know if Qt components have it), and I was thinking that QScintilla's components are more flexible to higlithing code.
When I said that "I get all I need from my compiler" is just that it do the lexer and sintax analysis, and give me an XML of what I need to put in the code-completion ListBox. That's way I want to use QScintilla, because of its features.

Anyway if can help me about it, I mean if Qt components can bring me all the features I need.

patrik08
13th July 2007, 22:42
Yesterday i make a part on html edit on scintilla ... + line nummer ecc..
&& Completion word is only grep from the self page...

if you like implement more word .. like sqllite db have a look on source ..
http://www.qt-apps.org/content/show.php/QKeyWord+grep+Robot+-+Word-Completer?content=59422
and subclass the db sql as QCompleter





QViScintilla::QViScintilla( QWidget* parent )
: QsciScintilla(parent)
{
const QString usersetfont = setter.value("DefaultFontsS").toString();
QFont settfont;
settfont.fromString(usersetfont);
int fromsetting = settfont.pointSize();
qDebug() << "### sci usersetfont " << usersetfont;
qDebug() << "### sci fromsetting " << fromsetting;
fontsize = 12;
#if defined Q_WS_MAC
fontsize = 22;
#endif
numerobase = 0;
if (fromsetting > 2) {
setFont(settfont);
} else {
QFont font;
font.setFamily(QString::fromUtf8("Arial"));
font.setPointSize(fontsize);
setFont(font);
}

/* QsciLexerHTML lexer overwrite font! */
setPaper(QColor("#fbffcb"));
setIndentationGuidesBackgroundColor(QColor("#e6e6de"));
setAutoCompletionThreshold(2);
setFolding(QsciScintilla::BoxedFoldStyle);;
setMarginLineNumbers(1,true);
setAutoCompletionFillupsEnabled(true);
setAutoCompletionSource(QsciScintilla::AcsAll);
setCaretWidth(10);
setCaretLineBackgroundColor(QColor("#e6fff0"));
setCaretLineVisible(true);
ensureLineVisible(1);
setUtf8(true);
setWhitespaceVisibility(QsciScintilla::WsVisible);
QsciLexerHTML *htmllex = new QsciLexerHTML(this);
setLexer(htmllex);
shortcut1 = new QShortcut(QKeySequence("Ctrl+S"),this);
model = PAGER_LOADING_FUNCTIONS;
connect(shortcut1, SIGNAL(activated()),this, SLOT(SaveCurrentDoc()));
/////////connect(this, SIGNAL(textChanged()),this, SLOT(UpdateParent()));
shortcut7 = new QShortcut(QKeySequence::ZoomOut,this); /* CTRL- */
shortcut8 = new QShortcut(QKeySequence::ZoomIn,this); /* CTRL+ */
connect(shortcut7, SIGNAL(activated()),this, SLOT(Decreasefont()));
connect(shortcut8, SIGNAL(activated()),this, SLOT(Increasefont()));
}
void QViScintilla::Increasefont()
{
////qDebug() << "### zoom + " << fontsize;
zoomIn();
}

void QViScintilla::Decreasefont()
{
////qDebug() << "### zoom - " << fontsize;
zoomOut();
}