submiteditorwidget.h 5.4 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
Eike Ziller's avatar
Eike Ziller committed
3
4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
Eike Ziller's avatar
Eike Ziller committed
12
13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18
19
20
21
22
23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25
26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
con's avatar
con committed
27
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
hjk's avatar
hjk committed
30

con's avatar
con committed
31
32
33
#ifndef SUBMITEDITORWIDGET_H
#define SUBMITEDITORWIDGET_H

34
35
#include "vcsbase_global.h"

36
#include <QAbstractItemView>
con's avatar
con committed
37
38
39

QT_BEGIN_NAMESPACE
class QAction;
40
class QModelIndex;
con's avatar
con committed
41
42
QT_END_NAMESPACE

43
namespace Utils { class CompletingTextEdit; }
44
namespace VcsBase {
con's avatar
con committed
45

46
class SubmitFieldWidget;
con's avatar
con committed
47
struct SubmitEditorWidgetPrivate;
48
class SubmitFileModel;
con's avatar
con committed
49

50
class VCSBASE_EXPORT SubmitEditorWidget : public QWidget
hjk's avatar
hjk committed
51
{
con's avatar
con committed
52
53
    Q_OBJECT
    Q_PROPERTY(QString descriptionText READ descriptionText WRITE setDescriptionText DESIGNABLE true)
54
    Q_PROPERTY(QAbstractItemView::SelectionMode fileListSelectionMode READ fileListSelectionMode WRITE setFileListSelectionMode DESIGNABLE true)
55
56
    Q_PROPERTY(bool lineWrap READ lineWrap WRITE setLineWrap DESIGNABLE true)
    Q_PROPERTY(int lineWrapWidth READ lineWrapWidth WRITE setLineWrapWidth DESIGNABLE true)
57
    Q_PROPERTY(bool descriptionMandatory READ isDescriptionMandatory WRITE setDescriptionMandatory DESIGNABLE false)
58
59
    Q_PROPERTY(bool emptyFileListEnabled READ isEmptyFileListEnabled WRITE setEmptyFileListEnabled DESIGNABLE true)

con's avatar
con committed
60
public:
61
62
    SubmitEditorWidget();
    ~SubmitEditorWidget();
con's avatar
con committed
63

64
65
66
    // Register/Unregister actions that are managed by ActionManager with this widget.
    // The submit action should have Core::Command::CA_UpdateText set as its text will
    // be updated.
con's avatar
con committed
67
68
69
70
71
72
73
74
    void registerActions(QAction *editorUndoAction,  QAction *editorRedoAction,
                         QAction *submitAction = 0, QAction *diffAction = 0);
    void unregisterActions(QAction *editorUndoAction,  QAction *editorRedoAction,
                           QAction *submitAction = 0, QAction *diffAction = 0);

    QString descriptionText() const;
    void setDescriptionText(const QString &text);

75
76
77
78
    // 'Commit' action enabled despite empty file list
    bool isEmptyFileListEnabled() const;
    void setEmptyFileListEnabled(bool e);

79
80
81
82
83
84
    bool lineWrap() const;
    void setLineWrap(bool);

    int lineWrapWidth() const;
    void setLineWrapWidth(int);

85
86
87
    bool isDescriptionMandatory() const;
    void setDescriptionMandatory(bool);

88
89
90
    QAbstractItemView::SelectionMode fileListSelectionMode() const;
    void setFileListSelectionMode(QAbstractItemView::SelectionMode sm);

91
92
    void setFileModel(SubmitFileModel *model);
    SubmitFileModel *fileModel() const;
con's avatar
con committed
93
94
95
96

    // Files to be included in submit
    QStringList checkedFiles() const;

97
    Utils::CompletingTextEdit *descriptionEdit() const;
con's avatar
con committed
98

99
100
101
    void addDescriptionEditContextMenuAction(QAction *a);
    void insertDescriptionEditContextMenuAction(int pos, QAction *a);

102
103
    void addSubmitFieldWidget(SubmitFieldWidget *f);
    QList<SubmitFieldWidget *> submitFieldWidgets() const;
104

105
    virtual bool canSubmit() const;
106
    void setUpdateInProgress(bool value);
107
    bool updateInProgress() const;
108

con's avatar
con committed
109
signals:
110
    void diffSelected(const QList<int> &);
con's avatar
con committed
111
    void fileSelectionChanged(bool someFileSelected);
112
    void submitActionTextChanged(const QString &);
Hugues Delorme's avatar
Hugues Delorme committed
113
    void submitActionEnabledChanged(bool);
114

dt's avatar
dt committed
115
116
117
private slots:
    void updateCheckAllComboBox();
    void checkAllToggled();
118
119
    void checkAll();
    void uncheckAll();
con's avatar
con committed
120
121

protected:
122
    virtual QString cleanupDescription(const QString &) const;
123
    virtual QString commitName() const;
con's avatar
con committed
124
    void insertTopWidget(QWidget *w);
125
    void insertLeftWidget(QWidget *w);
126
    void addSubmitButtonMenu(QMenu *menu);
127
    void hideDescription();
128
129

protected slots:
Yuchen Deng's avatar
Yuchen Deng committed
130
    void descriptionTextChanged();
131
132

public slots:
133
    void updateSubmitAction();
con's avatar
con committed
134
135
136

private slots:
    void triggerDiffSelected();
137
138
139
140
    void diffActivated(const QModelIndex &index);
    void diffActivatedDelayed();
    void updateActions();
    void updateDiffAction();
141
    void editorCustomContextMenuRequested(const QPoint &);
142
    void fileListCustomContextMenuRequested(const QPoint & pos);
con's avatar
con committed
143
144

private:
145
    bool hasSelection() const;
146
    int checkedFilesCount() const;
147
148
    void wrapDescription();
    void trimDescription();
con's avatar
con committed
149

hjk's avatar
hjk committed
150
    SubmitEditorWidgetPrivate *d;
con's avatar
con committed
151
152
};

153
} // namespace VcsBase
hjk's avatar
hjk committed
154

con's avatar
con committed
155
#endif // SUBMITEDITORWIDGET_H