forked from qt-creator/qt-creator
more style
Change-Id: Iecd6819a5376beced5413f134d3026fb889a13b1 Reviewed-on: http://codereview.qt-project.org/5115 Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -89,7 +89,7 @@ FunctionHintProposalWidgetPrivate::FunctionHintProposalWidgetPrivate()
|
||||
// HintProposalWidget
|
||||
// ------------------
|
||||
FunctionHintProposalWidget::FunctionHintProposalWidget()
|
||||
: m_d(new FunctionHintProposalWidgetPrivate)
|
||||
: d(new FunctionHintProposalWidgetPrivate)
|
||||
{
|
||||
QToolButton *downArrow = new QToolButton;
|
||||
downArrow->setArrowType(Qt::DownArrow);
|
||||
@@ -101,18 +101,18 @@ FunctionHintProposalWidget::FunctionHintProposalWidget()
|
||||
upArrow->setFixedSize(16, 16);
|
||||
upArrow->setAutoRaise(true);
|
||||
|
||||
QHBoxLayout *pagerLayout = new QHBoxLayout(m_d->m_pager);
|
||||
QHBoxLayout *pagerLayout = new QHBoxLayout(d->m_pager);
|
||||
pagerLayout->setMargin(0);
|
||||
pagerLayout->setSpacing(0);
|
||||
pagerLayout->addWidget(upArrow);
|
||||
pagerLayout->addWidget(m_d->m_numberLabel);
|
||||
pagerLayout->addWidget(d->m_numberLabel);
|
||||
pagerLayout->addWidget(downArrow);
|
||||
|
||||
QHBoxLayout *popupLayout = new QHBoxLayout(m_d->m_popupFrame);
|
||||
QHBoxLayout *popupLayout = new QHBoxLayout(d->m_popupFrame);
|
||||
popupLayout->setMargin(0);
|
||||
popupLayout->setSpacing(0);
|
||||
popupLayout->addWidget(m_d->m_pager);
|
||||
popupLayout->addWidget(m_d->m_hintLabel);
|
||||
popupLayout->addWidget(d->m_pager);
|
||||
popupLayout->addWidget(d->m_hintLabel);
|
||||
|
||||
connect(upArrow, SIGNAL(clicked()), SLOT(previousPage()));
|
||||
connect(downArrow, SIGNAL(clicked()), SLOT(nextPage()));
|
||||
@@ -124,12 +124,13 @@ FunctionHintProposalWidget::FunctionHintProposalWidget()
|
||||
|
||||
FunctionHintProposalWidget::~FunctionHintProposalWidget()
|
||||
{
|
||||
delete m_d->m_model;
|
||||
delete d->m_model;
|
||||
delete d;
|
||||
}
|
||||
|
||||
void FunctionHintProposalWidget::setAssistant(CodeAssistant *assistant)
|
||||
{
|
||||
m_d->m_assistant = assistant;
|
||||
d->m_assistant = assistant;
|
||||
}
|
||||
|
||||
void FunctionHintProposalWidget::setReason(AssistReason)
|
||||
@@ -140,17 +141,17 @@ void FunctionHintProposalWidget::setKind(AssistKind)
|
||||
|
||||
void FunctionHintProposalWidget::setUnderlyingWidget(const QWidget *underlyingWidget)
|
||||
{
|
||||
m_d->m_underlyingWidget = underlyingWidget;
|
||||
d->m_underlyingWidget = underlyingWidget;
|
||||
}
|
||||
|
||||
void FunctionHintProposalWidget::setModel(IAssistProposalModel *model)
|
||||
{
|
||||
m_d->m_model = static_cast<IFunctionHintProposalModel *>(model);
|
||||
d->m_model = static_cast<IFunctionHintProposalModel *>(model);
|
||||
}
|
||||
|
||||
void FunctionHintProposalWidget::setDisplayRect(const QRect &rect)
|
||||
{
|
||||
m_d->m_displayRect = rect;
|
||||
d->m_displayRect = rect;
|
||||
}
|
||||
|
||||
void FunctionHintProposalWidget::setIsSynchronized(bool)
|
||||
@@ -158,18 +159,18 @@ void FunctionHintProposalWidget::setIsSynchronized(bool)
|
||||
|
||||
void FunctionHintProposalWidget::showProposal(const QString &prefix)
|
||||
{
|
||||
m_d->m_totalHints = m_d->m_model->size();
|
||||
if (m_d->m_totalHints == 0) {
|
||||
d->m_totalHints = d->m_model->size();
|
||||
if (d->m_totalHints == 0) {
|
||||
abort();
|
||||
return;
|
||||
}
|
||||
m_d->m_pager->setVisible(m_d->m_totalHints > 1);
|
||||
m_d->m_currentHint = 0;
|
||||
d->m_pager->setVisible(d->m_totalHints > 1);
|
||||
d->m_currentHint = 0;
|
||||
if (!updateAndCheck(prefix)) {
|
||||
abort();
|
||||
return;
|
||||
}
|
||||
m_d->m_popupFrame->show();
|
||||
d->m_popupFrame->show();
|
||||
}
|
||||
|
||||
void FunctionHintProposalWidget::updateProposal(const QString &prefix)
|
||||
@@ -184,8 +185,8 @@ void FunctionHintProposalWidget::closeProposal()
|
||||
|
||||
void FunctionHintProposalWidget::abort()
|
||||
{
|
||||
if (m_d->m_popupFrame->isVisible())
|
||||
m_d->m_popupFrame->close();
|
||||
if (d->m_popupFrame->isVisible())
|
||||
d->m_popupFrame->close();
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
@@ -194,14 +195,14 @@ bool FunctionHintProposalWidget::eventFilter(QObject *obj, QEvent *e)
|
||||
switch (e->type()) {
|
||||
case QEvent::ShortcutOverride:
|
||||
if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape) {
|
||||
m_d->m_escapePressed = true;
|
||||
d->m_escapePressed = true;
|
||||
}
|
||||
break;
|
||||
case QEvent::KeyPress:
|
||||
if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape) {
|
||||
m_d->m_escapePressed = true;
|
||||
d->m_escapePressed = true;
|
||||
}
|
||||
if (m_d->m_model->size() > 1) {
|
||||
if (d->m_model->size() > 1) {
|
||||
QKeyEvent *ke = static_cast<QKeyEvent*>(e);
|
||||
if (ke->key() == Qt::Key_Up) {
|
||||
previousPage();
|
||||
@@ -214,15 +215,15 @@ bool FunctionHintProposalWidget::eventFilter(QObject *obj, QEvent *e)
|
||||
}
|
||||
break;
|
||||
case QEvent::KeyRelease:
|
||||
if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape && m_d->m_escapePressed) {
|
||||
if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape && d->m_escapePressed) {
|
||||
abort();
|
||||
return false;
|
||||
}
|
||||
m_d->m_assistant->notifyChange();
|
||||
d->m_assistant->notifyChange();
|
||||
break;
|
||||
case QEvent::WindowDeactivate:
|
||||
case QEvent::FocusOut:
|
||||
if (obj != m_d->m_underlyingWidget) {
|
||||
if (obj != d->m_underlyingWidget) {
|
||||
break;
|
||||
}
|
||||
abort();
|
||||
@@ -245,27 +246,27 @@ bool FunctionHintProposalWidget::eventFilter(QObject *obj, QEvent *e)
|
||||
|
||||
void FunctionHintProposalWidget::nextPage()
|
||||
{
|
||||
m_d->m_currentHint = (m_d->m_currentHint + 1) % m_d->m_totalHints;
|
||||
d->m_currentHint = (d->m_currentHint + 1) % d->m_totalHints;
|
||||
updateContent();
|
||||
}
|
||||
|
||||
void FunctionHintProposalWidget::previousPage()
|
||||
{
|
||||
if (m_d->m_currentHint == 0)
|
||||
m_d->m_currentHint = m_d->m_totalHints - 1;
|
||||
if (d->m_currentHint == 0)
|
||||
d->m_currentHint = d->m_totalHints - 1;
|
||||
else
|
||||
--m_d->m_currentHint;
|
||||
--d->m_currentHint;
|
||||
updateContent();
|
||||
}
|
||||
|
||||
bool FunctionHintProposalWidget::updateAndCheck(const QString &prefix)
|
||||
{
|
||||
const int activeArgument = m_d->m_model->activeArgument(prefix);
|
||||
const int activeArgument = d->m_model->activeArgument(prefix);
|
||||
if (activeArgument == -1) {
|
||||
abort();
|
||||
return false;
|
||||
} else if (activeArgument != m_d->m_currentArgument) {
|
||||
m_d->m_currentArgument = activeArgument;
|
||||
} else if (activeArgument != d->m_currentArgument) {
|
||||
d->m_currentArgument = activeArgument;
|
||||
updateContent();
|
||||
}
|
||||
|
||||
@@ -274,8 +275,8 @@ bool FunctionHintProposalWidget::updateAndCheck(const QString &prefix)
|
||||
|
||||
void FunctionHintProposalWidget::updateContent()
|
||||
{
|
||||
m_d->m_hintLabel->setText(m_d->m_model->text(m_d->m_currentHint));
|
||||
m_d->m_numberLabel->setText(tr("%1 of %2").arg(m_d->m_currentHint + 1).arg(m_d->m_totalHints));
|
||||
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));
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
@@ -283,33 +284,33 @@ void FunctionHintProposalWidget::updatePosition()
|
||||
{
|
||||
const QDesktopWidget *desktop = QApplication::desktop();
|
||||
#ifdef Q_WS_MAC
|
||||
const QRect &screen = desktop->availableGeometry(desktop->screenNumber(m_d->m_underlyingWidget));
|
||||
const QRect &screen = desktop->availableGeometry(desktop->screenNumber(d->m_underlyingWidget));
|
||||
#else
|
||||
const QRect &screen = desktop->screenGeometry(desktop->screenNumber(m_d->m_underlyingWidget));
|
||||
const QRect &screen = desktop->screenGeometry(desktop->screenNumber(d->m_underlyingWidget));
|
||||
#endif
|
||||
|
||||
m_d->m_pager->setFixedWidth(m_d->m_pager->minimumSizeHint().width());
|
||||
d->m_pager->setFixedWidth(d->m_pager->minimumSizeHint().width());
|
||||
|
||||
m_d->m_hintLabel->setWordWrap(false);
|
||||
d->m_hintLabel->setWordWrap(false);
|
||||
const int maxDesiredWidth = screen.width() - 10;
|
||||
const QSize &minHint = m_d->m_popupFrame->minimumSizeHint();
|
||||
const QSize &minHint = d->m_popupFrame->minimumSizeHint();
|
||||
if (minHint.width() > maxDesiredWidth) {
|
||||
m_d->m_hintLabel->setWordWrap(true);
|
||||
m_d->m_popupFrame->setFixedWidth(maxDesiredWidth);
|
||||
const int extra = m_d->m_popupFrame->contentsMargins().bottom() +
|
||||
m_d->m_popupFrame->contentsMargins().top();
|
||||
m_d->m_popupFrame->setFixedHeight(
|
||||
m_d->m_hintLabel->heightForWidth(maxDesiredWidth - m_d->m_pager->width()) + extra);
|
||||
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);
|
||||
} else {
|
||||
m_d->m_popupFrame->setFixedSize(minHint);
|
||||
d->m_popupFrame->setFixedSize(minHint);
|
||||
}
|
||||
|
||||
const QSize &sz = m_d->m_popupFrame->size();
|
||||
QPoint pos = m_d->m_displayRect.topLeft();
|
||||
const QSize &sz = d->m_popupFrame->size();
|
||||
QPoint pos = d->m_displayRect.topLeft();
|
||||
pos.setY(pos.y() - sz.height() - 1);
|
||||
if (pos.x() + sz.width() > screen.right())
|
||||
pos.setX(screen.right() - sz.width());
|
||||
m_d->m_popupFrame->move(pos);
|
||||
d->m_popupFrame->move(pos);
|
||||
}
|
||||
|
||||
} // TextEditor
|
||||
|
||||
Reference in New Issue
Block a user