kmdi Library: guiclient.cpp Source File (kmdi Library)

| # kmdi Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# guiclient.cpp

    00001 /* This file is part of the KDE libraries
    00002    Copyright (C) 2003 Joseph Wenninger <jowenn@kde.org>
    00003    Copyright (C) 2004 Christoph Cullmann <cullmann@kde.org>
    00004    based on ktoolbarhandler.cpp: Copyright (C) 2002 Simon Hausmann <hausmann@kde.org>
    00005
    00006    This library is free software; you can redistribute it and/or
    00007    modify it under the terms of the GNU Library General Public
    00008    License version 2 as published by the Free Software Foundation.
    00009
    00010    This library is distributed in the hope that it will be useful,
    00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013    Library General Public License for more details.
    00014
    00015    You should have received a copy of the GNU Library General Public License
    00016    along with this library; see the file COPYING.LIB.  If not, write to
    00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018    Boston, MA 02111-1307, USA.
    00019 */
    00020
    00021 #include "guiclient.h"
    00022 #include "guiclient.moc"
    00023
    00024 #include <qpopupmenu.h>
    00025 #include <kapplication.h>
    00026 #include <kconfig.h>
    00027 #include <ktoolbar.h>
    00028 #include <klocale.h>
    00029 #include <kaction.h>
    00030 #include <qstring.h>
    00031 #include <kdebug.h>
    00032 #include <kdockwidget.h>
    00033
    00034 #include "mainwindow.h"
    00035 #include "toolviewaccessor.h"
    00036 #include "toolviewaccessor_p.h"
    00037
    00038 static const char *actionListName = "show_kmdi_document_tool_view_actions";
    00039
    00040 static const char *guiDescription = ""
    00041         "<!DOCTYPE kpartgui><kpartgui name=\"KMDIViewActions\">"
    00042         "<MenuBar>"
    00043         "    <Menu name=\"window\">"
    00044         "        <ActionList name=\"%1\" />"
    00045         "    </Menu>"
    00046         "</MenuBar>"
    00047         "</kpartgui>";
    00048
    00049 static const char *resourceFileName = "kmdiviewactions.rc";
    00050
    00051 namespace KMDIPrivate
    00052 {
    00053
    00054 GUIClient::GUIClient (KMDI::MainWindow* mdiMainFrm,const char* name)
    00055  : QObject ( mdiMainFrm,name )
    00056  , KXMLGUIClient ( mdiMainFrm )
    00057 {
    00058   m_mdiMainFrm=mdiMainFrm;
    00059
    00060   connect( mdiMainFrm->guiFactory(), SIGNAL( clientAdded( KXMLGUIClient * ) ),
    00061            this, SLOT( clientAdded( KXMLGUIClient * ) ) );
    00062
    00063   /* re-use an existing resource file if it exists. can happen if the user launches the
    00064    * toolbar editor */
    00065   /*
    00066   setXMLFile( resourceFileName );
    00067   */
    00068
    00069   if ( domDocument().documentElement().isNull() )
    00070   {
    00071     QString completeDescription = QString::fromLatin1( guiDescription ).arg( actionListName );
    00072
    00073     setXML( completeDescription, false /*merge*/ );
    00074   }
    00075
    00076   if (actionCollection()->kaccel()==0)
    00077     actionCollection()->setWidget(mdiMainFrm);
    00078
    00079   m_toolMenu=new KActionMenu(i18n("Tool &Views"),actionCollection(),"kmdi_toolview_menu");
    00080
    00081   m_gotoToolDockMenu=new KActionMenu(i18n("Tool &Docks"),actionCollection(),"kmdi_tooldock_menu");
    00082   m_gotoToolDockMenu->insert(new KAction(i18n("Switch Top Dock"),ALT+CTRL+SHIFT+Key_T,this,SIGNAL(toggleTop()),
    00083   actionCollection(),"kmdi_activate_top"));
    00084   m_gotoToolDockMenu->insert(new KAction(i18n("Switch Left Dock"),ALT+CTRL+SHIFT+Key_L,this,SIGNAL(toggleLeft()),
    00085   actionCollection(),"kmdi_activate_left"));
    00086   m_gotoToolDockMenu->insert(new KAction(i18n("Switch Right Dock"),ALT+CTRL+SHIFT+Key_R,this,SIGNAL(toggleRight()),
    00087   actionCollection(),"kmdi_activate_right"));
    00088   m_gotoToolDockMenu->insert(new KAction(i18n("Switch Bottom Dock"),ALT+CTRL+SHIFT+Key_B,this,SIGNAL(toggleBottom()),
    00089   actionCollection(),"kmdi_activate_bottom"));
    00090   m_gotoToolDockMenu->insert(new KActionSeparator(actionCollection(),"kmdi_goto_menu_separator"));
    00091   m_gotoToolDockMenu->insert(new KAction(i18n("Previous Tool View"),ALT+CTRL+Key_Left,m_mdiMainFrm,SLOT(prevToolViewInDock()),
    00092   actionCollection(),"kmdi_prev_toolview"));
    00093   m_gotoToolDockMenu->insert(new KAction(i18n("Next Tool View"),ALT+CTRL+Key_Right,m_mdiMainFrm,SLOT(nextToolViewInDock()),
    00094   actionCollection(),"kmdi_next_toolview"));
    00095
    00096   actionCollection()->readShortcutSettings( "Shortcuts", kapp->config() );
    00097 }
    00098
    00099 GUIClient::~GUIClient()
    00100 {
    00101 //     actionCollection()->writeShortcutSettings( "KMDI Shortcuts", kapp->config() );
    00102   for (uint i=0;i<m_toolViewActions.count();i++)
    00103     disconnect(m_toolViewActions.at(i),0,this,0);
    00104
    00105   m_toolViewActions.setAutoDelete( false );
    00106   m_toolViewActions.clear();
    00107   m_documentViewActions.setAutoDelete( false );
    00108   m_documentViewActions.clear();
    00109 }
    00110
    00111 void GUIClient::setupActions()
    00112 {
    00113   if ( !factory() || !m_mdiMainFrm )
    00114     return;
    00115
    00116   unplugActionList( actionListName );
    00117
    00118   QPtrList<KAction> addList;
    00119   if (m_toolViewActions.count()<3)
    00120   {
    00121     for (uint i=0;i<m_toolViewActions.count();i++)
    00122       addList.append(m_toolViewActions.at(i));
    00123   }
    00124   else
    00125     addList.append(m_toolMenu);
    00126
    00127   addList.append(m_gotoToolDockMenu);
    00128
    00129   kdDebug(760)<<"GUIClient::setupActions: plugActionList"<<endl;
    00130
    00131   plugActionList( actionListName, addList );
    00132 }
    00133
    00134 void GUIClient::addToolView(KMDI::ToolViewAccessor* mtva)
    00135 {
    00136   kdDebug(760)<<"*****void GUIClient::addToolView(KMDI::ToolViewAccessor* mtva)*****"<<endl;
    00137
    00138   QString aname = QString("kmdi_toolview_") + mtva->wrappedWidget()->name();
    00139
    00140   // try to read the action shortcut
    00141   KShortcut sc;
    00142   KConfig *cfg = kapp->config();
    00143   QString _grp = cfg->group();
    00144   cfg->setGroup("Shortcuts");
    00145   sc = KShortcut( cfg->readEntry( aname, "" ) );
    00146   cfg->setGroup( _grp );
    00147
    00148   KAction *a=new ToggleToolViewAction(i18n("Show %1").arg(mtva->wrappedWidget()->caption()),
    00149     /*QString::null*/sc,dynamic_cast<KDockWidget*>(mtva->wrapperWidget()),
    00150     m_mdiMainFrm,actionCollection(), aname.latin1() );
    00151
    00152   ((ToggleToolViewAction*)a)->setCheckedState(i18n("Hide %1").arg(mtva->wrappedWidget()->caption()));
    00153
    00154   connect(a,SIGNAL(destroyed(QObject*)),this,SLOT(actionDeleted(QObject*)));
    00155
    00156   m_toolViewActions.append(a);
    00157   m_toolMenu->insert(a);
    00158   mtva->d->action=a;
    00159
    00160   setupActions();
    00161 }
    00162
    00163 void GUIClient::actionDeleted(QObject* a)
    00164 {
    00165   m_toolViewActions.remove(static_cast<KAction*>(a));
    00166   setupActions();
    00167 }
    00168
    00169
    00170 void GUIClient::clientAdded( KXMLGUIClient *client )
    00171 {
    00172   if ( client == this )
    00173     setupActions();
    00174 }
    00175
    00176 ToggleToolViewAction::ToggleToolViewAction ( const QString& text, const KShortcut& cut,KDockWidget *dw, KMDI::MainWindow *mdiMainFrm,
    00177                                              QObject* parent, const char* name )
    00178  : KToggleAction(text,cut,parent,name)
    00179  , m_dw(dw)
    00180  , m_mdiMainFrm(mdiMainFrm)
    00181 {
    00182   if (m_dw)
    00183   {
    00184     connect(this,SIGNAL(toggled(bool)),this,SLOT(slotToggled(bool)));
    00185     connect(m_dw->dockManager(),SIGNAL(change()),this,SLOT(anDWChanged()));
    00186     connect(m_dw,SIGNAL(destroyed()),this,SLOT(slotWidgetDestroyed()));
    00187
    00188     setChecked(m_dw->mayBeHide());
    00189   }
    00190 }
    00191
    00192 ToggleToolViewAction::~ToggleToolViewAction()
    00193 {
    00194   unplugAll();
    00195 }
    00196
    00197 void ToggleToolViewAction::anDWChanged()
    00198 {
    00199   if (isChecked() && m_dw->mayBeShow())
    00200     setChecked(false);
    00201   else if ((!isChecked()) && m_dw->mayBeHide())
    00202     setChecked(true);
    00203   else if (isChecked() && (m_dw->parentDockTabGroup() &&
    00204           ((static_cast<KDockWidget*>(m_dw->parentDockTabGroup()->
    00205                   parent()->qt_cast("KDockWidget")))->mayBeShow())))
    00206     setChecked(false);
    00207 }
    00208
    00209
    00210 void ToggleToolViewAction::slotToggled(bool t)
    00211 {
    00212   if ((!t) && m_dw->mayBeHide() )
    00213     m_dw->undock();
    00214   else
    00215     if ( t && m_dw->mayBeShow() )
    00216       m_mdiMainFrm->makeDockVisible(m_dw);
    00217 }
    00218
    00219 void ToggleToolViewAction::slotWidgetDestroyed()
    00220 {
    00221   disconnect(m_dw->dockManager(),SIGNAL(change()),this,SLOT(anDWChanged()));
    00222   disconnect(this,SIGNAL(toggled(bool)),0,0);
    00223
    00224   unplugAll();
    00225   deleteLater();
    00226 }
    00227
    00228 }
    00229
    00230 // kate: space-indent on; indent-width 2; replace-tabs on;

This file is part of the documentation for kmdi Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:32:05 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003