File indexing completed on 2025-01-05 05:14:51
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 "ui_diffwidget.h" 0010 0011 #include <QTextOption> 0012 #include <QWidget> 0013 #include <entities/file.h> 0014 0015 #include "libkommitwidgets_export.h" 0016 0017 class CodeEditor; 0018 class LIBKOMMITWIDGETS_EXPORT DiffWidget : public QWidget, private Ui::DiffWIdget 0019 { 0020 Q_OBJECT 0021 0022 Q_PROPERTY(bool sameSize READ sameSize WRITE setSameSize NOTIFY sameSizeChanged) 0023 0024 public: 0025 explicit DiffWidget(QWidget *parent = nullptr); 0026 DiffWidget(QSharedPointer<Git::File> oldFile, QSharedPointer<Git::File> newFile, QWidget *parent = nullptr); 0027 0028 QSharedPointer<Git::File> oldFile() const; 0029 void setOldFile(QSharedPointer<Git::File> newOldFile); 0030 QSharedPointer<Git::File> newFile() const; 0031 void setNewFile(QSharedPointer<Git::File> newNewFile); 0032 0033 void compare(); 0034 0035 CodeEditor *oldCodeEditor() const; 0036 0037 CodeEditor *newCodeEditor() const; 0038 0039 bool sameSize() const; 0040 void setSameSize(bool newSameSize); 0041 0042 void scrollToTop(); 0043 0044 void setOldFileText(const QString &newOldFile); 0045 void setNewFileText(const QString &newNewFile); 0046 0047 public Q_SLOTS: 0048 void showHiddenChars(bool show); 0049 void showFilesInfo(bool show); 0050 void showSameSize(bool show); 0051 0052 Q_SIGNALS: 0053 void sameSizeChanged(); 0054 0055 private Q_SLOTS: 0056 void slotSegmentsScrollbarHover(int y, double pos); 0057 void slotSplitterSplitterMoved(int, int); 0058 void oldCodeEditor_scroll(int value); 0059 void newCodeEditor_scroll(int value); 0060 void oldCodeEditor_blockSelected(); 0061 void newCodeEditor_blockSelected(); 0062 0063 protected: 0064 void resizeEvent(QResizeEvent *event) override; 0065 void showEvent(QShowEvent *event) override; 0066 0067 private: 0068 constexpr static int mPreviewWidgetHeight{160}; 0069 QWidget *mPreviewWidget = nullptr; 0070 int mPreviewMargin{0}; 0071 CodeEditor *mPreviewEditorLeft = nullptr; 0072 CodeEditor *mPreviewEditorRight = nullptr; 0073 bool mSameSize{false}; 0074 QSharedPointer<Git::File> mOldFile; 0075 QSharedPointer<Git::File> mNewFile; 0076 0077 QTextOption mDefaultOption; 0078 0079 void recalculateInfoPaneSize(); 0080 void init(); 0081 void createPreviewWidget(); 0082 };