Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
SidebarWidget Class Reference
Inheritance diagram for SidebarWidget:
Collaboration diagram for SidebarWidget:

Public Member Functions

 SidebarWidget (JSEdit *editor)
 

Public Attributes

QVector< BlockInfo > lineNumbers
 
QColor backgroundColor
 
QColor lineNumberColor
 
QColor indicatorColor
 
QColor foldIndicatorColor
 
QFont font
 
int foldIndicatorWidth
 
QPixmap rightArrowIcon
 
QPixmap downArrowIcon
 

Protected Member Functions

void mousePressEvent (QMouseEvent *event)
 
void paintEvent (QPaintEvent *event)
 

Detailed Description

Definition at line 427 of file jsedit.cpp.

Constructor & Destructor Documentation

◆ SidebarWidget()

SidebarWidget::SidebarWidget ( JSEdit *  editor)

Definition at line 445 of file jsedit.cpp.

446  : QWidget(editor)
447  , foldIndicatorWidth(0)
448 {
449  backgroundColor = Qt::lightGray;
450  lineNumberColor = Qt::black;
451  indicatorColor = Qt::white;
452  foldIndicatorColor = Qt::lightGray;
453 }

References backgroundColor, foldIndicatorColor, indicatorColor, and lineNumberColor.

Member Function Documentation

◆ mousePressEvent()

void SidebarWidget::mousePressEvent ( QMouseEvent *  event)
protected

Definition at line 455 of file jsedit.cpp.

456 {
457  if (foldIndicatorWidth > 0) {
458  int xofs = width() - foldIndicatorWidth;
459  int lineNo = -1;
460  int fh = fontMetrics().lineSpacing();
461  int ys = event->pos().y();
462  if (event->pos().x() > xofs) {
463  foreach (BlockInfo ln, lineNumbers)
464  if (ln.position < ys && (ln.position + fh) > ys) {
465  if (ln.foldable)
466  lineNo = ln.number;
467  break;
468  }
469  }
470  if (lineNo >= 0) {
471  JSEdit *editor = qobject_cast<JSEdit*>(parent());
472  if (editor)
473  editor->toggleFold(lineNo);
474  }
475  }
476 }

References BlockInfo::foldable, foldIndicatorWidth, lineNumbers, BlockInfo::number, BlockInfo::position, and JSEdit::toggleFold().

Here is the call graph for this function:

◆ paintEvent()

void SidebarWidget::paintEvent ( QPaintEvent *  event)
protected

Definition at line 478 of file jsedit.cpp.

479 {
480  QPainter p(this);
481  p.fillRect(event->rect(), backgroundColor);
482  p.setPen(lineNumberColor);
483  p.setFont(font);
484  int fh = QFontMetrics(font).height();
485  foreach (BlockInfo ln, lineNumbers)
486  p.drawText(0, ln.position, width() - 4 - foldIndicatorWidth, fh, Qt::AlignRight, QString::number(ln.number));
487 
488  if (foldIndicatorWidth > 0) {
489  int xofs = width() - foldIndicatorWidth;
490  p.fillRect(xofs, 0, foldIndicatorWidth, height(), indicatorColor);
491 
492  // initialize (or recreate) the arrow icons whenever necessary
493  if (foldIndicatorWidth != rightArrowIcon.width()) {
494  QPainter iconPainter;
495  QPolygonF polygon;
496 
497  int dim = foldIndicatorWidth;
498  rightArrowIcon = QPixmap(dim, dim);
499  rightArrowIcon.fill(Qt::transparent);
501 
502  polygon << QPointF(dim * 0.4, dim * 0.25);
503  polygon << QPointF(dim * 0.4, dim * 0.75);
504  polygon << QPointF(dim * 0.8, dim * 0.5);
505  iconPainter.begin(&rightArrowIcon);
506  iconPainter.setRenderHint(QPainter::Antialiasing);
507  iconPainter.setPen(Qt::NoPen);
508  iconPainter.setBrush(foldIndicatorColor);
509  iconPainter.drawPolygon(polygon);
510  iconPainter.end();
511 
512  polygon.clear();
513  polygon << QPointF(dim * 0.25, dim * 0.4);
514  polygon << QPointF(dim * 0.75, dim * 0.4);
515  polygon << QPointF(dim * 0.5, dim * 0.8);
516  iconPainter.begin(&downArrowIcon);
517  iconPainter.setRenderHint(QPainter::Antialiasing);
518  iconPainter.setPen(Qt::NoPen);
519  iconPainter.setBrush(foldIndicatorColor);
520  iconPainter.drawPolygon(polygon);
521  iconPainter.end();
522  }
523 
524  foreach (BlockInfo ln, lineNumbers)
525  if (ln.foldable) {
526  if (ln.folded)
527  p.drawPixmap(xofs, ln.position, rightArrowIcon);
528  else
529  p.drawPixmap(xofs, ln.position, downArrowIcon);
530  }
531  }
532 }

