X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/e2b844437e9308a04ddf043ae9d2f5c8ffef97b0..ca5d3fde114dfdb280e46995e8a425d3ec558596:/src/views/tooltips/tooltipmanager.cpp diff --git a/src/views/tooltips/tooltipmanager.cpp b/src/views/tooltips/tooltipmanager.cpp index 09e97861a..69ed1e3be 100644 --- a/src/views/tooltips/tooltipmanager.cpp +++ b/src/views/tooltips/tooltipmanager.cpp @@ -22,6 +22,7 @@ #include "filemetadatatooltip.h" #include #include +#include #include #include @@ -47,17 +48,6 @@ ToolTipManager::ToolTipManager(QAbstractItemView* parent, m_item(), m_itemRect() { - static FileMetaDataToolTip* sharedToolTip = 0; - if (sharedToolTip == 0) { - sharedToolTip = new FileMetaDataToolTip(); - // TODO: Using K_GLOBAL_STATIC would be preferable to maintain the - // instance, but the cleanup of KFileMetaDataWidget at this stage does - // not work. - } - m_fileMetaDataToolTip = sharedToolTip; - connect(m_fileMetaDataToolTip, SIGNAL(metaDataRequestFinished(KFileItemList)), - this, SLOT(slotMetaDataRequestFinished())); - m_dolphinModel = static_cast(m_proxyModel->sourceModel()); connect(parent, SIGNAL(entered(const QModelIndex&)), this, SLOT(requestToolTip(const QModelIndex&))); @@ -85,6 +75,7 @@ ToolTipManager::ToolTipManager(QAbstractItemView* parent, connect(parent->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hideToolTip())); + Q_ASSERT(m_view); m_view->viewport()->installEventFilter(this); m_view->installEventFilter(this); } @@ -105,10 +96,11 @@ void ToolTipManager::hideToolTip() m_showToolTipTimer->stop(); m_contentRetrievalTimer->stop(); - m_fileMetaDataToolTip->setItems(KFileItemList()); - m_fileMetaDataToolTip->hide(); + delete m_fileMetaDataToolTip; + m_fileMetaDataToolTip = 0; } + bool ToolTipManager::eventFilter(QObject* watched, QEvent* event) { if (watched == m_view->viewport()) { @@ -144,6 +136,11 @@ void ToolTipManager::requestToolTip(const QModelIndex& index) // 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; @@ -164,11 +161,12 @@ void ToolTipManager::startContentRetrieval() // meta-data have been received. m_metaDataRequested = true; m_fileMetaDataToolTip->setItems(KFileItemList() << m_item); + m_fileMetaDataToolTip->adjustSize(); // Request a preview of the item m_fileMetaDataToolTip->setPreview(QPixmap()); - KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << m_item, 256, 256); + KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << m_item, QSize(256, 256)); connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), this, SLOT(setPreviewPix(const KFileItem&, const QPixmap&))); @@ -215,6 +213,7 @@ void ToolTipManager::slotMetaDataRequestFinished() } m_metaDataRequested = false; + if (!m_showToolTipTimer->isActive()) { showToolTip(); } @@ -260,35 +259,36 @@ void ToolTipManager::showToolTip() } // m_itemRect defines the area of the item, where the tooltip should be - // shown. Per default the tooltip is shown in the bottom right corner. + // shown. Per default the tooltip is shown centered at the bottom. // It must be assured that: // - the content is fully visible // - the content is not drawn inside m_itemRect - const bool hasRoomToLeft = (m_itemRect.left() - size.width() >= screen.left()); - const bool hasRoomToRight = (m_itemRect.right() + size.width() <= screen.right()); - const bool hasRoomAbove = (m_itemRect.top() - size.height() >= screen.top()); - const bool hasRoomBelow = (m_itemRect.bottom() + size.height() <= screen.bottom()); + const int margin = 3; + 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()); + const bool hasRoomBelow = (m_itemRect.bottom() + size.height() + margin <= screen.bottom()); if (!hasRoomAbove && !hasRoomBelow && !hasRoomToLeft && !hasRoomToRight) { return; } int x, y; if (hasRoomBelow || hasRoomAbove) { - x = QCursor::pos().x() + 16; // TODO: use mouse pointer width instead of the magic value of 16 + x = qMax(screen.left(), m_itemRect.center().x() - size.width() / 2); if (x + size.width() >= screen.right()) { x = screen.right() - size.width() + 1; } if (hasRoomBelow) { - y = m_itemRect.bottom() + 1; + y = m_itemRect.bottom() + margin; } else { - y = m_itemRect.top() - size.height(); + y = m_itemRect.top() - size.height() - margin; } } else { Q_ASSERT(hasRoomToLeft || hasRoomToRight); if (hasRoomToRight) { - x = m_itemRect.right() + 1; + x = m_itemRect.right() + margin; } else { - x = m_itemRect.left() - size.width(); + x = m_itemRect.left() - size.width() - margin; } // Put the tooltip at the bottom of the screen. The x-coordinate has already // been adjusted, so that no overlapping with m_itemRect occurs. @@ -298,7 +298,7 @@ void ToolTipManager::showToolTip() // Step #3 - Alter tooltip geometry m_fileMetaDataToolTip->setFixedSize(size); m_fileMetaDataToolTip->layout()->setSizeConstraint(QLayout::SetNoConstraint); - m_fileMetaDataToolTip->setGeometry(x, y, size.width(), size.height()); + m_fileMetaDataToolTip->move(QPoint(x, y)); m_fileMetaDataToolTip->show(); m_toolTipRequested = false;