File indexing completed on 2024-12-01 04:36:51
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "statuscombobox.h" 0008 #include "model/statusmodel.h" 0009 #include "model/statusmodelfilterproxymodel.h" 0010 0011 StatusCombobox::StatusCombobox(QWidget *parent) 0012 : QComboBox(parent) 0013 { 0014 setSizeAdjustPolicy(QComboBox::AdjustToContents); 0015 } 0016 0017 StatusCombobox::~StatusCombobox() = default; 0018 0019 User::PresenceStatus StatusCombobox::status() const 0020 { 0021 return currentData(StatusModel::Status).value<User::PresenceStatus>(); 0022 } 0023 0024 void StatusCombobox::setStatus(User::PresenceStatus status, const QString &customText) 0025 { 0026 if (customText.isEmpty()) { 0027 setCurrentIndex(findData(QVariant::fromValue(status), StatusModel::Status)); 0028 } else { 0029 // TODO use customText 0030 setCurrentIndex(findData(QVariant::fromValue(status), StatusModel::Status)); 0031 } 0032 } 0033 0034 void StatusCombobox::setUseOnlyStandardStatus() 0035 { 0036 auto statusProxyModel = new StatusModelFilterProxyModel(this); 0037 statusProxyModel->setUseOnlyStandardStatus(true); 0038 statusProxyModel->setSourceModel(new StatusModel(this)); 0039 setModel(statusProxyModel); 0040 } 0041 0042 #include "moc_statuscombobox.cpp"