📄 tewidget.cpp
字号:
actSel = 2; // within selection emit extendSelectionSignal( endSel.x(), endSel.y() ); emit endSelectionSignal(preserve_line_breaks); preserve_line_breaks = TRUE; }}void TEWidget::focusInEvent( QFocusEvent * ){ // do nothing, to prevent repainting}void TEWidget::focusOutEvent( QFocusEvent * ){ // do nothing, to prevent repainting}bool TEWidget::focusNextPrevChild( bool next ){ if (next) return false; // This disables changing the active part in konqueror // when pressing Tab return QFrame::focusNextPrevChild( next );}int TEWidget::charClass(char ch) const{ // This might seem like overkill, but imagine if ch was a Unicode // character (Qt 2.0 QChar) - it might then be sensible to separate // the different language ranges, etc. if ( isspace(ch) ) return ' '; static const char *word_characters = ":@-./_~"; if ( isalnum(ch) || strchr(word_characters, ch) ) return 'a'; // Everything else is weird return 1;}void TEWidget::setMouseMarks(bool on){ mouse_marks = on; setCursor( mouse_marks ? ibeamCursor : arrowCursor );}/* ------------------------------------------------------------------------- *//* *//* Clipboard *//* *//* ------------------------------------------------------------------------- */#undef KeyPressvoid TEWidget::emitSelection()// Paste Clipboard by simulating keypress events{#ifndef QT_NO_CLIPBOARD QString text = QApplication::clipboard()->text(); if ( ! text.isNull() ) { text.replace(QRegExp("\n"), "\r"); QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); emit keyPressedSignal(&e); // expose as a big fat keypress event emit clearSelectionSignal(); }#endif}void TEWidget::emitText(QString text){ QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); emit keyPressedSignal(&e); // expose as a big fat keypress event}void TEWidget::pasteClipboard( ){ emitSelection();}static bool weSetSelection = FALSE;void TEWidget::setSelection(const QString& t){#ifndef QT_NO_CLIPBOARD // this disconnection doesn't work at we receive the event after we reconnect // Disconnect signal while WE set the clipboard// QObject *cb = QApplication::clipboard();// QObject::disconnect( cb, SIGNAL(dataChanged()),// this, SLOT(onClearSelection()) ); weSetSelection = TRUE; QApplication::clipboard()->setText(t);// QObject::connect( cb, SIGNAL(dataChanged()),// this, SLOT(onClearSelection()) );#endif}void TEWidget::onClearSelection(){ if ( weSetSelection ) { weSetSelection = FALSE; return; } emit clearSelectionSignal();}/* ------------------------------------------------------------------------- *//* *//* Keyboard *//* *//* ------------------------------------------------------------------------- *///FIXME: an `eventFilter' has been installed instead of a `keyPressEvent'// due to a bug in `QT' or the ignorance of the author to prevent// repaint events being emitted to the screen whenever one leaves// or reenters the screen to/from another application.//// Troll says one needs to change focusInEvent() and focusOutEvent(),// which would also let you have an in-focus cursor and an out-focus// cursor like xterm does.// for the auto-hide cursor feature, I added empty focusInEvent() and// focusOutEvent() so that update() isn't called.// For auto-hide, we need to get keypress-events, but we only get them when// we have focus.void TEWidget::doScroll(int lines){ scrollbar->setValue(scrollbar->value()+lines);}bool TEWidget::eventFilter( QObject *obj, QEvent *e ){ if ( (e->type() == QEvent::Accel || e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { static_cast<QKeyEvent *>( e )->ignore(); return true; } if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) return FALSE; // not us if ( e->type() == QEvent::Wheel) { QApplication::sendEvent(scrollbar, e); }#ifdef FAKE_CTRL_AND_ALT static bool control = FALSE; static bool alt = FALSE; // Has a keyboard with no CTRL and ALT keys, but we fake it: bool dele=FALSE; if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { QKeyEvent* ke = (QKeyEvent*)e; bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); switch (ke->key()) { case Key_F9: // let this be "Control" control = keydown; e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); dele=TRUE; break; case Key_F13: // let this be "Alt" alt = keydown; e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); dele=TRUE; break; default: if ( control ) { int a = toupper(ke->ascii())-64; if ( a >= 0 && a < ' ' ) { e = new QKeyEvent(e->type(), ke->key(), a, ke->state()|ControlButton, QChar(a,0)); dele=TRUE; } } if ( alt ) { e = new QKeyEvent(e->type(), ke->key(), ke->ascii(), ke->state()|AltButton, ke->text()); dele=TRUE; } } }#endif if ( e->type() == QEvent::KeyPress ) { QKeyEvent* ke = (QKeyEvent*)e; actSel=0; // Key stroke implies a screen update, so TEWidget won't // know where the current selection is. emit keyPressedSignal(ke); // expose ke->accept();#ifdef FAKE_CTRL_AND_ALT if ( dele ) delete e;#endif return true; // stop the event } if ( e->type() == QEvent::Enter ) { QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), this, SLOT(onClearSelection()) ); } if ( e->type() == QEvent::Leave ) { QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), this, SLOT(onClearSelection()) ); } return QFrame::eventFilter( obj, e );}/* ------------------------------------------------------------------------- *//* *//* Frame *//* *//* ------------------------------------------------------------------------- */void TEWidget::frameChanged(){ propagateSize(); update();}/* ------------------------------------------------------------------------- *//* *//* Sound *//* *//* ------------------------------------------------------------------------- */void TEWidget::Bell(){ QApplication::beep();}/* ------------------------------------------------------------------------- *//* *//* Auxiluary *//* *//* ------------------------------------------------------------------------- */void TEWidget::clearImage()// initialize the image// for internal use only{ for (int y = 0; y < lines; y++) for (int x = 0; x < columns; x++) { image[loc(x,y)].c = 0xff; //' '; image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; }}// Create Image ///////////////////////////////////////////////////////void TEWidget::calcGeometry(){ //FIXME: set rimX == rimY == 0 when running in full screen mode. scrollbar->resize(QApplication::style().scrollBarExtent().width(), contentsRect().height()); switch(scrollLoc) { case SCRNONE : columns = ( contentsRect().width() - 2 * rimX ) / font_w; blX = (contentsRect().width() - (columns*font_w) ) / 2; brX = blX; scrollbar->hide(); break; case SCRLEFT : columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; blX = brX + scrollbar->width(); scrollbar->move(contentsRect().topLeft()); scrollbar->show(); break; case SCRRIGHT: columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; brX = blX; scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); scrollbar->show(); break; } //FIXME: support 'rounding' styles lines = ( contentsRect().height() - 2 * rimY ) / font_h; bY = (contentsRect().height() - (lines *font_h)) / 2;}void TEWidget::makeImage()//FIXME: rename 'calcGeometry?{ calcGeometry(); image = (ca*) malloc(lines*columns*sizeof(ca)); clearImage();}// calculate the needed sizeQSize TEWidget::calcSize(int cols, int lins) const{ int frw = width() - contentsRect().width(); int frh = height() - contentsRect().height(); int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh );}QSize TEWidget::sizeHint() const{ return size();}void TEWidget::styleChange(QStyle &){ propagateSize();}#ifndef QT_NO_DRAGANDDROP/* --------------------------------------------------------------------- *//* *//* Drag & Drop *//* *//* --------------------------------------------------------------------- */void TEWidget::dragEnterEvent(QDragEnterEvent* e){ e->accept(QTextDrag::canDecode(e) || QUriDrag::canDecode(e));}void TEWidget::dropEvent(QDropEvent* event){ // The current behaviour when URL(s) are dropped is: // * if there is only ONE URL and if it's a LOCAL one, ask for paste or cd // * in all other cases, just paste // (for non-local ones, or for a list of URLs, 'cd' is nonsense) QStrList strlist; int file_count = 0; dropText = ""; bool bPopup = true; if(QUriDrag::decode(event, strlist)) { if (strlist.count()) { for(const char* p = strlist.first(); p; p = strlist.next()) { if(file_count++ > 0) { dropText += " "; bPopup = false; // more than one file, don't popup }/* KURL url(p); if (url.isLocalFile()) { dropText += url.path(); // local URL : remove protocol } else { dropText += url.prettyURL(); bPopup = false; // a non-local file, don't popup }*/ } if (bPopup) // m_drop->popup(pos() + event->pos()); m_drop->popup(mapToGlobal(event->pos())); else { if (currentSession) { currentSession->getEmulation()->sendString(dropText.local8Bit()); }// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; } } } else if(QTextDrag::decode(event, dropText)) {// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; if (currentSession) { currentSession->getEmulation()->sendString(dropText.local8Bit()); } // Paste it }}#endifvoid TEWidget::drop_menu_activated(int item){#ifndef QT_NO_DRAGANDDROP switch (item) { case 0: // paste currentSession->getEmulation()->sendString(dropText.local8Bit());// KWM::activate((Window)this->winId()); break; case 1: // cd ... currentSession->getEmulation()->sendString("cd "); struct stat statbuf; if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) { if ( !S_ISDIR(statbuf.st_mode) ) {/* KURL url; url.setPath( dropText ); dropText = url.directory( true, false ); // remove filename*/ } } dropText.replace(QRegExp(" "), "\\ "); // escape spaces currentSession->getEmulation()->sendString(dropText.local8Bit()); currentSession->getEmulation()->sendString("\n");// KWM::activate((Window)this->winId()); break; }#else Q_UNUSED(item);#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -