Vidalia 0.2.10

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 3735 2009-04-28 20:28:01Z edmanm $
00014 ** \brief A collection of configuration pages
00015 */
00016 
00017 #include "ConfigPageStack.h"
00018 
00019 #include <QAction>
00020 
00021 
00022 /** Default constructor. */
00023 ConfigPageStack::ConfigPageStack(QWidget *parent)
00024 : QStackedWidget(parent)
00025 {
00026 }
00027 
00028 /** Adds a page to the stack. */
00029 void
00030 ConfigPageStack::add(ConfigPage *page, QAction *action)
00031 {
00032   _pages.insert(action, page);
00033   insertWidget(count(), page);
00034 }
00035 
00036 /** Sets the current config page and checks its action. */
00037 void
00038 ConfigPageStack::setCurrentPage(ConfigPage *page)
00039 {
00040   foreach (QAction *action, _pages.keys(page)) {
00041     action->setChecked(true);
00042   }
00043   setCurrentWidget(page);
00044 }
00045 
00046 /** Sets the current config page index and checks its action. */
00047 void
00048 ConfigPageStack::setCurrentIndex(int index)
00049 {
00050   setCurrentPage((ConfigPage *)widget(index));
00051 }
00052 
00053 /** Shows the config page associated with the activated action. */
00054 void
00055 ConfigPageStack::showPage(QAction *pageAction)
00056 {
00057   setCurrentWidget(_pages.value(pageAction));
00058 }
00059 
00060 /** Returns a list of all pages in the stack. The order of the pages in the
00061  * returned QList is the same as the order in which the pages were initially
00062  * added to the stack. */
00063 QList<ConfigPage *>
00064 ConfigPageStack::pages() const
00065 {
00066   QList<ConfigPage *> pages;
00067   for (int i = 0; i < count(); i++)
00068     pages << dynamic_cast<ConfigPage *>(widget(i));
00069   return pages;
00070 }
00071