📄 krbriefview.cpp
字号:
// are we using krusader's classic quicksearch, or wincmd style? { KConfigGroupSaver grpSvr( _config, "Look&Feel" ); if ( !_config->readBoolEntry( "New Style Quicksearch", _NewStyleQuicksearch ) ) KIconView::keyPressEvent( e ); else { // first, show the quicksearch if its hidden if ( ACTIVE_PANEL->quickSearch->isHidden() ) { ACTIVE_PANEL->quickSearch->show(); // hack: if the pressed key requires a scroll down, the selected // item is "below" the quick search window, as the icon view will // realize its new size after the key processing. The following line // will resize the icon view immediately. ACTIVE_PANEL->layout->activate(); // second, we need to disable the dirup action - hack! krDirUp->setEnabled( false ); } // now, send the key to the quicksearch ACTIVE_PANEL->quickSearch->myKeyPressEvent( e ); } } //} else // e->ignore(); // send to panel } else { if ( ACTIVE_PANEL->quickSearch->isShown() ) { ACTIVE_PANEL->quickSearch->hide(); ACTIVE_PANEL->quickSearch->clear(); krDirUp->setEnabled( true ); } KIconView::keyPressEvent( e ); } } // emit the new item description slotItemDescription( currentItem() ); // actually send the QIconViewItem}// overridden to make sure EXTENTION won't be lost during renamevoid KrBriefView::rename( QIconViewItem * item ) { currentlyRenamedItem = dynamic_cast< KrBriefViewItem * >( item ); currentlyRenamedItem->rename(); //TODO: renameLineEdit() ->selectAll();}void KrBriefView::renameCurrentItem() { QString newName, fileName; // handle inplace renaming, if possible KrBriefViewItem *it = static_cast<KrBriefViewItem*>(getCurrentKrViewItem()); if ( it ) fileName = it->name(); else return ; // quit if no current item available // don't allow anyone to rename .. if ( fileName == ".." ) return ; rename( static_cast<QIconViewItem*>( it ) ); // if applicable, select only the name without extension/* TODO: KConfigGroupSaver svr(krConfig,"Look&Feel"); if (!krConfig->readBoolEntry("Rename Selects Extension", true)) { if (it->hasExtension() && !it->VF->vfile_isDir() ) renameLineEdit()->setSelection(0, it->name().findRev(it->extension())-1); }*/}void KrBriefView::inplaceRenameFinished( QIconViewItem * it ) { if ( !it ) { // major failure - call developers krOut << "Major failure at inplaceRenameFinished(): item is null" << endl; return; } KrBriefViewItem *item = dynamic_cast<KrBriefViewItem *>( it ); if( item->text() != item->name() ) op()->emitRenameItem( item->name(), item->text() ); currentlyRenamedItem = 0; setFocus();}// TODO: move the whole quicksearch mess out of here and into krviewvoid KrBriefView::quickSearch( const QString & str, int direction ) { KrViewItem * item = getCurrentKrViewItem(); if (!item) return; KConfigGroupSaver grpSvr( _config, "Look&Feel" ); bool caseSensitive = _config->readBoolEntry( "Case Sensitive Quicksearch", _CaseSensitiveQuicksearch ); if ( !direction ) { if ( caseSensitive ? item->name().startsWith( str ) : item->name().lower().startsWith( str.lower() ) ) return ; direction = 1; } KrViewItem * startItem = item; while ( true ) { item = ( direction > 0 ) ? getNext( item ) : getPrev( item ); if ( !item ) item = ( direction > 0 ) ? getFirst() : getLast(); if ( item == startItem ) return ; if ( caseSensitive ? item->name().startsWith( str ) : item->name().lower().startsWith( str.lower() ) ) { setCurrentItem( item->name() ); makeItemVisible( item ); return ; } }}void KrBriefView::stopQuickSearch( QKeyEvent * e ) { if( ACTIVE_PANEL && ACTIVE_PANEL->quickSearch ) { ACTIVE_PANEL->quickSearch->hide(); ACTIVE_PANEL->quickSearch->clear(); krDirUp->setEnabled( true ); if ( e ) keyPressEvent( e ); }}void KrBriefView::setNameToMakeCurrent( QIconViewItem * it ) { if (!it) return; KrView::setNameToMakeCurrent( static_cast<KrBriefViewItem*>( it ) ->name() );}void KrBriefView::slotMouseClicked( int button, QIconViewItem * item, const QPoint& ) { pressedItem = 0; // if the signals are emitted, don't emit twice at contentsMouseReleaseEvent if ( button == Qt::MidButton ) emit middleButtonClicked( dynamic_cast<KrViewItem *>( item ) );}void KrBriefView::refreshColors() { krConfig->setGroup("Colors"); bool kdeDefault = krConfig->readBoolEntry("KDE Default"); if ( !kdeDefault ) { // KDE default is not choosen: set the background color (as this paints the empty areas) and the alternate color bool isActive = hasFocus(); if ( MAIN_VIEW && ACTIVE_PANEL && ACTIVE_PANEL->view ) isActive = ( static_cast<KrView *>( this ) == ACTIVE_PANEL->view ); QColorGroup cg; KrColorCache::getColorCache().getColors(cg, KrColorItemType(KrColorItemType::File, false, isActive, false, false)); setPaletteBackgroundColor( cg.background() ); } else { // KDE default is choosen: set back the background color setPaletteBackgroundColor( KGlobalSettings::baseColor() ); } slotUpdate();}bool KrBriefView::event( QEvent *e ) { modifierPressed = false; switch ( e->type() ) { case QEvent::Timer: case QEvent::MouseMove: case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: break; default: CANCEL_TWO_CLICK_RENAME; } if( e->type() == QEvent::Wheel ) { if ( !_focused ) op()->emitNeedFocus(); setFocus(); } return KIconView::event( e );}bool KrBriefView::eventFilter( QObject * watched, QEvent * e ){ if( watched == horizontalScrollBar() ) { if( e->type() == QEvent::Hide || e->type() == QEvent::Show ) { bool res = KIconView::eventFilter( watched, e ); arrangeItemsInGrid(); return res; } } else if( watched == header ) { if( e->type() == QEvent::MouseButtonPress && ((QMouseEvent *)e )->button() == Qt::RightButton ) { setColumnNr(); return TRUE; } return FALSE; } return KIconView::eventFilter( watched, e );}void KrBriefView::makeItemVisible( const KrViewItem *item ) {// qApp->processEvents(); // Please don't remove the comment. Causes crash if it is inserted! ensureItemVisible( (QIconViewItem *)( static_cast<const KrBriefViewItem*>( item ) ) ); }void KrBriefView::initOperator() { _operator = new KrViewOperator(this, this); // QIconView emits selection changed, so chain them to operator connect(this, SIGNAL(selectionChanged()), _operator, SIGNAL(selectionChanged()));}void KrBriefView::initProperties() { // TODO: move this to a general location, maybe KrViewProperties constructor ? _properties = new KrBriefViewProperties; _properties->filter = KrViewProperties::All; _properties->filterMask = KRQuery( "*" ); KConfigGroupSaver grpSvr( _config, "Look&Feel" ); _properties->displayIcons = _config->readBoolEntry( "With Icons", _WithIcons ); bool dirsByNameAlways = _config->readBoolEntry("Always sort dirs by name", false); _properties->sortMode = static_cast<KrViewProperties::SortSpec>( KrViewProperties::Name | KrViewProperties::Descending | KrViewProperties::DirsFirst | (dirsByNameAlways ? KrViewProperties::AlwaysSortDirsByName : 0) ); if ( !_config->readBoolEntry( "Case Sensative Sort", _CaseSensativeSort ) ) _properties->sortMode = static_cast<KrViewProperties::SortSpec>( _properties->sortMode | KrViewProperties::IgnoreCase ); _properties->humanReadableSize = krConfig->readBoolEntry("Human Readable Size", _HumanReadableSize); _properties->localeAwareCompareIsCaseSensitive = QString( "a" ).localeAwareCompare( "B" ) > 0; // see KDE bug #40131 QStringList defaultAtomicExtensions; defaultAtomicExtensions += ".tar.gz"; defaultAtomicExtensions += ".tar.bz2"; defaultAtomicExtensions += ".moc.cpp"; QStringList atomicExtensions = krConfig->readListEntry("Atomic Extensions", defaultAtomicExtensions); for (QStringList::iterator i = atomicExtensions.begin(); i != atomicExtensions.end(); ) { QString & ext = *i; ext = ext.stripWhiteSpace(); if (!ext.length()) { i = atomicExtensions.remove(i); continue; } if (!ext.startsWith(".")) ext.insert(0, '.'); ++i; } _properties->atomicExtensions = atomicExtensions; _config->setGroup( nameInKConfig() ); PROPS->numberOfColumns = _config->readNumEntry( "Number Of Brief Columns", _NumberOfBriefColumns ); if( PROPS->numberOfColumns < 1 ) PROPS->numberOfColumns = 1; else if( PROPS->numberOfColumns > MAX_COLS ) PROPS->numberOfColumns = MAX_COLS;}void KrBriefView::setColumnNr(){ KPopupMenu popup( this ); popup.insertTitle( i18n("Columns")); int COL_ID = 14700; for( int i=1; i <= MAX_COLS; i++ ) { popup.insertItem( QString( "%1" ).arg( i ), COL_ID + i ); popup.setItemChecked( COL_ID + i, PROPS->numberOfColumns == i ); } int result=popup.exec(QCursor::pos()); krConfig->setGroup( nameInKConfig() ); if( result > COL_ID && result <= COL_ID + MAX_COLS ) { krConfig->writeEntry( "Number Of Brief Columns", result - COL_ID ); PROPS->numberOfColumns = result - COL_ID; redrawColumns(); }}void KrBriefView::sortOrderChanged() { ensureItemVisible(currentItem()); if( !_focused ) op()->emitNeedFocus();}void KrBriefView::updateView() { arrangeItemsInGrid(); op()->emitSelectionChanged();}void KrBriefView::updateItem(KrViewItem* item) { dynamic_cast<KrBriefViewItem*>(item)->repaintItem();}void KrBriefView::slotRightButtonPressed(QIconViewItem*, const QPoint& point) { op()->emitEmptyContextMenu(point);}void KrBriefView::changeSortOrder(){ bool asc = !sortDirection(); header->setSortIndicator( 0, asc ? Qt::Ascending : Qt::Descending ); sort( asc );}QMouseEvent * KrBriefView::transformMouseEvent( QMouseEvent * e ){ if( findItem( e->pos() ) != 0 ) return e; QIconViewItem *closestItem = 0; int mouseX = e->pos().x(), mouseY = e->pos().y(); int closestDelta = 0x7FFFFFFF; int minX = ( mouseX / gridX() ) * gridX(); int maxX = minX + gridX(); QIconViewItem *current = firstItem(); while( current ) { if( current->x() >= minX && current->x() < maxX ) { int delta = mouseY - current->y(); if( delta >= 0 && delta < closestDelta ) { closestDelta = delta; closestItem = current; } } current = current->nextItem(); } if( closestItem != 0 ) { if( mouseX - closestItem->x() > gridX() ) closestItem = 0; else if( mouseY - closestItem->y() > closestItem->height() ) closestItem = 0; } if( closestItem != 0 ) { QRect rec = closestItem->textRect( false ); if( mouseX < rec.x() ) mouseX = rec.x(); if( mouseY < rec.y() ) mouseY = rec.y(); if( mouseX > rec.x() + rec.width() -1 ) mouseX = rec.x() + rec.width() -1; if( mouseY > rec.y() + rec.height() -1 ) mouseY = rec.y() + rec.height() -1; QPoint newPos( mouseX, mouseY ); QPoint glPos; if( !e->globalPos().isNull() ) { glPos = QPoint( mouseX - e->pos().x() + e->globalPos().x(), mouseY - e->pos().y() + e->globalPos().y() ); } if( mouseEvent ) delete mouseEvent; return mouseEvent = new QMouseEvent( e->type(), newPos, glPos, e->button(), e->state() ); } return e;}#include "krbriefview.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -