OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / libs / utils / submiteditorwidget.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef SUBMITEDITORWIDGET_H
35 #define SUBMITEDITORWIDGET_H
36
37 #include "utils_global.h"
38
39 #include <QtGui/QWidget>
40 #include <QtGui/QAbstractItemView>
41
42 QT_BEGIN_NAMESPACE
43 class QTextEdit;
44 class QListWidgetItem;
45 class QAction;
46 class QAbstractItemModel;
47 class QModelIndex;
48 class QLineEdit;
49 QT_END_NAMESPACE
50
51 namespace Utils {
52
53 class SubmitFieldWidget;
54 struct SubmitEditorWidgetPrivate;
55
56 /* The submit editor presents the commit message in a text editor and an
57  * checkable list of modified files in a list window. The user can delete
58  * files from the list by unchecking them or diff the selection
59  * by doubleclicking. A list model which contains the file in a column
60  * specified by fileNameColumn should be set using setFileModel().
61  *
62  * Additionally, standard creator actions  can be registered:
63  * Undo/redo will be set up to work with the description editor.
64  * Submit will be set up to be enabled according to checkstate.
65  * Diff will be set up to trigger diffSelected().
66  *
67  * Note that the actions are connected by signals; in the rare event that there
68  * are several instances of the SubmitEditorWidget belonging to the same
69  * context active, the actions must be registered/unregistered in the editor
70  * change event.
71  * Care should be taken to ensure the widget is deleted properly when the
72  * editor closes. */
73
74 class QTCREATOR_UTILS_EXPORT SubmitEditorWidget : public QWidget
75 {
76     Q_OBJECT
77     Q_DISABLE_COPY(SubmitEditorWidget)
78     Q_PROPERTY(QString descriptionText READ descriptionText WRITE setDescriptionText DESIGNABLE true)
79     Q_PROPERTY(int fileNameColumn READ fileNameColumn WRITE setFileNameColumn DESIGNABLE false)
80     Q_PROPERTY(QAbstractItemView::SelectionMode fileListSelectionMode READ fileListSelectionMode WRITE setFileListSelectionMode DESIGNABLE true)
81     Q_PROPERTY(bool lineWrap READ lineWrap WRITE setLineWrap DESIGNABLE true)
82     Q_PROPERTY(int lineWrapWidth READ lineWrapWidth WRITE setLineWrapWidth DESIGNABLE true)
83     Q_PROPERTY(bool emptyFileListEnabled READ isEmptyFileListEnabled WRITE setEmptyFileListEnabled DESIGNABLE true)
84
85 public:
86     explicit SubmitEditorWidget(QWidget *parent = 0);
87     virtual ~SubmitEditorWidget();
88
89     // Register/Unregister actions that are managed by ActionManager with this widget.
90     // The submit action should have Core::Command::CA_UpdateText set as its text will
91     // be updated.
92     void registerActions(QAction *editorUndoAction,  QAction *editorRedoAction,
93                          QAction *submitAction = 0, QAction *diffAction = 0);
94     void unregisterActions(QAction *editorUndoAction,  QAction *editorRedoAction,
95                            QAction *submitAction = 0, QAction *diffAction = 0);
96
97     QString descriptionText() const;
98     void setDescriptionText(const QString &text);
99
100     // 'Commit' action enabled despite empty file list
101     bool isEmptyFileListEnabled() const;
102     void setEmptyFileListEnabled(bool e);
103
104     int fileNameColumn() const;
105     void setFileNameColumn(int c);
106
107     bool lineWrap() const;
108     void setLineWrap(bool);
109
110     int lineWrapWidth() const;
111     void setLineWrapWidth(int);
112
113     QAbstractItemView::SelectionMode fileListSelectionMode() const;
114     void setFileListSelectionMode(QAbstractItemView::SelectionMode sm);
115
116     void setFileModel(QAbstractItemModel *model);
117     QAbstractItemModel *fileModel() const;
118
119     // Files to be included in submit
120     QStringList checkedFiles() const;
121
122     // Selected files for diff
123     QStringList selectedFiles() const;
124
125     QTextEdit *descriptionEdit() const;
126
127     void addDescriptionEditContextMenuAction(QAction *a);
128     void insertDescriptionEditContextMenuAction(int pos, QAction *a);
129
130     void addSubmitFieldWidget(SubmitFieldWidget *f);
131     QList<SubmitFieldWidget *> submitFieldWidgets() const;
132
133     virtual bool canSubmit() const;
134
135 signals:
136     void diffSelected(const QStringList &);
137     void fileSelectionChanged(bool someFileSelected);
138     void submitActionTextChanged(const QString &);
139     void submitActionEnabledChanged(const bool);
140
141 public slots:
142     void checkAll();
143     void uncheckAll();
144
145 protected:
146     virtual QString cleanupDescription(const QString &) const;
147     virtual void changeEvent(QEvent *e);
148     void insertTopWidget(QWidget *w);
149
150 protected slots:
151     void updateSubmitAction();
152
153 private slots:
154     void triggerDiffSelected();
155     void diffActivated(const QModelIndex &index);
156     void diffActivatedDelayed();
157     void updateActions();
158     void updateDiffAction();
159     void editorCustomContextMenuRequested(const QPoint &);
160     void fileListCustomContextMenuRequested(const QPoint & pos);
161
162 private:
163     bool hasSelection() const;
164     unsigned checkedFilesCount() const;
165
166     SubmitEditorWidgetPrivate *m_d;
167 };
168
169 } // namespace Utils
170
171 #endif // SUBMITEDITORWIDGET_H