From koffice-devel Sat Oct 23 03:49:37 2004 From: Thorsten Zachmann Date: Sat, 23 Oct 2004 03:49:37 +0000 To: koffice-devel Subject: kpresenter patch Message-Id: <200410230549.37900.t.zachmann () zagge ! de> X-MARC-Message: https://marc.info/?l=koffice-devel&m=109850369422392 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_RTdeB4p9eVr6/fv" --Boundary-00=_RTdeB4p9eVr6/fv Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello all, I have reworked the sidebar code of kpresenter. Thats what I did: o Let drag and dorp of slide in sidebar only generate an call to move the slide, but no longer move it itself. o Moving of slides no longer recreates all OutlineItems but moves the them, and updates the titles of the slides in between. All the changes together give a big speed up, as now the methods are only called once and are more effective. As I'm not the best at this gui stuff I would prefere I someone could have a look at the patch before I commit. Maybe there is a much easier way to archive this results. Thorsten --Boundary-00=_RTdeB4p9eVr6/fv Content-Type: text/x-diff; charset="us-ascii"; name="sidebar-nomove.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="sidebar-nomove.diff" ? .kpbackground.cc.swp ? .kppixmapobject.cc.swo ? .kprcanvas.cc.swm ? .kprcanvas.cc.swn ? .kprcanvas.cc.swo ? .kprcanvas.h.swo ? .kprcommand.cc.swn ? .kprcommand.cc.swo ? .kprcommand.h.swo ? .kpresenter_doc.cc.swp ? .kpresenter_doc.h.swp ? .kprpage.cc.swo ? .kprpage.h.swo ? .kptextobject.cc.swp ? .sidebar.h.swp ? .slidetransitiondia.cc.swo ? .slidetransitiondia.cc.swp ? .slidetransitiondia.h.swp ? .slidetransitionwidget.h.swp ? .swn ? .swo ? .swp ? .transeffectdia.cc.swp ? effecthandlernew.cc ? effecthandlernew.h ? kppieobject.cc.save Index: sidebar.cc =================================================================== RCS file: /home/kde/koffice/kpresenter/sidebar.cc,v retrieving revision 1.78 diff -u -3 -p -r1.78 sidebar.cc --- sidebar.cc 19 Oct 2004 08:44:21 -0000 1.78 +++ sidebar.cc 23 Oct 2004 03:36:31 -0000 @@ -94,6 +94,7 @@ public: void setPage( KPrPage* p ); void update(); + void updateTitle(); private: KPrPage* m_page; @@ -570,11 +571,7 @@ void OutlineSlideItem::update() { if( !m_page ) return; KPresenterDoc *doc = m_page->kPresenterDoc(); - int index = doc->pageList().findRef( m_page ); - QString title = m_page->pageTitle(); - if ( !doc->isSlideSelected( index ) ) - title = i18n( "(%1)" ).arg( title ); - setText( 0, title ); + updateTitle(); // add all objects OutlineObjectItem *ooi = 0; @@ -634,6 +631,13 @@ void OutlineSlideItem::update() (ooi->listView())->setSelected( ooi, true ); } +void OutlineSlideItem::updateTitle() +{ + QString title = m_page->pageTitle(); + if ( ! m_page->isSlideSelected() ) + title = i18n( "(%1)" ).arg( title ); + setText( 0, title ); +} OutlineObjectItem::OutlineObjectItem( OutlineSlideItem* parent, KPObject* _object, bool sticky, const QString& name ) @@ -725,8 +729,6 @@ Outline::Outline( QWidget *parent, KPres m_outlineTip = new OutlineToolTip(this); connect( this, SIGNAL( currentChanged( QListViewItem * ) ), this, SLOT( itemClicked( QListViewItem * ) ) ); - connect( this, SIGNAL( moved( QListViewItem *, QListViewItem *, QListViewItem * ) ), - this, SLOT( movedItems( QListViewItem *, QListViewItem *, QListViewItem * ) ) ); connect( this, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ), this, SLOT( rightButtonPressed( QListViewItem *, const QPoint &, int ) ) ); @@ -814,15 +816,32 @@ void Outline::moveItem( int oldPos, int int lowPage = oldPos > newPos ? newPos : oldPos; int highPage = oldPos < newPos ? newPos : oldPos; - // update, for all between lowPage & highPage - int page = lowPage; - OutlineSlideItem* item = slideItem( page ); - for( ; item ; ++page ) { - KPrPage* newPage = m_doc->pageList().at( page ); - item->setPage( newPage ); - item = dynamic_cast( item->nextSibling() ); - if ( page == highPage ) break; + OutlineSlideItem *item = dynamic_cast( firstChild() ); + QListViewItem *itemToMove = 0; + QListViewItem *itemAfter = 0; + + // moving backwards + if ( newPos < oldPos ) + newPos--; + + for ( int index = 0; item; ++index, item = dynamic_cast( item->nextSibling() ) ) + { + if ( index == oldPos ) + itemToMove = item; + if ( index == newPos ) + itemAfter = item; + if ( index >= lowPage && index <= highPage ) + item->updateTitle(); + } + + if ( itemAfter == 0 ) + { + QListViewItem *first = firstChild(); + itemToMove->moveItem( first ); + itemAfter = itemToMove; + itemToMove = first; } + itemToMove->moveItem( itemAfter ); } void Outline::removeItem( int pos ) @@ -918,41 +937,88 @@ void Outline::contentsDropEvent( QDropEv connect( this, SIGNAL( currentChanged( QListViewItem * ) ), this, SLOT( itemClicked( QListViewItem * ) ) ); } -// when item is about to move (using drag-and-drop), make sure: -// it's not moved right after object. only slides can move, objects can't. +/** + * The method no longer moves the item by itself. I just calls m_doc->movePage + * which then moves the item. At the moment the method only works as long as + * only one object is moves. + * When an item is about to move (using drag-and-drop), it makes shure that + * it's not moved right after an object. + */ void Outline::movableDropEvent( QListViewItem* parent, QListViewItem* target ) { - // slide doesn't have parent (always 0) - if( parent ) return; + /* slide doesn't have parent (always 0) + * Only slides can move at the moment, objects can't. */ + if ( parent ) + return; - KListView::movableDropEvent( parent, target ); -} + // This code is taken from KListView + QPtrList items, afterFirsts, afterNows; + QListViewItem *current=currentItem(); + bool hasMoved=false; + for (QListViewItem *i = firstChild(), *iNext=0; i != 0; i = iNext) + { + iNext=i->itemBelow(); + if (!i->isSelected()) + continue; -void Outline::movedItems( QListViewItem *i, QListViewItem *, QListViewItem *newAfter ) -{ - m_movedItem = i; - m_movedAfter = newAfter; - QTimer::singleShot( 300, this, SLOT( doMoveItems() ) ); + // don't drop an item after itself, or else + // it moves to the top of the list + if (i==target) + continue; + + i->setSelected(false); + + QListViewItem *afterFirst = i->itemAbove(); + + if (!hasMoved) + { + emit aboutToMove(); + hasMoved=true; + } + + // don't move the item as it is allready + moveItem(i, parent, target); + + emit moved(i, afterFirst, target); + + items.append (i); + afterFirsts.append (afterFirst); + afterNows.append (target); + + target = i; + // We only allow to select on object so we break after we have moved it + // otherwise it might move to object twice. + break; + } + + emit moved(items,afterFirsts,afterNows); + + if (firstChild()) + emit moved(); } -void Outline::doMoveItems() +void Outline::moveItem( QListViewItem *i, QListViewItem *, QListViewItem *newAfter ) { - OutlineSlideItem* srcItem = dynamic_cast(m_movedItem); - if( !srcItem ) return; + OutlineSlideItem* srcItem = dynamic_cast( i ); + if( !srcItem ) + return; int num = m_doc->pageList().findRef( srcItem->page() ); - OutlineSlideItem* dstItem = dynamic_cast(m_movedAfter); - if( m_movedAfter && !dstItem ) return; - - int numNow = m_movedAfter ? m_doc->pageList().findRef( dstItem->page() ) : -1; - if ( numNow < num ) numNow++; + int numNow = 0; + if ( newAfter ) + { + OutlineSlideItem* dstItem = dynamic_cast( newAfter ); + if( !dstItem ) + return; - if(num!=numNow) { - emit movePage( num, numNow ); - // this has to be done because moving a page is take + insert the page - setSelected( m_movedItem, true ); + numNow = m_doc->pageList().findRef( dstItem->page() ); + if ( numNow < num ) + numNow++; } + + if( num!=numNow ) + m_doc->movePage( num, numNow ); } void Outline::rightButtonPressed( QListViewItem *, const QPoint &pnt, int ) Index: sidebar.h =================================================================== RCS file: /home/kde/koffice/kpresenter/sidebar.h,v retrieving revision 1.29 diff -u -3 -p -r1.29 sidebar.h --- sidebar.h 19 Oct 2004 08:44:21 -0000 1.29 +++ sidebar.h 23 Oct 2004 03:36:31 -0000 @@ -95,6 +95,7 @@ public: protected: void contentsDropEvent( QDropEvent *e ); void movableDropEvent( QListViewItem* parent, QListViewItem* target ); + void moveItem( QListViewItem *i, QListViewItem *firstAfter, QListViewItem *newAfter ); OutlineSlideItem* slideItem( int pageNumber ); signals: // all page numbers 0-based @@ -109,8 +110,6 @@ public slots: private slots: void itemClicked( QListViewItem *i ); void rightButtonPressed( QListViewItem *i, const QPoint &pnt, int c ); - void movedItems( QListViewItem *i, QListViewItem *firstAfter, QListViewItem *newAfter ); - void doMoveItems(); private: KPresenterDoc *m_doc; --Boundary-00=_RTdeB4p9eVr6/fv Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ koffice-devel mailing list koffice-devel@kde.org https://mail.kde.org/mailman/listinfo/koffice-devel --Boundary-00=_RTdeB4p9eVr6/fv--