Changeset View
Changeset View
Standalone View
Standalone View
plugins/projectmanagerview/projectmodelitemdelegate.cpp
Show All 14 Lines | 1 | /* This file is part of KDevelop | |||
---|---|---|---|---|---|
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "projectmodelitemdelegate.h" | 20 | #include "projectmodelitemdelegate.h" | ||
21 | 21 | | |||
22 | #include "vcsoverlayproxymodel.h" | 22 | #include "vcsoverlayproxymodel.h" | ||
23 | #include <debug.h> | ||||
23 | 24 | | |||
25 | #include <project/projectmodel.h> | ||||
26 | #include <language/duchain/duchainutils.h> | ||||
27 | #include <language/duchain/duchainlock.h> | ||||
28 | #include <language/duchain/duchain.h> | ||||
29 | #include <language/util/navigationtooltip.h> | ||||
30 | #include <util/path.h> | ||||
31 | | ||||
32 | #include <QHelpEvent> | ||||
33 | #include <QToolTip> | ||||
34 | #include <QAbstractItemView> | ||||
24 | #include <QPainter> | 35 | #include <QPainter> | ||
25 | 36 | | |||
37 | using namespace KDevelop; | ||||
38 | | ||||
26 | ProjectModelItemDelegate::ProjectModelItemDelegate(QObject* parent) | 39 | ProjectModelItemDelegate::ProjectModelItemDelegate(QObject* parent) | ||
27 | : QItemDelegate(parent) | 40 | : QItemDelegate(parent) | ||
28 | {} | 41 | {} | ||
29 | 42 | | |||
30 | static QIcon::Mode IconMode( QStyle::State state ) | 43 | static QIcon::Mode IconMode( QStyle::State state ) | ||
31 | { | 44 | { | ||
32 | if (!(state & QStyle::State_Enabled)) { | 45 | if (!(state & QStyle::State_Enabled)) { | ||
33 | return QIcon::Disabled; | 46 | return QIcon::Disabled; | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | 165 | if (option.state & QStyle::State_Selected) { | |||
153 | painter->setPen(option.palette.color(cg, QPalette::HighlightedText)); | 166 | painter->setPen(option.palette.color(cg, QPalette::HighlightedText)); | ||
154 | } else { | 167 | } else { | ||
155 | painter->setPen(option.palette.color(cg, QPalette::Text)); | 168 | painter->setPen(option.palette.color(cg, QPalette::Text)); | ||
156 | } | 169 | } | ||
157 | 170 | | |||
158 | QFontMetrics fm(painter->fontMetrics()); | 171 | QFontMetrics fm(painter->fontMetrics()); | ||
159 | painter->drawText(rect, fm.elidedText(text, Qt::ElideRight, rect.width())); | 172 | painter->drawText(rect, fm.elidedText(text, Qt::ElideRight, rect.width())); | ||
160 | } | 173 | } | ||
174 | | ||||
175 | bool ProjectModelItemDelegate::helpEvent(QHelpEvent* event, | ||||
176 | QAbstractItemView* view, const QStyleOptionViewItem& option, | ||||
177 | const QModelIndex& index) | ||||
178 | { | ||||
179 | if (!event || !view) { | ||||
180 | return false; | ||||
181 | } | ||||
182 | | ||||
183 | if (event->type() == QEvent::ToolTip) { | ||||
184 | QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event); | ||||
185 | | ||||
186 | // explicitely close current tooltip, as its autoclose margins overlap items | ||||
187 | if ((m_tooltippedIndex != index) && m_tooltip) { | ||||
188 | m_tooltip->close(); | ||||
189 | m_tooltip.clear(); | ||||
190 | } | ||||
191 | | ||||
192 | const ProjectBaseItem* it = index.data(ProjectModel::ProjectItemRole).value<ProjectBaseItem*>(); | ||||
193 | | ||||
194 | // show navigation tooltip for files | ||||
195 | if (it && it->file()) { | ||||
196 | if (!m_tooltip) { | ||||
197 | m_tooltippedIndex = index; | ||||
198 | KDevelop::DUChainReadLocker lock(KDevelop::DUChain::lock()); | ||||
199 | const TopDUContext* top = DUChainUtils::standardContextForUrl(it->file()->path().toUrl()); | ||||
200 | | ||||
201 | if (top) { | ||||
202 | QWidget* navigationWidget = top->createNavigationWidget(); | ||||
203 | if (navigationWidget) { | ||||
204 | // force possible existing normal tooltip for other list item to hide | ||||
205 | // Seems that is still only done with a small delay though, | ||||
206 | // but the API seems not to allow more control. | ||||
207 | QToolTip::hideText(); | ||||
208 | | ||||
209 | m_tooltip = new KDevelop::NavigationToolTip(view, helpEvent->globalPos() + QPoint(40, 0), navigationWidget); | ||||
210 | m_tooltip->resize(navigationWidget->sizeHint() + QSize(10, 10)); | ||||
211 | auto rect = view->visualRect(m_tooltippedIndex); | ||||
212 | rect.moveTopLeft(view->mapToGlobal(rect.topLeft())); | ||||
213 | m_tooltip->setHandleRect(rect); | ||||
214 | ActiveToolTip::showToolTip(m_tooltip); | ||||
215 | } | ||||
216 | } | ||||
217 | } | ||||
218 | | ||||
219 | // tooltip successfully handled by us? | ||||
220 | if (m_tooltip) { | ||||
221 | return true; | ||||
222 | } | ||||
223 | } | ||||
224 | } | ||||
225 | | ||||
226 | return QItemDelegate::helpEvent(event, view, option, index); | ||||
227 | } |