2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-04-15 16:19:23 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-15 16:19:23 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-04-15 16:19:23 +02: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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-04-15 16:19:23 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-15 16:19:23 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-04-15 16:19:23 +02:00
|
|
|
|
|
|
|
|
#include "functionhintproposalwidget.h"
|
|
|
|
|
#include "ifunctionhintproposalmodel.h"
|
|
|
|
|
#include "codeassistant.h"
|
|
|
|
|
|
2017-08-18 12:21:45 +02:00
|
|
|
#include <utils/algorithm.h>
|
2011-04-15 16:19:23 +02:00
|
|
|
#include <utils/faketooltip.h>
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2015-08-07 09:13:55 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2011-04-15 16:19:23 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
|
#include <QKeyEvent>
|
2015-11-03 12:54:45 +01:00
|
|
|
#include <QPointer>
|
2019-02-11 10:17:53 +01:00
|
|
|
#include <QScreen>
|
2011-04-15 16:19:23 +02:00
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
|
2017-08-18 12:21:45 +02:00
|
|
|
static const int maxSelectedFunctionHints = 20;
|
|
|
|
|
|
|
|
|
|
class SelectedFunctionHints
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
void insert(int basePosition, const QString &hintId)
|
|
|
|
|
{
|
|
|
|
|
if (basePosition < 0 || hintId.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const int index = indexOf(basePosition);
|
|
|
|
|
|
|
|
|
|
// Add new item
|
|
|
|
|
if (index == -1) {
|
|
|
|
|
if (m_items.size() + 1 > maxSelectedFunctionHints)
|
|
|
|
|
m_items.removeLast();
|
|
|
|
|
m_items.prepend(FunctionHintItem(basePosition, hintId));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update existing item
|
|
|
|
|
m_items[index].hintId = hintId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString hintId(int basePosition) const
|
|
|
|
|
{
|
|
|
|
|
const int index = indexOf(basePosition);
|
|
|
|
|
return index == -1 ? QString() : m_items.at(index).hintId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int indexOf(int basePosition) const
|
|
|
|
|
{
|
|
|
|
|
return Utils::indexOf(m_items, [&](const FunctionHintItem &item) {
|
|
|
|
|
return item.basePosition == basePosition;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct FunctionHintItem {
|
|
|
|
|
FunctionHintItem(int basePosition, const QString &hintId)
|
|
|
|
|
: basePosition(basePosition), hintId(hintId) {}
|
|
|
|
|
|
|
|
|
|
int basePosition = -1;
|
|
|
|
|
QString hintId;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QList<FunctionHintItem> m_items;
|
|
|
|
|
};
|
|
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
// -------------------------
|
|
|
|
|
// HintProposalWidgetPrivate
|
|
|
|
|
// -------------------------
|
|
|
|
|
struct FunctionHintProposalWidgetPrivate
|
|
|
|
|
{
|
|
|
|
|
FunctionHintProposalWidgetPrivate();
|
|
|
|
|
|
2018-02-14 09:51:31 +01:00
|
|
|
const QWidget *m_underlyingWidget = nullptr;
|
|
|
|
|
CodeAssistant *m_assistant = nullptr;
|
2018-02-14 14:32:51 +01:00
|
|
|
FunctionHintProposalModelPtr m_model;
|
2018-02-15 09:15:49 +01:00
|
|
|
QPointer<Utils::FakeToolTip> m_popupFrame; // guard WA_DeleteOnClose widget
|
2018-02-14 09:51:31 +01:00
|
|
|
QLabel *m_numberLabel = nullptr;
|
|
|
|
|
QLabel *m_hintLabel = nullptr;
|
|
|
|
|
QWidget *m_pager = nullptr;
|
2011-04-15 16:19:23 +02:00
|
|
|
QRect m_displayRect;
|
2018-02-14 09:51:31 +01:00
|
|
|
int m_currentHint = -1;
|
|
|
|
|
int m_totalHints = 0;
|
|
|
|
|
int m_currentArgument = -1;
|
|
|
|
|
bool m_escapePressed = false;
|
2011-04-15 16:19:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FunctionHintProposalWidgetPrivate::FunctionHintProposalWidgetPrivate()
|
2018-02-14 09:51:31 +01:00
|
|
|
: m_popupFrame(new Utils::FakeToolTip)
|
2011-04-15 16:19:23 +02:00
|
|
|
, m_numberLabel(new QLabel)
|
|
|
|
|
, m_hintLabel(new QLabel)
|
|
|
|
|
, m_pager(new QWidget)
|
|
|
|
|
{
|
|
|
|
|
m_hintLabel->setTextFormat(Qt::RichText);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------------------
|
|
|
|
|
// HintProposalWidget
|
|
|
|
|
// ------------------
|
|
|
|
|
FunctionHintProposalWidget::FunctionHintProposalWidget()
|
2011-09-16 13:10:06 +02:00
|
|
|
: d(new FunctionHintProposalWidgetPrivate)
|
2011-04-15 16:19:23 +02:00
|
|
|
{
|
2018-02-14 09:51:31 +01:00
|
|
|
auto downArrow = new QToolButton;
|
2011-04-15 16:19:23 +02:00
|
|
|
downArrow->setArrowType(Qt::DownArrow);
|
|
|
|
|
downArrow->setFixedSize(16, 16);
|
|
|
|
|
downArrow->setAutoRaise(true);
|
|
|
|
|
|
2018-02-14 09:51:31 +01:00
|
|
|
auto upArrow = new QToolButton;
|
2011-04-15 16:19:23 +02:00
|
|
|
upArrow->setArrowType(Qt::UpArrow);
|
|
|
|
|
upArrow->setFixedSize(16, 16);
|
|
|
|
|
upArrow->setAutoRaise(true);
|
|
|
|
|
|
2018-02-14 09:51:31 +01:00
|
|
|
auto pagerLayout = new QHBoxLayout(d->m_pager);
|
2019-08-29 10:36:01 +02:00
|
|
|
pagerLayout->setContentsMargins(0, 0, 0, 0);
|
2011-04-15 16:19:23 +02:00
|
|
|
pagerLayout->setSpacing(0);
|
|
|
|
|
pagerLayout->addWidget(upArrow);
|
2011-09-16 13:10:06 +02:00
|
|
|
pagerLayout->addWidget(d->m_numberLabel);
|
2011-04-15 16:19:23 +02:00
|
|
|
pagerLayout->addWidget(downArrow);
|
|
|
|
|
|
2018-02-14 09:51:31 +01:00
|
|
|
auto popupLayout = new QHBoxLayout(d->m_popupFrame);
|
2019-08-29 10:36:01 +02:00
|
|
|
popupLayout->setContentsMargins(0, 0, 0, 0);
|
2011-04-15 16:19:23 +02:00
|
|
|
popupLayout->setSpacing(0);
|
2011-09-16 13:10:06 +02:00
|
|
|
popupLayout->addWidget(d->m_pager);
|
|
|
|
|
popupLayout->addWidget(d->m_hintLabel);
|
2011-04-15 16:19:23 +02:00
|
|
|
|
2015-12-13 01:18:33 +02:00
|
|
|
connect(upArrow, &QAbstractButton::clicked, this, &FunctionHintProposalWidget::previousPage);
|
|
|
|
|
connect(downArrow, &QAbstractButton::clicked, this, &FunctionHintProposalWidget::nextPage);
|
2015-11-16 07:14:44 +01:00
|
|
|
connect(d->m_popupFrame.data(), &QObject::destroyed, this, &FunctionHintProposalWidget::abort);
|
2011-04-15 16:19:23 +02:00
|
|
|
|
|
|
|
|
setFocusPolicy(Qt::NoFocus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FunctionHintProposalWidget::~FunctionHintProposalWidget()
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
delete d;
|
2011-04-15 16:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FunctionHintProposalWidget::setAssistant(CodeAssistant *assistant)
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_assistant = assistant;
|
2011-04-15 16:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
2011-06-23 15:04:01 +02:00
|
|
|
void FunctionHintProposalWidget::setReason(AssistReason)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
void FunctionHintProposalWidget::setKind(AssistKind)
|
|
|
|
|
{}
|
2011-04-15 16:19:23 +02:00
|
|
|
|
|
|
|
|
void FunctionHintProposalWidget::setUnderlyingWidget(const QWidget *underlyingWidget)
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_underlyingWidget = underlyingWidget;
|
2011-04-15 16:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
2018-02-14 14:32:51 +01:00
|
|
|
void FunctionHintProposalWidget::setModel(ProposalModelPtr model)
|
2011-04-15 16:19:23 +02:00
|
|
|
{
|
2018-02-14 14:32:51 +01:00
|
|
|
d->m_model = model.staticCast<IFunctionHintProposalModel>();
|
2011-04-15 16:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FunctionHintProposalWidget::setDisplayRect(const QRect &rect)
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_displayRect = rect;
|
2011-04-15 16:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FunctionHintProposalWidget::setIsSynchronized(bool)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
void FunctionHintProposalWidget::showProposal(const QString &prefix)
|
|
|
|
|
{
|
2015-08-11 08:47:21 +02:00
|
|
|
QTC_ASSERT(d->m_model && d->m_assistant, abort(); return; );
|
|
|
|
|
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_totalHints = d->m_model->size();
|
2015-08-11 08:47:21 +02:00
|
|
|
QTC_ASSERT(d->m_totalHints != 0, abort(); return; );
|
|
|
|
|
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_pager->setVisible(d->m_totalHints > 1);
|
2017-08-18 12:21:45 +02:00
|
|
|
d->m_currentHint = loadSelectedHint();
|
2016-04-26 16:22:54 +02:00
|
|
|
if (!updateAndCheck(prefix))
|
|
|
|
|
return;
|
2015-08-11 08:47:21 +02:00
|
|
|
|
|
|
|
|
qApp->installEventFilter(this);
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_popupFrame->show();
|
2011-04-15 16:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FunctionHintProposalWidget::updateProposal(const QString &prefix)
|
|
|
|
|
{
|
|
|
|
|
updateAndCheck(prefix);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FunctionHintProposalWidget::closeProposal()
|
|
|
|
|
{
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FunctionHintProposalWidget::abort()
|
|
|
|
|
{
|
2015-11-03 12:54:45 +01:00
|
|
|
qApp->removeEventFilter(this);
|
2011-09-16 13:10:06 +02:00
|
|
|
if (d->m_popupFrame->isVisible())
|
|
|
|
|
d->m_popupFrame->close();
|
2011-04-15 16:19:23 +02:00
|
|
|
deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-18 12:21:45 +02:00
|
|
|
static SelectedFunctionHints selectedFunctionHints(CodeAssistant &codeAssistant)
|
|
|
|
|
{
|
|
|
|
|
const QVariant variant = codeAssistant.userData();
|
|
|
|
|
return variant.value<SelectedFunctionHints>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FunctionHintProposalWidget::loadSelectedHint() const
|
|
|
|
|
{
|
|
|
|
|
const QString hintId = selectedFunctionHints(*d->m_assistant).hintId(basePosition());
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < d->m_model->size(); ++i) {
|
|
|
|
|
if (d->m_model->id(i) == hintId)
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FunctionHintProposalWidget::storeSelectedHint()
|
|
|
|
|
{
|
|
|
|
|
SelectedFunctionHints table = selectedFunctionHints(*d->m_assistant);
|
|
|
|
|
table.insert(basePosition(), d->m_model->id(d->m_currentHint));
|
|
|
|
|
|
|
|
|
|
d->m_assistant->setUserData(QVariant::fromValue(table));
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
bool FunctionHintProposalWidget::eventFilter(QObject *obj, QEvent *e)
|
|
|
|
|
{
|
|
|
|
|
switch (e->type()) {
|
|
|
|
|
case QEvent::ShortcutOverride:
|
2013-08-21 23:21:13 +03:00
|
|
|
if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape) {
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_escapePressed = true;
|
2013-08-21 23:21:13 +03:00
|
|
|
e->accept();
|
|
|
|
|
}
|
2011-04-15 16:19:23 +02:00
|
|
|
break;
|
|
|
|
|
case QEvent::KeyPress:
|
2013-08-21 23:21:13 +03:00
|
|
|
if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape) {
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_escapePressed = true;
|
2013-08-21 23:21:13 +03:00
|
|
|
e->accept();
|
|
|
|
|
}
|
2015-08-07 09:13:55 +02:00
|
|
|
QTC_CHECK(d->m_model);
|
|
|
|
|
if (d->m_model && d->m_model->size() > 1) {
|
2018-09-20 01:16:01 +03:00
|
|
|
auto ke = static_cast<QKeyEvent*>(e);
|
2011-04-15 16:19:23 +02:00
|
|
|
if (ke->key() == Qt::Key_Up) {
|
|
|
|
|
previousPage();
|
|
|
|
|
return true;
|
|
|
|
|
} else if (ke->key() == Qt::Key_Down) {
|
|
|
|
|
nextPage();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2013-10-16 12:22:31 +02:00
|
|
|
case QEvent::KeyRelease: {
|
2018-09-20 01:16:01 +03:00
|
|
|
auto ke = static_cast<QKeyEvent*>(e);
|
2013-10-16 12:22:31 +02:00
|
|
|
if (ke->key() == Qt::Key_Escape && d->m_escapePressed) {
|
|
|
|
|
abort();
|
|
|
|
|
emit explicitlyAborted();
|
|
|
|
|
return false;
|
|
|
|
|
} else if (ke->key() == Qt::Key_Up || ke->key() == Qt::Key_Down) {
|
2015-08-07 09:13:55 +02:00
|
|
|
QTC_CHECK(d->m_model);
|
|
|
|
|
if (d->m_model && d->m_model->size() > 1)
|
2013-10-16 12:22:31 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2016-04-15 15:21:26 +02:00
|
|
|
if (QTC_GUARD(d->m_assistant))
|
2015-08-07 09:13:55 +02:00
|
|
|
d->m_assistant->notifyChange();
|
2011-04-15 16:19:23 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case QEvent::WindowDeactivate:
|
|
|
|
|
case QEvent::FocusOut:
|
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 (obj != d->m_underlyingWidget)
|
2011-04-15 16:19:23 +02:00
|
|
|
break;
|
|
|
|
|
abort();
|
|
|
|
|
break;
|
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
|
case QEvent::MouseButtonDblClick:
|
2015-08-11 08:47:21 +02:00
|
|
|
case QEvent::Wheel:
|
|
|
|
|
if (QWidget *widget = qobject_cast<QWidget *>(obj)) {
|
2015-11-03 12:54:45 +01:00
|
|
|
if (d->m_popupFrame && !d->m_popupFrame->isAncestorOf(widget)) {
|
2011-04-15 16:19:23 +02:00
|
|
|
abort();
|
2011-11-03 13:14:39 -04:00
|
|
|
} else if (e->type() == QEvent::Wheel) {
|
2019-08-30 10:12:38 +02:00
|
|
|
if (static_cast<QWheelEvent*>(e)->angleDelta().y() > 0)
|
2011-11-03 13:14:39 -04:00
|
|
|
previousPage();
|
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
|
2011-11-03 13:14:39 -04:00
|
|
|
nextPage();
|
|
|
|
|
return true;
|
2011-04-15 16:19:23 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FunctionHintProposalWidget::nextPage()
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_currentHint = (d->m_currentHint + 1) % d->m_totalHints;
|
2017-08-18 12:21:45 +02:00
|
|
|
|
|
|
|
|
storeSelectedHint();
|
2011-04-15 16:19:23 +02:00
|
|
|
updateContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FunctionHintProposalWidget::previousPage()
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
if (d->m_currentHint == 0)
|
|
|
|
|
d->m_currentHint = d->m_totalHints - 1;
|
2011-04-15 16:19:23 +02:00
|
|
|
else
|
2011-09-16 13:10:06 +02:00
|
|
|
--d->m_currentHint;
|
2017-08-18 12:21:45 +02:00
|
|
|
|
|
|
|
|
storeSelectedHint();
|
2011-04-15 16:19:23 +02:00
|
|
|
updateContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FunctionHintProposalWidget::updateAndCheck(const QString &prefix)
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
const int activeArgument = d->m_model->activeArgument(prefix);
|
2011-04-15 16:19:23 +02:00
|
|
|
if (activeArgument == -1) {
|
|
|
|
|
abort();
|
|
|
|
|
return false;
|
2011-09-16 13:10:06 +02:00
|
|
|
} else if (activeArgument != d->m_currentArgument) {
|
|
|
|
|
d->m_currentArgument = activeArgument;
|
2011-04-15 16:19:23 +02:00
|
|
|
updateContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FunctionHintProposalWidget::updateContent()
|
|
|
|
|
{
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_hintLabel->setText(d->m_model->text(d->m_currentHint));
|
|
|
|
|
d->m_numberLabel->setText(tr("%1 of %2").arg(d->m_currentHint + 1).arg(d->m_totalHints));
|
2011-04-15 16:19:23 +02:00
|
|
|
updatePosition();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FunctionHintProposalWidget::updatePosition()
|
|
|
|
|
{
|
|
|
|
|
const QDesktopWidget *desktop = QApplication::desktop();
|
2019-02-11 10:17:53 +01:00
|
|
|
const int screenNumber = desktop->screenNumber(d->m_underlyingWidget);
|
|
|
|
|
auto widgetScreen = QGuiApplication::screens().value(screenNumber, QGuiApplication::primaryScreen());
|
2012-08-23 15:53:58 +02:00
|
|
|
const QRect &screen = Utils::HostOsInfo::isMacHost()
|
2019-02-11 10:17:53 +01:00
|
|
|
? widgetScreen->availableGeometry() : widgetScreen->geometry();
|
2011-04-15 16:19:23 +02:00
|
|
|
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_pager->setFixedWidth(d->m_pager->minimumSizeHint().width());
|
2011-04-15 16:19:23 +02:00
|
|
|
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_hintLabel->setWordWrap(false);
|
2011-04-15 16:19:23 +02:00
|
|
|
const int maxDesiredWidth = screen.width() - 10;
|
2011-09-16 13:10:06 +02:00
|
|
|
const QSize &minHint = d->m_popupFrame->minimumSizeHint();
|
2011-04-15 16:19:23 +02:00
|
|
|
if (minHint.width() > maxDesiredWidth) {
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_hintLabel->setWordWrap(true);
|
|
|
|
|
d->m_popupFrame->setFixedWidth(maxDesiredWidth);
|
|
|
|
|
const int extra = d->m_popupFrame->contentsMargins().bottom() +
|
|
|
|
|
d->m_popupFrame->contentsMargins().top();
|
|
|
|
|
d->m_popupFrame->setFixedHeight(
|
|
|
|
|
d->m_hintLabel->heightForWidth(maxDesiredWidth - d->m_pager->width()) + extra);
|
2011-04-15 16:19:23 +02:00
|
|
|
} else {
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_popupFrame->setFixedSize(minHint);
|
2011-04-15 16:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
2011-09-16 13:10:06 +02:00
|
|
|
const QSize &sz = d->m_popupFrame->size();
|
|
|
|
|
QPoint pos = d->m_displayRect.topLeft();
|
2011-04-15 16:19:23 +02:00
|
|
|
pos.setY(pos.y() - sz.height() - 1);
|
|
|
|
|
if (pos.x() + sz.width() > screen.right())
|
|
|
|
|
pos.setX(screen.right() - sz.width());
|
2011-09-16 13:10:06 +02:00
|
|
|
d->m_popupFrame->move(pos);
|
2011-04-15 16:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // TextEditor
|
2017-08-18 12:21:45 +02:00
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(TextEditor::SelectedFunctionHints)
|