1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #pragma once
27 
28 #include <utils/id.h>
29 
30 #include <QIcon>
31 #include <QString>
32 #include <QObject>
33 
QT_FORWARD_DECLARE_CLASS(QWidget)34 QT_FORWARD_DECLARE_CLASS(QWidget)
35 
36 namespace TextEditor { class TextEditorWidget; }
37 
38 namespace DiffEditor {
39 
40 class FileData;
41 
42 namespace Internal {
43 
44 class DiffEditorDocument;
45 class SideBySideDiffEditorWidget;
46 class UnifiedDiffEditorWidget;
47 
48 class IDiffView : public QObject
49 {
50     Q_OBJECT
51 
52 public:
53     explicit IDiffView(QObject *parent = nullptr);
54 
55     QIcon icon() const;
56     QString toolTip() const;
57     bool supportsSync() const;
58     QString syncToolTip() const;
59 
60     Utils::Id id() const;
61     virtual QWidget *widget() = 0;
62     virtual void setDocument(DiffEditorDocument *document) = 0;
63 
64     virtual void beginOperation() = 0;
65     virtual void setCurrentDiffFileIndex(int index) = 0;
66     virtual void setDiff(const QList<FileData> &diffFileList, const QString &workingDirectory) = 0;
67     virtual void endOperation(bool success) = 0;
68 
69     virtual void setSync(bool) = 0;
70 
71 signals:
72     void currentDiffFileIndexChanged(int index);
73 
74 protected:
75     void setIcon(const QIcon &icon);
76     void setToolTip(const QString &toolTip);
77     void setId(const Utils::Id &id);
78     void setSupportsSync(bool sync);
79     void setSyncToolTip(const QString &text);
80 
81 private:
82     QIcon m_icon;
83     QString m_toolTip;
84     Utils::Id m_id;
85     bool m_supportsSync = false;
86     QString m_syncToolTip;
87 };
88 
89 class UnifiedView : public IDiffView
90 {
91     Q_OBJECT
92 
93 public:
94     UnifiedView();
95 
96     QWidget *widget() override;
97     TextEditor::TextEditorWidget *textEditorWidget();
98 
99     void setDocument(DiffEditorDocument *document) override;
100 
101     void beginOperation() override;
102     void setCurrentDiffFileIndex(int index) override;
103     void setDiff(const QList<FileData> &diffFileList, const QString &workingDirectory) override;
104     void endOperation(bool success) override;
105 
106     void setSync(bool sync) override;
107 
108 private:
109     UnifiedDiffEditorWidget *m_widget = nullptr;
110 };
111 
112 class SideBySideView : public IDiffView
113 {
114     Q_OBJECT
115 
116 public:
117     SideBySideView();
118 
119     QWidget *widget() override;
120     TextEditor::TextEditorWidget *leftEditorWidget();
121     TextEditor::TextEditorWidget *rightEditorWidget();
122 
123     void setDocument(DiffEditorDocument *document) override;
124 
125     void beginOperation() override;
126     void setCurrentDiffFileIndex(int index) override;
127     void setDiff(const QList<FileData> &diffFileList, const QString &workingDirectory) override;
128     void endOperation(bool success) override;
129 
130     void setSync(bool sync) override;
131 
132 private:
133     SideBySideDiffEditorWidget *m_widget;
134 };
135 
136 } // namespace Internal
137 } // namespace DiffEditor
138