• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdemdi
 

tdemdi

tdemdiguiclient.cpp

00001 /* This file is part of the KDE libraries
00002   Copyright (C) 2003 Joseph Wenninger <jowenn@kde.org>
00003   based on tdetoolbarhandler.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., 51 Franklin Street, Fifth Floor,
00017   Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "tdemdiguiclient.h"
00021 #include "tdemdiguiclient.moc"
00022 
00023 #include <tqpopupmenu.h>
00024 #include <tdeapplication.h>
00025 #include <tdeconfig.h>
00026 #include <tdetoolbar.h>
00027 #include <tdemainwindow.h>
00028 #include <tdelocale.h>
00029 #include <tdeaction.h>
00030 #include <tqstring.h>
00031 #include <assert.h>
00032 #include <kdebug.h>
00033 #include <kdockwidget.h>
00034 #include <tdeversion.h>
00035 #include "tdemdimainfrm.h"
00036 #include "tdemditoolviewaccessor.h"
00037 #include "tdemditoolviewaccessor_p.h"
00038 namespace
00039 {
00040 const char *actionListName = "show_tdemdi_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 = "tdemdiviewactions.rc";
00052 
00053 }
00054 
00055 
00056 using namespace KMDIPrivate;
00057 
00058 
00059 
00060 ToggleToolViewAction::ToggleToolViewAction( const TQString& text, const TDEShortcut& cut, KDockWidget *dw, KMdiMainFrm *mdiMainFrm,
00061         TQObject* parent, const char* name )
00062         : TDEToggleAction( text, cut, parent, name ), m_dw( dw ), m_mdiMainFrm( mdiMainFrm )
00063 {
00064     if ( m_dw )
00065     {
00066         connect( this, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotToggled( bool ) ) );
00067         connect( m_dw->dockManager(), TQT_SIGNAL( change() ), this, TQT_SLOT( anDWChanged() ) );
00068         connect( m_dw, TQT_SIGNAL( destroyed() ), this, TQT_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                                ( ( ::tqqt_cast<KDockWidget*>( m_dw->parentDockTabGroup() ->
00087                                                               parent() ) ) ->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(), TQT_SIGNAL( change() ), this, TQT_SLOT( anDWChanged() ) );
00108     disconnect( this, TQT_SIGNAL( toggled( bool ) ), 0, 0 );
00109     unplugAll();
00110     deleteLater();
00111 }
00112 
00113 
00114 KMDIGUIClient::KMDIGUIClient( KMdiMainFrm* mdiMainFrm, bool showMDIModeAction, const char* name ) : TQObject( mdiMainFrm, name ),
00115         KXMLGUIClient( mdiMainFrm )
00116 {
00117     m_mdiMode = KMdi::ChildframeMode;
00118     m_mdiMainFrm = mdiMainFrm;
00119     connect( mdiMainFrm->guiFactory(), TQT_SIGNAL( clientAdded( KXMLGUIClient * ) ),
00120              this, TQT_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         TQString completeDescription = TQString::fromLatin1( guiDescription )
00132                                       .arg( actionListName );
00133 
00134         setXML( completeDescription, false /*merge*/ );
00135     }
00136 
00137     if ( actionCollection() ->tdeaccel() == 0 )
00138         actionCollection() ->setWidget( mdiMainFrm );
00139     m_toolMenu = new TDEActionMenu( i18n( "Tool &Views" ), actionCollection(), "tdemdi_toolview_menu" );
00140     if ( showMDIModeAction )
00141     {
00142         m_mdiModeAction = new TDESelectAction( i18n( "MDI Mode" ), 0, actionCollection() );
00143         TQStringList 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, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( changeViewMode( int ) ) );
00147     }
00148     else
00149         m_mdiModeAction = 0;
00150 
00151     connect( m_mdiMainFrm, TQT_SIGNAL( mdiModeHasBeenChangedTo( KMdi::MdiMode ) ),
00152              this, TQT_SLOT( mdiModeHasBeenChangedTo( KMdi::MdiMode ) ) );
00153 
00154     m_gotoToolDockMenu = new TDEActionMenu( i18n( "Tool &Docks" ), actionCollection(), "tdemdi_tooldock_menu" );
00155     m_gotoToolDockMenu->insert( new TDEAction( i18n( "Switch Top Dock" ), ALT + CTRL + SHIFT + Key_T, this, TQT_SIGNAL( toggleTop() ),
00156                                 actionCollection(), "tdemdi_activate_top" ) );
00157     m_gotoToolDockMenu->insert( new TDEAction( i18n( "Switch Left Dock" ), ALT + CTRL + SHIFT + Key_L, this, TQT_SIGNAL( toggleLeft() ),
00158                                 actionCollection(), "tdemdi_activate_left" ) );
00159     m_gotoToolDockMenu->insert( new TDEAction( i18n( "Switch Right Dock" ), ALT + CTRL + SHIFT + Key_R, this, TQT_SIGNAL( toggleRight() ),
00160                                 actionCollection(), "tdemdi_activate_right" ) );
00161     m_gotoToolDockMenu->insert( new TDEAction( i18n( "Switch Bottom Dock" ), ALT + CTRL + SHIFT + Key_B, this, TQT_SIGNAL( toggleBottom() ),
00162                                 actionCollection(), "tdemdi_activate_bottom" ) );
00163     m_gotoToolDockMenu->insert( new TDEActionSeparator( actionCollection(), "tdemdi_goto_menu_separator" ) );
00164     m_gotoToolDockMenu->insert( new TDEAction( i18n( "Previous Tool View" ), ALT + CTRL + Key_Left, TQT_TQOBJECT(m_mdiMainFrm), TQT_SLOT( prevToolViewInDock() ),
00165                                 actionCollection(), "tdemdi_prev_toolview" ) );
00166     m_gotoToolDockMenu->insert( new TDEAction( i18n( "Next Tool View" ), ALT + CTRL + Key_Right, TQT_TQOBJECT(m_mdiMainFrm), TQT_SLOT( nextToolViewInDock() ),
00167                                 actionCollection(), "tdemdi_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 TDEAction( "TESTKMDIGUICLIENT", TQString::null, 0,
00228     //             this, TQT_SLOT(blah()),actionCollection(),"nothing"));
00229 
00230     TQPtrList<TDEAction> 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     TQString aname = TQString( "tdemdi_toolview_" ) + mtva->wrappedWidget() ->name();
00251 
00252     // try to read the action shortcut
00253     TDEShortcut sc;
00254     TDEConfig *cfg = kapp->config();
00255     TQString _grp = cfg->group();
00256     cfg->setGroup( "Shortcuts" );
00257     //  if ( cfg->hasKey( aname ) )
00258     sc = TDEShortcut( cfg->readEntry( aname, "" ) );
00259     cfg->setGroup( _grp );
00260     TDEAction *a = new ToggleToolViewAction( i18n( "Show %1" ).arg( mtva->wrappedWidget() ->caption() ),
00261                                            /*TQString::null*/sc, tqt_dynamic_cast<KDockWidget*>( mtva->wrapperWidget() ),
00262                                            m_mdiMainFrm, actionCollection(), aname.latin1() );
00263 #if KDE_IS_VERSION(3,2,90)
00264 
00265     ( ( ToggleToolViewAction* ) a ) ->setCheckedState( TQString(i18n( "Hide %1" ).arg( mtva->wrappedWidget() ->caption() )) );
00266 #endif
00267 
00268     connect( a, TQT_SIGNAL( destroyed( TQObject* ) ), this, TQT_SLOT( actionDeleted( TQObject* ) ) );
00269     m_toolViewActions.append( a );
00270     m_toolMenu->insert( a );
00271     mtva->d->action = a;
00272 
00273     setupActions();
00274 }
00275 
00276 void KMDIGUIClient::actionDeleted( TQObject* a )
00277 {
00278     m_toolViewActions.remove( static_cast<TDEAction*>( a ) );
00279     /*  if (!m_toolMenu.isNull()) m_toolMenu->remove(static_cast<TDEAction*>(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;

tdemdi

Skip menu "tdemdi"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdemdi

Skip menu "tdemdi"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdemdi by doxygen 1.7.1
This website is maintained by Timothy Pearson.