1 /****************************************************************************
2 **
3 ** Copyright (C) 2021 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 <annotation.h>
29 
30 #include <QWidget>
31 #include <QPointer>
32 
33 #include <memory>
34 
35 QT_BEGIN_NAMESPACE
36 class QDir;
37 QT_END_NAMESPACE
38 
39 namespace QmlDesigner {
40 
41 namespace Ui {
42 class AnnotationCommentTab;
43 }
44 
45 class RichTextEditor;
46 class DefaultAnnotationsModel;
47 
48 class AnnotationCommentTab : public QWidget
49 {
50     Q_OBJECT
51 
52 public:
53     explicit AnnotationCommentTab(QWidget *parent = nullptr);
54     ~AnnotationCommentTab();
55 
56     Comment currentComment() const;
57 
58     Comment originalComment() const;
59     void setComment(const Comment &comment);
60 
61     void resetUI();
62     void resetComment();
63 
64     DefaultAnnotationsModel *defaultAnnotations() const;
65     void setDefaultAnnotations(DefaultAnnotationsModel *);
66 
67 signals:
68     void titleChanged(const QString &text, QWidget *widget);
69 
70 private:
71     QString backupFile(const QString &filePath);
72     void ensureDir(const QDir &dir);
73     int compareFileChecksum(const QString &firstFile, const QString &secondFile);
74 
75 private:
76     std::unique_ptr<Ui::AnnotationCommentTab> ui;
77     RichTextEditor *m_editor;
78 
79     Comment m_comment;
80     QPointer<DefaultAnnotationsModel> m_defaults;
81 };
82 
83 } //namespace QmlDesigner
84