diff --git a/core/libs/widgets/itemview/itemviewtooltip.cpp b/core/libs/widgets/itemview/itemviewtooltip.cpp index e33d04729b..0db4f8c8b9 100644 --- a/core/libs/widgets/itemview/itemviewtooltip.cpp +++ b/core/libs/widgets/itemview/itemviewtooltip.cpp @@ -1,210 +1,211 @@ /* ============================================================ * * This file is a part of digiKam project * http://www.digikam.org * * Date : 2009-04-24 * Description : A DItemToolTip prepared for use in QAbstractItemViews * * Copyright (C) 2009-2011 by Marcel Wiesweg * * This program 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, or (at your option) * any later version. * * This program 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. * * ============================================================ */ #include "itemviewtooltip.h" // Qt includes #include #include // Local includes #include "digikam_debug.h" namespace Digikam { class ItemViewToolTip::Private { public: explicit Private() { view = 0; filterInstalled = false; } QAbstractItemView* view; QModelIndex index; QRect rect; QString text; bool filterInstalled; }; -ItemViewToolTip::ItemViewToolTip(QAbstractItemView* view) - : DItemToolTip(view), d(new Private) +ItemViewToolTip::ItemViewToolTip(QAbstractItemView* const view) + : DItemToolTip(view), + d(new Private) { d->view = view; setBackgroundRole(QPalette::ToolTipBase); setPalette(QToolTip::palette()); setMouseTracking(true); } ItemViewToolTip::~ItemViewToolTip() { delete d; } QAbstractItemView* ItemViewToolTip::view() const { return d->view; } QAbstractItemModel* ItemViewToolTip::model() const { return d->view ? d->view->model() : 0; } QModelIndex ItemViewToolTip::currentIndex() const { return d->index; } void ItemViewToolTip::show(const QStyleOptionViewItem& option, const QModelIndex& index) { d->index = index; d->rect = option.rect; d->rect.moveTopLeft(d->view->viewport()->mapToGlobal(d->rect.topLeft())); updateToolTip(); reposition(); if (isHidden() && !toolTipIsEmpty()) { if (!d->filterInstalled) { qApp->installEventFilter(this); d->filterInstalled = true; } DItemToolTip::show(); } } void ItemViewToolTip::setTipContents(const QString& tipContents) { d->text = tipContents; updateToolTip(); } QString ItemViewToolTip::tipContents() { return d->text; } QRect ItemViewToolTip::repositionRect() { return d->rect; } void ItemViewToolTip::hideEvent(QHideEvent*) { d->rect = QRect(); d->index = QModelIndex(); if (d->filterInstalled) { d->filterInstalled = false; qApp->removeEventFilter(this); } } // The following code is inspired by qtooltip.cpp, // Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). bool ItemViewToolTip::eventFilter(QObject* o, QEvent* e) { switch (e->type()) { #ifdef Q_OS_OSX case QEvent::KeyPress: case QEvent::KeyRelease: { int key = static_cast(e)->key(); Qt::KeyboardModifiers mody = static_cast(e)->modifiers(); if (!(mody & Qt::KeyboardModifierMask) && key != Qt::Key_Shift && key != Qt::Key_Control && key != Qt::Key_Alt && key != Qt::Key_Meta) { hide(); } break; } #endif // Q_OS_OSX case QEvent::Leave: hide(); // could add a 300ms timer here, like Qt break; case QEvent::WindowActivate: case QEvent::WindowDeactivate: case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseButtonDblClick: case QEvent::FocusIn: case QEvent::FocusOut: case QEvent::Wheel: hide(); break; case QEvent::MouseMove: { // needs mouse tracking, obviously if (o == d->view->viewport() && !d->rect.isNull() && !d->rect.contains(static_cast(e)->globalPos())) { hide(); } break; } default: break; } return false; } void ItemViewToolTip::mouseMoveEvent(QMouseEvent* e) { if (d->rect.isNull()) { return; } QPoint pos = e->globalPos(); pos = d->view->viewport()->mapFromGlobal(pos); if (!d->rect.contains(pos)) { hide(); } DItemToolTip::mouseMoveEvent(e); } } // namespace Digikam diff --git a/core/libs/widgets/itemview/itemviewtooltip.h b/core/libs/widgets/itemview/itemviewtooltip.h index f917e6f340..ed140b75ff 100644 --- a/core/libs/widgets/itemview/itemviewtooltip.h +++ b/core/libs/widgets/itemview/itemviewtooltip.h @@ -1,81 +1,81 @@ /* ============================================================ * * This file is a part of digiKam project * http://www.digikam.org * * Date : 2009-04-24 * Description : A DItemToolTip prepared for use in QAbstractItemViews * * Copyright (C) 2009-2011 by Marcel Wiesweg * * This program 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, or (at your option) * any later version. * * This program 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. * * ============================================================ */ #ifndef DIGIKAM_ITEM_VIEW_TOOL_TIP_H #define DIGIKAM_ITEM_VIEW_TOOL_TIP_H // Qt includes #include // Local includes #include "ditemtooltip.h" #include "digikam_export.h" namespace Digikam { class DIGIKAM_EXPORT ItemViewToolTip : public DItemToolTip { public: - explicit ItemViewToolTip(QAbstractItemView* view); + explicit ItemViewToolTip(QAbstractItemView* const view); ~ItemViewToolTip(); QAbstractItemView* view() const; QAbstractItemModel* model() const; QModelIndex currentIndex() const; /** * Show the tooltip for the given item. * The rect of the given option is taken as area for which * the tooltip is shown. */ void show(const QStyleOptionViewItem& option, const QModelIndex& index); void setTipContents(const QString& tipContents); /** * Default implementation is based on setTipContents(). * Reimplement if you dynamically provide the contents. */ virtual QString tipContents(); protected: virtual QRect repositionRect(); bool eventFilter(QObject* o, QEvent* e); void hideEvent(QHideEvent*); void mouseMoveEvent(QMouseEvent* e); private: class Private; Private* const d; }; } // namespace Digikam #endif // DIGIKAM_ITEM_VIEW_TOOL_TIP_H diff --git a/core/libs/widgets/metadata/metadatalistviewitem.cpp b/core/libs/widgets/metadata/metadatalistviewitem.cpp index dc3ab8ed01..8a0551f286 100644 --- a/core/libs/widgets/metadata/metadatalistviewitem.cpp +++ b/core/libs/widgets/metadata/metadatalistviewitem.cpp @@ -1,101 +1,101 @@ /* ============================================================ * * This file is a part of digiKam project * http://www.digikam.org * * Date : 2006-02-21 * Description : a generic list view item widget to * display metadata * * Copyright (C) 2006-2018 by Gilles Caulier * * This program 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, or (at your option) * any later version. * * This program 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. * * ============================================================ */ #include "metadatalistviewitem.h" // Qt includes #include #include #include // KDE includes #include // Local includes #include "ditemtooltip.h" namespace Digikam { MetadataListViewItem::MetadataListViewItem(QTreeWidgetItem* const parent, const QString& key, - const QString& title, const QString& value) + const QString& title, const QString& value) : QTreeWidgetItem(parent), m_key(key) { setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator); setText(0, title); setToolTip(0, title); setDisabled(false); QString tagVal = value.simplified(); if (tagVal.length() > 512) { tagVal.truncate(512); tagVal.append(QLatin1String("...")); } setText(1, tagVal); DToolTipStyleSheet cnt; setToolTip(1, QLatin1String("

") + cnt.breakString(tagVal) + QLatin1String("

")); } MetadataListViewItem::MetadataListViewItem(QTreeWidgetItem* const parent, const QString& key, - const QString& title) + const QString& title) : QTreeWidgetItem(parent), m_key(key) { setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator); setText(0, title); setToolTip(0, title); setDisabled(true); setText(1, i18n("Unavailable")); QFont fnt = font(1); fnt.setItalic(true); setFont(1, fnt); } MetadataListViewItem::~MetadataListViewItem() { } QString MetadataListViewItem::getKey() { return m_key; } QString MetadataListViewItem::getTitle() { return text(0); } QString MetadataListViewItem::getValue() { return text(1); } } // namespace Digikam