Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/wizards/kmymoneywizard_p.h
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | kmymoneywizard_p.h | ||||
3 | ------------------- | ||||
4 | copyright : (C) 2006 by Thomas Baumagrt | ||||
5 | email : ipwizard@users.sourceforge.net | ||||
6 | (C) 2017 by Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> | ||||
7 | ***************************************************************************/ | ||||
8 | | ||||
9 | /*************************************************************************** | ||||
10 | * * | ||||
11 | * This program is free software; you can redistribute it and/or modify * | ||||
12 | * it under the terms of the GNU General Public License as published by * | ||||
13 | * the Free Software Foundation; either version 2 of the License, or * | ||||
14 | * (at your option) any later version. * | ||||
15 | * * | ||||
16 | ***************************************************************************/ | ||||
17 | | ||||
18 | #ifndef KMYMONEYWIZARD_P_H | ||||
19 | #define KMYMONEYWIZARD_P_H | ||||
20 | | ||||
21 | #include "kmymoneywizard.h" | ||||
22 | | ||||
23 | // ---------------------------------------------------------------------------- | ||||
24 | // QT Includes | ||||
25 | | ||||
26 | #include <QLabel> | ||||
27 | #include <QFont> | ||||
28 | #include <QHBoxLayout> | ||||
29 | #include <QList> | ||||
30 | #include <QVBoxLayout> | ||||
31 | #include <QPushButton> | ||||
32 | #include <QIcon> | ||||
33 | #include <QStyle> | ||||
34 | | ||||
35 | // ---------------------------------------------------------------------------- | ||||
36 | // KDE Includes | ||||
37 | | ||||
38 | #include <KLocalizedString> | ||||
39 | #include <KStandardGuiItem> | ||||
40 | #include <KColorScheme> | ||||
41 | #include <KHelpClient> | ||||
42 | | ||||
43 | // ---------------------------------------------------------------------------- | ||||
44 | // Project Includes | ||||
45 | | ||||
46 | #include "kmymoneywizardpage.h" | ||||
47 | #include "kmymoneytitlelabel.h" | ||||
48 | #include "icons/icons.h" | ||||
49 | | ||||
50 | using namespace Icons; | ||||
51 | | ||||
52 | class KMyMoneyWizardPrivate | ||||
53 | { | ||||
54 | Q_DISABLE_COPY(KMyMoneyWizardPrivate) | ||||
55 | Q_DECLARE_PUBLIC(KMyMoneyWizard) | ||||
56 | | ||||
57 | public: | ||||
58 | KMyMoneyWizardPrivate(KMyMoneyWizard *qq) : | ||||
59 | q_ptr(qq), | ||||
60 | m_step(0) | ||||
61 | { | ||||
62 | } | ||||
63 | | ||||
64 | virtual ~KMyMoneyWizardPrivate() | ||||
65 | { | ||||
66 | } | ||||
67 | | ||||
68 | void init(bool modal) | ||||
69 | { | ||||
70 | Q_Q(KMyMoneyWizard); | ||||
71 | q->setModal(modal); | ||||
72 | | ||||
73 | // enable the little grip in the right corner | ||||
74 | q->setSizeGripEnabled(true); | ||||
75 | | ||||
76 | // create buttons | ||||
77 | m_cancelButton = new QPushButton(i18n("&Cancel"), q); | ||||
78 | m_backButton = new QPushButton(i18nc("Go to previous page of the wizard", "&Back"), q); | ||||
79 | m_nextButton = new QPushButton(i18nc("Go to next page of the wizard", "&Next"), q); | ||||
80 | m_finishButton = new QPushButton(i18nc("Finish the wizard", "&Finish"), q); | ||||
81 | m_helpButton = new QPushButton(i18n("&Help"), q); | ||||
82 | | ||||
83 | if (q->style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons, 0, q)) { | ||||
84 | m_backButton->setIcon(KStandardGuiItem::back(KStandardGuiItem::UseRTL).icon()); | ||||
85 | m_nextButton->setIcon(KStandardGuiItem::forward(KStandardGuiItem::UseRTL).icon()); | ||||
86 | m_finishButton->setIcon(QIcon::fromTheme(g_Icons[Icon::DialogOKApply])); | ||||
87 | m_cancelButton->setIcon(QIcon::fromTheme(g_Icons[Icon::DialogCancel])); | ||||
88 | m_helpButton->setIcon(QIcon::fromTheme(g_Icons[Icon::HelpContents])); | ||||
89 | } | ||||
90 | | ||||
91 | // create button layout | ||||
92 | m_buttonLayout = new QHBoxLayout; | ||||
93 | m_buttonLayout->addWidget(m_helpButton); | ||||
94 | m_buttonLayout->addStretch(1); | ||||
95 | m_buttonLayout->addWidget(m_backButton); | ||||
96 | m_buttonLayout->addWidget(m_nextButton); | ||||
97 | m_buttonLayout->addWidget(m_finishButton); | ||||
98 | m_buttonLayout->addWidget(m_cancelButton); | ||||
99 | | ||||
100 | // create wizard layout | ||||
101 | m_wizardLayout = new QVBoxLayout(q); | ||||
102 | m_wizardLayout->setContentsMargins(6, 6, 6, 6); | ||||
103 | m_wizardLayout->setSpacing(0); | ||||
104 | m_wizardLayout->setObjectName("wizardLayout"); | ||||
105 | m_titleLabel = new KMyMoneyTitleLabel(q); | ||||
106 | m_titleLabel->setObjectName("titleLabel"); | ||||
107 | m_wizardLayout->addWidget(m_titleLabel); | ||||
108 | | ||||
109 | QHBoxLayout* hboxLayout = new QHBoxLayout; | ||||
110 | hboxLayout->setContentsMargins(0, 0, 0, 0); | ||||
111 | hboxLayout->setSpacing(6); | ||||
112 | hboxLayout->setObjectName("hboxLayout"); | ||||
113 | | ||||
114 | // create stage layout and frame | ||||
115 | m_stepFrame = new QFrame(q); | ||||
116 | m_stepFrame->setObjectName("stepFrame"); | ||||
117 | QPalette palette = m_stepFrame->palette(); | ||||
118 | palette.setColor(m_stepFrame->backgroundRole(), KColorScheme::NormalText); | ||||
119 | m_stepFrame->setPalette(palette); | ||||
120 | m_stepLayout = new QVBoxLayout(m_stepFrame); | ||||
121 | m_stepLayout->setContentsMargins(11, 11, 11, 11); | ||||
122 | m_stepLayout->setSpacing(6); | ||||
123 | m_stepLayout->setObjectName("stepLayout"); | ||||
124 | m_stepLayout->addWidget(new QLabel(QString(), m_stepFrame)); | ||||
125 | m_stepLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding)); | ||||
126 | m_stepLabel = new QLabel(m_stepFrame); | ||||
127 | m_stepLabel->setAlignment(Qt::AlignHCenter); | ||||
128 | m_stepLayout->addWidget(m_stepLabel); | ||||
129 | hboxLayout->addWidget(m_stepFrame); | ||||
130 | | ||||
131 | m_stepPalette = m_stepLabel->palette(); | ||||
132 | | ||||
133 | // add a vertical line between the stepFrame and the pages | ||||
134 | QFrame* line = new QFrame(q); | ||||
135 | line->setObjectName("line"); | ||||
136 | line->setFrameShadow(QFrame::Sunken); | ||||
137 | line->setFrameShape(QFrame::VLine); | ||||
138 | hboxLayout->addWidget(line); | ||||
139 | | ||||
140 | // create page layout | ||||
141 | m_pageLayout = new QVBoxLayout; | ||||
142 | m_pageLayout->setContentsMargins(0, 0, 0, 0); | ||||
143 | m_pageLayout->setSpacing(6); | ||||
144 | m_pageLayout->setObjectName("pageLayout"); | ||||
145 | | ||||
146 | // the page will be inserted later dynamically above q line | ||||
147 | line = new QFrame(q); | ||||
148 | line->setObjectName("line"); | ||||
149 | line->setFrameShadow(QFrame::Sunken); | ||||
150 | line->setFrameShape(QFrame::HLine); | ||||
151 | m_pageLayout->addWidget(line); | ||||
152 | m_pageLayout->addLayout(m_buttonLayout); | ||||
153 | | ||||
154 | // now glue everything together | ||||
155 | hboxLayout->addLayout(m_pageLayout); | ||||
156 | m_wizardLayout->addLayout(hboxLayout); | ||||
157 | | ||||
158 | q->resize(QSize(670, 550).expandedTo(q->minimumSizeHint())); | ||||
159 | | ||||
160 | m_titleLabel->setText(i18n("No Title specified")); | ||||
161 | m_titleLabel->setRightImageFile("pics/titlelabel_background.png"); | ||||
162 | | ||||
163 | m_finishButton->hide(); | ||||
164 | | ||||
165 | q->connect(m_backButton, &QAbstractButton::clicked, q, &KMyMoneyWizard::backButtonClicked); | ||||
166 | q->connect(m_nextButton, &QAbstractButton::clicked, q, &KMyMoneyWizard::nextButtonClicked); | ||||
167 | q->connect(m_cancelButton, &QAbstractButton::clicked, q, &QDialog::reject); | ||||
168 | q->connect(m_finishButton, &QAbstractButton::clicked, q, &KMyMoneyWizard::accept); | ||||
169 | q->connect(m_helpButton, &QAbstractButton::clicked, q, &KMyMoneyWizard::helpButtonClicked); | ||||
170 | } | ||||
171 | | ||||
172 | /** | ||||
173 | * Switch to page which is currently the top of the history stack. | ||||
174 | * @p oldPage is a pointer to the current page or 0 if no page | ||||
175 | * is shown. | ||||
176 | * | ||||
177 | * @param oldPage pointer to currently displayed page | ||||
178 | */ | ||||
179 | void switchPage(KMyMoneyWizardPage* oldPage) | ||||
180 | { | ||||
181 | Q_Q(KMyMoneyWizard); | ||||
182 | if (oldPage) { | ||||
183 | oldPage->widget()->hide(); | ||||
184 | m_pageLayout->removeWidget(oldPage->widget()); | ||||
185 | q->disconnect(oldPage->object(), SIGNAL(completeStateChanged()), q, SLOT(completeStateChanged())); | ||||
186 | } | ||||
187 | KMyMoneyWizardPage* newPage = m_history.back(); | ||||
188 | if (newPage) { | ||||
189 | m_pageLayout->insertWidget(0, newPage->widget()); | ||||
190 | q->connect(newPage->object(), SIGNAL(completeStateChanged()), q, SLOT(completeStateChanged())); | ||||
191 | newPage->widget()->show(); | ||||
192 | selectStep(newPage->step()); | ||||
193 | if (newPage->isLastPage()) { | ||||
194 | m_nextButton->setDefault(false); | ||||
195 | m_finishButton->setDefault(true); | ||||
196 | } else { | ||||
197 | m_finishButton->setDefault(false); | ||||
198 | m_nextButton->setDefault(true); | ||||
199 | } | ||||
200 | QWidget* w = newPage->initialFocusWidget(); | ||||
201 | if (w) | ||||
202 | w->setFocus(); | ||||
203 | } | ||||
204 | q->completeStateChanged(); | ||||
205 | } | ||||
206 | | ||||
207 | /** | ||||
208 | * This method selects the step given by @p step. | ||||
209 | * | ||||
210 | * @param step step to be selected | ||||
211 | */ | ||||
212 | void selectStep(int step) | ||||
213 | { | ||||
214 | Q_Q(KMyMoneyWizard); | ||||
215 | if ((step < 1) || (step > m_steps.count())) | ||||
216 | return; | ||||
217 | | ||||
218 | m_step = step; | ||||
219 | QList<QLabel*>::iterator it_l; | ||||
220 | QFont f = m_steps[0]->font(); | ||||
221 | for (it_l = m_steps.begin(); it_l != m_steps.end(); ++it_l) { | ||||
222 | f.setBold(false); | ||||
223 | (*it_l)->setFrameStyle(QFrame::NoFrame); | ||||
224 | if (--step == 0) { | ||||
225 | f.setBold(true); | ||||
226 | (*it_l)->setFrameStyle(QFrame::Box | QFrame::Sunken); | ||||
227 | } | ||||
228 | (*it_l)->setFont(f); | ||||
229 | } | ||||
230 | updateStepCount(); | ||||
231 | } | ||||
232 | | ||||
233 | /** | ||||
234 | * This method sets up the first page after creation of the object | ||||
235 | * | ||||
236 | * @param page pointer to first page of wizard | ||||
237 | */ | ||||
238 | void setFirstPage(KMyMoneyWizardPage* page) | ||||
239 | { | ||||
240 | page->resetPage(); | ||||
241 | m_history.clear(); | ||||
242 | m_history.append(page); | ||||
243 | switchPage(0); | ||||
244 | } | ||||
245 | | ||||
246 | /** | ||||
247 | * This method allows to hide or show a @p step. | ||||
248 | * | ||||
249 | * @param step step to be shown/hidden | ||||
250 | * @param hidden hide step if true (the default) or show it if false | ||||
251 | */ | ||||
252 | void setStepHidden(int step, bool hidden = true) | ||||
253 | { | ||||
254 | Q_Q(KMyMoneyWizard); | ||||
255 | if ((step < 1) || (step > m_steps.count())) | ||||
256 | return; | ||||
257 | | ||||
258 | m_steps[--step]->setHidden(hidden); | ||||
259 | updateStepCount(); | ||||
260 | } | ||||
261 | | ||||
262 | void updateStepCount() | ||||
263 | { | ||||
264 | QList<QLabel*>::iterator it_l; | ||||
265 | int stepCount = 0; | ||||
266 | int hiddenAdjust = 0; | ||||
267 | int step = 0; | ||||
268 | for (it_l = m_steps.begin(); it_l != m_steps.end(); ++it_l) { | ||||
269 | if (!(*it_l)->isHidden()) | ||||
270 | ++stepCount; | ||||
271 | else if (step < m_step) | ||||
272 | hiddenAdjust++; | ||||
273 | ++step; | ||||
274 | } | ||||
275 | m_stepLabel->setText(i18n("Step %1 of %2", (m_step - hiddenAdjust), stepCount)); | ||||
276 | } | ||||
277 | | ||||
278 | KMyMoneyWizard *q_ptr; | ||||
279 | | ||||
280 | /* | ||||
281 | * The buttons | ||||
282 | */ | ||||
283 | QPushButton* m_cancelButton; | ||||
284 | QPushButton* m_backButton; | ||||
285 | QPushButton* m_nextButton; | ||||
286 | QPushButton* m_finishButton; | ||||
287 | QPushButton* m_helpButton; | ||||
288 | | ||||
289 | /* | ||||
290 | * The layouts | ||||
291 | */ | ||||
292 | QVBoxLayout* m_wizardLayout; | ||||
293 | QVBoxLayout* m_stepLayout; | ||||
294 | QVBoxLayout* m_pageLayout; | ||||
295 | QHBoxLayout* m_buttonLayout; | ||||
296 | | ||||
297 | /* | ||||
298 | * Some misc. widgets required | ||||
299 | */ | ||||
300 | QFrame* m_stepFrame; | ||||
301 | QLabel* m_stepLabel; | ||||
302 | QPalette m_stepPalette; | ||||
303 | | ||||
304 | QList<QLabel*> m_steps; // the list of step labels | ||||
305 | int m_step; // the currently selected step | ||||
306 | | ||||
307 | /* | ||||
308 | * The title bar | ||||
309 | */ | ||||
310 | KMyMoneyTitleLabel* m_titleLabel; | ||||
311 | | ||||
312 | /* | ||||
313 | * The history stack | ||||
314 | */ | ||||
315 | QList<KMyMoneyWizardPage*> m_history; | ||||
316 | | ||||
317 | QString m_helpContext; | ||||
318 | }; | ||||
319 | | ||||
320 | #endif |