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

List:       kde-devel
Subject:    in-place-editing patch for konqueror bookmarks
From:       Oelewapperke <oelewapperke () ulyssis ! org>(by way of Oelewapperke <oelewapperke () uly
Date:       2002-12-28 23:17:49
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

- -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

hi,

my name is Christophe Devriese

I have written a patch to kdelibs to give one the option of right-clicking on
a bookmark and selecting "delete" (implemented), or "add" (to be added to the
patch, this one is a proof of concept), etc. This patch works without
requiring any modifications to konqueror itself.

I miss this feature a lot in konqueror.

I have a number of options to proceed
- - -> make kbookmark an abstract class, and force anyone wanting to use it to
create a subclass, then include the events on them as pure virtuals in the
abstract class
	pro : 	-> this is, imho, the way it should be done
			-> it uses OO to accomplish the task, an the responsability for bookmarks
is with the bookmarks
			-> it allows us to use the objects without further modifications in the
future (to for example include drag-and-drop to a .url file ...)
			-> it is faster than the other options (in terms of execution, not in
 terms of developer time) (by a few nanosecs ;-) )

	con : 	-> requires (complicated) changes to both konqueror and other apps
using bookmarks
			-> that means it will take developer time, and a lot more commits
			-> not binary compatible (but I don't know any app other than konq that
uses bookmarks)

- - -> add a routine (or signal) to kbookmarkowner à la MouseEvent(QMouseEvent
 qm, KBookmark bm)
	pro :		-> "the quick hack", doesn't require changes to any other app (that
 is kdelibs and konq need some changes)
			-> one more commit will do it
			-> binary compatible
			-> I can (but it would be even uglier) avoid making any changes at all to
konqueror

	con : 	-> slower
			-> not extensible
			-> complicated semantics without a very good reason (like having to call
QPopupMenu::exec and not QPopupMenu::popup)
- -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+DjDGJFU6C5Uo8MgRAveHAKCmQTczcQORHGuufEEvzNoNk1FcgQCePMpL
ql75oOAceoqIQaV3InadvVY=
=ox1M
- -----END PGP SIGNATURE-----


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+DjEdJFU6C5Uo8MgRAtE8AJ9G3DNccLvpWvO9fvbHDAod+aINwACfVwJJ
WPlqO63IGkC4fzdWgYy5WY0=
=S27w
-----END PGP SIGNATURE-----

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

