2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-02-10 20:58:17 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-02-10 20:58:17 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-02-10 20:58:17 +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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-02-10 20:58:17 +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
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-02-10 20:58:17 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-02-10 20:58:17 +01:00
|
|
|
|
|
|
|
|
#include "variablechooser.h"
|
|
|
|
|
#include "variablemanager.h"
|
2011-03-03 20:50:25 +01:00
|
|
|
#include "coreconstants.h"
|
2011-02-10 20:58:17 +01:00
|
|
|
|
2011-08-17 12:54:58 +02:00
|
|
|
#include <utils/fancylineedit.h> // IconButton
|
2013-03-28 11:05:35 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2011-08-17 12:54:58 +02:00
|
|
|
|
2014-06-20 00:34:41 +02:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QLabel>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QLineEdit>
|
2014-06-20 00:34:41 +02:00
|
|
|
#include <QListWidget>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QListWidgetItem>
|
2014-06-20 00:34:41 +02:00
|
|
|
#include <QPlainTextEdit>
|
|
|
|
|
#include <QPointer>
|
|
|
|
|
#include <QTextEdit>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QVBoxLayout>
|
2011-06-22 16:21:04 +02:00
|
|
|
|
2014-06-20 00:34:41 +02:00
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \internal
|
|
|
|
|
*/
|
|
|
|
|
class VariableChooserPrivate : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
VariableChooserPrivate(VariableChooser *parent)
|
|
|
|
|
: q(parent),
|
|
|
|
|
m_defaultDescription(tr("Select a variable to insert.")),
|
|
|
|
|
m_lineEdit(0),
|
|
|
|
|
m_textEdit(0),
|
|
|
|
|
m_plainTextEdit(0)
|
|
|
|
|
{
|
|
|
|
|
m_variableList = new QListWidget(q);
|
|
|
|
|
m_variableList->setAttribute(Qt::WA_MacSmallSize);
|
|
|
|
|
m_variableList->setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
|
|
|
foreach (const QByteArray &variable, VariableManager::variables())
|
|
|
|
|
m_variableList->addItem(QString::fromLatin1(variable));
|
|
|
|
|
|
|
|
|
|
m_variableDescription = new QLabel(q);
|
|
|
|
|
m_variableDescription->setText(m_defaultDescription);
|
|
|
|
|
m_variableDescription->setMinimumSize(QSize(0, 60));
|
|
|
|
|
m_variableDescription->setAlignment(Qt::AlignLeft|Qt::AlignTop);
|
|
|
|
|
m_variableDescription->setWordWrap(true);
|
|
|
|
|
m_variableDescription->setAttribute(Qt::WA_MacSmallSize);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *verticalLayout = new QVBoxLayout(q);
|
|
|
|
|
verticalLayout->setContentsMargins(3, 3, 3, 12);
|
|
|
|
|
verticalLayout->addWidget(m_variableList);
|
|
|
|
|
verticalLayout->addWidget(m_variableDescription);
|
|
|
|
|
|
|
|
|
|
connect(m_variableList, SIGNAL(currentTextChanged(QString)),
|
|
|
|
|
this, SLOT(updateDescription(QString)));
|
|
|
|
|
connect(m_variableList, SIGNAL(itemActivated(QListWidgetItem*)),
|
|
|
|
|
this, SLOT(handleItemActivated(QListWidgetItem*)));
|
|
|
|
|
connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)),
|
|
|
|
|
this, SLOT(updateCurrentEditor(QWidget*,QWidget*)));
|
|
|
|
|
updateCurrentEditor(0, qApp->focusWidget());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void createIconButton()
|
|
|
|
|
{
|
|
|
|
|
m_iconButton = new Utils::IconButton;
|
|
|
|
|
m_iconButton->setPixmap(QPixmap(QLatin1String(":/core/images/replace.png")));
|
|
|
|
|
m_iconButton->setToolTip(tr("Insert variable"));
|
|
|
|
|
m_iconButton->hide();
|
|
|
|
|
connect(m_iconButton, SIGNAL(clicked()), this, SLOT(updatePositionAndShow()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
void updateDescription(const QString &variable);
|
|
|
|
|
void updateCurrentEditor(QWidget *old, QWidget *widget);
|
|
|
|
|
void handleItemActivated(QListWidgetItem *item);
|
|
|
|
|
void insertVariable(const QString &variable);
|
|
|
|
|
void updatePositionAndShow();
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
QWidget *currentWidget();
|
|
|
|
|
|
|
|
|
|
VariableChooser *q;
|
|
|
|
|
QString m_defaultDescription;
|
|
|
|
|
QPointer<QLineEdit> m_lineEdit;
|
|
|
|
|
QPointer<QTextEdit> m_textEdit;
|
|
|
|
|
QPointer<QPlainTextEdit> m_plainTextEdit;
|
|
|
|
|
QPointer<Utils::IconButton> m_iconButton;
|
|
|
|
|
|
|
|
|
|
QListWidget *m_variableList;
|
|
|
|
|
QLabel *m_variableDescription;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
|
|
|
|
using namespace Internal;
|
2011-02-10 20:58:17 +01:00
|
|
|
|
2013-03-28 10:27:57 +01:00
|
|
|
/*!
|
|
|
|
|
* \class Core::VariableChooser
|
|
|
|
|
* \brief The VariableChooser class is used to add a tool window for selecting \QC variables
|
|
|
|
|
* to line edits, text edits or plain text edits.
|
|
|
|
|
*
|
|
|
|
|
* If you allow users to add \QC variables to strings that are specified in your UI, for example
|
|
|
|
|
* when users can provide a string through a text control, you should add a variable chooser to it.
|
|
|
|
|
* The variable chooser allows users to open a tool window that contains the list of
|
|
|
|
|
* all available variables together with a description. Double-clicking a variable inserts the
|
|
|
|
|
* corresponding string into the corresponding text control like a line edit.
|
|
|
|
|
*
|
|
|
|
|
* \image variablechooser.png "External Tools Preferences with Variable Chooser"
|
|
|
|
|
*
|
|
|
|
|
* The variable chooser monitors focus changes of all children of its parent widget.
|
|
|
|
|
* When a text control gets focus, the variable chooser checks if it has variable support set,
|
2013-10-07 13:34:40 +02:00
|
|
|
* either through the addVariableSupport() function or by manually setting the
|
2013-03-28 10:27:57 +01:00
|
|
|
* custom kVariableSupportProperty on the control. If the control supports variables,
|
|
|
|
|
* a tool button which opens the variable chooser is shown in it while it has focus.
|
|
|
|
|
*
|
|
|
|
|
* Supported text controls are QLineEdit, QTextEdit and QPlainTextEdit.
|
|
|
|
|
*
|
|
|
|
|
* The variable chooser is deleted when its parent widget is deleted.
|
|
|
|
|
*
|
|
|
|
|
* Example:
|
|
|
|
|
* \code
|
|
|
|
|
* QWidget *myOptionsContainerWidget = new QWidget;
|
|
|
|
|
* new Core::VariableChooser(myOptionsContainerWidget)
|
|
|
|
|
* QLineEdit *myLineEditOption = new QLineEdit(myOptionsContainerWidget);
|
|
|
|
|
* myOptionsContainerWidget->layout()->addWidget(myLineEditOption);
|
|
|
|
|
* Core::VariableChooser::addVariableSupport(myLineEditOption);
|
|
|
|
|
* \endcode
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \variable VariableChooser::kVariableSupportProperty
|
|
|
|
|
* Property name that is checked for deciding if a widget supports \QC variables.
|
|
|
|
|
* Can be manually set with
|
|
|
|
|
* \c{textcontrol->setProperty(VariableChooser::kVariableSupportProperty, true)}
|
|
|
|
|
* \sa addVariableSupport()
|
|
|
|
|
*/
|
2013-03-28 11:05:35 +01:00
|
|
|
const char VariableChooser::kVariableSupportProperty[] = "QtCreator.VariableSupport";
|
|
|
|
|
|
2013-03-28 10:27:57 +01:00
|
|
|
/*!
|
|
|
|
|
* Creates a variable chooser that tracks all children of \a parent for variable support.
|
|
|
|
|
* Ownership is also transferred to \a parent.
|
|
|
|
|
* \sa addVariableSupport()
|
|
|
|
|
*/
|
2011-02-10 20:58:17 +01:00
|
|
|
VariableChooser::VariableChooser(QWidget *parent) :
|
|
|
|
|
QWidget(parent),
|
2014-06-20 00:34:41 +02:00
|
|
|
d(new VariableChooserPrivate(this))
|
2011-02-10 20:58:17 +01:00
|
|
|
{
|
2014-06-20 00:34:41 +02:00
|
|
|
setWindowTitle(tr("Variables"));
|
2011-02-10 20:58:17 +01:00
|
|
|
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
2011-06-28 15:28:29 +02:00
|
|
|
setFocusPolicy(Qt::StrongFocus);
|
2014-06-20 00:34:41 +02:00
|
|
|
setFocusProxy(d->m_variableList);
|
2011-02-10 20:58:17 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-28 10:27:57 +01:00
|
|
|
/*!
|
|
|
|
|
* \internal
|
|
|
|
|
*/
|
2011-02-10 20:58:17 +01:00
|
|
|
VariableChooser::~VariableChooser()
|
|
|
|
|
{
|
2014-06-20 00:34:41 +02:00
|
|
|
delete d->m_iconButton;
|
|
|
|
|
delete d;
|
2011-02-10 20:58:17 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-28 10:27:57 +01:00
|
|
|
/*!
|
|
|
|
|
* Marks the control as supporting variables.
|
|
|
|
|
* \sa kVariableSupportProperty
|
|
|
|
|
*/
|
2013-03-28 11:05:35 +01:00
|
|
|
void VariableChooser::addVariableSupport(QWidget *textcontrol)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(textcontrol, return);
|
|
|
|
|
textcontrol->setProperty(kVariableSupportProperty, true);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-28 10:27:57 +01:00
|
|
|
/*!
|
|
|
|
|
* \internal
|
|
|
|
|
*/
|
2014-06-20 00:34:41 +02:00
|
|
|
void VariableChooserPrivate::updateDescription(const QString &variable)
|
2011-02-10 20:58:17 +01:00
|
|
|
{
|
|
|
|
|
if (variable.isNull())
|
2014-06-20 00:34:41 +02:00
|
|
|
m_variableDescription->setText(m_defaultDescription);
|
2011-02-10 20:58:17 +01:00
|
|
|
else
|
2014-06-20 00:34:41 +02:00
|
|
|
m_variableDescription->setText(VariableManager::variableDescription(variable.toUtf8())
|
2014-06-23 17:24:34 +02:00
|
|
|
+ QLatin1String("<p>") + tr("Current Value: %1").arg(VariableManager::value(variable.toUtf8())));
|
2011-02-10 20:58:17 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-28 10:27:57 +01:00
|
|
|
/*!
|
|
|
|
|
* \internal
|
|
|
|
|
*/
|
2014-06-20 00:34:41 +02:00
|
|
|
void VariableChooserPrivate::updateCurrentEditor(QWidget *old, QWidget *widget)
|
2011-02-10 20:58:17 +01:00
|
|
|
{
|
2012-12-20 15:34:42 +01:00
|
|
|
if (old)
|
|
|
|
|
old->removeEventFilter(this);
|
2011-03-03 20:50:25 +01:00
|
|
|
if (!widget) // we might loose focus, but then keep the previous state
|
|
|
|
|
return;
|
|
|
|
|
// prevent children of the chooser itself, and limit to children of chooser's parent
|
|
|
|
|
bool handle = false;
|
|
|
|
|
QWidget *parent = widget;
|
|
|
|
|
while (parent) {
|
2014-06-20 00:34:41 +02:00
|
|
|
if (parent == q)
|
2011-03-03 20:50:25 +01:00
|
|
|
return;
|
2014-06-20 00:34:41 +02:00
|
|
|
if (parent == q->parentWidget()) {
|
2011-03-03 20:50:25 +01:00
|
|
|
handle = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
parent = parent->parentWidget();
|
|
|
|
|
}
|
|
|
|
|
if (!handle)
|
|
|
|
|
return;
|
2012-12-20 15:34:42 +01:00
|
|
|
widget->installEventFilter(this); // for intercepting escape key presses
|
2011-03-03 20:50:25 +01:00
|
|
|
QLineEdit *previousLineEdit = m_lineEdit;
|
2014-06-05 08:27:17 +02:00
|
|
|
QWidget *previousWidget = currentWidget();
|
2011-03-03 20:50:25 +01:00
|
|
|
m_lineEdit = 0;
|
|
|
|
|
m_textEdit = 0;
|
|
|
|
|
m_plainTextEdit = 0;
|
2014-06-20 00:34:41 +02:00
|
|
|
QVariant variablesSupportProperty = widget->property(VariableChooser::kVariableSupportProperty);
|
2011-03-03 20:50:25 +01:00
|
|
|
bool supportsVariables = (variablesSupportProperty.isValid()
|
|
|
|
|
? variablesSupportProperty.toBool() : false);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(widget))
|
2011-03-03 20:50:25 +01:00
|
|
|
m_lineEdit = (supportsVariables ? lineEdit : 0);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (QTextEdit *textEdit = qobject_cast<QTextEdit *>(widget))
|
2011-03-03 20:50:25 +01:00
|
|
|
m_textEdit = (supportsVariables ? textEdit : 0);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else if (QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit *>(widget))
|
2011-03-03 20:50:25 +01:00
|
|
|
m_plainTextEdit = (supportsVariables ? plainTextEdit : 0);
|
|
|
|
|
if (!(m_lineEdit || m_textEdit || m_plainTextEdit))
|
2014-06-20 00:34:41 +02:00
|
|
|
q->hide();
|
2014-06-05 08:27:17 +02:00
|
|
|
|
|
|
|
|
QWidget *current = currentWidget();
|
|
|
|
|
if (current != previousWidget) {
|
2011-03-03 20:50:25 +01:00
|
|
|
if (previousLineEdit)
|
|
|
|
|
previousLineEdit->setTextMargins(0, 0, 0, 0);
|
|
|
|
|
if (m_iconButton) {
|
|
|
|
|
m_iconButton->hide();
|
|
|
|
|
m_iconButton->setParent(0);
|
|
|
|
|
}
|
2014-06-05 08:27:17 +02:00
|
|
|
if (current) {
|
2011-03-03 20:50:25 +01:00
|
|
|
if (!m_iconButton)
|
|
|
|
|
createIconButton();
|
|
|
|
|
int margin = m_iconButton->pixmap().width() + 8;
|
2014-06-20 00:34:41 +02:00
|
|
|
if (q->style()->inherits("OxygenStyle"))
|
2011-03-03 20:50:25 +01:00
|
|
|
margin = qMax(24, margin);
|
2014-06-05 08:27:17 +02:00
|
|
|
if (m_lineEdit)
|
|
|
|
|
m_lineEdit->setTextMargins(0, 0, margin, 0);
|
|
|
|
|
m_iconButton->setParent(current);
|
|
|
|
|
m_iconButton->setGeometry(current->rect().adjusted(
|
|
|
|
|
current->width() - (margin + 4), 0,
|
|
|
|
|
0, -qMax(0, current->height() - (margin + 4))));
|
2011-03-03 20:50:25 +01:00
|
|
|
m_iconButton->show();
|
|
|
|
|
}
|
2011-02-10 20:58:17 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-30 14:28:34 +02:00
|
|
|
|
2013-03-28 10:27:57 +01:00
|
|
|
/*!
|
|
|
|
|
* \internal
|
|
|
|
|
*/
|
2014-06-20 00:34:41 +02:00
|
|
|
void VariableChooserPrivate::updatePositionAndShow()
|
2011-03-30 14:28:34 +02:00
|
|
|
{
|
2014-06-20 00:34:41 +02:00
|
|
|
if (QWidget *w = q->parentWidget()) {
|
|
|
|
|
QPoint parentCenter = w->mapToGlobal(w->geometry().center());
|
|
|
|
|
q->move(parentCenter.x() - q->width()/2, parentCenter.y() - q->height()/2);
|
2011-03-30 14:28:34 +02:00
|
|
|
}
|
2014-06-20 00:34:41 +02:00
|
|
|
q->show();
|
|
|
|
|
q->raise();
|
|
|
|
|
q->activateWindow();
|
2011-03-03 20:50:25 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-05 08:27:17 +02:00
|
|
|
/*!
|
|
|
|
|
* \internal
|
|
|
|
|
*/
|
2014-06-20 00:34:41 +02:00
|
|
|
QWidget *VariableChooserPrivate::currentWidget()
|
2014-06-05 08:27:17 +02:00
|
|
|
{
|
|
|
|
|
if (m_lineEdit)
|
|
|
|
|
return m_lineEdit;
|
|
|
|
|
if (m_textEdit)
|
|
|
|
|
return m_textEdit;
|
|
|
|
|
return m_plainTextEdit;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-28 10:27:57 +01:00
|
|
|
/*!
|
|
|
|
|
* \internal
|
|
|
|
|
*/
|
2014-06-20 00:34:41 +02:00
|
|
|
void VariableChooserPrivate::handleItemActivated(QListWidgetItem *item)
|
2011-02-10 20:58:17 +01:00
|
|
|
{
|
|
|
|
|
if (item)
|
|
|
|
|
insertVariable(item->text());
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-28 10:27:57 +01:00
|
|
|
/*!
|
|
|
|
|
* \internal
|
|
|
|
|
*/
|
2014-06-20 00:34:41 +02:00
|
|
|
void VariableChooserPrivate::insertVariable(const QString &variable)
|
2011-02-10 20:58:17 +01:00
|
|
|
{
|
2011-03-21 09:01:46 +01:00
|
|
|
const QString &text = QLatin1String("%{") + variable + QLatin1String("}");
|
2011-02-10 20:58:17 +01:00
|
|
|
if (m_lineEdit) {
|
|
|
|
|
m_lineEdit->insert(text);
|
2011-03-03 20:50:25 +01:00
|
|
|
m_lineEdit->activateWindow();
|
2011-02-10 20:58:17 +01:00
|
|
|
} else if (m_textEdit) {
|
|
|
|
|
m_textEdit->insertPlainText(text);
|
2011-03-03 20:50:25 +01:00
|
|
|
m_textEdit->activateWindow();
|
2011-02-10 20:58:17 +01:00
|
|
|
} else if (m_plainTextEdit) {
|
|
|
|
|
m_plainTextEdit->insertPlainText(text);
|
2011-03-03 20:50:25 +01:00
|
|
|
m_plainTextEdit->activateWindow();
|
2011-02-10 20:58:17 +01:00
|
|
|
}
|
|
|
|
|
}
|
2011-06-22 16:21:04 +02:00
|
|
|
|
2013-03-28 10:27:57 +01:00
|
|
|
/*!
|
|
|
|
|
* \internal
|
|
|
|
|
*/
|
2012-12-20 15:34:42 +01:00
|
|
|
static bool handleEscapePressed(QKeyEvent *ke, QWidget *widget)
|
2011-06-22 16:21:04 +02:00
|
|
|
{
|
|
|
|
|
if (ke->key() == Qt::Key_Escape && !ke->modifiers()) {
|
|
|
|
|
ke->accept();
|
2012-12-20 15:34:42 +01:00
|
|
|
QTimer::singleShot(0, widget, SLOT(close()));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-28 10:27:57 +01:00
|
|
|
/*!
|
|
|
|
|
* \internal
|
|
|
|
|
*/
|
2012-12-20 15:34:42 +01:00
|
|
|
void VariableChooser::keyPressEvent(QKeyEvent *ke)
|
|
|
|
|
{
|
|
|
|
|
handleEscapePressed(ke, this);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-28 10:27:57 +01:00
|
|
|
/*!
|
|
|
|
|
* \internal
|
|
|
|
|
*/
|
2012-12-20 15:34:42 +01:00
|
|
|
bool VariableChooser::eventFilter(QObject *, QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->type() == QEvent::KeyPress && isVisible()) {
|
|
|
|
|
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
|
|
|
|
|
return handleEscapePressed(ke, this);
|
2011-06-22 16:21:04 +02:00
|
|
|
}
|
2012-12-20 15:34:42 +01:00
|
|
|
return false;
|
2011-06-22 16:21:04 +02:00
|
|
|
}
|
2014-06-20 00:34:41 +02:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
|
|
|
|
#include "variablechooser.moc"
|