1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef SUBMITEDITORWIDGET_H
35 #define SUBMITEDITORWIDGET_H
37 #include "utils_global.h"
39 #include <QtGui/QWidget>
40 #include <QtGui/QAbstractItemView>
44 class QListWidgetItem;
46 class QAbstractItemModel;
53 class SubmitFieldWidget;
54 struct SubmitEditorWidgetPrivate;
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().
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().
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
71 * Care should be taken to ensure the widget is deleted properly when the
74 class QTCREATOR_UTILS_EXPORT SubmitEditorWidget : public QWidget
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)
86 explicit SubmitEditorWidget(QWidget *parent = 0);
87 virtual ~SubmitEditorWidget();
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
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);
97 QString descriptionText() const;
98 void setDescriptionText(const QString &text);
100 // 'Commit' action enabled despite empty file list
101 bool isEmptyFileListEnabled() const;
102 void setEmptyFileListEnabled(bool e);
104 int fileNameColumn() const;
105 void setFileNameColumn(int c);
107 bool lineWrap() const;
108 void setLineWrap(bool);
110 int lineWrapWidth() const;
111 void setLineWrapWidth(int);
113 QAbstractItemView::SelectionMode fileListSelectionMode() const;
114 void setFileListSelectionMode(QAbstractItemView::SelectionMode sm);
116 void setFileModel(QAbstractItemModel *model);
117 QAbstractItemModel *fileModel() const;
119 // Files to be included in submit
120 QStringList checkedFiles() const;
122 // Selected files for diff
123 QStringList selectedFiles() const;
125 QTextEdit *descriptionEdit() const;
127 void addDescriptionEditContextMenuAction(QAction *a);
128 void insertDescriptionEditContextMenuAction(int pos, QAction *a);
130 void addSubmitFieldWidget(SubmitFieldWidget *f);
131 QList<SubmitFieldWidget *> submitFieldWidgets() const;
133 virtual bool canSubmit() const;
136 void diffSelected(const QStringList &);
137 void fileSelectionChanged(bool someFileSelected);
138 void submitActionTextChanged(const QString &);
139 void submitActionEnabledChanged(const bool);
146 virtual QString cleanupDescription(const QString &) const;
147 virtual void changeEvent(QEvent *e);
148 void insertTopWidget(QWidget *w);
151 void updateSubmitAction();
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);
163 bool hasSelection() const;
164 unsigned checkedFilesCount() const;
166 SubmitEditorWidgetPrivate *m_d;
171 #endif // SUBMITEDITORWIDGET_H