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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
/* ============================================================
*
* This file is a part of digiKam project
* http://www.digikam.org
*
* Date : 2005-03-22
* Description : a widget to manage sidebar in gui.
*
* Copyright (C) 2005-2006 by Joern Ahrens <[email protected]>
* Copyright (C) 2006-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* 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, 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.
*
* ============================================================ */
/** @file sidebar.cpp */
// TQt includes.
#include <tqsplitter.h>
#include <tqwidgetstack.h>
#include <tqdatastream.h>
#include <tqtimer.h>
// KDE includes.
#include <tdeapplication.h>
#include <tdeconfig.h>
#include <tdeversion.h>
#include <kiconloader.h>
// Local includes.
#include "ddebug.h"
#include "sidebar.h"
#include "sidebar.moc"
namespace Digikam
{
class SidebarPriv
{
public:
SidebarPriv()
{
minimizedDefault = false;
minimized = false;
isMinimized = false;
tabs = 0;
activeTab = -1;
minSize = 0;
maxSize = 0;
dragSwitchId = -1;
stack = 0;
splitter = 0;
dragSwitchTimer = 0;
}
bool minimizedDefault;
bool minimized;
bool isMinimized; // Backup of minimized status (used with Fullscreen)
int tabs;
int activeTab;
int minSize;
int maxSize;
int dragSwitchId;
TQWidgetStack *stack;
TQSplitter *splitter;
TQSize bigSize;
TQTimer *dragSwitchTimer;
Sidebar::Side side;
};
Sidebar::Sidebar(TQWidget *parent, const char *name, Side side, bool minimizedDefault)
: KMultiTabBar(KMultiTabBar::Vertical, parent, name)
{
d = new SidebarPriv;
d->minimizedDefault = minimizedDefault;
d->side = side;
d->dragSwitchTimer = new TQTimer(this);
connect(d->dragSwitchTimer, TQ_SIGNAL(timeout()),
this, TQ_SLOT(slotDragSwitchTimer()));
}
Sidebar::~Sidebar()
{
saveViewState();
delete d;
}
void Sidebar::updateMinimumWidth()
{
int width = 0;
for (int i = 0; i < d->tabs; i++)
{
TQWidget *w = d->stack->widget(i);
if (w && w->width() > width)
width = w->width();
}
d->stack->setMinimumWidth(width);
}
void Sidebar::setSplitter(TQSplitter *sp)
{
#if KDE_IS_VERSION(3,3,0)
setStyle(KMultiTabBar::VSNET);
#else
setStyle(KMultiTabBar::KDEV3);
#endif
d->splitter = sp;
d->stack = new TQWidgetStack(d->splitter);
if(d->side == Left)
setPosition(KMultiTabBar::Left);
else
setPosition(KMultiTabBar::Right);
}
TQSplitter* Sidebar::splitter() const
{
return d->splitter;
}
void Sidebar::loadViewState()
{
TDEConfig *config = kapp->config();
config->setGroup(TQString("%1").arg(name()));
int tab = config->readNumEntry("ActiveTab", 0);
bool minimized = config->readBoolEntry("Minimized", d->minimizedDefault);
// validate
if(tab >= d->tabs || tab < 0)
tab = 0;
if (minimized)
{
d->activeTab = tab;
//setTab(d->activeTab, true);
d->stack->raiseWidget(d->activeTab);
emit signalChangedTab(d->stack->visibleWidget());
}
else
{
d->activeTab = -1;
}
clicked(tab);
}
void Sidebar::saveViewState()
{
TDEConfig *config = kapp->config();
config->setGroup(TQString("%1").arg(name()));
config->writeEntry("ActiveTab", d->activeTab);
config->writeEntry("Minimized", d->minimized);
config->sync();
}
void Sidebar::backup()
{
d->isMinimized = d->minimized;
if (!d->isMinimized)
shrink();
KMultiTabBar::hide();
}
void Sidebar::restore()
{
if (!d->isMinimized)
expand();
KMultiTabBar::show();
}
void Sidebar::appendTab(TQWidget *w, const TQPixmap &pic, const TQString &title)
{
w->reparent(d->stack, TQPoint(0, 0));
KMultiTabBar::appendTab(pic, d->tabs, title);
d->stack->addWidget(w, d->tabs);
tab(d->tabs)->setAcceptDrops(true);
tab(d->tabs)->installEventFilter(this);
connect(tab(d->tabs), TQ_SIGNAL(clicked(int)),
this, TQ_SLOT(clicked(int)));
d->tabs++;
}
void Sidebar::deleteTab(TQWidget *w)
{
int tab = d->stack->id(w);
if(tab < 0)
return;
if(tab == d->activeTab)
d->activeTab = -1;
d->stack->removeWidget(d->stack->widget(tab));
removeTab(tab);
d->tabs--;
updateMinimumWidth();
//TODO show another widget
}
void Sidebar::clicked(int tab)
{
if(tab >= d->tabs || tab < 0)
return;
if(tab == d->activeTab)
{
d->stack->isHidden() ? expand() : shrink();
}
else
{
if(d->activeTab >= 0)
setTab(d->activeTab, false);
d->activeTab = tab;
setTab(d->activeTab, true);
d->stack->raiseWidget(d->activeTab);
if(d->minimized)
expand();
emit signalChangedTab(d->stack->visibleWidget());
}
}
void Sidebar::setActiveTab(TQWidget *w)
{
int tab = d->stack->id(w);
if(tab < 0)
return;
if(d->activeTab >= 0)
setTab(d->activeTab, false);
d->activeTab = tab;
setTab(d->activeTab, true);
d->stack->raiseWidget(d->activeTab);
if(d->minimized)
expand();
emit signalChangedTab(d->stack->visibleWidget());
}
TQWidget* Sidebar::getActiveTab()
{
return d->stack->visibleWidget();
}
void Sidebar::shrink()
{
d->minimized = true;
d->bigSize = size();
d->minSize = minimumWidth();
d->maxSize = maximumWidth();
d->stack->hide();
KMultiTabBarTab* tab = tabs()->first();
if (tab)
setFixedWidth(tab->width());
else
setFixedWidth(width());
emit signalViewChanged();
}
void Sidebar::expand()
{
d->minimized = false;
d->stack->show();
resize(d->bigSize);
setMinimumWidth(d->minSize);
setMaximumWidth(d->maxSize);
emit signalViewChanged();
}
bool Sidebar::isExpanded()
{
return !d->minimized;
}
bool Sidebar::eventFilter(TQObject *obj, TQEvent *ev)
{
TQPtrList<KMultiTabBarTab>* pTabs = tabs();
for (TQPtrListIterator<KMultiTabBarTab> it(*pTabs); it.current(); ++it)
{
if ( obj == *it )
{
if ( ev->type() == TQEvent::DragEnter)
{
TQDragEnterEvent *e = static_cast<TQDragEnterEvent *>(ev);
enterEvent(e);
e->accept(true);
return false;
}
else if (ev->type() == TQEvent::DragMove)
{
if (!d->dragSwitchTimer->isActive())
{
d->dragSwitchTimer->start(800, true);
d->dragSwitchId = (*it)->id();
}
return false;
}
else if (ev->type() == TQEvent::DragLeave)
{
d->dragSwitchTimer->stop();
TQDragLeaveEvent *e = static_cast<TQDragLeaveEvent *>(ev);
leaveEvent(e);
return false;
}
else if (ev->type() == TQEvent::Drop)
{
d->dragSwitchTimer->stop();
TQDropEvent *e = static_cast<TQDropEvent *>(ev);
leaveEvent(e);
return false;
}
else
{
return false;
}
}
}
// Else, pass the event on to the parent class
return KMultiTabBar::eventFilter(obj, ev);
}
void Sidebar::slotDragSwitchTimer()
{
clicked(d->dragSwitchId);
}
} // namespace Digikam
|