kmdi Library API Documentation

kmdiguiclient.cpp

00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2003 Joseph Wenninger <jowenn@kde.org> 00003 based on ktoolbarhandler.cpp: Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License version 2 as published by the Free Software Foundation. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #include "kmdiguiclient.h" 00021 #include "kmdiguiclient.moc" 00022 00023 #include <qpopupmenu.h> 00024 #include <kapplication.h> 00025 #include <kconfig.h> 00026 #include <ktoolbar.h> 00027 #include <kmainwindow.h> 00028 #include <klocale.h> 00029 #include <kaction.h> 00030 #include <qstring.h> 00031 #include <assert.h> 00032 #include <kdebug.h> 00033 #include <kdockwidget.h> 00034 #include <kdeversion.h> 00035 #include "kmdimainfrm.h" 00036 #include "kmditoolviewaccessor.h" 00037 #include "kmditoolviewaccessor_p.h" 00038 namespace 00039 { 00040 const char *actionListName = "show_kmdi_document_tool_view_actions"; 00041 00042 const char *guiDescription = "" 00043 "<!DOCTYPE kpartgui><kpartgui name=\"KMDIViewActions\">" 00044 "<MenuBar>" 00045 " <Menu name=\"view\">" 00046 " <ActionList name=\"%1\" />" 00047 " </Menu>" 00048 "</MenuBar>" 00049 "</kpartgui>"; 00050 00051 const char *resourceFileName = "kmdiviewactions.rc"; 00052 00053 } 00054 00055 00056 using namespace KMDIPrivate; 00057 00058 00059 00060 ToggleToolViewAction::ToggleToolViewAction( const QString& text, const KShortcut& cut, KDockWidget *dw, KMdiMainFrm *mdiMainFrm, 00061 QObject* parent, const char* name ) 00062 : KToggleAction( text, cut, parent, name ), m_dw( dw ), m_mdiMainFrm( mdiMainFrm ) 00063 { 00064 if ( m_dw ) 00065 { 00066 connect( this, SIGNAL( toggled( bool ) ), this, SLOT( slotToggled( bool ) ) ); 00067 connect( m_dw->dockManager(), SIGNAL( change() ), this, SLOT( anDWChanged() ) ); 00068 connect( m_dw, SIGNAL( destroyed() ), this, SLOT( slotWidgetDestroyed() ) ); 00069 setChecked( m_dw->mayBeHide() ); 00070 } 00071 } 00072 00073 00074 ToggleToolViewAction::~ToggleToolViewAction() 00075 { 00076 unplugAll(); 00077 } 00078 00079 void ToggleToolViewAction::anDWChanged() 00080 { 00081 if ( isChecked() && m_dw->mayBeShow() ) 00082 setChecked( false ); 00083 else if ( ( !isChecked() ) && m_dw->mayBeHide() ) 00084 setChecked( true ); 00085 else if ( isChecked() && ( m_dw->parentDockTabGroup() && 00086 ( ( static_cast<KDockWidget*>( m_dw->parentDockTabGroup() -> 00087 parent() ->qt_cast( "KDockWidget" ) ) ) ->mayBeShow() ) ) ) 00088 setChecked( false ); 00089 } 00090 00091 00092 void ToggleToolViewAction::slotToggled( bool t ) 00093 { 00094 // m_mw->mainDock->setDockSite( KDockWidget::DockCorner ); 00095 00096 if ( ( !t ) && m_dw->mayBeHide() ) 00097 m_dw->undock(); 00098 else 00099 if ( t && m_dw->mayBeShow() ) 00100 m_mdiMainFrm->makeDockVisible( m_dw ); 00101 00102 // m_mw->mainDock->setDockSite( KDockWidget::DockNone ); 00103 } 00104 00105 void ToggleToolViewAction::slotWidgetDestroyed() 00106 { 00107 disconnect( m_dw->dockManager(), SIGNAL( change() ), this, SLOT( anDWChanged() ) ); 00108 disconnect( this, SIGNAL( toggled( bool ) ), 0, 0 ); 00109 unplugAll(); 00110 deleteLater(); 00111 } 00112 00113 00114 KMDIGUIClient::KMDIGUIClient( KMdiMainFrm* mdiMainFrm, bool showMDIModeAction, const char* name ) : QObject( mdiMainFrm, name ), 00115 KXMLGUIClient( mdiMainFrm ) 00116 { 00117 m_mdiMode = KMdi::ChildframeMode; 00118 m_mdiMainFrm = mdiMainFrm; 00119 connect( mdiMainFrm->guiFactory(), SIGNAL( clientAdded( KXMLGUIClient * ) ), 00120 this, SLOT( clientAdded( KXMLGUIClient * ) ) ); 00121 00122 /* re-use an existing resource file if it exists. can happen if the user launches the 00123 * toolbar editor */ 00124 /* 00125 setXMLFile( resourceFileName ); 00126 */ 00127 00128 if ( domDocument().documentElement().isNull() ) 00129 { 00130 00131 QString completeDescription = QString::fromLatin1( guiDescription ) 00132 .arg( actionListName ); 00133 00134 setXML( completeDescription, false /*merge*/ ); 00135 } 00136 00137 if ( actionCollection() ->kaccel() == 0 ) 00138 actionCollection() ->setWidget( mdiMainFrm ); 00139 m_toolMenu = new KActionMenu( i18n( "Tool &Views" ), actionCollection(), "kmdi_toolview_menu" ); 00140 if ( showMDIModeAction ) 00141 { 00142 m_mdiModeAction = new KSelectAction( i18n( "MDI Mode" ), 0, actionCollection() ); 00143 QStringList modes; 00144 modes << i18n( "&Toplevel Mode" ) << i18n( "C&hildframe Mode" ) << i18n( "Ta&b Page Mode" ) << i18n( "I&DEAl Mode" ); 00145 m_mdiModeAction->setItems( modes ); 00146 connect( m_mdiModeAction, SIGNAL( activated( int ) ), this, SLOT( changeViewMode( int ) ) ); 00147 } 00148 else 00149 m_mdiModeAction = 0; 00150 00151 connect( m_mdiMainFrm, SIGNAL( mdiModeHasBeenChangedTo( KMdi::MdiMode ) ), 00152 this, SLOT( mdiModeHasBeenChangedTo( KMdi::MdiMode ) ) ); 00153 00154 m_gotoToolDockMenu = new KActionMenu( i18n( "Tool &Docks" ), actionCollection(), "kmdi_tooldock_menu" ); 00155 m_gotoToolDockMenu->insert( new KAction( i18n( "Switch Top Dock" ), ALT + CTRL + SHIFT + Key_T, this, SIGNAL( toggleTop() ), 00156 actionCollection(), "kmdi_activate_top" ) ); 00157 m_gotoToolDockMenu->insert( new KAction( i18n( "Switch Left Dock" ), ALT + CTRL + SHIFT + Key_L, this, SIGNAL( toggleLeft() ), 00158 actionCollection(), "kmdi_activate_left" ) ); 00159 m_gotoToolDockMenu->insert( new KAction( i18n( "Switch Right Dock" ), ALT + CTRL + SHIFT + Key_R, this, SIGNAL( toggleRight() ), 00160 actionCollection(), "kmdi_activate_right" ) ); 00161 m_gotoToolDockMenu->insert( new KAction( i18n( "Switch Bottom Dock" ), ALT + CTRL + SHIFT + Key_B, this, SIGNAL( toggleBottom() ), 00162 actionCollection(), "kmdi_activate_bottom" ) ); 00163 m_gotoToolDockMenu->insert( new KActionSeparator( actionCollection(), "kmdi_goto_menu_separator" ) ); 00164 m_gotoToolDockMenu->insert( new KAction( i18n( "Previous Tool View" ), ALT + CTRL + Key_Left, m_mdiMainFrm, SLOT( prevToolViewInDock() ), 00165 actionCollection(), "kmdi_prev_toolview" ) ); 00166 m_gotoToolDockMenu->insert( new KAction( i18n( "Next Tool View" ), ALT + CTRL + Key_Right, m_mdiMainFrm, SLOT( nextToolViewInDock() ), 00167 actionCollection(), "kmdi_next_toolview" ) ); 00168 00169 actionCollection() ->readShortcutSettings( "Shortcuts", kapp->config() ); 00170 } 00171 00172 KMDIGUIClient::~KMDIGUIClient() 00173 { 00174 00175 // actionCollection()->writeShortcutSettings( "KMDI Shortcuts", kapp->config() ); 00176 for ( uint i = 0;i < m_toolViewActions.count();i++ ) 00177 disconnect( m_toolViewActions.at( i ), 0, this, 0 ); 00178 00179 m_toolViewActions.setAutoDelete( false ); 00180 m_toolViewActions.clear(); 00181 m_documentViewActions.setAutoDelete( false ); 00182 m_documentViewActions.clear(); 00183 } 00184 00185 void KMDIGUIClient::changeViewMode( int id ) 00186 { 00187 switch ( id ) 00188 { 00189 case 0: 00190 m_mdiMainFrm->switchToToplevelMode(); 00191 break; 00192 case 1: 00193 m_mdiMainFrm->switchToChildframeMode(); 00194 break; 00195 case 2: 00196 m_mdiMainFrm->switchToTabPageMode(); 00197 break; 00198 case 3: 00199 m_mdiMainFrm->switchToIDEAlMode(); 00200 break; 00201 default: 00202 Q_ASSERT( 0 ); 00203 } 00204 } 00205 00206 void KMDIGUIClient::setupActions() 00207 { 00208 if ( !factory() || !m_mdiMainFrm ) 00209 return ; 00210 00211 // BarActionBuilder builder( actionCollection(), m_mainWindow, m_toolBars ); 00212 00213 // if ( !builder.needsRebuild() ) 00214 // return; 00215 00216 00217 unplugActionList( actionListName ); 00218 00219 // m_actions.setAutoDelete( true ); 00220 // m_actions.clear(); 00221 // m_actions.setAutoDelete( false ); 00222 00223 // m_actions = builder.create(); 00224 00225 // m_toolBars = builder.toolBars(); 00226 00227 // m_toolViewActions.append(new KAction( "TESTKMDIGUICLIENT", QString::null, 0, 00228 // this, SLOT(blah()),actionCollection(),"nothing")); 00229 00230 QPtrList<KAction> addList; 00231 if ( m_toolViewActions.count() < 3 ) 00232 for ( uint i = 0;i < m_toolViewActions.count();i++ ) 00233 addList.append( m_toolViewActions.at( i ) ); 00234 else 00235 addList.append( m_toolMenu ); 00236 if ( m_mdiMode == KMdi::IDEAlMode ) 00237 addList.append( m_gotoToolDockMenu ); 00238 if ( m_mdiModeAction ) 00239 addList.append( m_mdiModeAction ); 00240 kdDebug( 760 ) << "KMDIGUIClient::setupActions: plugActionList" << endl; 00241 plugActionList( actionListName, addList ); 00242 00243 // connectToActionContainers(); 00244 } 00245 00246 void KMDIGUIClient::addToolView( KMdiToolViewAccessor* mtva ) 00247 { 00248 kdDebug( 760 ) << "*****void KMDIGUIClient::addToolView(KMdiToolViewAccessor* mtva)*****" << endl; 00249 // kdDebug()<<"name: "<<mtva->wrappedWidget()->name()<<endl; 00250 QString aname = QString( "kmdi_toolview_" ) + mtva->wrappedWidget() ->name(); 00251 00252 // try to read the action shortcut 00253 KShortcut sc; 00254 KConfig *cfg = kapp->config(); 00255 QString _grp = cfg->group(); 00256 cfg->setGroup( "Shortcuts" ); 00257 // if ( cfg->hasKey( aname ) ) 00258 sc = KShortcut( cfg->readEntry( aname, "" ) ); 00259 cfg->setGroup( _grp ); 00260 KAction *a = new ToggleToolViewAction( i18n( "Show %1" ).arg( mtva->wrappedWidget() ->caption() ), 00261 /*QString::null*/sc, dynamic_cast<KDockWidget*>( mtva->wrapperWidget() ), 00262 m_mdiMainFrm, actionCollection(), aname.latin1() ); 00263 #if KDE_IS_VERSION(3,2,90) 00264 00265 ( ( ToggleToolViewAction* ) a ) ->setCheckedState( i18n( "Hide %1" ).arg( mtva->wrappedWidget() ->caption() ) ); 00266 #endif 00267 00268 connect( a, SIGNAL( destroyed( QObject* ) ), this, SLOT( actionDeleted( QObject* ) ) ); 00269 m_toolViewActions.append( a ); 00270 m_toolMenu->insert( a ); 00271 mtva->d->action = a; 00272 00273 setupActions(); 00274 } 00275 00276 void KMDIGUIClient::actionDeleted( QObject* a ) 00277 { 00278 m_toolViewActions.remove( static_cast<KAction*>( a ) ); 00279 /* if (!m_toolMenu.isNull()) m_toolMenu->remove(static_cast<KAction*>(a));*/ 00280 setupActions(); 00281 } 00282 00283 00284 void KMDIGUIClient::clientAdded( KXMLGUIClient *client ) 00285 { 00286 if ( client == this ) 00287 setupActions(); 00288 } 00289 00290 00291 void KMDIGUIClient::mdiModeHasBeenChangedTo( KMdi::MdiMode mode ) 00292 { 00293 kdDebug( 760 ) << "KMDIGUIClient::mdiModeHasBennChangeTo" << endl; 00294 m_mdiMode = mode; 00295 if ( m_mdiModeAction ) 00296 { 00297 switch ( mode ) 00298 { 00299 case KMdi::ToplevelMode: 00300 m_mdiModeAction->setCurrentItem( 0 ); 00301 break; 00302 case KMdi::ChildframeMode: 00303 m_mdiModeAction->setCurrentItem( 1 ); 00304 break; 00305 case KMdi::TabPageMode: 00306 m_mdiModeAction->setCurrentItem( 2 ); 00307 break; 00308 case KMdi::IDEAlMode: 00309 m_mdiModeAction->setCurrentItem( 3 ); 00310 break; 00311 default: 00312 Q_ASSERT( 0 ); 00313 } 00314 } 00315 setupActions(); 00316 00317 } 00318 00319 00320 // kate: space-indent off; tab-width 4; replace-tabs off; indent-mode csands;
KDE Logo
This file is part of the documentation for kmdi Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Apr 14 00:37:13 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003