📄 krdetailedview.cpp
字号:
if ( !_focused ) op()->emitNeedFocus(); KListView::contentsWheelEvent( e );}void KrDetailedView::handleContextMenu( QListViewItem * it, const QPoint & pos, int ) { if ( !_focused ) op()->emitNeedFocus(); if ( !it ) return ; if ( static_cast<KrDetailedViewItem*>( it ) -> name() == ".." ) return ; int i = KrSelectionMode::getSelectionHandler()->showContextMenu(); contextMenuPoint = QPoint( pos.x(), pos.y() - header() ->height() ); if (i < 0) showContextMenu(); else if (i > 0) contextMenuTimer.start(i, true);}void KrDetailedView::showContextMenu(){ if (lastSwushPosition) lastSwushPosition->setSelected(true); op()->emitContextMenu( contextMenuPoint );}KrViewItem *KrDetailedView::getKrViewItemAt( const QPoint & vp ) { return dynamic_cast<KrViewItem*>( KListView::itemAt( vp ) );}bool KrDetailedView::acceptDrag( QDropEvent* ) const { return true;}QRect KrDetailedView::drawItemHighlighter(QPainter *painter, QListViewItem *item){ QRect r; if( _currDragItem && item ) { r = itemRect(item); if (painter) style().drawPrimitive(QStyle::PE_FocusRect, painter, r, colorGroup(), QStyle::Style_FocusAtBorder, colorGroup().highlight()); } return r;}void KrDetailedView::contentsDropEvent( QDropEvent * e ) { e->setPoint( contentsToViewport( e->pos() ) ); op()->emitGotDrop(e); e->ignore(); KListView::contentsDropEvent( e );}void KrDetailedView::contentsDragMoveEvent( QDragMoveEvent * e ) { _currDragItem = getKrViewItemAt(contentsToViewport(e->pos())); if( _currDragItem && !_currDragItem->VF->vfile_isDir() ) _currDragItem = 0; KListView::contentsDragMoveEvent( e );}void KrDetailedView::imStartEvent(QIMEvent* e){ if ( ACTIVE_PANEL->quickSearch->isShown() ) { ACTIVE_PANEL->quickSearch->myIMStartEvent( e ); return ; }else { KConfigGroupSaver grpSvr( _config, "Look&Feel" ); if ( !_config->readBoolEntry( "New Style Quicksearch", _NewStyleQuicksearch ) ) KListView::imStartEvent( 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 list view will // realize its new size after the key processing. The following line // will resize the list 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->myIMStartEvent( e ); } }}void KrDetailedView::imEndEvent(QIMEvent* e){ if ( ACTIVE_PANEL->quickSearch->isShown() ) { ACTIVE_PANEL->quickSearch->myIMEndEvent( e ); return ; }}void KrDetailedView::imComposeEvent(QIMEvent* e){ if ( ACTIVE_PANEL->quickSearch->isShown() ) { ACTIVE_PANEL->quickSearch->myIMComposeEvent( e ); return ; }}// TODO: for brief mode, move as much of this as possible to the viewOperatorvoid KrDetailedView::keyPressEvent( QKeyEvent * e ) { if ( !e || !firstChild() ) return ; // subclass bug if ( ACTIVE_PANEL->quickSearch->isShown() ) { ACTIVE_PANEL->quickSearch->myKeyPressEvent( e ); return ; } switch ( e->key() ) { case Key_Up : if ( e->state() == ControlButton ) { // let the panel handle it - jump to the Location Bar e->ignore(); break; } else if (!KrSelectionMode::getSelectionHandler()->useQTSelection()) { QListViewItem * i = currentItem(); if ( !i ) break; if ( e->state() == ShiftButton ) setSelected( i, !i->isSelected() ); i = i->itemAbove(); if ( i ) { QListView::setCurrentItem( i ); QListView::ensureItemVisible( i ); } } else KListView::keyPressEvent(e); break; case Key_Down : if ( e->state() == ControlButton || e->state() == ( ControlButton | ShiftButton ) ) { // let the panel handle it - jump to command line e->ignore(); break; } else if (!KrSelectionMode::getSelectionHandler()->useQTSelection()){ QListViewItem * i = currentItem(); if ( !i ) break; if ( e->state() == ShiftButton ) setSelected( i, !i->isSelected() ); i = i->itemBelow(); if ( i ) {QListView::setCurrentItem( i ); QListView::ensureItemVisible( i ); } } else KListView::keyPressEvent(e); break; case Key_Next: if (!KrSelectionMode::getSelectionHandler()->useQTSelection()){ QListViewItem * i = currentItem(), *j; if ( !i ) break; QRect r( itemRect( i ) ); if ( !r.height() ) break; for ( int page = visibleHeight() / r.height() - 1; page > 0 && ( j = i->itemBelow() ); --page ) i = j; if ( i ) {QListView::setCurrentItem( i ); QListView::ensureItemVisible( i ); } } else KListView::keyPressEvent(e); break; case Key_Prior: if (!KrSelectionMode::getSelectionHandler()->useQTSelection()){ QListViewItem * i = currentItem(), *j; if ( !i ) break; QRect r( itemRect( i ) ); if ( !r.height() ) break; for ( int page = visibleHeight() / r.height() - 1; page > 0 && ( j = i->itemAbove() ); --page ) i = j; if ( i ) {QListView::setCurrentItem( i ); QListView::ensureItemVisible( i ); } } else KListView::keyPressEvent(e); break; case Key_Home: if (!KrSelectionMode::getSelectionHandler()->useQTSelection()){ if ( e->state() & ShiftButton ) /* Shift+Home */ { clearSelection(); KListView::keyPressEvent( e ); op()->emitSelectionChanged(); triggerUpdate(); break; } else { QListViewItem * i = firstChild(); if ( i ) {QListView::setCurrentItem( i ); QListView::ensureItemVisible( i ); } } } else KListView::keyPressEvent(e); break; case Key_End: if (!KrSelectionMode::getSelectionHandler()->useQTSelection()){ if ( e->state() & ShiftButton ) /* Shift+End */ { clearSelection(); KListView::keyPressEvent( e ); op()->emitSelectionChanged(); triggerUpdate(); break; } else { QListViewItem *i = firstChild(), *j; while ( ( j = i->nextSibling() ) ) i = j; while ( ( j = i->itemBelow() ) ) i = j; if ( i ) {QListView::setCurrentItem( i ); QListView::ensureItemVisible( i ); } break; } } else KListView::keyPressEvent(e); break; case Key_Enter : case Key_Return : { if ( e->state() & ControlButton ) // let the panel handle it e->ignore(); else { KrViewItem * i = getCurrentKrViewItem(); QString tmp = i->name(); op()->emitExecuted(tmp); } break; } case Key_QuoteLeft : // Terminal Emulator bugfix if ( e->state() == ControlButton ) { // let the panel handle it e->ignore(); break; } else { // a normal click - do a lynx-like moving thing SLOTS->home(); // ask krusader to move up a directory return ; // safety } break; case Key_Right : if ( e->state() == ControlButton || e->state() == ShiftButton ) { // let the panel handle it e->ignore(); break; } else { // just a normal click - do a lynx-like moving thing KrViewItem *i = getCurrentKrViewItem(); if ( i->name() == ".." ) { // if clicking on the ".." entry SLOTS->dirUp(); // ask krusader to move up a directory return ; } if ( i->VF->vfile_isDir() ) { // we create a return-pressed event, QString tmp = i->name(); op()->emitExecuted(tmp); // thereby emulating a chdir } else if( i->VF->vfile_getUrl().isLocalFile() ) { bool encrypted; KURL url = i->VF->vfile_getUrl(); QString mime = ((vfile *)(i->VF))->vfile_getMime(); QString type = KRarcHandler::getType( encrypted, url.path(), mime, false ); if( KRarcHandler::arcSupported( type ) ) { KURL url = i->VF->vfile_getUrl(); if( type == "-tar" || type == "-tgz" || type == "-tbz" ) url.setProtocol( "tar" ); else url.setProtocol( "krarc" ); ACTIVE_FUNC->openUrl( url ); } } return ; // safety } case Key_Backspace : // Terminal Emulator bugfix case Key_Left : if ( e->state() == ControlButton || e->state() == ShiftButton ) { // let the panel handle it e->ignore(); break; } else { // a normal click - do a lynx-like moving thing SLOTS->dirUp(); // ask krusader to move up a directory return ; // safety } //case Key_Up : //KListView::keyPressEvent( e ); //break;/*#ifndef _newSelectionHandling case Key_Down : if ( e->state() == ControlButton ) { // let the panel handle it e->ignore(); break; } else KListView::keyPressEvent( e ); break;#endif*/ case Key_Delete : // kill file SLOTS->deleteFiles( e->state() == ShiftButton || e->state() == ControlButton ); break ; case Key_Insert : { if (KrSelectionMode::getSelectionHandler()->insertMovesDown()) KListView::keyPressEvent( e ); else { QKeyEvent ev = QKeyEvent( QKeyEvent::KeyPress, Key_Space, 0, 0 ); KListView::keyPressEvent( & ev ); } break ; } case Key_Space : { KrDetailedViewItem * viewItem = static_cast<KrDetailedViewItem *> ( getCurrentKrViewItem() ); if ( !viewItem || viewItem->name() == ".." ) { // wrong type, just mark(unmark it) if (KrSelectionMode::getSelectionHandler()->spaceMovesDown()) { QKeyEvent ev = QKeyEvent( QKeyEvent::KeyPress, Key_Insert, 0, 0 ); KListView::keyPressEvent( & ev ); } else KListView::keyPressEvent( e ); break ; } if ( viewItem->VF->vfile_isDir() && viewItem->VF->vfile_getSize() <= 0 && KrSelectionMode::getSelectionHandler()->spaceCalculatesDiskSpace()) { // // NOTE: this is buggy incase somewhere down in the folder we're calculating, // there's a folder we can't enter (permissions). in that case, the returned // size will not be correct. // KIO::filesize_t totalSize = 0; unsigned long totalFiles = 0, totalDirs = 0; QStringList items; items.push_back( viewItem->name() ); if ( ACTIVE_PANEL->func->calcSpace( items, totalSize, totalFiles, totalDirs ) ) { // did we succeed to calcSpace? we'll fail if we don't have permissions if ( totalSize == 0 ) { // just mark it, and bail out goto mark; } viewItem->setSize( totalSize ); viewItem->repaintItem(); } }mark: if (KrSelectionMode::getSelectionHandler()->spaceMovesDown()) { QKeyEvent ev = QKeyEvent( QKeyEvent::KeyPress, Key_Insert, 0, 0 ); KListView::keyPressEvent( & ev ); } else KListView::keyPressEvent( e ); } break; case Key_A : // mark all if ( e->state() == ControlButton ) { KListView::keyPressEvent( e ); updateView(); break; } default: if ( e->key() == Key_Escape ) { QListView::keyPressEvent( e ); return ; // otherwise the selection gets lost??!?? } // if the key is A..Z or 1..0 do quick search otherwise... if ( e->text().length() > 0 && e->text() [ 0 ].isPrint() ) // better choice. Otherwise non-ascii characters like can not be the first character of a filename /* if ( ( e->key() >= Key_A && e->key() <= Key_Z ) || ( e->key() >= Key_0 && e->key() <= Key_9 ) || ( e->key() == Key_Backspace ) || ( e->key() == Key_Down ) || ( e->key() == Key_Period ) ) */{ // are we doing quicksearch? if not, send keys to panel //if ( _config->readBoolEntry( "Do Quicksearch", _DoQuicksearch ) ) { // are we using krusader's classic quicksearch, or wincmd style? { KConfigGroupSaver grpSvr( _config, "Look&Feel" ); if ( !_config->readBoolEntry( "New Style Quicksearch", _NewStyleQuicksearch ) ) KListView::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 list view will // realize its new size after the key processing. The following line // will resize the list 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 ); } KListView::keyPressEvent( e ); } } // emit the new item description slotItemDescription( currentItem() ); // actually send the QListViewItem}// overridden to make sure EXTENTION won't be lost during renamevoid KrDetailedView::rename( QListViewItem * item, int c ) { // do we have an EXT column? if so, handle differently: // copy the contents of the EXT column over to the name if ( COLUMN( Extention ) != -1 ) { item->setText( COLUMN( Name ), static_cast<KrDetailedViewItem*>( item ) ->name() ); item->setText( COLUMN( Extention ), QString::null ); repaintItem( item ); } currentlyRenamedItem = item; renameLineEdit()->setBackgroundMode(Qt::FixedColor); renameLineEdit()->setPaletteBackgroundColor(Qt::white); renameLineEdit()->setPaletteForegroundColor(Qt::black); KListView::rename( item, c ); renameLineEdit() ->selectAll();}void KrDetailedView::renameCurrentItem() { int c;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -