[Pkg-owncloud-commits] [owncloud-client] 226/470: Update QTreeView tooltips as they change #3403
Sandro Knauß
hefee-guest at moszumanska.debian.org
Thu May 12 16:25:06 UTC 2016
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit 10a7128d1aac7549b9f5b59f6f4aa7b6c1a3c321
Author: Christian Kamm <mail at ckamm.de>
Date: Thu Jan 21 11:32:27 2016 +0100
Update QTreeView tooltips as they change #3403
---
src/gui/CMakeLists.txt | 1 +
src/gui/accountsettings.cpp | 3 +++
src/gui/tooltipupdater.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++
src/gui/tooltipupdater.h | 51 +++++++++++++++++++++++++++++++++++++++
4 files changed, 114 insertions(+)
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt
index 4bc076d..0f98ce8 100644
--- a/src/gui/CMakeLists.txt
+++ b/src/gui/CMakeLists.txt
@@ -84,6 +84,7 @@ set(client_SRCS
proxyauthhandler.cpp
proxyauthdialog.cpp
synclogdialog.cpp
+ tooltipupdater.cpp
creds/credentialsfactory.cpp
creds/httpcredentialsgui.cpp
creds/shibbolethcredentials.cpp
diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp
index efc703f..0dea852 100644
--- a/src/gui/accountsettings.cpp
+++ b/src/gui/accountsettings.cpp
@@ -29,6 +29,7 @@
#include "accountmanager.h"
#include "owncloudsetupwizard.h"
#include "creds/abstractcredentials.h"
+#include "tooltipupdater.h"
#include <math.h>
@@ -87,6 +88,8 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) :
#else
ui->_folderList->setMinimumWidth( 300 );
#endif
+ new ToolTipUpdater(ui->_folderList);
+
createAccountToolbox();
connect(AccountManager::instance(), SIGNAL(accountAdded(AccountState*)),
SLOT(slotAccountAdded(AccountState*)));
diff --git a/src/gui/tooltipupdater.cpp b/src/gui/tooltipupdater.cpp
new file mode 100644
index 0000000..9edcb8d
--- /dev/null
+++ b/src/gui/tooltipupdater.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) by Christian Kamm <mail at ckamm.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include "tooltipupdater.h"
+
+#include <QTreeView>
+#include <QHelpEvent>
+#include <QToolTip>
+#include <QDebug>
+
+using namespace OCC;
+
+ToolTipUpdater::ToolTipUpdater(QTreeView* treeView)
+ : QObject(treeView)
+ , _treeView(treeView)
+{
+ connect(_treeView->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)),
+ SLOT(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
+ _treeView->viewport()->installEventFilter(this);
+}
+
+bool ToolTipUpdater::eventFilter(QObject* /*obj*/, QEvent* ev)
+{
+ if (ev->type() == QEvent::ToolTip)
+ {
+ QHelpEvent *helpEvent = static_cast<QHelpEvent *>(ev);
+ _toolTipPos = helpEvent->globalPos();
+ }
+ return false;
+}
+
+void ToolTipUpdater::dataChanged(const QModelIndex& topLeft,
+ const QModelIndex& bottomRight,
+ const QVector<int>& roles)
+{
+ if (!QToolTip::isVisible() || !roles.contains(Qt::ToolTipRole) || _toolTipPos.isNull()) {
+ return;
+ }
+
+ // Was it the item under the cursor that changed?
+ auto index = _treeView->indexAt(_treeView->mapFromGlobal(QCursor::pos()));
+ if (topLeft == bottomRight && index != topLeft) {
+ return;
+ }
+
+ // Update the currently active tooltip
+ QToolTip::showText(_toolTipPos, _treeView->model()->data(index, Qt::ToolTipRole).toString());
+}
+
diff --git a/src/gui/tooltipupdater.h b/src/gui/tooltipupdater.h
new file mode 100644
index 0000000..ae32882
--- /dev/null
+++ b/src/gui/tooltipupdater.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) by Christian Kamm <mail at ckamm.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include <QObject>
+#include <QPoint>
+
+class QTreeView;
+
+namespace OCC {
+
+/**
+ * @brief Updates tooltips of items in a QTreeView when they change.
+ * @ingroup gui
+ *
+ * Usually tooltips are not updated as they change. Since we want to
+ * use tooltips to show rapidly updating progress information, we
+ * need to make sure that that information is displayed to the user
+ * as it changes.
+ *
+ * To accomplish that, the eventFilter() stores the tooltip's position
+ * and the dataChanged() slot updates the tooltip if Qt::ToolTipRole
+ * gets updated while a tooltip is shown.
+ */
+class ToolTipUpdater : public QObject
+{
+ Q_OBJECT
+public:
+ ToolTipUpdater(QTreeView* treeView);
+
+protected:
+ bool eventFilter(QObject* obj, QEvent* ev) Q_DECL_OVERRIDE;
+
+private slots:
+ void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles);
+
+private:
+ QTreeView* _treeView;
+ QPoint _toolTipPos;
+};
+
+} // namespace OCC
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list