File indexing completed on 2024-05-05 04:38:42
0001 /* 0002 SPDX-FileCopyrightText: 2007 Vladimir Prus 0003 SPDX-FileCopyrightText: 2009-2010 David Nolden 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KDEVPLATFORM_ACTIVE_TOOLTIP_H 0009 #define KDEVPLATFORM_ACTIVE_TOOLTIP_H 0010 0011 #include <QWidget> 0012 #include "utilexport.h" 0013 0014 namespace KDevelop { 0015 class ActiveToolTipPrivate; 0016 0017 /** This class implements a tooltip that can contain arbitrary 0018 widgets that the user can interact with. 0019 0020 Usage example: 0021 @code 0022 KDevelop::ActiveToolTip* tooltip = new KDevelop::ActiveToolTip(mainWindow, QCursor::pos()); 0023 QVBoxLayout* layout = new QVBoxLayout(tooltip); 0024 layout->addWidget(widget); 0025 tooltip->resize( tooltip->sizeHint() ); 0026 ActiveToolTip::showToolTip(tooltip); 0027 @endcode 0028 */ 0029 class KDEVPLATFORMUTIL_EXPORT ActiveToolTip : public QWidget 0030 { 0031 Q_OBJECT 0032 0033 public: 0034 ///@param parent Parent widget. Must not be zero, else the widget won't be shown. 0035 /// @param position Position where to show the tooltip, in global coordinates. 0036 ActiveToolTip(QWidget* parent, const QPoint& position); 0037 ~ActiveToolTip() override; 0038 0039 ///Shows and registers the given tool-tip. 0040 ///This should be used instead of just calling show() to make multiple different 0041 ///tooltips work together. 0042 ///The tooltip is owned by the manager after this is called. It will delete itself. 0043 ///@param tooltip The tooltip to show. It should not be visible yet, show() will eventually be called from here, with some delay. 0044 /// The ownership stays with the caller. 0045 ///@param priority The priority of this tooltip. Lower is better. Multiple tooltips will be stacked down in the given order. 0046 /// If it is zero, the given tooltip will be shown exclusively. 0047 ///@param uniqueId If this is nonempty, ActiveTooltip will make sure that only one tooltip with the given id is shown at a time 0048 static void showToolTip(ActiveToolTip* tooltip, float priority = 100, const QString& uniqueId = QString()); 0049 0050 bool eventFilter(QObject* object, QEvent* e) override; 0051 0052 bool insideThis(QObject* object); 0053 0054 void showEvent(QShowEvent*) override; 0055 0056 void resizeEvent(QResizeEvent*) override; 0057 0058 void paintEvent(QPaintEvent*) override; 0059 0060 void adjustRect(); 0061 0062 ///Clicks within the friend widget are allowed 0063 void addFriendWidget(QWidget* widget); 0064 0065 ///Set rect of handle (object) this tool tip is created for 0066 ///Moving mouse inside this rect, and between this and bounding geometry won't hide the tooltip 0067 void setHandleRect(const QRect& rect); 0068 0069 ///Set the area within which the mouse can be moved freely without hiding the tooltip 0070 void setBoundingGeometry(const QRect& geometry); 0071 Q_SIGNALS: 0072 void resized(); 0073 // Emitted whenever mouse-activity is noticed within the tooltip area 0074 void mouseIn(); 0075 // Emitted whenever mouse-activity is noticed outside of the tooltip area 0076 void mouseOut(); 0077 0078 private: 0079 void closeEvent(QCloseEvent*) override; 0080 0081 private: 0082 const QScopedPointer<class ActiveToolTipPrivate> d_ptr; 0083 Q_DECLARE_PRIVATE(ActiveToolTip) 0084 }; 0085 0086 } 0087 0088 #endif