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 <QMap>
0010 #include <QWidget>
0011 #include <diff.h>
0012 
0013 #include "libkommitwidgets_export.h"
0014 
0015 class CodeEditor;
0016 class LIBKOMMITWIDGETS_EXPORT SegmentConnector : public QWidget
0017 {
0018     Q_OBJECT
0019 
0020 public:
0021     explicit SegmentConnector(QWidget *parent = nullptr);
0022     ~SegmentConnector() override;
0023 
0024     CodeEditor *left() const;
0025     void setLeft(CodeEditor *newLeft);
0026 
0027     CodeEditor *right() const;
0028     void setRight(CodeEditor *newRight);
0029 
0030     const QList<Diff::DiffSegment *> &segments() const;
0031     void setSegments(const QList<Diff::DiffSegment *> &newSegments);
0032 
0033     Diff::Segment *currentSegment() const;
0034     void setCurrentSegment(Diff::Segment *newCurrentSegment);
0035 
0036     Q_REQUIRED_RESULT bool sameSize() const;
0037     void setSameSize(bool newSameSize);
0038 
0039     Q_REQUIRED_RESULT int topMargin() const;
0040     void setTopMargin(int newTopMargin);
0041 
0042 Q_SIGNALS:
0043     void sameSizeChanged();
0044     void segmentsChanged();
0045 
0046 protected:
0047     void paintEvent(QPaintEvent *event) override;
0048 
0049 private:
0050     CodeEditor *mLeft{nullptr};
0051     CodeEditor *mRight{nullptr};
0052     QList<Diff::DiffSegment *> mSegments;
0053     Diff::Segment *mCurrentSegment{nullptr};
0054     bool m_sameSize{false};
0055     int m_topMargin = 0;
0056     struct SegmentPos {
0057         int leftStart;
0058         int leftEnd;
0059         int rightStart;
0060         int rightEnd;
0061     };
0062 
0063     QMap<Diff::Segment *, SegmentPos> mSegmentPos;
0064 };