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

kmdi

  • kmdi
kmdiguiclient.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2003 Joseph Wenninger <jowenn@kde.org>
3  based on ktoolbarhandler.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 "kmdiguiclient.h"
21 #include "kmdiguiclient.moc"
22 
23 #include <tqpopupmenu.h>
24 #include <kapplication.h>
25 #include <kconfig.h>
26 #include <ktoolbar.h>
27 #include <kmainwindow.h>
28 #include <klocale.h>
29 #include <kaction.h>
30 #include <tqstring.h>
31 #include <assert.h>
32 #include <kdebug.h>
33 #include <kdockwidget.h>
34 #include <kdeversion.h>
35 #include "kmdimainfrm.h"
36 #include "kmditoolviewaccessor.h"
37 #include "kmditoolviewaccessor_p.h"
38 namespace
39 {
40 const char *actionListName = "show_kmdi_document_tool_view_actions";
41 
42 const char *guiDescription = ""
43  "<!DOCTYPE kpartgui><kpartgui name=\"KMDIViewActions\">"
44  "<MenuBar>"
45  " <Menu name=\"view\">"
46  " <ActionList name=\"%1\" />"
47  " </Menu>"
48  "</MenuBar>"
49  "</kpartgui>";
50 
51 const char *resourceFileName = "kmdiviewactions.rc";
52 
53 }
54 
55 
56 using namespace KMDIPrivate;
57 
58 
59 
60 ToggleToolViewAction::ToggleToolViewAction( const TQString& text, const KShortcut& cut, KDockWidget *dw, KMdiMainFrm *mdiMainFrm,
61  TQObject* parent, const char* name )
62  : KToggleAction( text, cut, parent, name ), m_dw( dw ), m_mdiMainFrm( mdiMainFrm )
63 {
64  if ( m_dw )
65  {
66  connect( this, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( slotToggled( bool ) ) );
67  connect( m_dw->dockManager(), TQT_SIGNAL( change() ), this, TQT_SLOT( anDWChanged() ) );
68  connect( m_dw, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotWidgetDestroyed() ) );
69  setChecked( m_dw->mayBeHide() );
70  }
71 }
72 
73 
74 ToggleToolViewAction::~ToggleToolViewAction()
75 {
76  unplugAll();
77 }
78 
79 void ToggleToolViewAction::anDWChanged()
80 {
81  if ( isChecked() && m_dw->mayBeShow() )
82  setChecked( false );
83  else if ( ( !isChecked() ) && m_dw->mayBeHide() )
84  setChecked( true );
85  else if ( isChecked() && ( m_dw->parentDockTabGroup() &&
86  ( ( ::tqqt_cast<KDockWidget*>( m_dw->parentDockTabGroup() ->
87  parent() ) ) ->mayBeShow() ) ) )
88  setChecked( false );
89 }
90 
91 
92 void ToggleToolViewAction::slotToggled( bool t )
93 {
94  // m_mw->mainDock->setDockSite( KDockWidget::DockCorner );
95 
96  if ( ( !t ) && m_dw->mayBeHide() )
97  m_dw->undock();
98  else
99  if ( t && m_dw->mayBeShow() )
100  m_mdiMainFrm->makeDockVisible( m_dw );
101 
102  // m_mw->mainDock->setDockSite( KDockWidget::DockNone );
103 }
104 
105 void ToggleToolViewAction::slotWidgetDestroyed()
106 {
107  disconnect( m_dw->dockManager(), TQT_SIGNAL( change() ), this, TQT_SLOT( anDWChanged() ) );
108  disconnect( this, TQT_SIGNAL( toggled( bool ) ), 0, 0 );
109  unplugAll();
110  deleteLater();
111 }
112 
113 
114 KMDIGUIClient::KMDIGUIClient( KMdiMainFrm* mdiMainFrm, bool showMDIModeAction, const char* name ) : TQObject( mdiMainFrm, name ),
115  KXMLGUIClient( mdiMainFrm )
116 {
117  m_mdiMode = KMdi::ChildframeMode;
118  m_mdiMainFrm = mdiMainFrm;
119  connect( mdiMainFrm->guiFactory(), TQT_SIGNAL( clientAdded( KXMLGUIClient * ) ),
120  this, TQT_SLOT( clientAdded( KXMLGUIClient * ) ) );
121 
122  /* re-use an existing resource file if it exists. can happen if the user launches the
123  * toolbar editor */
124  /*
125  setXMLFile( resourceFileName );
126  */
127 
128  if ( domDocument().documentElement().isNull() )
129  {
130 
131  TQString completeDescription = TQString::fromLatin1( guiDescription )
132  .arg( actionListName );
133 
134  setXML( completeDescription, false /*merge*/ );
135  }
136 
137  if ( actionCollection() ->kaccel() == 0 )
138  actionCollection() ->setWidget( mdiMainFrm );
139  m_toolMenu = new KActionMenu( i18n( "Tool &Views" ), actionCollection(), "kmdi_toolview_menu" );
140  if ( showMDIModeAction )
141  {
142  m_mdiModeAction = new KSelectAction( i18n( "MDI Mode" ), 0, actionCollection() );
143  TQStringList modes;
144  modes << i18n( "&Toplevel Mode" ) << i18n( "C&hildframe Mode" ) << i18n( "Ta&b Page Mode" ) << i18n( "I&DEAl Mode" );
145  m_mdiModeAction->setItems( modes );
146  connect( m_mdiModeAction, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( changeViewMode( int ) ) );
147  }
148  else
149  m_mdiModeAction = 0;
150 
151  connect( m_mdiMainFrm, TQT_SIGNAL( mdiModeHasBeenChangedTo( KMdi::MdiMode ) ),
152  this, TQT_SLOT( mdiModeHasBeenChangedTo( KMdi::MdiMode ) ) );
153 
154  m_gotoToolDockMenu = new KActionMenu( i18n( "Tool &Docks" ), actionCollection(), "kmdi_tooldock_menu" );
155  m_gotoToolDockMenu->insert( new KAction( i18n( "Switch Top Dock" ), ALT + CTRL + SHIFT + Key_T, this, TQT_SIGNAL( toggleTop() ),
156  actionCollection(), "kmdi_activate_top" ) );
157  m_gotoToolDockMenu->insert( new KAction( i18n( "Switch Left Dock" ), ALT + CTRL + SHIFT + Key_L, this, TQT_SIGNAL( toggleLeft() ),
158  actionCollection(), "kmdi_activate_left" ) );
159  m_gotoToolDockMenu->insert( new KAction( i18n( "Switch Right Dock" ), ALT + CTRL + SHIFT + Key_R, this, TQT_SIGNAL( toggleRight() ),
160  actionCollection(), "kmdi_activate_right" ) );
161  m_gotoToolDockMenu->insert( new KAction( i18n( "Switch Bottom Dock" ), ALT + CTRL + SHIFT + Key_B, this, TQT_SIGNAL( toggleBottom() ),
162  actionCollection(), "kmdi_activate_bottom" ) );
163  m_gotoToolDockMenu->insert( new KActionSeparator( actionCollection(), "kmdi_goto_menu_separator" ) );
164  m_gotoToolDockMenu->insert( new KAction( i18n( "Previous Tool View" ), ALT + CTRL + Key_Left, TQT_TQOBJECT(m_mdiMainFrm), TQT_SLOT( prevToolViewInDock() ),
165  actionCollection(), "kmdi_prev_toolview" ) );
166  m_gotoToolDockMenu->insert( new KAction( i18n( "Next Tool View" ), ALT + CTRL + Key_Right, TQT_TQOBJECT(m_mdiMainFrm), TQT_SLOT( nextToolViewInDock() ),
167  actionCollection(), "kmdi_next_toolview" ) );
168 
169  actionCollection() ->readShortcutSettings( "Shortcuts", kapp->config() );
170 }
171 
172 KMDIGUIClient::~KMDIGUIClient()
173 {
174 
175  // actionCollection()->writeShortcutSettings( "KMDI Shortcuts", kapp->config() );
176  for ( uint i = 0;i < m_toolViewActions.count();i++ )
177  disconnect( m_toolViewActions.at( i ), 0, this, 0 );
178 
179  m_toolViewActions.setAutoDelete( false );
180  m_toolViewActions.clear();
181  m_documentViewActions.setAutoDelete( false );
182  m_documentViewActions.clear();
183 }
184 
185 void KMDIGUIClient::changeViewMode( int id )
186 {
187  switch ( id )
188  {
189  case 0:
190  m_mdiMainFrm->switchToToplevelMode();
191  break;
192  case 1:
193  m_mdiMainFrm->switchToChildframeMode();
194  break;
195  case 2:
196  m_mdiMainFrm->switchToTabPageMode();
197  break;
198  case 3:
199  m_mdiMainFrm->switchToIDEAlMode();
200  break;
201  default:
202  Q_ASSERT( 0 );
203  }
204 }
205 
206 void KMDIGUIClient::setupActions()
207 {
208  if ( !factory() || !m_mdiMainFrm )
209  return ;
210 
211  // BarActionBuilder builder( actionCollection(), m_mainWindow, m_toolBars );
212 
213  // if ( !builder.needsRebuild() )
214  // return;
215 
216 
217  unplugActionList( actionListName );
218 
219  // m_actions.setAutoDelete( true );
220  // m_actions.clear();
221  // m_actions.setAutoDelete( false );
222 
223  // m_actions = builder.create();
224 
225  // m_toolBars = builder.toolBars();
226 
227  // m_toolViewActions.append(new KAction( "TESTKMDIGUICLIENT", TQString::null, 0,
228  // this, TQT_SLOT(blah()),actionCollection(),"nothing"));
229 
230  TQPtrList<KAction> addList;
231  if ( m_toolViewActions.count() < 3 )
232  for ( uint i = 0;i < m_toolViewActions.count();i++ )
233  addList.append( m_toolViewActions.at( i ) );
234  else
235  addList.append( m_toolMenu );
236  if ( m_mdiMode == KMdi::IDEAlMode )
237  addList.append( m_gotoToolDockMenu );
238  if ( m_mdiModeAction )
239  addList.append( m_mdiModeAction );
240  kdDebug( 760 ) << "KMDIGUIClient::setupActions: plugActionList" << endl;
241  plugActionList( actionListName, addList );
242 
243  // connectToActionContainers();
244 }
245 
246 void KMDIGUIClient::addToolView( KMdiToolViewAccessor* mtva )
247 {
248  kdDebug( 760 ) << "*****void KMDIGUIClient::addToolView(KMdiToolViewAccessor* mtva)*****" << endl;
249  // kdDebug()<<"name: "<<mtva->wrappedWidget()->name()<<endl;
250  TQString aname = TQString( "kmdi_toolview_" ) + mtva->wrappedWidget() ->name();
251 
252  // try to read the action shortcut
253  KShortcut sc;
254  KConfig *cfg = kapp->config();
255  TQString _grp = cfg->group();
256  cfg->setGroup( "Shortcuts" );
257  // if ( cfg->hasKey( aname ) )
258  sc = KShortcut( cfg->readEntry( aname, "" ) );
259  cfg->setGroup( _grp );
260  KAction *a = new ToggleToolViewAction( i18n( "Show %1" ).arg( mtva->wrappedWidget() ->caption() ),
261  /*TQString::null*/sc, tqt_dynamic_cast<KDockWidget*>( mtva->wrapperWidget() ),
262  m_mdiMainFrm, actionCollection(), aname.latin1() );
263 #if KDE_IS_VERSION(3,2,90)
264 
265  ( ( ToggleToolViewAction* ) a ) ->setCheckedState( TQString(i18n( "Hide %1" ).arg( mtva->wrappedWidget() ->caption() )) );
266 #endif
267 
268  connect( a, TQT_SIGNAL( destroyed( TQObject* ) ), this, TQT_SLOT( actionDeleted( TQObject* ) ) );
269  m_toolViewActions.append( a );
270  m_toolMenu->insert( a );
271  mtva->d->action = a;
272 
273  setupActions();
274 }
275 
276 void KMDIGUIClient::actionDeleted( TQObject* a )
277 {
278  m_toolViewActions.remove( static_cast<KAction*>( a ) );
279  /* if (!m_toolMenu.isNull()) m_toolMenu->remove(static_cast<KAction*>(a));*/
280  setupActions();
281 }
282 
283 
284 void KMDIGUIClient::clientAdded( KXMLGUIClient *client )
285 {
286  if ( client == this )
287  setupActions();
288 }
289 
290 
291 void KMDIGUIClient::mdiModeHasBeenChangedTo( KMdi::MdiMode mode )
292 {
293  kdDebug( 760 ) << "KMDIGUIClient::mdiModeHasBennChangeTo" << endl;
294  m_mdiMode = mode;
295  if ( m_mdiModeAction )
296  {
297  switch ( mode )
298  {
299  case KMdi::ToplevelMode:
300  m_mdiModeAction->setCurrentItem( 0 );
301  break;
302  case KMdi::ChildframeMode:
303  m_mdiModeAction->setCurrentItem( 1 );
304  break;
305  case KMdi::TabPageMode:
306  m_mdiModeAction->setCurrentItem( 2 );
307  break;
308  case KMdi::IDEAlMode:
309  m_mdiModeAction->setCurrentItem( 3 );
310  break;
311  default:
312  Q_ASSERT( 0 );
313  }
314  }
315  setupActions();
316 
317 }
318 
319 
320 // kate: space-indent off; tab-width 4; replace-tabs off; indent-mode csands;
KMdiMainFrm
Base class for all your special main frames.
Definition: kmdimainfrm.h:239
KMDIPrivate
Definition: kmdiguiclient.h:34
KMDIPrivate::ToggleToolViewAction
A KToggleAction specifically for toggling the showing or the hiding of a KMDI tool view...
Definition: kmdiguiclient.h:121
KMDIPrivate::KMDIGUIClient::addToolView
void addToolView(KMdiToolViewAccessor *)
Add a new tool view to this KMDIGUIClient.
Definition: kmdiguiclient.cpp:246

kmdi

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

kmdi

Skip menu "kmdi"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kmdi by doxygen 1.8.8
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |