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 <ktoolbar.h> 00026 #include <kmainwindow.h> 00027 #include <klocale.h> 00028 #include <kaction.h> 00029 #include <qstring.h> 00030 #include <assert.h> 00031 #include <kdebug.h> 00032 #include <kdockwidget.h> 00033 #include "kmdimainfrm.h" 00034 #include "kmditoolviewaccessor.h" 00035 #include "kmditoolviewaccessor_p.h" 00036 namespace 00037 { 00038 const char *actionListName = "show_kmdi_document_tool_view_actions"; 00039 00040 const char *guiDescription = "" 00041 "<!DOCTYPE kpartgui><kpartgui name=\"KMDIViewActions\">" 00042 "<MenuBar>" 00043 " <Menu name=\"view\">" 00044 " <ActionList name=\"%1\" />" 00045 " </Menu>" 00046 "</MenuBar>" 00047 "</kpartgui>"; 00048 00049 const char *resourceFileName = "kmdiviewactions.rc"; 00050 00051 } 00052 00053 00054 using namespace KMDIPrivate; 00055 00056 00057 00058 ToggleToolViewAction::ToggleToolViewAction( const QString& text, const KShortcut& cut,KDockWidget *dw, KMdiMainFrm *mdiMainFrm, 00059 QObject* parent, const char* name ) 00060 :KToggleAction(text,cut,parent,name),m_dw(dw),m_mdiMainFrm(mdiMainFrm) 00061 { 00062 if (m_dw) { 00063 connect(this,SIGNAL(toggled(bool)),this,SLOT(slotToggled(bool))); 00064 connect(m_dw->dockManager(),SIGNAL(change()),this,SLOT(anDWChanged())); 00065 connect(m_dw,SIGNAL(destroyed()),this,SLOT(slotWidgetDestroyed())); 00066 setChecked(m_dw->mayBeHide()); 00067 } 00068 } 00069 00070 00071 ToggleToolViewAction::~ToggleToolViewAction(){unplugAll();} 00072 00073 void ToggleToolViewAction::anDWChanged() 00074 { 00075 if (isChecked() && m_dw->mayBeShow()) setChecked(false); 00076 else if ((!isChecked()) && m_dw->mayBeHide()) setChecked(true); 00077 else if (isChecked() && (m_dw->parentDockTabGroup() && 00078 ((static_cast<KDockWidget*>(m_dw->parentDockTabGroup()-> 00079 parent()->qt_cast("KDockWidget")))->mayBeShow()))) setChecked(false); 00080 } 00081 00082 00083 void ToggleToolViewAction::slotToggled(bool t) 00084 { 00085 // m_mw->mainDock->setDockSite( KDockWidget::DockCorner ); 00086 00087 if ((!t) && m_dw->mayBeHide() ) m_dw->undock(); 00088 else 00089 if ( t && m_dw->mayBeShow() ) m_mdiMainFrm->makeDockVisible(m_dw); 00090 00091 // m_mw->mainDock->setDockSite( KDockWidget::DockNone ); 00092 } 00093 00094 void ToggleToolViewAction::slotWidgetDestroyed() 00095 { 00096 disconnect(m_dw->dockManager(),SIGNAL(change()),this,SLOT(anDWChanged())); 00097 disconnect(this,SIGNAL(toggled(bool)),0,0); 00098 unplugAll(); 00099 deleteLater(); 00100 } 00101 00102 00103 KMDIGUIClient::KMDIGUIClient(KMdiMainFrm* mdiMainFrm,bool showMDIModeAction, const char* name): QObject( mdiMainFrm,name ), 00104 KXMLGUIClient( mdiMainFrm ) 00105 { 00106 m_mdiMode=KMdi::ChildframeMode; 00107 m_mdiMainFrm=mdiMainFrm; 00108 connect( mdiMainFrm->guiFactory(), SIGNAL( clientAdded( KXMLGUIClient * ) ), 00109 this, SLOT( clientAdded( KXMLGUIClient * ) ) ); 00110 00111 /* re-use an existing resource file if it exists. can happen if the user launches the 00112 * toolbar editor */ 00113 /* 00114 setXMLFile( resourceFileName ); 00115 */ 00116 00117 if ( domDocument().documentElement().isNull() ) { 00118 00119 QString completeDescription = QString::fromLatin1( guiDescription ) 00120 .arg( actionListName ); 00121 00122 setXML( completeDescription, false /*merge*/ ); 00123 } 00124 00125 if (actionCollection()->kaccel()==0) 00126 actionCollection()->setWidget(mdiMainFrm); 00127 m_toolMenu=new KActionMenu(i18n("Tool &Views"),actionCollection(),"kmdi_toolview_menu"); 00128 if (showMDIModeAction) { 00129 m_mdiModeAction=new KSelectAction(i18n("MDI Mode"),0,actionCollection()); 00130 QStringList modes; 00131 modes<<i18n("&Toplevel Mode")<<i18n("C&hildframe Mode")<<i18n("Ta&b Page Mode")<<i18n("I&DEAl Mode"); 00132 m_mdiModeAction->setItems(modes); 00133 connect(m_mdiModeAction,SIGNAL(activated(int)),this,SLOT(changeViewMode(int))); 00134 } else m_mdiModeAction=0; 00135 00136 connect(m_mdiMainFrm,SIGNAL(mdiModeHasBeenChangedTo(KMdi::MdiMode)), 00137 this,SLOT(mdiModeHasBeenChangedTo(KMdi::MdiMode))); 00138 00139 m_gotoToolDockMenu=new KActionMenu(i18n("Tool &Docks"),actionCollection(),"kmdi_tooldock_menu"); 00140 m_gotoToolDockMenu->insert(new KAction(i18n("Switch Top Dock"),ALT+CTRL+SHIFT+Key_T,this,SIGNAL(toggleTop()), 00141 actionCollection(),"kmdi_activate_top")); 00142 m_gotoToolDockMenu->insert(new KAction(i18n("Switch Left Dock"),ALT+CTRL+SHIFT+Key_L,this,SIGNAL(toggleLeft()), 00143 actionCollection(),"kmdi_activate_left")); 00144 m_gotoToolDockMenu->insert(new KAction(i18n("Switch Right Dock"),ALT+CTRL+SHIFT+Key_R,this,SIGNAL(toggleRight()), 00145 actionCollection(),"kmdi_activate_right")); 00146 m_gotoToolDockMenu->insert(new KAction(i18n("Switch Bottom Dock"),ALT+CTRL+SHIFT+Key_B,this,SIGNAL(toggleBottom()), 00147 actionCollection(),"kmdi_activate_bottom")); 00148 m_gotoToolDockMenu->insert(new KActionSeparator(actionCollection(),"kmdi_goto_menu_separator")); 00149 m_gotoToolDockMenu->insert(new KAction(i18n("Previous Tool View"),ALT+CTRL+Key_Left,m_mdiMainFrm,SLOT(prevToolViewInDock()), 00150 actionCollection(),"kmdi_prev_toolview")); 00151 m_gotoToolDockMenu->insert(new KAction(i18n("Next Tool View"),ALT+CTRL+Key_Right,m_mdiMainFrm,SLOT(nextToolViewInDock()), 00152 actionCollection(),"kmdi_next_toolview")); 00153 00154 } 00155 00156 KMDIGUIClient::~KMDIGUIClient() 00157 { 00158 00159 for (uint i=0;i<m_toolViewActions.count();i++) 00160 disconnect(m_toolViewActions.at(i),0,this,0); 00161 00162 m_toolViewActions.setAutoDelete( false ); 00163 m_toolViewActions.clear(); 00164 m_documentViewActions.setAutoDelete( false ); 00165 m_documentViewActions.clear(); 00166 } 00167 00168 00169 void KMDIGUIClient::changeViewMode(int id) { 00170 switch (id) { 00171 case 0: m_mdiMainFrm->switchToToplevelMode(); 00172 break; 00173 case 1: m_mdiMainFrm->switchToChildframeMode(); 00174 break; 00175 case 2: m_mdiMainFrm->switchToTabPageMode(); 00176 break; 00177 case 3: m_mdiMainFrm->switchToIDEAlMode(); 00178 break; 00179 default: 00180 Q_ASSERT(0); 00181 } 00182 } 00183 00184 void KMDIGUIClient::setupActions() 00185 { 00186 if ( !factory() || !m_mdiMainFrm ) 00187 return; 00188 00189 // BarActionBuilder builder( actionCollection(), m_mainWindow, m_toolBars ); 00190 00191 // if ( !builder.needsRebuild() ) 00192 // return; 00193 00194 00195 unplugActionList( actionListName ); 00196 00197 // m_actions.setAutoDelete( true ); 00198 // m_actions.clear(); 00199 // m_actions.setAutoDelete( false ); 00200 00201 // m_actions = builder.create(); 00202 00203 // m_toolBars = builder.toolBars(); 00204 00205 // m_toolViewActions.append(new KAction( "TESTKMDIGUICLIENT", QString::null, 0, 00206 // this, SLOT(blah()),actionCollection(),"nothing")); 00207 00208 QPtrList<KAction> addList; 00209 if (m_toolViewActions.count()<3) 00210 for (uint i=0;i<m_toolViewActions.count();i++) 00211 addList.append(m_toolViewActions.at(i)); 00212 else 00213 addList.append(m_toolMenu); 00214 if (m_mdiMode==KMdi::IDEAlMode) addList.append(m_gotoToolDockMenu); 00215 if (m_mdiModeAction) addList.append(m_mdiModeAction); 00216 kdDebug(760)<<"KMDIGUIClient::setupActions: plugActionList"<<endl; 00217 plugActionList( actionListName, addList ); 00218 00219 // connectToActionContainers(); 00220 } 00221 00222 void KMDIGUIClient::addToolView(KMdiToolViewAccessor* mtva) { 00223 kdDebug(760)<<"*****void KMDIGUIClient::addToolView(KMdiToolViewAccessor* mtva)*****"<<endl; 00224 KAction *a=new ToggleToolViewAction(i18n("Show %1").arg(mtva->wrappedWidget()->caption()), 00225 QString::null,dynamic_cast<KDockWidget*>(mtva->wrapperWidget()),m_mdiMainFrm,actionCollection() ); 00226 connect(a,SIGNAL(destroyed(QObject*)),this,SLOT(actionDeleted(QObject*))); 00227 m_toolViewActions.append(a); 00228 m_toolMenu->insert(a); 00229 mtva->d->action=a; 00230 setupActions(); 00231 } 00232 00233 void KMDIGUIClient::actionDeleted(QObject* a) { 00234 m_toolViewActions.remove(static_cast<KAction*>(a)); 00235 /* if (!m_toolMenu.isNull()) m_toolMenu->remove(static_cast<KAction*>(a));*/ 00236 setupActions(); 00237 } 00238 00239 00240 void KMDIGUIClient::clientAdded( KXMLGUIClient *client ) 00241 { 00242 if ( client == this ) 00243 setupActions(); 00244 } 00245 00246 00247 void KMDIGUIClient::mdiModeHasBeenChangedTo(KMdi::MdiMode mode) { 00248 kdDebug(760)<<"KMDIGUIClient::mdiModeHasBennChangeTo"<<endl; 00249 m_mdiMode=mode; 00250 if (m_mdiModeAction) { 00251 switch (mode) { 00252 case KMdi::ToplevelMode: 00253 m_mdiModeAction->setCurrentItem(0); 00254 break; 00255 case KMdi::ChildframeMode: 00256 m_mdiModeAction->setCurrentItem(1); 00257 break; 00258 case KMdi::TabPageMode: 00259 m_mdiModeAction->setCurrentItem(2); 00260 break; 00261 case KMdi::IDEAlMode: 00262 m_mdiModeAction->setCurrentItem(3); 00263 break; 00264 default: Q_ASSERT(0); 00265 } 00266 } 00267 setupActions(); 00268 00269 } 00270 00271
KDE Logo
This file is part of the documentation for kmdi Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Aug 30 22:56:07 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003