2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-08-02 14:50:38 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-08-02 14:50:38 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-08-02 14:50:38 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-08-02 14:50:38 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-08-02 14:50:38 +02:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2010-08-02 14:50:38 +02:00
|
|
|
|
2013-01-10 15:07:17 +01:00
|
|
|
#include "../utils_global.h"
|
2010-08-02 14:50:38 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSharedPointer>
|
|
|
|
|
#include <QObject>
|
2016-05-09 10:57:52 +02:00
|
|
|
#include <QPointer>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QRect>
|
2019-01-29 11:43:43 +01:00
|
|
|
#include <QVariant>
|
2010-08-23 15:21:02 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* In its current form QToolTip is not extensible. So this is an attempt to provide a more
|
|
|
|
|
* flexible and customizable tooltip mechanism for Creator. Part of the code here is duplicated
|
|
|
|
|
* from QToolTip. This includes a private Qt header and the non-exported class QTipLabel, which
|
|
|
|
|
* here serves as a base tip class. Please notice that Qt relies on this particular class name in
|
|
|
|
|
* order to correctly apply the native styles for tooltips. Therefore the QTipLabel name should
|
|
|
|
|
* not be changed.
|
|
|
|
|
*/
|
2010-08-02 14:50:38 +02:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QPoint;
|
2014-12-13 00:18:59 +01:00
|
|
|
class QVariant;
|
2016-07-22 08:57:32 +02:00
|
|
|
class QLayout;
|
2010-08-02 14:50:38 +02:00
|
|
|
class QWidget;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
2013-01-10 15:07:17 +01:00
|
|
|
namespace Utils {
|
2018-11-21 10:17:25 +01:00
|
|
|
namespace Internal { class TipLabel; }
|
2010-08-02 14:50:38 +02:00
|
|
|
|
2013-01-10 15:07:17 +01:00
|
|
|
class QTCREATOR_UTILS_EXPORT ToolTip : public QObject
|
2010-08-02 14:50:38 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2013-08-20 07:46:19 +02:00
|
|
|
protected:
|
|
|
|
|
ToolTip();
|
2010-08-02 14:50:38 +02:00
|
|
|
|
|
|
|
|
public:
|
2018-05-07 15:07:21 +02:00
|
|
|
~ToolTip() override;
|
2010-08-02 14:50:38 +02:00
|
|
|
|
2014-12-13 00:18:59 +01:00
|
|
|
enum {
|
|
|
|
|
ColorContent = 0,
|
|
|
|
|
TextContent = 1,
|
|
|
|
|
WidgetContent = 42
|
|
|
|
|
};
|
|
|
|
|
|
2018-05-07 15:07:21 +02:00
|
|
|
bool eventFilter(QObject *o, QEvent *event) override;
|
2010-08-02 14:50:38 +02:00
|
|
|
|
2013-09-11 17:11:15 +02:00
|
|
|
static ToolTip *instance();
|
2010-09-01 12:08:38 +02:00
|
|
|
|
2018-05-07 17:33:02 +02:00
|
|
|
static void show(const QPoint &pos, const QString &content, QWidget *w = nullptr,
|
2019-01-29 11:43:43 +01:00
|
|
|
const QVariant &contextHelp = {}, const QRect &rect = QRect());
|
2019-11-04 17:14:25 +01:00
|
|
|
static void show(const QPoint &pos,
|
|
|
|
|
const QString &content,
|
|
|
|
|
Qt::TextFormat format,
|
|
|
|
|
QWidget *w = nullptr,
|
|
|
|
|
const QVariant &contextHelp = {},
|
|
|
|
|
const QRect &rect = QRect());
|
|
|
|
|
static void show(const QPoint &pos,
|
|
|
|
|
const QColor &color,
|
|
|
|
|
QWidget *w = nullptr,
|
|
|
|
|
const QVariant &contextHelp = {},
|
|
|
|
|
const QRect &rect = QRect());
|
2018-05-07 17:33:02 +02:00
|
|
|
static void show(const QPoint &pos, QWidget *content, QWidget *w = nullptr,
|
2019-01-29 11:43:43 +01:00
|
|
|
const QVariant &contextHelp = {}, const QRect &rect = QRect());
|
2018-05-07 17:33:02 +02:00
|
|
|
static void show(const QPoint &pos, QLayout *content, QWidget *w = nullptr,
|
2019-01-29 11:43:43 +01:00
|
|
|
const QVariant &contextHelp = {}, const QRect &rect = QRect());
|
2020-08-06 13:42:30 +02:00
|
|
|
static void move(const QPoint &pos);
|
2013-09-11 17:11:15 +02:00
|
|
|
static void hide();
|
2016-01-29 17:17:18 +01:00
|
|
|
static void hideImmediately();
|
2013-09-11 17:11:15 +02:00
|
|
|
static bool isVisible();
|
2010-08-02 14:50:38 +02:00
|
|
|
|
2015-05-06 15:58:46 +02:00
|
|
|
static QPoint offsetFromPosition();
|
|
|
|
|
|
2014-12-13 00:18:59 +01:00
|
|
|
// Helper to 'pin' (show as real window) a tooltip shown
|
|
|
|
|
// using WidgetContent
|
|
|
|
|
static bool pinToolTip(QWidget *w, QWidget *parent);
|
|
|
|
|
|
2019-01-29 11:43:43 +01:00
|
|
|
static QVariant contextHelp();
|
2015-08-07 17:21:38 +02:00
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void shown();
|
|
|
|
|
void hidden();
|
|
|
|
|
|
2010-08-02 14:50:38 +02:00
|
|
|
private:
|
2015-08-07 17:21:38 +02:00
|
|
|
void showInternal(const QPoint &pos, const QVariant &content, int typeId, QWidget *w,
|
2019-01-29 11:43:43 +01:00
|
|
|
const QVariant &contextHelp, const QRect &rect);
|
2014-12-08 10:57:05 +01:00
|
|
|
void hideTipImmediately();
|
2015-08-07 17:21:38 +02:00
|
|
|
bool acceptShow(const QVariant &content, int typeId, const QPoint &pos, QWidget *w,
|
2019-01-29 11:43:43 +01:00
|
|
|
const QVariant &contextHelp, const QRect &rect);
|
2014-12-13 00:18:59 +01:00
|
|
|
void setUp(const QPoint &pos, QWidget *w, const QRect &rect);
|
2015-08-07 17:21:38 +02:00
|
|
|
bool tipChanged(const QPoint &pos, const QVariant &content, int typeId, QWidget *w,
|
2019-01-29 11:43:43 +01:00
|
|
|
const QVariant &contextHelp) const;
|
2010-08-23 15:21:02 +02:00
|
|
|
void setTipRect(QWidget *w, const QRect &rect);
|
2020-08-06 13:42:30 +02:00
|
|
|
void placeTip(const QPoint &pos);
|
2010-08-02 14:50:38 +02:00
|
|
|
void showTip();
|
|
|
|
|
void hideTipWithDelay();
|
|
|
|
|
|
2018-11-21 10:17:25 +01:00
|
|
|
QPointer<Internal::TipLabel> m_tip;
|
2010-08-02 14:50:38 +02:00
|
|
|
QWidget *m_widget;
|
2010-08-23 15:21:02 +02:00
|
|
|
QRect m_rect;
|
2010-08-02 14:50:38 +02:00
|
|
|
QTimer m_showTimer;
|
|
|
|
|
QTimer m_hideDelayTimer;
|
2019-01-29 11:43:43 +01:00
|
|
|
QVariant m_contextHelp;
|
2010-08-02 14:50:38 +02:00
|
|
|
};
|
|
|
|
|
|
2013-01-10 15:07:17 +01:00
|
|
|
} // namespace Utils
|