Changeset View
Changeset View
Standalone View
Standalone View
sidebar/ToolTips/tooltipmanager.cpp
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 51 | Private() : | |||
---|---|---|---|---|---|
52 | tooltip(nullptr), | 52 | tooltip(nullptr), | ||
53 | view(nullptr), | 53 | view(nullptr), | ||
54 | timer(nullptr), | 54 | timer(nullptr), | ||
55 | delay(300) | 55 | delay(300) | ||
56 | { } | 56 | { } | ||
57 | 57 | | |||
58 | KToolTipWidget *tooltip; | 58 | KToolTipWidget *tooltip; | ||
59 | QWidget* view; | 59 | QWidget* view; | ||
60 | QAbstractItemModel *model; | 60 | const QAbstractItemModel *model; | ||
61 | QTimer* timer; | 61 | QTimer* timer; | ||
62 | QPersistentModelIndex item; | 62 | QPersistentModelIndex item; | ||
63 | QRect itemRect; | 63 | QRect itemRect; | ||
64 | int delay; | 64 | int delay; | ||
65 | ToolTipPosition toolTipPosition; | 65 | ToolTipPosition toolTipPosition; | ||
66 | }; | 66 | }; | ||
67 | 67 | | |||
68 | ToolTipManager::ToolTipManager(QAbstractItemModel *model, QWidget* parent, ToolTipPosition toolTipPosition) | 68 | ToolTipManager::ToolTipManager(const QAbstractItemModel *model, QWidget* parent, ToolTipPosition toolTipPosition) | ||
69 | : QObject(parent) | 69 | : QObject(parent) | ||
70 | , d(new ToolTipManager::Private) | 70 | , d(new ToolTipManager::Private) | ||
71 | { | 71 | { | ||
72 | d->view = parent; | 72 | d->view = parent; | ||
73 | d->model = model; | 73 | d->model = model; | ||
74 | d->toolTipPosition = toolTipPosition; | 74 | d->toolTipPosition = toolTipPosition; | ||
75 | d->tooltip = new KToolTipWidget(d->view); | 75 | d->tooltip = new KToolTipWidget(d->view); | ||
76 | d->tooltip->setHideDelay(0); | 76 | d->tooltip->setHideDelay(0); | ||
77 | 77 | | |||
78 | d->timer = new QTimer(this); | 78 | d->timer = new QTimer(this); | ||
79 | d->timer->setSingleShot(true); | 79 | d->timer->setSingleShot(true); | ||
80 | connect(d->timer, &QTimer::timeout, this, &ToolTipManager::prepareToolTip); | 80 | connect(d->timer, &QTimer::timeout, this, &ToolTipManager::prepareToolTip); | ||
81 | 81 | | |||
82 | 82 | | |||
83 | d->view->installEventFilter(this); | 83 | d->view->installEventFilter(this); | ||
84 | } | 84 | } | ||
85 | 85 | | |||
86 | ToolTipManager::~ToolTipManager() | 86 | ToolTipManager::~ToolTipManager() | ||
87 | { | 87 | { | ||
88 | delete d; | 88 | delete d; | ||
89 | } | 89 | } | ||
90 | 90 | | |||
91 | void ToolTipManager::setModel(const QAbstractItemModel *model) | ||||
92 | { | ||||
93 | d->model = model; | ||||
94 | } | ||||
95 | | ||||
96 | const QAbstractItemModel *ToolTipManager::model() const | ||||
97 | { | ||||
98 | return d->model; | ||||
99 | } | ||||
100 | | ||||
91 | bool ToolTipManager::eventFilter(QObject* watched, QEvent* event) | 101 | bool ToolTipManager::eventFilter(QObject* watched, QEvent* event) | ||
92 | { | 102 | { | ||
93 | if (watched == d->view) { | 103 | if (watched == d->view) { | ||
94 | switch (event->type()) { | 104 | switch (event->type()) { | ||
95 | case QEvent::Leave: | 105 | case QEvent::Leave: | ||
96 | case QEvent::MouseButtonPress: | 106 | case QEvent::MouseButtonPress: | ||
97 | hideToolTip(); | 107 | hideToolTip(); | ||
98 | break; | 108 | break; | ||
▲ Show 20 Lines • Show All 140 Lines • Show Last 20 Lines |