File indexing completed on 2024-12-08 04:34:38
0001 /* 0002 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "whatsnewcomboboxwidget.h" 0008 #include <KLocalizedString> 0009 #include <KSeparator> 0010 #include <QComboBox> 0011 #include <QHBoxLayout> 0012 #include <QLabel> 0013 0014 WhatsNewComboBoxWidget::WhatsNewComboBoxWidget(QWidget *parent) 0015 : QWidget{parent} 0016 , mVersionComboBox(new QComboBox(this)) 0017 { 0018 auto mainLayout = new QVBoxLayout(this); 0019 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0020 mainLayout->setContentsMargins({}); 0021 0022 auto hboxLayout = new QHBoxLayout; 0023 hboxLayout->setObjectName(QStringLiteral("hboxLayout")); 0024 hboxLayout->setContentsMargins({}); 0025 mainLayout->addLayout(hboxLayout); 0026 0027 auto label = new QLabel(i18n("Version:"), this); 0028 label->setObjectName(QStringLiteral("label")); 0029 hboxLayout->addWidget(label); 0030 0031 mVersionComboBox->setObjectName(QStringLiteral("mVersionComboBox")); 0032 hboxLayout->addWidget(mVersionComboBox); 0033 hboxLayout->addStretch(1); 0034 0035 auto separator = new KSeparator(this); 0036 separator->setObjectName(QStringLiteral("separator")); 0037 mainLayout->addWidget(separator); 0038 0039 fillCombobox(); 0040 connect(mVersionComboBox, &QComboBox::currentIndexChanged, this, &WhatsNewComboBoxWidget::slotCurrentIndexChanged); 0041 } 0042 0043 WhatsNewComboBoxWidget::~WhatsNewComboBoxWidget() = default; 0044 0045 QString WhatsNewComboBoxWidget::convertVersionEnumToString(WhatsNewComboBoxWidget::VersionType type) 0046 { 0047 switch (type) { 0048 case AllVersion: 0049 return i18n("All Version"); 0050 case Version2_0: 0051 return i18n("Version 2.0"); 0052 case Version2_1: 0053 return i18n("Version 2.1"); 0054 } 0055 return {}; 0056 } 0057 0058 void WhatsNewComboBoxWidget::fillCombobox() 0059 { 0060 mVersionComboBox->addItem(convertVersionEnumToString(AllVersion), AllVersion); 0061 mVersionComboBox->addItem(convertVersionEnumToString(Version2_0), Version2_0); 0062 mVersionComboBox->addItem(convertVersionEnumToString(Version2_1), Version2_1); 0063 } 0064 0065 void WhatsNewComboBoxWidget::initializeVersion(WhatsNewComboBoxWidget::VersionType type) 0066 { 0067 const int index = mVersionComboBox->findData(type); 0068 if (index != -1) { 0069 mVersionComboBox->setCurrentIndex(index); 0070 } 0071 } 0072 0073 void WhatsNewComboBoxWidget::slotCurrentIndexChanged(int index) 0074 { 0075 const VersionType type = mVersionComboBox->itemData(index).value<VersionType>(); 0076 Q_EMIT versionChanged(type); 0077 } 0078 0079 #include "moc_whatsnewcomboboxwidget.cpp"