submiteditorwidget.h 5.2 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 62 63 64
public:
    explicit SubmitEditorWidget(QWidget *parent = 0);
    virtual ~SubmitEditorWidget();

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 107
    virtual bool canSubmit() const;

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

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

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

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

private slots:
    void triggerDiffSelected();
133 134 135 136
    void diffActivated(const QModelIndex &index);
    void diffActivatedDelayed();
    void updateActions();
    void updateDiffAction();
137
    void editorCustomContextMenuRequested(const QPoint &);
138
    void fileListCustomContextMenuRequested(const QPoint & pos);
con's avatar
con committed
139 140

private:
141
    bool hasSelection() const;
142
    int checkedFilesCount() const;
con's avatar
con committed
143

hjk's avatar
hjk committed
144
    SubmitEditorWidgetPrivate *d;
con's avatar
con committed
145 146
};

147
} // namespace VcsBase
hjk's avatar
hjk committed
148

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