Krita Source Code Documentation
Loading...
Searching...
No Matches
KoItemToolTip Class Referenceabstract

#include <KoItemToolTip.h>

+ Inheritance diagram for KoItemToolTip:

Public Member Functions

 KoItemToolTip ()
 
 Private ()
 
void showTip (QWidget *widget, const QPoint &pos, const QStyleOptionViewItem &option, const QModelIndex &index)
 
QSize sizeHint () const override
 
 ~KoItemToolTip () override
 

Public Attributes

QTextDocument * document
 
QPersistentModelIndex index
 
QPoint pos
 
QBasicTimer timer
 

Protected Member Functions

virtual QTextDocument * createDocument (const QModelIndex &index)=0
 
bool eventFilter (QObject *object, QEvent *event) override
 
void paintEvent (QPaintEvent *e) override
 
void timerEvent (QTimerEvent *e) override
 

Private Member Functions

void updatePosition (QWidget *widget, const QPoint &pos, const QStyleOptionViewItem &option)
 
- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

Base class for tooltips that can show extensive information about the contents of the data pointed to by something that contains a QModelIndex. Subclasses need to use this data to create a QTextDocument that is formatted to provide the complete tooltip.

Definition at line 20 of file KoItemToolTip.cpp.

Constructor & Destructor Documentation

◆ KoItemToolTip()

KoItemToolTip::KoItemToolTip ( )

Definition at line 31 of file KoItemToolTip.cpp.

32 : d(new Private)
33{
34 d->document = new QTextDocument(this);
35 setWindowFlags(Qt::FramelessWindowHint | Qt::ToolTip
36 | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
37 QApplication::instance()->installEventFilter(this);
38}
Private *const d

References d.

◆ ~KoItemToolTip()

KoItemToolTip::~KoItemToolTip ( )
override

Definition at line 40 of file KoItemToolTip.cpp.

41{
42 delete d;
43}

References d.

Member Function Documentation

◆ createDocument()

virtual QTextDocument * KoItemToolTip::createDocument ( const QModelIndex & index)
protectedpure virtual

Re-implement this to provide the actual tooltip contents. For instance:

QTextDocument *doc = new QTextDocument(this);
QImage thumb = index.data(Qt::UserRole + KisAbstractResourceModel::LargeThumbnail).value<QImage>();
doc->addResource(QTextDocument::ImageResource, QUrl("data:thumbnail"), thumb);
QString name = index.data(Qt::DisplayRole).toString();
const QString image = QString("<img src=\"data:thumbnail\">");
const QString body = QString("<h3 align=\"center\">%1</h3>").arg(name) + image;
const QString html = QString("<html><body>%1</body></html>").arg(body);
doc->setHtml(html);
doc->setTextWidth(qMin(doc->size().width(), 500.0));
return doc;
@ LargeThumbnail
A larger thumbnail for displaying in a tooltip. 200x200 or so.
QPersistentModelIndex index

Implemented in KisIconToolTip, and NodeToolTip.

◆ eventFilter()

bool KoItemToolTip::eventFilter ( QObject * object,
QEvent * event )
overrideprotected

Definition at line 111 of file KoItemToolTip.cpp.

112{
113 switch(event->type())
114 {
115 case QEvent::KeyPress:
116 case QEvent::KeyRelease:
117 case QEvent::MouseButtonPress:
118 case QEvent::MouseButtonRelease:
119 case QEvent::FocusIn:
120 case QEvent::FocusOut:
121 case QEvent::Enter:
122 case QEvent::Leave:
123 hide();
124 default: break;
125 }
126
127 return QFrame::eventFilter(object, event);
128}

◆ paintEvent()

void KoItemToolTip::paintEvent ( QPaintEvent * e)
overrideprotected

Definition at line 97 of file KoItemToolTip.cpp.

98{
99 QPainter p(this);
100 d->document->drawContents(&p, rect());
101 p.drawRect(0, 0, width() - 1, height() - 1);
102}
const Params2D p

References d, and p.

◆ Private()

KoItemToolTip::Private ( )
inline

Definition at line 28 of file KoItemToolTip.cpp.

28: document(0) { }
QTextDocument * document

◆ showTip()

void KoItemToolTip::showTip ( QWidget * widget,
const QPoint & pos,
const QStyleOptionViewItem & option,
const QModelIndex & index )

Definition at line 45 of file KoItemToolTip.cpp.

46{
47 QTextDocument *doc = createDocument(index);
48
49 QPoint p = (isVisible() && index == d->index) ? d->pos : pos;
50
51 if (!isVisible() || index != d->index || doc->toHtml() != d->document->toHtml())
52 {
53 d->pos = p;
54 d->index = index;
55 delete d->document;
56 d->document = doc;
57 updatePosition(widget, p, option);
58 if (!isVisible())
59 show();
60 else
61 update();
62 d->timer.start(10000, this);
63 }
64 else
65 delete doc;
66}
void updatePosition(QWidget *widget, const QPoint &pos, const QStyleOptionViewItem &option)
virtual QTextDocument * createDocument(const QModelIndex &index)=0
bool update(QSpinBox *spinBox)

References createDocument(), d, index, p, pos, and updatePosition().

◆ sizeHint()

QSize KoItemToolTip::sizeHint ( ) const
override

Definition at line 92 of file KoItemToolTip.cpp.

93{
94 return d->document->size().toSize();
95}

References d.

◆ timerEvent()

void KoItemToolTip::timerEvent ( QTimerEvent * e)
overrideprotected

Definition at line 104 of file KoItemToolTip.cpp.

105{
106 if (e->timerId() == d->timer.timerId()) {
107 hide();
108 }
109}

References d.

◆ updatePosition()

void KoItemToolTip::updatePosition ( QWidget * widget,
const QPoint & pos,
const QStyleOptionViewItem & option )
private

Definition at line 68 of file KoItemToolTip.cpp.

69{
70 QScreen *screen = widget->screen();
71 const QRect drect = screen->availableGeometry();
72 const QSize size = sizeHint();
73 const int width = size.width(), height = size.height();
74 const QPoint gpos = widget->mapToGlobal(pos);
75 const QRect irect(widget->mapToGlobal(option.rect.topLeft()), option.rect.size());
76
77 int y = gpos.y() + 20;
78 if (y + height > drect.bottom())
79 y = qMax(drect.top(), irect.top() - height);
80
81 int x;
82 if (gpos.x() + width < drect.right())
83 x = gpos.x();
84 else
85 x = qMax(drect.left(), gpos.x() - width);
86
87 move(x, y);
88
89 resize(sizeHint());
90 }
QSize sizeHint() const override
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References pos, and sizeHint().

Member Data Documentation

◆ d

Private* const KoItemToolTip::d
private

Definition at line 58 of file KoItemToolTip.h.

◆ document

QTextDocument* KoItemToolTip::document

Definition at line 23 of file KoItemToolTip.cpp.

◆ index

QPersistentModelIndex KoItemToolTip::index

Definition at line 24 of file KoItemToolTip.cpp.

◆ pos

QPoint KoItemToolTip::pos

Definition at line 25 of file KoItemToolTip.cpp.

◆ timer

QBasicTimer KoItemToolTip::timer

Definition at line 26 of file KoItemToolTip.cpp.


The documentation for this class was generated from the following files: