File indexing completed on 2024-04-28 04:21:03
0001 /* SPDX-FileCopyrightText: 2003-2020 The KPhotoAlbum Development Team 0002 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "RangeWidget.h" 0007 0008 #include <KComboBox> 0009 #include <QGridLayout> 0010 #include <qlabel.h> 0011 0012 Exif::RangeWidget::RangeWidget(const QString &text, const QString &searchTag, const ValueList &list, QGridLayout *layout, int row, QObject *parent) 0013 : QObject(parent) 0014 , m_searchTag(searchTag) 0015 , m_list(list) 0016 { 0017 int col = 0; 0018 0019 // widget layout: <title text> <from_value> "to" <to_value> 0020 // register title text: 0021 QLabel *label = new QLabel(text); 0022 layout->addWidget(label, row, col++); 0023 0024 // register from-field: 0025 m_from = new KComboBox; 0026 layout->addWidget(m_from, row, col++); 0027 0028 // register filler between from- and to-field: 0029 label = new QLabel(QString::fromLatin1("to")); 0030 layout->addWidget(label, row, col++); 0031 0032 // register to-field: 0033 m_to = new KComboBox; 0034 layout->addWidget(m_to, row, col++); 0035 0036 Q_ASSERT(list.count() > 2); 0037 ValueList::ConstIterator it = list.begin(); 0038 m_from->addItem(QString::fromLatin1("< %1").arg((*it).text)); 0039 0040 for (; it != list.end(); ++it) { 0041 m_from->addItem((*it).text); 0042 } 0043 0044 m_from->addItem(QString::fromLatin1("> %1").arg(list.last().text)); 0045 slotUpdateTo(0); 0046 m_to->setCurrentIndex(m_to->count() - 1); // set range to be min->max 0047 0048 connect(m_from, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &RangeWidget::slotUpdateTo); 0049 } 0050 0051 void Exif::RangeWidget::slotUpdateTo(int fromIndex) 0052 { 0053 m_to->clear(); 0054 0055 if (fromIndex == 0) 0056 m_to->addItem(QString::fromLatin1("< %1").arg(m_list.first().text)); 0057 else 0058 fromIndex--; 0059 0060 for (int i = fromIndex; i < m_list.count(); ++i) { 0061 m_to->addItem(m_list[i].text); 0062 } 0063 m_to->addItem(QString::fromLatin1("> %1").arg(m_list.last().text)); 0064 } 0065 0066 Exif::SearchInfo::Range Exif::RangeWidget::range() const 0067 { 0068 SearchInfo::Range result(m_searchTag); 0069 result.min = m_list.first().value; 0070 result.max = m_list.last().value; 0071 if (m_from->currentIndex() == 0) 0072 result.isLowerMin = true; 0073 else if (m_from->currentIndex() == m_from->count() - 1) 0074 result.isLowerMax = true; 0075 else 0076 result.min = m_list[m_from->currentIndex() - 1].value; 0077 0078 if (m_to->currentIndex() == 0 && m_from->currentIndex() == 0) 0079 result.isUpperMin = true; 0080 else if (m_to->currentIndex() == m_to->count() - 1) 0081 result.isUpperMax = true; 0082 else 0083 result.max = m_list[m_to->currentIndex() + m_from->currentIndex() - 1].value; 0084 0085 return result; 0086 } 0087 0088 // vi:expandtab:tabstop=4 shiftwidth=4: 0089 0090 #include "moc_RangeWidget.cpp"