33 #include <config-kleopatra.h>
42 #include <KLocalizedString>
43 #include <KPushButton>
44 #include <KStandardGuiItem>
46 #include <QDialogButtonBox>
49 #include <QStackedWidget>
51 #include <QVBoxLayout>
58 using namespace Kleo::Crypto::Gui;
60 class Wizard::Private {
61 friend class ::Wizard;
64 explicit Private(
Wizard * qq );
67 void updateButtonStates();
68 bool isLastPage(
int id )
const;
69 int previousPage()
const;
73 std::vector<int> pageOrder;
74 std::set<int> hiddenPages;
75 std::map<int, WizardPage*> idToPage;
78 KPushButton* nextButton;
92 Wizard::Private::Private(
Wizard * qq )
95 nextPageTimer =
new QTimer(
q );
96 nextPageTimer->setInterval( 0 );
97 connect( nextPageTimer, SIGNAL(timeout()),
q, SLOT(next()) );
98 nextItem = KGuiItem( i18n(
"&Next" ) );
99 finishItem = KStandardGuiItem::ok();
104 titleFrame->setAutoFillBackground(
true );
105 titleFrame->setBackgroundRole( QPalette::Base );
109 subTitleLabel =
new QLabel;
113 titleFrame->setVisible(
false );
117 explanationFrame =
new QFrame;
119 explanationFrame->setAutoFillBackground(
true );
120 explanationFrame->setBackgroundRole( QPalette::Base );
122 explanationLabel =
new QLabel;
124 explanationLayout->
addWidget( explanationLabel );
126 explanationFrame->setVisible(
false );
132 cancelButton = box->
addButton( QDialogButtonBox::Cancel );
133 q->connect( cancelButton, SIGNAL(clicked()),
q, SLOT(reject()) );
136 backButton->
setText( i18n(
"Back" ) );
137 q->connect( backButton, SIGNAL(clicked()),
q, SLOT(back()) );
138 box->
addButton( backButton, QDialogButtonBox::ActionRole );
140 nextButton =
new KPushButton;
141 nextButton->setGuiItem( nextItem );
142 q->connect( nextButton, SIGNAL(clicked()),
q, SLOT(next()) );
143 box->
addButton( nextButton, QDialogButtonBox::ActionRole );
148 q->connect(
q, SIGNAL(rejected()),
q, SIGNAL(canceled()) );
151 Wizard::Private::~Private() { kDebug(); }
155 bool Wizard::Private::isLastPage(
int id )
const
157 return !pageOrder.empty() ? pageOrder.back() ==
id :
false;
160 void Wizard::Private::updateButtonStates()
162 const bool isLast = isLastPage( currentId );
163 const bool canGoToNext =
q->canGoToNextPage();
166 if ( customNext.text().isEmpty() && customNext.icon().isNull() )
167 nextButton->setGuiItem( isLast ? finishItem : nextItem );
169 nextButton->setGuiItem( customNext );
170 nextButton->setEnabled( canGoToNext );
171 cancelButton->setEnabled( !isLast || !canGoToNext );
172 backButton->setEnabled(
q->canGoToPreviousPage() );
174 nextPageTimer->start();
177 void Wizard::Private::updateHeader()
180 assert( !widget || stack->indexOf( widget ) != -1 );
182 stack->setCurrentWidget( widget );
187 titleLabel->setVisible( !title.
isEmpty() );
188 titleLabel->setText( title );
189 subTitleLabel->setText( subTitle );
190 subTitleLabel->setVisible( !subTitle.
isEmpty() );
191 explanationFrame->setVisible( !explanation.
isEmpty() );
192 explanationLabel->setVisible( !explanation.
isEmpty() );
193 explanationLabel->setText( explanation );
194 q->resize(
q->sizeHint().expandedTo(
q->size() ) );
198 :
QDialog( parent, f ),
d( new Private( this ) )
208 kleo_assert( d->idToPage.find(
id ) == d->idToPage.end() );
209 d->idToPage[id] = widget;
210 d->stack->addWidget( widget );
211 connect( widget, SIGNAL(completeChanged()),
this, SLOT(updateButtonStates()) );
212 connect( widget, SIGNAL(titleChanged()),
this, SLOT(updateHeader()) );
213 connect( widget, SIGNAL(subTitleChanged()),
this, SLOT(updateHeader()) );
214 connect( widget, SIGNAL(explanationChanged()),
this, SLOT(updateHeader()) );
215 connect( widget, SIGNAL(autoAdvanceChanged()),
this, SLOT(updateButtonStates()) );
221 d->pageOrder = pageOrder;
222 d->hiddenPages.clear();
223 if ( pageOrder.empty() )
234 d->updateButtonStates();
240 d->hiddenPages.erase(
id );
242 d->hiddenPages.insert(
id );
255 return current ? current->
isComplete() :
false;
260 const int prev = d->previousPage();
275 std::vector<int>::const_iterator it = qBinaryFind( d->pageOrder.begin(), d->pageOrder.end(), d->currentId );
276 assert( it != d->pageOrder.end() );
281 while ( d->hiddenPages.find( *it ) != d->hiddenPages.end() );
283 if ( it == d->pageOrder.end() )
294 int Wizard::Private::previousPage()
const
296 if ( pageOrder.empty() )
299 std::vector<int>::const_iterator it = qBinaryFind( pageOrder.begin(), pageOrder.end(), currentId );
300 if ( it == pageOrder.begin() || it == pageOrder.end() )
305 }
while ( it != pageOrder.begin() && hiddenPages.find( *it ) != hiddenPages.end() );
312 const int prev = d->previousPage();
323 const std::map<int, WizardPage*>::const_iterator it = d->idToPage.find(
id );
330 return page( d->currentId );
336 return page( d->currentId );
341 Q_UNUSED( currentId )
347 Q_UNUSED( currentId )
355 const std::map<int, WizardPage*>::const_iterator it = d->idToPage.find(
id );
360 #include "moc_wizard.cpp"
const WizardPage * page(int id) const
void setPageOrder(const std::vector< int > &pages)
void setFrameShape(Shape)
virtual void onNext(int currentId)
bool canGoToNextPage() const
void setCurrentPage(int id)
bool canGoToPreviousPage() const
void setMargin(int margin)
bool isCommitPage() const
QString explanation() const
#define kleo_assert(cond)
virtual void onBack(int currentId)
const WizardPage * currentPageWidget() const
KGuiItem customNextButton() const
void setText(const QString &text)
virtual bool isComplete() const =0
void setPage(int id, WizardPage *page)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setWordWrap(bool on)
void setPageVisible(int id, bool visible)