1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

[TabPreviews] Only show previews after a small delay of mouse at tab

Instead of showing previews on ToolTipEvent, which would be fired
immediately if moving from one tooltip to another, it now always show
preview after a set small delay.
This delay have been changed to 300 msecs from original 200 msecs.
This commit is contained in:
nowrep 2013-12-24 11:55:40 +01:00
parent 0038fd6cb6
commit 4ed66114e7
2 changed files with 31 additions and 24 deletions

View File

@ -64,10 +64,15 @@ TabBar::TabBar(QupZilla* mainClass, TabWidget* tabWidget)
connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int)));
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
m_tabPreviewTimer = new QTimer(this);
m_tabPreviewTimer->setInterval(200);
m_tabPreviewTimer->setSingleShot(true);
connect(m_tabPreviewTimer, SIGNAL(timeout()), m_tabPreview, SLOT(hideAnimated()));
m_tabPreviewShowTimer = new QTimer(this);
m_tabPreviewShowTimer->setInterval(300);
m_tabPreviewShowTimer->setSingleShot(true);
connect(m_tabPreviewShowTimer, SIGNAL(timeout()), this, SLOT(showTabPreview()));
m_tabPreviewHideTimer = new QTimer(this);
m_tabPreviewHideTimer->setInterval(300);
m_tabPreviewHideTimer->setSingleShot(true);
connect(m_tabPreviewHideTimer, SIGNAL(timeout()), m_tabPreview, SLOT(hideAnimated()));
// ComboTabBar features
setUsesScrollButtons(true);
@ -485,14 +490,24 @@ void TabBar::restoreTabTextColor(int index)
setTabTextColor(index, m_originalTabTextColor);
}
void TabBar::showTabPreview()
void TabBar::showTabPreview(bool delayed)
{
if (delayed) {
int index = tabAt(mapFromGlobal(QCursor::pos()));
if (index == -1) {
return;
}
m_tabPreview->setPreviewIndex(index);
m_tabPreviewShowTimer->stop();
}
WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_tabPreview->previewIndex()));
if (!webTab) {
return;
}
m_tabPreviewTimer->stop();
m_tabPreviewHideTimer->stop();
m_tabPreview->setWebTab(webTab, m_tabPreview->previewIndex() == currentIndex());
QRect r(tabRect(m_tabPreview->previewIndex()));
@ -505,7 +520,7 @@ void TabBar::showTabPreview()
void TabBar::hideTabPreview(bool delayed)
{
if (delayed) {
m_tabPreviewTimer->start();
m_tabPreviewHideTimer->start();
}
else {
m_tabPreview->hideAnimated();
@ -592,9 +607,13 @@ void TabBar::mouseMoveEvent(QMouseEvent* event)
// Tab Preview
const int tab = tabAt(event->pos());
if (tab != -1 && tab != m_tabPreview->previewIndex() && event->buttons() == Qt::NoButton && m_dragStartPosition.isNull()) {
if (m_tabPreview->isVisible() && tab != -1 && tab != m_tabPreview->previewIndex() && event->buttons() == Qt::NoButton && m_dragStartPosition.isNull()) {
m_tabPreview->setPreviewIndex(tab);
showTabPreview();
showTabPreview(false);
}
if (!m_tabPreview->isVisible()) {
m_tabPreviewShowTimer->start();
}
ComboTabBar::mouseMoveEvent(event);
@ -641,19 +660,6 @@ bool TabBar::event(QEvent* event)
hideTabPreview(false);
break;
case QEvent::ToolTip:
if (m_showTabPreviews) {
QHelpEvent* ev = static_cast<QHelpEvent*>(event);
int index = tabAt(ev->pos());
if (index != -1 && !m_tabPreview->isVisible() && m_dragStartPosition.isNull()) {
m_tabPreview->setPreviewIndex(index);
showTabPreview();
}
return true;
}
break;
default:
break;
}

View File

@ -77,7 +77,7 @@ private slots:
void closeCurrentTab();
void closeTabFromButton();
void showTabPreview();
void showTabPreview(bool delayed = true);
void hideTabPreview(bool delayed = true);
void overFlowChange(bool overFlowed);
@ -107,7 +107,8 @@ private:
QupZilla* p_QupZilla;
TabWidget* m_tabWidget;
TabPreview* m_tabPreview;
QTimer* m_tabPreviewTimer;
QTimer* m_tabPreviewShowTimer;
QTimer* m_tabPreviewHideTimer;
bool m_showTabPreviews;
bool m_hideTabBarWithOneTab;