Commit d89e2e14 authored by Leandro Melo's avatar Leandro Melo Committed by Leandro T. C. Melo

Editors: Introduce option to constrain tooltips

It's now possible to have tooltips popup only when the Shift key is down.
This has been requested quite a lot.

Task-number: QTCREATORBUG-5282
Change-Id: Ibc8568737fecbeff981ba97d9f155a70f6072413
Reviewed-on: http://codereview.qt.nokia.com/1881Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
Reviewed-by: default avatarLeena Miettinen <riitta-leena.miettinen@nokia.com>
parent c5cb64ad
......@@ -2292,6 +2292,16 @@ bool BaseTextEditorWidget::scrollWheelZoomingEnabled() const
return d->m_behaviorSettings.m_scrollWheelZooming;
}
void BaseTextEditorWidget::setConstrainTooltips(bool b)
{
d->m_behaviorSettings.m_constrainTooltips = b;
}
bool BaseTextEditorWidget::constrainTooltips() const
{
return d->m_behaviorSettings.m_constrainTooltips;
}
void BaseTextEditorWidget::setRevisionsVisible(bool b)
{
d->m_revisionsVisible = b;
......@@ -2511,9 +2521,14 @@ bool BaseTextEditorWidget::viewportEvent(QEvent *event)
if (ce->reason() == QContextMenuEvent::Mouse && !textCursor().hasSelection())
setTextCursor(cursorForPosition(ce->pos()));
} else if (event->type() == QEvent::ToolTip) {
if (QApplication::keyboardModifiers() & Qt::ControlModifier
|| (!(QApplication::keyboardModifiers() & Qt::ShiftModifier)
&& d->m_behaviorSettings.m_constrainTooltips)) {
// Tooltips should be eaten when either control is pressed (so they don't get in the
// way of code navigation) or if they are in constrained mode and shift is not pressed.
return true;
}
const QHelpEvent *he = static_cast<QHelpEvent*>(event);
if (QApplication::keyboardModifiers() & Qt::ControlModifier)
return true; // eat tooltip event when control is pressed
const QPoint &pos = he->pos();
RefactorMarker refactorMarker = d->m_refactorOverlay->markerAt(pos);
......@@ -4166,9 +4181,13 @@ void BaseTextEditorWidget::leaveEvent(QEvent *e)
void BaseTextEditorWidget::keyReleaseEvent(QKeyEvent *e)
{
// Clear link emulation when Ctrl is released
if (e->key() == Qt::Key_Control)
if (e->key() == Qt::Key_Control) {
clearLink();
} else if (e->key() == Qt::Key_Shift
&& d->m_behaviorSettings.m_constrainTooltips
&& ToolTip::instance()->isVisible()) {
ToolTip::instance()->hide();
}
QPlainTextEdit::keyReleaseEvent(e);
}
......@@ -5481,8 +5500,7 @@ void BaseTextEditorWidget::setDisplaySettings(const DisplaySettings &ds)
void BaseTextEditorWidget::setBehaviorSettings(const TextEditor::BehaviorSettings &bs)
{
setMouseNavigationEnabled(bs.m_mouseNavigation);
setScrollWheelZoomingEnabled(bs.m_scrollWheelZooming);
d->m_behaviorSettings = bs;
}
void BaseTextEditorWidget::setStorageSettings(const StorageSettings &storageSettings)
......
......@@ -203,6 +203,9 @@ public:
void setScrollWheelZoomingEnabled(bool b);
bool scrollWheelZoomingEnabled() const;
void setConstrainTooltips(bool b);
bool constrainTooltips() const;
void setRevisionsVisible(bool b);
bool revisionsVisible() const;
......
......@@ -39,13 +39,15 @@
static const char mouseNavigationKey[] = "MouseNavigation";
static const char scrollWheelZoomingKey[] = "ScrollWheelZooming";
static const char constrainTooltips[] = "ConstrainTooltips";
static const char groupPostfix[] = "BehaviorSettings";
namespace TextEditor {
BehaviorSettings::BehaviorSettings() :
m_mouseNavigation(true),
m_scrollWheelZooming(true)
m_scrollWheelZooming(true),
m_constrainTooltips(false)
{
}
......@@ -64,6 +66,7 @@ void BehaviorSettings::toMap(const QString &prefix, QVariantMap *map) const
{
map->insert(prefix + QLatin1String(mouseNavigationKey), m_mouseNavigation);
map->insert(prefix + QLatin1String(scrollWheelZoomingKey), m_scrollWheelZooming);
map->insert(prefix + QLatin1String(constrainTooltips), m_constrainTooltips);
}
void BehaviorSettings::fromMap(const QString &prefix, const QVariantMap &map)
......@@ -72,12 +75,15 @@ void BehaviorSettings::fromMap(const QString &prefix, const QVariantMap &map)
map.value(prefix + QLatin1String(mouseNavigationKey), m_mouseNavigation).toBool();
m_scrollWheelZooming =
map.value(prefix + QLatin1String(scrollWheelZoomingKey), m_scrollWheelZooming).toBool();
m_constrainTooltips =
map.value(prefix + QLatin1String(constrainTooltips), m_constrainTooltips).toBool();
}
bool BehaviorSettings::equals(const BehaviorSettings &ds) const
{
return m_mouseNavigation == ds.m_mouseNavigation
&& m_scrollWheelZooming == ds.m_scrollWheelZooming
&& m_constrainTooltips == ds.m_constrainTooltips
;
}
......
......@@ -62,6 +62,7 @@ public:
bool m_mouseNavigation;
bool m_scrollWheelZooming;
bool m_constrainTooltips;
};
inline bool operator==(const BehaviorSettings &t1, const BehaviorSettings &t2) { return t1.equals(t2); }
......
......@@ -90,6 +90,8 @@ BehaviorSettingsWidget::BehaviorSettingsWidget(QWidget *parent)
this, SLOT(slotBehaviorSettingsChanged()));
connect(m_d->m_ui.scrollWheelZooming, SIGNAL(clicked(bool)),
this, SLOT(slotBehaviorSettingsChanged()));
connect(m_d->m_ui.constrainTooltips, SIGNAL(clicked()),
this, SLOT(slotBehaviorSettingsChanged()));
connect(m_d->m_ui.utf8BomBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(slotExtraEncodingChanged()));
connect(m_d->m_ui.encodingBox, SIGNAL(currentIndexChanged(int)),
......@@ -149,12 +151,14 @@ void BehaviorSettingsWidget::setAssignedBehaviorSettings(const BehaviorSettings
{
m_d->m_ui.mouseNavigation->setChecked(behaviorSettings.m_mouseNavigation);
m_d->m_ui.scrollWheelZooming->setChecked(behaviorSettings.m_scrollWheelZooming);
m_d->m_ui.constrainTooltips->setChecked(behaviorSettings.m_constrainTooltips);
}
void BehaviorSettingsWidget::assignedBehaviorSettings(BehaviorSettings *behaviorSettings) const
{
behaviorSettings->m_mouseNavigation = m_d->m_ui.mouseNavigation->isChecked();
behaviorSettings->m_scrollWheelZooming = m_d->m_ui.scrollWheelZooming->isChecked();
behaviorSettings->m_constrainTooltips = m_d->m_ui.constrainTooltips->isChecked();
}
void BehaviorSettingsWidget::setAssignedExtraEncodingSettings(
......@@ -184,6 +188,7 @@ QString BehaviorSettingsWidget::collectUiKeywords() const
<< sep << m_d->m_ui.utf8BomLabel->text()
<< sep << m_d->m_ui.mouseNavigation->text()
<< sep << m_d->m_ui.scrollWheelZooming->text()
<< sep << m_d->m_ui.constrainTooltips->text()
<< sep << m_d->m_ui.groupBoxStorageSettings->title()
<< sep << m_d->m_ui.groupBoxEncodings->title()
<< sep << m_d->m_ui.groupBoxMouse->title();
......
......@@ -186,7 +186,7 @@
<property name="title">
<string>Mouse</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="mouseNavigation">
<property name="text">
......@@ -201,6 +201,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="constrainTooltips">
<property name="text">
<string>Enable &amp;tooltips only when Shift key is down</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment