Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/CMakeLists.txt1
-rw-r--r--src/gui/accountsettings.cpp3
-rw-r--r--src/gui/tooltipupdater.cpp59
-rw-r--r--src/gui/tooltipupdater.h51
4 files changed, 114 insertions, 0 deletions
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt
index 4bc076de5..0f98ce857 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 efc703fab..0dea852ff 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 000000000..9edcb8d6e
--- /dev/null
+++ b/src/gui/tooltipupdater.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) by Christian Kamm <mail@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 000000000..ae32882d4
--- /dev/null
+++ b/src/gui/tooltipupdater.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) by Christian Kamm <mail@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