? kipebookmarkmenu.h
Index: kbookmarkbar.cc
===================================================================
RCS file: /home/kde/kdelibs/kio/bookmarks/kbookmarkbar.cc,v
retrieving revision 1.35
diff -u -3 -p -r1.35 kbookmarkbar.cc
--- kbookmarkbar.cc	17 Nov 2002 02:16:26 -0000	1.35
+++ kbookmarkbar.cc	28 Dec 2002 23:00:22 -0000
@@ -83,46 +83,20 @@ void KBookmarkBar::slotBookmarksChanged(
 
 void KBookmarkBar::fillBookmarkBar(KBookmarkGroup & parent)
 {
-    if (parent.isNull())
-        return;
+  if (parent.isNull())
+    return;
 
-    for (KBookmark bm = parent.first(); !bm.isNull(); bm = parent.next(bm))
+  for (KBookmark bm = parent.first(); !bm.isNull(); bm = parent.next(bm))
+  {
+    QString text = bm.text();
+    text.replace( '&', "&&" );
+    if ( bm.isSeparator() )
+      m_toolBar->insertLineSeparator();
+    else
     {
-		QString text = bm.text();
-        text.replace( '&', "&&" );
-        if (!bm.isGroup())
-        {
-            if ( bm.isSeparator() )
-                m_toolBar->insertLineSeparator();
-            else
-            {
-                KAction *action;
-                // create a normal URL item, with ID as a name
-                action = new KAction(text, bm.icon(), 0,
-                                     this, SLOT(slotBookmarkSelected()),
-                                     m_actionCollection,
-                                     bm.url().url().utf8());
-                action->plug(m_toolBar);
-            }
-        }
-        else
-        {
-            KActionMenu *action = new KActionMenu(text, bm.icon(),
-                                                  m_actionCollection, \
                "bookmarkbar-actionmenu");
-            action->setDelayed(false);
-
-            // this flag doesn't have any UI yet
-            KGlobal::config()->setGroup( "Settings" );
-            bool addEntriesBookmarkBar = \
                KGlobal::config()->readBoolEntry("AddEntriesBookmarkBar",true);
-
-            KBookmarkMenu *menu = new KBookmarkMenu(m_pManager, m_pOwner, \
                action->popupMenu(),
-                                                    m_actionCollection, false, \
                addEntriesBookmarkBar,
-                                                    bm.address());
-            //menu->fillBookmarkMenu();
-            action->plug(m_toolBar);
-            m_lstSubMenus.append( menu );
-        }
+      m_toolBar->insertWidget( 0, 25, new KIPEToolBarButton( m_toolBar, bm, m_pOwner \
) );  }
+  }
 }
 
 void KBookmarkBar::slotBookmarkSelected()
Index: kbookmarkbar.h
===================================================================
RCS file: /home/kde/kdelibs/kio/bookmarks/kbookmarkbar.h,v
retrieving revision 1.14
diff -u -3 -p -r1.14 kbookmarkbar.h
--- kbookmarkbar.h	4 Mar 2002 13:40:28 -0000	1.14
+++ kbookmarkbar.h	28 Dec 2002 23:00:22 -0000
@@ -24,7 +24,12 @@
 #include <qptrlist.h>
 #include <kbookmark.h>
 
-class KToolBar;
+#include <ktoolbar.h>
+#include <qpopupmenu.h>
+#include <kiconloader.h>
+#include <ktoolbarbutton.h>
+#include <qstyle.h>
+#include <kbookmarkmanager.h>
 class KBookmarkMenu;
 class KBookmarkOwner;
 class KActionCollection;
@@ -40,12 +45,7 @@ class KBookmarkBar : public QObject
     Q_OBJECT
 public:
     /**
-     * Fills a bookmark toolbar
-     *
-     * @param owner implementation of the KBookmarkOwner interface (callbacks)
-     * @param toolBar toolbar to fill
-     * @param collec parent for the KActions OBSOLETE
-     * @param manager the bookmark manager
+     * Is a bookmark toolbar
      */
     KBookmarkBar( KBookmarkManager* mgr,
                   KBookmarkOwner *owner, KToolBar *toolBar,
@@ -68,6 +68,150 @@ private:
     KActionCollection *m_actionCollection;
     KBookmarkManager *m_pManager;
     QPtrList<KBookmarkMenu> m_lstSubMenus;
+};
+
+class KBookmarkPopup : public QPopupMenu 
+{
+  Q_OBJECT
+  public:
+    KBookmarkPopup(QPoint start, KBookmarkGroup & bm, KBookmarkOwner * owner) : \
QPopupMenu(), _owner(owner), _bm(bm) +    {
+      // kdDebug() << k_funcinfo << endl;
+
+      bookmarkOptions.insertItem( QString("delete"), this, SLOT( deleteBookmark() ) \
); +      
+      insertItems();
+      popup( start );
+    }
+
+    bool isCheckable()
+    {
+      return false;
+    }
+
+  private:
+    KBookmarkOwner * _owner;
+    
+    int selecteditem;
+    KBookmarkGroup & _bm;
+
+  protected:
+    QPopupMenu bookmarkOptions;
+    
+    void insertItems()
+    {
+      clear();
+      
+      int i = 0;
+      for (KBookmark bm = _bm.first(); !bm.isNull(); bm = _bm.next(bm))
+      {
+        QPixmap pm = KGlobal::iconLoader()->loadIcon( bm.icon() , KIcon::Toolbar);
+        insertItem( pm, bm.text(), this, SLOT( doNothing() ), i++ );
+      }
+    }
+    
+    virtual void mousePressEvent( QMouseEvent * e )
+    {
+      // kdDebug() << k_funcinfo << endl << "e->button()" << " = " << e->button() << \
endl; +      // kdDebug() << "Qt::RightButton" << " = " << Qt::RightButton << endl;
+      // kdDebug() << "Qt::LeftButton" << " = " << Qt::LeftButton << endl;
+
+      int item = itemAtPos( e->pos() );
+      switch ( e->button() )
+      {
+        case Qt::LeftButton:
+          // FIXME
+          _owner->openBookmarkURL( bookmarkFromItem(item).url().url() );
+          break;
+        case Qt::RightButton:
+          selecteditem = item;
+          bookmarkOptions.exec(e->globalPos());
+          break;
+        case Qt::MidButton:
+          break;
+      }
+      return;
+    }
+
+    KBookmark bookmarkFromItem(int item)
+    {
+        KBookmark bm;
+        int i = 0;
+        for (bm = _bm.first(); !bm.isNull(); bm = _bm.next(bm))
+        {
+          if (i == item) break;
+          i++;
+        }
+        assert(i == item);
+        return bm;
+    }
+		
+    public slots:
+      void deleteBookmark()
+      {
+        //kdDebug() << k_funcinfo << endl;
+        int i = 0;
+        KBookmark bm;
+        for (bm = _bm.first(); !bm.isNull(); bm = _bm.next(bm))
+        {
+          if (i == selecteditem) break;
+          i++;
+        }
+        if (i == selecteditem) bm.parentGroup().deleteBookmark( bm );
+
+        close(true);
+      };
+};
+
+class KIPEToolBarButton : public KToolBarButton
+{
+  Q_OBJECT
+  public:
+    KIPEToolBarButton(QWidget* w, KBookmark bm, KBookmarkOwner * owner)
+      : KToolBarButton( bm.icon(), 0, w, NULL, bm.text()) ,_bm(bm), _owner(owner)
+      {
+        //kdDebug() << k_funcinfo << endl;
+      }
+
+  private:
+    KBookmark _bm;
+    KBookmarkOwner * _owner;
+
+  protected:
+    void drawButton( QPainter *p)
+    {
+      KToolBarButton::drawButton(p);
+      if (! _bm.isNull())
+        if (_bm.isGroup())
+        {
+          QStyle::SFlags arrowFlags = QStyle::Style_Default;
+
+          if (isDown())       arrowFlags |= QStyle::Style_Down;
+          if (isEnabled())    arrowFlags |= QStyle::Style_Enabled;
+
+          style().drawPrimitive(QStyle::PE_ArrowDown, p,
+              QRect(width()-7, height()-7, 7, 7), colorGroup(),
+              arrowFlags, QStyleOption() );
+        }
+    }
+
+    virtual void mousePressEvent( QMouseEvent * me )
+    {
+      //kdDebug() << k_funcinfo << endl;
+
+      if (me->button() == Qt::RightButton)
+      {
+        return;
+      }
+
+      if (me->button() == Qt::LeftButton && _bm.isGroup() )
+      {
+        new KBookmarkPopup( QPoint( mapToGlobal( QPoint(0, height() ) ).x(), \
mapToGlobal( QPoint(0, height() ) ).y() ), (KBookmarkGroup&) _bm, _owner); +        \
return; +      }
+
+      KToolBarButton::mousePressEvent( me );
+    }
 };
 
 #endif // KBOOKMARKBAR_H


>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

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

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