forked from qt-creator/qt-creator
fancylineedit: enforce conscious choice between history or special completer
Change-Id: Ia667895b619d0bb37561dce348adb7269df2fb9c Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
@@ -29,6 +29,8 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#include "fancylineedit.h"
|
#include "fancylineedit.h"
|
||||||
|
#include "historycompleter.h"
|
||||||
|
#include "qtcassert.h"
|
||||||
|
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@@ -97,7 +99,8 @@ enum { margin = 6 };
|
|||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
// --------- FancyLineEditPrivate
|
// --------- FancyLineEditPrivate
|
||||||
class FancyLineEditPrivate : public QObject {
|
class FancyLineEditPrivate : public QObject
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
explicit FancyLineEditPrivate(FancyLineEdit *parent);
|
explicit FancyLineEditPrivate(FancyLineEdit *parent);
|
||||||
|
|
||||||
@@ -109,12 +112,14 @@ public:
|
|||||||
bool m_menuTabFocusTrigger[2];
|
bool m_menuTabFocusTrigger[2];
|
||||||
IconButton *m_iconbutton[2];
|
IconButton *m_iconbutton[2];
|
||||||
bool m_iconEnabled[2];
|
bool m_iconEnabled[2];
|
||||||
|
|
||||||
|
HistoryCompleter *m_completer;
|
||||||
|
QString m_historyKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
FancyLineEditPrivate::FancyLineEditPrivate(FancyLineEdit *parent) :
|
FancyLineEditPrivate::FancyLineEditPrivate(FancyLineEdit *parent) :
|
||||||
QObject(parent),
|
QObject(parent), m_lineEdit(parent), m_completer(0)
|
||||||
m_lineEdit(parent)
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 2; ++i) {
|
for (int i = 0; i < 2; ++i) {
|
||||||
m_menu[i] = 0;
|
m_menu[i] = 0;
|
||||||
@@ -298,6 +303,19 @@ bool FancyLineEdit::hasAutoHideButton(Side side) const
|
|||||||
return d->m_iconbutton[side]->hasAutoHide();
|
return d->m_iconbutton[side]->hasAutoHide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FancyLineEdit::setHistoryKey(const QString &historyKey)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(!d->m_completer, return);
|
||||||
|
d->m_historyKey = historyKey;
|
||||||
|
d->m_completer = new HistoryCompleter(this, historyKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FancyLineEdit::setSpecialCompleter(QCompleter *completer)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(!d->m_completer, return);
|
||||||
|
QLineEdit::setCompleter(completer);
|
||||||
|
}
|
||||||
|
|
||||||
void FancyLineEdit::setAutoHideButton(Side side, bool h)
|
void FancyLineEdit::setAutoHideButton(Side side, bool h)
|
||||||
{
|
{
|
||||||
d->m_iconbutton[side]->setAutoHide(h);
|
d->m_iconbutton[side]->setAutoHide(h);
|
||||||
|
|||||||
@@ -94,6 +94,12 @@ public:
|
|||||||
void setAutoHideButton(Side side, bool h);
|
void setAutoHideButton(Side side, bool h);
|
||||||
bool hasAutoHideButton(Side side) const;
|
bool hasAutoHideButton(Side side) const;
|
||||||
|
|
||||||
|
// Enable a history completer with a history of entries.
|
||||||
|
void setHistoryKey(const QString &historyKey);
|
||||||
|
|
||||||
|
// Sets a completer that is not a history completer.
|
||||||
|
void setSpecialCompleter(QCompleter *completer);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void buttonClicked(Utils::FancyLineEdit::Side side);
|
void buttonClicked(Utils::FancyLineEdit::Side side);
|
||||||
void leftButtonClicked();
|
void leftButtonClicked();
|
||||||
@@ -107,6 +113,10 @@ protected:
|
|||||||
virtual void resizeEvent(QResizeEvent *e);
|
virtual void resizeEvent(QResizeEvent *e);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Unimplemented, to force the user to make a decision on
|
||||||
|
// whether to use setHistoryKey() or setSpecialCompleter().
|
||||||
|
void setCompleter(QCompleter *);
|
||||||
|
|
||||||
void updateMargins();
|
void updateMargins();
|
||||||
void updateButtonPositions();
|
void updateButtonPositions();
|
||||||
friend class Utils::FancyLineEditPrivate;
|
friend class Utils::FancyLineEditPrivate;
|
||||||
|
|||||||
@@ -213,8 +213,7 @@ StartApplicationDialog::StartApplicationDialog(QWidget *parent)
|
|||||||
d->localExecutablePathChooser = new PathChooser(this);
|
d->localExecutablePathChooser = new PathChooser(this);
|
||||||
d->localExecutablePathChooser->setExpectedKind(PathChooser::File);
|
d->localExecutablePathChooser->setExpectedKind(PathChooser::File);
|
||||||
d->localExecutablePathChooser->setPromptDialogTitle(tr("Select Executable"));
|
d->localExecutablePathChooser->setPromptDialogTitle(tr("Select Executable"));
|
||||||
d->localExecutablePathChooser->lineEdit()->setCompleter(
|
d->localExecutablePathChooser->lineEdit()->setHistoryKey(QLatin1String("LocalExecutable"));
|
||||||
new HistoryCompleter(d->localExecutablePathChooser->lineEdit(), QLatin1String("LocalExecutable")));
|
|
||||||
|
|
||||||
d->arguments = new QLineEdit(this);
|
d->arguments = new QLineEdit(this);
|
||||||
d->arguments->setCompleter(
|
d->arguments->setCompleter(
|
||||||
@@ -223,8 +222,7 @@ StartApplicationDialog::StartApplicationDialog(QWidget *parent)
|
|||||||
d->workingDirectory = new PathChooser(this);
|
d->workingDirectory = new PathChooser(this);
|
||||||
d->workingDirectory->setExpectedKind(PathChooser::ExistingDirectory);
|
d->workingDirectory->setExpectedKind(PathChooser::ExistingDirectory);
|
||||||
d->workingDirectory->setPromptDialogTitle(tr("Select Working Directory"));
|
d->workingDirectory->setPromptDialogTitle(tr("Select Working Directory"));
|
||||||
d->workingDirectory->lineEdit()->setCompleter(
|
d->workingDirectory->lineEdit()->setHistoryKey(QLatin1String("WorkingDirectory"));
|
||||||
new HistoryCompleter(d->workingDirectory->lineEdit(), QLatin1String("WorkingDirectory")));
|
|
||||||
|
|
||||||
d->runInTerminalCheckBox = new QCheckBox(this);
|
d->runInTerminalCheckBox = new QCheckBox(this);
|
||||||
|
|
||||||
|
|||||||
@@ -105,8 +105,8 @@ FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumen
|
|||||||
|
|
||||||
m_findCompleter->setModel(m_plugin->findCompletionModel());
|
m_findCompleter->setModel(m_plugin->findCompletionModel());
|
||||||
m_replaceCompleter->setModel(m_plugin->replaceCompletionModel());
|
m_replaceCompleter->setModel(m_plugin->replaceCompletionModel());
|
||||||
m_ui.findEdit->setCompleter(m_findCompleter);
|
m_ui.findEdit->setSpecialCompleter(m_findCompleter);
|
||||||
m_ui.replaceEdit->setCompleter(m_replaceCompleter);
|
m_ui.replaceEdit->setSpecialCompleter(m_replaceCompleter);
|
||||||
|
|
||||||
QMenu *lineEditMenu = new QMenu(m_ui.findEdit);
|
QMenu *lineEditMenu = new QMenu(m_ui.findEdit);
|
||||||
m_ui.findEdit->setButtonMenu(Utils::FancyLineEdit::Left, lineEditMenu);
|
m_ui.findEdit->setButtonMenu(Utils::FancyLineEdit::Left, lineEditMenu);
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ FindToolWindow::FindToolWindow(FindPlugin *plugin, QWidget *parent)
|
|||||||
connect(m_ui.searchTerm, SIGNAL(textChanged(QString)), this, SLOT(updateButtonStates()));
|
connect(m_ui.searchTerm, SIGNAL(textChanged(QString)), this, SLOT(updateButtonStates()));
|
||||||
|
|
||||||
m_findCompleter->setModel(m_plugin->findCompletionModel());
|
m_findCompleter->setModel(m_plugin->findCompletionModel());
|
||||||
m_ui.searchTerm->setCompleter(m_findCompleter);
|
m_ui.searchTerm->setSpecialCompleter(m_findCompleter);
|
||||||
m_ui.searchTerm->installEventFilter(this);
|
m_ui.searchTerm->installEventFilter(this);
|
||||||
QVBoxLayout *layout = new QVBoxLayout;
|
QVBoxLayout *layout = new QVBoxLayout;
|
||||||
layout->setMargin(0);
|
layout->setMargin(0);
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
|
|||||||
m_queryModel->setStringList(m_parameters->savedQueries);
|
m_queryModel->setStringList(m_parameters->savedQueries);
|
||||||
QCompleter *completer = new QCompleter(this);
|
QCompleter *completer = new QCompleter(this);
|
||||||
completer->setModel(m_queryModel);
|
completer->setModel(m_queryModel);
|
||||||
m_queryLineEdit->setCompleter(completer);
|
m_queryLineEdit->setSpecialCompleter(completer);
|
||||||
filterLayout->addWidget(queryLabel);
|
filterLayout->addWidget(queryLabel);
|
||||||
filterLayout->addWidget(m_queryLineEdit);
|
filterLayout->addWidget(m_queryLineEdit);
|
||||||
filterLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored));
|
filterLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored));
|
||||||
|
|||||||
Reference in New Issue
Block a user