configpagestack.cpp

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file configpagestack.cpp
00013 ** \version $Id: configpagestack.cpp 2367 2008-03-01 22:11:52Z edmanm $
00014 ** \brief A collection of configuration pages
00015 */
00016 
00017 #include <QAction>
00018 #include "configpagestack.h"
00019 
00020 
00021 /** Default constructor. */
00022 ConfigPageStack::ConfigPageStack(QWidget *parent)
00023 : QStackedWidget(parent)
00024 {
00025 }
00026 
00027 /** Adds a page to the stack. */
00028 void
00029 ConfigPageStack::add(ConfigPage *page, QAction *action)
00030 {
00031   _pages.insert(action, page);
00032   insertWidget(count(), page);
00033 }
00034 
00035 /** Sets the current config page and checks its action. */
00036 void
00037 ConfigPageStack::setCurrentPage(ConfigPage *page)
00038 {
00039   foreach (QAction *action, _pages.keys(page)) {
00040     action->setChecked(true);
00041   }
00042   setCurrentWidget(page);
00043 }
00044 
00045 /** Sets the current config page index and checks its action. */
00046 void
00047 ConfigPageStack::setCurrentIndex(int index)
00048 {
00049   setCurrentPage((ConfigPage *)widget(index));
00050 }
00051 
00052 /** Shows the config page associated with the activated action. */
00053 void
00054 ConfigPageStack::showPage(QAction *pageAction)
00055 {
00056   setCurrentWidget(_pages.value(pageAction));
00057 }
00058 
00059 /** Returns a list of all pages in the stack. The order of the pages in the
00060  * returned QList is the same as the order in which the pages were initially
00061  * added to the stack. */
00062 QList<ConfigPage *>
00063 ConfigPageStack::pages() const
00064 {
00065   QList<ConfigPage *> pages;
00066   for (int i = 0; i < count(); i++)
00067     pages << dynamic_cast<ConfigPage *>(widget(i));
00068   return pages;
00069 }
00070 

Generated on 2 Sep 2009 for Vidalia by  doxygen 1.6.1