summaryrefslogtreecommitdiffstats
path: root/akregator/src/listtabwidget.cpp
blob: 5434a4a6ee507dee3ad59a3c48c2ee3f4adf16c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
    This file is part of Akregator.

    Copyright (C) 2005 Frank Osterfeld <frank.osterfeld at kdemail.net>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

    As a special exception, permission is given to link this program
    with any edition of Qt, and distribute the resulting executable,
    without including the source code for Qt in the source distribution.
*/

#include "listtabwidget.h"
#include "feedlistview.h"
#include "folder.h"
#include "treenode.h"

#include <kmultitabbar.h>

#include <tqiconset.h>
#include <tqlayout.h>
#include <tqmap.h>
#include <tqptrlist.h>
#include <tqstring.h>
#include <tqvaluelist.h>
#include <tqwidgetstack.h>

#include <kdebug.h>

namespace Akregator {

class ListTabWidget::ListTabWidgetPrivate
{

public:
    int idCounter;
    KMultiTabBar* tabBar;
    TQWidgetStack* stack;
    NodeListView* current;
    int currentID;
    TQValueList<NodeListView*> views;
    TQMap<int, NodeListView*> idToView;
    TQHBoxLayout* layout;
    ViewMode viewMode;
    TQMap<TQWidget*, TQString> captions;
};


void ListTabWidget::slotItemUp()
{
    if (d->current)
        d->current->slotItemUp();
}

void ListTabWidget::slotItemDown()
{
    if (d->current)
        d->current->slotItemDown();
}

void ListTabWidget::slotItemBegin()
{
    if (d->current)
        d->current->slotItemBegin();
}

void ListTabWidget::slotItemEnd()
{
    if (d->current)
        d->current->slotItemEnd();
}

void ListTabWidget::slotItemLeft()
{
    if (d->current)
        d->current->slotItemLeft();
}

void ListTabWidget::slotItemRight()
{
    if (d->current)
        d->current->slotItemRight();
}

void ListTabWidget::slotPrevFeed()
{
    if (d->current)
        d->current->slotPrevFeed();
}

void ListTabWidget::slotNextFeed()
{
    if (d->current)
        d->current->slotNextFeed();
}

void ListTabWidget::slotPrevUnreadFeed()
{
    if (d->current)
        d->current->slotPrevUnreadFeed();
}

void ListTabWidget::slotNextUnreadFeed()
{
    if (d->current)
        d->current->slotNextUnreadFeed();
}

void ListTabWidget::slotRootNodeChanged(NodeListView* view, TreeNode* node)
{
/*
    int unread = node->unread();
    if (unread > 0)
    {
        //uncomment this to append unread count
        //d->tabWidget->changeTab(view,  TQString("<qt>%1 (%2)").arg(d->captions[view]).arg(node->unread()));
        d->tabWidget->changeTab(view, d->captions[view]);
    }
    else
    {
        d->tabWidget->changeTab(view, d->captions[view]);
    }
*/
}

void ListTabWidget::slotTabClicked(int id)
{
    NodeListView* view = d->idToView[id];
    if (view)
    {
        d->stack->raiseWidget(view);
        d->current = view;

        if (d->currentID >= 0)
            d->tabBar->setTab(d->currentID, false);
        d->currentID = id;
        d->tabBar->setTab(d->currentID, true);

        emit signalNodeSelected(d->current->selectedNode());
    }
}

ListTabWidget::ListTabWidget(TQWidget* parent, const char* name) : TQWidget(parent, name), d(new ListTabWidgetPrivate)
{
    d->idCounter = 0;
    d->current = 0;
    d->currentID = -1;
    d->viewMode = verticalTabs;
    d->layout = new TQHBoxLayout(this);
    //d->layout = new TQGridLayout(this, 1, 2);
    d->tabBar = new KMultiTabBar(KMultiTabBar::Vertical, this); 
    d->tabBar->setStyle(KMultiTabBar::KDEV3ICON);
    //d->tabBar->setStyle(KMultiTabBar::KDEV3);
    d->tabBar->showActiveTabTexts(true);
    d->tabBar->setPosition(KMultiTabBar::Left);
    d->layout->addWidget(d->tabBar/*, 0, 0*/);

    d->stack = new TQWidgetStack(this);
    d->layout->addWidget(d->stack/*, 0, 1*/);
    
//    connect(d->tabBar, TQT_SIGNAL(currentChanged(TQWidget*)), this, TQT_SLOT(slotCurrentChanged(TQWidget*)));
}

ListTabWidget::~ListTabWidget()
{
    delete d;
    d = 0;
}


void ListTabWidget::setViewMode(ViewMode mode)
{
    if (mode == d->viewMode)
        return;

    d->viewMode = mode;

    // if mode is "single", we hide the tab bar
    d->tabBar->setHidden(mode == single);
}

ListTabWidget::ViewMode ListTabWidget::viewMode() const
{
    return d->viewMode;
}

void ListTabWidget::addView(NodeListView* view, const TQString& caption, const TQPixmap& icon)
{
    d->captions[view] = caption;    

    view->reparent(d->stack, TQPoint(0,0));
    d->stack->addWidget(view);
   
    int tabId = d->idCounter++;
    d->tabBar->appendTab(icon, tabId, caption);
    d->idToView[tabId] = view;
    connect(d->tabBar->tab(tabId), TQT_SIGNAL(clicked(int)), this, TQT_SLOT(slotTabClicked(int)));

    
    connect(view, TQT_SIGNAL(signalNodeSelected(TreeNode*)), this, TQT_SIGNAL(signalNodeSelected(TreeNode*)));
    connect(view, TQT_SIGNAL(signalRootNodeChanged(NodeListView*, TreeNode*)), this, TQT_SLOT(slotRootNodeChanged(NodeListView*, TreeNode*)));


    if (tabId == 0) // first widget
    {
        d->current = view;
        d->currentID = tabId;
        d->tabBar->setTab(d->currentID, true);
        d->stack->raiseWidget(view);
    }
}

NodeListView* ListTabWidget::activeView() const
{
    return d->current;
}

}

#include "listtabwidget.h"

#include "listtabwidget.moc"