diff options
| author | Peter Penz <[email protected]> | 2011-08-08 23:41:18 +0200 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-08-09 16:22:36 +0200 |
| commit | 3957884bf2e44619a4ed35ba0ffead519988885b (patch) | |
| tree | d8a5bf1a015cc6001adb4afc5f0f1da721908a22 /src/views/tooltips | |
| parent | 4692eb7c96f57328479862c0d17d7945b4e87188 (diff) | |
Improvements for selections, smooth scrolling, tooltips and info-panel
Diffstat (limited to 'src/views/tooltips')
| -rw-r--r-- | src/views/tooltips/tooltipmanager.cpp | 115 | ||||
| -rw-r--r-- | src/views/tooltips/tooltipmanager.h | 24 |
2 files changed, 52 insertions, 87 deletions
diff --git a/src/views/tooltips/tooltipmanager.cpp b/src/views/tooltips/tooltipmanager.cpp index 8f18dbde4..df89a882e 100644 --- a/src/views/tooltips/tooltipmanager.cpp +++ b/src/views/tooltips/tooltipmanager.cpp @@ -22,18 +22,18 @@ #include "filemetadatatooltip.h" #include <KIcon> #include <KIO/PreviewJob> -#include <KSharedConfig> #include <QApplication> #include <QDesktopWidget> #include <QLayout> #include <QScrollArea> #include <QScrollBar> +#include <QStyle> #include <QTimer> ToolTipManager::ToolTipManager(QWidget* parent) : QObject(parent), - m_view(parent), + m_parentWidget(parent), m_showToolTipTimer(0), m_contentRetrievalTimer(0), m_fileMetaDataToolTip(0), @@ -43,13 +43,6 @@ ToolTipManager::ToolTipManager(QWidget* parent) : m_item(), m_itemRect() { - //m_dolphinModel = static_cast<DolphinModel*>(m_proxyModel->sourceModel()); - //connect(parent, SIGNAL(entered(QModelIndex)), - // this, SLOT(requestToolTip(QModelIndex))); - //connect(parent, SIGNAL(viewportEntered()), - // this, SLOT(hideToolTip())); - - // Initialize timers m_showToolTipTimer = new QTimer(this); m_showToolTipTimer->setSingleShot(true); m_showToolTipTimer->setInterval(500); @@ -61,22 +54,36 @@ ToolTipManager::ToolTipManager(QWidget* parent) : connect(m_contentRetrievalTimer, SIGNAL(timeout()), this, SLOT(startContentRetrieval())); Q_ASSERT(m_contentRetrievalTimer->interval() < m_showToolTipTimer->interval()); - - // When the mousewheel is used, the items don't get a hovered indication - // (Qt-issue #200665). To assure that the tooltip still gets hidden, - // the scrollbars are observed. - /*connect(parent->horizontalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(hideToolTip())); - connect(parent->verticalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(hideToolTip()));*/ - - Q_ASSERT(m_view); - //m_view->viewport()->installEventFilter(this); - //m_view->installEventFilter(this); } ToolTipManager::~ToolTipManager() { + delete m_fileMetaDataToolTip; + m_fileMetaDataToolTip = 0; +} + +void ToolTipManager::showToolTip(const KFileItem& item, const QRectF& itemRect) +{ + hideToolTip(); + + m_itemRect = itemRect.toRect(); + + const int margin = toolTipMargin(); + m_itemRect.adjust(-margin, -margin, margin, margin); + m_item = item; + + // Only start the retrieving of the content, when the mouse has been over this + // item for 200 milliseconds. This prevents a lot of useless preview jobs and + // meta data retrieval, when passing rapidly over a lot of items. + Q_ASSERT(!m_fileMetaDataToolTip); + m_fileMetaDataToolTip = new FileMetaDataToolTip(m_parentWidget); + connect(m_fileMetaDataToolTip, SIGNAL(metaDataRequestFinished(KFileItemList)), + this, SLOT(slotMetaDataRequestFinished())); + + m_contentRetrievalTimer->start(); + m_showToolTipTimer->start(); + m_toolTipRequested = true; + Q_ASSERT(!m_metaDataRequested); } void ToolTipManager::hideToolTip() @@ -91,56 +98,10 @@ void ToolTipManager::hideToolTip() m_showToolTipTimer->stop(); m_contentRetrievalTimer->stop(); - delete m_fileMetaDataToolTip; - m_fileMetaDataToolTip = 0; -} - - -bool ToolTipManager::eventFilter(QObject* watched, QEvent* event) -{ - /*if (watched == m_view->viewport()) { - switch (event->type()) { - case QEvent::Leave: - case QEvent::MouseButtonPress: - hideToolTip(); - break; - default: - break; - } - } else if ((watched == m_view) && (event->type() == QEvent::KeyPress)) { - hideToolTip(); - }*/ - - return QObject::eventFilter(watched, event); -} - -void ToolTipManager::requestToolTip(const QModelIndex& index) -{ - Q_UNUSED(index); - hideToolTip(); - - // Only request a tooltip for the name column and when no selection or - // drag & drop operation is done (indicated by the left mouse button) - if (!(QApplication::mouseButtons() & Qt::LeftButton)) { - m_itemRect = QRect(); //m_view->visualRect(index); - const QPoint pos; // = m_view->viewport()->mapToGlobal(m_itemRect.topLeft()); - m_itemRect.moveTo(pos); - - //const QModelIndex dirIndex = m_proxyModel->mapToSource(index); - //m_item = m_dolphinModel->itemForIndex(dirIndex); - - // Only start the retrieving of the content, when the mouse has been over this - // item for 200 milliseconds. This prevents a lot of useless preview jobs and - // meta data retrieval, when passing rapidly over a lot of items. - Q_ASSERT(!m_fileMetaDataToolTip); - m_fileMetaDataToolTip = new FileMetaDataToolTip(m_view); - connect(m_fileMetaDataToolTip, SIGNAL(metaDataRequestFinished(KFileItemList)), - this, SLOT(slotMetaDataRequestFinished())); - - m_contentRetrievalTimer->start(); - m_showToolTipTimer->start(); - m_toolTipRequested = true; - Q_ASSERT(!m_metaDataRequested); + if (m_fileMetaDataToolTip) { + m_fileMetaDataToolTip->hide(); + delete m_fileMetaDataToolTip; + m_fileMetaDataToolTip = 0; } } @@ -223,10 +184,6 @@ void ToolTipManager::showToolTip() m_appliedWaitCursor = false; } - if (QApplication::mouseButtons() & Qt::LeftButton) { - return; - } - if (m_fileMetaDataToolTip->preview().isNull() || m_metaDataRequested) { Q_ASSERT(!m_appliedWaitCursor); QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); @@ -259,7 +216,7 @@ void ToolTipManager::showToolTip() // It must be assured that: // - the content is fully visible // - the content is not drawn inside m_itemRect - const int margin = 3; + const int margin = toolTipMargin(); const bool hasRoomToLeft = (m_itemRect.left() - size.width() - margin >= screen.left()); const bool hasRoomToRight = (m_itemRect.right() + size.width() + margin <= screen.right()); const bool hasRoomAbove = (m_itemRect.top() - size.height() - margin >= screen.top()); @@ -300,4 +257,10 @@ void ToolTipManager::showToolTip() m_toolTipRequested = false; } +int ToolTipManager::toolTipMargin() const +{ + const int margin = m_parentWidget->style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth); + return qMax(4, margin); +} + #include "tooltipmanager.moc" diff --git a/src/views/tooltips/tooltipmanager.h b/src/views/tooltips/tooltipmanager.h index 11ef3d3ac..b13641109 100644 --- a/src/views/tooltips/tooltipmanager.h +++ b/src/views/tooltips/tooltipmanager.h @@ -47,19 +47,20 @@ public: explicit ToolTipManager(QWidget* parent); virtual ~ToolTipManager(); -public slots: /** - * Hides the currently shown tooltip. Invoking this method is - * only needed when the tooltip should be hidden although - * an item is hovered. + * Triggers the showing of the tooltip for the item \p item + * where the item has the maximum boundaries of \p itemRect. + * The tooltip manager takes care that the tooltip is shown + * slightly delayed. */ - void hideToolTip(); + void showToolTip(const KFileItem& item, const QRectF& itemRect); -protected: - virtual bool eventFilter(QObject* watched, QEvent* event); + /** + * Hides the currently shown tooltip. + */ + void hideToolTip(); private slots: - void requestToolTip(const QModelIndex& index); void startContentRetrieval(); void setPreviewPix(const KFileItem& item, const QPixmap& pix); void previewFailed(); @@ -67,9 +68,10 @@ private slots: void showToolTip(); private: - QWidget* m_view; - DolphinModel* m_dolphinModel; - DolphinSortFilterProxyModel* m_proxyModel; + int toolTipMargin() const; + +private: + QWidget* m_parentWidget; /// Timeout from requesting a tooltip until the tooltip /// should be shown |
