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