28 #include <tqpushbutton.h>
29 #include <tqpainter.h>
35 : TQWidget(parent, name)
37 tabs =
new TQTabBar(
this,
"_tabbar");
38 connect(tabs, TQ_SIGNAL(selected(
int)),
this, TQ_SLOT(showTab(
int)));
50 void KTabCtl::resizeEvent(TQResizeEvent *)
53 TQRect r = getChildRect();
56 for (i=0; i<(int)pages.size(); i++) {
57 pages[i]->setGeometry(r);
59 if( ( tabs->shape() == TQTabBar::RoundedBelow ) ||
60 ( tabs->shape() == TQTabBar::TriangularBelow ) ) {
61 tabs->move( 0, height()-tabs->height()-4 );
66 void KTabCtl::setFont(
const TQFont & font)
69 f.setWeight(TQFont::Light);
75 void KTabCtl::setTabFont(
const TQFont & font)
93 for(i = 0; i < pages.size(); i++)
96 TQResizeEvent r(size(), size());
102 bool KTabCtl::isTabEnabled(
const TQString& name)
106 for(i = 0; i < pages.size(); i++)
107 if (TQString::fromLatin1(pages[i]->
name()) == name)
108 return tabs->isTabEnabled(i);
112 void KTabCtl::setTabEnabled(
const TQString& name,
bool state)
119 for (i = 0; i < pages.size(); i++)
120 if (TQString::fromLatin1(pages[i]->
name()) == name)
121 tabs->setTabEnabled(i, state);
124 void KTabCtl::setSizes()
128 TQSize min(tabs->sizeHint());
132 TQSize max(TQCOORD_MAX,TQCOORD_MAX);
135 for (i = 0; i < pages.size(); i++) {
141 if (pages[i]->maximumSize().height() < max.height())
142 max.setHeight(pages[i]->maximumSize().height());
143 if (pages[i]->maximumSize().width() < max.width())
144 max.setWidth( pages[i]->maximumSize().width());
145 if ( pages[i]->minimumSize().height() > min.height())
146 min.setHeight( pages[i]->minimumSize().height());
147 if ( pages[i]->minimumSize().width() > min.width())
148 min.setWidth( pages[i]->minimumSize().width());
154 if (max.width() < min.width())
155 max.setWidth(min.width());
156 if (max.height() < min.height())
157 max.setHeight(min.height());
163 for( i=0; i<(uint)pages.size(); i++ ) {
164 pages[i]->setMinimumSize(min);
165 pages[i]->setMaximumSize(max);
170 setMinimumSize(min.width()+4, min.height()+tabs->height()+4);
177 TQResizeEvent r(size(), size());
182 void KTabCtl::setBorder(
bool state )
187 void KTabCtl::setShape( TQTabBar::Shape shape )
189 tabs->setShape( shape );
193 KTabCtl::sizeHint()
const
196 TQSize hint(tabs->sizeHint());
200 for (
unsigned int i = 0; i < pages.size(); i++)
202 TQSize sizeI(pages[i]->sizeHint());
207 if (sizeI.width() > pageHint.width())
208 pageHint.setWidth(sizeI.width());
210 if (sizeI.height() > pageHint.height())
211 pageHint.setHeight(sizeI.height());
215 if (pageHint.isValid())
218 if (pageHint.width() > hint.width())
219 hint.setWidth(pageHint.width());
222 hint.setHeight(hint.height() + pageHint.height());
228 return (hint + TQSize(4,4));
238 void KTabCtl::paintEvent(TQPaintEvent *)
249 int y0 = getChildRect().top() - 1;
250 int y1 = getChildRect().bottom() + 2;
251 int x1 = getChildRect().right() + 2;
252 int x0 = getChildRect().left() - 1;
254 p.setPen(colorGroup().light());
255 p.drawLine(x0, y0 - 1, x1 - 1, y0 - 1);
256 p.setPen(colorGroup().midlight());
257 p.drawLine(x0, y0, x1 - 1, y0);
258 p.setPen(colorGroup().light());
259 p.drawLine(x0, y0 + 1, x0, y1);
261 p.drawLine(x1, y1, x0, y1);
262 p.drawLine(x1, y1 - 1, x1, y0);
263 p.setPen(colorGroup().dark());
264 p.drawLine(x0 + 1, y1 - 1, x1 - 1, y1 - 1);
265 p.drawLine(x1 - 1, y1 - 2, x1 - 1, y0 + 1);
274 TQRect KTabCtl::getChildRect()
const
276 if( ( tabs->shape() == TQTabBar::RoundedBelow ) ||
277 ( tabs->shape() == TQTabBar::TriangularBelow ) ) {
278 return TQRect(2, 1, width() - 4,
279 height() - tabs->height() - 4);
281 return TQRect(2, tabs->height() + 1, width() - 4,
282 height() - tabs->height() - 4);
291 void KTabCtl::showTab(
int i)
294 for (j = 0; j < pages.size(); j++) {
295 if (j != (
unsigned)i) {
300 if((
unsigned)i < pages.size()) {
301 emit(tabSelected(i));
302 if( pages.size() >= 2 ) {
305 tabs->setCurrentTab(i);
306 pages[i]->setGeometry(getChildRect());
319 void KTabCtl::addTab(TQWidget *w,
const TQString& name)
321 TQTab *t =
new TQTab();
323 t->setEnabled(
true );
324 int id = tabs->addTab(t);
325 if (
id == (
int)pages.size()) {
326 pages.resize(
id + 1);
333 void KTabCtl::virtual_hook(
int,
void* )
336 #include "ktabctl.moc"
KTabCtl(TQWidget *parent=0, const char *name=0)
KTabCtl provides a universal tab control.
TQString name(StdAccel id)