19 #include "ktoolbarhandler_p.h"
21 #include <QtXml/QDomDocument>
35 #include <kstandardaction_p.h>
39 const char *actionListName =
"show_menu_and_toolbar_actionlist";
41 const char *guiDescription =
""
42 "<!DOCTYPE kpartgui><kpartgui name=\"StandardToolBarMenuHandler\">"
44 " <Menu name=\"settings\">"
45 " <ActionList name=\"%1\" />"
50 class BarActionBuilder
54 QLinkedList<KToolBar*> &oldToolBarList )
55 : m_actionCollection( actionCollection ), m_mainWindow( mainWindow ), m_needsRebuild( false )
59 foreach(
KToolBar * toolBar, toolBars) {
63 if ( !oldToolBarList.contains( toolBar ) )
64 m_needsRebuild =
true;
66 m_toolBars.append( toolBar );
69 if ( !m_needsRebuild )
70 m_needsRebuild = ( oldToolBarList.count() != m_toolBars.count() );
73 bool needsRebuild()
const
75 return m_needsRebuild;
82 if ( !m_needsRebuild )
85 foreach (
KToolBar* bar, m_toolBars )
88 if ( m_toolBarActions.count() == 0 )
91 if ( m_toolBarActions.count() == 1 ) {
94 action->setText(
i18n( pInfo->psLabel ) );
95 return m_toolBarActions;
99 m_actionCollection->addAction(
"toolbars_submenu_action", menuAction);
101 foreach (
QAction* action, m_toolBarActions )
102 menuAction->
menu()->addAction( action );
104 actions.append( menuAction );
109 const QLinkedList<KToolBar*> &toolBars()
const
115 void handleToolBar(
KToolBar *toolBar )
119 toolBar->windowTitle(),
121 m_actionCollection->addAction(toolBar->objectName(), action);
124 m_toolBarActions.append( action );
130 QLinkedList<KToolBar*> m_toolBars;
133 bool m_needsRebuild : 1;
137 using namespace KDEPrivate;
139 class ToolBarHandler::Private
142 Private( ToolBarHandler *_parent )
150 parent->setupActions();
154 void connectToActionContainers();
155 void connectToActionContainer(
QAction *action );
156 void connectToActionContainer(
QWidget *container );
158 ToolBarHandler *parent;
168 QObject::connect( mainWindow->guiFactory(), SIGNAL(clientAdded(
KXMLGUIClient*)),
171 if ( parent->domDocument().documentElement().isNull() ) {
173 QString completeDescription = QString::fromLatin1( guiDescription )
174 .arg( actionListName );
176 parent->setXML( completeDescription,
false );
180 void ToolBarHandler::Private::connectToActionContainers()
182 foreach (
QAction* action, actions )
183 connectToActionContainer( action );
186 void ToolBarHandler::Private::connectToActionContainer(
QAction *action )
188 uint containerCount = action->associatedWidgets().count();
190 for ( uint i = 0; i < containerCount; ++i )
191 connectToActionContainer( action->associatedWidgets().value( i ) );
194 void ToolBarHandler::Private::connectToActionContainer(
QWidget *container )
196 QMenu *popupMenu = qobject_cast<
QMenu *>( container );
200 connect( popupMenu, SIGNAL(aboutToShow()),
201 parent, SLOT(setupActions()) );
206 d( new Private( this ) )
208 d->init( mainWindow );
213 d( new Private( this ) )
215 d->init( mainWindow );
218 ToolBarHandler::~ToolBarHandler()
220 qDeleteAll( d->actions );
226 QAction *ToolBarHandler::toolBarMenuAction()
228 Q_ASSERT( d->actions.count() == 1 );
229 return d->actions.first();
232 void ToolBarHandler::setupActions()
234 if ( !factory() || !d->mainWindow )
237 BarActionBuilder builder( actionCollection(), d->mainWindow, d->toolBars );
239 if ( !builder.needsRebuild() )
242 unplugActionList( actionListName );
244 qDeleteAll( d->actions );
247 d->actions = builder.create();
249 d->toolBars = builder.toolBars();
255 plugActionList( actionListName, d->actions );
257 d->connectToActionContainers();
260 #include "ktoolbarhandler_p.moc"
QString i18n(const char *text)
A container for a set of QAction objects.
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document...
KDE top level main window with predefined action layout
KAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)
Creates an action corresponding to one of the KStandardAction::StandardAction actions, which is connected to the given object and slot, and is owned by parent.
void readSettings(KConfigGroup *config=0)
Read all key associations from config.
bool authorizeKAction(const QString &action)