From kde-core-devel Thu Jan 16 15:54:26 2003 From: Oelewapperke Date: Thu, 16 Jan 2003 15:54:26 +0000 To: kde-core-devel Subject: Re: in-place-editing patch for konqueror bookmarks X-MARC-Message: https://marc.info/?l=kde-core-devel&m=104273560200932 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_yWtJ+Tfn3xqPcAo" --Boundary-00=_yWtJ+Tfn3xqPcAo Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Description: clearsigned data Content-Disposition: inline -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wednesday 15 January 2003 16:23, David Faure wrote: > On Wednesday 15 January 2003 15:08, Oelewapperke wrote: > > indeed. I will post an additional patch to do that later. (btw I never > > ever use the menu except to get to "edit bookmarks"). > > But what matters is that it's implemented in a consistent and generic way. > Both KBookmarkBar and the bookmark menu use KBookmarkMenu - it's the > class for _any_ bookmark popupmenu (main menu or submenu). So I would > expect that most of the code goes in there. I have made a subclass of QPopupmenu to do this. I could easily make it inherit from KBookmarkMenu, but it would only introduce overhead as I'm not using any functionality of that class. > > I couldn't use the normal KToolbarButton drawing routines, as they need > > the button to show a QPopupmenu that is constructed ahead of time, > > something I don't do (and why should I ? It slows the startup time > > You can pass a new but empty QPopupMenu to KToolbatButton, and connect > to aboutToShow() (from QPopupMenu). This is what the KBookmarkMenu already > does. Which means you don't even have to do that. Simply do the changes in > KBookmarkMenu::refill() (which is called by slotAboutToShow()). > Or do I miss something? this isn't an option as refill() is not virtual, I can override it in a subclass, but it wouldn't get called at all. ipe_patch1 is for the directory kdelibs/kio/bookmarks the 2 files kipebookmarkbar.cc and .h also for that directory (I am sorry but I cannot cvs add, because I don't have write access) konq_patch is for kdebase/konqueror (right mouse menu is not yet implemented, but middle click to open in a new tab is (for the menu's) ) still needs quite a few fixes, cleanups and additions, but I am in the middle of my exams, and still learning about kde too, so it will probably take a while. Oelewapperke -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+JtWyJFU6C5Uo8MgRAlu1AKDWr92NKsddQVrYa+3ejB0SbUDA5ACbB6FY 3xTGaBlS2MdcNs5SZEVJKkU= =8AlR -----END PGP SIGNATURE----- --Boundary-00=_yWtJ+Tfn3xqPcAo Content-Type: text/x-diff; charset="iso-8859-1"; name="ipe_patch1" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="ipe_patch1" ? kipebookmarkbar.cc ? kipebookmarkbar.h Index: Makefile.am =================================================================== RCS file: /home/kde/kdelibs/kio/bookmarks/Makefile.am,v retrieving revision 1.1 diff -u -3 -p -b -r1.1 Makefile.am --- Makefile.am 4 Mar 2002 13:40:28 -0000 1.1 +++ Makefile.am 16 Jan 2003 15:47:15 -0000 @@ -27,8 +27,9 @@ METASOURCES = AUTO include_HEADERS = \ kbookmark.h kbookmarkbar.h kbookmarkdrag.h kbookmarkexporter.h \ - kbookmarkimporter.h kbookmarkmanager.h kbookmarkmenu.h kbookmarknotifier.h + kbookmarkimporter.h kbookmarkmanager.h kbookmarkmenu.h kbookmarknotifier.h \ + kipebookmarkbar.h libkbookmarks_la_SOURCES = \ kbookmark.cc kbookmarkbar.cc kbookmarkdrag.cc kbookmarkexporter.cc \ kbookmarkimporter.cc kbookmarkmanager.cc kbookmarkmenu.cc \ - kbookmarkmanager.skel kbookmarknotifier.skel + kbookmarkmanager.skel kbookmarknotifier.skel kipebookmarkbar.cc Index: kbookmarkmanager.h =================================================================== RCS file: /home/kde/kdelibs/kio/bookmarks/kbookmarkmanager.h,v retrieving revision 1.17 diff -u -3 -p -b -r1.17 kbookmarkmanager.h --- kbookmarkmanager.h 30 Mar 2002 07:13:27 -0000 1.17 +++ kbookmarkmanager.h 16 Jan 2003 15:47:15 -0000 @@ -266,4 +266,29 @@ protected: virtual void virtual_hook( int id, void* data ); }; +class KIPEBookmarkOwner : public KBookmarkOwner +{ +public: + /** + * These functions are called when a mouse event occurs over a bookmark + * by default, they do nothing. + * If they return "true" that means the user has given some sort of command, and you + * think the popupmenu should be closed + */ + virtual bool mousePressEvent ( KBookmark & b, QMouseEvent * e ) + { + return true; + } + + virtual bool mouseReleaseEvent ( KBookmark & b, QMouseEvent * e ) + { + return true; + } + + virtual bool mouseDoubleClickEvent ( KBookmark & b, QMouseEvent * e ) + { + return true; + } +}; + #endif --Boundary-00=_yWtJ+Tfn3xqPcAo Content-Type: text/x-c++src; charset="iso-8859-1"; name="kipebookmarkbar.cc" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kipebookmarkbar.cc" /* This file is part of the KDE project Copyright (C) 1999 Kurt Granroth Copyright (C) 1998, 1999 Torben Weis This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include KIPEBookmarkBar::KIPEBookmarkBar( KBookmarkManager* mgr, KIPEBookmarkOwner *_owner, KToolBar *_toolBar, KActionCollection *coll, QObject *parent, const char *name ) : QObject( parent, name ), m_pOwner(_owner), m_toolBar(_toolBar), m_actionCollection( coll ), m_pManager(mgr) { m_lstSubMenus.setAutoDelete( true ); connect( mgr, SIGNAL( changed(const QString &, const QString &) ), SLOT( slotBookmarksChanged(const QString &) ) ); KBookmarkGroup toolbar = mgr->toolbar(); fillBookmarkBar( toolbar ); } KIPEBookmarkBar::~KIPEBookmarkBar() { clear(); } void KIPEBookmarkBar::clear() { m_lstSubMenus.clear(); if ( m_toolBar ) m_toolBar->clear(); } void KIPEBookmarkBar::slotBookmarksChanged( const QString & group ) { KBookmarkGroup tb = m_pManager->toolbar(); if ( tb.isNull() ) return; if ( tb.address() == group ) { clear(); fillBookmarkBar( tb ); } else { // Iterate recursively into child menus QPtrListIterator it( m_lstSubMenus ); for (; it.current(); ++it ) { it.current()->slotBookmarksChanged( group ); } } } void KIPEBookmarkBar::fillBookmarkBar(KBookmarkGroup & parent) { if (parent.isNull()) return; for (KBookmark bm = parent.first(); !bm.isNull(); bm = parent.next(bm)) { QString text = bm.text(); text.replace( '&', "&&" ); if ( bm.isSeparator() ) m_toolBar->insertLineSeparator(); else { m_toolBar->insertWidget( 0, 25, new KIPEToolBarButton( m_toolBar, bm, m_pOwner ) ); } } } void KIPEBookmarkBar::slotBookmarkSelected() { if (!m_pOwner) return; // this view doesn't handle bookmarks... m_pOwner->openBookmarkURL(QString::fromUtf8(sender()->name())); } #include "kipebookmarkbar.moc" --Boundary-00=_yWtJ+Tfn3xqPcAo Content-Type: text/x-chdr; charset="iso-8859-1"; name="kipebookmarkbar.h" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kipebookmarkbar.h" /* This file is part of the KDE project Copyright (C) 1999 Kurt Granroth This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef KIPEBOOKMARKBAR_H #define KIPEBOOKMARKBAR_H #include #include #include #include #include #include #include #include #include #include class KBookmarkMenu; class KIPEBookmarkOwner; class KActionCollection; class KAction; /** * This class provides a bookmark toolbar. Using this class is nearly * identical to using @ref KBookmarkMenu so follow the directions * there. */ class KIPEBookmarkBar : public QObject { Q_OBJECT public: /** * Is a bookmark toolbar */ KIPEBookmarkBar( KBookmarkManager* mgr, KIPEBookmarkOwner *owner, KToolBar *toolBar, KActionCollection *, QObject *parent = 0L, const char *name = 0L); virtual ~KIPEBookmarkBar(); public slots: void slotBookmarksChanged( const QString & ); void slotBookmarkSelected(); void clear(); protected: void fillBookmarkBar( KBookmarkGroup & parent ); private: KIPEBookmarkOwner *m_pOwner; QGuardedPtr m_toolBar; KActionCollection *m_actionCollection; KBookmarkManager *m_pManager; QPtrList m_lstSubMenus; }; class KIPEBookmarkPopup : public QPopupMenu { Q_OBJECT public: KIPEBookmarkPopup(QPoint start, KBookmarkGroup & bm, KIPEBookmarkOwner * owner) : QPopupMenu(), _owner(owner), _bm(bm) { // kdDebug() << k_funcinfo << endl; insertItems(); popup( start ); } bool isCheckable() { return false; } private: KIPEBookmarkOwner * _owner; int selecteditem; KBookmarkGroup & _bm; protected: 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 ) { int item = itemAtPos( e->pos() ); KBookmark b(bookmarkFromItem(item)); if (_owner->mousePressEvent(b, e)) close(false); } // virtual void mouseReleaseEvent( QMouseEvent * e ) // { // int item = itemAtPos( e->pos() ); // KBookmark b(bookmarkFromItem(item)); // // if (_owner->mouseReleaseEvent(b, e)) close(true); // } virtual void mouseDoubleClickEvent( QMouseEvent * e ) { int item = itemAtPos( e->pos() ); KBookmark b(bookmarkFromItem(item)); if (_owner->mouseDoubleClickEvent(b, e)) close(false); } KBookmark bookmarkFromItem(const 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; } }; class KIPEToolBarButton : public KToolBarButton { Q_OBJECT public: KIPEToolBarButton(QWidget* w, KBookmark bm, KIPEBookmarkOwner * owner) : KToolBarButton( bm.icon(), 0, w, NULL, bm.text()) ,_bm(bm), _owner(owner) { //kdDebug() << k_funcinfo << endl; } private: KBookmark _bm; KIPEBookmarkOwner * _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 KIPEBookmarkPopup( QPoint( mapToGlobal( QPoint(0, height() ) ).x(), mapToGlobal( QPoint(0, height() ) ).y() ), (KBookmarkGroup&) _bm, _owner); return; } KToolBarButton::mousePressEvent( me ); } }; #endif // KIPEBOOKMARKBAR_H --Boundary-00=_yWtJ+Tfn3xqPcAo Content-Type: text/x-diff; charset="iso-8859-1"; name="konq_patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="konq_patch" ? preloader/Makefile.in Index: konq_mainwindow.cc =================================================================== RCS file: /home/kde/kdebase/konqueror/konq_mainwindow.cc,v retrieving revision 1.1083.2.3 diff -u -3 -p -b -r1.1083.2.3 konq_mainwindow.cc --- konq_mainwindow.cc 19 Dec 2002 10:58:13 -0000 1.1083.2.3 +++ konq_mainwindow.cc 16 Jan 2003 15:49:23 -0000 @@ -61,7 +61,7 @@ #include #include -#include +#include #include #include #include @@ -304,7 +304,7 @@ void KonqMainWindow::initBookmarkBar() if (!bar) return; if (m_paBookmarkBar) return; - m_paBookmarkBar = new KBookmarkBar( KonqBookmarkManager::self(), this, bar, m_bookmarkBarActionCollection, this ); + m_paBookmarkBar = new KIPEBookmarkBar( KonqBookmarkManager::self(), this, bar, m_bookmarkBarActionCollection, this ); // hide if empty if (bar->count() == 0 ) Index: konq_mainwindow.h =================================================================== RCS file: /home/kde/kdebase/konqueror/konq_mainwindow.h,v retrieving revision 1.374 diff -u -3 -p -b -r1.374 konq_mainwindow.h --- konq_mainwindow.h 8 Nov 2002 10:41:46 -0000 1.374 +++ konq_mainwindow.h 16 Jan 2003 15:49:23 -0000 @@ -40,6 +40,9 @@ #include "konq_combo.h" #include "konq_frame.h" +//FIXME only for debugging ... +#include + class QFile; class KAction; class KActionCollection; @@ -51,7 +54,7 @@ class KProgress; class KSelectAction; class KToggleAction; class KonqBidiHistoryAction; -class KBookmarkBar; +class KIPEBookmarkBar; class KonqView; class KonqComboAction; class KonqFrame; @@ -82,7 +85,7 @@ namespace KParts { class KonqMainWindow : public KParts::MainWindow, - virtual public KBookmarkOwner, + virtual public KIPEBookmarkOwner, public KonqFrameContainerBase { Q_OBJECT @@ -437,6 +440,29 @@ protected slots: void slotIconsChanged(); protected: + + // KIPEBookmarkOwner implementation + virtual bool mousePressEvent ( KBookmark & b, QMouseEvent * e ) + { + kdDebug() << "boem baby" << endl; + switch ( e->button() ) + { + case LeftButton: + openBookmarkURL(QString::fromUtf8(b.url().url().utf8())); + break; + case RightButton: + openBookmarkURL("www.newsforge.org"); + break; + case MidButton: + KonqOpenURLRequest req; + req.newTab = true; + req.newTabInFront = true; + openURL( 0L, QString::fromUtf8(b.url().url().utf8()), QString::null, req ); + break; + } + return true; // true = close the menu + } + static QString detectNameFilter( QString & url ); virtual bool eventFilter(QObject*obj,QEvent *ev); @@ -570,7 +596,7 @@ private: KonqLogoAction *m_paAnimatedLogo; - KBookmarkBar *m_paBookmarkBar; + KIPEBookmarkBar *m_paBookmarkBar; KAction * m_paFindFiles; KToggleAction *m_ptaUseHTML; --Boundary-00=_yWtJ+Tfn3xqPcAo--