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
|
/*
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.
*/
/*
Copyright (C) 2005 Francois Chazal <neptune3k@free.fr>
Copyright (C) 2006-2007 Eike Hein <hein@kde.org>
*/
#include "tab_bar.h"
#include "tab_bar.moc"
#include "settings.h"
#include <tqtooltip.h>
#include <tqwhatsthis.h>
#include <klocale.h>
#include <kpopupmenu.h>
TabBar::TabBar(TQWidget* tqparent, const char* name, bool translucency, const TQString & skin)
: TranslucentWidget(tqparent, name, translucency)
{
loadSkin(skin);
connect(plus_button, TQT_SIGNAL(clicked()), this, TQT_SIGNAL(addItem()));
connect(minus_button, TQT_SIGNAL(clicked()), this, TQT_SIGNAL(removeItem()));
connect(tabs_widget, TQT_SIGNAL(itemSelected(int)), this, TQT_SIGNAL(itemSelected(int)));
connect(tabs_widget, TQT_SIGNAL(addItem()), this, TQT_SIGNAL(addItem()));
connect(this, TQT_SIGNAL(updateBackground()), this, TQT_SLOT(slotUpdateBackground()));
}
TabBar::~TabBar()
{
delete tabs_widget;
delete plus_button;
delete minus_button;
}
int TabBar::pressedPosition()
{
return tabs_widget->pressedPosition();
}
void TabBar::resetPressedPosition()
{
tabs_widget->resetPressedPosition();
}
void TabBar::addItem(int session_id)
{
tabs_widget->addItem(session_id);
tabs_widget->selectItem(session_id);
}
int TabBar::removeItem(int session_id)
{
return tabs_widget->removeItem(session_id);
}
const TQString TabBar::itemName(int session_id)
{
return tabs_widget->itemName(session_id);
}
void TabBar::renameItem(int session_id, const TQString& name)
{
tabs_widget->renameItem(session_id, name);
}
void TabBar::interactiveRename()
{
tabs_widget->interactiveRename();
}
int TabBar::tabPositionForSessionId(int session_id)
{
return tabs_widget->tabPositionForSessionId(session_id);
}
int TabBar::sessionIdForTabPosition(int position)
{
return tabs_widget->sessionIdForTabPosition(position);
}
void TabBar::selectItem(int session_id)
{
tabs_widget->selectItem(session_id);
}
void TabBar::selectPosition(int position)
{
tabs_widget->selectPosition(position);
}
void TabBar::slotSelectNextItem()
{
tabs_widget->selectNextItem();
}
void TabBar::slotSelectPreviousItem()
{
tabs_widget->selectPreviousItem();
}
void TabBar::slotMoveItemLeft()
{
tabs_widget->moveItemLeft();
}
void TabBar::slotMoveItemRight()
{
tabs_widget->moveItemRight();
}
void TabBar::paintEvent(TQPaintEvent*)
{
TQPainter painter(this);
erase();
if (!useTranslucency())
painter.fillRect(0, 0, width(), height(), Settings::skinbgcolor());
painter.drawPixmap(0, 0, left_corner);
painter.drawPixmap(width() - right_corner.width(), 0, right_corner);
painter.drawTiledPixmap(left_corner.width(), 0, width() -
left_corner.width() -right_corner.width(), height(), back_image);
painter.end();
}
void TabBar::resizeEvent(TQResizeEvent*)
{
plus_button->move(plus_position.x(), plus_position.y());
minus_button->move(width() - minus_position.x(), minus_position.y());
tabs_widget->move(tabs_position.x(), tabs_position.y());
tabs_widget->resize(width() - 2 * tabs_position.x(), tabs_widget->height());
tabs_widget->refreshBuffer();
}
void TabBar::loadSkin(const TQString& skin)
{
tabs_widget = new TabbedWidget(this, "Tabbed widget", useTranslucency());
TQWhatsThis::add(tabs_widget, i18n("The tab bar allows you to switch between sessions."));
connect(this, TQT_SIGNAL(updateBackground()), tabs_widget, TQT_SLOT(slotUpdateBackground()));
plus_button = new ImageButton(this, "Plus button", useTranslucency());
plus_button->setDelayedPopup(true);
TQToolTip::add(plus_button, i18n("New Session"));
TQWhatsThis::add(plus_button, i18n("Adds a new session. Press and hold to select session type from menu."));
connect(this, TQT_SIGNAL(updateBackground()), plus_button, TQT_SLOT(slotUpdateBackground()));
minus_button = new ImageButton(this, "Minus button", useTranslucency());
TQToolTip::add(minus_button, i18n("Close Session"));
TQWhatsThis::add(minus_button, i18n("Closes the active session."));
connect(this, TQT_SIGNAL(updateBackground()), minus_button, TQT_SLOT(slotUpdateBackground()));
setPixmaps(skin);
resize(width(), back_image.height());
}
void TabBar::reloadSkin(const TQString& skin)
{
setPixmaps(skin);
resize(width(), back_image.height());
plus_button->move(plus_position.x(), plus_position.y());
minus_button->move(width() - minus_position.x(), minus_position.y());
tabs_widget->move(tabs_position.x(), tabs_position.y());
tabs_widget->resize(width() - 2 * tabs_position.x(), tabs_widget->height());
minus_button->tqrepaint();
plus_button->tqrepaint();
tabs_widget->refreshBuffer();
tqrepaint();
}
void TabBar::setPixmaps(const TQString& skin)
{
TQUrl url(locate("appdata", skin + "/tabs.skin"));
KConfig config(url.path());
config.setGroup("Tabs");
tabs_position.setX(config.readNumEntry("x", 20));
tabs_position.setY(config.readNumEntry("y", 0));
tabs_widget->setFontColor(TQColor(config.readNumEntry("red", 255),
config.readNumEntry("green", 255),
config.readNumEntry("blue", 255)));
tabs_widget->setSeparatorPixmap(url.dirPath() + config.readEntry("separator_image", ""));
tabs_widget->setSelectedPixmap(url.dirPath() + config.readEntry("selected_background", ""));
tabs_widget->setSelectedLeftPixmap(url.dirPath() + config.readEntry("selected_left_corner", ""));
tabs_widget->setSelectedRightPixmap(url.dirPath() + config.readEntry("selected_right_corner", ""));
tabs_widget->setUnselectedPixmap(url.dirPath() + config.readEntry("unselected_background", ""));
// Load the background pixmaps.
config.setGroup("Background");
tabs_widget->setBackgroundPixmap(url.dirPath() + config.readEntry("back_image", ""));
back_image.load(url.dirPath() + config.readEntry("back_image", ""));
left_corner.load(url.dirPath() + config.readEntry("left_corner", ""));
right_corner.load(url.dirPath() + config.readEntry("right_corner", ""));
// Load the plus button.
config.setGroup("PlusButton");
plus_position.setX(config.readNumEntry("x", 2));
plus_position.setY(config.readNumEntry("y", 2));
plus_button->setUpPixmap(url.dirPath() + config.readEntry("up_image", ""));
plus_button->setOverPixmap(url.dirPath() + config.readEntry("over_image", ""));
plus_button->setDownPixmap(url.dirPath() + config.readEntry("down_image", ""));
// Load the minus button.
config.setGroup("MinusButton");
minus_position.setX(config.readNumEntry("x", 18));
minus_position.setY(config.readNumEntry("y", 2));
minus_button->setUpPixmap(url.dirPath() + config.readEntry("up_image", ""));
minus_button->setOverPixmap(url.dirPath() + config.readEntry("over_image", ""));
minus_button->setDownPixmap(url.dirPath() + config.readEntry("down_image", ""));
}
void TabBar::setSessionMenu(KPopupMenu* menu)
{
plus_button->setPopupMenu(menu);
}
|