2007-09-14 10:02:33 +00:00
|
|
|
/***************************************************************************
|
2013-03-14 22:09:07 +00:00
|
|
|
* Copyright (C) 2004-2006 by Albert Astals Cid <aacid@kde.org> *
|
2007-09-14 10:02:33 +00:00
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "toolaction.h"
|
|
|
|
|
|
|
|
#include <qmenu.h>
|
|
|
|
#include <qtoolbar.h>
|
|
|
|
#include <qtoolbutton.h>
|
|
|
|
|
2014-10-12 15:20:07 +00:00
|
|
|
#include <KLocalizedString>
|
2007-09-14 10:02:33 +00:00
|
|
|
|
|
|
|
ToolAction::ToolAction( QObject *parent )
|
2015-01-28 16:44:42 +00:00
|
|
|
: KSelectAction( parent )
|
2007-09-14 10:02:33 +00:00
|
|
|
{
|
|
|
|
setText( i18n( "Selection Tools" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolAction::~ToolAction()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolAction::addAction( QAction *action )
|
|
|
|
{
|
|
|
|
bool setDefault = !m_buttons.isEmpty() ? m_buttons.first()->menu()->actions().isEmpty() : false;
|
|
|
|
foreach ( QToolButton *button, m_buttons )
|
|
|
|
if ( button )
|
|
|
|
{
|
|
|
|
button->menu()->addAction( action );
|
|
|
|
if ( setDefault )
|
|
|
|
button->setDefaultAction( action );
|
|
|
|
}
|
|
|
|
m_actions.append( action );
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget* ToolAction::createWidget( QWidget *parent )
|
|
|
|
{
|
|
|
|
QToolBar *toolBar = qobject_cast< QToolBar * >( parent );
|
|
|
|
if ( !toolBar )
|
2017-09-05 21:27:18 +00:00
|
|
|
return nullptr;
|
2007-09-14 10:02:33 +00:00
|
|
|
|
|
|
|
QToolButton *button = new QToolButton( toolBar );
|
|
|
|
button->setAutoRaise( true );
|
|
|
|
button->setFocusPolicy( Qt::NoFocus );
|
|
|
|
button->setIconSize( toolBar->iconSize() );
|
|
|
|
button->setToolButtonStyle( toolBar->toolButtonStyle() );
|
|
|
|
button->setPopupMode( QToolButton::DelayedPopup );
|
|
|
|
button->setMenu( new QMenu( button ) );
|
|
|
|
button->setCheckable( true );
|
2014-10-01 17:40:48 +00:00
|
|
|
connect(toolBar, &QToolBar::iconSizeChanged, button, &QToolButton::setIconSize);
|
|
|
|
connect(toolBar, &QToolBar::toolButtonStyleChanged, button, &QToolButton::setToolButtonStyle);
|
|
|
|
connect(button, &QToolButton::triggered, toolBar, &QToolBar::actionTriggered);
|
2015-10-29 12:37:11 +00:00
|
|
|
connect( button->menu(), &QMenu::triggered, this, &ToolAction::slotNewDefaultAction );
|
2007-09-14 10:02:33 +00:00
|
|
|
|
|
|
|
m_buttons.append( button );
|
|
|
|
|
|
|
|
if ( !m_actions.isEmpty() )
|
|
|
|
{
|
2012-03-09 17:43:40 +00:00
|
|
|
button->setDefaultAction( m_actions.first() );
|
2007-09-14 10:02:33 +00:00
|
|
|
foreach ( QAction *action, m_actions )
|
|
|
|
{
|
|
|
|
button->menu()->addAction( action );
|
2012-03-09 17:43:40 +00:00
|
|
|
if ( action->isChecked() )
|
|
|
|
button->setDefaultAction( action );
|
2007-09-14 10:02:33 +00:00
|
|
|
}
|
2007-11-28 22:54:22 +00:00
|
|
|
button->setToolTip( i18n("Click to use the current selection tool\nClick and hold to choose another selection tool") );
|
2007-09-14 10:02:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolAction::slotNewDefaultAction( QAction *action )
|
|
|
|
{
|
|
|
|
foreach ( QToolButton *button, m_buttons )
|
|
|
|
if ( button )
|
|
|
|
{
|
|
|
|
button->setDefaultAction( action );
|
|
|
|
button->setToolTip( i18n("Click to use the current selection tool\nClick and hold to choose another selection tool") );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-08 22:00:07 +00:00
|
|
|
#include "moc_toolaction.cpp"
|