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

KDEUI

kassistantdialog.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002     Copyright (C) 2006 Olivier Goffart <ogoffart at kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License version 2 as published by the Free Software Foundation.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library; see the file COPYING.LIB.  If not, write to
00015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "kassistantdialog.h"
00020 
00021 #include <kstandardguiitem.h>
00022 #include <klocale.h>
00023 #include <kdebug.h>
00024 
00025 #include <QHash>
00026 
00027 class KAssistantDialog::Private
00028 {
00029     public:
00030         Private(KAssistantDialog *q)
00031             : q(q)
00032         {
00033         }
00034 
00035         KAssistantDialog *q;
00036         QHash<KPageWidgetItem*, bool> valid;
00037         QHash<KPageWidgetItem*, bool> appropriate;
00038         KPageWidgetModel *pageModel;
00039 
00040         void init();
00041         void _k_slotCurrentPageChanged();
00042 
00043         QModelIndex getNext(QModelIndex nextIndex)
00044         {
00045             QModelIndex currentIndex;
00046             do {
00047                 currentIndex=nextIndex;
00048                 nextIndex=currentIndex.child(0, 0);
00049                 if (!nextIndex.isValid())
00050                     nextIndex=currentIndex.sibling(currentIndex.row() + 1, 0);
00051             } while (nextIndex.isValid() && !appropriate.value(pageModel->item(nextIndex), true));
00052             return nextIndex;
00053         }
00054 
00055         QModelIndex getPrevious(QModelIndex nextIndex)
00056         {
00057             QModelIndex currentIndex;
00058             do {
00059                 currentIndex=nextIndex;
00060                 nextIndex=currentIndex.sibling(currentIndex.row() - 1, 0);
00061                 if (!nextIndex.isValid())
00062                     nextIndex=currentIndex.parent();
00063             } while (nextIndex.isValid() && !appropriate.value(pageModel->item(nextIndex), true));
00064             return nextIndex;
00065         }
00066 };
00067 
00068 KAssistantDialog::KAssistantDialog(QWidget * parent, Qt::WFlags flags)
00069     : KPageDialog(parent, flags), d(new Private(this))
00070 {
00071     d->init();
00072     //workaround to get the page model
00073     KPageWidget *pagewidget=findChild<KPageWidget*>();
00074     Q_ASSERT(pagewidget);
00075     d->pageModel=static_cast<KPageWidgetModel*>(pagewidget->model());
00076 }
00077 
00078 KAssistantDialog::KAssistantDialog(KPageWidget *widget, QWidget *parent, Qt::WFlags flags)
00079     : KPageDialog(widget, parent, flags), d(new Private(this))
00080 {
00081     d->init();
00082     d->pageModel=static_cast<KPageWidgetModel*>(widget->model());
00083 }
00084 
00085 KAssistantDialog::~KAssistantDialog()
00086 {
00087     delete d;
00088 }
00089 
00090 void KAssistantDialog::Private::init()
00091 {
00092     q->setButtons(KDialog::Cancel | KDialog::User1 | KDialog::User2 | KDialog::User3 | KDialog::Help);
00093     q->setButtonGuiItem( KDialog::User3, KStandardGuiItem::back(KStandardGuiItem::UseRTL) );
00094     q->setButtonText( KDialog::User2, i18nc("Opposite to Back", "Next") );
00095     q->setButtonText(KDialog::User1, i18n("Finish"));
00096     q->setButtonIcon( KDialog::User2, KStandardGuiItem::forward(KStandardGuiItem::UseRTL).icon() );
00097     q->setButtonIcon( KDialog::User1, KIcon("dialog-ok-apply") );
00098     q->setDefaultButton(KDialog::User2);
00099     q->showButtonSeparator(true);
00100     q->setFaceType(KPageDialog::Plain);
00101 
00102     q->connect(q, SIGNAL(user3Clicked()), q, SLOT(back()));
00103     q->connect(q, SIGNAL(user2Clicked()), q, SLOT(next()));
00104     q->connect(q, SIGNAL(user1Clicked()), q, SLOT(accept()));
00105 
00106     q->connect(q, SIGNAL(currentPageChanged(KPageWidgetItem *, KPageWidgetItem *)), q, SLOT(_k_slotCurrentPageChanged()));
00107 }
00108 
00109 
00110 void KAssistantDialog::back()
00111 {
00112     QModelIndex nextIndex=d->getPrevious(d->pageModel->index(currentPage()));
00113     if (nextIndex.isValid())
00114         setCurrentPage(d->pageModel->item(nextIndex));
00115 }
00116 
00117 void KAssistantDialog::next()
00118 {
00119     QModelIndex nextIndex=d->getNext(d->pageModel->index(currentPage()));
00120     if (nextIndex.isValid())
00121         setCurrentPage(d->pageModel->item(nextIndex));
00122 }
00123 
00124 void KAssistantDialog::setValid(KPageWidgetItem * page, bool enable)
00125 {
00126     d->valid[page]=enable;
00127     if (page == currentPage())
00128         d->_k_slotCurrentPageChanged();
00129 }
00130 
00131 bool KAssistantDialog::isValid(KPageWidgetItem * page) const
00132 {
00133     return d->valid.value(page, true);
00134 }
00135 
00136 void KAssistantDialog::Private::_k_slotCurrentPageChanged()
00137 {
00138     QModelIndex currentIndex=pageModel->index(q->currentPage());
00139     //change the caption of the next/finish button
00140     QModelIndex nextIndex=getNext(currentIndex);
00141     q->enableButton(KDialog::User1, !nextIndex.isValid() && q->isValid(q->currentPage()));
00142     q->enableButton(KDialog::User2, nextIndex.isValid() && q->isValid(q->currentPage()));
00143     q->setDefaultButton(nextIndex.isValid() ? KDialog::User2 : KDialog::User1);
00144     //enable or disable the back button;
00145     nextIndex=getPrevious(currentIndex);
00146     q->enableButton(KDialog::User3, nextIndex.isValid());
00147 }
00148 
00149 void KAssistantDialog::showEvent(QShowEvent * event)
00150 {
00151     d->_k_slotCurrentPageChanged(); //called because last time that function was called is when the first page was added, so the next button show "finish"
00152     KPageDialog::showEvent(event);
00153 }
00154 
00155 void KAssistantDialog::setAppropriate(KPageWidgetItem * page, bool appropriate)
00156 {
00157     d->appropriate[page]=appropriate;
00158 }
00159 
00160 bool KAssistantDialog::isAppropriate(KPageWidgetItem * page) const
00161 {
00162     return d->appropriate.value(page, true);
00163 }
00164 
00165 #include "kassistantdialog.moc"

KDEUI

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal