• 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 <tdelocale.h>
32 #include <ksqueezedtextlabel.h>
33 #include <tdeconfig.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 ( TDEConfig* 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, including 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  long docListPos = it.current()->getDoc()->documentListPosition();
256  config->setGroup( group );
257  config->writeEntry( TQString("View %1").arg( (docListPos<0)?idx:docListPos ), it.current()->getDoc()->url().prettyURL() );
258 
259  // view config, group: "ViewSpace <n> url"
260  TQString vgroup = TQString("%1 %2").arg(group).arg(it.current()->getDoc()->url().prettyURL());
261  config->setGroup( vgroup );
262  it.current()->writeSessionConfig( config );
263  }
264 
265  idx++;
266  }
267 }
268 
269 void KateViewSpace::modifiedOnDisc(Kate::Document *, bool, unsigned char)
270 {
271  if ( currentView() )
272  mStatusBar->updateMod( currentView()->getDoc()->isModified() );
273 }
274 
275 void KateViewSpace::restoreConfig ( KateViewSpaceContainer *viewMan, TDEConfig* config, const TQString &group )
276 {
277  config->setGroup (group);
278  TQString fn = config->readEntry( "Active View" );
279 
280  if ( !fn.isEmpty() )
281  {
282  Kate::Document *doc = KateDocManager::self()->findDocumentByUrl (KURL(fn));
283 
284  if (doc)
285  {
286  // view config, group: "ViewSpace <n> url"
287  TQString vgroup = TQString("%1 %2").arg(group).arg(fn);
288  config->setGroup( vgroup );
289 
290  viewMan->createView (doc);
291 
292  Kate::View *v = viewMan->activeView ();
293 
294  if (v)
295  v->readSessionConfig( config );
296  }
297  }
298 
299  if (mViewList.isEmpty())
300  viewMan->createView (KateDocManager::self()->document(0));
301 
302  m_group = group; // used for restroing view configs later
303 }
304 //END KateViewSpace
305 
306 //BEGIN KateVSStatusBar
307 KateVSStatusBar::KateVSStatusBar ( KateViewSpace *parent, const char *name )
308  : KStatusBar( parent, name ),
309  m_viewSpace( parent )
310 {
311  m_lineColLabel = new TQLabel( this );
312  addWidget( m_lineColLabel, 0, false );
313  m_lineColLabel->setAlignment( Qt::AlignCenter );
314  m_lineColLabel->installEventFilter( this );
315 
316  m_modifiedLabel = new TQLabel( TQString(" "), this );
317  addWidget( m_modifiedLabel, 0, false );
318  m_modifiedLabel->setAlignment( Qt::AlignCenter );
319  m_modifiedLabel->installEventFilter( this );
320 
321  m_insertModeLabel = new TQLabel( i18n(" INS "), this );
322  addWidget( m_insertModeLabel, 0, false );
323  m_insertModeLabel->setAlignment( Qt::AlignCenter );
324  m_insertModeLabel->installEventFilter( this );
325 
326  m_selectModeLabel = new TQLabel( i18n(" NORM "), this );
327  addWidget( m_selectModeLabel, 0, false );
328  m_selectModeLabel->setAlignment( Qt::AlignCenter );
329  m_selectModeLabel->installEventFilter( this );
330 
331  m_fileNameLabel=new KSqueezedTextLabel( this );
332  addWidget( m_fileNameLabel, 1, true );
333  m_fileNameLabel->setMinimumSize( 0, 0 );
334  m_fileNameLabel->setSizePolicy(TQSizePolicy( TQSizePolicy::Ignored, TQSizePolicy::Fixed ));
335  m_fileNameLabel->setAlignment( /*Qt::AlignRight*/Qt::AlignLeft );
336  m_fileNameLabel->installEventFilter( this );
337 
338  installEventFilter( this );
339  m_modPm = SmallIcon("modified");
340  m_modDiscPm = SmallIcon("modonhd");
341  m_modmodPm = SmallIcon("modmod");
342  m_noPm = SmallIcon("null");
343 }
344 
345 KateVSStatusBar::~KateVSStatusBar ()
346 {
347 }
348 
349 void KateVSStatusBar::setStatus( int r, int c, int ovr, bool block, int, const TQString &msg )
350 {
351  m_lineColLabel->setText(
352  i18n(" Line: %1 Col: %2 ").arg(TDEGlobal::locale()->formatNumber(r+1, 0))
353  .arg(TDEGlobal::locale()->formatNumber(c+1, 0)) );
354 
355  if (ovr == 0)
356  m_insertModeLabel->setText( i18n(" R/O ") );
357  else if (ovr == 1)
358  m_insertModeLabel->setText( i18n(" OVR ") );
359  else if (ovr == 2)
360  m_insertModeLabel->setText( i18n(" INS ") );
361 
362 // updateMod( mod );
363 
364  m_selectModeLabel->setText( block ? i18n(" BLK ") : i18n(" NORM ") );
365 
366  m_fileNameLabel->setText( msg );
367 }
368 
369 void KateVSStatusBar::updateMod( bool mod )
370 {
371  Kate::View *v = m_viewSpace->currentView();
372  if ( v )
373  {
374  const KateDocumentInfo *info
375  = KateDocManager::self()->documentInfo ( v->getDoc() );
376 
377  bool modOnHD = info && info->modifiedOnDisc;
378 
379  m_modifiedLabel->setPixmap(
380  mod ?
381  info && modOnHD ?
382  m_modmodPm :
383  m_modPm :
384  info && modOnHD ?
385  m_modDiscPm :
386  m_noPm
387  );
388  }
389 }
390 
391 void KateVSStatusBar::modifiedChanged()
392 {
393  Kate::View *v = m_viewSpace->currentView();
394  if ( v )
395  updateMod( v->getDoc()->isModified() );
396 }
397 
398 void KateVSStatusBar::showMenu()
399 {
400  TDEMainWindow* mainWindow = static_cast<TDEMainWindow*>( topLevelWidget() );
401  TQPopupMenu* menu = static_cast<TQPopupMenu*>( mainWindow->factory()->container("viewspace_popup", mainWindow ) );
402 
403  if (menu)
404  menu->exec(TQCursor::pos());
405 }
406 
407 bool KateVSStatusBar::eventFilter(TQObject*,TQEvent *e)
408 {
409  if (e->type()==TQEvent::MouseButtonPress)
410  {
411  if ( m_viewSpace->currentView() )
412  m_viewSpace->currentView()->setFocus();
413 
414  if ( ((TQMouseEvent*)e)->button()==Qt::RightButton)
415  showMenu();
416 
417  return true;
418  }
419 
420  return false;
421 }
422 //END KateVSStatusBar

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
  • libkonq
  • twin
  •   lib
Generated for kate by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.