• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • dialogs
kassistantdialog.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 2006 Olivier Goffart <ogoffart at kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#include "kassistantdialog.h"
20
21#include <kstandardguiitem.h>
22#include <klocale.h>
23#include <kdebug.h>
24
25#include <QHash>
26
27class KAssistantDialog::Private
28{
29 public:
30 Private(KAssistantDialog *q)
31 : q(q)
32 {
33 }
34
35 KAssistantDialog *q;
36 QHash<KPageWidgetItem*, bool> valid;
37 QHash<KPageWidgetItem*, bool> appropriate;
38 KPageWidgetModel *pageModel;
39
40 void init();
41 void _k_slotUpdateButtons();
42
43 QModelIndex getNext(QModelIndex nextIndex)
44 {
45 QModelIndex currentIndex;
46 do {
47 currentIndex=nextIndex;
48 nextIndex=currentIndex.child(0, 0);
49 if (!nextIndex.isValid())
50 nextIndex=currentIndex.sibling(currentIndex.row() + 1, 0);
51 } while (nextIndex.isValid() && !appropriate.value(pageModel->item(nextIndex), true));
52 return nextIndex;
53 }
54
55 QModelIndex getPrevious(QModelIndex nextIndex)
56 {
57 QModelIndex currentIndex;
58 do {
59 currentIndex=nextIndex;
60 nextIndex=currentIndex.sibling(currentIndex.row() - 1, 0);
61 if (!nextIndex.isValid())
62 nextIndex=currentIndex.parent();
63 } while (nextIndex.isValid() && !appropriate.value(pageModel->item(nextIndex), true));
64 return nextIndex;
65 }
66};
67
68KAssistantDialog::KAssistantDialog(QWidget * parent, Qt::WindowFlags flags)
69 : KPageDialog(parent, flags), d(new Private(this))
70{
71 d->init();
72 //workaround to get the page model
73 KPageWidget *pagewidget=findChild<KPageWidget*>();
74 Q_ASSERT(pagewidget);
75 d->pageModel=static_cast<KPageWidgetModel*>(pagewidget->model());
76}
77
78KAssistantDialog::KAssistantDialog(KPageWidget *widget, QWidget *parent, Qt::WindowFlags flags)
79 : KPageDialog(widget, parent, flags), d(new Private(this))
80{
81 d->init();
82 d->pageModel=static_cast<KPageWidgetModel*>(widget->model());
83}
84
85KAssistantDialog::~KAssistantDialog()
86{
87 delete d;
88}
89
90void KAssistantDialog::Private::init()
91{
92 q->setButtons(KDialog::Cancel | KDialog::User1 | KDialog::User2 | KDialog::User3 | KDialog::Help);
93 q->setButtonGuiItem( KDialog::User3, KStandardGuiItem::back(KStandardGuiItem::UseRTL) );
94 q->setButtonText( KDialog::User2, i18nc("Opposite to Back", "Next") );
95 q->setButtonText(KDialog::User1, i18n("Finish"));
96 q->setButtonIcon( KDialog::User2, KStandardGuiItem::forward(KStandardGuiItem::UseRTL).icon() );
97 q->setButtonIcon( KDialog::User1, KIcon("dialog-ok-apply") );
98 q->setDefaultButton(KDialog::User2);
99 q->setFaceType(KPageDialog::Plain);
100
101 q->connect(q, SIGNAL(user3Clicked()), q, SLOT(back()));
102 q->connect(q, SIGNAL(user2Clicked()), q, SLOT(next()));
103 q->connect(q, SIGNAL(user1Clicked()), q, SLOT(accept()));
104
105 q->connect(q, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), q, SLOT(_k_slotUpdateButtons()));
106}
107
108
109void KAssistantDialog::back()
110{
111 QModelIndex nextIndex=d->getPrevious(d->pageModel->index(currentPage()));
112 if (nextIndex.isValid())
113 setCurrentPage(d->pageModel->item(nextIndex));
114}
115
116void KAssistantDialog::next()
117{
118 QModelIndex nextIndex=d->getNext(d->pageModel->index(currentPage()));
119 if (nextIndex.isValid())
120 setCurrentPage(d->pageModel->item(nextIndex));
121 else if (isValid(currentPage()))
122 accept();
123}
124
125void KAssistantDialog::setValid(KPageWidgetItem * page, bool enable)
126{
127 d->valid[page]=enable;
128 if (page == currentPage())
129 d->_k_slotUpdateButtons();
130}
131
132bool KAssistantDialog::isValid(KPageWidgetItem * page) const
133{
134 return d->valid.value(page, true);
135}
136
137void KAssistantDialog::Private::_k_slotUpdateButtons()
138{
139 QModelIndex currentIndex=pageModel->index(q->currentPage());
140 //change the caption of the next/finish button
141 QModelIndex nextIndex=getNext(currentIndex);
142 q->enableButton(KDialog::User1, !nextIndex.isValid() && q->isValid(q->currentPage()));
143 q->enableButton(KDialog::User2, nextIndex.isValid() && q->isValid(q->currentPage()));
144 q->setDefaultButton(nextIndex.isValid() ? KDialog::User2 : KDialog::User1);
145 //enable or disable the back button;
146 nextIndex=getPrevious(currentIndex);
147 q->enableButton(KDialog::User3, nextIndex.isValid());
148}
149
150void KAssistantDialog::showEvent(QShowEvent * event)
151{
152 d->_k_slotUpdateButtons(); //called because last time that function was called is when the first page was added, so the next button show "finish"
153 KPageDialog::showEvent(event);
154}
155
156void KAssistantDialog::setAppropriate(KPageWidgetItem * page, bool appropriate)
157{
158 d->appropriate[page]=appropriate;
159 d->_k_slotUpdateButtons();
160}
161
162bool KAssistantDialog::isAppropriate(KPageWidgetItem * page) const
163{
164 return d->appropriate.value(page, true);
165}
166
167#include "kassistantdialog.moc"
KAssistantDialog
This class provides a framework for assistant dialogs.
Definition: kassistantdialog.h:55
KAssistantDialog::isValid
bool isValid(KPageWidgetItem *page) const
return if a page is valid
Definition: kassistantdialog.cpp:132
KAssistantDialog::showEvent
virtual void showEvent(QShowEvent *event)
Definition: kassistantdialog.cpp:150
KAssistantDialog::~KAssistantDialog
virtual ~KAssistantDialog()
Definition: kassistantdialog.cpp:85
KAssistantDialog::back
virtual void back()
Called when the user clicks the Back button.
Definition: kassistantdialog.cpp:109
KAssistantDialog::next
virtual void next()
Called when the user clicks the Next/Finish button.
Definition: kassistantdialog.cpp:116
KAssistantDialog::isAppropriate
bool isAppropriate(KPageWidgetItem *page) const
Check if a page is appropriate for use in the assistant dialog.
Definition: kassistantdialog.cpp:162
KAssistantDialog::setAppropriate
void setAppropriate(KPageWidgetItem *page, bool appropriate)
Specify whether a page is appropriate.
Definition: kassistantdialog.cpp:156
KAssistantDialog::setValid
void setValid(KPageWidgetItem *page, bool enable)
Specify if the content of the page is valid, and if the next button may be enabled on this page.
Definition: kassistantdialog.cpp:125
KAssistantDialog::KAssistantDialog
KAssistantDialog(QWidget *parent=0, Qt::WindowFlags flags=0)
Construct a new assistant dialog with parent as parent.
Definition: kassistantdialog.cpp:68
KDialog::setButtonIcon
void setButtonIcon(ButtonCode id, const KIcon &icon)
Sets the icon of any button.
Definition: kdialog.cpp:742
KDialog::setButtonGuiItem
void setButtonGuiItem(ButtonCode id, const KGuiItem &item)
Sets the KGuiItem directly for the button instead of using 3 methods to set the text,...
Definition: kdialog.cpp:699
KDialog::enableButton
void enableButton(ButtonCode id, bool state)
Enable or disable (gray out) a general action button.
Definition: kdialog.cpp:661
KDialog::setButtons
void setButtons(ButtonCodes buttonMask)
Creates (or recreates) the button box and all the buttons in it.
Definition: kdialog.cpp:206
KDialog::Help
@ Help
Show Help button. (this button will run the help set with setHelp)
Definition: kdialog.h:139
KDialog::User1
@ User1
Show User defined button 1.
Definition: kdialog.h:150
KDialog::Cancel
@ Cancel
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected)
Definition: kdialog.h:144
KDialog::User3
@ User3
Show User defined button 3.
Definition: kdialog.h:152
KDialog::User2
@ User2
Show User defined button 2.
Definition: kdialog.h:151
KDialog::setButtonText
void setButtonText(ButtonCode id, const QString &text)
Sets the text of any button.
Definition: kdialog.cpp:719
KDialog::setDefaultButton
void setDefaultButton(ButtonCode id)
Sets the button that will be activated when the Enter key is pressed.
Definition: kdialog.cpp:287
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:41
KPageDialog
A dialog base class which can handle multiple pages.
Definition: kpagedialog.h:66
KPageDialog::Plain
@ Plain
Definition: kpagedialog.h:90
KPageDialog::setCurrentPage
void setCurrentPage(KPageWidgetItem *item)
Sets the page which is associated with the given.
Definition: kpagedialog.cpp:108
KPageDialog::currentPage
KPageWidgetItem * currentPage() const
Returns the.
Definition: kpagedialog.cpp:113
KPageDialog::setFaceType
void setFaceType(FaceType faceType)
Sets the face type of the dialog.
Definition: kpagedialog.cpp:68
KPageView::model
QAbstractItemModel * model() const
Returns the model of the page view.
Definition: kpageview.cpp:350
KPageWidgetItem
KPageWidgetItem is used by KPageWidget and represents a page.
Definition: kpagewidgetmodel.h:51
KPageWidgetModel
This page model is used by.
Definition: kpagewidgetmodel.h:189
KPageWidgetModel::item
KPageWidgetItem * item(const QModelIndex &index) const
Returns the.
Definition: kpagewidgetmodel.cpp:520
KPageWidgetModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: kpagewidgetmodel.cpp:332
KPageWidget
Page widget with many layouts (faces).
Definition: kpagewidget.h:37
QHash
QWidget
kassistantdialog.h
kdebug.h
klocale.h
i18n
QString i18n(const char *text)
i18nc
QString i18nc(const char *ctxt, const char *text)
kstandardguiitem.h
KStandardGuiItem::UseRTL
@ UseRTL
Definition: kstandardguiitem.h:46
KStandardGuiItem::back
KGuiItem back(BidiMode useBidi)
Returns the 'Back' gui item, like Konqueror's back button.
Definition: kstandardguiitem.cpp:206
KStandardGuiItem::forward
KGuiItem forward(BidiMode useBidi)
Returns the 'Forward' gui item, like Konqueror's forward button.
Definition: kstandardguiitem.cpp:214
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal