File indexing completed on 2024-05-26 05:10:15
0001 /* 0002 SPDX-FileCopyrightText: 2010 Fernando Vilas <kmymoney-devel@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "assetaccountwizardpage.h" 0007 0008 // ---------------------------------------------------------------------------- 0009 // QT Includes 0010 0011 #include <QIcon> 0012 0013 // ---------------------------------------------------------------------------- 0014 // KDE Includes 0015 0016 #include "ui_assetaccountwizardpage.h" 0017 0018 #include <KLocalizedString> 0019 #include <KGuiItem> 0020 0021 // ---------------------------------------------------------------------------- 0022 // Project Includes 0023 0024 #include "kmymoneysettings.h" 0025 #include "mymoneyaccount.h" 0026 #include "wizards/newaccountwizard/knewaccountwizard.h" 0027 #include "icons/icons.h" 0028 0029 using namespace Icons; 0030 0031 AssetAccountWizardPage::AssetAccountWizardPage(QWidget *parent) 0032 : QWizardPage(parent), 0033 ui(new Ui::AssetAccountWizardPage) 0034 { 0035 ui->setupUi(this); 0036 0037 // Register the fields with the QWizard and connect the 0038 // appropriate signals to update the "Next" button correctly 0039 registerField("dontCreatePayoutCheckBox", ui->m_dontCreatePayoutCheckBox); 0040 registerField("paymentDate", ui->m_paymentDate, "date"); 0041 registerField("assetAccountEdit", ui->m_assetAccountEdit, "selectedItems"); 0042 0043 connect(ui->m_assetAccountEdit, &KMyMoneySelector::stateChanged, this, &QWizardPage::completeChanged); 0044 connect(ui->m_dontCreatePayoutCheckBox, &QAbstractButton::clicked, this, &QWizardPage::completeChanged); 0045 0046 // load button icons 0047 KGuiItem createAssetButtonItem(i18n("&Create..."), 0048 Icons::get(Icon::DocumentNew), 0049 i18n("Create a new asset account"), 0050 i18n("Use this to create a new account to which the initial payment should be made")); 0051 KGuiItem::assign(ui->m_createNewAssetButton, createAssetButtonItem); 0052 0053 connect(ui->m_createNewAssetButton, &QAbstractButton::clicked, this, &AssetAccountWizardPage::slotAccountNew); 0054 0055 ui->m_assetAccountEdit->removeButtons(); 0056 ui->m_dontCreatePayoutCheckBox->setChecked(false); 0057 } 0058 0059 AssetAccountWizardPage::~AssetAccountWizardPage() 0060 { 0061 delete ui; 0062 } 0063 0064 /** 0065 * Update the "Next" button 0066 */ 0067 bool AssetAccountWizardPage::isComplete() const 0068 { 0069 if (ui->m_dontCreatePayoutCheckBox->isChecked()) { 0070 ui->m_assetAccountEdit->setEnabled(false); 0071 ui->m_paymentDate->setEnabled(false); 0072 ui->m_createNewAssetButton->setEnabled(false); 0073 return true; 0074 } else { 0075 ui->m_assetAccountEdit->setEnabled(true); 0076 ui->m_paymentDate->setEnabled(true); 0077 ui->m_createNewAssetButton->setEnabled(true); 0078 if (!ui->m_assetAccountEdit->selectedItems().isEmpty() 0079 && ui->m_paymentDate->date().isValid()) 0080 return true; 0081 } 0082 return false; 0083 } 0084 0085 void AssetAccountWizardPage::slotAccountNew() 0086 { 0087 MyMoneyAccount account; 0088 account.setOpeningDate(KMyMoneySettings::firstFiscalDate()); 0089 NewAccountWizard::Wizard::newAccount(account); 0090 }