22 #include <QPushButton>
23 #include <QToolButton>
24 #include <QHBoxLayout>
42 static const char*
sum_xpm[] = {
"16 16 6 1",
"# c None",
". c None",
"b c #808080",
43 "d c #010000",
"c c #aaaaaa",
"a c #303030",
"................",
44 ".#aaaaaaaaaa##..",
".abbbbbbcbbba...",
".#abbaaaaabba...",
"..#aabba..aba...",
45 "....#abba..a#...",
".....#abba......",
".....#abba......",
"...##abba...#...",
46 "...#abba...aa...",
"..#abba...aca...",
".#abbaaaaabba...",
".abbbbbbbbbba...",
47 ".aaaaaaaaaaa#...",
"................",
"................"};
50 static const char*
stop_xpm[] = {
"16 16 4 1",
" c None",
". c #FF0000",
"+ c #FF8080",
51 "@ c #FFFFFF",
" ",
" ",
" ...... ",
52 " ...+++.. ",
" ....@@@... ",
" .....@@@.... ",
" .....@@@.... ",
53 " .....@@@.... ",
" .....@@@.... ",
" ............ ",
" ....@@@.... ",
54 " ...@@@... ",
" ....... ",
" ..... ",
" ",
58 : QWidget(parent), _dialog(0), _context(
""), _searchPath(
""), _applyOnSelect(applyOnSelect) {
71 error->setHidden(
true);
82 QToolButton* button =
new QToolButton();
84 button->setIcon(QIcon(QPixmap(
sum_xpm)));
191 edit->setText(newText);
214 bool valid =
expr.isValid();
216 if (!valid) err =
expr.parseError();
222 error->setHidden(hidden);
224 error->setToolTip(QString::fromStdString(err));
229 edit->setHidden(enabled);
239 edit->setHorizontalScrollBarPolicy(policy);
246 setMaximumHeight(25);
256 QTreeView* treePopup =
new QTreeView;
258 treePopup->setRootIsDecorated(
false);
259 treePopup->setMinimumWidth(300);
260 treePopup->setMinimumHeight(50);
261 treePopup->setItemsExpandable(
true);
264 completer->setCompletionMode(QCompleter::PopupCompletion);
265 completer->setCaseSensitivity(Qt::CaseInsensitive);
272 QTextEdit::focusInEvent(e);
278 QTextCursor newCursor = textCursor();
279 newCursor.clearSelection();
280 setTextCursor(newCursor);
283 QTextEdit::focusOutEvent(e);
288 QTextEdit::mousePressEvent(event);
293 QTextEdit::mouseDoubleClickEvent(event);
302 QTextEdit::paintEvent(e);
314 case Qt::Key_Backtab:
323 if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
327 }
else if (e->key() == Qt::Key_Escape) {
332 }
else if (e->key() == Qt::Key_Tab) {
333 QWidget::keyPressEvent(e);
342 bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E);
344 QTextEdit::keyPressEvent(e);
346 const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
347 if (!
completer || (ctrlOrShift && e->text().isEmpty()))
return;
349 bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
352 QTextCursor tc = textCursor();
353 tc.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
354 QString line = tc.selectedText();
357 static QRegExp completion(
"^(?:.*[^A-Za-z0-9_$])?((?:\\$[A-Za-z0-9_]*)|[A-Za-z]+[A-Za-z0-9_]*)$");
358 int index = completion.indexIn(line);
359 QString completionPrefix;
360 if (
index != -1 && !line.contains(
'#')) {
361 completionPrefix = completion.cap(1);
366 if (!isShortcut && (hasModifier || e->text().isEmpty() || completionPrefix.length() < 1 ||
index == -1)) {
371 if (completionPrefix !=
completer->completionPrefix()) {
372 completer->setCompletionPrefix(completionPrefix);
377 QRect cr = cursorRect();
378 cr.setWidth(2 * (
completer->popup()->sizeHintForColumn(0) +
completer->popup()->sizeHintForColumn(1) +
379 completer->popup()->verticalScrollBar()->sizeHint().width()));
386 static QRegExp inFunction(
"^(?:.*[^A-Za-z0-9_$])?([A-Za-z0-9_]+)\\([^()]*$");
387 int index2 = inFunction.indexIn(line);
389 QString functionName = inFunction.cap(1);
391 QString tip =
"<b>" + tips[0] +
"</b>";
392 for (
int i = 1; i < tips.size(); i++) {
393 tip +=
"<br>" + tips[i];
403 if (
string ==
"")
return;
407 QRect cr = cursorRect();
409 cr.setWidth(cr.width() * 3);
423 QTextCursor tc = textCursor();
424 int extra = completion.length() -
completer->completionPrefix().length();
425 tc.movePosition(QTextCursor::Left);
426 tc.movePosition(QTextCursor::EndOfWord);
427 tc.insertText(completion.right(extra));
428 if (completion[0] !=
'$') tc.insertText(
"(");