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

kate

kateviewspace.cpp
00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
00003    Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
00004    Copyright (C) 2001, 2005 Anders Lund <anders.lund@lund.tdcadsl.dk>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License version 2 as published by the Free Software Foundation.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "kateviewspace.h"
00022 #include "kateviewspace.moc"
00023 
00024 #include "katemainwindow.h"
00025 #include "kateviewspacecontainer.h"
00026 #include "katedocmanager.h"
00027 #include "kateapp.h"
00028 #include "katesession.h"
00029 
00030 #include <kiconloader.h>
00031 #include <tdelocale.h>
00032 #include <ksqueezedtextlabel.h>
00033 #include <tdeconfig.h>
00034 #include <kdebug.h>
00035 
00036 #include <tqwidgetstack.h>
00037 #include <tqpainter.h>
00038 #include <tqlabel.h>
00039 #include <tqcursor.h>
00040 #include <tqpopupmenu.h>
00041 #include <tqpixmap.h>
00042 
00043 //BEGIN KVSSBSep
00044 /*
00045    "KateViewSpaceStatusBarSeparator"
00046    A 2 px line to separate the statusbar from the view.
00047    It is here to compensate for the lack of a frame in the view,
00048    I think Kate looks very nice this way, as TQScrollView with frame
00049    looks slightly clumsy...
00050    Slight 3D effect. I looked for suitable TQStyle props or methods,
00051    but found none, though maybe it should use TQStyle::PM_DefaultFrameWidth
00052    for height (TRY!).
00053    It does look a bit funny with flat styles (Light, .Net) as is,
00054    but there are on methods to paint panel lines separately. And,
00055    those styles tends to look funny on their own, as a light line
00056    in a 3D frame next to a light contents widget is not functional.
00057    Also, TQStatusBar is up to now completely ignorant to style.
00058    -anders
00059 */
00060 class KVSSBSep : public TQWidget {
00061 public:
00062   KVSSBSep( KateViewSpace *parent=0) : TQWidget(parent)
00063   {
00064     setFixedHeight( 2 );
00065   }
00066 protected:
00067   void paintEvent( TQPaintEvent *e )
00068   {
00069     TQPainter p( this );
00070     p.setPen( colorGroup().shadow() );
00071     p.drawLine( e->rect().left(), 0, e->rect().right(), 0 );
00072     p.setPen( ((KateViewSpace*)parentWidget())->isActiveSpace() ? colorGroup().light() : colorGroup().midlight() );
00073     p.drawLine( e->rect().left(), 1, e->rect().right(), 1 );
00074   }
00075 };
00076 //END KVSSBSep
00077 
00078 //BEGIN KateViewSpace
00079 KateViewSpace::KateViewSpace( KateViewSpaceContainer *viewManager,
00080                               TQWidget* parent, const char* name )
00081   : TQVBox(parent, name),
00082     m_viewManager( viewManager )
00083 {
00084   mViewList.setAutoDelete(false);
00085 
00086   stack = new TQWidgetStack( this );
00087   setStretchFactor(stack, 1);
00088   stack->setFocus();
00089   //sep = new KVSSBSep( this );
00090   mStatusBar = new KateVSStatusBar(this);
00091   mIsActiveSpace = false;
00092   mViewCount = 0;
00093 
00094   setMinimumWidth (mStatusBar->minimumWidth());
00095   m_group = TQString::null;
00096 }
00097 
00098 KateViewSpace::~KateViewSpace()
00099 {
00100 }
00101 
00102 void KateViewSpace::polish()
00103 {
00104   mStatusBar->show();
00105 }
00106 
00107 void KateViewSpace::addView(Kate::View* v, bool show)
00108 {
00109   // restore the config of this view if possible
00110   if ( !m_group.isEmpty() )
00111   {
00112     TQString fn = v->getDoc()->url().prettyURL();
00113     if (!fn.isEmpty())
00114     {
00115       TQString vgroup = TQString("%1 %2").arg(m_group).arg(fn);
00116 
00117       const KateSession *as = KateSessionManager::self()->getActiveSession();
00118       TDEConfig *asCfg = as->getConfig();
00119       if (asCfg && asCfg->hasGroup(vgroup))
00120       {
00121         asCfg->setGroup(vgroup);
00122         v->readSessionConfig(asCfg);
00123       }
00124     }
00125   }
00126 
00127   uint id = mViewList.count();
00128   stack->addWidget(v, id);
00129   if (show) {
00130     mViewList.append(v);
00131     showView( v );
00132   }
00133   else {
00134     Kate::View* c = mViewList.current();
00135     mViewList.prepend( v );
00136     showView( c );
00137   }
00138 }
00139 
00140 void KateViewSpace::removeView(Kate::View* v)
00141 {
00142   disconnect( v->getDoc(), TQT_SIGNAL(modifiedChanged()),
00143               mStatusBar, TQT_SLOT(modifiedChanged()) );
00144 
00145   bool active = ( v == currentView() );
00146 
00147   mViewList.remove (v);
00148   stack->removeWidget (v);
00149 
00150   if ( ! active )
00151     return;
00152 
00153   if (currentView() != 0L)
00154     showView(mViewList.current());
00155   else if (mViewList.count() > 0)
00156     showView(mViewList.last());
00157 }
00158 
00159 bool KateViewSpace::showView(Kate::View* v)
00160 {
00161   return showView( v->getDoc()->documentNumber() );
00162 }
00163 
00164 bool KateViewSpace::showView(uint documentNumber)
00165 {
00166   TQPtrListIterator<Kate::View> it (mViewList);
00167   it.toLast();
00168   for( ; it.current(); --it ) {
00169     if (((Kate::Document*)it.current()->getDoc())->documentNumber() == documentNumber) {
00170       if ( currentView() )
00171         disconnect( currentView()->getDoc(), TQT_SIGNAL(modifiedChanged()),
00172                     mStatusBar, TQT_SLOT(modifiedChanged()) );
00173 
00174       Kate::View* kv = it.current();
00175       connect( kv->getDoc(), TQT_SIGNAL(modifiedChanged()),
00176                mStatusBar, TQT_SLOT(modifiedChanged()) );
00177 
00178       mViewList.removeRef( kv );
00179       mViewList.append( kv );
00180       stack->raiseWidget( kv );
00181       kv->show();
00182       mStatusBar->modifiedChanged();
00183       return true;
00184     }
00185   }
00186    return false;
00187 }
00188 
00189 
00190 Kate::View* KateViewSpace::currentView()
00191 {
00192   if (mViewList.count() > 0)
00193     return (Kate::View*)stack->visibleWidget();
00194 
00195   return 0L;
00196 }
00197 
00198 bool KateViewSpace::isActiveSpace()
00199 {
00200   return mIsActiveSpace;
00201 }
00202 
00203 void KateViewSpace::setActive( bool active, bool )
00204 {
00205   mIsActiveSpace = active;
00206 
00207   // change the statusbar palette and make sure it gets updated
00208   TQPalette pal( palette() );
00209   if ( ! active )
00210   {
00211     pal.setColor( TQColorGroup::Background, pal.active().mid() );
00212     pal.setColor( TQColorGroup::Light, pal.active().midlight() );
00213   }
00214 
00215   mStatusBar->setPalette( pal );
00216   mStatusBar->update();
00217   //sep->update();
00218 }
00219 
00220 bool KateViewSpace::event( TQEvent *e )
00221 {
00222   if ( e->type() == TQEvent::PaletteChange )
00223   {
00224     setActive( mIsActiveSpace );
00225     return true;
00226   }
00227   return TQVBox::event( e );
00228 }
00229 
00230 void KateViewSpace::slotStatusChanged (Kate::View *view, int r, int c, int ovr, bool block, int mod, const TQString &msg)
00231 {
00232   if ((TQWidgetStack *)view->parentWidget() != stack)
00233     return;
00234   mStatusBar->setStatus( r, c, ovr, block, mod, msg );
00235 }
00236 
00237 void KateViewSpace::saveConfig ( TDEConfig* config, int myIndex ,const TQString& viewConfGrp)
00238 {
00239 //   kdDebug()<<"KateViewSpace::saveConfig("<<myIndex<<", "<<viewConfGrp<<") - currentView: "<<currentView()<<")"<<endl;
00240   TQString group = TQString(viewConfGrp+"-ViewSpace %1").arg( myIndex );
00241 
00242   config->setGroup (group);
00243   config->writeEntry ("Count", mViewList.count());
00244 
00245   if (currentView())
00246     config->writeEntry( "Active View", currentView()->getDoc()->url().prettyURL() );
00247 
00248   // Save file list, including cursor position in this instance.
00249   TQPtrListIterator<Kate::View> it(mViewList);
00250 
00251   int idx = 0;
00252   for (; it.current(); ++it)
00253   {
00254     if ( !it.current()->getDoc()->url().isEmpty() )
00255     {
00256       long docListPos = it.current()->getDoc()->documentListPosition();
00257       config->setGroup( group );
00258       config->writeEntry( TQString("View %1").arg( (docListPos<0)?idx:docListPos ), it.current()->getDoc()->url().prettyURL() );
00259 
00260       // view config, group: "ViewSpace <n> url"
00261       TQString vgroup = TQString("%1 %2").arg(group).arg(it.current()->getDoc()->url().prettyURL());
00262       config->setGroup( vgroup );
00263       it.current()->writeSessionConfig( config );
00264     }
00265 
00266     idx++;
00267   }
00268 }
00269 
00270 void KateViewSpace::modifiedOnDisc(Kate::Document *, bool, unsigned char)
00271 {
00272   if ( currentView() )
00273     mStatusBar->updateMod( currentView()->getDoc()->isModified() );
00274 }
00275 
00276 void KateViewSpace::restoreConfig ( KateViewSpaceContainer *viewMan, TDEConfig* config, const TQString &group )
00277 {
00278   config->setGroup (group);
00279   TQString fn = config->readEntry( "Active View" );
00280 
00281   if ( !fn.isEmpty() )
00282   {
00283     Kate::Document *doc = KateDocManager::self()->findDocumentByUrl (KURL(fn));
00284 
00285     if (doc)
00286     {
00287       // view config, group: "ViewSpace <n> url"
00288       TQString vgroup = TQString("%1 %2").arg(group).arg(fn);
00289       config->setGroup( vgroup );
00290 
00291       viewMan->createView (doc);
00292 
00293       Kate::View *v = viewMan->activeView ();
00294 
00295       if (v)
00296         v->readSessionConfig( config );
00297     }
00298   }
00299 
00300   if (mViewList.isEmpty())
00301     viewMan->createView (KateDocManager::self()->document(0));
00302 
00303   m_group = group; // used for restroing view configs later
00304 }
00305 //END KateViewSpace
00306 
00307 //BEGIN KateVSStatusBar
00308 KateVSStatusBar::KateVSStatusBar ( KateViewSpace *parent, const char *name )
00309   : KStatusBar( parent, name ),
00310     m_viewSpace( parent )
00311 {
00312   m_lineColLabel = new TQLabel( this );
00313   addWidget( m_lineColLabel, 0, false );
00314   m_lineColLabel->setAlignment( Qt::AlignCenter );
00315   m_lineColLabel->installEventFilter( this );
00316 
00317   m_modifiedLabel = new TQLabel( TQString("   "), this );
00318   addWidget( m_modifiedLabel, 0, false );
00319   m_modifiedLabel->setAlignment( Qt::AlignCenter );
00320   m_modifiedLabel->installEventFilter( this );
00321 
00322   m_insertModeLabel = new TQLabel( i18n(" INS "), this );
00323   addWidget( m_insertModeLabel, 0, false );
00324   m_insertModeLabel->setAlignment( Qt::AlignCenter );
00325   m_insertModeLabel->installEventFilter( this );
00326 
00327   m_selectModeLabel = new TQLabel( i18n(" NORM "), this );
00328   addWidget( m_selectModeLabel, 0, false );
00329   m_selectModeLabel->setAlignment( Qt::AlignCenter );
00330   m_selectModeLabel->installEventFilter( this );
00331 
00332   m_fileNameLabel=new KSqueezedTextLabel( this );
00333   addWidget( m_fileNameLabel, 1, true );
00334   m_fileNameLabel->setMinimumSize( 0, 0 );
00335   m_fileNameLabel->setSizePolicy(TQSizePolicy( TQSizePolicy::Ignored, TQSizePolicy::Fixed ));
00336   m_fileNameLabel->setAlignment( /*Qt::AlignRight*/Qt::AlignLeft );
00337   m_fileNameLabel->installEventFilter( this );
00338 
00339   installEventFilter( this );
00340   m_modPm = SmallIcon("modified");
00341   m_modDiscPm = SmallIcon("modonhd");
00342   m_modmodPm = SmallIcon("modmod");
00343   m_noPm = SmallIcon("null");
00344 }
00345 
00346 KateVSStatusBar::~KateVSStatusBar ()
00347 {
00348 }
00349 
00350 void KateVSStatusBar::setStatus( int r, int c, int ovr, bool block, int, const TQString &msg )
00351 {
00352   m_lineColLabel->setText(
00353     i18n(" Line: %1 Col: %2 ").arg(TDEGlobal::locale()->formatNumber(r+1, 0))
00354                               .arg(TDEGlobal::locale()->formatNumber(c+1, 0)) );
00355 
00356   if (ovr == 0)
00357     m_insertModeLabel->setText( i18n(" R/O ") );
00358   else if (ovr == 1)
00359     m_insertModeLabel->setText( i18n(" OVR ") );
00360   else if (ovr == 2)
00361     m_insertModeLabel->setText( i18n(" INS ") );
00362 
00363 //   updateMod( mod );
00364 
00365   m_selectModeLabel->setText( block ? i18n(" BLK ") : i18n(" NORM ") );
00366 
00367   m_fileNameLabel->setText( msg );
00368 }
00369 
00370 void KateVSStatusBar::updateMod( bool mod )
00371 {
00372   Kate::View *v = m_viewSpace->currentView();
00373   if ( v )
00374   {
00375     const KateDocumentInfo *info
00376       = KateDocManager::self()->documentInfo ( v->getDoc() );
00377 
00378     bool modOnHD = info && info->modifiedOnDisc;
00379 
00380     m_modifiedLabel->setPixmap(
00381         mod ?
00382           info && modOnHD ?
00383             m_modmodPm :
00384             m_modPm :
00385           info && modOnHD ?
00386             m_modDiscPm :
00387         m_noPm
00388         );
00389   }
00390 }
00391 
00392 void KateVSStatusBar::modifiedChanged()
00393 {
00394   Kate::View *v = m_viewSpace->currentView();
00395   if ( v )
00396     updateMod( v->getDoc()->isModified() );
00397 }
00398 
00399 void KateVSStatusBar::showMenu()
00400 {
00401    TDEMainWindow* mainWindow = static_cast<TDEMainWindow*>( topLevelWidget() );
00402    TQPopupMenu* menu = static_cast<TQPopupMenu*>( mainWindow->factory()->container("viewspace_popup", mainWindow ) );
00403 
00404    if (menu)
00405      menu->exec(TQCursor::pos());
00406 }
00407 
00408 bool KateVSStatusBar::eventFilter(TQObject*,TQEvent *e)
00409 {
00410   if (e->type()==TQEvent::MouseButtonPress)
00411   {
00412     if ( m_viewSpace->currentView() )
00413       m_viewSpace->currentView()->setFocus();
00414 
00415     if ( ((TQMouseEvent*)e)->button()==Qt::RightButton)
00416       showMenu();
00417 
00418     return true;
00419   }
00420 
00421   return false;
00422 }
00423 //END KateVSStatusBar
00424 // 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
  • libkonq
  • twin
  •   lib
Generated for kate by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.