summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-10-18 15:31:23 (UTC)
committer llornkcor <llornkcor>2002-10-18 15:31:23 (UTC)
commit0910b94b5b6618c84b3eb6c457c9137d63a7277f (patch) (unidiff)
tree44df052721286af898978416a1efcce3c472baaa
parent88b3a159060ed7057bfee4cc1ccfcf81a63a4780 (diff)
downloadopie-0910b94b5b6618c84b3eb6c457c9137d63a7277f.zip
opie-0910b94b5b6618c84b3eb6c457c9137d63a7277f.tar.gz
opie-0910b94b5b6618c84b3eb6c457c9137d63a7277f.tar.bz2
handle Ctrl-V event
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/TEWidget.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/core/apps/embeddedkonsole/TEWidget.cpp b/core/apps/embeddedkonsole/TEWidget.cpp
index 6d5c6e9..b1ad008 100644
--- a/core/apps/embeddedkonsole/TEWidget.cpp
+++ b/core/apps/embeddedkonsole/TEWidget.cpp
@@ -775,489 +775,494 @@ void TEWidget::mouseMoveEvent(QMouseEvent* ev)
775 pntSel = here; 775 pntSel = here;
776 emit extendSelectionSignal( here.x(), here.y() ); 776 emit extendSelectionSignal( here.x(), here.y() );
777} 777}
778 778
779void TEWidget::mouseReleaseEvent(QMouseEvent* ev) 779void TEWidget::mouseReleaseEvent(QMouseEvent* ev)
780{ 780{
781//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); 781//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
782 if ( ev->button() == LeftButton) 782 if ( ev->button() == LeftButton)
783 { 783 {
784 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); 784 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks);
785 preserve_line_breaks = TRUE; 785 preserve_line_breaks = TRUE;
786 actSel = 0; 786 actSel = 0;
787 787
788 //FIXME: emits a release event even if the mouse is 788 //FIXME: emits a release event even if the mouse is
789 // outside the range. The procedure used in `mouseMoveEvent' 789 // outside the range. The procedure used in `mouseMoveEvent'
790 // applies here, too. 790 // applies here, too.
791 791
792 QPoint tL = contentsRect().topLeft(); 792 QPoint tL = contentsRect().topLeft();
793 int tLx = tL.x(); 793 int tLx = tL.x();
794 int tLy = tL.y(); 794 int tLy = tL.y();
795 795
796 if (!mouse_marks && !(ev->state() & ShiftButton)) 796 if (!mouse_marks && !(ev->state() & ShiftButton))
797 emit mouseSignal( 3, // release 797 emit mouseSignal( 3, // release
798 (ev->x()-tLx-blX)/font_w + 1, 798 (ev->x()-tLx-blX)/font_w + 1,
799 (ev->y()-tLy-bY)/font_h + 1 ); 799 (ev->y()-tLy-bY)/font_h + 1 );
800 releaseMouse(); 800 releaseMouse();
801 } 801 }
802} 802}
803 803
804void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev) 804void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev)
805{ 805{
806 if ( ev->button() != LeftButton) return; 806 if ( ev->button() != LeftButton) return;
807 807
808 QPoint tL = contentsRect().topLeft(); 808 QPoint tL = contentsRect().topLeft();
809 int tLx = tL.x(); 809 int tLx = tL.x();
810 int tLy = tL.y(); 810 int tLy = tL.y();
811 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 811 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
812 812
813 // pass on double click as two clicks. 813 // pass on double click as two clicks.
814 if (!mouse_marks && !(ev->state() & ShiftButton)) 814 if (!mouse_marks && !(ev->state() & ShiftButton))
815 { 815 {
816 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 816 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
817 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release 817 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release
818 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 818 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
819 return; 819 return;
820 } 820 }
821 821
822 822
823 emit clearSelectionSignal(); 823 emit clearSelectionSignal();
824 QPoint bgnSel = pos; 824 QPoint bgnSel = pos;
825 QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 825 QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
826 int i = loc(bgnSel.x(),bgnSel.y()); 826 int i = loc(bgnSel.x(),bgnSel.y());
827 iPntSel = bgnSel; 827 iPntSel = bgnSel;
828 828
829 word_selection_mode = TRUE; 829 word_selection_mode = TRUE;
830 830
831 // find word boundaries... 831 // find word boundaries...
832 int selClass = charClass(image[i].c); 832 int selClass = charClass(image[i].c);
833 { 833 {
834 // set the start... 834 // set the start...
835 int x = bgnSel.x(); 835 int x = bgnSel.x();
836 while ( x > 0 && charClass(image[i-1].c) == selClass ) 836 while ( x > 0 && charClass(image[i-1].c) == selClass )
837 { i--; x--; } 837 { i--; x--; }
838 bgnSel.setX(x); 838 bgnSel.setX(x);
839 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); 839 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() );
840 840
841 // set the end... 841 // set the end...
842 i = loc( endSel.x(), endSel.y() ); 842 i = loc( endSel.x(), endSel.y() );
843 x = endSel.x(); 843 x = endSel.x();
844 while( x < columns-1 && charClass(image[i+1].c) == selClass ) 844 while( x < columns-1 && charClass(image[i+1].c) == selClass )
845 { i++; x++ ; } 845 { i++; x++ ; }
846 endSel.setX(x); 846 endSel.setX(x);
847 actSel = 2; // within selection 847 actSel = 2; // within selection
848 emit extendSelectionSignal( endSel.x(), endSel.y() ); 848 emit extendSelectionSignal( endSel.x(), endSel.y() );
849 emit endSelectionSignal(preserve_line_breaks); 849 emit endSelectionSignal(preserve_line_breaks);
850 preserve_line_breaks = TRUE; 850 preserve_line_breaks = TRUE;
851 } 851 }
852} 852}
853 853
854void TEWidget::focusInEvent( QFocusEvent * ) 854void TEWidget::focusInEvent( QFocusEvent * )
855{ 855{
856 856
857 // do nothing, to prevent repainting 857 // do nothing, to prevent repainting
858} 858}
859 859
860 860
861void TEWidget::focusOutEvent( QFocusEvent * ) 861void TEWidget::focusOutEvent( QFocusEvent * )
862{ 862{
863 // do nothing, to prevent repainting 863 // do nothing, to prevent repainting
864} 864}
865 865
866bool TEWidget::focusNextPrevChild( bool next ) 866bool TEWidget::focusNextPrevChild( bool next )
867{ 867{
868 if (next) 868 if (next)
869 return false; // This disables changing the active part in konqueror 869 return false; // This disables changing the active part in konqueror
870 // when pressing Tab 870 // when pressing Tab
871 return QFrame::focusNextPrevChild( next ); 871 return QFrame::focusNextPrevChild( next );
872} 872}
873 873
874 874
875int TEWidget::charClass(char ch) const 875int TEWidget::charClass(char ch) const
876{ 876{
877 // This might seem like overkill, but imagine if ch was a Unicode 877 // This might seem like overkill, but imagine if ch was a Unicode
878 // character (Qt 2.0 QChar) - it might then be sensible to separate 878 // character (Qt 2.0 QChar) - it might then be sensible to separate
879 // the different language ranges, etc. 879 // the different language ranges, etc.
880 880
881 if ( isspace(ch) ) return ' '; 881 if ( isspace(ch) ) return ' ';
882 882
883 static const char *word_characters = ":@-./_~"; 883 static const char *word_characters = ":@-./_~";
884 if ( isalnum(ch) || strchr(word_characters, ch) ) 884 if ( isalnum(ch) || strchr(word_characters, ch) )
885 return 'a'; 885 return 'a';
886 886
887 // Everything else is weird 887 // Everything else is weird
888 return 1; 888 return 1;
889} 889}
890 890
891void TEWidget::setMouseMarks(bool on) 891void TEWidget::setMouseMarks(bool on)
892{ 892{
893 mouse_marks = on; 893 mouse_marks = on;
894 setCursor( mouse_marks ? ibeamCursor : arrowCursor ); 894 setCursor( mouse_marks ? ibeamCursor : arrowCursor );
895} 895}
896 896
897/* ------------------------------------------------------------------------- */ 897/* ------------------------------------------------------------------------- */
898/* */ 898/* */
899/* Clipboard */ 899/* Clipboard */
900/* */ 900/* */
901/* ------------------------------------------------------------------------- */ 901/* ------------------------------------------------------------------------- */
902 902
903#undef KeyPress 903#undef KeyPress
904 904
905void TEWidget::emitSelection() 905void TEWidget::emitSelection()
906// Paste Clipboard by simulating keypress events 906// Paste Clipboard by simulating keypress events
907{ 907{
908#ifndef QT_NO_CLIPBOARD 908#ifndef QT_NO_CLIPBOARD
909 QString text = QApplication::clipboard()->text(); 909 QString text = QApplication::clipboard()->text();
910 if ( ! text.isNull() ) 910 if ( ! text.isNull() )
911 { 911 {
912 text.replace(QRegExp("\n"), "\r"); 912 text.replace(QRegExp("\n"), "\r");
913 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 913 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
914 emit keyPressedSignal(&e); // expose as a big fat keypress event 914 emit keyPressedSignal(&e); // expose as a big fat keypress event
915 emit clearSelectionSignal(); 915 emit clearSelectionSignal();
916 } 916 }
917#endif 917#endif
918} 918}
919 919
920void TEWidget::emitText(QString text) 920void TEWidget::emitText(QString text)
921{ 921{
922 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 922 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
923 emit keyPressedSignal(&e); // expose as a big fat keypress event 923 emit keyPressedSignal(&e); // expose as a big fat keypress event
924} 924}
925 925
926void TEWidget::pasteClipboard( ) 926void TEWidget::pasteClipboard( )
927{ 927{
928 emitSelection(); 928 emitSelection();
929} 929}
930 930
931void TEWidget::setSelection(const QString& t) 931void TEWidget::setSelection(const QString& t)
932{ 932{
933#ifndef QT_NO_CLIPBOARD 933#ifndef QT_NO_CLIPBOARD
934 // Disconnect signal while WE set the clipboard 934 // Disconnect signal while WE set the clipboard
935 QObject *cb = QApplication::clipboard(); 935 QObject *cb = QApplication::clipboard();
936 QObject::disconnect( cb, SIGNAL(dataChanged()), 936 QObject::disconnect( cb, SIGNAL(dataChanged()),
937 this, SLOT(onClearSelection()) ); 937 this, SLOT(onClearSelection()) );
938 938
939 QApplication::clipboard()->setText(t); 939 QApplication::clipboard()->setText(t);
940 940
941 QObject::connect( cb, SIGNAL(dataChanged()), 941 QObject::connect( cb, SIGNAL(dataChanged()),
942 this, SLOT(onClearSelection()) ); 942 this, SLOT(onClearSelection()) );
943#endif 943#endif
944} 944}
945 945
946void TEWidget::onClearSelection() 946void TEWidget::onClearSelection()
947{ 947{
948 emit clearSelectionSignal(); 948 emit clearSelectionSignal();
949} 949}
950 950
951/* ------------------------------------------------------------------------- */ 951/* ------------------------------------------------------------------------- */
952/* */ 952/* */
953/* Keyboard */ 953/* Keyboard */
954/* */ 954/* */
955/* ------------------------------------------------------------------------- */ 955/* ------------------------------------------------------------------------- */
956 956
957//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' 957//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent'
958// due to a bug in `QT' or the ignorance of the author to prevent 958// due to a bug in `QT' or the ignorance of the author to prevent
959// repaint events being emitted to the screen whenever one leaves 959// repaint events being emitted to the screen whenever one leaves
960// or reenters the screen to/from another application. 960// or reenters the screen to/from another application.
961// 961//
962// Troll says one needs to change focusInEvent() and focusOutEvent(), 962// Troll says one needs to change focusInEvent() and focusOutEvent(),
963// which would also let you have an in-focus cursor and an out-focus 963// which would also let you have an in-focus cursor and an out-focus
964// cursor like xterm does. 964// cursor like xterm does.
965 965
966// for the auto-hide cursor feature, I added empty focusInEvent() and 966// for the auto-hide cursor feature, I added empty focusInEvent() and
967// focusOutEvent() so that update() isn't called. 967// focusOutEvent() so that update() isn't called.
968// For auto-hide, we need to get keypress-events, but we only get them when 968// For auto-hide, we need to get keypress-events, but we only get them when
969// we have focus. 969// we have focus.
970 970
971void TEWidget::doScroll(int lines) 971void TEWidget::doScroll(int lines)
972{ 972{
973 scrollbar->setValue(scrollbar->value()+lines); 973 scrollbar->setValue(scrollbar->value()+lines);
974} 974}
975 975
976bool TEWidget::eventFilter( QObject *obj, QEvent *e ) 976bool TEWidget::eventFilter( QObject *obj, QEvent *e )
977{ 977{
978 if ( (e->type() == QEvent::Accel || 978 if ( (e->type() == QEvent::Accel ||
979 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { 979 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) {
980 static_cast<QKeyEvent *>( e )->ignore(); 980 static_cast<QKeyEvent *>( e )->ignore();
981 return true; 981 return true;
982 } 982 }
983 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) 983 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ )
984 return FALSE; // not us 984 return FALSE; // not us
985 if ( e->type() == QEvent::Wheel) { 985 if ( e->type() == QEvent::Wheel) {
986 QApplication::sendEvent(scrollbar, e); 986 QApplication::sendEvent(scrollbar, e);
987 } 987 }
988 988
989#ifdef FAKE_CTRL_AND_ALT 989#ifdef FAKE_CTRL_AND_ALT
990 static bool control = FALSE; 990 static bool control = FALSE;
991 static bool alt = FALSE; 991 static bool alt = FALSE;
992// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); 992// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:");
993 bool dele=FALSE; 993 bool dele=FALSE;
994 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 994 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
995 QKeyEvent* ke = (QKeyEvent*)e; 995 QKeyEvent* ke = (QKeyEvent*)e;
996 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); 996 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat();
997 switch (ke->key()) { 997 switch (ke->key()) {
998 case Key_F9: // let this be "Control" 998 case Key_F9: // let this be "Control"
999 control = keydown; 999 control = keydown;
1000 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); 1000 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state());
1001 dele=TRUE; 1001 dele=TRUE;
1002 break; 1002 break;
1003 case Key_F13: // let this be "Alt" 1003 case Key_F13: // let this be "Alt"
1004 alt = keydown; 1004 alt = keydown;
1005 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); 1005 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state());
1006 dele=TRUE; 1006 dele=TRUE;
1007 break; 1007 break;
1008 default: 1008 default:
1009 if ( control ) { 1009 if ( control ) {
1010 int a = toupper(ke->ascii())-64; 1010 int a = toupper(ke->ascii())-64;
1011 if ( a >= 0 && a < ' ' ) { 1011 if ( a >= 0 && a < ' ' ) {
1012 e = new QKeyEvent(e->type(), ke->key(), 1012 e = new QKeyEvent(e->type(), ke->key(),
1013 a, ke->state()|ControlButton, QChar(a,0)); 1013 a, ke->state()|ControlButton, QChar(a,0));
1014 dele=TRUE; 1014 dele=TRUE;
1015 } 1015 }
1016 } 1016 }
1017 if ( alt ) { 1017 if ( alt ) {
1018 e = new QKeyEvent(e->type(), ke->key(), 1018 e = new QKeyEvent(e->type(), ke->key(),
1019 ke->ascii(), ke->state()|AltButton, ke->text()); 1019 ke->ascii(), ke->state()|AltButton, ke->text());
1020 dele=TRUE; 1020 dele=TRUE;
1021 } 1021 }
1022 } 1022 }
1023 } 1023 }
1024#endif 1024#endif
1025 1025
1026 if ( e->type() == QEvent::KeyPress ) { 1026 if ( e->type() == QEvent::KeyPress ) {
1027 QKeyEvent* ke = (QKeyEvent*)e; 1027 QKeyEvent* ke = (QKeyEvent*)e;
1028 actSel=0; // Key stroke implies a screen update, so TEWidget won't 1028 actSel=0; // Key stroke implies a screen update, so TEWidget won't
1029 // know where the current selection is. 1029 // know where the current selection is.
1030 1030
1031// qDebug("key pressed is 0x%x",ke->key()); 1031// qDebug("key pressed is 0x%x, state %d",ke->key(), ke->state());
1032 1032
1033 if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker 1033 if( ke->state() == ShiftButton && ke->key() == Key_Tab) {
1034 //lets hardcode this sucker
1034 1035
1035// qDebug("key pressed 2 is 0x%x",ke->key()); 1036// qDebug("key pressed 2 is 0x%x",ke->key());
1036 emitText("\\"); // expose 1037 emitText("\\"); // expose
1037 } else 1038 }
1039 else if( ke->state() == ControlButton && ke->key() == Key_V) {
1040 pasteClipboard();
1041 }
1042 else
1038 emit keyPressedSignal(ke); // expose 1043 emit keyPressedSignal(ke); // expose
1039 ke->accept(); 1044 ke->accept();
1040#ifdef FAKE_CTRL_AND_ALT 1045#ifdef FAKE_CTRL_AND_ALT
1041 if ( dele ) delete e; 1046 if ( dele ) delete e;
1042#endif 1047#endif
1043 return true; // stop the event 1048 return true; // stop the event
1044 } 1049 }
1045 if ( e->type() == QEvent::Enter ) { 1050 if ( e->type() == QEvent::Enter ) {
1046 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), 1051 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()),
1047 this, SLOT(onClearSelection()) ); 1052 this, SLOT(onClearSelection()) );
1048 } 1053 }
1049 if ( e->type() == QEvent::Leave ) { 1054 if ( e->type() == QEvent::Leave ) {
1050 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 1055 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
1051 this, SLOT(onClearSelection()) ); 1056 this, SLOT(onClearSelection()) );
1052 } 1057 }
1053 return QFrame::eventFilter( obj, e ); 1058 return QFrame::eventFilter( obj, e );
1054} 1059}
1055 1060
1056/* ------------------------------------------------------------------------- */ 1061/* ------------------------------------------------------------------------- */
1057/* */ 1062/* */
1058/* Frame */ 1063/* Frame */
1059/* */ 1064/* */
1060/* ------------------------------------------------------------------------- */ 1065/* ------------------------------------------------------------------------- */
1061 1066
1062void TEWidget::frameChanged() 1067void TEWidget::frameChanged()
1063{ 1068{
1064 propagateSize(); 1069 propagateSize();
1065 update(); 1070 update();
1066} 1071}
1067 1072
1068/* ------------------------------------------------------------------------- */ 1073/* ------------------------------------------------------------------------- */
1069/* */ 1074/* */
1070/* Sound */ 1075/* Sound */
1071/* */ 1076/* */
1072/* ------------------------------------------------------------------------- */ 1077/* ------------------------------------------------------------------------- */
1073 1078
1074void TEWidget::Bell() 1079void TEWidget::Bell()
1075{ 1080{
1076 QApplication::beep(); 1081 QApplication::beep();
1077} 1082}
1078 1083
1079/* ------------------------------------------------------------------------- */ 1084/* ------------------------------------------------------------------------- */
1080/* */ 1085/* */
1081/* Auxiluary */ 1086/* Auxiluary */
1082/* */ 1087/* */
1083/* ------------------------------------------------------------------------- */ 1088/* ------------------------------------------------------------------------- */
1084 1089
1085void TEWidget::clearImage() 1090void TEWidget::clearImage()
1086// initialize the image 1091// initialize the image
1087// for internal use only 1092// for internal use only
1088{ 1093{
1089 for (int y = 0; y < lines; y++) 1094 for (int y = 0; y < lines; y++)
1090 for (int x = 0; x < columns; x++) 1095 for (int x = 0; x < columns; x++)
1091 { 1096 {
1092 image[loc(x,y)].c = 0xff; //' '; 1097 image[loc(x,y)].c = 0xff; //' ';
1093 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; 1098 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR;
1094 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; 1099 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR;
1095 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; 1100 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION;
1096 } 1101 }
1097} 1102}
1098 1103
1099// Create Image /////////////////////////////////////////////////////// 1104// Create Image ///////////////////////////////////////////////////////
1100 1105
1101void TEWidget::calcGeometry() 1106void TEWidget::calcGeometry()
1102{ 1107{
1103 //FIXME: set rimX == rimY == 0 when running in full screen mode. 1108 //FIXME: set rimX == rimY == 0 when running in full screen mode.
1104 1109
1105 scrollbar->resize(QApplication::style().scrollBarExtent().width(), 1110 scrollbar->resize(QApplication::style().scrollBarExtent().width(),
1106 contentsRect().height()); 1111 contentsRect().height());
1107 switch(scrollLoc) 1112 switch(scrollLoc)
1108 { 1113 {
1109 case SCRNONE : 1114 case SCRNONE :
1110 columns = ( contentsRect().width() - 2 * rimX ) / font_w; 1115 columns = ( contentsRect().width() - 2 * rimX ) / font_w;
1111 blX = (contentsRect().width() - (columns*font_w) ) / 2; 1116 blX = (contentsRect().width() - (columns*font_w) ) / 2;
1112 brX = blX; 1117 brX = blX;
1113 scrollbar->hide(); 1118 scrollbar->hide();
1114 break; 1119 break;
1115 case SCRLEFT : 1120 case SCRLEFT :
1116 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1121 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1117 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1122 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1118 blX = brX + scrollbar->width(); 1123 blX = brX + scrollbar->width();
1119 scrollbar->move(contentsRect().topLeft()); 1124 scrollbar->move(contentsRect().topLeft());
1120 scrollbar->show(); 1125 scrollbar->show();
1121 break; 1126 break;
1122 case SCRRIGHT: 1127 case SCRRIGHT:
1123 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1128 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1124 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1129 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1125 brX = blX; 1130 brX = blX;
1126 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); 1131 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0));
1127 scrollbar->show(); 1132 scrollbar->show();
1128 break; 1133 break;
1129 } 1134 }
1130 //FIXME: support 'rounding' styles 1135 //FIXME: support 'rounding' styles
1131 lines = ( contentsRect().height() - 2 * rimY ) / font_h; 1136 lines = ( contentsRect().height() - 2 * rimY ) / font_h;
1132 bY = (contentsRect().height() - (lines *font_h)) / 2; 1137 bY = (contentsRect().height() - (lines *font_h)) / 2;
1133} 1138}
1134 1139
1135void TEWidget::makeImage() 1140void TEWidget::makeImage()
1136//FIXME: rename 'calcGeometry? 1141//FIXME: rename 'calcGeometry?
1137{ 1142{
1138 calcGeometry(); 1143 calcGeometry();
1139 image = (ca*) malloc(lines*columns*sizeof(ca)); 1144 image = (ca*) malloc(lines*columns*sizeof(ca));
1140 clearImage(); 1145 clearImage();
1141} 1146}
1142 1147
1143// calculate the needed size 1148// calculate the needed size
1144QSize TEWidget::calcSize(int cols, int lins) const 1149QSize TEWidget::calcSize(int cols, int lins) const
1145{ 1150{
1146 int frw = width() - contentsRect().width(); 1151 int frw = width() - contentsRect().width();
1147 int frh = height() - contentsRect().height(); 1152 int frh = height() - contentsRect().height();
1148 int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); 1153 int scw = (scrollLoc==SCRNONE?0:scrollbar->width());
1149 return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); 1154 return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh );
1150} 1155}
1151 1156
1152QSize TEWidget::sizeHint() const 1157QSize TEWidget::sizeHint() const
1153{ 1158{
1154 return size(); 1159 return size();
1155} 1160}
1156 1161
1157void TEWidget::styleChange(QStyle &) 1162void TEWidget::styleChange(QStyle &)
1158{ 1163{
1159 propagateSize(); 1164 propagateSize();
1160} 1165}
1161 1166
1162#ifndef QT_NO_DRAGANDDROP 1167#ifndef QT_NO_DRAGANDDROP
1163 1168
1164/* --------------------------------------------------------------------- */ 1169/* --------------------------------------------------------------------- */
1165/* */ 1170/* */
1166/* Drag & Drop */ 1171/* Drag & Drop */
1167/* */ 1172/* */
1168/* --------------------------------------------------------------------- */ 1173/* --------------------------------------------------------------------- */
1169 1174
1170 1175
1171void TEWidget::dragEnterEvent(QDragEnterEvent* e) 1176void TEWidget::dragEnterEvent(QDragEnterEvent* e)
1172{ 1177{
1173 e->accept(QTextDrag::canDecode(e) || 1178 e->accept(QTextDrag::canDecode(e) ||
1174 QUriDrag::canDecode(e)); 1179 QUriDrag::canDecode(e));
1175} 1180}
1176 1181
1177void TEWidget::dropEvent(QDropEvent* event) 1182void TEWidget::dropEvent(QDropEvent* event)
1178{ 1183{
1179 // The current behaviour when url(s) are dropped is 1184 // The current behaviour when url(s) are dropped is
1180 // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd 1185 // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd
1181 // * in all other cases, just paste 1186 // * in all other cases, just paste
1182 // (for non-local ones, or for a list of URLs, 'cd' is nonsense) 1187 // (for non-local ones, or for a list of URLs, 'cd' is nonsense)
1183 QStrList strlist; 1188 QStrList strlist;
1184 int file_count = 0; 1189 int file_count = 0;
1185 dropText = ""; 1190 dropText = "";
1186 bool bPopup = true; 1191 bool bPopup = true;
1187 1192
1188 if(QUriDrag::decode(event, strlist)) { 1193 if(QUriDrag::decode(event, strlist)) {
1189 if (strlist.count()) { 1194 if (strlist.count()) {
1190 for(const char* p = strlist.first(); p; p = strlist.next()) { 1195 for(const char* p = strlist.first(); p; p = strlist.next()) {
1191 if(file_count++ > 0) { 1196 if(file_count++ > 0) {
1192 dropText += " "; 1197 dropText += " ";
1193 bPopup = false; // more than one file, don't popup 1198 bPopup = false; // more than one file, don't popup
1194 } 1199 }
1195 1200
1196/* 1201/*
1197 KURL url(p); 1202 KURL url(p);
1198 if (url.isLocalFile()) { 1203 if (url.isLocalFile()) {
1199 dropText += url.path(); // local URL : remove protocol 1204 dropText += url.path(); // local URL : remove protocol
1200 } 1205 }
1201 else { 1206 else {
1202 dropText += url.prettyURL(); 1207 dropText += url.prettyURL();
1203 bPopup = false; // a non-local file, don't popup 1208 bPopup = false; // a non-local file, don't popup
1204 } 1209 }
1205*/ 1210*/
1206 1211
1207 } 1212 }
1208 1213
1209 if (bPopup) 1214 if (bPopup)
1210 // m_drop->popup(pos() + event->pos()); 1215 // m_drop->popup(pos() + event->pos());
1211 m_drop->popup(mapToGlobal(event->pos())); 1216 m_drop->popup(mapToGlobal(event->pos()));
1212 else 1217 else
1213 { 1218 {
1214 if (currentSession) { 1219 if (currentSession) {
1215 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1220 currentSession->getEmulation()->sendString(dropText.local8Bit());
1216 } 1221 }
1217// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1222// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1218 } 1223 }
1219 } 1224 }
1220 } 1225 }
1221 else if(QTextDrag::decode(event, dropText)) { 1226 else if(QTextDrag::decode(event, dropText)) {
1222// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1227// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1223 if (currentSession) { 1228 if (currentSession) {
1224 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1229 currentSession->getEmulation()->sendString(dropText.local8Bit());
1225 } 1230 }
1226 // Paste it 1231 // Paste it
1227 } 1232 }
1228} 1233}
1229#endif 1234#endif
1230 1235
1231 1236
1232void TEWidget::drop_menu_activated(int item) 1237void TEWidget::drop_menu_activated(int item)
1233{ 1238{
1234#ifndef QT_NO_DRAGANDDROP 1239#ifndef QT_NO_DRAGANDDROP
1235 switch (item) 1240 switch (item)
1236 { 1241 {
1237 case 0: // paste 1242 case 0: // paste
1238 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1243 currentSession->getEmulation()->sendString(dropText.local8Bit());
1239// KWM::activate((Window)this->winId()); 1244// KWM::activate((Window)this->winId());
1240 break; 1245 break;
1241 case 1: // cd ... 1246 case 1: // cd ...
1242 currentSession->getEmulation()->sendString("cd "); 1247 currentSession->getEmulation()->sendString("cd ");
1243 struct stat statbuf; 1248 struct stat statbuf;
1244 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) 1249 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 )
1245 { 1250 {
1246 if ( !S_ISDIR(statbuf.st_mode) ) 1251 if ( !S_ISDIR(statbuf.st_mode) )
1247 { 1252 {
1248/* 1253/*
1249 KURL url; 1254 KURL url;
1250 url.setPath( dropText ); 1255 url.setPath( dropText );
1251 dropText = url.directory( true, false ); // remove filename 1256 dropText = url.directory( true, false ); // remove filename
1252*/ 1257*/
1253 } 1258 }
1254 } 1259 }
1255 dropText.replace(QRegExp(" "), "\\ "); // escape spaces 1260 dropText.replace(QRegExp(" "), "\\ "); // escape spaces
1256 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1261 currentSession->getEmulation()->sendString(dropText.local8Bit());
1257 currentSession->getEmulation()->sendString("\n"); 1262 currentSession->getEmulation()->sendString("\n");
1258// KWM::activate((Window)this->winId()); 1263// KWM::activate((Window)this->winId());
1259 break; 1264 break;
1260 } 1265 }
1261#endif 1266#endif
1262} 1267}
1263 1268