2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at qt-sales@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "submiteditorwidget.h"
|
|
|
|
|
#include "ui_submiteditorwidget.h"
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
#include <QtCore/QPointer>
|
2009-01-12 17:44:04 +01:00
|
|
|
#include <QtCore/QTimer>
|
2009-03-19 17:40:01 +01:00
|
|
|
#include <QtCore/QSignalMapper>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2008-12-02 17:05:53 +01:00
|
|
|
#include <QtGui/QPushButton>
|
2009-03-19 17:40:01 +01:00
|
|
|
#include <QtGui/QMenu>
|
|
|
|
|
#include <QtGui/QLineEdit>
|
|
|
|
|
#include <QtGui/QFormLayout>
|
|
|
|
|
#include <QtGui/QHBoxLayout>
|
|
|
|
|
#include <QtGui/QToolButton>
|
|
|
|
|
#include <QtGui/QSpacerItem>
|
2008-12-02 17:05:53 +01:00
|
|
|
|
2008-12-02 14:09:21 +01:00
|
|
|
enum { debug = 0 };
|
2009-03-20 14:20:28 +01:00
|
|
|
enum { defaultLineWidth = 72 };
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
namespace Utils {
|
|
|
|
|
|
2008-12-02 17:05:53 +01:00
|
|
|
// QActionPushButton: A push button tied to an action
|
|
|
|
|
// (similar to a QToolButton)
|
2008-12-09 11:07:24 +01:00
|
|
|
class QActionPushButton : public QPushButton
|
|
|
|
|
{
|
2008-12-02 17:05:53 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
explicit QActionPushButton(QAction *a);
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void actionChanged();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QActionPushButton::QActionPushButton(QAction *a) :
|
|
|
|
|
QPushButton(a->icon(), a->text())
|
|
|
|
|
{
|
|
|
|
|
connect(a, SIGNAL(changed()), this, SLOT(actionChanged()));
|
|
|
|
|
connect(this, SIGNAL(clicked()), a, SLOT(trigger()));
|
|
|
|
|
setEnabled(a->isEnabled());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QActionPushButton::actionChanged()
|
|
|
|
|
{
|
|
|
|
|
if (const QAction *a = qobject_cast<QAction*>(sender()))
|
|
|
|
|
setEnabled(a->isEnabled());
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-12 17:44:04 +01:00
|
|
|
// Helpers to retrieve model data
|
|
|
|
|
static inline bool listModelChecked(const QAbstractItemModel *model, int row, int column = 0)
|
|
|
|
|
{
|
|
|
|
|
const QModelIndex checkableIndex = model->index(row, column, QModelIndex());
|
|
|
|
|
return model->data(checkableIndex, Qt::CheckStateRole).toInt() == Qt::Checked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline QString listModelText(const QAbstractItemModel *model, int row, int column)
|
|
|
|
|
{
|
|
|
|
|
const QModelIndex index = model->index(row, column, QModelIndex());
|
|
|
|
|
return model->data(index, Qt::DisplayRole).toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find a check item in a model
|
|
|
|
|
static bool listModelContainsCheckedItem(const QAbstractItemModel *model)
|
|
|
|
|
{
|
|
|
|
|
const int count = model->rowCount();
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
if (listModelChecked(model, i, 0))
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convenience to extract a list of selected indexes
|
|
|
|
|
QList<int> selectedRows(const QAbstractItemView *view)
|
|
|
|
|
{
|
|
|
|
|
const QModelIndexList indexList = view->selectionModel()->selectedRows(0);
|
|
|
|
|
if (indexList.empty())
|
|
|
|
|
return QList<int>();
|
|
|
|
|
QList<int> rc;
|
|
|
|
|
const QModelIndexList::const_iterator cend = indexList.constEnd();
|
|
|
|
|
for (QModelIndexList::const_iterator it = indexList.constBegin(); it != cend; ++it)
|
|
|
|
|
rc.push_back(it->row());
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 17:05:53 +01:00
|
|
|
// ----------- SubmitEditorWidgetPrivate
|
2009-03-19 17:40:01 +01:00
|
|
|
|
2008-12-02 14:09:21 +01:00
|
|
|
struct SubmitEditorWidgetPrivate
|
|
|
|
|
{
|
2009-03-19 17:40:01 +01:00
|
|
|
// A pair of position/action to extend context menus
|
|
|
|
|
typedef QPair<int, QPointer<QAction> > AdditionalContextMenuAction;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
SubmitEditorWidgetPrivate();
|
|
|
|
|
|
|
|
|
|
Ui::SubmitEditorWidget m_ui;
|
|
|
|
|
bool m_filesSelected;
|
|
|
|
|
bool m_filesChecked;
|
2009-01-12 17:44:04 +01:00
|
|
|
int m_fileNameColumn;
|
|
|
|
|
int m_activatedRow;
|
2009-03-19 17:40:01 +01:00
|
|
|
|
|
|
|
|
QList<AdditionalContextMenuAction> descriptionEditContextMenuActions;
|
|
|
|
|
QFormLayout *m_fieldLayout;
|
|
|
|
|
// Field entries (label, line edits)
|
|
|
|
|
typedef QPair<QString, QLineEdit*> FieldEntry;
|
|
|
|
|
QList<FieldEntry> m_fieldEntries;
|
|
|
|
|
QSignalMapper *m_fieldSignalMapper;
|
2009-03-20 14:20:28 +01:00
|
|
|
int m_lineWidth;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SubmitEditorWidgetPrivate::SubmitEditorWidgetPrivate() :
|
|
|
|
|
m_filesSelected(false),
|
2009-01-12 17:44:04 +01:00
|
|
|
m_filesChecked(false),
|
|
|
|
|
m_fileNameColumn(1),
|
2009-03-19 17:40:01 +01:00
|
|
|
m_activatedRow(-1),
|
|
|
|
|
m_fieldLayout(0),
|
2009-03-20 14:20:28 +01:00
|
|
|
m_fieldSignalMapper(0),
|
|
|
|
|
m_lineWidth(defaultLineWidth)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SubmitEditorWidget::SubmitEditorWidget(QWidget *parent) :
|
|
|
|
|
QWidget(parent),
|
|
|
|
|
m_d(new SubmitEditorWidgetPrivate)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_ui.setupUi(this);
|
2009-03-19 17:40:01 +01:00
|
|
|
m_d->m_ui.description->setContextMenuPolicy(Qt::CustomContextMenu);
|
2009-03-20 14:20:28 +01:00
|
|
|
m_d->m_ui.description->setLineWrapMode(QTextEdit::NoWrap);
|
2009-03-19 17:40:01 +01:00
|
|
|
connect(m_d->m_ui.description, SIGNAL(customContextMenuRequested(QPoint)),
|
|
|
|
|
this, SLOT(editorCustomContextMenuRequested(QPoint)));
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// File List
|
2009-01-12 17:44:04 +01:00
|
|
|
m_d->m_ui.fileView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
|
|
|
m_d->m_ui.fileView->setRootIsDecorated(false);
|
|
|
|
|
connect(m_d->m_ui.fileView, SIGNAL(doubleClicked(QModelIndex)),
|
|
|
|
|
this, SLOT(diffActivated(QModelIndex)));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Text
|
|
|
|
|
m_d->m_ui.description->setFont(QFont(QLatin1String("Courier")));
|
|
|
|
|
|
|
|
|
|
setFocusPolicy(Qt::StrongFocus);
|
|
|
|
|
setFocusProxy(m_d->m_ui.description);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SubmitEditorWidget::~SubmitEditorWidget()
|
|
|
|
|
{
|
|
|
|
|
delete m_d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SubmitEditorWidget::registerActions(QAction *editorUndoAction, QAction *editorRedoAction,
|
|
|
|
|
QAction *submitAction, QAction *diffAction)
|
|
|
|
|
{
|
|
|
|
|
if (editorUndoAction) {
|
|
|
|
|
editorUndoAction->setEnabled(m_d->m_ui.description->document()->isUndoAvailable());
|
|
|
|
|
connect(m_d->m_ui.description, SIGNAL(undoAvailable(bool)), editorUndoAction, SLOT(setEnabled(bool)));
|
|
|
|
|
connect(editorUndoAction, SIGNAL(triggered()), m_d->m_ui.description, SLOT(undo()));
|
|
|
|
|
}
|
|
|
|
|
if (editorRedoAction) {
|
|
|
|
|
editorRedoAction->setEnabled(m_d->m_ui.description->document()->isRedoAvailable());
|
|
|
|
|
connect(m_d->m_ui.description, SIGNAL(redoAvailable(bool)), editorRedoAction, SLOT(setEnabled(bool)));
|
|
|
|
|
connect(editorRedoAction, SIGNAL(triggered()), m_d->m_ui.description, SLOT(redo()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (submitAction) {
|
2009-01-12 17:44:04 +01:00
|
|
|
if (debug) {
|
|
|
|
|
int count = 0;
|
|
|
|
|
if (const QAbstractItemModel *model = m_d->m_ui.fileView->model())
|
|
|
|
|
count = model->rowCount();
|
2009-03-20 14:20:28 +01:00
|
|
|
qDebug() << Q_FUNC_INFO << submitAction << count << "items" << m_d->m_filesChecked;
|
2009-01-12 17:44:04 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
submitAction->setEnabled(m_d->m_filesChecked);
|
|
|
|
|
connect(this, SIGNAL(fileCheckStateChanged(bool)), submitAction, SLOT(setEnabled(bool)));
|
2008-12-02 17:05:53 +01:00
|
|
|
m_d->m_ui.buttonLayout->addWidget(new QActionPushButton(submitAction));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
if (diffAction) {
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << diffAction << m_d->m_filesSelected;
|
2008-12-02 17:05:53 +01:00
|
|
|
diffAction->setEnabled(m_d->m_filesSelected);
|
|
|
|
|
connect(this, SIGNAL(fileSelectionChanged(bool)), diffAction, SLOT(setEnabled(bool)));
|
|
|
|
|
connect(diffAction, SIGNAL(triggered()), this, SLOT(triggerDiffSelected()));
|
|
|
|
|
m_d->m_ui.buttonLayout->addWidget(new QActionPushButton(diffAction));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SubmitEditorWidget::unregisterActions(QAction *editorUndoAction, QAction *editorRedoAction,
|
|
|
|
|
QAction *submitAction, QAction *diffAction)
|
|
|
|
|
{
|
|
|
|
|
if (editorUndoAction) {
|
|
|
|
|
disconnect(m_d->m_ui.description, SIGNAL(undoAvailableChanged(bool)), editorUndoAction, SLOT(setEnabled(bool)));
|
|
|
|
|
disconnect(editorUndoAction, SIGNAL(triggered()), m_d->m_ui.description, SLOT(undo()));
|
|
|
|
|
}
|
|
|
|
|
if (editorRedoAction) {
|
|
|
|
|
disconnect(m_d->m_ui.description, SIGNAL(redoAvailableChanged(bool)), editorRedoAction, SLOT(setEnabled(bool)));
|
|
|
|
|
disconnect(editorRedoAction, SIGNAL(triggered()), m_d->m_ui.description, SLOT(redo()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (submitAction)
|
|
|
|
|
disconnect(this, SIGNAL(fileCheckStateChanged(bool)), submitAction, SLOT(setEnabled(bool)));
|
|
|
|
|
|
|
|
|
|
if (diffAction) {
|
|
|
|
|
disconnect(this, SIGNAL(fileSelectionChanged(bool)), diffAction, SLOT(setEnabled(bool)));
|
|
|
|
|
disconnect(diffAction, SIGNAL(triggered()), this, SLOT(triggerDiffSelected()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SubmitEditorWidget::trimmedDescriptionText() const
|
|
|
|
|
{
|
|
|
|
|
// Make sure we have one terminating NL
|
|
|
|
|
QString text = descriptionText().trimmed();
|
|
|
|
|
text += QLatin1Char('\n');
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SubmitEditorWidget::descriptionText() const
|
|
|
|
|
{
|
2009-03-19 17:40:01 +01:00
|
|
|
QString rc = m_d->m_ui.description->toPlainText();
|
|
|
|
|
// append field entries
|
|
|
|
|
foreach(const SubmitEditorWidgetPrivate::FieldEntry &fe, m_d->m_fieldEntries) {
|
|
|
|
|
const QString fieldText = fe.second->text().trimmed();
|
|
|
|
|
if (!fieldText.isEmpty()) {
|
|
|
|
|
rc += fe.first;
|
|
|
|
|
rc += QLatin1Char(' ');
|
|
|
|
|
rc += fieldText;
|
|
|
|
|
rc += QLatin1Char('\n');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return rc;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SubmitEditorWidget::setDescriptionText(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_ui.description->setPlainText(text);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-20 14:20:28 +01:00
|
|
|
bool SubmitEditorWidget::lineWrap() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_ui.description->lineWrapMode() != QTextEdit::NoWrap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SubmitEditorWidget::setLineWrap(bool v)
|
|
|
|
|
{
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << v;
|
|
|
|
|
if (v) {
|
|
|
|
|
m_d->m_ui.description->setLineWrapColumnOrWidth(m_d->m_lineWidth);
|
|
|
|
|
m_d->m_ui.description->setLineWrapMode(QTextEdit::FixedColumnWidth);
|
|
|
|
|
} else {
|
|
|
|
|
m_d->m_ui.description->setLineWrapMode(QTextEdit::NoWrap);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SubmitEditorWidget::lineWrapWidth() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_lineWidth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SubmitEditorWidget::setLineWrapWidth(int v)
|
|
|
|
|
{
|
|
|
|
|
if (debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << v << lineWrap();
|
|
|
|
|
if (m_d->m_lineWidth == v)
|
|
|
|
|
return;
|
|
|
|
|
m_d->m_lineWidth = v;
|
|
|
|
|
if (lineWrap())
|
|
|
|
|
m_d->m_ui.description->setLineWrapColumnOrWidth(v);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-12 17:44:04 +01:00
|
|
|
int SubmitEditorWidget::fileNameColumn() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-12 17:44:04 +01:00
|
|
|
return m_d->m_fileNameColumn;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-12 17:44:04 +01:00
|
|
|
void SubmitEditorWidget::setFileNameColumn(int c)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-12 17:44:04 +01:00
|
|
|
m_d->m_fileNameColumn = c;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-13 10:06:06 +01:00
|
|
|
QAbstractItemView::SelectionMode SubmitEditorWidget::fileListSelectionMode() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_ui.fileView->selectionMode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SubmitEditorWidget::setFileListSelectionMode(QAbstractItemView::SelectionMode sm)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_ui.fileView->setSelectionMode(sm);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-12 17:44:04 +01:00
|
|
|
void SubmitEditorWidget::setFileModel(QAbstractItemModel *model)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-12 17:44:04 +01:00
|
|
|
m_d->m_ui.fileView->clearSelection(); // trigger the change signals
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-12 17:44:04 +01:00
|
|
|
m_d->m_ui.fileView->setModel(model);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-12 17:44:04 +01:00
|
|
|
if (model->rowCount()) {
|
|
|
|
|
const int columnCount = model->columnCount();
|
|
|
|
|
for (int c = 0; c < columnCount; c++)
|
|
|
|
|
m_d->m_ui.fileView->resizeColumnToContents(c);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-01-12 17:44:04 +01:00
|
|
|
|
|
|
|
|
connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
|
|
|
this, SLOT(updateSubmitAction()));
|
|
|
|
|
connect(model, SIGNAL(modelReset()),
|
|
|
|
|
this, SLOT(updateSubmitAction()));
|
|
|
|
|
connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
|
|
|
|
|
this, SLOT(updateSubmitAction()));
|
|
|
|
|
connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
|
|
|
|
|
this, SLOT(updateSubmitAction()));
|
|
|
|
|
connect(m_d->m_ui.fileView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
|
|
|
|
|
this, SLOT(updateDiffAction()));
|
|
|
|
|
updateActions();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-12 17:44:04 +01:00
|
|
|
QAbstractItemModel *SubmitEditorWidget::fileModel() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-12 17:44:04 +01:00
|
|
|
return m_d->m_ui.fileView->model();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList SubmitEditorWidget::selectedFiles() const
|
|
|
|
|
{
|
2009-01-12 17:44:04 +01:00
|
|
|
const QList<int> selection = selectedRows(m_d->m_ui.fileView);
|
|
|
|
|
if (selection.empty())
|
|
|
|
|
return QStringList();
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QStringList rc;
|
2009-01-12 17:44:04 +01:00
|
|
|
const QAbstractItemModel *model = m_d->m_ui.fileView->model();
|
|
|
|
|
const int count = selection.size();
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
rc.push_back(listModelText(model, selection.at(i), fileNameColumn()));
|
2008-12-02 12:01:29 +01:00
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList SubmitEditorWidget::checkedFiles() const
|
|
|
|
|
{
|
|
|
|
|
QStringList rc;
|
2009-01-12 17:44:04 +01:00
|
|
|
const QAbstractItemModel *model = m_d->m_ui.fileView->model();
|
|
|
|
|
if (!model)
|
|
|
|
|
return rc;
|
|
|
|
|
const int count = model->rowCount();
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
if (listModelChecked(model, i, 0))
|
|
|
|
|
rc.push_back(listModelText(model, i, fileNameColumn()));
|
2008-12-02 12:01:29 +01:00
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-20 14:20:28 +01:00
|
|
|
QTextEdit *SubmitEditorWidget::descriptionEdit() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_d->m_ui.description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SubmitEditorWidget::triggerDiffSelected()
|
|
|
|
|
{
|
|
|
|
|
const QStringList sel = selectedFiles();
|
|
|
|
|
if (!sel.empty())
|
|
|
|
|
emit diffSelected(sel);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-12 17:44:04 +01:00
|
|
|
void SubmitEditorWidget::diffActivatedDelayed()
|
|
|
|
|
{
|
|
|
|
|
const QStringList files = QStringList(listModelText(m_d->m_ui.fileView->model(), m_d->m_activatedRow, fileNameColumn()));
|
|
|
|
|
emit diffSelected(files);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SubmitEditorWidget::diffActivated(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
// We need to delay the signal, otherwise, the diff editor will not
|
|
|
|
|
// be in the foreground.
|
|
|
|
|
m_d->m_activatedRow = index.row();
|
|
|
|
|
QTimer::singleShot(0, this, SLOT(diffActivatedDelayed()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SubmitEditorWidget::updateActions()
|
|
|
|
|
{
|
|
|
|
|
updateSubmitAction();
|
|
|
|
|
updateDiffAction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Enable submit depending on having checked files
|
|
|
|
|
void SubmitEditorWidget::updateSubmitAction()
|
|
|
|
|
{
|
|
|
|
|
const bool newFilesCheckedState = hasCheckedFiles();
|
|
|
|
|
if (m_d->m_filesChecked != newFilesCheckedState) {
|
|
|
|
|
m_d->m_filesChecked = newFilesCheckedState;
|
|
|
|
|
emit fileCheckStateChanged(m_d->m_filesChecked);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-12 17:44:04 +01:00
|
|
|
// Enable diff depending on selected files
|
|
|
|
|
void SubmitEditorWidget::updateDiffAction()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-12 17:44:04 +01:00
|
|
|
const bool filesSelected = hasSelection();
|
|
|
|
|
if (m_d->m_filesSelected != filesSelected) {
|
|
|
|
|
m_d->m_filesSelected = filesSelected;
|
2008-12-02 12:01:29 +01:00
|
|
|
emit fileSelectionChanged(m_d->m_filesSelected);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-12 17:44:04 +01:00
|
|
|
bool SubmitEditorWidget::hasSelection() const
|
|
|
|
|
{
|
|
|
|
|
// Not present until model is set
|
|
|
|
|
if (const QItemSelectionModel *sm = m_d->m_ui.fileView->selectionModel())
|
|
|
|
|
return sm->hasSelection();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SubmitEditorWidget::hasCheckedFiles() const
|
|
|
|
|
{
|
|
|
|
|
if (const QAbstractItemModel *model = m_d->m_ui.fileView->model())
|
|
|
|
|
return listModelContainsCheckedItem(model);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void SubmitEditorWidget::changeEvent(QEvent *e)
|
|
|
|
|
{
|
2009-03-17 14:34:27 +01:00
|
|
|
QWidget::changeEvent(e);
|
2008-12-09 11:07:24 +01:00
|
|
|
switch (e->type()) {
|
2008-12-02 12:01:29 +01:00
|
|
|
case QEvent::LanguageChange:
|
|
|
|
|
m_d->m_ui.retranslateUi(this);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SubmitEditorWidget::insertTopWidget(QWidget *w)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_ui.vboxLayout->insertWidget(0, w);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-19 17:40:01 +01:00
|
|
|
void SubmitEditorWidget::addDescriptionEditContextMenuAction(QAction *a)
|
|
|
|
|
{
|
|
|
|
|
m_d->descriptionEditContextMenuActions.push_back(SubmitEditorWidgetPrivate::AdditionalContextMenuAction(-1, a));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SubmitEditorWidget::insertDescriptionEditContextMenuAction(int pos, QAction *a)
|
|
|
|
|
{
|
|
|
|
|
m_d->descriptionEditContextMenuActions.push_back(SubmitEditorWidgetPrivate::AdditionalContextMenuAction(pos, a));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SubmitEditorWidget::editorCustomContextMenuRequested(const QPoint &pos)
|
|
|
|
|
{
|
|
|
|
|
QMenu *menu = m_d->m_ui.description->createStandardContextMenu();
|
|
|
|
|
// Extend
|
|
|
|
|
foreach (const SubmitEditorWidgetPrivate::AdditionalContextMenuAction &a, m_d->descriptionEditContextMenuActions) {
|
|
|
|
|
if (a.second) {
|
|
|
|
|
if (a.first >= 0) {
|
|
|
|
|
menu->insertAction(menu->actions().at(a.first), a.second);
|
|
|
|
|
} else {
|
|
|
|
|
menu->addAction(a.second);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
menu->exec(m_d->m_ui.description->mapToGlobal(pos));
|
|
|
|
|
delete menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLineEdit *SubmitEditorWidget::addField(const QString &label, bool hasDialogButton)
|
|
|
|
|
{
|
|
|
|
|
// Insert the form layout below the editor
|
|
|
|
|
if (!m_d->m_fieldLayout) {
|
|
|
|
|
QHBoxLayout *outerLayout = new QHBoxLayout;
|
|
|
|
|
m_d->m_fieldLayout = new QFormLayout;
|
|
|
|
|
outerLayout->addLayout(m_d->m_fieldLayout);
|
|
|
|
|
outerLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored));
|
|
|
|
|
QBoxLayout *descrLayout = qobject_cast<QBoxLayout*>(m_d->m_ui.descriptionBox->layout());
|
|
|
|
|
Q_ASSERT(descrLayout);
|
|
|
|
|
descrLayout->addLayout(outerLayout);
|
|
|
|
|
}
|
|
|
|
|
if (hasDialogButton && !m_d->m_fieldSignalMapper) {
|
|
|
|
|
m_d->m_fieldSignalMapper = new QSignalMapper;
|
|
|
|
|
connect(m_d->m_fieldSignalMapper, SIGNAL(mapped(int)), this, SIGNAL(fieldDialogRequested(int)));
|
|
|
|
|
}
|
|
|
|
|
// Add a field row consisting of label and line edit
|
|
|
|
|
QLineEdit *lineEdit = new QLineEdit;
|
|
|
|
|
QHBoxLayout *fieldLayout = new QHBoxLayout;
|
|
|
|
|
fieldLayout->addWidget(lineEdit);
|
|
|
|
|
if (hasDialogButton) {
|
|
|
|
|
QToolButton *dialogButton = new QToolButton;
|
|
|
|
|
dialogButton->setText(tr("..."));
|
|
|
|
|
connect(dialogButton, SIGNAL(clicked()), m_d->m_fieldSignalMapper, SLOT(map()));
|
|
|
|
|
m_d->m_fieldSignalMapper->setMapping(dialogButton, m_d->m_fieldEntries.size());
|
|
|
|
|
fieldLayout->addWidget(dialogButton);
|
|
|
|
|
}
|
|
|
|
|
QToolButton *clearButton = new QToolButton;
|
|
|
|
|
clearButton->setText(tr("Clear"));
|
|
|
|
|
connect(clearButton, SIGNAL(clicked()), lineEdit, SLOT(clear()));
|
|
|
|
|
fieldLayout->addWidget(clearButton);
|
|
|
|
|
m_d->m_fieldLayout->addRow(label, fieldLayout);
|
|
|
|
|
m_d->m_fieldEntries.push_back(SubmitEditorWidgetPrivate::FieldEntry(label, lineEdit));
|
|
|
|
|
return lineEdit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLineEdit *SubmitEditorWidget::fieldLineEdit(int i) const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_fieldEntries.at(i).second;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
} // namespace Utils
|
|
|
|
|
} // namespace Core
|
2008-12-02 17:05:53 +01:00
|
|
|
|
|
|
|
|
#include "submiteditorwidget.moc"
|