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
|
/***************************************************************************
tabwidget.cpp - Widget with tabs
-------------------
copyright : (C) 2002 by Marc Britton
email : consume@optusnet.com.au
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
/* KDE INCLUDES */
#include <klocale.h>
#include <kiconloader.h>
/* QT INCLUDES */
#include <tqstring.h>
#include <tqwidget.h>
#include <tqstringlist.h>
#include <tqevent.h>
#include <tqtabwidget.h>
#include <tqtabbar.h>
/* OTHER INCLUDES */
#include <kommanderwidget.h>
#include "kommanderplugin.h"
#include <specials.h>
#include "tabwidget.h"
enum Functions {
FirstFunction = 357,
TAB_setTabIcon,
TAB_tabLabel,
TAB_isTabEnabled,
TAB_setTabEnabled,
TAB_showTabBar,
TAB_setCurrentPage,
TAB_setTabLabel,
LastFunction
};
TabWidget::TabWidget(TQWidget *a_parent, const char *a_name, int a_flags)
: TQTabWidget(a_parent, a_name, a_flags), KommanderWidget(TQT_TQOBJECT(this))
{
TQStringList states;
states << "default";
setStates(states);
setDisplayStates(states);
KommanderPlugin::setDefaultGroup(Group::DCOP);
KommanderPlugin::registerFunction(TAB_setTabIcon, "setTabIcon(TQString widget, int Tab, TQString Icon)", i18n("Sets an icon on the specified tab. Index is zero based."), 3);
KommanderPlugin::registerFunction(TAB_tabLabel, "tabLabel(TQString widget, int Tab)", i18n("Returns the tab label at the given index. Index is zero based."), 2);
KommanderPlugin::registerFunction(TAB_isTabEnabled, "isTabEnabled(TQString widget, int Tab)", i18n("Returns true if tab at specified index is enabled, otherwise returns false."), 2);
KommanderPlugin::registerFunction(TAB_setTabEnabled, "setTabEnabled(TQString widget, int Tab, bool Enabled)", i18n("Sets the tab at the given index to enabled or disabled."), 3);
KommanderPlugin::registerFunction(TAB_showTabBar, "showTabBar(TQString widget, bool Show)", i18n("Show or hide the tabs on the tab widget."), 2);
KommanderPlugin::registerFunction(TAB_setCurrentPage, "setCurrentPage(TQString widget, TQString Page)", i18n("Set the current page by name."), 2);
KommanderPlugin::registerFunction(TAB_setTabLabel, "setTabLabel(TQString widget, int Tab, TQString Text)", i18n("Sets the tab tab label."), 3);
}
TabWidget::~TabWidget()
{
}
TQString TabWidget::currentState() const
{
return TQString("default");
}
bool TabWidget::isKommanderWidget() const
{
return true;
}
TQStringList TabWidget::associatedText() const
{
return KommanderWidget::associatedText();
}
void TabWidget::setAssociatedText(const TQStringList& a_at)
{
KommanderWidget::setAssociatedText(a_at);
}
void TabWidget::setPopulationText(const TQString& a_text)
{
KommanderWidget::setPopulationText( a_text );
}
TQString TabWidget::populationText() const
{
return KommanderWidget::populationText();
}
void TabWidget::populate()
{
}
void TabWidget::showEvent(TQShowEvent* e)
{
TQTabWidget::showEvent(e);
emit widgetOpened();
}
void TabWidget::contextMenuEvent( TQContextMenuEvent * e )
{
e->accept();
TQPoint p = e->globalPos();
emit contextMenuRequested(p.x(), p.y());
}
bool TabWidget::isFunctionSupported(int f)
{
return f == DCOP::currentItem || f == DCOP::setCurrentItem || f == DCOP::insertTab || (f >= FirstFunction && f <= LastFunction) ;
}
TQString TabWidget::handleDCOP(int function, const TQStringList& args)
{
switch (function) {
case DCOP::currentItem:
return TQString::number(currentPageIndex());
case DCOP::setCurrentItem:
setCurrentPage(args[0].toUInt());
break;
case DCOP::insertTab:
insertTab(0L, args[0], args[1].toUInt());
break;
case TAB_tabLabel:
{
TQString s = this->label(args[0].toInt());
return s.remove("&");
break;
}
case TAB_setTabIcon:
{
TQWidget *w = page(args[0].toInt());
setTabIconSet(w, TDEGlobal::iconLoader()->loadIcon(args[1], KIcon::NoGroup, KIcon::SizeMedium));
break;
}
case TAB_isTabEnabled:
{
TQWidget *w = page(args[0].toInt());
return TQString::number(this->isTabEnabled(w));
break;
}
case TAB_setTabLabel:
{
TQWidget *w = page(args[0].toInt());
setTabLabel(w, args[1]);
break;
}
case TAB_setTabEnabled:
{
TQWidget *w = page(args[0].toInt());
this->setTabEnabled(w, args[1].toInt());
break;
}
case TAB_setCurrentPage:
{
int cnt = this->count();
int i = 0;
bool found = false;
while (i < cnt) {
TQString s = this->label(i);
if (s.remove("&") == args[0])
{
setCurrentPage(i);
found = true;
break;
}
i++;
}
return TQString::number(found);
break;
}
case TAB_showTabBar:
{
TQTabBar *t = this->tabBar();
if (args[0].toInt() == 1)
t->show();
else
t->hide();
break;
}
default:
return KommanderWidget::handleDCOP(function, args);
}
return TQString();
}
#include "tabwidget.moc"
|