From a2fb031a1d468ce4470cb0f9d1a9d6eda4ef39af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Thu, 18 Jun 2009 22:48:55 +0000 Subject: [PATCH] [GB.QT.EXT] * NEW: Editor.ShowWord() is a new method that highlights a piece of text on a specific line. git-svn-id: svn://localhost/gambas/trunk@2026 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- gb.qt/src/ext/CEditor.cpp | 11 ++++++ gb.qt/src/ext/gview.cpp | 72 +++++++++++++++++++++++++++------------ gb.qt/src/ext/gview.h | 3 ++ 3 files changed, 65 insertions(+), 21 deletions(-) diff --git a/gb.qt/src/ext/CEditor.cpp b/gb.qt/src/ext/CEditor.cpp index 39391d776..7ba227381 100644 --- a/gb.qt/src/ext/CEditor.cpp +++ b/gb.qt/src/ext/CEditor.cpp @@ -953,6 +953,16 @@ BEGIN_METHOD(CEDITOR_show_string, GB_STRING str; GB_BOOLEAN ignoreCase) END_METHOD +BEGIN_METHOD(CEDITOR_show_word, GB_INTEGER line; GB_INTEGER col; GB_INTEGER len) + + int line = VARGOPT(line, -1); + int col = VARGOPT(col, -1); + int len = VARGOPT(len, -1); + + WIDGET->showWord(line, col, len); + +END_METHOD + /***************************************************************************/ @@ -1128,6 +1138,7 @@ GB_DESC CEditorDesc[] = GB_PROPERTY("Highlight", "i", CEDITOR_highlight), GB_PROPERTY("KeywordsUseUpperCase", "b", CEDITOR_keywords_ucase), GB_METHOD("ShowString", NULL, CEDITOR_show_string, "[(String)s(IgnoreCase)b]"), + GB_METHOD("ShowWord", NULL, CEDITOR_show_word, "[(Line)i(Column)i(Length)i]"), GB_PROPERTY("TabSize", "i", CEDITOR_tab_length), GB_METHOD("Reset", NULL, CEDITOR_reset, NULL), diff --git a/gb.qt/src/ext/gview.cpp b/gb.qt/src/ext/gview.cpp index 5e1ebc34b..317725746 100644 --- a/gb.qt/src/ext/gview.cpp +++ b/gb.qt/src/ext/gview.cpp @@ -124,6 +124,9 @@ GEditor::GEditor(QWidget *parent) flashed = false; painting = false; _showStringIgnoreCase = false; + _showRow = -1; + _showCol = 0; + _showLen = 0; for (i = 0; i < GLine::NUM_STATE; i++) { @@ -380,25 +383,6 @@ void GEditor::paintText(QPainter &p, GLine *l, int x, int y, int xmin, int lmax, bool draw_bg; p.setFont(font()); - - if (_showString.length()) - { - pos = 0; - bg = styles[GLine::Highlight].color; - for(;;) - { - if (pos >= (int)l->s.length()) - break; - pos = l->s.find(_showString, pos, _showStringIgnoreCase); - if (pos < 0) - break; - ps = lineWidth(row, pos); - nx = lineWidth(row, pos + _showString.length()); - p.fillRect(ps, 0, nx - ps, h, bg); - pos += _showString.length(); - } - } - pos = 0; ps = find_last_non_space(l->s.getString()) + 1; @@ -489,6 +473,39 @@ void GEditor::paintText(QPainter &p, GLine *l, int x, int y, int xmin, int lmax, } } +void GEditor::paintShowString(QPainter &p, GLine *l, int x, int y, int xmin, int lmax, int h, int row) +{ + int pos; + QString sd; + int nx; + int ps; + QColor bg; + + pos = 0; + bg = styles[GLine::Highlight].color; + for(;;) + { + if (pos >= (int)l->s.length()) + break; + pos = l->s.find(_showString, pos, _showStringIgnoreCase); + if (pos < 0) + break; + ps = lineWidth(row, pos); + //if (ps > (xmin + lmax)) + // break; + nx = lineWidth(row, pos + _showString.length()); + p.fillRect(ps, 0, nx - ps, h, bg); + pos += _showString.length(); + } + + if (row == _showRow && _showLen > 0 && _showCol >= 0 && _showCol < (int)l->s.length()) + { + ps = lineWidth(row, _showCol); + nx = lineWidth(row, QMAX((int)l->s.length(), _showCol + _showLen)); + p.fillRect(ps, 0, nx - ps, h, bg); + } +} + static void make_blend(QPixmap &pix, QColor start, QColor end, int height) //, bool loop = false) { double r, g, b, dr, dg, db; @@ -650,6 +667,10 @@ void GEditor::paintCell(QPainter * painter, int row, int) p.translate(-ur.left(), 0); + // Show string + if (highlight && (_showRow == realRow || _showString.length())) + paintShowString(p, l, margin, fm.ascent() + 1, xmin, lmax, cellHeight(), realRow); + // Selection background xs1 = 0; xs2 = 0; @@ -732,9 +753,10 @@ void GEditor::paintCell(QPainter * painter, int row, int) // Folding symbol if (margin && l->proc) { - p.setPen(styles[GLine::Normal].color); + QPalette pal; + pal.setColor(QColorGroup::Foreground, styles[GLine::Normal].color); style().drawPrimitive(folded ? QStyle::PE_ArrowRight : QStyle::PE_ArrowDown, &p, - QRect(margin - 12, 0, 12, 12), QApplication::palette().active(), QStyle::Style_Default | QStyle::Style_Enabled); + QRect(margin - 12, 0, 12, 12), pal.active(), QStyle::Style_Default | QStyle::Style_Enabled); } // Breakpoint symbol @@ -2100,3 +2122,11 @@ void GEditor::showString(GString s, bool ignoreCase) _showStringIgnoreCase = ignoreCase; updateContents(); } + +void GEditor::showWord(int y, int x, int len) +{ + _showRow = y; + _showCol = x; + _showLen = len; + updateLine(y); +} diff --git a/gb.qt/src/ext/gview.h b/gb.qt/src/ext/gview.h index bef0170ac..18222d817 100644 --- a/gb.qt/src/ext/gview.h +++ b/gb.qt/src/ext/gview.h @@ -76,6 +76,7 @@ private: bool painting; GString _showString; bool _showStringIgnoreCase; + int _showRow, _showCol, _showLen; int lastx; bool left; @@ -106,6 +107,7 @@ private: int findLargestLine(); void paintText(QPainter &p, GLine *l, int x, int y, int xmin, int lmax, int h, int x1, int x2, int row); + void paintShowString(QPainter &p, GLine *l, int x, int y, int xmin, int lmax, int h, int row); void paintDottedSpaces(QPainter &p, int row, int ps, int ls); void docTextChanged(); @@ -212,6 +214,7 @@ public: void checkMatching(); void flash(); void showString(GString s, bool ignoreCase); + void showWord(int y, int x, int len); void foldClear() { fold.clear(); } void foldLine(int row, bool no_refresh = false);