00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00029 #include <kiconloader.h>
00030 #include <klocale.h>
00031 #include <ksqueezedtextlabel.h>
00032 #include <kconfig.h>
00033 #include <kdebug.h>
00034
00035 #include <qwidgetstack.h>
00036 #include <qpainter.h>
00037 #include <qlabel.h>
00038 #include <qcursor.h>
00039 #include <qpopupmenu.h>
00040 #include <qpixmap.h>
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 class KVSSBSep : public QWidget {
00060 public:
00061 KVSSBSep( KateViewSpace *parent=0) : QWidget(parent)
00062 {
00063 setFixedHeight( 2 );
00064 }
00065 protected:
00066 void paintEvent( QPaintEvent *e )
00067 {
00068 QPainter p( this );
00069 p.setPen( colorGroup().shadow() );
00070 p.drawLine( e->rect().left(), 0, e->rect().right(), 0 );
00071 p.setPen( ((KateViewSpace*)parentWidget())->isActiveSpace() ? colorGroup().light() : colorGroup().midlight() );
00072 p.drawLine( e->rect().left(), 1, e->rect().right(), 1 );
00073 }
00074 };
00075
00076
00077
00078 KateViewSpace::KateViewSpace( KateViewSpaceContainer *viewManager,
00079 QWidget* parent, const char* name )
00080 : QVBox(parent, name),
00081 m_viewManager( viewManager )
00082 {
00083 mViewList.setAutoDelete(false);
00084
00085 stack = new QWidgetStack( this );
00086 setStretchFactor(stack, 1);
00087 stack->setFocus();
00088 sep = new KVSSBSep( this );
00089 mStatusBar = new KateVSStatusBar(this);
00090 mIsActiveSpace = false;
00091 mViewCount = 0;
00092
00093 setMinimumWidth (mStatusBar->minimumWidth());
00094 m_group = QString::null;
00095 }
00096
00097 KateViewSpace::~KateViewSpace()
00098 {
00099 }
00100
00101 void KateViewSpace::polish()
00102 {
00103 mStatusBar->show();
00104 }
00105
00106 void KateViewSpace::addView(Kate::View* v, bool show)
00107 {
00108
00109 if ( !m_group.isEmpty() )
00110 {
00111 QString fn = v->getDoc()->url().prettyURL();
00112 if ( ! fn.isEmpty() )
00113 {
00114 QString vgroup = QString("%1 %2").arg(m_group).arg(fn);
00115 if ( KateApp::kateSessionConfig()->hasGroup( vgroup ) )
00116 {
00117 KateApp::kateSessionConfig()->setGroup( vgroup );
00118 v->readSessionConfig( KateApp::kateSessionConfig() );
00119 }
00120
00121 }
00122 }
00123
00124 uint id = mViewList.count();
00125 stack->addWidget(v, id);
00126 if (show) {
00127 mViewList.append(v);
00128 showView( v );
00129 }
00130 else {
00131 Kate::View* c = mViewList.current();
00132 mViewList.prepend( v );
00133 showView( c );
00134 }
00135 }
00136
00137 void KateViewSpace::removeView(Kate::View* v)
00138 {
00139 disconnect( v->getDoc(), SIGNAL(modifiedChanged()),
00140 mStatusBar, SLOT(modifiedChanged()) );
00141
00142 bool active = ( v == currentView() );
00143
00144 mViewList.remove (v);
00145 stack->removeWidget (v);
00146
00147 if ( ! active )
00148 return;
00149
00150 if (currentView() != 0L)
00151 showView(mViewList.current());
00152 else if (mViewList.count() > 0)
00153 showView(mViewList.last());
00154 }
00155
00156 bool KateViewSpace::showView(Kate::View* v)
00157 {
00158 return showView( v->getDoc()->documentNumber() );
00159 }
00160
00161 bool KateViewSpace::showView(uint documentNumber)
00162 {
00163 QPtrListIterator<Kate::View> it (mViewList);
00164 it.toLast();
00165 for( ; it.current(); --it ) {
00166 if (((Kate::Document*)it.current()->getDoc())->documentNumber() == documentNumber) {
00167 if ( currentView() )
00168 disconnect( currentView()->getDoc(), SIGNAL(modifiedChanged()),
00169 mStatusBar, SLOT(modifiedChanged()) );
00170
00171 Kate::View* kv = it.current();
00172 connect( kv->getDoc(), SIGNAL(modifiedChanged()),
00173 mStatusBar, SLOT(modifiedChanged()) );
00174
00175 mViewList.removeRef( kv );
00176 mViewList.append( kv );
00177 stack->raiseWidget( kv );
00178 kv->show();
00179 mStatusBar->modifiedChanged();
00180 return true;
00181 }
00182 }
00183 return false;
00184 }
00185
00186
00187 Kate::View* KateViewSpace::currentView()
00188 {
00189 if (mViewList.count() > 0)
00190 return (Kate::View*)stack->visibleWidget();
00191
00192 return 0L;
00193 }
00194
00195 bool KateViewSpace::isActiveSpace()
00196 {
00197 return mIsActiveSpace;
00198 }
00199
00200 void KateViewSpace::setActive( bool active, bool )
00201 {
00202 mIsActiveSpace = active;
00203
00204
00205 QPalette pal( palette() );
00206 if ( ! active )
00207 {
00208 pal.setColor( QColorGroup::Background, pal.active().mid() );
00209 pal.setColor( QColorGroup::Light, pal.active().midlight() );
00210 }
00211
00212 mStatusBar->setPalette( pal );
00213 mStatusBar->update();
00214 sep->update();
00215 }
00216
00217 bool KateViewSpace::event( QEvent *e )
00218 {
00219 if ( e->type() == QEvent::PaletteChange )
00220 {
00221 setActive( mIsActiveSpace );
00222 return true;
00223 }
00224 return QVBox::event( e );
00225 }
00226
00227 void KateViewSpace::slotStatusChanged (Kate::View *view, int r, int c, int ovr, bool block, int mod, const QString &msg)
00228 {
00229 if ((QWidgetStack *)view->parentWidget() != stack)
00230 return;
00231 mStatusBar->setStatus( r, c, ovr, block, mod, msg );
00232 }
00233
00234 void KateViewSpace::saveConfig ( KConfig* config, int myIndex ,const QString& viewConfGrp)
00235 {
00236
00237 QString group = QString(viewConfGrp+"-ViewSpace %1").arg( myIndex );
00238
00239 config->setGroup (group);
00240 config->writeEntry ("Count", mViewList.count());
00241
00242 if (currentView())
00243 config->writeEntry( "Active View", currentView()->getDoc()->url().prettyURL() );
00244
00245
00246 QPtrListIterator<Kate::View> it(mViewList);
00247
00248 int idx = 0;
00249 for (; it.current(); ++it)
00250 {
00251 if ( !it.current()->getDoc()->url().isEmpty() )
00252 {
00253 config->setGroup( group );
00254 config->writeEntry( QString("View %1").arg( idx ), it.current()->getDoc()->url().prettyURL() );
00255
00256
00257 QString vgroup = QString("%1 %2").arg(group).arg(it.current()->getDoc()->url().prettyURL());
00258 config->setGroup( vgroup );
00259 it.current()->writeSessionConfig( config );
00260 }
00261
00262 idx++;
00263 }
00264 }
00265
00266 void KateViewSpace::modifiedOnDisc(Kate::Document *, bool, unsigned char)
00267 {
00268 if ( currentView() )
00269 mStatusBar->updateMod( currentView()->getDoc()->isModified() );
00270 }
00271
00272 void KateViewSpace::restoreConfig ( KateViewSpaceContainer *viewMan, KConfig* config, const QString &group )
00273 {
00274 config->setGroup (group);
00275 QString fn = config->readEntry( "Active View" );
00276
00277 if ( !fn.isEmpty() )
00278 {
00279 Kate::Document *doc = KateDocManager::self()->findDocumentByUrl (KURL(fn));
00280
00281 if (doc)
00282 {
00283
00284 QString vgroup = QString("%1 %2").arg(group).arg(fn);
00285 config->setGroup( vgroup );
00286
00287 viewMan->createView (doc);
00288
00289 Kate::View *v = viewMan->activeView ();
00290
00291 if (v)
00292 v->readSessionConfig( config );
00293 }
00294 }
00295
00296 if (mViewList.isEmpty())
00297 viewMan->createView (KateDocManager::self()->document(0));
00298
00299 m_group = group;
00300 }
00301
00302
00303
00304 KateVSStatusBar::KateVSStatusBar ( KateViewSpace *parent, const char *name )
00305 : KStatusBar( parent, name ),
00306 m_viewSpace( parent )
00307 {
00308 m_lineColLabel = new QLabel( this );
00309 addWidget( m_lineColLabel, 0, false );
00310 m_lineColLabel->setAlignment( Qt::AlignCenter );
00311 m_lineColLabel->installEventFilter( this );
00312
00313 m_modifiedLabel = new QLabel( QString(" "), this );
00314 addWidget( m_modifiedLabel, 0, false );
00315 m_modifiedLabel->setAlignment( Qt::AlignCenter );
00316 m_modifiedLabel->installEventFilter( this );
00317
00318 m_insertModeLabel = new QLabel( i18n(" INS "), this );
00319 addWidget( m_insertModeLabel, 0, false );
00320 m_insertModeLabel->setAlignment( Qt::AlignCenter );
00321 m_insertModeLabel->installEventFilter( this );
00322
00323 m_selectModeLabel = new QLabel( i18n(" NORM "), this );
00324 addWidget( m_selectModeLabel, 0, false );
00325 m_selectModeLabel->setAlignment( Qt::AlignCenter );
00326 m_selectModeLabel->installEventFilter( this );
00327
00328 m_fileNameLabel=new KSqueezedTextLabel( this );
00329 addWidget( m_fileNameLabel, 1, true );
00330 m_fileNameLabel->setMinimumSize( 0, 0 );
00331 m_fileNameLabel->setSizePolicy(QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed ));
00332 m_fileNameLabel->setAlignment( Qt::AlignLeft );
00333 m_fileNameLabel->installEventFilter( this );
00334
00335 installEventFilter( this );
00336 m_modPm = SmallIcon("modified");
00337 m_modDiscPm = SmallIcon("modonhd");
00338 m_modmodPm = SmallIcon("modmod");
00339 m_noPm = SmallIcon("null");
00340 }
00341
00342 KateVSStatusBar::~KateVSStatusBar ()
00343 {
00344 }
00345
00346 void KateVSStatusBar::setStatus( int r, int c, int ovr, bool block, int mod, const QString &msg )
00347 {
00348 m_lineColLabel->setText(
00349 i18n(" Line: %1 Col: %2 ").arg(KGlobal::locale()->formatNumber(r+1, 0))
00350 .arg(KGlobal::locale()->formatNumber(c+1, 0)) );
00351
00352 if (ovr == 0)
00353 m_insertModeLabel->setText( i18n(" R/O ") );
00354 else if (ovr == 1)
00355 m_insertModeLabel->setText( i18n(" OVR ") );
00356 else if (ovr == 2)
00357 m_insertModeLabel->setText( i18n(" INS ") );
00358
00359
00360
00361 m_selectModeLabel->setText( block ? i18n(" BLK ") : i18n(" NORM ") );
00362
00363 m_fileNameLabel->setText( msg );
00364 }
00365
00366 void KateVSStatusBar::updateMod( bool mod )
00367 {
00368 Kate::View *v = m_viewSpace->currentView();
00369 if ( v )
00370 {
00371 const KateDocumentInfo *info
00372 = KateDocManager::self()->documentInfo ( v->getDoc() );
00373
00374 m_modifiedLabel->setPixmap(
00375 mod ?
00376 info && info->modifiedOnDisc ?
00377 m_modmodPm :
00378 m_modPm :
00379 info && info->modifiedOnDisc ?
00380 m_modDiscPm :
00381 m_noPm
00382 );
00383 }
00384 }
00385
00386 void KateVSStatusBar::modifiedChanged()
00387 {
00388 Kate::View *v = m_viewSpace->currentView();
00389 if ( v )
00390 updateMod( v->getDoc()->isModified() );
00391 }
00392
00393 void KateVSStatusBar::showMenu()
00394 {
00395 KMainWindow* mainWindow = static_cast<KMainWindow*>( topLevelWidget() );
00396 QPopupMenu* menu = static_cast<QPopupMenu*>( mainWindow->factory()->container("viewspace_popup", mainWindow ) );
00397
00398 if (menu)
00399 menu->exec(QCursor::pos());
00400 }
00401
00402 bool KateVSStatusBar::eventFilter(QObject*,QEvent *e)
00403 {
00404 if (e->type()==QEvent::MouseButtonPress)
00405 {
00406 if ( m_viewSpace->currentView() )
00407 m_viewSpace->currentView()->setFocus();
00408
00409 if ( ((QMouseEvent*)e)->button()==RightButton)
00410 showMenu();
00411
00412 return true;
00413 }
00414
00415 return false;
00416 }
00417
00418