Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/wizards/kmymoneywizard.cpp
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | kmymoneywizard.cpp | ||||
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 | #include "kmymoneywizard.h" | ||||
19 | #include "kmymoneywizard_p.h" | ||||
20 | | ||||
21 | // ---------------------------------------------------------------------------- | ||||
22 | // QT Includes | ||||
23 | | ||||
24 | #include <QLabel> | ||||
25 | #include <QFont> | ||||
26 | #include <QHBoxLayout> | ||||
27 | #include <QList> | ||||
28 | #include <QVBoxLayout> | ||||
29 | #include <QPushButton> | ||||
30 | #include <QIcon> | ||||
31 | #include <QStyle> | ||||
32 | | ||||
33 | // ---------------------------------------------------------------------------- | ||||
34 | // KDE Includes | ||||
35 | | ||||
36 | #include <KLocalizedString> | ||||
37 | #include <KStandardGuiItem> | ||||
38 | #include <KColorScheme> | ||||
39 | #include <KHelpClient> | ||||
40 | | ||||
41 | // ---------------------------------------------------------------------------- | ||||
42 | // Project Includes | ||||
43 | | ||||
44 | #include "kmymoneywizardpage.h" | ||||
45 | #include "kmymoneytitlelabel.h" | ||||
46 | #include "icons/icons.h" | ||||
47 | | ||||
48 | using namespace Icons; | ||||
49 | | ||||
50 | KMyMoneyWizard::KMyMoneyWizard(QWidget *parent, bool modal, Qt::WindowFlags f) : | ||||
51 | QDialog(parent, f), | ||||
52 | d_ptr(new KMyMoneyWizardPrivate(this)) | ||||
53 | { | ||||
54 | Q_D(KMyMoneyWizard); | ||||
55 | d->init(modal); | ||||
56 | } | ||||
57 | | ||||
58 | KMyMoneyWizard::KMyMoneyWizard(KMyMoneyWizardPrivate &dd, QWidget* parent, bool modal, Qt::WindowFlags f) : | ||||
59 | QDialog(parent, f), | ||||
60 | d_ptr(&dd) | ||||
61 | { | ||||
62 | Q_D(KMyMoneyWizard); | ||||
63 | d->init(modal); | ||||
64 | } | ||||
65 | | ||||
66 | KMyMoneyWizard::~KMyMoneyWizard() | ||||
67 | { | ||||
68 | Q_D(KMyMoneyWizard); | ||||
69 | delete d; | ||||
70 | } | ||||
71 | | ||||
72 | void KMyMoneyWizard::setTitle(const QString& txt) | ||||
73 | { | ||||
74 | Q_D(KMyMoneyWizard); | ||||
75 | d->m_titleLabel->setText(txt); | ||||
76 | } | ||||
77 | | ||||
78 | void KMyMoneyWizard::addStep(const QString& text) | ||||
79 | { | ||||
80 | Q_D(KMyMoneyWizard); | ||||
81 | QLabel* step = new QLabel(text, d->m_stepFrame); | ||||
82 | step->setFrameStyle(QFrame::Panel | QFrame::Raised); | ||||
83 | step->setAlignment(Qt::AlignHCenter); | ||||
84 | step->setFrameStyle(QFrame::Box | QFrame::Sunken); | ||||
85 | step->setMargin(2); | ||||
86 | step->setPalette(d->m_stepPalette); | ||||
87 | | ||||
88 | d->m_steps.append(step); | ||||
89 | d->m_stepLayout->insertWidget(d->m_steps.count(), step); | ||||
90 | | ||||
91 | QFont font(step->font()); | ||||
92 | font.setBold(true); | ||||
93 | QFontMetrics fm(font); | ||||
94 | int w = fm.width(text) + 30; | ||||
95 | if (d->m_stepFrame->minimumWidth() < w) { | ||||
96 | d->m_stepFrame->setMinimumWidth(w); | ||||
97 | } | ||||
98 | } | ||||
99 | | ||||
100 | QList<KMyMoneyWizardPage*> KMyMoneyWizard::historyPages() const | ||||
101 | { | ||||
102 | Q_D(const KMyMoneyWizard); | ||||
103 | return d->m_history; | ||||
104 | } | ||||
105 | | ||||
106 | void KMyMoneyWizard::reselectStep() | ||||
107 | { | ||||
108 | Q_D(KMyMoneyWizard); | ||||
109 | d->selectStep(d->m_step); | ||||
110 | } | ||||
111 | | ||||
112 | void KMyMoneyWizard::setHelpContext(const QString& ctx) | ||||
113 | { | ||||
114 | Q_D(KMyMoneyWizard); | ||||
115 | d->m_helpContext = ctx; | ||||
116 | } | ||||
117 | | ||||
118 | void KMyMoneyWizard::backButtonClicked() | ||||
119 | { | ||||
120 | Q_D(KMyMoneyWizard); | ||||
121 | KMyMoneyWizardPage* oldPage = d->m_history.back(); | ||||
122 | d->m_history.pop_back(); | ||||
123 | oldPage->leavePage(); | ||||
124 | oldPage->resetPage(); | ||||
125 | d->switchPage(oldPage); | ||||
126 | } | ||||
127 | | ||||
128 | void KMyMoneyWizard::nextButtonClicked() | ||||
129 | { | ||||
130 | Q_D(KMyMoneyWizard); | ||||
131 | // make sure it is really complete. Some widgets only change state during focusOutEvent, | ||||
132 | // so we just create such an animal by changing the focus to the next button and | ||||
133 | // check again for copmpleness | ||||
134 | d->m_nextButton->setFocus(); | ||||
135 | KMyMoneyWizardPage* oldPage = d->m_history.back(); | ||||
136 | if (oldPage->isComplete()) { | ||||
137 | KMyMoneyWizardPage* newPage = oldPage->nextPage(); | ||||
138 | d->m_history.append(newPage); | ||||
139 | newPage->enterPage(); | ||||
140 | newPage->resetPage(); | ||||
141 | d->switchPage(oldPage); | ||||
142 | } | ||||
143 | } | ||||
144 | | ||||
145 | void KMyMoneyWizard::helpButtonClicked() | ||||
146 | { | ||||
147 | Q_D(KMyMoneyWizard); | ||||
148 | KMyMoneyWizardPage* currentPage = d->m_history.back(); | ||||
149 | QString ctx = currentPage->helpContext(); | ||||
150 | if (ctx.isEmpty()) | ||||
151 | ctx = d->m_helpContext; | ||||
152 | KHelpClient::invokeHelp(ctx); | ||||
153 | } | ||||
154 | | ||||
155 | void KMyMoneyWizard::completeStateChanged() | ||||
156 | { | ||||
157 | Q_D(KMyMoneyWizard); | ||||
158 | KMyMoneyWizardPage* currentPage = d->m_history.back(); | ||||
159 | bool lastPage = currentPage->isLastPage(); | ||||
160 | | ||||
161 | d->m_finishButton->setVisible(lastPage); | ||||
162 | d->m_nextButton->setVisible(!lastPage); | ||||
163 | | ||||
164 | QPushButton* button; | ||||
165 | | ||||
166 | button = lastPage ? d->m_finishButton : d->m_nextButton; | ||||
167 | | ||||
168 | auto rc = currentPage->isComplete(); | ||||
169 | button->setEnabled(rc); | ||||
170 | | ||||
171 | d->m_backButton->setEnabled(d->m_history.count() > 1); | ||||
172 | } | ||||
173 | | ||||
174 | void KMyMoneyWizard::accept() | ||||
175 | { | ||||
176 | Q_D(KMyMoneyWizard); | ||||
177 | // make sure it is really complete. Some widgets only change state during focusOutEvent, | ||||
178 | // so we just create such an animal by changing the focus to the finish button and | ||||
179 | // check again for completeness. | ||||
180 | d->m_finishButton->setFocus(); | ||||
181 | KMyMoneyWizardPage* page = d->m_history.back(); | ||||
182 | if (page->isComplete()) | ||||
183 | QDialog::accept(); | ||||
184 | } |