Pimcommon

whatsnewcomboboxwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "whatsnewcomboboxwidget.h"
8#include <KLocalizedString>
9#include <KSeparator>
10#include <QComboBox>
11#include <QHBoxLayout>
12#include <QLabel>
13using namespace PimCommon;
14WhatsNewComboBoxWidget::WhatsNewComboBoxWidget(QWidget *parent)
15 : QWidget{parent}
16 , mVersionComboBox(new QComboBox(this))
17{
18 auto mainLayout = new QVBoxLayout(this);
19 mainLayout->setObjectName(QStringLiteral("mainLayout"));
20 mainLayout->setContentsMargins({});
21
22 auto hboxLayout = new QHBoxLayout;
23 hboxLayout->setObjectName(QStringLiteral("hboxLayout"));
24 hboxLayout->setContentsMargins({});
25 mainLayout->addLayout(hboxLayout);
26
27 auto label = new QLabel(i18nc("@label:textbox", "Version:"), this);
28 label->setObjectName(QStringLiteral("label"));
29 hboxLayout->addWidget(label);
30
31 mVersionComboBox->setObjectName(QStringLiteral("mVersionComboBox"));
32 hboxLayout->addWidget(mVersionComboBox);
33 hboxLayout->addStretch(1);
34
35 auto separator = new KSeparator(this);
36 separator->setObjectName(QStringLiteral("separator"));
37 mainLayout->addWidget(separator);
38
39 connect(mVersionComboBox, &QComboBox::currentIndexChanged, this, &WhatsNewComboBoxWidget::slotCurrentIndexChanged);
40}
41
42void WhatsNewComboBoxWidget::addVersion(const QString &name, int identifier)
43{
44 mVersionComboBox->addItem(name, identifier);
45}
46
47WhatsNewComboBoxWidget::~WhatsNewComboBoxWidget() = default;
48
49void WhatsNewComboBoxWidget::initializeVersion(int identifier)
50{
51 const int index = mVersionComboBox->findData(identifier);
52 if (index != -1) {
53 mVersionComboBox->setCurrentIndex(index);
54 }
55}
56
57void WhatsNewComboBoxWidget::slotCurrentIndexChanged(int index)
58{
59 const int type = mVersionComboBox->itemData(index).toInt();
60 Q_EMIT versionChanged(type);
61}
62
63#include "moc_whatsnewcomboboxwidget.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
Type type(const QSqlDatabase &db)
QString label(StandardShortcut id)
folderdialogacltab.h
void addItem(const QIcon &icon, const QString &text, const QVariant &userData)
void setCurrentIndex(int index)
void currentIndexChanged(int index)
int findData(const QVariant &data, int role, Qt::MatchFlags flags) const const
QVariant itemData(int index, int role) const const
Q_EMITQ_EMIT
void setObjectName(QAnyStringView name)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
int toInt(bool *ok) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:07:34 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.