diff options
| author | Elvis Angelaccio <[email protected]> | 2017-02-05 22:53:50 +0100 |
|---|---|---|
| committer | Elvis Angelaccio <[email protected]> | 2017-02-05 22:56:40 +0100 |
| commit | 230fe13d1fccf8c2ab09c0873c1cc4c733cfc3b4 (patch) | |
| tree | b4dba8cc512700f5dfa5b488dfa841096db8fa8c /src/views/tooltips/tooltipmanager.cpp | |
| parent | 6fc68fe650a41fcd7f4d52c8e97723c06b0dfbff (diff) | |
Port tooltips to KToolTipWidget
Use the new KToolTipWidget class (introduced by kwidgetsaddons 5.30) as backend of ToolTipManager.
FileMetaDataToolTip becomes a simple widget used as content of the tooltip.
It is now possible to actually use the metadata widget shown inside the tooltips.
Tooltips are now functional on Wayland as well.
More information about KToolTipWidget in https://git.reviewboard.kde.org/r/129648/
BUG: 352276
BUG: 371223
FIXED-IN: 17.04.0
Closes T4980
Differential Revision: D4449
Diffstat (limited to 'src/views/tooltips/tooltipmanager.cpp')
| -rw-r--r-- | src/views/tooltips/tooltipmanager.cpp | 84 |
1 files changed, 11 insertions, 73 deletions
diff --git a/src/views/tooltips/tooltipmanager.cpp b/src/views/tooltips/tooltipmanager.cpp index 404d6801c..d19e98c81 100644 --- a/src/views/tooltips/tooltipmanager.cpp +++ b/src/views/tooltips/tooltipmanager.cpp @@ -24,18 +24,22 @@ #include <KIO/JobUiDelegate> #include <KIO/PreviewJob> #include <KJobWidgets> +#include <KToolTipWidget> #include <QApplication> #include <QDesktopWidget> #include <QLayout> #include <QStyle> #include <QTimer> +#include <QWindow> ToolTipManager::ToolTipManager(QWidget* parent) : QObject(parent), m_showToolTipTimer(0), m_contentRetrievalTimer(0), + m_transientParent(0), m_fileMetaDataToolTip(0), + m_tooltipWidget(new KToolTipWidget()), m_toolTipRequested(false), m_metaDataRequested(false), m_appliedWaitCursor(false), @@ -62,11 +66,9 @@ ToolTipManager::ToolTipManager(QWidget* parent) : ToolTipManager::~ToolTipManager() { - delete m_fileMetaDataToolTip; - m_fileMetaDataToolTip = 0; } -void ToolTipManager::showToolTip(const KFileItem& item, const QRectF& itemRect) +void ToolTipManager::showToolTip(const KFileItem& item, const QRectF& itemRect, QWindow *transientParent) { hideToolTip(); @@ -75,10 +77,12 @@ void ToolTipManager::showToolTip(const KFileItem& item, const QRectF& itemRect) m_itemRect.adjust(-m_margin, -m_margin, m_margin, m_margin); m_item = item; + m_transientParent = transientParent; + // 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); + delete m_fileMetaDataToolTip; m_fileMetaDataToolTip = new FileMetaDataToolTip(); connect(m_fileMetaDataToolTip, &FileMetaDataToolTip::metaDataRequestFinished, this, &ToolTipManager::slotMetaDataRequestFinished); @@ -100,14 +104,7 @@ void ToolTipManager::hideToolTip() m_metaDataRequested = false; m_showToolTipTimer->stop(); m_contentRetrievalTimer->stop(); - - if (m_fileMetaDataToolTip) { - m_fileMetaDataToolTip->hide(); - // Do not delete the tool tip immediately to prevent crashes when - // QCoreApplication tries to deliver an 'Enter' event to it, see bug 310579. - m_fileMetaDataToolTip->deleteLater(); - m_fileMetaDataToolTip = 0; - } + m_tooltipWidget->hideLater(); } void ToolTipManager::startContentRetrieval() @@ -200,68 +197,9 @@ void ToolTipManager::showToolTip() return; } - const QRect screen = QApplication::desktop()->screenGeometry(QCursor::pos()); - - // Restrict tooltip size to current screen size when needed. - // Because layout controlling widget doesn't respect widget's maximumSize property - // (correct me if I'm wrong), we need to let layout do its work, then manually change - // geometry if resulting widget doesn't fit the screen. - - // Step #1 - make sizeHint return calculated tooltip size - m_fileMetaDataToolTip->layout()->setSizeConstraint(QLayout::SetFixedSize); + // Adjust the size to get a proper sizeHint() m_fileMetaDataToolTip->adjustSize(); - QSize size = m_fileMetaDataToolTip->sizeHint(); - - // Step #2 - correct tooltip size when needed - if (size.width() > screen.width()) { - size.setWidth(screen.width()); - } - if (size.height() > screen.height()) { - size.setHeight(screen.height()); - } - - // m_itemRect defines the area of the item, where the tooltip should be - // 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() - m_margin >= screen.left()); - const bool hasRoomToRight = (m_itemRect.right() + size.width() + m_margin <= screen.right()); - const bool hasRoomAbove = (m_itemRect.top() - size.height() - m_margin >= screen.top()); - const bool hasRoomBelow = (m_itemRect.bottom() + size.height() + m_margin <= screen.bottom()); - if (!hasRoomAbove && !hasRoomBelow && !hasRoomToLeft && !hasRoomToRight) { - return; - } - - int x, y; - if (hasRoomBelow || hasRoomAbove) { - 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() + m_margin; - } else { - y = m_itemRect.top() - size.height() - m_margin; - } - } else { - Q_ASSERT(hasRoomToLeft || hasRoomToRight); - if (hasRoomToRight) { - x = m_itemRect.right() + m_margin; - } else { - x = m_itemRect.left() - size.width() - m_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. - y = screen.bottom() - size.height() + 1; - } - - // Step #3 - Alter tooltip geometry - m_fileMetaDataToolTip->setFixedSize(size); - m_fileMetaDataToolTip->layout()->setSizeConstraint(QLayout::SetNoConstraint); - m_fileMetaDataToolTip->move(QPoint(x, y)); - m_fileMetaDataToolTip->show(); - + m_tooltipWidget->showBelow(m_itemRect, m_fileMetaDataToolTip, m_transientParent); m_toolTipRequested = false; } |
