[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
This commit is contained in:
Benoît Minisini 2009-06-18 22:48:55 +00:00
parent d35c59fbc8
commit a2fb031a1d
3 changed files with 65 additions and 21 deletions

View File

@ -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),

View File

@ -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);
}

View File

@ -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);