2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-03-10 11:21:56 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2010-03-10 11:21:56 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-03-10 11:21:56 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2010-03-10 11:21:56 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-03-10 11:21:56 +01:00
|
|
|
|
|
|
|
|
#include "commandmappings.h"
|
|
|
|
|
#include "commandsfile.h"
|
2014-02-14 19:45:35 +01:00
|
|
|
|
2013-08-29 16:36:42 +02:00
|
|
|
#include <coreplugin/dialogs/shortcutsettings.h>
|
2010-03-10 11:21:56 +01:00
|
|
|
|
2013-03-20 15:45:38 +01:00
|
|
|
#include <utils/headerviewstretcher.h>
|
2014-02-14 19:45:35 +01:00
|
|
|
#include <utils/fancylineedit.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
2010-03-10 11:21:56 +01:00
|
|
|
|
2012-08-06 13:42:46 +02:00
|
|
|
#include <QDebug>
|
2014-02-14 19:45:35 +01:00
|
|
|
#include <QGroupBox>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QPointer>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QTreeWidgetItem>
|
|
|
|
|
#include <QVBoxLayout>
|
2010-03-10 11:21:56 +01:00
|
|
|
|
2010-12-16 11:25:28 +01:00
|
|
|
Q_DECLARE_METATYPE(Core::Internal::ShortcutItem*)
|
2010-03-10 11:21:56 +01:00
|
|
|
|
2014-02-14 19:45:35 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class CommandMappingsPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CommandMappingsPrivate(CommandMappings *parent)
|
2015-04-27 12:29:55 +02:00
|
|
|
: q(parent)
|
2014-02-14 19:45:35 +01:00
|
|
|
{
|
2015-04-27 12:29:55 +02:00
|
|
|
groupBox = new QGroupBox(parent);
|
2014-02-14 19:45:35 +01:00
|
|
|
groupBox->setTitle(CommandMappings::tr("Command Mappings"));
|
|
|
|
|
|
|
|
|
|
filterEdit = new FancyLineEdit(groupBox);
|
|
|
|
|
filterEdit->setFiltering(true);
|
|
|
|
|
|
|
|
|
|
commandList = new QTreeWidget(groupBox);
|
|
|
|
|
commandList->setRootIsDecorated(false);
|
|
|
|
|
commandList->setUniformRowHeights(true);
|
|
|
|
|
commandList->setSortingEnabled(true);
|
|
|
|
|
commandList->setColumnCount(3);
|
|
|
|
|
|
|
|
|
|
QTreeWidgetItem *item = commandList->headerItem();
|
|
|
|
|
item->setText(2, CommandMappings::tr("Target"));
|
|
|
|
|
item->setText(1, CommandMappings::tr("Label"));
|
|
|
|
|
item->setText(0, CommandMappings::tr("Command"));
|
|
|
|
|
|
|
|
|
|
defaultButton = new QPushButton(CommandMappings::tr("Reset All"), groupBox);
|
2014-03-06 14:42:25 +01:00
|
|
|
defaultButton->setToolTip(CommandMappings::tr("Reset all to default."));
|
2014-02-14 19:45:35 +01:00
|
|
|
|
|
|
|
|
importButton = new QPushButton(CommandMappings::tr("Import..."), groupBox);
|
|
|
|
|
exportButton = new QPushButton(CommandMappings::tr("Export..."), groupBox);
|
|
|
|
|
|
|
|
|
|
QHBoxLayout *hboxLayout1 = new QHBoxLayout();
|
|
|
|
|
hboxLayout1->addWidget(defaultButton);
|
|
|
|
|
hboxLayout1->addStretch();
|
|
|
|
|
hboxLayout1->addWidget(importButton);
|
|
|
|
|
hboxLayout1->addWidget(exportButton);
|
|
|
|
|
|
|
|
|
|
QHBoxLayout *hboxLayout = new QHBoxLayout();
|
|
|
|
|
hboxLayout->addWidget(filterEdit);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *vboxLayout1 = new QVBoxLayout(groupBox);
|
|
|
|
|
vboxLayout1->addLayout(hboxLayout);
|
|
|
|
|
vboxLayout1->addWidget(commandList);
|
|
|
|
|
vboxLayout1->addLayout(hboxLayout1);
|
|
|
|
|
|
2015-04-27 12:29:55 +02:00
|
|
|
QVBoxLayout *vboxLayout = new QVBoxLayout(parent);
|
2014-02-14 19:45:35 +01:00
|
|
|
vboxLayout->addWidget(groupBox);
|
|
|
|
|
|
2015-04-27 12:29:55 +02:00
|
|
|
q->connect(exportButton, &QPushButton::clicked,
|
|
|
|
|
q, &CommandMappings::exportAction);
|
|
|
|
|
q->connect(importButton, &QPushButton::clicked,
|
|
|
|
|
q, &CommandMappings::importAction);
|
|
|
|
|
q->connect(defaultButton, &QPushButton::clicked,
|
|
|
|
|
q, &CommandMappings::defaultAction);
|
2014-02-14 19:45:35 +01:00
|
|
|
|
|
|
|
|
commandList->sortByColumn(0, Qt::AscendingOrder);
|
|
|
|
|
|
2015-04-27 12:29:55 +02:00
|
|
|
q->connect(filterEdit, &FancyLineEdit::textChanged,
|
|
|
|
|
q, &CommandMappings::filterChanged);
|
|
|
|
|
q->connect(commandList, &QTreeWidget::currentItemChanged,
|
2015-04-29 18:01:21 +02:00
|
|
|
q, &CommandMappings::currentCommandChanged);
|
2014-02-14 19:45:35 +01:00
|
|
|
|
|
|
|
|
new HeaderViewStretcher(commandList->header(), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CommandMappings *q;
|
|
|
|
|
|
|
|
|
|
QGroupBox *groupBox;
|
|
|
|
|
FancyLineEdit *filterEdit;
|
|
|
|
|
QTreeWidget *commandList;
|
|
|
|
|
QPushButton *defaultButton;
|
|
|
|
|
QPushButton *importButton;
|
|
|
|
|
QPushButton *exportButton;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
2010-03-10 11:21:56 +01:00
|
|
|
|
2015-04-27 12:29:55 +02:00
|
|
|
CommandMappings::CommandMappings(QWidget *parent)
|
|
|
|
|
: QWidget(parent), d(new Internal::CommandMappingsPrivate(this))
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-14 19:45:35 +01:00
|
|
|
CommandMappings::~CommandMappings()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
2010-03-10 11:21:56 +01:00
|
|
|
|
|
|
|
|
void CommandMappings::setImportExportEnabled(bool enabled)
|
|
|
|
|
{
|
2014-02-14 19:45:35 +01:00
|
|
|
d->importButton->setVisible(enabled);
|
|
|
|
|
d->exportButton->setVisible(enabled);
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTreeWidget *CommandMappings::commandList() const
|
|
|
|
|
{
|
2014-02-14 19:45:35 +01:00
|
|
|
return d->commandList;
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-12 08:51:56 +01:00
|
|
|
void CommandMappings::setPageTitle(const QString &s)
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
2014-02-14 19:45:35 +01:00
|
|
|
d->groupBox->setTitle(s);
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-12 08:51:56 +01:00
|
|
|
void CommandMappings::setTargetHeader(const QString &s)
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
2014-02-14 19:45:35 +01:00
|
|
|
d->commandList->setHeaderLabels(QStringList() << tr("Command") << tr("Label") << s);
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandMappings::filterChanged(const QString &f)
|
|
|
|
|
{
|
2014-02-14 19:45:35 +01:00
|
|
|
for (int i = 0; i < d->commandList->topLevelItemCount(); ++i) {
|
|
|
|
|
QTreeWidgetItem *item = d->commandList->topLevelItem(i);
|
2012-05-22 14:56:37 +02:00
|
|
|
filter(f, item);
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-22 14:56:37 +02:00
|
|
|
bool CommandMappings::filter(const QString &filterString, QTreeWidgetItem *item)
|
2010-03-10 11:21:56 +01:00
|
|
|
{
|
2012-05-22 14:56:37 +02:00
|
|
|
bool visible = filterString.isEmpty();
|
|
|
|
|
int columnCount = item->columnCount();
|
2015-04-27 15:39:09 +02:00
|
|
|
for (int i = 0; !visible && i < columnCount; ++i)
|
|
|
|
|
visible |= !filterColumn(filterString, item, i);
|
2012-05-22 14:56:37 +02:00
|
|
|
|
|
|
|
|
int childCount = item->childCount();
|
|
|
|
|
if (childCount > 0) {
|
|
|
|
|
// force visibility if this item matches
|
|
|
|
|
QString leafFilterString = visible ? QString() : filterString;
|
|
|
|
|
for (int i = 0; i < childCount; ++i) {
|
|
|
|
|
QTreeWidgetItem *citem = item->child(i);
|
|
|
|
|
visible |= !filter(leafFilterString, citem); // parent visible if any child visible
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
2012-05-22 14:56:37 +02:00
|
|
|
item->setHidden(!visible);
|
|
|
|
|
return !visible;
|
2010-03-10 11:21:56 +01:00
|
|
|
}
|
2010-03-29 14:42:46 +02:00
|
|
|
|
2015-04-27 15:39:09 +02:00
|
|
|
bool CommandMappings::filterColumn(const QString &filterString, QTreeWidgetItem *item,
|
|
|
|
|
int column) const
|
|
|
|
|
{
|
|
|
|
|
return !item->text(column).contains(filterString, Qt::CaseInsensitive);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-29 14:42:46 +02:00
|
|
|
void CommandMappings::setModified(QTreeWidgetItem *item , bool modified)
|
|
|
|
|
{
|
|
|
|
|
QFont f = item->font(0);
|
|
|
|
|
f.setItalic(modified);
|
|
|
|
|
item->setFont(0, f);
|
|
|
|
|
item->setFont(1, f);
|
|
|
|
|
f.setBold(modified);
|
|
|
|
|
item->setFont(2, f);
|
|
|
|
|
}
|
2010-12-06 17:21:03 +01:00
|
|
|
|
|
|
|
|
QString CommandMappings::filterText() const
|
|
|
|
|
{
|
2015-04-29 18:01:21 +02:00
|
|
|
return d->filterEdit->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandMappings::setFilterText(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
d->filterEdit->setText(text);
|
2010-12-06 17:21:03 +01:00
|
|
|
}
|
2014-02-14 19:45:35 +01:00
|
|
|
|
|
|
|
|
} // namespace Core
|