[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    PATCH: #25530 (cursor problems in kspread)
From:       Daniel Naber <daniel.naber () t-online ! de>
Date:       2001-07-31 20:21:32
[Download RAW message or body]

Hi,

this is more a hack than a patch, but I don't know how to solve this 
better: doubleclick should place the cursor at the mouse pointer, not at 
the end of the cell.

This patch also fixes that cursor left/right should not jump the other 
cells when editing (I deleted some strangely indented code which I didn't 
understand, perhaps that's not good).

The patch has this problem: when you delete a character with Del, the 
cursor will jump to the end. More precisely, it will jump to the position 
where you used Backspace before. I have no idea what's going on there, but 
with some help I can perhaps fix these problems for KOffice 1.1.

Regards
 Daniel

-- 
Daniel Naber, Paul-Gerhardt-Str. 2, 33332 Guetersloh, Germany
Tel. 05241-59371, Mobil 0170-4819674

["kspread_doubleclick.diff" (text/x-diff)]

Index: kspread_canvas.h
===================================================================
RCS file: /home/kde/koffice/kspread/kspread_canvas.h,v
retrieving revision 1.60
diff -u -r1.60 kspread_canvas.h
--- kspread_canvas.h	2001/05/04 07:26:09	1.60
+++ kspread_canvas.h	2001/07/31 20:10:03
@@ -209,7 +209,7 @@
      * Chooses the correct @ref #EditorType by looking at
      * the current cells value. By default CellEditor is chosen.
      */
-    void createEditor();
+    void createEditor( int pos = -1 );
     void createEditor( EditorType type );
     /**
      * Deletes the current cell editor.
Index: kspread_canvas.cc
===================================================================
RCS file: /home/kde/koffice/kspread/kspread_canvas.cc,v
retrieving revision 1.202
diff -u -r1.202 kspread_canvas.cc
--- kspread_canvas.cc	2001/05/17 13:44:25	1.202
+++ kspread_canvas.cc	2001/07/31 20:10:20
@@ -1246,10 +1246,10 @@
   m_iMouseStartRow = chooseMarkerRow();
 }
 
-void KSpreadCanvas::mouseDoubleClickEvent( QMouseEvent*  )
+void KSpreadCanvas::mouseDoubleClickEvent( QMouseEvent *ev  )
 {
   if ( m_pView->koDocument()->isReadWrite() )
-    createEditor();
+    createEditor(ev->x());
 }
 
 void KSpreadCanvas::wheelEvent( QWheelEvent* _ev )
@@ -1389,7 +1389,6 @@
   // "end of editing" stuff here, instead of for each case - this bool is
   // also used for make_select (extending selection), so it doesn't include Return
   bool bChangingCells = ( _ev->key() == Key_Down || _ev->key() == Key_Up ||
-                          _ev->key() == Key_Left || _ev->key() == Key_Right ||
                           _ev->key() == Key_Prior || _ev->key() == Key_Next );
 
   // End of editing a cell
@@ -1605,50 +1604,20 @@
 	  return;
 
       case Key_Right:
-
-	  if ( !m_bChoose && markerColumn() >= 26*26)//0xFFFF )
-	      return;
-	  if ( m_bChoose && chooseMarkerColumn() >= 26*26)//0xFFFF )
-	      return;
-                   if(m_bChoose)
-                        moveHide=chooseMarkerColumn();
-                   else
-                        moveHide=markerColumn() ;
-                   do
-                        {
-                                moveHide++;
-                                cl= activeTable()->nonDefaultColumnLayout( moveHide \
                );
-                        }
-                   while( cl->isHide() );
-
 	  if ( m_bChoose )
 	      chooseGotoLocation( QMIN( 26*26/*0x7FFF*/, /*chooseMarkerColumn() + \
1*/moveHide ), chooseMarkerRow(), 0, make_select ); +	  else if( m_pEditor )
+	      m_pEditor->setCursorPosition(m_pEditor->cursorPosition()+1);
 	  else
 	      gotoLocation( QMIN( /*26*26*/0x7FFF, /*markerColumn() + 1*/moveHide ), \
markerRow(), 0, make_select,false,true );  
 	  return;
 
       case Key_Left:
-
-	  if ( !m_bChoose && markerColumn() == 1 )
-	      return;
-	  if ( m_bChoose && chooseMarkerColumn() == 1 )
-	      return;
-                  if(m_bChoose)
-                        moveHide=chooseMarkerColumn();
-                   else
-                        moveHide=markerColumn();
-                   do
-                        {
-                                moveHide--;
-                                cl= activeTable()->nonDefaultColumnLayout( moveHide \
                );
-                        }
-                   while( cl->isHide() && moveHide!=0);
-                   // if column==0 return;
-                   if(moveHide==0)
-                        return;
 	  if ( m_bChoose )
 	      chooseGotoLocation( QMAX( 1, /*chooseMarkerColumn() - 1*/moveHide ), \
chooseMarkerRow(), 0, make_select ); +	  else if( m_pEditor )
+	      m_pEditor->setCursorPosition(m_pEditor->cursorPosition()-1);
 	  else
 	      gotoLocation( QMAX( 1, /*markerColumn() - 1*/ moveHide), markerRow(), 0, \
make_select,false,true );  
@@ -1987,13 +1956,37 @@
   setFocus();
 }
 
-void KSpreadCanvas::createEditor()
+void KSpreadCanvas::createEditor( int pos )
 {
   KSpreadCell* cell = activeTable()->cellAt( markerColumn(), markerRow() );
 
   createEditor( CellEditor );
-  if ( cell )
-      m_pEditor->setText(cell->text());
+  if ( cell ) {
+      QString text = cell->text();
+      m_pEditor->setText(text);
+      if( pos != -1 && !text.isEmpty() ) {
+	  // don't place the cursor at the end but at the position
+	  // the user clicked:
+	  // FIXME: 
+	  // -double click in a cell and press Del: cursor jumps to last char, why?
+	  // -doesn't work for numbers (right-aligned)
+	  // TODO:
+	  // -markup like "<b>" should be ignored?!
+	  pos = pos - m_pEditor->x();
+	  unsigned int pos_count = 0;
+	  QFontMetrics fm = m_pEditor->fontMetrics();
+	  while( fm.width(text.left(pos_count)) < pos && pos_count < text.length() ) {
+	      pos_count++;
+	  }
+	  // place cursor before the current character if that's more precise:
+	  int diff1 = abs(fm.width(text.left(pos_count)) - pos);
+	  int diff2 = abs(fm.width(text.left(pos_count-1)) - pos);
+	  if( diff2 <= diff1 ) {
+	      pos_count--;
+	  }
+          m_pEditor->setCursorPosition( pos_count );
+      }
+  }
 }
 
 void KSpreadCanvas::createEditor( EditorType ed )


_______________________________________________
Koffice-devel mailing list
Koffice-devel@master.kde.org
http://master.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic