1 /***************************************************************************
2 * Copyright (C) 2004-2006 by Albert Astals Cid <tsdgeos@terra.es> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 ***************************************************************************/
10 #include "toolaction.h"
14 #include <qtoolbutton.h>
18 ToolAction::ToolAction( QObject
*parent
)
21 setText( i18n( "Selection Tools" ) );
24 ToolAction::~ToolAction()
28 void ToolAction::addAction( QAction
*action
)
30 bool setDefault
= !m_buttons
.isEmpty() ? m_buttons
.first()->menu()->actions().isEmpty() : false;
31 foreach ( QToolButton
*button
, m_buttons
)
34 button
->menu()->addAction( action
);
36 button
->setDefaultAction( action
);
38 m_actions
.append( action
);
41 QWidget
* ToolAction::createWidget( QWidget
*parent
)
43 QToolBar
*toolBar
= qobject_cast
< QToolBar
* >( parent
);
47 QToolButton
*button
= new QToolButton( toolBar
);
48 button
->setAutoRaise( true );
49 button
->setFocusPolicy( Qt::NoFocus
);
50 button
->setIconSize( toolBar
->iconSize() );
51 button
->setToolButtonStyle( toolBar
->toolButtonStyle() );
52 button
->setPopupMode( QToolButton::DelayedPopup
);
53 button
->setMenu( new QMenu( button
) );
54 button
->setCheckable( true );
55 connect( toolBar
, SIGNAL( iconSizeChanged( const QSize
& ) ),
56 button
, SLOT( setIconSize( const QSize
& ) ) );
57 connect( toolBar
, SIGNAL( toolButtonStyleChanged( Qt::ToolButtonStyle
) ),
58 button
, SLOT( setToolButtonStyle( Qt::ToolButtonStyle
) ) );
59 connect( button
, SIGNAL( triggered( QAction
* ) ), toolBar
, SIGNAL( actionTriggered( QAction
* ) ) );
60 connect( button
->menu(), SIGNAL( triggered( QAction
* ) ), this, SLOT( slotNewDefaultAction( QAction
* ) ) );
62 m_buttons
.append( button
);
64 if ( !m_actions
.isEmpty() )
66 foreach ( QAction
*action
, m_actions
)
68 button
->menu()->addAction( action
);
70 button
->setDefaultAction( button
->menu()->actions().first() );
71 button
->setToolTip( i18n("Click to use the current selection tool\nClick and hold to choose another selection tool") );
77 void ToolAction::slotNewDefaultAction( QAction
*action
)
79 foreach ( QToolButton
*button
, m_buttons
)
82 button
->setDefaultAction( action
);
83 button
->setToolTip( i18n("Click to use the current selection tool\nClick and hold to choose another selection tool") );
87 #include "toolaction.moc"