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

tdemdi

  • tdemdi
tdemdiguiclient.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2003 Joseph Wenninger <jowenn@kde.org>
3  based on tdetoolbarhandler.cpp: Copyright (C) 2002 Simon Hausmann <hausmann@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "tdemdiguiclient.h"
21 #include "tdemdiguiclient.moc"
22 
23 #include <tqpopupmenu.h>
24 #include <tdeapplication.h>
25 #include <tdeconfig.h>
26 #include <tdetoolbar.h>
27 #include <tdemainwindow.h>
28 #include <tdelocale.h>
29 #include <tdeaction.h>
30 #include <tqstring.h>
31 #include <assert.h>
32 #include <kdebug.h>
33 #include <kdockwidget.h>
34 #include "tdemdimainfrm.h"
35 #include "tdemditoolviewaccessor.h"
36 #include "tdemditoolviewaccessor_p.h"
37 namespace
38 {
39 const char *actionListName = "show_tdemdi_document_tool_view_actions";
40 
41 const char *guiDescription = ""
42  "<!DOCTYPE kpartgui><kpartgui name=\"KMDIViewActions\">"
43  "<MenuBar>"
44  " <Menu name=\"view\">"
45  " <ActionList name=\"%1\" />"
46  " </Menu>"
47  "</MenuBar>"
48  "</kpartgui>";
49 
50 const char *resourceFileName = "tdemdiviewactions.rc";
51 
52 }
53 
54 
55 using namespace KMDIPrivate;
56 
57 
58 
59 ToggleToolViewAction::ToggleToolViewAction( const TQString& text, const TDEShortcut& cut, KDockWidget *dw, KMdiMainFrm *mdiMainFrm,
60  TQObject* parent, const char* name )
61  : TDEToggleAction( text, cut, parent, name ), m_dw( dw ), m_mdiMainFrm( mdiMainFrm )
62 {
63  if ( m_dw )
64  {
65  connect( this, TQ_SIGNAL( toggled( bool ) ), this, TQ_SLOT( slotToggled( bool ) ) );
66  connect( m_dw->dockManager(), TQ_SIGNAL( change() ), this, TQ_SLOT( anDWChanged() ) );
67  connect( m_dw, TQ_SIGNAL( destroyed() ), this, TQ_SLOT( slotWidgetDestroyed() ) );
68  setChecked( m_dw->mayBeHide() );
69  }
70 }
71 
72 
73 ToggleToolViewAction::~ToggleToolViewAction()
74 {
75  unplugAll();
76 }
77 
78 void ToggleToolViewAction::anDWChanged()
79 {
80  if ( isChecked() && m_dw->mayBeShow() )
81  setChecked( false );
82  else if ( ( !isChecked() ) && m_dw->mayBeHide() )
83  setChecked( true );
84  else if ( isChecked() && ( m_dw->parentDockTabGroup() &&
85  ( ( ::tqt_cast<KDockWidget*>( m_dw->parentDockTabGroup() ->
86  parent() ) ) ->mayBeShow() ) ) )
87  setChecked( false );
88 }
89 
90 
91 void ToggleToolViewAction::slotToggled( bool t )
92 {
93  // m_mw->mainDock->setDockSite( KDockWidget::DockCorner );
94 
95  if ( ( !t ) && m_dw->mayBeHide() )
96  m_dw->undock();
97  else
98  if ( t && m_dw->mayBeShow() )
99  m_mdiMainFrm->makeDockVisible( m_dw );
100 
101  // m_mw->mainDock->setDockSite( KDockWidget::DockNone );
102 }
103 
104 void ToggleToolViewAction::slotWidgetDestroyed()
105 {
106  disconnect( m_dw->dockManager(), TQ_SIGNAL( change() ), this, TQ_SLOT( anDWChanged() ) );
107  disconnect( this, TQ_SIGNAL( toggled( bool ) ), 0, 0 );
108  unplugAll();
109  deleteLater();
110 }
111 
112 
113 KMDIGUIClient::KMDIGUIClient( KMdiMainFrm* mdiMainFrm, bool showMDIModeAction, const char* name ) : TQObject( mdiMainFrm, name ),
114  KXMLGUIClient( mdiMainFrm )
115 {
116  m_mdiMode = KMdi::ChildframeMode;
117  m_mdiMainFrm = mdiMainFrm;
118  connect( mdiMainFrm->guiFactory(), TQ_SIGNAL( clientAdded( KXMLGUIClient * ) ),
119  this, TQ_SLOT( clientAdded( KXMLGUIClient * ) ) );
120 
121  /* re-use an existing resource file if it exists. can happen if the user launches the
122  * toolbar editor */
123  /*
124  setXMLFile( resourceFileName );
125  */
126 
127  if ( domDocument().documentElement().isNull() )
128  {
129 
130  TQString completeDescription = TQString::fromLatin1( guiDescription )
131  .arg( actionListName );
132 
133  setXML( completeDescription, false /*merge*/ );
134  }
135 
136  if ( actionCollection() ->tdeaccel() == 0 )
137  actionCollection() ->setWidget( mdiMainFrm );
138  m_toolMenu = new TDEActionMenu( i18n( "Tool &Views" ), actionCollection(), "tdemdi_toolview_menu" );
139  if ( showMDIModeAction )
140  {
141  m_mdiModeAction = new TDESelectAction( i18n( "MDI Mode" ), 0, actionCollection() );
142  TQStringList modes;
143  modes << i18n( "&Toplevel Mode" ) << i18n( "C&hildframe Mode" ) << i18n( "Ta&b Page Mode" ) << i18n( "I&DEAl Mode" );
144  m_mdiModeAction->setItems( modes );
145  connect( m_mdiModeAction, TQ_SIGNAL( activated( int ) ), this, TQ_SLOT( changeViewMode( int ) ) );
146  }
147  else
148  m_mdiModeAction = 0;
149 
150  connect( m_mdiMainFrm, TQ_SIGNAL( mdiModeHasBeenChangedTo( KMdi::MdiMode ) ),
151  this, TQ_SLOT( mdiModeHasBeenChangedTo( KMdi::MdiMode ) ) );
152 
153  m_gotoToolDockMenu = new TDEActionMenu( i18n( "Tool &Docks" ), actionCollection(), "tdemdi_tooldock_menu" );
154  m_gotoToolDockMenu->insert( new TDEAction( i18n( "Switch Top Dock" ), ALT + CTRL + SHIFT + Key_T, this, TQ_SIGNAL( toggleTop() ),
155  actionCollection(), "tdemdi_activate_top" ) );
156  m_gotoToolDockMenu->insert( new TDEAction( i18n( "Switch Left Dock" ), ALT + CTRL + SHIFT + Key_L, this, TQ_SIGNAL( toggleLeft() ),
157  actionCollection(), "tdemdi_activate_left" ) );
158  m_gotoToolDockMenu->insert( new TDEAction( i18n( "Switch Right Dock" ), ALT + CTRL + SHIFT + Key_R, this, TQ_SIGNAL( toggleRight() ),
159  actionCollection(), "tdemdi_activate_right" ) );
160  m_gotoToolDockMenu->insert( new TDEAction( i18n( "Switch Bottom Dock" ), ALT + CTRL + SHIFT + Key_B, this, TQ_SIGNAL( toggleBottom() ),
161  actionCollection(), "tdemdi_activate_bottom" ) );
162  m_gotoToolDockMenu->insert( new TDEActionSeparator( actionCollection(), "tdemdi_goto_menu_separator" ) );
163  m_gotoToolDockMenu->insert( new TDEAction( i18n( "Previous Tool View" ), ALT + CTRL + Key_Left, m_mdiMainFrm, TQ_SLOT( prevToolViewInDock() ),
164  actionCollection(), "tdemdi_prev_toolview" ) );
165  m_gotoToolDockMenu->insert( new TDEAction( i18n( "Next Tool View" ), ALT + CTRL + Key_Right, m_mdiMainFrm, TQ_SLOT( nextToolViewInDock() ),
166  actionCollection(), "tdemdi_next_toolview" ) );
167 
168  actionCollection() ->readShortcutSettings( "Shortcuts", tdeApp->config() );
169 }
170 
171 KMDIGUIClient::~KMDIGUIClient()
172 {
173 
174  // actionCollection()->writeShortcutSettings( "KMDI Shortcuts", tdeApp->config() );
175  for ( uint i = 0;i < m_toolViewActions.count();i++ )
176  disconnect( m_toolViewActions.at( i ), 0, this, 0 );
177 
178  m_toolViewActions.setAutoDelete( false );
179  m_toolViewActions.clear();
180  m_documentViewActions.setAutoDelete( false );
181  m_documentViewActions.clear();
182 }
183 
184 void KMDIGUIClient::changeViewMode( int id )
185 {
186  switch ( id )
187  {
188  case 0:
189  m_mdiMainFrm->switchToToplevelMode();
190  break;
191  case 1:
192  m_mdiMainFrm->switchToChildframeMode();
193  break;
194  case 2:
195  m_mdiMainFrm->switchToTabPageMode();
196  break;
197  case 3:
198  m_mdiMainFrm->switchToIDEAlMode();
199  break;
200  default:
201  Q_ASSERT( 0 );
202  }
203 }
204 
205 void KMDIGUIClient::setupActions()
206 {
207  if ( !factory() || !m_mdiMainFrm )
208  return ;
209 
210  // BarActionBuilder builder( actionCollection(), m_mainWindow, m_toolBars );
211 
212  // if ( !builder.needsRebuild() )
213  // return;
214 
215 
216  unplugActionList( actionListName );
217 
218  // m_actions.setAutoDelete( true );
219  // m_actions.clear();
220  // m_actions.setAutoDelete( false );
221 
222  // m_actions = builder.create();
223 
224  // m_toolBars = builder.toolBars();
225 
226  // m_toolViewActions.append(new TDEAction( "TESTKMDIGUICLIENT", TQString::null, 0,
227  // this, TQ_SLOT(blah()),actionCollection(),"nothing"));
228 
229  TQPtrList<TDEAction> addList;
230  if ( m_toolViewActions.count() < 3 )
231  for ( uint i = 0;i < m_toolViewActions.count();i++ )
232  addList.append( m_toolViewActions.at( i ) );
233  else
234  addList.append( m_toolMenu );
235  if ( m_mdiMode == KMdi::IDEAlMode )
236  addList.append( m_gotoToolDockMenu );
237  if ( m_mdiModeAction )
238  addList.append( m_mdiModeAction );
239  kdDebug( 760 ) << "KMDIGUIClient::setupActions: plugActionList" << endl;
240  plugActionList( actionListName, addList );
241 
242  // connectToActionContainers();
243 }
244 
245 void KMDIGUIClient::addToolView( KMdiToolViewAccessor* mtva )
246 {
247  kdDebug( 760 ) << "*****void KMDIGUIClient::addToolView(KMdiToolViewAccessor* mtva)*****" << endl;
248  // kdDebug()<<"name: "<<mtva->wrappedWidget()->name()<<endl;
249  TQString aname = TQString( "tdemdi_toolview_" ) + mtva->wrappedWidget() ->name();
250 
251  // try to read the action shortcut
252  TDEShortcut sc;
253  TDEConfig *cfg = tdeApp->config();
254  TQString _grp = cfg->group();
255  cfg->setGroup( "Shortcuts" );
256  // if ( cfg->hasKey( aname ) )
257  sc = TDEShortcut( cfg->readEntry( aname, "" ) );
258  cfg->setGroup( _grp );
259  TDEAction *a = new ToggleToolViewAction( i18n( "Show %1" ).arg( mtva->wrappedWidget() ->caption() ),
260  /*TQString::null*/sc, dynamic_cast<KDockWidget*>( mtva->wrapperWidget() ),
261  m_mdiMainFrm, actionCollection(), aname.latin1() );
262  ( ( ToggleToolViewAction* ) a ) ->setCheckedState( TQString(i18n( "Hide %1" ).arg( mtva->wrappedWidget() ->caption() )) );
263  connect( a, TQ_SIGNAL( destroyed( TQObject* ) ), this, TQ_SLOT( actionDeleted( TQObject* ) ) );
264  m_toolViewActions.append( a );
265  m_toolMenu->insert( a );
266  mtva->d->action = a;
267 
268  setupActions();
269 }
270 
271 void KMDIGUIClient::actionDeleted( TQObject* a )
272 {
273  m_toolViewActions.remove( static_cast<TDEAction*>( a ) );
274  /* if (!m_toolMenu.isNull()) m_toolMenu->remove(static_cast<TDEAction*>(a));*/
275  setupActions();
276 }
277 
278 
279 void KMDIGUIClient::clientAdded( KXMLGUIClient *client )
280 {
281  if ( client == this )
282  setupActions();
283 }
284 
285 
286 void KMDIGUIClient::mdiModeHasBeenChangedTo( KMdi::MdiMode mode )
287 {
288  kdDebug( 760 ) << "KMDIGUIClient::mdiModeHasBennChangeTo" << endl;
289  m_mdiMode = mode;
290  if ( m_mdiModeAction )
291  {
292  switch ( mode )
293  {
294  case KMdi::ToplevelMode:
295  m_mdiModeAction->setCurrentItem( 0 );
296  break;
297  case KMdi::ChildframeMode:
298  m_mdiModeAction->setCurrentItem( 1 );
299  break;
300  case KMdi::TabPageMode:
301  m_mdiModeAction->setCurrentItem( 2 );
302  break;
303  case KMdi::IDEAlMode:
304  m_mdiModeAction->setCurrentItem( 3 );
305  break;
306  default:
307  Q_ASSERT( 0 );
308  }
309  }
310  setupActions();
311 
312 }
KMDIPrivate::KMDIGUIClient::addToolView
void addToolView(KMdiToolViewAccessor *)
Add a new tool view to this KMDIGUIClient.
Definition: tdemdiguiclient.cpp:245
KMDIPrivate::ToggleToolViewAction
A TDEToggleAction specifically for toggling the showing or the hiding of a KMDI tool view.
Definition: tdemdiguiclient.h:122
KMdiMainFrm
Base class for all your special main frames.
Definition: tdemdimainfrm.h:240

tdemdi

Skip menu "tdemdi"
  • Main Page
  • Namespace List
  • 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.9.1
This website is maintained by Timothy Pearson.