File indexing completed on 2024-05-19 05:08:43
0001 /* 0002 SPDX-FileCopyrightText: 2006 Thomas Baumagrt <ipwizard@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2017 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KMYMONEYWIZARD_P_H 0008 #define KMYMONEYWIZARD_P_H 0009 0010 #include "kmymoneywizard.h" 0011 0012 // ---------------------------------------------------------------------------- 0013 // QT Includes 0014 0015 #include <QLabel> 0016 #include <QFont> 0017 #include <QHBoxLayout> 0018 #include <QList> 0019 #include <QVBoxLayout> 0020 #include <QPushButton> 0021 #include <QIcon> 0022 #include <QStyle> 0023 0024 // ---------------------------------------------------------------------------- 0025 // KDE Includes 0026 0027 #include <KLocalizedString> 0028 #include <KStandardGuiItem> 0029 #include <KColorScheme> 0030 0031 // ---------------------------------------------------------------------------- 0032 // Project Includes 0033 0034 #include "kmymoneywizardpage.h" 0035 #include "kmymoneywizardpage_p.h" 0036 #include "icons/icons.h" 0037 0038 using namespace Icons; 0039 0040 class KMyMoneyWizardPrivate 0041 { 0042 Q_DISABLE_COPY(KMyMoneyWizardPrivate) 0043 Q_DECLARE_PUBLIC(KMyMoneyWizard) 0044 0045 public: 0046 explicit KMyMoneyWizardPrivate(KMyMoneyWizard* qq) 0047 : q_ptr(qq) 0048 , m_cancelButton(nullptr) 0049 , m_backButton(nullptr) 0050 , m_nextButton(nullptr) 0051 , m_finishButton(nullptr) 0052 , m_helpButton(nullptr) 0053 , m_wizardLayout(nullptr) 0054 , m_stepLayout(nullptr) 0055 , m_pageLayout(nullptr) 0056 , m_buttonLayout(nullptr) 0057 , m_stepFrame(nullptr) 0058 , m_stepLabel(nullptr) 0059 , m_step(0) 0060 { 0061 } 0062 0063 virtual ~KMyMoneyWizardPrivate() 0064 { 0065 } 0066 0067 void init(bool modal) 0068 { 0069 Q_Q(KMyMoneyWizard); 0070 q->setModal(modal); 0071 0072 // enable the little grip in the right corner 0073 q->setSizeGripEnabled(true); 0074 0075 // create buttons 0076 m_cancelButton = new QPushButton(i18n("&Cancel"), q); 0077 m_backButton = new QPushButton(i18nc("Go to previous page of the wizard", "&Back"), q); 0078 m_nextButton = new QPushButton(i18nc("Go to next page of the wizard", "&Next"), q); 0079 m_finishButton = new QPushButton(i18nc("Finish the wizard", "&Finish"), q); 0080 m_helpButton = new QPushButton(i18n("&Help"), q); 0081 0082 if (q->style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons, 0, q)) { 0083 m_backButton->setIcon(KStandardGuiItem::back(KStandardGuiItem::UseRTL).icon()); 0084 m_nextButton->setIcon(KStandardGuiItem::forward(KStandardGuiItem::UseRTL).icon()); 0085 m_finishButton->setIcon(Icons::get(Icon::DialogOKApply)); 0086 m_cancelButton->setIcon(Icons::get(Icon::DialogCancel)); 0087 m_helpButton->setIcon(Icons::get(Icon::Help)); 0088 } 0089 0090 // create button layout 0091 m_buttonLayout = new QHBoxLayout; 0092 m_buttonLayout->addWidget(m_helpButton); 0093 m_buttonLayout->addStretch(1); 0094 m_buttonLayout->addWidget(m_backButton); 0095 m_buttonLayout->addWidget(m_nextButton); 0096 m_buttonLayout->addWidget(m_finishButton); 0097 m_buttonLayout->addWidget(m_cancelButton); 0098 0099 // create wizard layout 0100 m_wizardLayout = new QVBoxLayout(q); 0101 m_wizardLayout->setContentsMargins(6, 6, 6, 6); 0102 m_wizardLayout->setSpacing(0); 0103 m_wizardLayout->setObjectName("wizardLayout"); 0104 0105 QHBoxLayout* hboxLayout = new QHBoxLayout; 0106 hboxLayout->setContentsMargins(0, 0, 0, 0); 0107 hboxLayout->setSpacing(6); 0108 hboxLayout->setObjectName("hboxLayout"); 0109 0110 // create stage layout and frame 0111 m_stepFrame = new QFrame(q); 0112 m_stepFrame->setObjectName("stepFrame"); 0113 QPalette palette = m_stepFrame->palette(); 0114 palette.setColor(m_stepFrame->backgroundRole(), KColorScheme::NormalText); 0115 m_stepFrame->setPalette(palette); 0116 m_stepLayout = new QVBoxLayout(m_stepFrame); 0117 m_stepLayout->setContentsMargins(11, 11, 11, 11); 0118 m_stepLayout->setSpacing(6); 0119 m_stepLayout->setObjectName("stepLayout"); 0120 m_stepLayout->addWidget(new QLabel(QString(), m_stepFrame)); 0121 m_stepLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding)); 0122 m_stepLabel = new QLabel(m_stepFrame); 0123 m_stepLabel->setAlignment(Qt::AlignHCenter); 0124 m_stepLayout->addWidget(m_stepLabel); 0125 hboxLayout->addWidget(m_stepFrame); 0126 0127 m_stepPalette = m_stepLabel->palette(); 0128 0129 // add a vertical line between the stepFrame and the pages 0130 QFrame* line = new QFrame(q); 0131 line->setObjectName("line"); 0132 line->setFrameShadow(QFrame::Sunken); 0133 line->setFrameShape(QFrame::VLine); 0134 hboxLayout->addWidget(line); 0135 0136 // create page layout 0137 m_pageLayout = new QVBoxLayout; 0138 m_pageLayout->setContentsMargins(0, 0, 0, 0); 0139 m_pageLayout->setSpacing(6); 0140 m_pageLayout->setObjectName("pageLayout"); 0141 0142 // the page will be inserted later dynamically above q line 0143 line = new QFrame(q); 0144 line->setObjectName("line"); 0145 line->setFrameShadow(QFrame::Sunken); 0146 line->setFrameShape(QFrame::HLine); 0147 m_pageLayout->addWidget(line); 0148 m_pageLayout->addLayout(m_buttonLayout); 0149 0150 // now glue everything together 0151 hboxLayout->addLayout(m_pageLayout); 0152 m_wizardLayout->addLayout(hboxLayout); 0153 0154 q->resize(QSize(670, 550).expandedTo(q->minimumSizeHint())); 0155 0156 m_finishButton->hide(); 0157 0158 q->connect(m_backButton, &QAbstractButton::clicked, q, &KMyMoneyWizard::backButtonClicked); 0159 q->connect(m_nextButton, &QAbstractButton::clicked, q, &KMyMoneyWizard::nextButtonClicked); 0160 q->connect(m_cancelButton, &QAbstractButton::clicked, q, &QDialog::reject); 0161 q->connect(m_finishButton, &QAbstractButton::clicked, q, &KMyMoneyWizard::accept); 0162 q->connect(m_helpButton, &QAbstractButton::clicked, q, &KMyMoneyWizard::helpButtonClicked); 0163 } 0164 0165 /** 0166 * Switch to page which is currently the top of the history stack. 0167 * @p oldPage is a pointer to the current page or 0 if no page 0168 * is shown. 0169 * 0170 * @param oldPage pointer to currently displayed page 0171 */ 0172 void switchPage(KMyMoneyWizardPage* oldPage) 0173 { 0174 Q_Q(KMyMoneyWizard); 0175 if (oldPage) { 0176 oldPage->widget()->hide(); 0177 m_pageLayout->removeWidget(oldPage->widget()); 0178 q->disconnect(oldPage->object(), &KMyMoneyWizardPagePrivate::completeStateChanged, q, &KMyMoneyWizard::completeStateChanged); 0179 } 0180 KMyMoneyWizardPage* newPage = m_history.back(); 0181 if (newPage) { 0182 m_pageLayout->insertWidget(0, newPage->widget()); 0183 q->connect(newPage->object(), &KMyMoneyWizardPagePrivate::completeStateChanged, q, &KMyMoneyWizard::completeStateChanged); 0184 newPage->widget()->show(); 0185 selectStep(newPage->step()); 0186 if (newPage->isLastPage()) { 0187 m_nextButton->setDefault(false); 0188 m_finishButton->setDefault(true); 0189 } else { 0190 m_finishButton->setDefault(false); 0191 m_nextButton->setDefault(true); 0192 } 0193 QWidget* w = newPage->initialFocusWidget(); 0194 if (w) 0195 w->setFocus(); 0196 } 0197 q->completeStateChanged(); 0198 } 0199 0200 /** 0201 * This method selects the step given by @p step. 0202 * 0203 * @param step step to be selected 0204 */ 0205 void selectStep(int step) 0206 { 0207 if ((step < 1) || (step > m_steps.count())) 0208 return; 0209 0210 m_step = step; 0211 QList<QLabel*>::iterator it_l; 0212 QFont f = m_steps[0]->font(); 0213 for (it_l = m_steps.begin(); it_l != m_steps.end(); ++it_l) { 0214 f.setBold(false); 0215 (*it_l)->setFrameStyle(QFrame::NoFrame); 0216 if (--step == 0) { 0217 f.setBold(true); 0218 (*it_l)->setFrameStyle(QFrame::Box | QFrame::Sunken); 0219 } 0220 (*it_l)->setFont(f); 0221 } 0222 updateStepCount(); 0223 } 0224 0225 /** 0226 * This method sets up the first page after creation of the object 0227 * 0228 * @param page pointer to first page of wizard 0229 */ 0230 void setFirstPage(KMyMoneyWizardPage* page) 0231 { 0232 page->resetPage(); 0233 m_history.clear(); 0234 m_history.append(page); 0235 switchPage(0); 0236 } 0237 0238 /** 0239 * This method allows to hide or show a @p step. 0240 * 0241 * @param step step to be shown/hidden 0242 * @param hidden hide step if true (the default) or show it if false 0243 */ 0244 void setStepHidden(int step, bool hidden = true) 0245 { 0246 if ((step < 1) || (step > m_steps.count())) 0247 return; 0248 0249 m_steps[--step]->setHidden(hidden); 0250 updateStepCount(); 0251 } 0252 0253 void updateStepCount() 0254 { 0255 QList<QLabel*>::iterator it_l; 0256 int stepCount = 0; 0257 int hiddenAdjust = 0; 0258 int step = 0; 0259 for (it_l = m_steps.begin(); it_l != m_steps.end(); ++it_l) { 0260 if (!(*it_l)->isHidden()) 0261 ++stepCount; 0262 else if (step < m_step) 0263 hiddenAdjust++; 0264 ++step; 0265 } 0266 m_stepLabel->setText(i18n("Step %1 of %2", (m_step - hiddenAdjust), stepCount)); 0267 } 0268 0269 KMyMoneyWizard *q_ptr; 0270 0271 /* 0272 * The buttons 0273 */ 0274 QPushButton* m_cancelButton; 0275 QPushButton* m_backButton; 0276 QPushButton* m_nextButton; 0277 QPushButton* m_finishButton; 0278 QPushButton* m_helpButton; 0279 0280 /* 0281 * The layouts 0282 */ 0283 QVBoxLayout* m_wizardLayout; 0284 QVBoxLayout* m_stepLayout; 0285 QVBoxLayout* m_pageLayout; 0286 QHBoxLayout* m_buttonLayout; 0287 0288 /* 0289 * Some misc. widgets required 0290 */ 0291 QFrame* m_stepFrame; 0292 QLabel* m_stepLabel; 0293 QPalette m_stepPalette; 0294 0295 QList<QLabel*> m_steps; // the list of step labels 0296 int m_step; // the currently selected step 0297 0298 /* 0299 * The history stack 0300 */ 0301 QList<KMyMoneyWizardPage*> m_history; 0302 0303 QString m_helpContext; 0304 }; 0305 0306 #endif