File indexing completed on 2024-04-28 04:21:03
0001 // SPDX-FileCopyrightText: 2003-2020 The KPhotoAlbum Development Team 0002 // SPDX-FileCopyrightText: 2021 Johannes Zarl-Zierl <johannes@zarl-zierl.at> 0003 // SPDX-FileCopyrightText: 2022 Johannes Zarl-Zierl <johannes@zarl-zierl.at> 0004 // 0005 // SPDX-License-Identifier: GPL-2.0-or-later 0006 0007 #include "InfoDialog.h" 0008 0009 #include "Grid.h" 0010 #include "MetaDataDisplay.h" 0011 #include <kpaexif/Info.h> 0012 0013 #include <DB/ImageDB.h> 0014 #include <ImageManager/AsyncLoader.h> 0015 #include <ImageManager/ImageRequest.h> 0016 #include <kpabase/SettingsData.h> 0017 0018 #include <KLocalizedString> 0019 #include <QComboBox> 0020 #include <QDialogButtonBox> 0021 #include <QLabel> 0022 #include <QLayout> 0023 #include <QLineEdit> 0024 #include <QPushButton> 0025 #include <QTabWidget> 0026 #include <QTextCodec> 0027 0028 using Utilities::StringSet; 0029 0030 Exif::InfoDialog::InfoDialog(const DB::FileName &fileName, QWidget *parent) 0031 : QDialog(parent) 0032 { 0033 setWindowTitle(i18nc("@title:window", "Exif Information and file metadata")); 0034 0035 setAttribute(Qt::WA_DeleteOnClose); 0036 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close); 0037 buttonBox->button(QDialogButtonBox::Close)->setShortcut(Qt::CTRL | Qt::Key_Return); 0038 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0039 0040 QWidget *top = new QWidget(this); 0041 QVBoxLayout *vlay = new QVBoxLayout(top); 0042 setLayout(vlay); 0043 vlay->addWidget(top); 0044 0045 // -------------------------------------------------- File name and pixmap 0046 QHBoxLayout *hlay = new QHBoxLayout; 0047 vlay->addLayout(hlay); 0048 m_fileNameLabel = new QLabel(top); 0049 QFont fnt = font(); 0050 fnt.setPointSize((int)(fnt.pointSize() * 1.2)); 0051 fnt.setWeight(QFont::Bold); 0052 m_fileNameLabel->setFont(fnt); 0053 m_fileNameLabel->setAlignment(Qt::AlignCenter); 0054 hlay->addWidget(m_fileNameLabel, 1); 0055 0056 m_pix = new QLabel(top); 0057 hlay->addWidget(m_pix); 0058 0059 // -------------------------------------------------- Exif info part 0060 0061 auto *exifWidget = new QWidget; 0062 auto *exifWidgetLayout = new QVBoxLayout(exifWidget); 0063 0064 // -------------------------------------------------- Exif Grid 0065 m_grid = new Exif::Grid(top); 0066 exifWidgetLayout->addWidget(m_grid); 0067 0068 // -------------------------------------------------- Current Search 0069 hlay = new QHBoxLayout; 0070 exifWidgetLayout->addLayout(hlay); 0071 0072 m_searchBox = new QLineEdit(top); 0073 m_searchBox->setPlaceholderText(i18nc("@label:textbox The search box allows the user to filter by exif label names", "Filter labels ...")); 0074 hlay->addWidget(m_searchBox); 0075 hlay->addStretch(1); 0076 0077 QLabel *iptcLabel = new QLabel(i18n("IPTC character set:"), top); 0078 m_iptcCharset = new QComboBox(top); 0079 QStringList charsets; 0080 QList<QByteArray> charsetsBA = QTextCodec::availableCodecs(); 0081 for (QList<QByteArray>::const_iterator it = charsetsBA.constBegin(); it != charsetsBA.constEnd(); ++it) 0082 charsets << QLatin1String(*it); 0083 m_iptcCharset->insertItems(0, charsets); 0084 m_iptcCharset->setCurrentIndex(qMax(0, QTextCodec::availableCodecs().indexOf(Settings::SettingsData::instance()->iptcCharset().toLatin1()))); 0085 hlay->addWidget(iptcLabel); 0086 hlay->addWidget(m_iptcCharset); 0087 0088 // -------------------------------------------------- File metadata part 0089 0090 m_metaDataDisplay = new MetaDataDisplay; 0091 0092 // -------------------------------------------------- Tab widget 0093 auto *tabWidget = new QTabWidget; 0094 vlay->addWidget(tabWidget); 0095 tabWidget->addTab(exifWidget, i18n("Exif info")); 0096 tabWidget->addTab(m_metaDataDisplay, i18n("File metadata")); 0097 0098 // -------------------------------------------------- layout done 0099 connect(m_searchBox, &QLineEdit::textChanged, m_grid, &Grid::updateSearchString); 0100 connect(m_iptcCharset, &QComboBox::textActivated, m_grid, &Grid::setupUI); 0101 setImage(fileName); 0102 0103 vlay->addWidget(buttonBox); 0104 } 0105 0106 QSize Exif::InfoDialog::sizeHint() const 0107 { 0108 return QSize(800, 400); 0109 } 0110 0111 void Exif::InfoDialog::pixmapLoaded(ImageManager::ImageRequest *request, const QImage &image) 0112 { 0113 if (request->loadedOK()) 0114 m_pix->setPixmap(QPixmap::fromImage(image)); 0115 } 0116 0117 void Exif::InfoDialog::setImage(const DB::FileName &fileName) 0118 { 0119 m_fileNameLabel->setText(fileName.relative()); 0120 m_grid->setFileName(fileName); 0121 m_metaDataDisplay->setFileName(fileName.absolute()); 0122 0123 const auto info = DB::ImageDB::instance()->info(fileName); 0124 ImageManager::ImageRequest *request = new ImageManager::ImageRequest(fileName, QSize(128, 128), info->angle(), this); 0125 request->setPriority(ImageManager::Viewer); 0126 ImageManager::AsyncLoader::instance()->load(request); 0127 } 0128 0129 void Exif::InfoDialog::enterEvent(QEvent *) 0130 { 0131 m_grid->setFocus(); 0132 } 0133 0134 // vi:expandtab:tabstop=4 shiftwidth=4: 0135 0136 #include "moc_InfoDialog.cpp"