summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <peter.penz19@gmail.com>2012-02-02 14:10:45 (GMT)
committerPeter Penz <peter.penz19@gmail.com>2012-02-02 15:02:29 (GMT)
commitd80f35e634aba07281f4339125e8d0a51cd07eda (patch)
treec130c4790e1614b644cf8da7c251747d5abc1293
parentb6f71b1e48b9d56c6334ba7a18d68ac09f02ec02 (diff)
Fix crash when opening a tab during a tooltip is shown
Thanks a lot to Mathias Tillman for finding a 100 % reliable way how to reproduce the issue and for the initial patch! BUG: 278302 FIXED-IN: 4.8.1
-rw-r--r--dolphin/src/views/dolphinview.cpp6
-rw-r--r--dolphin/src/views/dolphinview.h3
-rw-r--r--dolphin/src/views/tooltips/tooltipmanager.cpp34
-rw-r--r--dolphin/src/views/tooltips/tooltipmanager.h6
4 files changed, 25 insertions, 24 deletions
diff --git a/dolphin/src/views/dolphinview.cpp b/dolphin/src/views/dolphinview.cpp
index 661ce10..16163c8 100644
--- a/dolphin/src/views/dolphinview.cpp
+++ b/dolphin/src/views/dolphinview.cpp
@@ -694,6 +694,12 @@ void DolphinView::wheelEvent(QWheelEvent* event)
}
}
+void DolphinView::hideEvent(QHideEvent* event)
+{
+ hideToolTip();
+ QWidget::hideEvent(event);
+}
+
void DolphinView::activate()
{
setActive(true);
diff --git a/dolphin/src/views/dolphinview.h b/dolphin/src/views/dolphinview.h
index 56ebbe4..bc65a8b 100644
--- a/dolphin/src/views/dolphinview.h
+++ b/dolphin/src/views/dolphinview.h
@@ -549,6 +549,9 @@ protected:
/** Changes the zoom level if Control is pressed during a wheel event. */
virtual void wheelEvent(QWheelEvent* event);
+ /** @reimp */
+ virtual void hideEvent(QHideEvent* event);
+
private slots:
/**
* Marks the view as active (DolphinView:isActive() will return true)
diff --git a/dolphin/src/views/tooltips/tooltipmanager.cpp b/dolphin/src/views/tooltips/tooltipmanager.cpp
index df89a88..3c262b7 100644
--- a/dolphin/src/views/tooltips/tooltipmanager.cpp
+++ b/dolphin/src/views/tooltips/tooltipmanager.cpp
@@ -33,16 +33,20 @@
ToolTipManager::ToolTipManager(QWidget* parent) :
QObject(parent),
- m_parentWidget(parent),
m_showToolTipTimer(0),
m_contentRetrievalTimer(0),
m_fileMetaDataToolTip(0),
m_toolTipRequested(false),
m_metaDataRequested(false),
m_appliedWaitCursor(false),
+ m_margin(4),
m_item(),
m_itemRect()
{
+ if (parent) {
+ m_margin = qMax(m_margin, parent->style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth));
+ }
+
m_showToolTipTimer = new QTimer(this);
m_showToolTipTimer->setSingleShot(true);
m_showToolTipTimer->setInterval(500);
@@ -68,15 +72,14 @@ void ToolTipManager::showToolTip(const KFileItem& item, const QRectF& itemRect)
m_itemRect = itemRect.toRect();
- const int margin = toolTipMargin();
- m_itemRect.adjust(-margin, -margin, margin, margin);
+ m_itemRect.adjust(-m_margin, -m_margin, m_margin, m_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);
+ m_fileMetaDataToolTip = new FileMetaDataToolTip();
connect(m_fileMetaDataToolTip, SIGNAL(metaDataRequestFinished(KFileItemList)),
this, SLOT(slotMetaDataRequestFinished()));
@@ -216,11 +219,10 @@ void ToolTipManager::showToolTip()
// It must be assured that:
// - the content is fully visible
// - the content is not drawn inside m_itemRect
- 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());
- const bool hasRoomBelow = (m_itemRect.bottom() + size.height() + margin <= screen.bottom());
+ 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;
}
@@ -232,16 +234,16 @@ void ToolTipManager::showToolTip()
x = screen.right() - size.width() + 1;
}
if (hasRoomBelow) {
- y = m_itemRect.bottom() + margin;
+ y = m_itemRect.bottom() + m_margin;
} else {
- y = m_itemRect.top() - size.height() - margin;
+ y = m_itemRect.top() - size.height() - m_margin;
}
} else {
Q_ASSERT(hasRoomToLeft || hasRoomToRight);
if (hasRoomToRight) {
- x = m_itemRect.right() + margin;
+ x = m_itemRect.right() + m_margin;
} else {
- x = m_itemRect.left() - size.width() - margin;
+ 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.
@@ -257,10 +259,4 @@ 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/dolphin/src/views/tooltips/tooltipmanager.h b/dolphin/src/views/tooltips/tooltipmanager.h
index b136411..4fd8f84 100644
--- a/dolphin/src/views/tooltips/tooltipmanager.h
+++ b/dolphin/src/views/tooltips/tooltipmanager.h
@@ -68,11 +68,6 @@ private slots:
void showToolTip();
private:
- int toolTipMargin() const;
-
-private:
- QWidget* m_parentWidget;
-
/// Timeout from requesting a tooltip until the tooltip
/// should be shown
QTimer* m_showToolTipTimer;
@@ -86,6 +81,7 @@ private:
bool m_toolTipRequested;
bool m_metaDataRequested;
bool m_appliedWaitCursor;
+ int m_margin;
KFileItem m_item;
QRect m_itemRect;
};