summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@nokia.com>2012-01-06 11:56:46 +0100
committerLeandro Melo <leandro.melo@nokia.com>2012-01-11 12:31:02 +0100
commitf6a1444088d7529eabf0625e4ebcf3d103c36e6a (patch)
treec16d01671271ece5157d841704bd12f36b0cad57 /src
parent4095b807938778b4a8f2f41785461fc6eff30111 (diff)
downloadqt-creator-f6a1444088d7529eabf0625e4ebcf3d103c36e6a.tar.gz
added tooltip popup if alt-key was pressed and released
Change-Id: I167aca3c6f0e25d9a7a76f9e0d51ae85ed1a3a8f Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/locator/locatorwidget.cpp113
-rw-r--r--src/plugins/locator/locatorwidget.h3
2 files changed, 84 insertions, 32 deletions
diff --git a/src/plugins/locator/locatorwidget.cpp b/src/plugins/locator/locatorwidget.cpp
index 549701b8aa..944af8e6e8 100644
--- a/src/plugins/locator/locatorwidget.cpp
+++ b/src/plugins/locator/locatorwidget.cpp
@@ -68,6 +68,7 @@
#include <QtGui/QPushButton>
#include <QtGui/QScrollBar>
#include <QtGui/QTreeView>
+#include <QtGui/QToolTip>
Q_DECLARE_METATYPE(Locator::ILocatorFilter*)
Q_DECLARE_METATYPE(Locator::FilterEntry)
@@ -172,12 +173,17 @@ QVariant LocatorModel::data(const QModelIndex &index, int role) const
if (!index.isValid() || index.row() >= mEntries.size())
return QVariant();
- if (role == Qt::DisplayRole || role == Qt::ToolTipRole) {
+ if (role == Qt::DisplayRole) {
if (index.column() == 0) {
return mEntries.at(index.row()).displayName;
} else if (index.column() == 1) {
return mEntries.at(index.row()).extraInfo;
}
+ } else if (role == Qt::ToolTipRole) {
+ if (mEntries.at(index.row()).extraInfo.isEmpty())
+ return QVariant(mEntries.at(index.row()).displayName);
+ else
+ return QVariant(mEntries.at(index.row()).displayName + "\n\n" + mEntries.at(index.row()).extraInfo);
} else if (role == Qt::DecorationRole && index.column() == 0) {
FilterEntry &entry = mEntries[index.row()];
if (entry.resolveFileIcon && entry.displayIcon.isNull()) {
@@ -395,33 +401,7 @@ void LocatorWidget::updateFilterList()
bool LocatorWidget::eventFilter(QObject *obj, QEvent *event)
{
- if (obj == m_fileLineEdit && event->type() == QEvent::KeyPress) {
- QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
- switch (keyEvent->key()) {
- case Qt::Key_Up:
- case Qt::Key_Down:
- case Qt::Key_PageUp:
- case Qt::Key_PageDown:
- showCompletionList();
- QApplication::sendEvent(m_completionList, event);
- return true;
- case Qt::Key_Enter:
- case Qt::Key_Return:
- scheduleAcceptCurrentEntry();
- return true;
- case Qt::Key_Escape:
- m_completionList->hide();
- return true;
- case Qt::Key_Tab:
- m_completionList->next();
- return true;
- case Qt::Key_Backtab:
- m_completionList->previous();
- return true;
- default:
- break;
- }
- } else if (obj == m_fileLineEdit && event->type() == QEvent::FocusOut) {
+ if (obj == m_fileLineEdit && event->type() == QEvent::FocusOut) {
#if defined(Q_OS_WIN)
QFocusEvent *fev = static_cast<QFocusEvent*>(event);
if (fev->reason() != Qt::ActiveWindowFocusReason ||
@@ -432,15 +412,84 @@ bool LocatorWidget::eventFilter(QObject *obj, QEvent *event)
showPopupNow();
} else if (obj == this && event->type() == QEvent::ShortcutOverride) {
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
- if (ke->key() == Qt::Key_Escape && !ke->modifiers()) {
- event->accept();
- QTimer::singleShot(0, Core::ModeManager::instance(), SLOT(setFocusToCurrentMode()));
- return true;
+ switch (ke->key()) {
+ case Qt::Key_Escape:
+ if (!ke->modifiers()) {
+ event->accept();
+ QTimer::singleShot(0, Core::ModeManager::instance(), SLOT(setFocusToCurrentMode()));
+ return true;
+ }
+ case Qt::Key_Alt:
+ if (ke->modifiers() == Qt::AltModifier) {
+ event->accept();
+ return true;
+ }
+ break;
+ default:
+ break;
}
}
return QWidget::eventFilter(obj, event);
}
+void LocatorWidget::keyPressEvent(QKeyEvent *keyEvent)
+{
+ if (QToolTip::isVisible())
+ QToolTip::hideText();
+ if (m_possibleToolTipRequest)
+ m_possibleToolTipRequest = false;
+
+ switch (keyEvent->key()) {
+ case Qt::Key_Up:
+ case Qt::Key_Down:
+ case Qt::Key_PageUp:
+ case Qt::Key_PageDown:
+ showCompletionList();
+ QApplication::sendEvent(m_completionList, keyEvent);
+ return;
+ case Qt::Key_Enter:
+ case Qt::Key_Return:
+ scheduleAcceptCurrentEntry();
+ return;
+ case Qt::Key_Escape:
+ m_completionList->hide();
+ return;
+ case Qt::Key_Tab:
+ m_completionList->next();
+ return;
+ case Qt::Key_Backtab:
+ m_completionList->previous();
+ return;
+ case Qt::Key_Alt:
+ if (keyEvent->modifiers() == Qt::AltModifier) {
+ m_possibleToolTipRequest = true;
+ return;
+ }
+ break;
+ default:
+ break;
+ }
+ QWidget::keyPressEvent(keyEvent);
+}
+
+void LocatorWidget::keyReleaseEvent(QKeyEvent *keyEvent)
+{
+ if (m_possibleToolTipRequest) {
+ m_possibleToolTipRequest = false;
+ if (m_completionList->isVisible()
+ && (keyEvent->key() == Qt::Key_Alt)
+ && (keyEvent->modifiers() == Qt::NoModifier)) {
+ const QModelIndex index = m_completionList->currentIndex();
+ if (index.isValid()) {
+ QToolTip::showText(m_completionList->pos() + m_completionList->visualRect(index).topRight(),
+ m_locatorModel->data(index, Qt::ToolTipRole).toString());
+ return;
+ }
+ }
+ }
+ QWidget::keyReleaseEvent(keyEvent);
+}
+
void LocatorWidget::showCompletionList()
{
const int border = m_completionList->frameWidth();
diff --git a/src/plugins/locator/locatorwidget.h b/src/plugins/locator/locatorwidget.h
index 4b03570988..84a4e3d958 100644
--- a/src/plugins/locator/locatorwidget.h
+++ b/src/plugins/locator/locatorwidget.h
@@ -80,6 +80,8 @@ private slots:
private:
bool eventFilter(QObject *obj, QEvent *event);
+ void keyPressEvent(QKeyEvent *keyEvent);
+ void keyReleaseEvent(QKeyEvent *keyEvent);
void showEvent(QShowEvent *e);
@@ -100,6 +102,7 @@ private:
QMap<QString, QAction *> m_filterActionMap;
bool m_updateRequested;
bool m_acceptRequested;
+ bool m_possibleToolTipRequest;
};
} // namespace Internal