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

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • 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 
27 class 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 
68 KAssistantDialog::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 
78 KAssistantDialog::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 
85 KAssistantDialog::~KAssistantDialog()
86 {
87  delete d;
88 }
89 
90 void 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 
109 void KAssistantDialog::back()
110 {
111  QModelIndex nextIndex=d->getPrevious(d->pageModel->index(currentPage()));
112  if (nextIndex.isValid())
113  setCurrentPage(d->pageModel->item(nextIndex));
114 }
115 
116 void 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 
125 void KAssistantDialog::setValid(KPageWidgetItem * page, bool enable)
126 {
127  d->valid[page]=enable;
128  if (page == currentPage())
129  d->_k_slotUpdateButtons();
130 }
131 
132 bool KAssistantDialog::isValid(KPageWidgetItem * page) const
133 {
134  return d->valid.value(page, true);
135 }
136 
137 void 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 
150 void 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 
156 void KAssistantDialog::setAppropriate(KPageWidgetItem * page, bool appropriate)
157 {
158  d->appropriate[page]=appropriate;
159  d->_k_slotUpdateButtons();
160 }
161 
162 bool KAssistantDialog::isAppropriate(KPageWidgetItem * page) const
163 {
164  return d->appropriate.value(page, true);
165 }
166 
167 #include "kassistantdialog.moc"
i18n
QString i18n(const char *text)
QModelIndex
QWidget
KPageDialog
A dialog base class which can handle multiple pages.
Definition: kpagedialog.h:65
KStandardGuiItem::back
KGuiItem back(BidiMode useBidi)
Returns the 'Back' gui item, like Konqueror's back button.
Definition: kstandardguiitem.cpp:206
kdebug.h
KStandardAction::back
KAction * back(const QObject *recvr, const char *slot, QObject *parent)
Move back (web style menu).
Definition: kstandardaction.cpp:394
KPageDialog::setCurrentPage
void setCurrentPage(KPageWidgetItem *item)
Sets the page which is associated with the given.
Definition: kpagedialog.cpp:108
KDialog::Cancel
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected) ...
Definition: kdialog.h:144
KAssistantDialog::isAppropriate
bool isAppropriate(KPageWidgetItem *page) const
Check if a page is appropriate for use in the assistant dialog.
Definition: kassistantdialog.cpp:162
KAssistantDialog::back
virtual void back()
Called when the user clicks the Back button.
Definition: kassistantdialog.cpp:109
kstandardguiitem.h
KAssistantDialog::KAssistantDialog
KAssistantDialog(QWidget *parent=0, Qt::WindowFlags flags=0)
Construct a new assistant dialog with parent as parent.
Definition: kassistantdialog.cpp:68
klocale.h
KAssistantDialog::next
virtual void next()
Called when the user clicks the Next/Finish button.
Definition: kassistantdialog.cpp:116
KAssistantDialog::~KAssistantDialog
virtual ~KAssistantDialog()
Definition: kassistantdialog.cpp:85
KPageDialog::Plain
Definition: kpagedialog.h:90
KPageWidgetModel
This page model is used by.
Definition: kpagewidgetmodel.h:188
i18nc
QString i18nc(const char *ctxt, const char *text)
KAssistantDialog
This class provides a framework for assistant dialogs.
Definition: kassistantdialog.h:54
QModelIndex::isValid
bool isValid() const
KPageDialog::currentPage
KPageWidgetItem * currentPage() const
Returns the.
Definition: kpagedialog.cpp:113
KAssistantDialog::setAppropriate
void setAppropriate(KPageWidgetItem *page, bool appropriate)
Specify whether a page is appropriate.
Definition: kassistantdialog.cpp:156
KAssistantDialog::isValid
bool isValid(KPageWidgetItem *page) const
return if a page is valid
Definition: kassistantdialog.cpp:132
QHash< KPageWidgetItem *, bool >
QShowEvent
QModelIndex::row
int row() const
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:40
KDialog::Help
Show Help button. (this button will run the help set with setHelp)
Definition: kdialog.h:139
QModelIndex::parent
QModelIndex parent() const
KPageView::model
QAbstractItemModel * model() const
Returns the model of the page view.
Definition: kpageview.cpp:350
KDialog::User3
Show User defined button 3.
Definition: kdialog.h:152
QDialog::accept
virtual void accept()
KPageWidget
Page widget with many layouts (faces).
Definition: kpagewidget.h:36
KStandardAction::next
KAction * next(const QObject *recvr, const char *slot, QObject *parent)
Scroll down one page.
Definition: kstandardaction.cpp:414
KStandardGuiItem::forward
KGuiItem forward(BidiMode useBidi)
Returns the 'Forward' gui item, like Konqueror's forward button.
Definition: kstandardguiitem.cpp:214
QModelIndex::child
QModelIndex child(int row, int column) const
kassistantdialog.h
QModelIndex::sibling
QModelIndex sibling(int row, int column) const
KPageWidgetItem
KPageWidgetItem is used by KPageWidget and represents a page.
Definition: kpagewidgetmodel.h:50
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
KDialog::User2
Show User defined button 2.
Definition: kdialog.h:151
KStandardGuiItem::UseRTL
Definition: kstandardguiitem.h:46
QDialog::showEvent
virtual void showEvent(QShowEvent *event)
Qt::WindowFlags
typedef WindowFlags
KAssistantDialog::showEvent
virtual void showEvent(QShowEvent *event)
Definition: kassistantdialog.cpp:150
KDialog::User1
Show User defined button 1.
Definition: kdialog.h:150
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:23:58 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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