References backgroundColor, downArrowIcon, BlockInfo::foldable, BlockInfo::folded, foldIndicatorColor, foldIndicatorWidth, font, indicatorColor, lineNumberColor, lineNumbers, BlockInfo::number, BlockInfo::position, and rightArrowIcon.

Member Data Documentation

◆ backgroundColor

QColor SidebarWidget::backgroundColor

Definition at line 432 of file jsedit.cpp.

Referenced by paintEvent(), and SidebarWidget().

◆ downArrowIcon

QPixmap SidebarWidget::downArrowIcon

Definition at line 439 of file jsedit.cpp.

Referenced by paintEvent().

◆ foldIndicatorColor

QColor SidebarWidget::foldIndicatorColor

Definition at line 435 of file jsedit.cpp.

Referenced by paintEvent(), and SidebarWidget().

◆ foldIndicatorWidth

int SidebarWidget::foldIndicatorWidth

Definition at line 437 of file jsedit.cpp.

Referenced by mousePressEvent(), and paintEvent().

◆ font

QFont SidebarWidget::font

Definition at line 436 of file jsedit.cpp.

Referenced by paintEvent().

◆ indicatorColor

QColor SidebarWidget::indicatorColor

Definition at line 434 of file jsedit.cpp.

Referenced by paintEvent(), and SidebarWidget().

◆ lineNumberColor

QColor SidebarWidget::lineNumberColor

Definition at line 433 of file jsedit.cpp.

Referenced by paintEvent(), and SidebarWidget().

◆ lineNumbers

QVector<BlockInfo> SidebarWidget::lineNumbers

Definition at line 431 of file jsedit.cpp.

Referenced by mousePressEvent(), and paintEvent().

◆ rightArrowIcon

QPixmap SidebarWidget::rightArrowIcon

Definition at line 438 of file jsedit.cpp.

Referenced by paintEvent().


The documentation for this class was generated from the following file:
SidebarWidget::foldIndicatorWidth
int foldIndicatorWidth
Definition: jsedit.cpp:437
BlockInfo::number
int number
Definition: jsedit.cpp:420
SidebarWidget::lineNumberColor
QColor lineNumberColor
Definition: jsedit.cpp:433
BlockInfo::position
int position
Definition: jsedit.cpp:419
BlockInfo
Definition: jsedit.cpp:418
BlockInfo::foldable
bool foldable
Definition: jsedit.cpp:421
SidebarWidget::font
QFont font
Definition: jsedit.cpp:436
JSEdit
Definition: jsedit.h:50
SidebarWidget::foldIndicatorColor
QColor foldIndicatorColor
Definition: jsedit.cpp:435
SidebarWidget::indicatorColor
QColor indicatorColor
Definition: jsedit.cpp:434
SidebarWidget::downArrowIcon
QPixmap downArrowIcon
Definition: jsedit.cpp:439
SidebarWidget::rightArrowIcon
QPixmap rightArrowIcon
Definition: jsedit.cpp:438
BlockInfo::folded
bool folded
Definition: jsedit.cpp:422
SidebarWidget::lineNumbers
QVector< BlockInfo > lineNumbers
Definition: jsedit.cpp:431
JSEdit::toggleFold
void toggleFold(int line)
Definition: jsedit.cpp:842
SidebarWidget::backgroundColor
QColor backgroundColor
Definition: jsedit.cpp:432