[patch] unfinished backport of keditbookmarks bug to branch

Alexander Kellett lypanov at kde.org
Mon May 5 19:04:21 BST 2003


yoyo backporting magicians,

can't for the life of me get this working.
if anyone feels like delving into keditbookmarks
and event filtering of listview rename fields,
please by all means feel free to fix it up :)

for some reason the tab's aren't processed
by the filter in the backport yet in head
the same eventfilter works just perfectly.

cheers,
Alex
-------------- next part --------------
Index: items.cpp
===================================================================
RCS file: /home/kde/kdebase/konqueror/keditbookmarks/Attic/items.cpp,v
retrieving revision 1.8
diff -u -p -B -w -r1.8 items.cpp
--- items.cpp	29 Oct 2002 10:19:50 -0000	1.8
+++ items.cpp	5 May 2003 17:56:45 -0000
@@ -44,17 +44,6 @@
 
 #include <konq_faviconmgr.h>
 
-void KEBListView::rename( QListViewItem *_item, int c )
-{
-   KEBListViewItem * item = static_cast<KEBListViewItem *>(_item);
-   if ( !(item->bookmark().isGroup() && c == 1) 
-         && !item->bookmark().isSeparator() 
-         && ( firstChild() != item) 
-   ) {
-      KListView::rename( _item, c );
-   }
-}
-
 bool KEBListView::acceptDrag(QDropEvent * e) const
 {
    return e->source() == viewport() || KBookmarkDrag::canDecode( e );
Index: toplevel.cpp
===================================================================
RCS file: /home/kde/kdebase/konqueror/keditbookmarks/toplevel.cpp,v
retrieving revision 1.138.2.1
diff -u -p -B -w -r1.138.2.1 toplevel.cpp
--- toplevel.cpp	2 Dec 2002 18:09:17 -0000	1.138.2.1
+++ toplevel.cpp	5 May 2003 17:56:46 -0000
@@ -44,6 +44,8 @@
 #include <klocale.h>
 #include <kiconloader.h>
 
+#include <klineedit.h>
+
 #include <favicons.h>
 
 #define COL_NAME 0
@@ -598,20 +600,91 @@ KEBListViewItem * KEBTopLevel::findByAdd
 
 void KEBTopLevel::slotRename()
 {
-   QListViewItem *item = selectedItem();
-   Q_ASSERT(item);
-   if (item) {
-      m_pListView->rename(item, COL_NAME);
-   }
+   m_pListView->rename(selectedItems()->first(), COL_NAME);
 }
 
 void KEBTopLevel::slotChangeURL()
 {
-   QListViewItem* item = selectedItem();
-   Q_ASSERT(item);
-   if (item) {
-      m_pListView->rename(item, COL_URL);
+   m_pListView->rename(selectedItems()->first(), COL_URL);
+}
+
+static KEBListViewItem *s_myrenameitem;
+static int s_myrenamecolumn;
+
+class KeyPressEater : public QObject {
+public:
+   KeyPressEater( QWidget *parent = 0, const char *name = 0 ) { ; }
+protected:
+   bool eventFilter(QObject *, QEvent *);
+};
+
+bool KeyPressEater::eventFilter(QObject *, QEvent *pe) {
+   if (pe->type() == QEvent::KeyPress) {
+      kdDebug() << "QEvent::KeyPress!!!" << endl;
+      QKeyEvent *k = (QKeyEvent *) pe;
+      if ((k->key() == Qt::Key_Backtab || k->key() == Qt::Key_Tab)
+      && !(k->state() & ControlButton || k->state() & AltButton)
+      ) {
+         bool fwd = (k->key() == Key_Tab && !(k->state() & ShiftButton));
+         KEBTopLevel::self()->renameNextCell(fwd);
+         return true;
+      }
+   }
+   return false;
+}
+
+void KEBListView::rename(QListViewItem *qitem, int column) {
+   KEBListViewItem *item = static_cast<KEBListViewItem *>(qitem);
+   if ( !(column == COL_NAME || column == COL_URL)
+     || !item 
+     || item == firstChild() 
+     || item->bookmark().isSeparator()
+     || (column == COL_URL && item->bookmark().isGroup())
+   ) {
+      return;
+   }
+   s_myrenamecolumn = column;
+   s_myrenameitem = item;
+   kdDebug() << "attempting to install new handler!!!" << endl;
+   static KeyPressEater *keyPressEater = new KeyPressEater(this);
+   renameLineEdit()->removeEventFilter(keyPressEater);
+   renameLineEdit()->installEventFilter(keyPressEater);
+   KListView::rename(item, column);
+}
+
+void KEBTopLevel::renameNextCell(bool fwd) {
+   // this needs to take special care
+   // of the current listview focus!
+   // but for the moment we just default
+   // to using the item listview
+   // in fact, because the two are so 
+   // different they each need to be 
+   // handled almost completely differently...
+   kdDebug() << "using new handler!!!" << endl;
+   while (1) {
+      if (fwd && s_myrenamecolumn < COL_URL) {
+         s_myrenamecolumn++;
+      } else if (!fwd && s_myrenamecolumn > COL_NAME) {
+         s_myrenamecolumn--;
+      } else {
+         s_myrenameitem    = 
+            static_cast<KEBListViewItem *>(
+              fwd ? ( s_myrenameitem->itemBelow() 
+                    ? s_myrenameitem->itemBelow() : m_pListView->firstChild() ) 
+                  : ( s_myrenameitem->itemAbove()
+                    ? s_myrenameitem->itemAbove() : m_pListView->lastItem() ) );
+         s_myrenamecolumn  
+            = fwd ? COL_NAME : COL_URL;
+      }
+      if (s_myrenameitem 
+       && s_myrenameitem != m_pListView->firstChild()
+       && !s_myrenameitem->bookmark().isSeparator()
+       && !(s_myrenamecolumn == COL_URL && s_myrenameitem->bookmark().isGroup())
+      ) {
+         break;
+      }
    }
+   m_pListView->rename(s_myrenameitem, s_myrenamecolumn);
 }
 
 void KEBTopLevel::deleteSelection(QString commandName)
Index: toplevel.h
===================================================================
RCS file: /home/kde/kdebase/konqueror/keditbookmarks/toplevel.h,v
retrieving revision 1.57
diff -u -p -B -w -r1.57 toplevel.h
--- toplevel.h	6 Nov 2002 17:16:16 -0000	1.57
+++ toplevel.h	5 May 2003 17:56:46 -0000
@@ -139,6 +139,8 @@ public:
     KBookmark rootBookmark() const;
     KBookmark selectedBookmark() const;
 
+    void renameNextCell(bool fwd);
+
     void testBookmarks(QValueList<KBookmark> bks);
 
     // @return where to insert a new item - depending on the selected item


More information about the kde-core-devel mailing list