-class CaretWidget {
-public:
- CaretWidget() : dir(1), l_shape(false), completable(false),
- x(0), y(0), slope(0)
- {}
-
- /* Draw the caret. Parameter \c horiz_offset is not 0 when there
- * has been horizontal scrolling in current row
- */
- void draw(QPainter & painter, int horiz_offset)
- {
- if (dim.empty())
- return;
- // correction is (1) for horizontal scrolling and (2) for
- // better positionning of large cursors.
- int const xx = x - horiz_offset - dim.wid / 2;
- int const lx = dim.height() / 3;
-
- // draw caret box
- painter.setPen(color);
- QPainterPath path;
- path.moveTo(xx + dim.asc * slope, y);
- path.lineTo(xx - dim.des * slope, y + dim.height());
- path.lineTo(xx + dir * dim.wid - dim.des * slope, y + dim.height());
- path.lineTo(xx + dir * dim.wid + dim.asc * slope, y);
- painter.setRenderHint(QPainter::Antialiasing, true);
- painter.fillPath(path, color);
- painter.setRenderHint(QPainter::Antialiasing, false);
-
- // draw RTL/LTR indication
- if (l_shape)
- painter.fillRect(xx - dim.des * slope,
- y + dim.height() - dim.wid + 1,
- dir * (dim.wid + lx - 1), dim.wid, color);
-
- // draw completion triangle
- if (completable) {
- int const m = y + dim.height() / 2;
- int const d = TabIndicatorWidth * dim.wid - 1;
- // offset for slanted carret
- int const sx = (dim.asc - (dim.height() / 2 - d)) * slope;
- painter.drawLine(xx + dir * (dim.wid + 1) + sx, m - d,
- xx + dir * (dim.wid + d + 1) + sx, m);
- painter.drawLine(xx + dir * (dim.wid + 1) + sx, m + d,
- xx + dir * (dim.wid + d + 1) + sx, m);
- }
- }
-
- void update(BufferView const * bv, bool complet) {
- // Cursor size and position
- Point point;
- bv->caretPosAndDim(point, dim);
- x = point.x_;
- y = point.y_;
- completable = complet;
-
- Cursor const & cur = bv->cursor();
- Font const & realfont = cur.real_current_font;
- FontMetrics const & fm = theFontMetrics(realfont.fontInfo());
- BufferParams const & bp = bv->buffer().params();
- bool const samelang = realfont.language() == bp.language;
- bool const isrtl = realfont.isVisibleRightToLeft();
- dir = isrtl ? -1 : 1;
- // special shape
- l_shape = (!samelang || isrtl != bp.language->rightToLeft())
- && realfont.language() != latex_language;
-
- // use slanted caret for italics in text edit mode
- // except for selections because the selection rect does not slant
- bool const slant = fm.italic() && cur.inTexted() && !cur.selection();
- slope = slant ? fm.italicSlope() : 0;
-
- color = guiApp->colorCache().get(Color_cursor);
- }
-
- /// text direction (1 for LtR, -1 for RtL)
- int dir;
- /// indication for language change
- bool l_shape;
- /// triangle to show that a completion is available
- bool completable;
- ///
- QColor color;
- /// dimension uf base caret
- Dimension dim;
- /// x position (were the vertical line is drawn)
- int x;
- /// y position (the top of the caret)
- int y;
- /// the slope for drawing slanted caret
- double slope;
-};
-
-