File indexing completed on 2025-04-27 03:58:35

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2006-02-21
0007  * Description : a generic list view item widget to
0008  *               display metadata
0009  *
0010  * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "metadatalistviewitem.h"
0017 
0018 // Qt includes
0019 
0020 #include <QPalette>
0021 #include <QFont>
0022 #include <QPainter>
0023 
0024 // KDE includes
0025 
0026 #include <klocalizedstring.h>
0027 
0028 // Local includes
0029 
0030 #include "ditemtooltip.h"
0031 
0032 namespace Digikam
0033 {
0034 
0035 MetadataListViewItem::MetadataListViewItem(QTreeWidgetItem* const parent, const QString& key,
0036                                            const QString& title, const QString& value)
0037     : QTreeWidgetItem(parent),
0038       m_key          (key)
0039 {
0040     setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator);
0041     setText(0, title);
0042     setToolTip(0, title);
0043     setDisabled(false);
0044     QString tagVal = value.simplified();
0045 
0046     if (tagVal.length() > 512)
0047     {
0048         tagVal.truncate(512);
0049         tagVal.append(QLatin1String("..."));
0050     }
0051 
0052     setText(1, tagVal);
0053 
0054     DToolTipStyleSheet cnt;
0055     setToolTip(1, QLatin1String("<qt><p>") + cnt.breakString(tagVal) + QLatin1String("</p></qt>"));
0056 }
0057 
0058 MetadataListViewItem::MetadataListViewItem(QTreeWidgetItem* const parent, const QString& key,
0059                                            const QString& title)
0060     : QTreeWidgetItem(parent),
0061       m_key          (key)
0062 {
0063     setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator);
0064     setText(0, title);
0065     setToolTip(0, title);
0066     setDisabled(true);
0067     setText(1, i18n("Unavailable"));
0068     QFont fnt = font(1);
0069     fnt.setItalic(true);
0070     setFont(1, fnt);
0071 }
0072 
0073 MetadataListViewItem::~MetadataListViewItem()
0074 {
0075 }
0076 
0077 QString MetadataListViewItem::getKey() const
0078 {
0079     return m_key;
0080 }
0081 
0082 QString MetadataListViewItem::getTitle() const
0083 {
0084     return text(0);
0085 }
0086 
0087 QString MetadataListViewItem::getValue() const
0088 {
0089     return text(1);
0090 }
0091 
0092 } // namespace Digikam