KDevelop API Documentation

lib/widgets/ktabzoombar.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2001-2003 * 00003 * The KDevelop Team * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 00012 #include <qintdict.h> 00013 #include <qpainter.h> 00014 #include <qlayout.h> 00015 #include <qframe.h> 00016 #include <qsignalmapper.h> 00017 #include <qtooltip.h> 00018 00019 00020 #include <kdebug.h> 00021 00022 00023 #include "ktabzoombutton.h" 00024 #include "ktabzoombarlayout.h" 00025 #include "ktabzoombar.h" 00026 00027 00028 class KTabZoomBarPrivate 00029 { 00030 public: 00031 00032 KTabZoomPosition::Position m_tabPosition; 00033 int m_selected; 00034 KTabZoomBarLayout *m_layout; 00035 QSignalMapper *m_clickedMapper; 00036 QIntDict<KTabZoomButton> m_buttons; 00037 int m_count; 00038 bool m_docked; 00039 00040 }; 00041 00042 00043 KTabZoomBar::KTabZoomBar(QWidget *parent, KTabZoomPosition::Position pos, const char *name) 00044 : QWidget(parent, name) 00045 { 00046 d = new KTabZoomBarPrivate; 00047 00048 d->m_tabPosition = pos; 00049 d->m_docked = false; 00050 d->m_count = 0; 00051 00052 d->m_layout = new KTabZoomBarLayout(this, pos); 00053 00054 if (pos == KTabZoomPosition::Left || pos == KTabZoomPosition::Right) 00055 setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred)); 00056 else 00057 setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum)); 00058 00059 d->m_selected = -1; 00060 00061 d->m_clickedMapper = new QSignalMapper(this); 00062 connect(d->m_clickedMapper, SIGNAL(mapped(int)), this, SLOT(clicked(int))); 00063 } 00064 00065 00066 KTabZoomBar::~KTabZoomBar() 00067 { 00068 delete d; 00069 } 00070 00071 00072 int KTabZoomBar::addTab(const QTab &tab, const QString& toolTip) 00073 { 00074 KTabZoomButton *btn = new KTabZoomButton(tab.text(), this, d->m_tabPosition); 00075 QToolTip::add( btn, toolTip ); 00076 d->m_layout->add(btn); 00077 btn->show(); 00078 00079 int index = d->m_count++; 00080 00081 d->m_buttons.insert(index, btn); 00082 00083 d->m_clickedMapper->setMapping(btn, index); 00084 connect(btn, SIGNAL(clicked()), d->m_clickedMapper, SLOT(map())); 00085 00086 return index; 00087 } 00088 00089 00090 void KTabZoomBar::removeTab(int index) 00091 { 00092 KTabZoomButton *button = d->m_buttons[index]; 00093 if (!button) 00094 return; 00095 00096 delete button; 00097 d->m_buttons.remove(index); 00098 } 00099 00100 00101 void KTabZoomBar::clicked(int index) 00102 { 00103 KTabZoomButton *button = d->m_buttons[index]; 00104 if (!button) 00105 return; 00106 00107 if (button->isOn()) 00108 { 00109 setActiveIndex(index); 00110 } 00111 else 00112 { 00113 emit unselected(); 00114 } 00115 } 00116 00117 00118 void KTabZoomBar::setActiveIndex(int index) 00119 { 00120 KTabZoomButton *button = d->m_buttons[index]; 00121 if (!button) 00122 return; 00123 QIntDictIterator<KTabZoomButton> it(d->m_buttons); 00124 while (it.current()) 00125 { 00126 if (it.currentKey() != index) 00127 it.current()->setOn(false); 00128 ++it; 00129 } 00130 button->setOn(true); 00131 emit selected(index); 00132 } 00133 00134 00135 void KTabZoomBar::unsetButtons() 00136 { 00137 QIntDictIterator<KTabZoomButton> it(d->m_buttons); 00138 while (it.current()) 00139 { 00140 if (it.current()->isOn()) { 00141 it.current()->setOn(false); 00142 emit unselected(); 00143 return; 00144 } 00145 ++it; 00146 } 00147 } 00148 00149 00150 void KTabZoomBar::setDockMode(bool docked) 00151 { 00152 d->m_docked = docked; 00153 } 00154 00155 00156 #include "ktabzoombar.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Oct 19 08:01:49 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003