File indexing completed on 2022-11-29 19:21:42

0001 /*
0002  * Copyright (C) 2008 by Konstantin Heil <konst.heil@stud.uni-heidelberg.de>
0003  * Copyright (C) 2011 Geoffry Song <goffrie@gmail.com>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Lesser General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2.1 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Lesser General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Lesser General Public
0016  * License along with this library; if not, write to the Free Software
0017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0018  */
0019 
0020 #ifndef TOOLTIPMANAGER_H
0021 #define TOOLTIPMANAGER_H
0022 
0023 #include <QtCore/QObject>
0024 
0025 #include <QtCore/QModelIndex>
0026 
0027 class QLayout;
0028 class MenuItem;
0029 class KToolTipItem;
0030 class QAbstractItemView;
0031 
0032 /**
0033  * @brief Manages the tooltips for an item view.
0034  *
0035  * When hovering an item, a tooltip is shown after
0036  * a short timeout. The tooltip is hidden again when the
0037  * viewport is hovered or the item view has been left.
0038  */
0039 class ToolTipManager : public QObject
0040 {
0041     Q_OBJECT
0042 
0043 public:
0044     /**
0045     * Standard constructor. The ToolTipManager will start handling ToolTip events on the provided
0046     * view immediately.
0047     *
0048     * @param parent The view which will have the tooltips displayed for.
0049     */
0050     explicit ToolTipManager(QAbstractItemView *parent);
0051     virtual ~ToolTipManager();
0052 
0053 public Q_SLOTS:
0054     /**
0055      * Hides the currently shown tooltip. Invoking this method is
0056      * only needed when the tooltip should be hidden although
0057      * an item is hovered.
0058      */
0059     void hideToolTip();
0060 
0061 protected:
0062     /**
0063     * Please see the Qt documentation for more details.
0064     *
0065     * @param watched The object that was being watched.
0066     * @param event The event object.
0067     * @returns true if the event was handled in this filter, or false if it was not.
0068     */
0069     virtual bool eventFilter(QObject *watched, QEvent *event);
0070 
0071 private Q_SLOTS:
0072     void prepareToolTip();
0073     void requestToolTip(const QModelIndex &index);
0074 
0075 private:
0076     void showToolTip(const QModelIndex &index);
0077     QWidget * createTipContent(const QModelIndex &index);
0078 
0079     class Private;
0080     ToolTipManager::Private *d;
0081 };
0082 
0083 #endif