1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "commandmappings.h"
34 #include "ui_commandmappings.h"
35 #include "actionmanager_p.h"
36 #include "actionmanager/command.h"
37 #include "command_p.h"
38 #include "commandsfile.h"
39 #include "coreconstants.h"
40 #include "filemanager.h"
42 #include "uniqueidmanager.h"
44 #include <utils/treewidgetcolumnstretcher.h>
46 #include <QtGui/QKeyEvent>
47 #include <QtGui/QShortcut>
48 #include <QtGui/QHeaderView>
49 #include <QtGui/QTreeWidgetItem>
50 #include <QtGui/QFileDialog>
51 #include <QtCore/QCoreApplication>
54 Q_DECLARE_METATYPE(Core::Internal::ShortcutItem*)
57 using namespace Core::Internal;
59 CommandMappings::CommandMappings(QObject *parent)
60 : IOptionsPage(parent), m_page(0)
64 CommandMappings::~CommandMappings()
70 QWidget *CommandMappings::createPage(QWidget *parent)
72 m_page = new Ui_CommandMappings();
73 QWidget *w = new QWidget(parent);
75 m_page->targetEdit->setAutoHideButton(Utils::FancyLineEdit::Right, true);
76 m_page->targetEdit->installEventFilter(this);
78 connect(m_page->targetEdit, SIGNAL(buttonClicked(Utils::FancyLineEdit::Side)),
79 this, SLOT(removeTargetIdentifier()));
80 connect(m_page->resetButton, SIGNAL(clicked()),
81 this, SLOT(resetTargetIdentifier()));
82 connect(m_page->exportButton, SIGNAL(clicked()),
83 this, SLOT(exportAction()));
84 connect(m_page->importButton, SIGNAL(clicked()),
85 this, SLOT(importAction()));
86 connect(m_page->defaultButton, SIGNAL(clicked()),
87 this, SLOT(defaultAction()));
91 m_page->commandList->sortByColumn(0, Qt::AscendingOrder);
93 connect(m_page->filterEdit, SIGNAL(textChanged(QString)),
94 this, SLOT(filterChanged(QString)));
95 connect(m_page->commandList, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
96 this, SLOT(commandChanged(QTreeWidgetItem *)));
97 connect(m_page->targetEdit, SIGNAL(textChanged(QString)),
98 this, SLOT(targetIdentifierChanged()));
100 new Utils::TreeWidgetColumnStretcher(m_page->commandList, 1);
107 void CommandMappings::setImportExportEnabled(bool enabled)
109 m_page->importButton->setVisible(enabled);
110 m_page->exportButton->setVisible(enabled);
113 QTreeWidget *CommandMappings::commandList() const
115 return m_page->commandList;
118 QLineEdit *CommandMappings::targetEdit() const
120 return m_page->targetEdit;
123 void CommandMappings::setPageTitle(const QString &s)
125 m_page->groupBox->setTitle(s);
128 void CommandMappings::setTargetLabelText(const QString &s)
130 m_page->targetEditLabel->setText(s);
133 void CommandMappings::setTargetEditTitle(const QString &s)
135 m_page->targetEditGroup->setTitle(s);
138 void CommandMappings::setTargetHeader(const QString &s)
140 m_page->commandList->setHeaderLabels(QStringList() << tr("Command") << tr("Label") << s);
143 void CommandMappings::finish()
145 if (!m_page) // page was never shown
151 void CommandMappings::commandChanged(QTreeWidgetItem *current)
153 if (!current || !current->data(0, Qt::UserRole).isValid()) {
154 m_page->targetEdit->setText("");
155 m_page->targetEditGroup->setEnabled(false);
158 m_page->targetEditGroup->setEnabled(true);
161 void CommandMappings::filterChanged(const QString &f)
165 for (int i=0; i<m_page->commandList->topLevelItemCount(); ++i) {
166 QTreeWidgetItem *item = m_page->commandList->topLevelItem(i);
167 item->setHidden(filter(f, item));
171 bool CommandMappings::filter(const QString &f, const QTreeWidgetItem *item)
173 if (QTreeWidgetItem *parent = item->parent()) {
174 if (parent->text(0).contains(f, Qt::CaseInsensitive))
178 if (item->childCount() == 0) {
181 for (int i = 0; i < item->columnCount(); ++i) {
182 if (item->text(i).contains(f, Qt::CaseInsensitive))
189 for (int i = 0; i < item->childCount(); ++i) {
190 QTreeWidgetItem *citem = item->child(i);
191 if (filter(f, citem)) {
192 citem->setHidden(true);
194 citem->setHidden(false);
201 void CommandMappings::setModified(QTreeWidgetItem *item , bool modified)
203 QFont f = item->font(0);
204 f.setItalic(modified);
211 QString CommandMappings::filterText() const
215 return m_page->filterEdit->text();