akregator/src

listtabwidget.cpp
1/*
2 This file is part of Akregator.
3
4 Copyright (C) 2005 Frank Osterfeld <frank.osterfeld at kdemail.net>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24
25#include "listtabwidget.h"
26#include "feedlistview.h"
27#include "folder.h"
28#include "treenode.h"
29
30#include <tdemultitabbar.h>
31
32#include <tqiconset.h>
33#include <tqlayout.h>
34#include <tqmap.h>
35#include <tqptrlist.h>
36#include <tqstring.h>
37#include <tqvaluelist.h>
38#include <tqwidgetstack.h>
39
40#include <kdebug.h>
41
42namespace Akregator {
43
44class ListTabWidget::ListTabWidgetPrivate
45{
46
47public:
48 int idCounter;
49 KMultiTabBar* tabBar;
50 TQWidgetStack* stack;
51 NodeListView* current;
52 int currentID;
53 TQValueList<NodeListView*> views;
54 TQMap<int, NodeListView*> idToView;
55 TQHBoxLayout* layout;
56 ViewMode viewMode;
57 TQMap<TQWidget*, TQString> captions;
58};
59
60
62{
63 if (d->current)
64 d->current->slotItemUp();
65}
66
68{
69 if (d->current)
70 d->current->slotItemDown();
71}
72
74{
75 if (d->current)
76 d->current->slotItemBegin();
77}
78
80{
81 if (d->current)
82 d->current->slotItemEnd();
83}
84
86{
87 if (d->current)
88 d->current->slotItemLeft();
89}
90
92{
93 if (d->current)
94 d->current->slotItemRight();
95}
96
97void ListTabWidget::slotPrevFeed()
98{
99 if (d->current)
100 d->current->slotPrevFeed();
101}
102
103void ListTabWidget::slotNextFeed()
104{
105 if (d->current)
106 d->current->slotNextFeed();
107}
108
109void ListTabWidget::slotPrevUnreadFeed()
110{
111 if (d->current)
112 d->current->slotPrevUnreadFeed();
113}
114
115void ListTabWidget::slotNextUnreadFeed()
116{
117 if (d->current)
118 d->current->slotNextUnreadFeed();
119}
120
121void ListTabWidget::slotRootNodeChanged(NodeListView* view, TreeNode* node)
122{
123/*
124 int unread = node->unread();
125 if (unread > 0)
126 {
127 //uncomment this to append unread count
128 //d->tabWidget->changeTab(view, TQString("<qt>%1 (%2)").arg(d->captions[view]).arg(node->unread()));
129 d->tabWidget->changeTab(view, d->captions[view]);
130 }
131 else
132 {
133 d->tabWidget->changeTab(view, d->captions[view]);
134 }
135*/
136}
137
138void ListTabWidget::slotTabClicked(int id)
139{
140 NodeListView* view = d->idToView[id];
141 if (view)
142 {
143 d->stack->raiseWidget(view);
144 d->current = view;
145
146 if (d->currentID >= 0)
147 d->tabBar->setTab(d->currentID, false);
148 d->currentID = id;
149 d->tabBar->setTab(d->currentID, true);
150
151 emit signalNodeSelected(d->current->selectedNode());
152 }
153}
154
155ListTabWidget::ListTabWidget(TQWidget* parent, const char* name) : TQWidget(parent, name), d(new ListTabWidgetPrivate)
156{
157 d->idCounter = 0;
158 d->current = 0;
159 d->currentID = -1;
160 d->viewMode = verticalTabs;
161 d->layout = new TQHBoxLayout(this);
162 //d->layout = new TQGridLayout(this, 1, 2);
163 d->tabBar = new KMultiTabBar(KMultiTabBar::Vertical, this);
164 d->tabBar->setStyle(KMultiTabBar::KDEV3ICON);
165 //d->tabBar->setStyle(KMultiTabBar::KDEV3);
166 d->tabBar->showActiveTabTexts(true);
167 d->tabBar->setPosition(KMultiTabBar::Left);
168 d->layout->addWidget(d->tabBar/*, 0, 0*/);
169
170 d->stack = new TQWidgetStack(this);
171 d->layout->addWidget(d->stack/*, 0, 1*/);
172
173// connect(d->tabBar, TQ_SIGNAL(currentChanged(TQWidget*)), this, TQ_SLOT(slotCurrentChanged(TQWidget*)));
174}
175
176ListTabWidget::~ListTabWidget()
177{
178 delete d;
179 d = 0;
180}
181
182
183void ListTabWidget::setViewMode(ViewMode mode)
184{
185 if (mode == d->viewMode)
186 return;
187
188 d->viewMode = mode;
189
190 // if mode is "single", we hide the tab bar
191 d->tabBar->setHidden(mode == single);
192}
193
194ListTabWidget::ViewMode ListTabWidget::viewMode() const
195{
196 return d->viewMode;
197}
198
199void ListTabWidget::addView(NodeListView* view, const TQString& caption, const TQPixmap& icon)
200{
201 d->captions[view] = caption;
202
203 view->reparent(d->stack, TQPoint(0,0));
204 d->stack->addWidget(view);
205
206 int tabId = d->idCounter++;
207 d->tabBar->appendTab(icon, tabId, caption);
208 d->idToView[tabId] = view;
209 connect(d->tabBar->tab(tabId), TQ_SIGNAL(clicked(int)), this, TQ_SLOT(slotTabClicked(int)));
210
211
212 connect(view, TQ_SIGNAL(signalNodeSelected(TreeNode*)), this, TQ_SIGNAL(signalNodeSelected(TreeNode*)));
213 connect(view, TQ_SIGNAL(signalRootNodeChanged(NodeListView*, TreeNode*)), this, TQ_SLOT(slotRootNodeChanged(NodeListView*, TreeNode*)));
214
215
216 if (tabId == 0) // first widget
217 {
218 d->current = view;
219 d->currentID = tabId;
220 d->tabBar->setTab(d->currentID, true);
221 d->stack->raiseWidget(view);
222 }
223}
224
225NodeListView* ListTabWidget::activeView() const
226{
227 return d->current;
228}
229
230}
231
232#include "listtabwidget.h"
233
234#include "listtabwidget.moc"
void slotItemUp()
go one item up
void slotItemLeft()
go to parent item
void slotItemDown()
go one item down
void slotItemBegin()
select the first item in the list
void slotItemRight()
go to first child
void slotItemEnd()
select last item in the list