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

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