Vidalia
0.2.17
|
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.torproject.org/projects/vidalia.html. No part of Vidalia, 00007 ** including this file, may be copied, modified, propagated, or distributed 00008 ** except according to the terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file ConfigPageStack.cpp 00013 ** \brief A collection of configuration pages 00014 */ 00015 00016 #include "ConfigPageStack.h" 00017 00018 #include <QAction> 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