File indexing completed on 2025-01-05 05:14:52
0001 /* 0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QWidget> 0010 0011 #include "libkommitwidgets_export.h" 0012 0013 class SegmentConnector; 0014 class LIBKOMMITWIDGETS_EXPORT SegmentsScrollBar : public QWidget 0015 { 0016 Q_OBJECT 0017 public: 0018 explicit SegmentsScrollBar(QWidget *parent = nullptr); 0019 0020 SegmentConnector *segmentConnector() const; 0021 void setSegmentConnector(SegmentConnector *newSegmentConnector); 0022 0023 protected: 0024 void paintEvent(QPaintEvent *event) override; 0025 void mouseMoveEvent(QMouseEvent *event) override; 0026 void resizeEvent(QResizeEvent *event) override; 0027 0028 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0029 void enterEvent(QEvent *event) override; 0030 #else 0031 void enterEvent(QEnterEvent *event) override; 0032 #endif 0033 void leaveEvent(QEvent *event) override; 0034 0035 private Q_SLOTS: 0036 void reload(); 0037 0038 Q_SIGNALS: 0039 void hover(int y, double pos); 0040 void mouseEntered(); 0041 void mouseLeaved(); 0042 0043 private: 0044 enum Side { Left, Right }; 0045 0046 int leftCount{0}; 0047 int rightCount{0}; 0048 SegmentConnector *mSegmentConnector{nullptr}; 0049 QImage mSegmentsImage; 0050 0051 void generateSegmentsImage(); 0052 0053 inline void paintSection(QPainter &painter, SegmentsScrollBar::Side side, int from, int len, const QBrush &brush, bool drawRect = false); 0054 };