listtabwidget.cpp
00001 /* 00002 This file is part of Akregator. 00003 00004 Copyright (C) 2005 Frank Osterfeld <frank.osterfeld at kdemail.net> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of TQt, and distribute the resulting executable, 00022 without including the source code for TQt in the source distribution. 00023 */ 00024 00025 #include "listtabwidget.h" 00026 #include "feedlistview.h" 00027 #include "folder.h" 00028 #include "treenode.h" 00029 00030 #include <tdemultitabbar.h> 00031 00032 #include <tqiconset.h> 00033 #include <tqlayout.h> 00034 #include <tqmap.h> 00035 #include <tqptrlist.h> 00036 #include <tqstring.h> 00037 #include <tqvaluelist.h> 00038 #include <tqwidgetstack.h> 00039 00040 #include <kdebug.h> 00041 00042 namespace Akregator { 00043 00044 class ListTabWidget::ListTabWidgetPrivate 00045 { 00046 00047 public: 00048 int idCounter; 00049 KMultiTabBar* tabBar; 00050 TQWidgetStack* stack; 00051 NodeListView* current; 00052 int currentID; 00053 TQValueList<NodeListView*> views; 00054 TQMap<int, NodeListView*> idToView; 00055 TQHBoxLayout* layout; 00056 ViewMode viewMode; 00057 TQMap<TQWidget*, TQString> captions; 00058 }; 00059 00060 00061 void ListTabWidget::slotItemUp() 00062 { 00063 if (d->current) 00064 d->current->slotItemUp(); 00065 } 00066 00067 void ListTabWidget::slotItemDown() 00068 { 00069 if (d->current) 00070 d->current->slotItemDown(); 00071 } 00072 00073 void ListTabWidget::slotItemBegin() 00074 { 00075 if (d->current) 00076 d->current->slotItemBegin(); 00077 } 00078 00079 void ListTabWidget::slotItemEnd() 00080 { 00081 if (d->current) 00082 d->current->slotItemEnd(); 00083 } 00084 00085 void ListTabWidget::slotItemLeft() 00086 { 00087 if (d->current) 00088 d->current->slotItemLeft(); 00089 } 00090 00091 void ListTabWidget::slotItemRight() 00092 { 00093 if (d->current) 00094 d->current->slotItemRight(); 00095 } 00096 00097 void ListTabWidget::slotPrevFeed() 00098 { 00099 if (d->current) 00100 d->current->slotPrevFeed(); 00101 } 00102 00103 void ListTabWidget::slotNextFeed() 00104 { 00105 if (d->current) 00106 d->current->slotNextFeed(); 00107 } 00108 00109 void ListTabWidget::slotPrevUnreadFeed() 00110 { 00111 if (d->current) 00112 d->current->slotPrevUnreadFeed(); 00113 } 00114 00115 void ListTabWidget::slotNextUnreadFeed() 00116 { 00117 if (d->current) 00118 d->current->slotNextUnreadFeed(); 00119 } 00120 00121 void ListTabWidget::slotRootNodeChanged(NodeListView* view, TreeNode* node) 00122 { 00123 /* 00124 int unread = node->unread(); 00125 if (unread > 0) 00126 { 00127 //uncomment this to append unread count 00128 //d->tabWidget->changeTab(view, TQString("<qt>%1 (%2)").arg(d->captions[view]).arg(node->unread())); 00129 d->tabWidget->changeTab(view, d->captions[view]); 00130 } 00131 else 00132 { 00133 d->tabWidget->changeTab(view, d->captions[view]); 00134 } 00135 */ 00136 } 00137 00138 void ListTabWidget::slotTabClicked(int id) 00139 { 00140 NodeListView* view = d->idToView[id]; 00141 if (view) 00142 { 00143 d->stack->raiseWidget(view); 00144 d->current = view; 00145 00146 if (d->currentID >= 0) 00147 d->tabBar->setTab(d->currentID, false); 00148 d->currentID = id; 00149 d->tabBar->setTab(d->currentID, true); 00150 00151 emit signalNodeSelected(d->current->selectedNode()); 00152 } 00153 } 00154 00155 ListTabWidget::ListTabWidget(TQWidget* parent, const char* name) : TQWidget(parent, name), d(new ListTabWidgetPrivate) 00156 { 00157 d->idCounter = 0; 00158 d->current = 0; 00159 d->currentID = -1; 00160 d->viewMode = verticalTabs; 00161 d->layout = new TQHBoxLayout(this); 00162 //d->layout = new TQGridLayout(this, 1, 2); 00163 d->tabBar = new KMultiTabBar(KMultiTabBar::Vertical, this); 00164 d->tabBar->setStyle(KMultiTabBar::KDEV3ICON); 00165 //d->tabBar->setStyle(KMultiTabBar::KDEV3); 00166 d->tabBar->showActiveTabTexts(true); 00167 d->tabBar->setPosition(KMultiTabBar::Left); 00168 d->layout->addWidget(d->tabBar/*, 0, 0*/); 00169 00170 d->stack = new TQWidgetStack(this); 00171 d->layout->addWidget(d->stack/*, 0, 1*/); 00172 00173 // connect(d->tabBar, TQT_SIGNAL(currentChanged(TQWidget*)), this, TQT_SLOT(slotCurrentChanged(TQWidget*))); 00174 } 00175 00176 ListTabWidget::~ListTabWidget() 00177 { 00178 delete d; 00179 d = 0; 00180 } 00181 00182 00183 void ListTabWidget::setViewMode(ViewMode mode) 00184 { 00185 if (mode == d->viewMode) 00186 return; 00187 00188 d->viewMode = mode; 00189 00190 // if mode is "single", we hide the tab bar 00191 d->tabBar->setHidden(mode == single); 00192 } 00193 00194 ListTabWidget::ViewMode ListTabWidget::viewMode() const 00195 { 00196 return d->viewMode; 00197 } 00198 00199 void ListTabWidget::addView(NodeListView* view, const TQString& caption, const TQPixmap& icon) 00200 { 00201 d->captions[view] = caption; 00202 00203 view->reparent(d->stack, TQPoint(0,0)); 00204 d->stack->addWidget(view); 00205 00206 int tabId = d->idCounter++; 00207 d->tabBar->appendTab(icon, tabId, caption); 00208 d->idToView[tabId] = view; 00209 connect(d->tabBar->tab(tabId), TQT_SIGNAL(clicked(int)), this, TQT_SLOT(slotTabClicked(int))); 00210 00211 00212 connect(view, TQT_SIGNAL(signalNodeSelected(TreeNode*)), this, TQT_SIGNAL(signalNodeSelected(TreeNode*))); 00213 connect(view, TQT_SIGNAL(signalRootNodeChanged(NodeListView*, TreeNode*)), this, TQT_SLOT(slotRootNodeChanged(NodeListView*, TreeNode*))); 00214 00215 00216 if (tabId == 0) // first widget 00217 { 00218 d->current = view; 00219 d->currentID = tabId; 00220 d->tabBar->setTab(d->currentID, true); 00221 d->stack->raiseWidget(view); 00222 } 00223 } 00224 00225 NodeListView* ListTabWidget::activeView() const 00226 { 00227 return d->current; 00228 } 00229 00230 } 00231 00232 #include "listtabwidget.h" 00233 00234 #include "listtabwidget.moc"