File indexing completed on 2024-05-19 04:56:00

0001 /**
0002  * \file coretaggedfileiconprovider.cpp
0003  * Provides icons for tagged files.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 29-Mar-2011
0008  *
0009  * Copyright (C) 2011-2024  Urs Fleisch
0010  *
0011  * This file is part of Kid3.
0012  *
0013  * Kid3 is free software; you can redistribute it and/or modify
0014  * it under the terms of the GNU General Public License as published by
0015  * the Free Software Foundation; either version 2 of the License, or
0016  * (at your option) any later version.
0017  *
0018  * Kid3 is distributed in the hope that it will be useful,
0019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0021  * GNU General Public License for more details.
0022  *
0023  * You should have received a copy of the GNU General Public License
0024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0025  */
0026 
0027 #include "coretaggedfileiconprovider.h"
0028 #include <QByteArray>
0029 #include "taggedfile.h"
0030 #include "tagconfig.h"
0031 
0032 /**
0033  * Constructor.
0034  */
0035 CoreTaggedFileIconProvider::CoreTaggedFileIconProvider()
0036 {
0037 }
0038 
0039 /**
0040  * Set icon to be used for modified files.
0041  * @param icon modified icon
0042  */
0043 void CoreTaggedFileIconProvider::setModifiedIcon(const QVariant& icon) {
0044   Q_UNUSED(icon)
0045 }
0046 
0047 /**
0048  * Set the requested size for icons.
0049  *
0050  * The size set with this method will be used to create icons.
0051  *
0052  * @param size icon size, the default is 16x16.
0053  */
0054 void CoreTaggedFileIconProvider::setRequestedSize(const QSize& size)
0055 {
0056   Q_UNUSED(size)
0057 }
0058 
0059 /**
0060  * Get an icon for a tagged file.
0061  *
0062  * @param taggedFile tagged file
0063  *
0064  * @return icon for tagged file
0065  */
0066 QVariant CoreTaggedFileIconProvider::iconForTaggedFile(const TaggedFile* taggedFile)
0067 {
0068   Q_UNUSED(taggedFile)
0069   return QVariant();
0070 }
0071 
0072 /**
0073  * Get an icon ID for a tagged file.
0074  *
0075  * @param taggedFile tagged file
0076  *
0077  * @return icon ID for tagged file
0078  */
0079 QByteArray CoreTaggedFileIconProvider::iconIdForTaggedFile(
0080     const TaggedFile* taggedFile) const
0081 {
0082   if (taggedFile) {
0083     if (taggedFile->isChanged()) {
0084       return "modified";
0085     }
0086     if (!taggedFile->isTagInformationRead())
0087       return "null";
0088 
0089     QByteArray id;
0090     if (taggedFile->hasTag(Frame::Tag_1))
0091       id += "v1";
0092     if (taggedFile->hasTag(Frame::Tag_2))
0093       id += "v2";
0094     if (taggedFile->hasTag(Frame::Tag_3))
0095       id += "v3";
0096     if (id.isEmpty())
0097       id = "notag";
0098     return id;
0099   }
0100   return "";
0101 }
0102 
0103 /**
0104  * Get pixmap for an icon ID.
0105  * @param id icon ID as returned by iconIdForTaggedFile(), or data for image
0106  * set with setImageData()
0107  * @return pixmap for @a id.
0108  */
0109 QVariant CoreTaggedFileIconProvider::pixmapForIconId(const QByteArray& id)
0110 {
0111   Q_UNUSED(id)
0112   return QVariant();
0113 }
0114 
0115 /**
0116  * Get background color for a tagged file.
0117  *
0118  * @param taggedFile tagged file
0119  *
0120  * @return background color for tagged file, invalid color if background
0121  * should not be set
0122  */
0123 QVariant CoreTaggedFileIconProvider::backgroundForTaggedFile(
0124     const TaggedFile* taggedFile) {
0125   Q_UNUSED(taggedFile)
0126   return QVariant();
0127 }
0128 
0129 /**
0130  * Get brush with color for a context.
0131  * @param context color context
0132  * @return brush.
0133  */
0134 QVariant CoreTaggedFileIconProvider::colorForContext(ColorContext context) const
0135 {
0136   switch (context) {
0137   case ColorContext::None:
0138     break;
0139   case ColorContext::Marked:
0140     return QLatin1String("*");
0141   case ColorContext::Error:
0142     return QLatin1String("E");
0143   }
0144   return QVariant();
0145 }
0146 
0147 /**
0148  * Get context for a brush.
0149  * @param color brush
0150  * @return color context.
0151  */
0152 ColorContext CoreTaggedFileIconProvider::contextForColor(const QVariant& color) const
0153 {
0154   if (QString code = color.toString(); code == QLatin1String("E")) {
0155     return ColorContext::Error;
0156   } else if (code == QLatin1String("*")) {
0157     return ColorContext::Marked;
0158   }
0159   return ColorContext::None;
0160 }