• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.5 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 
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"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Jul 16 2013 17:49:36 by doxygen 1.8.1.1 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.10.5 API Reference

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