diff --git a/Exif/Grid.cpp b/Exif/Grid.cpp index f6a2d41c..bfe56aa4 100644 --- a/Exif/Grid.cpp +++ b/Exif/Grid.cpp @@ -1,212 +1,212 @@ -/* Copyright (C) 2012 Jesper K. Pedersen +/* Copyright (C) 2012-2019 The KPhotoAlbum Development Team 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 of the License, 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. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "Grid.h" #include "Info.h" #include #include #include #include #include #include #include #include Exif::Grid::Grid(QWidget *parent) : QScrollArea(parent) { setFocusPolicy(Qt::WheelFocus); setWidgetResizable(true); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); viewport()->installEventFilter(this); setMinimumSize(800, 400); } class Background : public QWidget { protected: void paintEvent(QPaintEvent *event) override { QPainter painter(this); painter.fillRect(event->rect(), QColor(Qt::white)); - }; + } }; void Exif::Grid::setupUI(const QString &charset) { delete this->widget(); m_labels.clear(); Background *widget = new Background; QGridLayout *layout = new QGridLayout(widget); layout->setSpacing(0); int row = 0; const QMap map = Exif::Info::instance()->infoForDialog(m_fileName, charset); const StringSet groups = exifGroups(map); for (const QString &group : groups) { layout->addWidget(headerLabel(group), row++, 0, 1, 4); // Items of group const QMap items = itemsForGroup(group, map); QStringList sorted = items.keys(); sorted.sort(); int elements = sorted.size(); int perCol = (elements + 1) / 2; int count = 0; for (const QString &key : sorted) { const int subrow = (count % perCol); const QColor color = (subrow & 1) ? Qt::white : QColor(226, 235, 250); QPair pair = infoLabelPair(exifNameNoGroup(key), items[key].join(QLatin1String(", ")), color); int col = (count / perCol) * 2; layout->addWidget(pair.first, row + subrow, col); layout->addWidget(pair.second, row + subrow, col + 1); count++; } row += perCol; } setWidget(widget); widget->show(); QTimer::singleShot(0, this, SLOT(updateWidgetSize())); } QLabel *Exif::Grid::headerLabel(const QString &title) { QLabel *label = new QLabel(title); QPalette pal; pal.setBrush(QPalette::Background, Qt::lightGray); label->setPalette(pal); label->setAutoFillBackground(true); label->setAlignment(Qt::AlignCenter); return label; } QPair Exif::Grid::infoLabelPair(const QString &title, const QString &value, const QColor &color) { QLabel *keyLabel = new QLabel(title); QLabel *valueLabel = new QLabel(value); QPalette pal; pal.setBrush(QPalette::Background, color); keyLabel->setPalette(pal); valueLabel->setPalette(pal); keyLabel->setAutoFillBackground(true); valueLabel->setAutoFillBackground(true); m_labels.append(qMakePair(keyLabel, valueLabel)); return qMakePair(keyLabel, valueLabel); } void Exif::Grid::updateWidgetSize() { widget()->setFixedSize(viewport()->width(), widget()->height()); } StringSet Exif::Grid::exifGroups(const QMap &exifInfo) { StringSet result; for (QMap::ConstIterator it = exifInfo.begin(); it != exifInfo.end(); ++it) { result.insert(groupName(it.key())); } return result; } QMap Exif::Grid::itemsForGroup(const QString &group, const QMap &exifInfo) { QMap result; for (QMap::ConstIterator it = exifInfo.begin(); it != exifInfo.end(); ++it) { if (groupName(it.key()) == group) result.insert(it.key(), it.value()); } return result; } QString Exif::Grid::groupName(const QString &exifName) { QStringList list = exifName.split(QString::fromLatin1(".")); list.pop_back(); return list.join(QString::fromLatin1(".")); } QString Exif::Grid::exifNameNoGroup(const QString &fullName) { return fullName.split(QString::fromLatin1(".")).last(); } void Exif::Grid::scroll(int dy) { verticalScrollBar()->setValue(verticalScrollBar()->value() + dy); } void Exif::Grid::updateSearchString(const QString &search) { for (QPair tuple : m_labels) { const bool matches = tuple.first->text().contains(search, Qt::CaseInsensitive) && search.length() != 0; QPalette pal = tuple.first->palette(); pal.setBrush(QPalette::Foreground, matches ? Qt::red : Qt::black); tuple.first->setPalette(pal); tuple.second->setPalette(pal); QFont fnt = tuple.first->font(); fnt.setBold(matches); tuple.first->setFont(fnt); tuple.second->setFont(fnt); } } void Exif::Grid::keyPressEvent(QKeyEvent *e) { switch (e->key()) { case Qt::Key_Down: scroll(20); return; case Qt::Key_Up: scroll(-20); return; case Qt::Key_PageDown: scroll(viewport()->height() - 20); return; case Qt::Key_PageUp: scroll(-(viewport()->height() - 20)); return; case Qt::Key_Escape: QScrollArea::keyPressEvent(e); // Propagate to close dialog. return; } } bool Exif::Grid::eventFilter(QObject *object, QEvent *event) { if (object == viewport() && event->type() == QEvent::Resize) { QResizeEvent *re = static_cast(event); widget()->setFixedSize(re->size().width(), widget()->height()); } return false; } void Exif::Grid::setFileName(const DB::FileName &fileName) { m_fileName = fileName; setupUI(Settings::SettingsData::instance()->iptcCharset()); } // vi:expandtab:tabstop=4 shiftwidth=4: diff --git a/Exif/Grid.h b/Exif/Grid.h index c2470579..5a32d933 100644 --- a/Exif/Grid.h +++ b/Exif/Grid.h @@ -1,70 +1,76 @@ -/* Copyright (C) 2012 Jesper K. Pedersen +/* Copyright (C) 2012-2019 The KPhotoAlbum Development Team 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 of the License, 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. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef EXIF_GRID_H #define EXIF_GRID_H #include #include #include #include class QLabel; using Utilities::StringSet; namespace Exif { class Grid : public QScrollArea { Q_OBJECT public: explicit Grid(QWidget *parent); void setFileName(const DB::FileName &fileName); public slots: void updateSearchString(const QString &); + /** + * @brief setupUI sets up the scroll area for the given charset. + * Usually, this slot is only indirectly called through the setFileName function, + * but calling it directly can be used to change the display character set without changing the file name. + * @param charset + */ + void setupUI(const QString &charset); private: void keyPressEvent(QKeyEvent *) override; bool eventFilter(QObject *, QEvent *) override; StringSet exifGroups(const QMap &exifInfo); QMap itemsForGroup(const QString &group, const QMap &exifInfo); QString groupName(const QString &exifName); QString exifNameNoGroup(const QString &fullName); void scroll(int dy); QLabel *headerLabel(const QString &title); QPair infoLabelPair(const QString &title, const QString &value, const QColor &color); private slots: - void setupUI(const QString &charset); void updateWidgetSize(); private: QList> m_labels; int m_maxKeyWidth; DB::FileName m_fileName; }; } // namespace Exif #endif // EXIF_GRID_H // vi:expandtab:tabstop=4 shiftwidth=4: diff --git a/Exif/InfoDialog.cpp b/Exif/InfoDialog.cpp index ee56d6e7..4c192a21 100644 --- a/Exif/InfoDialog.cpp +++ b/Exif/InfoDialog.cpp @@ -1,127 +1,127 @@ -/* Copyright (C) 2003-2018 Jesper K. Pedersen +/* Copyright (C) 2003-2019 The KPhotoAlbum Development Team 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 of the License, 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. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "InfoDialog.h" #include "Grid.h" #include "Info.h" #include #include #include #include #include #include #include #include #include #include #include #include using Utilities::StringSet; Exif::InfoDialog::InfoDialog(const DB::FileName &fileName, QWidget *parent) : QDialog(parent) { setWindowTitle(i18nc("@title:window", "Exif Information")); setAttribute(Qt::WA_DeleteOnClose); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close); buttonBox->button(QDialogButtonBox::Close)->setShortcut(Qt::CTRL | Qt::Key_Return); connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); QWidget *top = new QWidget(this); QVBoxLayout *vlay = new QVBoxLayout(top); setLayout(vlay); vlay->addWidget(top); // -------------------------------------------------- File name and pixmap QHBoxLayout *hlay = new QHBoxLayout; vlay->addLayout(hlay); m_fileNameLabel = new QLabel(top); QFont fnt = font(); fnt.setPointSize((int)(fnt.pointSize() * 1.2)); fnt.setWeight(QFont::Bold); m_fileNameLabel->setFont(fnt); m_fileNameLabel->setAlignment(Qt::AlignCenter); hlay->addWidget(m_fileNameLabel, 1); m_pix = new QLabel(top); hlay->addWidget(m_pix); // -------------------------------------------------- Exif Grid m_grid = new Exif::Grid(top); vlay->addWidget(m_grid); // -------------------------------------------------- Current Search hlay = new QHBoxLayout; vlay->addLayout(hlay); QLabel *searchLabel = new QLabel(i18n("Exif label search: "), top); hlay->addWidget(searchLabel); m_searchBox = new QLineEdit(top); hlay->addWidget(m_searchBox); hlay->addStretch(1); QLabel *iptcLabel = new QLabel(i18n("IPTC character set:"), top); m_iptcCharset = new QComboBox(top); QStringList charsets; QList charsetsBA = QTextCodec::availableCodecs(); for (QList::const_iterator it = charsetsBA.constBegin(); it != charsetsBA.constEnd(); ++it) charsets << QLatin1String(*it); m_iptcCharset->insertItems(0, charsets); m_iptcCharset->setCurrentIndex(qMax(0, QTextCodec::availableCodecs().indexOf(Settings::SettingsData::instance()->iptcCharset().toLatin1()))); hlay->addWidget(iptcLabel); hlay->addWidget(m_iptcCharset); - connect(m_searchBox, SIGNAL(textChanged(QString)), m_grid, SLOT(updateSearchString(QString))); - connect(m_iptcCharset, SIGNAL(activated(QString)), m_grid, SLOT(setupUI(QString))); + connect(m_searchBox, &QLineEdit::textChanged, m_grid, &Grid::updateSearchString); + connect(m_iptcCharset, static_cast(&QComboBox::activated), m_grid, &Grid::setupUI); setImage(fileName); vlay->addWidget(buttonBox); } QSize Exif::InfoDialog::sizeHint() const { return QSize(800, 400); } void Exif::InfoDialog::pixmapLoaded(ImageManager::ImageRequest *request, const QImage &image) { if (request->loadedOK()) m_pix->setPixmap(QPixmap::fromImage(image)); } void Exif::InfoDialog::setImage(const DB::FileName &fileName) { m_fileNameLabel->setText(fileName.relative()); m_grid->setFileName(fileName); ImageManager::ImageRequest *request = new ImageManager::ImageRequest(fileName, QSize(128, 128), fileName.info()->angle(), this); request->setPriority(ImageManager::Viewer); ImageManager::AsyncLoader::instance()->load(request); } void Exif::InfoDialog::enterEvent(QEvent *) { m_grid->setFocus(); } // vi:expandtab:tabstop=4 shiftwidth=4: