katefilelist.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 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 //BEGIN Includes 00022 #include "katefilelist.h" 00023 #include "katefilelist.moc" 00024 00025 #include "katedocmanager.h" 00026 #include "kateviewmanager.h" 00027 #include "katemainwindow.h" 00028 00029 #include <tqapplication.h> 00030 #include <tqpainter.h> 00031 #include <tqpopupmenu.h> 00032 #include <tqheader.h> 00033 #include <tqcolor.h> 00034 #include <tqcheckbox.h> 00035 #include <tqhbox.h> 00036 #include <tqlayout.h> 00037 #include <tqgroupbox.h> 00038 #include <tqlabel.h> 00039 #include <tqwhatsthis.h> 00040 00041 #include <kiconloader.h> 00042 #include <kconfig.h> 00043 #include <klocale.h> 00044 #include <kglobalsettings.h> 00045 #include <kpassivepopup.h> 00046 #include <kdebug.h> 00047 #include <kapplication.h> 00048 #include <kstringhandler.h> 00049 #include <kcolorbutton.h> 00050 #include <kdialog.h> 00051 //END Includes 00052 00053 //BEGIN ToolTip 00054 class ToolTip : public TQToolTip 00055 { 00056 public: 00057 ToolTip( TQWidget *parent, KateFileList *lv ) 00058 : TQToolTip( parent ), 00059 m_listView( lv ) 00060 { 00061 } 00062 virtual ~ToolTip() {}; 00063 00064 void maybeTip( const TQPoint &pos ) 00065 { 00066 TQListViewItem *i = m_listView->itemAt( pos ); 00067 if ( ! i ) return; 00068 00069 KateFileListItem *item = ((KateFileListItem*)i); 00070 if ( ! item ) return; 00071 00072 tip( m_listView->itemRect( i ), m_listView->tooltip( item, 0 ) ); 00073 00074 } 00075 00076 private: 00077 KateFileList *m_listView; 00078 }; 00079 00080 //END ToolTip 00081 00082 //BEGIN KateFileList 00083 KateFileList::KateFileList (KateMainWindow *main, 00084 KateViewManager *_viewManager, 00085 TQWidget * parent, const char * name ) 00086 : KListView (parent, name) 00087 , m_sort( KateFileList::sortByID ) 00088 { 00089 m_main = main; 00090 m_tooltip = new ToolTip( viewport(), this ); 00091 00092 // default colors 00093 m_viewShade = TQColor( 51, 204, 255 ); 00094 m_editShade = TQColor( 255, 102, 153 ); 00095 m_enableBgShading = false; 00096 00097 setFocusPolicy ( TQ_NoFocus ); 00098 00099 viewManager = _viewManager; 00100 00101 header()->hide(); 00102 addColumn("Document Name"); 00103 00104 setSelectionMode( TQListView::Single ); 00105 setSortType(KateFileList::sortByID); 00106 setShowToolTips( false ); 00107 00108 setupActions (); 00109 00110 for (uint i = 0; i < KateDocManager::self()->documents(); i++) 00111 { 00112 slotDocumentCreated (KateDocManager::self()->document(i)); 00113 slotModChanged (KateDocManager::self()->document(i)); 00114 } 00115 00116 connect(KateDocManager::self(),TQT_SIGNAL(documentCreated(Kate::Document *)), 00117 this,TQT_SLOT(slotDocumentCreated(Kate::Document *))); 00118 connect(KateDocManager::self(),TQT_SIGNAL(documentDeleted(uint)), 00119 this,TQT_SLOT(slotDocumentDeleted(uint))); 00120 00121 // don't Honour KDE single/double click setting, this files are already open, 00122 // no need for hassle of considering double-click 00123 connect(this,TQT_SIGNAL(selectionChanged(TQListViewItem *)), 00124 this,TQT_SLOT(slotActivateView(TQListViewItem *))); 00125 connect(viewManager,TQT_SIGNAL(viewChanged()), this,TQT_SLOT(slotViewChanged())); 00126 connect(this,TQT_SIGNAL(contextMenuRequested( TQListViewItem *, const TQPoint &, int )), 00127 this,TQT_SLOT(slotMenu ( TQListViewItem *, const TQPoint &, int ))); 00128 } 00129 00130 KateFileList::~KateFileList () 00131 { 00132 delete m_tooltip; 00133 } 00134 00135 void KateFileList::setupActions () 00136 { 00137 windowNext = KStdAction::back(TQT_TQOBJECT(this), TQT_SLOT(slotPrevDocument()), m_main->actionCollection()); 00138 windowPrev = KStdAction::forward(TQT_TQOBJECT(this), TQT_SLOT(slotNextDocument()), m_main->actionCollection()); 00139 sortAction = new KSelectAction( i18n("Sort &By"), 0, 00140 m_main->actionCollection(), "filelist_sortby" ); 00141 listMoveFileUp = new KAction( i18n("Move File Up"), 0, m_main->actionCollection(), "filelist_move_up" ); 00142 //listMoveFileUp->setShortcut(KShortcut(CTRL + SHIFT + Key_Comma)); 00143 listMoveFileDown = new KAction( i18n("Move File Down"), 0, m_main->actionCollection(), "filelist_move_down" ); 00144 //listMoveFileDown->setShortcut(KShortcut(CTRL + SHIFT + Key_Period)); 00145 connect( listMoveFileUp, TQT_SIGNAL(activated()), TQT_TQOBJECT(this), TQT_SLOT(moveFileUp()) ); 00146 connect( listMoveFileDown, TQT_SIGNAL(activated()), TQT_TQOBJECT(this), TQT_SLOT(moveFileDown()) ); 00147 TQStringList l; 00148 l << i18n("Opening Order") << i18n("Document Name") << i18n("URL") << i18n("Manual Placement"); 00149 sortAction->setItems( l ); 00150 connect( sortAction, TQT_SIGNAL(activated(int)), TQT_TQOBJECT(this), TQT_SLOT(setSortType(int)) ); 00151 } 00152 00153 void KateFileList::updateActions () 00154 { 00155 windowNext->setEnabled(KateDocManager::self()->documents() > 1); 00156 windowPrev->setEnabled(KateDocManager::self()->documents() > 1); 00157 } 00158 00159 void KateFileList::keyPressEvent(TQKeyEvent *e) { 00160 if ( ( e->key() == Key_Return ) || ( e->key() == Key_Enter ) ) 00161 { 00162 e->accept(); 00163 slotActivateView( currentItem() ); 00164 } 00165 else 00166 { 00167 KListView::keyPressEvent(e); 00168 } 00169 } 00170 00171 // Protect single mode selection: don't let them 00172 // leftclick outside items. 00173 // ### if we get to accept keyboard navigation, set focus before 00174 // returning 00175 void KateFileList::contentsMousePressEvent( TQMouseEvent *e ) 00176 { 00177 if ( ! itemAt( contentsToViewport( e->pos() ) ) ) 00178 return; 00179 00180 KListView::contentsMousePressEvent( e ); 00181 } 00182 00183 void KateFileList::resizeEvent( TQResizeEvent *e ) 00184 { 00185 KListView::resizeEvent( e ); 00186 00187 // ### We may want to actually calculate the widest field, 00188 // since it's not automatically scrinked. If I add support for 00189 // tree or marks, the changes of the required width will vary 00190 // a lot with opening/closing of files and display changes for 00191 // the mark branches. 00192 int w = viewport()->width(); 00193 if ( columnWidth( 0 ) < w ) 00194 setColumnWidth( 0, w ); 00195 } 00196 00197 void KateFileList::slotNextDocument() 00198 { 00199 if ( ! currentItem() || childCount() == 0 ) 00200 return; 00201 00202 // ### more checking once more item types are added 00203 00204 if ( currentItem()->nextSibling() ) 00205 viewManager->activateView( ((KateFileListItem*)currentItem()->nextSibling())->documentNumber() ); 00206 else 00207 viewManager->activateView( ((KateFileListItem *)firstChild())->documentNumber() ); 00208 } 00209 00210 void KateFileList::slotPrevDocument() 00211 { 00212 if ( ! currentItem() || childCount() == 0 ) 00213 return; 00214 00215 // ### more checking once more item types are added 00216 00217 if ( currentItem()->itemAbove() ) 00218 viewManager->activateView( ((KateFileListItem*)currentItem()->itemAbove())->documentNumber() ); 00219 else 00220 viewManager->activateView( ((KateFileListItem *)lastItem())->documentNumber() ); 00221 } 00222 00223 void KateFileList::slotDocumentCreated (Kate::Document *doc) 00224 { 00225 new KateFileListItem( this, doc/*, doc->documentNumber()*/ ); 00226 connect(doc,TQT_SIGNAL(modStateChanged(Kate::Document *)),this,TQT_SLOT(slotModChanged(Kate::Document *))); 00227 connect(doc,TQT_SIGNAL(nameChanged(Kate::Document *)),this,TQT_SLOT(slotNameChanged(Kate::Document *))); 00228 connect(doc,TQT_SIGNAL(modifiedOnDisc(Kate::Document *, bool, unsigned char)),this,TQT_SLOT(slotModifiedOnDisc(Kate::Document *, bool, unsigned char))); 00229 00230 sort(); 00231 updateActions (); 00232 } 00233 00234 void KateFileList::slotDocumentDeleted (uint documentNumber) 00235 { 00236 TQListViewItem * item = firstChild(); 00237 while( item ) { 00238 if ( ((KateFileListItem *)item)->documentNumber() == documentNumber ) 00239 { 00240 // m_viewHistory.removeRef( (KateFileListItem *)item ); 00241 // m_editHistory.removeRef( (KateFileListItem *)item ); 00242 00243 removeItem( item ); 00244 00245 break; 00246 } 00247 item = item->nextSibling(); 00248 } 00249 00250 updateActions (); 00251 } 00252 00253 void KateFileList::slotActivateView( TQListViewItem *item ) 00254 { 00255 if ( ! item || item->rtti() != RTTI_KateFileListItem ) 00256 return; 00257 00258 viewManager->activateView( ((KateFileListItem *)item)->documentNumber() ); 00259 } 00260 00261 void KateFileList::slotModChanged (Kate::Document *doc) 00262 { 00263 if (!doc) return; 00264 00265 TQListViewItem * item = firstChild(); 00266 while( item ) 00267 { 00268 if ( ((KateFileListItem *)item)->documentNumber() == doc->documentNumber() ) 00269 break; 00270 00271 item = item->nextSibling(); 00272 } 00273 00274 if ( ((KateFileListItem *)item)->document()->isModified() ) 00275 { 00276 m_editHistory.removeRef( (KateFileListItem *)item ); 00277 m_editHistory.prepend( (KateFileListItem *)item ); 00278 00279 for ( uint i=0; i < m_editHistory.count(); i++ ) 00280 { 00281 m_editHistory.at( i )->setEditHistPos( i+1 ); 00282 repaintItem( m_editHistory.at( i ) ); 00283 } 00284 } 00285 else 00286 repaintItem( item ); 00287 } 00288 00289 void KateFileList::slotModifiedOnDisc (Kate::Document *doc, bool, unsigned char) 00290 { 00291 slotModChanged( doc ); 00292 } 00293 00294 void KateFileList::slotNameChanged (Kate::Document *doc) 00295 { 00296 if (!doc) return; 00297 00298 // ### using nextSibling to *only* look at toplevel items. 00299 // child items could be marks for example 00300 TQListViewItem * item = firstChild(); 00301 while( item ) { 00302 if ( ((KateFileListItem*)item)->document() == doc ) 00303 { 00304 item->setText( 0, doc->docName() ); 00305 repaintItem( item ); 00306 break; 00307 } 00308 item = item->nextSibling(); 00309 } 00310 updateSort(); 00311 } 00312 00313 void KateFileList::slotViewChanged () 00314 { 00315 if (!viewManager->activeView()) return; 00316 00317 Kate::View *view = viewManager->activeView(); 00318 uint dn = view->getDoc()->documentNumber(); 00319 00320 TQListViewItem * i = firstChild(); 00321 while( i ) { 00322 if ( ((KateFileListItem *)i)->documentNumber() == dn ) 00323 { 00324 break; 00325 } 00326 i = i->nextSibling(); 00327 } 00328 00329 if ( ! i ) 00330 return; 00331 00332 KateFileListItem *item = (KateFileListItem*)i; 00333 setCurrentItem( item ); 00334 00335 // ### During load of file lists, all the loaded views gets active. 00336 // Do something to avoid shading them -- maybe not creating views, just 00337 // open the documents??? 00338 00339 00340 // int p = 0; 00341 // if ( m_viewHistory.count() ) 00342 // { 00343 // int p = m_viewHistory.findRef( item ); // only repaint items that needs it 00344 // } 00345 00346 m_viewHistory.removeRef( item ); 00347 m_viewHistory.prepend( item ); 00348 00349 for ( uint i=0; i < m_viewHistory.count(); i++ ) 00350 { 00351 m_viewHistory.at( i )->setViewHistPos( i+1 ); 00352 repaintItem( m_viewHistory.at( i ) ); 00353 } 00354 00355 } 00356 00357 void KateFileList::slotMenu ( TQListViewItem *item, const TQPoint &p, int /*col*/ ) 00358 { 00359 if (!item) 00360 return; 00361 00362 m_clickedMenuItem = item; 00363 if (m_clickedMenuItem->itemAbove()) { 00364 listMoveFileUp->setEnabled(true); 00365 } 00366 else { 00367 listMoveFileUp->setEnabled(false); 00368 } 00369 if (m_clickedMenuItem->itemBelow()) { 00370 listMoveFileDown->setEnabled(true); 00371 } 00372 else { 00373 listMoveFileDown->setEnabled(false); 00374 } 00375 00376 TQPopupMenu *menu = (TQPopupMenu*) ((viewManager->mainWindow())->factory()->container("filelist_popup", viewManager->mainWindow())); 00377 00378 if (menu) { 00379 menu->exec(p); 00380 } 00381 } 00382 00383 TQString KateFileList::tooltip( TQListViewItem *item, int ) 00384 { 00385 KateFileListItem *i = ((KateFileListItem*)item); 00386 if ( ! i ) return TQString::null; 00387 00388 TQString str; 00389 const KateDocumentInfo *info = KateDocManager::self()->documentInfo(i->document()); 00390 00391 if (info && info->modifiedOnDisc) 00392 { 00393 if (info->modifiedOnDiscReason == 1) 00394 str += i18n("<b>This file was changed (modified) on disk by another program.</b><br />"); 00395 else if (info->modifiedOnDiscReason == 2) 00396 str += i18n("<b>This file was changed (created) on disk by another program.</b><br />"); 00397 else if (info->modifiedOnDiscReason == 3) 00398 str += i18n("<b>This file was changed (deleted) on disk by another program.</b><br />"); 00399 } 00400 00401 str += i->document()->url().prettyURL(); 00402 return str; 00403 } 00404 00405 00406 void KateFileList::setSortType (int s) 00407 { 00408 m_sort = s; 00409 if (m_sort == KateFileList::sortManual) { 00410 setSorting( -1, true ); 00411 setDragEnabled(true); 00412 setAcceptDrops(true); 00413 } 00414 else { 00415 setSorting( 0, true ); 00416 setDragEnabled(false); 00417 setAcceptDrops(false); 00418 updateSort (); 00419 } 00420 } 00421 00422 void KateFileList::moveFileUp() 00423 { 00424 if (m_clickedMenuItem) { 00425 sortAction->setCurrentItem(KateFileList::sortManual); 00426 setSortType(KateFileList::sortManual); 00427 TQListViewItem* nitemabove = m_clickedMenuItem->itemAbove(); 00428 if (nitemabove) { 00429 nitemabove = nitemabove->itemAbove(); 00430 if (nitemabove) { 00431 m_clickedMenuItem->moveItem(nitemabove); 00432 } 00433 else { 00434 // Qt made this hard 00435 nitemabove = m_clickedMenuItem->itemAbove(); 00436 nitemabove->moveItem(m_clickedMenuItem); 00437 } 00438 } 00439 } 00440 } 00441 00442 void KateFileList::moveFileDown() 00443 { 00444 if (m_clickedMenuItem) { 00445 sortAction->setCurrentItem(KateFileList::sortManual); 00446 setSortType(KateFileList::sortManual); 00447 TQListViewItem* nitemabove = m_clickedMenuItem->itemBelow(); 00448 if (nitemabove) { 00449 m_clickedMenuItem->moveItem(nitemabove); 00450 } 00451 } 00452 } 00453 00454 void KateFileList::updateSort () 00455 { 00456 sort (); 00457 } 00458 00459 void KateFileList::readConfig( KConfig *config, const TQString &group ) 00460 { 00461 TQString oldgroup = config->group(); 00462 config->setGroup( group ); 00463 00464 setSortType( config->readNumEntry( "Sort Type", sortByID ) ); 00465 m_viewShade = config->readColorEntry( "View Shade", &m_viewShade ); 00466 m_editShade = config->readColorEntry( "Edit Shade", &m_editShade ); 00467 m_enableBgShading = config->readBoolEntry( "Shading Enabled", &m_enableBgShading ); 00468 00469 sortAction->setCurrentItem( sortType() ); 00470 00471 config->setGroup( oldgroup ); 00472 } 00473 00474 void KateFileList::writeConfig( KConfig *config, const TQString &group ) 00475 { 00476 TQString oldgroup = config->group(); 00477 config->setGroup( group ); 00478 00479 config->writeEntry( "Sort Type", m_sort ); 00480 config->writeEntry( "View Shade", m_viewShade ); 00481 config->writeEntry( "Edit Shade", m_editShade ); 00482 config->writeEntry( "Shading Enabled", m_enableBgShading ); 00483 00484 config->setGroup( oldgroup ); 00485 } 00486 00487 void KateFileList::takeItem( TQListViewItem *item ) 00488 { 00489 if ( item->rtti() == RTTI_KateFileListItem ) 00490 { 00491 m_editHistory.removeRef( (KateFileListItem*)item ); 00492 m_viewHistory.removeRef( (KateFileListItem*)item ); 00493 } 00494 TQListView::takeItem( item ); 00495 } 00496 //END KateFileList 00497 00498 //BEGIN KateFileListItem 00499 KateFileListItem::KateFileListItem( TQListView* lv, 00500 Kate::Document *_doc ) 00501 : TQListViewItem( lv, _doc->docName() ), 00502 doc( _doc ), 00503 m_viewhistpos( 0 ), 00504 m_edithistpos( 0 ), 00505 m_docNumber( _doc->documentNumber() ) 00506 { 00507 // Move this document to the end of the list where it belongs 00508 TQListViewItem* lastitem = lv->lastItem(); 00509 if (lastitem) { 00510 moveItem(lastitem); 00511 } 00512 } 00513 00514 KateFileListItem::~KateFileListItem() 00515 { 00516 } 00517 00518 const TQPixmap *KateFileListItem::pixmap ( int column ) const 00519 { 00520 if ( column == 0) { 00521 static TQPixmap noPm = SmallIcon ("null"); 00522 static TQPixmap modPm = SmallIcon("modified"); 00523 static TQPixmap discPm = SmallIcon("modonhd"); 00524 static TQPixmap modmodPm = SmallIcon("modmod"); 00525 00526 const KateDocumentInfo *info = KateDocManager::self()->documentInfo(doc); 00527 00528 if (info && info->modifiedOnDisc) 00529 return doc->isModified() ? &modmodPm : &discPm; 00530 else 00531 return doc->isModified() ? &modPm : &noPm; 00532 } 00533 00534 return 0; 00535 } 00536 00537 void KateFileListItem::paintCell( TQPainter *painter, const TQColorGroup & cg, int column, int width, int align ) 00538 { 00539 KateFileList *fl = (KateFileList*)listView(); 00540 if ( ! fl ) return; 00541 00542 if ( column == 0 ) 00543 { 00544 TQColorGroup cgNew = cg; 00545 00546 // replace the base color with a different shading if necessary... 00547 if ( fl->shadingEnabled() && m_viewhistpos > 1 ) 00548 { 00549 TQColor b( cg.base() ); 00550 00551 TQColor shade = fl->viewShade(); 00552 TQColor eshade = fl->editShade(); 00553 int hc = fl->histCount(); 00554 // If this file is in the edit history, blend in the eshade 00555 // color. The blend is weighted by the position in the editing history 00556 if ( fl->shadingEnabled() && m_edithistpos > 0 ) 00557 { 00558 int ec = fl->editHistCount(); 00559 int v = hc-m_viewhistpos; 00560 int e = ec-m_edithistpos+1; 00561 e = e*e; 00562 int n = QMAX(v + e, 1); 00563 shade.setRgb( 00564 ((shade.red()*v) + (eshade.red()*e))/n, 00565 ((shade.green()*v) + (eshade.green()*e))/n, 00566 ((shade.blue()*v) + (eshade.blue()*e))/n 00567 ); 00568 } 00569 // blend in the shade color. 00570 // max transperancy < .5, latest is most colored. 00571 float t = (0.5/hc)*(hc-m_viewhistpos+1); 00572 b.setRgb( 00573 (int)((b.red()*(1-t)) + (shade.red()*t)), 00574 (int)((b.green()*(1-t)) + (shade.green()*t)), 00575 (int)((b.blue()*(1-t)) + (shade.blue()*t)) 00576 ); 00577 00578 cgNew.setColor(TQColorGroup::Base, b); 00579 } 00580 00581 TQListViewItem::paintCell( painter, cgNew, column, width, align ); 00582 } 00583 else 00584 TQListViewItem::paintCell( painter, cg, column, width, align ); 00585 } 00586 00587 int KateFileListItem::compare ( TQListViewItem * i, int col, bool ascending ) const 00588 { 00589 if ( i->rtti() == RTTI_KateFileListItem ) 00590 { 00591 switch( ((KateFileList*)listView())->sortType() ) 00592 { 00593 case KateFileList::sortByID: 00594 { 00595 00596 int d = (int)doc->documentNumber() - ((KateFileListItem*)i)->documentNumber(); 00597 return ascending ? d : -d; 00598 break; 00599 } 00600 case KateFileList::sortByURL: 00601 return doc->url().prettyURL().compare( ((KateFileListItem*)i)->document()->url().prettyURL() ); 00602 break; 00603 default: 00604 return TQListViewItem::compare( i, col, ascending ); 00605 } 00606 } 00607 return 0; 00608 } 00609 //END KateFileListItem 00610 00611 //BEGIN KFLConfigPage 00612 KFLConfigPage::KFLConfigPage( TQWidget* parent, const char *name, KateFileList *fl ) 00613 : Kate::ConfigPage( parent, name ), 00614 m_filelist( fl ), 00615 m_changed( false ) 00616 { 00617 TQVBoxLayout *lo1 = new TQVBoxLayout( this ); 00618 int spacing = KDialog::spacingHint(); 00619 lo1->setSpacing( spacing ); 00620 00621 TQGroupBox *gb = new TQGroupBox( 1, Qt::Horizontal, i18n("Background Shading"), this ); 00622 lo1->addWidget( gb ); 00623 00624 TQWidget *g = new TQWidget( gb ); 00625 TQGridLayout *lo = new TQGridLayout( g, 2, 2 ); 00626 lo->setSpacing( KDialog::spacingHint() ); 00627 cbEnableShading = new TQCheckBox( i18n("&Enable background shading"), g ); 00628 lo->addMultiCellWidget( cbEnableShading, 1, 1, 0, 1 ); 00629 00630 kcbViewShade = new KColorButton( g ); 00631 lViewShade = new TQLabel( kcbViewShade, i18n("&Viewed documents' shade:"), g ); 00632 lo->addWidget( lViewShade, 2, 0 ); 00633 lo->addWidget( kcbViewShade, 2, 1 ); 00634 00635 kcbEditShade = new KColorButton( g ); 00636 lEditShade = new TQLabel( kcbEditShade, i18n("&Modified documents' shade:"), g ); 00637 lo->addWidget( lEditShade, 3, 0 ); 00638 lo->addWidget( kcbEditShade, 3, 1 ); 00639 00640 // sorting 00641 TQHBox *hbSorting = new TQHBox( this ); 00642 lo1->addWidget( hbSorting ); 00643 lSort = new TQLabel( i18n("&Sort by:"), hbSorting ); 00644 cmbSort = new TQComboBox( hbSorting ); 00645 lSort->setBuddy( cmbSort ); 00646 TQStringList l; 00647 l << i18n("Opening Order") << i18n("Document Name") << i18n("URL"); 00648 cmbSort->insertStringList( l ); 00649 00650 lo1->insertStretch( -1, 10 ); 00651 00652 TQWhatsThis::add( cbEnableShading, i18n( 00653 "When background shading is enabled, documents that have been viewed " 00654 "or edited within the current session will have a shaded background. " 00655 "The most recent documents have the strongest shade.") ); 00656 TQWhatsThis::add( kcbViewShade, i18n( 00657 "Set the color for shading viewed documents.") ); 00658 TQWhatsThis::add( kcbEditShade, i18n( 00659 "Set the color for modified documents. This color is blended into " 00660 "the color for viewed files. The most recently edited documents get " 00661 "most of this color.") ); 00662 00663 TQWhatsThis::add( cmbSort, i18n( 00664 "Set the sorting method for the documents.") ); 00665 00666 reload(); 00667 00668 slotEnableChanged(); 00669 connect( cbEnableShading, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotMyChanged()) ); 00670 connect( cbEnableShading, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotEnableChanged()) ); 00671 connect( kcbViewShade, TQT_SIGNAL(changed(const TQColor&)), this, TQT_SLOT(slotMyChanged()) ); 00672 connect( kcbEditShade, TQT_SIGNAL(changed(const TQColor&)), this, TQT_SLOT(slotMyChanged()) ); 00673 connect( cmbSort, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotMyChanged()) ); 00674 } 00675 00676 void KFLConfigPage::apply() 00677 { 00678 if ( ! m_changed ) 00679 return; 00680 m_changed = false; 00681 00682 // Change settings in the filelist 00683 m_filelist->m_viewShade = kcbViewShade->color(); 00684 m_filelist->m_editShade = kcbEditShade->color(); 00685 m_filelist->m_enableBgShading = cbEnableShading->isChecked(); 00686 m_filelist->setSortType( cmbSort->currentItem() ); 00687 // repaint the affected items 00688 m_filelist->triggerUpdate(); 00689 } 00690 00691 void KFLConfigPage::reload() 00692 { 00693 // read in from config file 00694 KConfig *config = kapp->config(); 00695 config->setGroup( "Filelist" ); 00696 cbEnableShading->setChecked( config->readBoolEntry("Shading Enabled", &m_filelist->m_enableBgShading ) ); 00697 kcbViewShade->setColor( config->readColorEntry("View Shade", &m_filelist->m_viewShade ) ); 00698 kcbEditShade->setColor( config->readColorEntry("Edit Shade", &m_filelist->m_editShade ) ); 00699 cmbSort->setCurrentItem( m_filelist->sortType() ); 00700 m_changed = false; 00701 } 00702 00703 void KFLConfigPage::slotEnableChanged() 00704 { 00705 kcbViewShade->setEnabled( cbEnableShading->isChecked() ); 00706 kcbEditShade->setEnabled( cbEnableShading->isChecked() ); 00707 lViewShade->setEnabled( cbEnableShading->isChecked() ); 00708 lEditShade->setEnabled( cbEnableShading->isChecked() ); 00709 } 00710 00711 void KFLConfigPage::slotMyChanged() 00712 { 00713 m_changed = true; 00714 slotChanged(); 00715 } 00716 00717 //END KFLConfigPage 00718 00719 00720 // kate: space-indent on; indent-width 2; replace-tabs on;