• 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  const KateSession *as = KateSessionManager::self()->getActiveSession();
118  TDEConfig *asCfg = as->getConfig();
119  if (asCfg && asCfg->hasGroup(vgroup))
120  {
121  asCfg->setGroup(vgroup);
122  v->readSessionConfig(asCfg);
123  }
124  }
125  }
126 
127  uint id = mViewList.count();
128  stack->addWidget(v, id);
129  if (show) {
130  mViewList.append(v);
131  showView( v );
132  }
133  else {
134  Kate::View* c = mViewList.current();
135  mViewList.prepend( v );
136  showView( c );
137  }
138 }
139 
140 void KateViewSpace::removeView(Kate::View* v)
141 {
142  disconnect( v->getDoc(), TQ_SIGNAL(modifiedChanged()),
143  mStatusBar, TQ_SLOT(modifiedChanged()) );
144 
145  bool active = ( v == currentView() );
146 
147  mViewList.remove (v);
148  stack->removeWidget (v);
149 
150  if ( ! active )
151  return;
152 
153  if (currentView() != 0L)
154  showView(mViewList.current());
155  else if (mViewList.count() > 0)
156  showView(mViewList.last());
157 }
158 
159 bool KateViewSpace::showView(Kate::View* v)
160 {
161  return showView( v->getDoc()->documentNumber() );
162 }
163 
164 bool KateViewSpace::showView(uint documentNumber)
165 {
166  TQPtrListIterator<Kate::View> it (mViewList);
167  it.toLast();
168  for( ; it.current(); --it ) {
169  if (((Kate::Document*)it.current()->getDoc())->documentNumber() == documentNumber) {
170  if ( currentView() )
171  disconnect( currentView()->getDoc(), TQ_SIGNAL(modifiedChanged()),
172  mStatusBar, TQ_SLOT(modifiedChanged()) );
173 
174  Kate::View* kv = it.current();
175  connect( kv->getDoc(), TQ_SIGNAL(modifiedChanged()),
176  mStatusBar, TQ_SLOT(modifiedChanged()) );
177 
178  mViewList.removeRef( kv );
179  mViewList.append( kv );
180  stack->raiseWidget( kv );
181  kv->show();
182  mStatusBar->modifiedChanged();
183  return true;
184  }
185  }
186  return false;
187 }
188 
189 
190 Kate::View* KateViewSpace::currentView()
191 {
192  if (mViewList.count() > 0)
193  return (Kate::View*)stack->visibleWidget();
194 
195  return 0L;
196 }
197 
198 bool KateViewSpace::isActiveSpace()
199 {
200  return mIsActiveSpace;
201 }
202 
203 void KateViewSpace::setActive( bool active, bool )
204 {
205  mIsActiveSpace = active;
206 
207  // change the statusbar palette and make sure it gets updated
208  TQPalette pal( palette() );
209  if ( ! active )
210  {
211  pal.setColor( TQColorGroup::Background, pal.active().mid() );
212  pal.setColor( TQColorGroup::Light, pal.active().midlight() );
213  }
214 
215  mStatusBar->setPalette( pal );
216  mStatusBar->update();
217  //sep->update();
218 }
219 
220 bool KateViewSpace::event( TQEvent *e )
221 {
222  if ( e->type() == TQEvent::PaletteChange )
223  {
224  setActive( mIsActiveSpace );
225  return true;
226  }
227  return TQVBox::event( e );
228 }
229 
230 void KateViewSpace::slotStatusChanged (Kate::View *view, int r, int c, int ovr, bool block, int mod, const TQString &msg)
231 {
232  if ((TQWidgetStack *)view->parentWidget() != stack)
233  return;
234  mStatusBar->setStatus( r, c, ovr, block, mod, msg );
235 }
236 
237 void KateViewSpace::saveConfig ( TDEConfig* config, int myIndex ,const TQString& viewConfGrp)
238 {
239 // kdDebug()<<"KateViewSpace::saveConfig("<<myIndex<<", "<<viewConfGrp<<") - currentView: "<<currentView()<<")"<<endl;
240  TQString group = TQString(viewConfGrp+"-ViewSpace %1").arg( myIndex );
241 
242  config->setGroup (group);
243  config->writeEntry ("Count", mViewList.count());
244 
245  if (currentView())
246  config->writeEntry( "Active View", currentView()->getDoc()->url().prettyURL() );
247 
248  // Save file list, including cursor position in this instance.
249  TQPtrListIterator<Kate::View> it(mViewList);
250 
251  int idx = 0;
252  for (; it.current(); ++it)
253  {
254  if ( !it.current()->getDoc()->url().isEmpty() )
255  {
256  long docListPos = it.current()->getDoc()->documentListPosition();
257  config->setGroup( group );
258  config->writeEntry( TQString("View %1").arg( (docListPos<0)?idx:docListPos ), it.current()->getDoc()->url().prettyURL() );
259 
260  // view config, group: "ViewSpace <n> url"
261  TQString vgroup = TQString("%1 %2").arg(group).arg(it.current()->getDoc()->url().prettyURL());
262  config->setGroup( vgroup );
263  it.current()->writeSessionConfig( config );
264  }
265 
266  idx++;
267  }
268 }
269 
270 void KateViewSpace::modifiedOnDisc(Kate::Document *, bool, unsigned char)
271 {
272  if ( currentView() )
273  mStatusBar->updateMod( currentView()->getDoc()->isModified() );
274 }
275 
276 void KateViewSpace::restoreConfig ( KateViewSpaceContainer *viewMan, TDEConfig* config, const TQString &group )
277 {
278  config->setGroup (group);
279  TQString fn = config->readEntry( "Active View" );
280 
281  if ( !fn.isEmpty() )
282  {
283  Kate::Document *doc = KateDocManager::self()->findDocumentByUrl (KURL(fn));
284 
285  if (doc)
286  {
287  // view config, group: "ViewSpace <n> url"
288  TQString vgroup = TQString("%1 %2").arg(group).arg(fn);
289  config->setGroup( vgroup );
290 
291  viewMan->createView (doc);
292 
293  Kate::View *v = viewMan->activeView ();
294 
295  if (v)
296  v->readSessionConfig( config );
297  }
298  }
299 
300  if (mViewList.isEmpty())
301  viewMan->createView (KateDocManager::self()->document(0));
302 
303  m_group = group; // used for restroing view configs later
304 }
305 //END KateViewSpace
306 
307 //BEGIN KateVSStatusBar
308 KateVSStatusBar::KateVSStatusBar ( KateViewSpace *parent, const char *name )
309  : KStatusBar( parent, name ),
310  m_viewSpace( parent )
311 {
312  m_lineColLabel = new TQLabel( this );
313  addWidget( m_lineColLabel, 0, false );
314  m_lineColLabel->setAlignment( TQt::AlignCenter );
315  m_lineColLabel->installEventFilter( this );
316 
317  m_modifiedLabel = new TQLabel( TQString(" "), this );
318  addWidget( m_modifiedLabel, 0, false );
319  m_modifiedLabel->setAlignment( TQt::AlignCenter );
320  m_modifiedLabel->installEventFilter( this );
321 
322  m_insertModeLabel = new TQLabel( i18n(" INS "), this );
323  addWidget( m_insertModeLabel, 0, false );
324  m_insertModeLabel->setAlignment( TQt::AlignCenter );
325  m_insertModeLabel->installEventFilter( this );
326 
327  m_selectModeLabel = new TQLabel( i18n(" NORM "), this );
328  addWidget( m_selectModeLabel, 0, false );
329  m_selectModeLabel->setAlignment( TQt::AlignCenter );
330  m_selectModeLabel->installEventFilter( this );
331 
332  m_fileNameLabel=new KSqueezedTextLabel( this );
333  addWidget( m_fileNameLabel, 1, true );
334  m_fileNameLabel->setMinimumSize( 0, 0 );
335  m_fileNameLabel->setSizePolicy(TQSizePolicy( TQSizePolicy::Ignored, TQSizePolicy::Fixed ));
336  m_fileNameLabel->setAlignment( /*TQt::AlignRight*/TQt::AlignLeft );
337  m_fileNameLabel->installEventFilter( this );
338 
339  installEventFilter( this );
340  m_modPm = SmallIcon("modified");
341  m_modDiscPm = SmallIcon("modonhd");
342  m_modmodPm = SmallIcon("modmod");
343  m_noPm = SmallIcon("null");
344 }
345 
346 KateVSStatusBar::~KateVSStatusBar ()
347 {
348 }
349 
350 void KateVSStatusBar::setStatus( int r, int c, int ovr, bool block, int, const TQString &msg )
351 {
352  m_lineColLabel->setText(
353  i18n(" Line: %1 Col: %2 ").arg(TDEGlobal::locale()->formatNumber(r+1, 0))
354  .arg(TDEGlobal::locale()->formatNumber(c+1, 0)) );
355 
356  if (ovr == 0)
357  m_insertModeLabel->setText( i18n(" R/O ") );
358  else if (ovr == 1)
359  m_insertModeLabel->setText( i18n(" OVR ") );
360  else if (ovr == 2)
361  m_insertModeLabel->setText( i18n(" INS ") );
362 
363 // updateMod( mod );
364 
365  m_selectModeLabel->setText( block ? i18n(" BLK ") : i18n(" NORM ") );
366 
367  m_fileNameLabel->setText( msg );
368 }
369 
370 void KateVSStatusBar::updateMod( bool mod )
371 {
372  Kate::View *v = m_viewSpace->currentView();
373  if ( v )
374  {
375  const KateDocumentInfo *info
376  = KateDocManager::self()->documentInfo ( v->getDoc() );
377 
378  bool modOnHD = info && info->modifiedOnDisc;
379 
380  m_modifiedLabel->setPixmap(
381  mod ?
382  info && modOnHD ?
383  m_modmodPm :
384  m_modPm :
385  info && modOnHD ?
386  m_modDiscPm :
387  m_noPm
388  );
389  }
390 }
391 
392 void KateVSStatusBar::modifiedChanged()
393 {
394  Kate::View *v = m_viewSpace->currentView();
395  if ( v )
396  updateMod( v->getDoc()->isModified() );
397 }
398 
399 void KateVSStatusBar::showMenu()
400 {
401  TDEMainWindow* mainWindow = static_cast<TDEMainWindow*>( topLevelWidget() );
402  TQPopupMenu* menu = static_cast<TQPopupMenu*>( mainWindow->factory()->container("viewspace_popup", mainWindow ) );
403 
404  if (menu)
405  menu->exec(TQCursor::pos());
406 }
407 
408 bool KateVSStatusBar::eventFilter(TQObject*,TQEvent *e)
409 {
410  if (e->type()==TQEvent::MouseButtonPress)
411  {
412  if ( m_viewSpace->currentView() )
413  m_viewSpace->currentView()->setFocus();
414 
415  if ( ((TQMouseEvent*)e)->button()==TQt::RightButton)
416  showMenu();
417 
418  return true;
419  }
420 
421  return false;
422 }
423 //END KateVSStatusBar
KateSessionManager::self
static KateSessionManager * self()
get a pointer to the unique KateSessionManager instance.
Definition: katesession.cpp:321
KateSessionManager::getActiveSession
KateSession * getActiveSession()
Definition: katesession.h:269
KateSession
An object representing a Kate's session.
Definition: katesession.h:48

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.9.1
This website is maintained by Timothy Pearson.