• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • 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_slotUpdateButtons();
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->setFaceType(KPageDialog::Plain);
00100 
00101     q->connect(q, SIGNAL(user3Clicked()), q, SLOT(back()));
00102     q->connect(q, SIGNAL(user2Clicked()), q, SLOT(next()));
00103     q->connect(q, SIGNAL(user1Clicked()), q, SLOT(accept()));
00104 
00105     q->connect(q, SIGNAL(currentPageChanged(KPageWidgetItem *, KPageWidgetItem *)), q, SLOT(_k_slotUpdateButtons()));
00106 }
00107 
00108 
00109 void KAssistantDialog::back()
00110 {
00111     QModelIndex nextIndex=d->getPrevious(d->pageModel->index(currentPage()));
00112     if (nextIndex.isValid())
00113         setCurrentPage(d->pageModel->item(nextIndex));
00114 }
00115 
00116 void KAssistantDialog::next()
00117 {
00118     QModelIndex nextIndex=d->getNext(d->pageModel->index(currentPage()));
00119     if (nextIndex.isValid())
00120         setCurrentPage(d->pageModel->item(nextIndex));
00121 }
00122 
00123 void KAssistantDialog::setValid(KPageWidgetItem * page, bool enable)
00124 {
00125     d->valid[page]=enable;
00126     if (page == currentPage())
00127         d->_k_slotUpdateButtons();
00128 }
00129 
00130 bool KAssistantDialog::isValid(KPageWidgetItem * page) const
00131 {
00132     return d->valid.value(page, true);
00133 }
00134 
00135 void KAssistantDialog::Private::_k_slotUpdateButtons()
00136 {
00137     QModelIndex currentIndex=pageModel->index(q->currentPage());
00138     //change the caption of the next/finish button
00139     QModelIndex nextIndex=getNext(currentIndex);
00140     q->enableButton(KDialog::User1, !nextIndex.isValid() && q->isValid(q->currentPage()));
00141     q->enableButton(KDialog::User2, nextIndex.isValid() && q->isValid(q->currentPage()));
00142     q->setDefaultButton(nextIndex.isValid() ? KDialog::User2 : KDialog::User1);
00143     //enable or disable the back button;
00144     nextIndex=getPrevious(currentIndex);
00145     q->enableButton(KDialog::User3, nextIndex.isValid());
00146 }
00147 
00148 void KAssistantDialog::showEvent(QShowEvent * event)
00149 {
00150     d->_k_slotUpdateButtons(); //called because last time that function was called is when the first page was added, so the next button show "finish"
00151     KPageDialog::showEvent(event);
00152 }
00153 
00154 void KAssistantDialog::setAppropriate(KPageWidgetItem * page, bool appropriate)
00155 {
00156     d->appropriate[page]=appropriate;
00157     d->_k_slotUpdateButtons();
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
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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