File indexing completed on 2024-12-22 04:45:36
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 "administratorcustomuserstatuscreatedialog.h" 0008 0009 #include <KConfigGroup> 0010 #include <KLocalizedString> 0011 #include <KSharedConfig> 0012 #include <KWindowConfig> 0013 #include <QDialogButtonBox> 0014 #include <QPushButton> 0015 #include <QVBoxLayout> 0016 #include <QWindow> 0017 namespace 0018 { 0019 static const char myConfigAdministratorCustomUserStatusCreateDialogGroupName[] = "AdministratorCustomUserStatusCreateDialog"; 0020 } 0021 AdministratorCustomUserStatusCreateDialog::AdministratorCustomUserStatusCreateDialog(QWidget *parent) 0022 : QDialog(parent) 0023 , mCreateWidget(new AdministratorCustomUserStatusCreateWidget(this)) 0024 { 0025 setWindowTitle(i18nc("@title:window", "Create New User Status")); 0026 auto mainLayout = new QVBoxLayout(this); 0027 mainLayout->setObjectName(QStringLiteral("mainLayout")); 0028 0029 mCreateWidget->setObjectName(QStringLiteral("mCreateWidget")); 0030 mainLayout->addWidget(mCreateWidget); 0031 0032 auto button = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0033 button->setObjectName(QStringLiteral("button")); 0034 mainLayout->addWidget(button); 0035 connect(button, &QDialogButtonBox::rejected, this, &AdministratorCustomUserStatusCreateDialog::reject); 0036 connect(button, &QDialogButtonBox::accepted, this, &AdministratorCustomUserStatusCreateDialog::accept); 0037 mOkButton = button->button(QDialogButtonBox::Ok); 0038 mOkButton->setEnabled(false); 0039 connect(mCreateWidget, &AdministratorCustomUserStatusCreateWidget::updateOkButton, mOkButton, &QPushButton::setEnabled); 0040 readConfig(); 0041 } 0042 0043 AdministratorCustomUserStatusCreateDialog::~AdministratorCustomUserStatusCreateDialog() 0044 { 0045 writeConfig(); 0046 } 0047 0048 void AdministratorCustomUserStatusCreateDialog::readConfig() 0049 { 0050 create(); // ensure a window is created 0051 windowHandle()->resize(QSize(800, 300)); 0052 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myConfigAdministratorCustomUserStatusCreateDialogGroupName)); 0053 KWindowConfig::restoreWindowSize(windowHandle(), group); 0054 resize(windowHandle()->size()); // workaround for QTBUG-40584 0055 } 0056 0057 void AdministratorCustomUserStatusCreateDialog::writeConfig() 0058 { 0059 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myConfigAdministratorCustomUserStatusCreateDialogGroupName)); 0060 KWindowConfig::saveWindowSize(windowHandle(), group); 0061 } 0062 0063 AdministratorCustomUserStatusCreateWidget::UserStatusInfo AdministratorCustomUserStatusCreateDialog::userStatusInfo() const 0064 { 0065 return mCreateWidget->userStatusInfo(); 0066 } 0067 0068 void AdministratorCustomUserStatusCreateDialog::setUserStatusInfo(const AdministratorCustomUserStatusCreateWidget::UserStatusInfo &info) 0069 { 0070 mCreateWidget->setUserStatusInfo(info); 0071 setWindowTitle(i18nc("@title:window", "Edit User Status")); 0072 } 0073 0074 #include "moc_administratorcustomuserstatuscreatedialog.cpp"