20#include <tqbuttongroup.h>
21#include <tqnamespace.h>
22#include <tqtoolbutton.h>
28#include <tqdockwindow.h>
31#include <tdeparts/event.h>
33#include <tdetoolbar.h>
34#include <kiconloader.h>
35#include <kseparator.h>
37#include <tdeactioncollection.h>
38#include <tdeactionclasses.h>
40#include <KoMainWindow.h>
47KoToolBox::KoToolBox(
TDEMainWindow *mainWin,
const char* name, TDEInstance* instance,
int numberOfTooltypes )
48 :
TDEToolBar( mainWin, TQt::DockLeft, false,
name, true, true), m_instance(instance)
53 m_buttonGroup =
new TQButtonGroup( 0L );
54 m_buttonGroup->setExclusive(
true );
55 connect( m_buttonGroup, TQ_SIGNAL( pressed(
int ) ),
this, TQ_SLOT( slotButtonPressed(
int ) ) );
57 m_tools.setAutoDelete(
true );
59 for (
int i = 0; i < numberOfTooltypes ; ++i) {
60 ToolList * tl =
new ToolList();
65KoToolBox::~KoToolBox()
71void KoToolBox::slotPressButton(
int id )
73 m_buttonGroup->setButton(
id );
74 slotButtonPressed(
id );
77void KoToolBox::slotButtonPressed(
int id )
79 if(
id != m_buttonGroup->selectedId() && m_buttonGroup->selected() ) {
80 m_buttonGroup->selected()->setDown(
false );
82 m_idToActionMap.at(
id)->activate();
86void KoToolBox::registerTool(
TDEAction *tool,
int toolType, TQ_UINT32 priority )
89 ToolList * tl = m_tools.at(toolType);
90 while( (*tl)[prio] ) prio++;
94TQToolButton *KoToolBox::createButton(TQWidget * parent,
const char* iconName, TQString tooltip)
96 TQToolButton *button =
new TQToolButton(parent);
98 if ( iconName && *iconName ) {
99 TQPixmap pixmap = BarIcon( iconName, m_instance );
100 button->setPixmap( pixmap );
101 button->setToggleButton(
true );
104 if ( !tooltip.isEmpty() ) {
105 TQToolTip::add( button, tooltip );
111void KoToolBox::setupTools()
115 for (uint i = 0; i < m_tools.count(); ++i) {
116 ToolList * tl = m_tools.at(i);
119 if (tl->isEmpty())
continue;
121 ToolArea *tools =
new ToolArea(
this );
122 ToolList::Iterator it;
123 for ( it = tl->begin(); it != tl->end(); ++it )
125 TDEAction *tool = it.data();
128 TQToolButton *bn = createButton(tools->getNextParent(), tool->icon().latin1(), tool->
toolTip());
130 m_buttonGroup->insert( bn,
id++ );
131 m_idToActionMap.append( tool );
133 if (i < m_tools.count() -1) addSeparator();
134 m_toolBoxes.append(tools);
137 m_buttonGroup->setButton( 0 );
138 m_numberOfButtons = id;
142void KoToolBox::setOrientation ( TQt::Orientation o )
144 if (
barPos() == Floating ) {
145 o = o == TQt::Vertical ? TQt::Horizontal : TQt::Vertical;
148 TQDockWindow::setOrientation( o );
150 for (uint i = 0; i < m_toolBoxes.count(); ++i) {
151 ToolArea *t = m_toolBoxes.at(i);
152 t->setOrientation(o);
157void KoToolBox::enableTools(
bool enable)
159 if (m_tools.isEmpty())
return;
160 if (!m_buttonGroup)
return;
161 if (m_numberOfButtons <= 0)
return;
163 for (uint i = 0; i < m_tools.count(); ++i) {
164 ToolList * tl = m_tools.at(i);
168 ToolList::Iterator it;
169 for ( it = tl->begin(); it != tl->end(); ++it )
170 if (it != 0 && it.data())
171 it.data()->setEnabled(
enable);
173 m_buttonGroup->setEnabled(
enable);
174 for (TQ_UINT32 i = 0; i < m_numberOfButtons; ++i) {
175 m_buttonGroup->find( i )->setEnabled(
enable );
179void KoToolBox::slotSetTool(
const TQString & toolname)
181 for (uint i = 0; i < m_idToActionMap.count(); ++i) {
182 TDEAction * a = m_idToActionMap.at(i);
183 if (!a || a->name() != toolname)
continue;
185 m_buttonGroup->setButton(i);
196ToolArea::ToolArea(TQWidget *parent)
197 : TQWidget(parent), m_left(true)
199 m_layout =
new TQBoxLayout(
this, TQBoxLayout::LeftToRight, 0, 0, 0);
200 TQWidget *w =
new TQWidget(
this);
201 m_layout->addWidget(w);
203 TQGridLayout *grid =
new TQGridLayout(w, 2, 2);
204 m_leftRow =
new TQWidget(w);
205 grid->addWidget(m_leftRow, 0, 0);
206 m_leftLayout =
new TQBoxLayout(m_leftRow, TQBoxLayout::TopToBottom, 0, 1, 0);
208 w =
new TQWidget(
this);
209 m_layout->addWidget(w);
211 grid =
new TQGridLayout(w, 2, 2);
212 m_rightRow =
new TQWidget(w);
213 grid->addWidget(m_rightRow, 0, 0);
214 m_rightLayout =
new TQBoxLayout(m_rightRow, TQBoxLayout::TopToBottom, 0, 1, 0);
223void ToolArea::add(TQWidget *button)
226 m_leftLayout->addWidget(button);
228 m_rightLayout->addWidget(button);
234TQWidget* ToolArea::getNextParent()
242void ToolArea::setOrientation ( TQt::Orientation o )
244 TQBoxLayout::Direction dir = (o != TQt::Horizontal
245 ? TQBoxLayout::TopToBottom
246 : TQBoxLayout::LeftToRight);
247 m_leftLayout->setDirection(dir);
248 m_rightLayout->setDirection(dir);
250 m_layout->setDirection(o == TQt::Horizontal
251 ? TQBoxLayout::TopToBottom
252 : TQBoxLayout::LeftToRight);
256#include "KoToolBox.moc"
virtual TQString toolTip() const
const char * name(StdAction id)