submiteditorwidget.h 5.25 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
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 12 13 14
** 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
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

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

33 34 35
#include "vcsbase_global.h"

#include <utils/completingtextedit.h>
con's avatar
con committed
36

37 38
#include <QWidget>
#include <QAbstractItemView>
con's avatar
con committed
39 40 41

QT_BEGIN_NAMESPACE
class QAction;
42
class QModelIndex;
con's avatar
con committed
43 44
QT_END_NAMESPACE

45
namespace VcsBase {
con's avatar
con committed
46

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

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

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

65 66 67
    // 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
68 69 70 71 72 73 74 75
    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);

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

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

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

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

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

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

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

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

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

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

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

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

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

protected:
123
    virtual QString cleanupDescription(const QString &) const;
124
    virtual QString commitName() const;
con's avatar
con committed
125
    void insertTopWidget(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;
con's avatar
con committed
147

hjk's avatar
hjk committed
148
    SubmitEditorWidgetPrivate *d;
con's avatar
con committed
149 150
};

151
} // namespace VcsBase
hjk's avatar
hjk committed
152

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