1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
#ifndef BaseToolTipWidget_h
#define BaseToolTipWidget_h
/******************************************************************************
*
* Copyright (C) 2002 Hugo PEREIRA <mailto: hugo.pereira@free.fr>
*
* This 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; either version 2 of the License, or (at your option) any later
* version.
*
* This software 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.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
*******************************************************************************/
#include "Counter.h"
#include <QBasicTimer>
#include <QTimerEvent>
#include <QPaintEvent>
#include <QWidget>
class GridLayoutItem;
class BaseToolTipWidget: public QWidget, private Base::Counter<BaseToolTipWidget>
{
Q_OBJECT
public:
//* constructor
explicit BaseToolTipWidget( QWidget* );
//*@name accessors
//@{
//* enabled
bool isEnabled() const
{ return enabled_; }
//* follow mouse
bool followMouse() const
{ return followMouse_; }
//* default delay
int defaultDelay() const
{ return defaultDelay_; }
//* index rect
const QRect& indexRect() const
{ return rect_; }
//* preferred position
enum class Position
{
Left,
Right,
Top,
Bottom
};
//* preferred position
Position preferredPosition() const
{ return preferredPosition_; }
//@}
//*@name modifiers
//@{
//* enable state
void setEnabled( bool );
//* follow mouse
void setFollowMouse( bool value )
{ followMouse_ = value; }
//* default delay
void setDefaultDelay( int value )
{ if( value >= 0 ) defaultDelay_ = value; }
//* set index rect
void setIndexRect( const QRect& rect )
{
rect_ = rect;
if( isVisible() ) _adjustPosition();
}
//* preferred position
void setPreferredPosition( Position value )
{
if( preferredPosition_ == value ) return;
preferredPosition_ = value;
if( isVisible() ) _adjustPosition();
}
//@}
// event filter
bool eventFilter( QObject*, QEvent* ) override;
public Q_SLOTS:
//* change visibility
void setVisible( bool ) override;
//* show delayed
void showDelayed( int = -1 );
protected:
//* paint
void paintEvent( QPaintEvent* ) override;
//* mouse press
void mousePressEvent( QMouseEvent* ) override;
//* timer event
void timerEvent( QTimerEvent* ) override;
//* check mouse position
bool _checkMousePosition() const;
//* adjust position
void _adjustPosition();
private Q_SLOTS:
//* update configuration
void _updateConfiguration();
private:
//* enable state
bool enabled_ = false;
//* follow mouse
bool followMouse_ = false;
//* default tooltip delay
int defaultDelay_ = 1000;
//* prefered tooltip position with respect to index rect
Position preferredPosition_ = Position::Bottom;
//* index rect
QRect rect_;
//* timer
QBasicTimer timer_;
//* hidden timer
/** if running, showing again the tooltip is immediate, even when calling showDelayed */
QBasicTimer hiddenTimer_;
};
#endif
|