-class CaretWidget {
-public:
- CaretWidget() : rtl_(false), l_shape_(false), completable_(false),
- x_(0), caret_width_(0)
- {}
-
- /* Draw he 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 (!rect_.isValid())
- return;
-
- int const x = x_ - horiz_offset;
- int const y = rect_.top();
- int const l = x_ - rect_.left();
- int const r = rect_.right() - x_;
- int const bot = rect_.bottom();
-
- // draw vertical line
- painter.fillRect(x, y, caret_width_, rect_.height(), color_);
-
- // draw RTL/LTR indication
- painter.setPen(color_);
- if (l_shape_) {
- if (rtl_)
- painter.drawLine(x, bot, x - l + 1, bot);
- else
- painter.drawLine(x, bot, x + caret_width_ + r - 1, bot);
- }
-
- // draw completion triangle
- if (completable_) {
- int m = y + rect_.height() / 2;
- int d = TabIndicatorWidth - 1;
- if (rtl_) {
- painter.drawLine(x - 1, m - d, x - 1 - d, m);
- painter.drawLine(x - 1, m + d, x - 1 - d, m);
- } else {
- painter.drawLine(x + caret_width_, m - d, x + caret_width_ + d, m);
- painter.drawLine(x + caret_width_, m + d, x + caret_width_ + d, m);
- }
- }
- }
-
- void update(int x, int y, int h, bool l_shape,
- bool rtl, bool completable)
- {
- color_ = guiApp->colorCache().get(Color_cursor);
- l_shape_ = l_shape;
- rtl_ = rtl;
- completable_ = completable;
- x_ = x;
-
- // extension to left and right
- int l = 0;
- int r = 0;
-
- // RTL/LTR indication
- if (l_shape_) {
- if (rtl)
- l += h / 3;
- else
- r += h / 3;
- }
-
- // completion triangle
- if (completable_) {
- if (rtl)
- l = max(l, TabIndicatorWidth);
- else
- r = max(r, TabIndicatorWidth);
- }
-
- //FIXME: LyXRC::cursor_width should be caret_width
- caret_width_ = lyxrc.cursor_width
- ? lyxrc.cursor_width
- : 1 + int((lyxrc.currentZoom + 50) / 200.0);
-
- // compute overall rectangle
- rect_ = QRect(x - l, y, caret_width_ + r + l, h);
- }
-
- QRect const & rect() { return rect_; }
-
-private:
- /// caret is in RTL or LTR text
- bool rtl_;
- /// indication for RTL or LTR
- bool l_shape_;
- /// triangle to show that a completion is available
- bool completable_;
- ///
- QColor color_;
- /// rectangle, possibly with l_shape and completion triangle
- QRect rect_;
- /// x position (were the vertical line is drawn)
- int x_;
- /// the width of the vertical blinking bar
- int caret_width_;
-};
-
-