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

kate

  • kate
  • app
kateviewspace.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
3  Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
4  Copyright (C) 2001, 2005 Anders Lund <anders.lund@lund.tdcadsl.dk>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "kateviewspace.h"
22 #include "kateviewspace.moc"
23 
24 #include "katemainwindow.h"
25 #include "kateviewspacecontainer.h"
26 #include "katedocmanager.h"
27 #include "kateapp.h"
28 #include "katesession.h"
29 
30 #include <kiconloader.h>
31 #include <klocale.h>
32 #include <ksqueezedtextlabel.h>
33 #include <kconfig.h>
34 #include <kdebug.h>
35 
36 #include <tqwidgetstack.h>
37 #include <tqpainter.h>
38 #include <tqlabel.h>
39 #include <tqcursor.h>
40 #include <tqpopupmenu.h>
41 #include <tqpixmap.h>
42 
43 //BEGIN KVSSBSep
44 /*
45  "KateViewSpaceStatusBarSeparator"
46  A 2 px line to separate the statusbar from the view.
47  It is here to compensate for the lack of a frame in the view,
48  I think Kate looks very nice this way, as TQScrollView with frame
49  looks slightly clumsy...
50  Slight 3D effect. I looked for suitable TQStyle props or methods,
51  but found none, though maybe it should use TQStyle::PM_DefaultFrameWidth
52  for height (TRY!).
53  It does look a bit funny with flat styles (Light, .Net) as is,
54  but there are on methods to paint panel lines separately. And,
55  those styles tends to look funny on their own, as a light line
56  in a 3D frame next to a light contents widget is not functional.
57  Also, TQStatusBar is up to now completely ignorant to style.
58  -anders
59 */
60 class KVSSBSep : public TQWidget {
61 public:
62  KVSSBSep( KateViewSpace *parent=0) : TQWidget(parent)
63  {
64  setFixedHeight( 2 );
65  }
66 protected:
67  void paintEvent( TQPaintEvent *e )
68  {
69  TQPainter p( this );
70  p.setPen( colorGroup().shadow() );
71  p.drawLine( e->rect().left(), 0, e->rect().right(), 0 );
72  p.setPen( ((KateViewSpace*)parentWidget())->isActiveSpace() ? colorGroup().light() : colorGroup().midlight() );
73  p.drawLine( e->rect().left(), 1, e->rect().right(), 1 );
74  }
75 };
76 //END KVSSBSep
77 
78 //BEGIN KateViewSpace
79 KateViewSpace::KateViewSpace( KateViewSpaceContainer *viewManager,
80  TQWidget* parent, const char* name )
81  : TQVBox(parent, name),
82  m_viewManager( viewManager )
83 {
84  mViewList.setAutoDelete(false);
85 
86  stack = new TQWidgetStack( this );
87  setStretchFactor(stack, 1);
88  stack->setFocus();
89  //sep = new KVSSBSep( this );
90  mStatusBar = new KateVSStatusBar(this);
91  mIsActiveSpace = false;
92  mViewCount = 0;
93 
94  setMinimumWidth (mStatusBar->minimumWidth());
95  m_group = TQString::null;
96 }
97 
98 KateViewSpace::~KateViewSpace()
99 {
100 }
101 
102 void KateViewSpace::polish()
103 {
104  mStatusBar->show();
105 }
106 
107 void KateViewSpace::addView(Kate::View* v, bool show)
108 {
109  // restore the config of this view if possible
110  if ( !m_group.isEmpty() )
111  {
112  TQString fn = v->getDoc()->url().prettyURL();
113  if ( ! fn.isEmpty() )
114  {
115  TQString vgroup = TQString("%1 %2").arg(m_group).arg(fn);
116 
117  KateSession::Ptr as = KateSessionManager::self()->activeSession ();
118  if ( as->configRead() && as->configRead()->hasGroup( vgroup ) )
119  {
120  as->configRead()->setGroup( vgroup );
121  v->readSessionConfig ( as->configRead() );
122  }
123  }
124  }
125 
126  uint id = mViewList.count();
127  stack->addWidget(v, id);
128  if (show) {
129  mViewList.append(v);
130  showView( v );
131  }
132  else {
133  Kate::View* c = mViewList.current();
134  mViewList.prepend( v );
135  showView( c );
136  }
137 }
138 
139 void KateViewSpace::removeView(Kate::View* v)
140 {
141  disconnect( v->getDoc(), TQT_SIGNAL(modifiedChanged()),
142  mStatusBar, TQT_SLOT(modifiedChanged()) );
143 
144  bool active = ( v == currentView() );
145 
146  mViewList.remove (v);
147  stack->removeWidget (v);
148 
149  if ( ! active )
150  return;
151 
152  if (currentView() != 0L)
153  showView(mViewList.current());
154  else if (mViewList.count() > 0)
155  showView(mViewList.last());
156 }
157 
158 bool KateViewSpace::showView(Kate::View* v)
159 {
160  return showView( v->getDoc()->documentNumber() );
161 }
162 
163 bool KateViewSpace::showView(uint documentNumber)
164 {
165  TQPtrListIterator<Kate::View> it (mViewList);
166  it.toLast();
167  for( ; it.current(); --it ) {
168  if (((Kate::Document*)it.current()->getDoc())->documentNumber() == documentNumber) {
169  if ( currentView() )
170  disconnect( currentView()->getDoc(), TQT_SIGNAL(modifiedChanged()),
171  mStatusBar, TQT_SLOT(modifiedChanged()) );
172 
173  Kate::View* kv = it.current();
174  connect( kv->getDoc(), TQT_SIGNAL(modifiedChanged()),
175  mStatusBar, TQT_SLOT(modifiedChanged()) );
176 
177  mViewList.removeRef( kv );
178  mViewList.append( kv );
179  stack->raiseWidget( kv );
180  kv->show();
181  mStatusBar->modifiedChanged();
182  return true;
183  }
184  }
185  return false;
186 }
187 
188 
189 Kate::View* KateViewSpace::currentView()
190 {
191  if (mViewList.count() > 0)
192  return (Kate::View*)stack->visibleWidget();
193 
194  return 0L;
195 }
196 
197 bool KateViewSpace::isActiveSpace()
198 {
199  return mIsActiveSpace;
200 }
201 
202 void KateViewSpace::setActive( bool active, bool )
203 {
204  mIsActiveSpace = active;
205 
206  // change the statusbar palette and make sure it gets updated
207  TQPalette pal( palette() );
208  if ( ! active )
209  {
210  pal.setColor( TQColorGroup::Background, pal.active().mid() );
211  pal.setColor( TQColorGroup::Light, pal.active().midlight() );
212  }
213 
214  mStatusBar->setPalette( pal );
215  mStatusBar->update();
216  //sep->update();
217 }
218 
219 bool KateViewSpace::event( TQEvent *e )
220 {
221  if ( e->type() == TQEvent::PaletteChange )
222  {
223  setActive( mIsActiveSpace );
224  return true;
225  }
226  return TQVBox::event( e );
227 }
228 
229 void KateViewSpace::slotStatusChanged (Kate::View *view, int r, int c, int ovr, bool block, int mod, const TQString &msg)
230 {
231  if ((TQWidgetStack *)view->parentWidget() != stack)
232  return;
233  mStatusBar->setStatus( r, c, ovr, block, mod, msg );
234 }
235 
236 void KateViewSpace::saveConfig ( KConfig* config, int myIndex ,const TQString& viewConfGrp)
237 {
238 // kdDebug()<<"KateViewSpace::saveConfig("<<myIndex<<", "<<viewConfGrp<<") - currentView: "<<currentView()<<")"<<endl;
239  TQString group = TQString(viewConfGrp+"-ViewSpace %1").arg( myIndex );
240 
241  config->setGroup (group);
242  config->writeEntry ("Count", mViewList.count());
243 
244  if (currentView())
245  config->writeEntry( "Active View", currentView()->getDoc()->url().prettyURL() );
246 
247  // Save file list, includeing cursor position in this instance.
248  TQPtrListIterator<Kate::View> it(mViewList);
249 
250  int idx = 0;
251  for (; it.current(); ++it)
252  {
253  if ( !it.current()->getDoc()->url().isEmpty() )
254  {
255  config->setGroup( group );
256  config->writeEntry( TQString("View %1").arg( idx ), it.current()->getDoc()->url().prettyURL() );
257 
258  // view config, group: "ViewSpace <n> url"
259  TQString vgroup = TQString("%1 %2").arg(group).arg(it.current()->getDoc()->url().prettyURL());
260  config->setGroup( vgroup );
261  it.current()->writeSessionConfig( config );
262  }
263 
264  idx++;
265  }
266 }
267 
268 void KateViewSpace::modifiedOnDisc(Kate::Document *, bool, unsigned char)
269 {
270  if ( currentView() )
271  mStatusBar->updateMod( currentView()->getDoc()->isModified() );
272 }
273 
274 void KateViewSpace::restoreConfig ( KateViewSpaceContainer *viewMan, KConfig* config, const TQString &group )
275 {
276  config->setGroup (group);
277  TQString fn = config->readEntry( "Active View" );
278 
279  if ( !fn.isEmpty() )
280  {
281  Kate::Document *doc = KateDocManager::self()->findDocumentByUrl (KURL(fn));
282 
283  if (doc)
284  {
285  // view config, group: "ViewSpace <n> url"
286  TQString vgroup = TQString("%1 %2").arg(group).arg(fn);
287  config->setGroup( vgroup );
288 
289  viewMan->createView (doc);
290 
291  Kate::View *v = viewMan->activeView ();
292 
293  if (v)
294  v->readSessionConfig( config );
295  }
296  }
297 
298  if (mViewList.isEmpty())
299  viewMan->createView (KateDocManager::self()->document(0));
300 
301  m_group = group; // used for restroing view configs later
302 }
303 //END KateViewSpace
304 
305 //BEGIN KateVSStatusBar
306 KateVSStatusBar::KateVSStatusBar ( KateViewSpace *parent, const char *name )
307  : KStatusBar( parent, name ),
308  m_viewSpace( parent )
309 {
310  m_lineColLabel = new TQLabel( this );
311  addWidget( m_lineColLabel, 0, false );
312  m_lineColLabel->setAlignment( Qt::AlignCenter );
313  m_lineColLabel->installEventFilter( this );
314 
315  m_modifiedLabel = new TQLabel( TQString(" "), this );
316  addWidget( m_modifiedLabel, 0, false );
317  m_modifiedLabel->setAlignment( Qt::AlignCenter );
318  m_modifiedLabel->installEventFilter( this );
319 
320  m_insertModeLabel = new TQLabel( i18n(" INS "), this );
321  addWidget( m_insertModeLabel, 0, false );
322  m_insertModeLabel->setAlignment( Qt::AlignCenter );
323  m_insertModeLabel->installEventFilter( this );
324 
325  m_selectModeLabel = new TQLabel( i18n(" NORM "), this );
326  addWidget( m_selectModeLabel, 0, false );
327  m_selectModeLabel->setAlignment( Qt::AlignCenter );
328  m_selectModeLabel->installEventFilter( this );
329 
330  m_fileNameLabel=new KSqueezedTextLabel( this );
331  addWidget( m_fileNameLabel, 1, true );
332  m_fileNameLabel->setMinimumSize( 0, 0 );
333  m_fileNameLabel->setSizePolicy(TQSizePolicy( TQSizePolicy::Ignored, TQSizePolicy::Fixed ));
334  m_fileNameLabel->setAlignment( /*Qt::AlignRight*/Qt::AlignLeft );
335  m_fileNameLabel->installEventFilter( this );
336 
337  installEventFilter( this );
338  m_modPm = SmallIcon("modified");
339  m_modDiscPm = SmallIcon("modonhd");
340  m_modmodPm = SmallIcon("modmod");
341  m_noPm = SmallIcon("null");
342 }
343 
344 KateVSStatusBar::~KateVSStatusBar ()
345 {
346 }
347 
348 void KateVSStatusBar::setStatus( int r, int c, int ovr, bool block, int, const TQString &msg )
349 {
350  m_lineColLabel->setText(
351  i18n(" Line: %1 Col: %2 ").arg(KGlobal::locale()->formatNumber(r+1, 0))
352  .arg(KGlobal::locale()->formatNumber(c+1, 0)) );
353 
354  if (ovr == 0)
355  m_insertModeLabel->setText( i18n(" R/O ") );
356  else if (ovr == 1)
357  m_insertModeLabel->setText( i18n(" OVR ") );
358  else if (ovr == 2)
359  m_insertModeLabel->setText( i18n(" INS ") );
360 
361 // updateMod( mod );
362 
363  m_selectModeLabel->setText( block ? i18n(" BLK ") : i18n(" NORM ") );
364 
365  m_fileNameLabel->setText( msg );
366 }
367 
368 void KateVSStatusBar::updateMod( bool mod )
369 {
370  Kate::View *v = m_viewSpace->currentView();
371  if ( v )
372  {
373  const KateDocumentInfo *info
374  = KateDocManager::self()->documentInfo ( v->getDoc() );
375 
376  bool modOnHD = info && info->modifiedOnDisc;
377 
378  m_modifiedLabel->setPixmap(
379  mod ?
380  info && modOnHD ?
381  m_modmodPm :
382  m_modPm :
383  info && modOnHD ?
384  m_modDiscPm :
385  m_noPm
386  );
387  }
388 }
389 
390 void KateVSStatusBar::modifiedChanged()
391 {
392  Kate::View *v = m_viewSpace->currentView();
393  if ( v )
394  updateMod( v->getDoc()->isModified() );
395 }
396 
397 void KateVSStatusBar::showMenu()
398 {
399  KMainWindow* mainWindow = static_cast<KMainWindow*>( topLevelWidget() );
400  TQPopupMenu* menu = static_cast<TQPopupMenu*>( mainWindow->factory()->container("viewspace_popup", mainWindow ) );
401 
402  if (menu)
403  menu->exec(TQCursor::pos());
404 }
405 
406 bool KateVSStatusBar::eventFilter(TQObject*,TQEvent *e)
407 {
408  if (e->type()==TQEvent::MouseButtonPress)
409  {
410  if ( m_viewSpace->currentView() )
411  m_viewSpace->currentView()->setFocus();
412 
413  if ( ((TQMouseEvent*)e)->button()==Qt::RightButton)
414  showMenu();
415 
416  return true;
417  }
418 
419  return false;
420 }
421 //END KateVSStatusBar
422 // kate: space-indent on; indent-width 2; replace-tabs on;

kate

Skip menu "kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kate

Skip menu "kate"
  • kate
  • kwin
  •   lib
  • libkonq
Generated for kate by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |