Beispiel #1
0
void KWDocStructRootItem::setupTextFrameSets()
{

    // Delete Empty item from list.
    QListViewItem* lvItem = firstChild();
    if (lvItem && (lvItem->text(0) == i18n("Empty"))) delete lvItem;

    // Build a list of framesets ordered by their screen position (top left corner).
    KWDocument* dok = doc();
    QValueList<KWOrderedFrameSet> orderedFrameSets;
    for ( int i = dok->frameSetCount() - 1; i >= 0; i-- ) {
        KWFrameSet* frameset = dok->frameSet(i);
        if ( frameset->type() == FT_TEXT && frameset->frameSetInfo() == KWFrameSet::FI_BODY &&
            !frameset->groupmanager() && frameset->frameCount()>0)

            orderedFrameSets.append(KWOrderedFrameSet(frameset));
    }
    qHeapSort(orderedFrameSets);

    // Build a list of frameset pointers from the sorted list.
    QPtrList<KWTextFrameSet> frameSetPtrs;
    frameSetPtrs.setAutoDelete(false);
    for ( uint i = 0; i < orderedFrameSets.count(); i++ )
        frameSetPtrs.append(dynamic_cast<KWTextFrameSet *>(orderedFrameSets[i].frameSet()));

    // Remove deleted framesets from the listview.
    KWDocStructTextFrameSetItem* item = dynamic_cast<KWDocStructTextFrameSetItem *>(firstChild());
    KWDocStructTextFrameSetItem* delItem;
    while (item) {
        delItem = item;
        item = dynamic_cast<KWDocStructTextFrameSetItem *>(item->nextSibling());
        if (frameSetPtrs.containsRef(delItem->frameSet()) == 0) delete delItem;
    }

    // Add new framesets to the list or update existing ones.
    KWDocStructTextFrameSetItem* after = 0L;
    for ( uint i = 0; i < orderedFrameSets.count(); i++ )
    {
        KWTextFrameSet* textFrameset = dynamic_cast<KWTextFrameSet *>(orderedFrameSets[i].frameSet());
        item = findTextFrameSetItem(textFrameset);
        if (item)
            item->setText(0, textFrameset->name());
        else {
            if (after)
                item = new KWDocStructTextFrameSetItem(
                    this, after, textFrameset->name(), textFrameset);
            else
                item = new KWDocStructTextFrameSetItem(this, textFrameset->name(), textFrameset);
        }
        after = item;
        item->setupTextFrames();
    }

    if ( childCount() == 0 )
        ( void )new KListViewItem( this, i18n( "Empty" ) );
}
Beispiel #2
0
void KWDocStructTableItem::setupCells()
{
    // TODO: KWTableFrameSet::cell() method returns cells in screen order?
    // Build a list of cell pointers.
    QPtrList<KWTextFrameSet> cellPtrs;
    cellPtrs.setAutoDelete(false);
    for (uint row = 0; row < m_table->getRows(); ++row)
        for (uint col = 0; col < m_table->getColumns(); ++ col) {
            KWTextFrameSet* cell = m_table->cell(row, col);
            if (cell)
                cellPtrs.append(cell);
        }

    // Remove deleted cells from the listview.
    KWDocStructTextFrameItem* item = dynamic_cast<KWDocStructTextFrameItem *>(firstChild());
    KWDocStructTextFrameItem* delItem;
    while (item) {
        delItem = item;
        item = dynamic_cast<KWDocStructTextFrameItem *>(item->nextSibling());
        if (cellPtrs.containsRef(delItem->frameSet()) == 0) delete delItem;
    }

    // Add new cells to the list or update existing ones.
    // Note we skip over the frameset and add the frame instead,
    // as every cell has exactly one frame in the frameset.
    KWDocStructTextFrameItem* child;
    KWDocStructTextFrameItem* after = 0;
    for (uint j = 0; j < cellPtrs.count(); j++)
    {
        KWTextFrameSet* cell = cellPtrs.at(j);
        KWFrame* frame = cell->frame(0);
        if (frame) {
            QString name = cell->name();
            child = findCellItem(cell);
            if (child)
                child->setText(0, name);
            else {
                if (after)
                    child = new KWDocStructTextFrameItem(this, after, name, cell, frame);
                else
                    child = new KWDocStructTextFrameItem(this, name, cell, frame);
            }
            child->setupTextParags();
            after = child;
        }
    }
}
Beispiel #3
0
void KWDocStructTextFrameSetItem::setupTextFrames()
{
    // TODO: KWTextFrameSet::frame() method returns frames in screen order?
    // Build a list of frame pointers.
    QPtrList<KWFrame> framePtrs;
    framePtrs.setAutoDelete(false);
    for (uint j = 0; j < m_frameset->frameCount(); j++)
        framePtrs.append(m_frameset->frame(j));

    // Remove deleted frames from the listview.
    KWDocStructTextFrameItem* item = dynamic_cast<KWDocStructTextFrameItem *>(firstChild());
    KWDocStructTextFrameItem* delItem;
    while (item) {
        delItem = item;
        item = dynamic_cast<KWDocStructTextFrameItem *>(item->nextSibling());
        if (framePtrs.containsRef(delItem->frame()) == 0) delete delItem;
    }

    // Add new frames to the list or update existing ones.
    KWDocument* dok = doc();
    KWDocStructTextFrameItem* after = 0;
    for (uint j = 0; j < framePtrs.count(); j++)
    {
        KWFrame* frame = framePtrs.at(j);
        QString name;
        if ( KListViewItem::parent()->firstChild() == this && dok->processingType() == KWDocument::WP )
        {
            if ( dok->numColumns() == 1 )
                name=i18n( "Page %1" ).arg(QString::number(j + 1));
            else
                name=i18n( "Column %1" ).arg(QString::number(j + 1));
        }
        else
            name=i18n( "Text Frame %1" ).arg(QString::number(j + 1));
        KWDocStructTextFrameItem* child = findTextFrameItem(frame);
        if (child)
            child->setText(0, name);
        else {
            if (after)
                child = new KWDocStructTextFrameItem(this, after, name, m_frameset, frame);
            else
                child = new KWDocStructTextFrameItem(this, name, m_frameset, frame);
        }
        child->setupTextParags();
        after = child;
    }
}
ChatSession* ChatSessionManager::findChatSession(const Contact *user,
		ContactPtrList chatContacts, Protocol *protocol)
{
	ChatSession *result = 0L;
	QValueList<ChatSession*>::Iterator it;
	for ( it= d->sessions.begin(); it!=d->sessions.end() && !result ; ++it  )
	{
	  ChatSession* cs=(*it);
	  if ( cs->protocol() == protocol && user == cs->myself() )
		{
			QPtrList<Contact> contactlist = cs->members();

			// set this to false if chatContacts doesn't contain current cs's contactlist
			bool halfMatch = true;

			Contact *tmpContact;
			for (tmpContact = contactlist.first(); tmpContact && halfMatch; tmpContact = contactlist.next())
			{
				if ( !chatContacts.containsRef( tmpContact ) )
					halfMatch = false;
			}

			// If chatContacts contains current cs's contactlist, try the other way around
			if (halfMatch)
			{
				bool fullMatch = true;
				for (tmpContact = chatContacts.first(); tmpContact && fullMatch; tmpContact = chatContacts.next())
				{
					if ( !contactlist.containsRef( tmpContact ) )
						fullMatch = false;
				}
				// We have a winner
				if (fullMatch)
					result = cs;
			}
		}
	}
	return result;
}
Beispiel #5
0
void RenderCanvas::setSelection(RenderObject *s, int sp, RenderObject *e, int ep)
{
    // Check we got valid renderobjects. www.msnbc.com and clicking
    // around, to find the case where this happened.
    if ( !s || !e )
    {
        kdWarning(6040) << "RenderCanvas::setSelection() called with start=" << s << " end=" << e << endl;
        return;
    }
//     kdDebug( 6040 ) << "RenderCanvas::setSelection(" << s << "," << sp << "," << e << "," << ep << ")" << endl;

    bool changedSelectionBorder = ( s != m_selectionStart || e != m_selectionEnd );

    // Cut out early if the selection hasn't changed.
    if ( !changedSelectionBorder && m_selectionStartPos == sp && m_selectionEndPos == ep )
        return;

    // Record the old selected objects.  Will be used later
    // to delta against the selected objects.

    RenderObject *oldStart = m_selectionStart;
    int oldStartPos = m_selectionStartPos;
    RenderObject *oldEnd = m_selectionEnd;
    int oldEndPos = m_selectionEndPos;
    QPtrList<RenderObject> oldSelectedInside;
    QPtrList<RenderObject> newSelectedInside;
    RenderObject *os = oldStart;

    while (os && os != oldEnd)
    {
        RenderObject* no;
        if ( !(no = os->firstChild()) ){
            if ( !(no = os->nextSibling()) )
            {
                no = os->parent();
                while (no && !no->nextSibling())
                    no = no->parent();
                if (no)
                    no = no->nextSibling();
            }
        }
        if (os->selectionState() == SelectionInside && !oldSelectedInside.containsRef(os))
            oldSelectedInside.append(os);

        os = no;
    }
    if (changedSelectionBorder)
        clearSelection(false);

    while (s->firstChild())
        s = s->firstChild();
    while (e->lastChild())
        e = e->lastChild();

#if 0
    bool changedSelectionBorder = ( s != m_selectionStart || e != m_selectionEnd );

    if ( !changedSelectionBorder && m_selectionStartPos == sp && m_selectionEndPos = ep )
        return;
#endif

    // set selection start
    if (m_selectionStart)
        m_selectionStart->setIsSelectionBorder(false);
    m_selectionStart = s;
    if (m_selectionStart)
        m_selectionStart->setIsSelectionBorder(true);
    m_selectionStartPos = sp;

    // set selection end
    if (m_selectionEnd)
        m_selectionEnd->setIsSelectionBorder(false);
    m_selectionEnd = e;
    if (m_selectionEnd)
        m_selectionEnd->setIsSelectionBorder(true);
    m_selectionEndPos = ep;

#if 0
    kdDebug( 6040 ) << "old selection (" << oldStart << "," << oldStartPos << "," << oldEnd << "," << oldEndPos << ")" << endl;
    kdDebug( 6040 ) << "new selection (" << s << "," << sp << "," << e << "," << ep << ")" << endl;
#endif

    // update selection status of all objects between m_selectionStart and m_selectionEnd
    RenderObject* o = s;

    while (o && o!=e)
    {
        o->setSelectionState(SelectionInside);
//      kdDebug( 6040 ) << "setting selected " << o << ", " << o->isText() << endl;
        RenderObject* no;
        if ( !(no = o->firstChild()) )
            if ( !(no = o->nextSibling()) )
            {
                no = o->parent();
                while (no && !no->nextSibling())
                    no = no->parent();
                if (no)
                    no = no->nextSibling();
            }
        if (o->selectionState() == SelectionInside && !newSelectedInside.containsRef(o))
            newSelectedInside.append(o);

        o=no;
    }
    s->setSelectionState(SelectionStart);
    e->setSelectionState(SelectionEnd);
    if(s == e) s->setSelectionState(SelectionBoth);

    if (!m_view)
        return;

    newSelectedInside.removeRef(s);
    newSelectedInside.removeRef(e);

    QRect updateRect;

    // Don't use repaint() because it will cause all rects to
    // be united (see khtmlview::scheduleRepaint()).  Instead
    // just draw damage rects for objects that have a change
    // in selection state.
    // ### for Qt, updateContents will unite them, too. This has to be
    // circumvented somehow (LS)

    // Are any of the old fully selected objects not in the new selection?
    // If so we have to draw them.
    // Could be faster by building list of non-intersecting rectangles rather
    // than unioning rectangles.
    QPtrListIterator<RenderObject> oldIterator(oldSelectedInside);
    bool firstRect = true;
    for (; oldIterator.current(); ++oldIterator){
        if (!newSelectedInside.containsRef(oldIterator.current())){
            if (firstRect){
                updateRect = enclosingPositionedRect(oldIterator.current());
                firstRect = false;
            }
            else
                updateRect = updateRect.unite(enclosingPositionedRect(oldIterator.current()));
        }
    }
    if (!firstRect){
        m_view->updateContents( updateRect );
    }

    // Are any of the new fully selected objects not in the previous selection?
    // If so we have to draw them.
    // Could be faster by building list of non-intersecting rectangles rather
    // than unioning rectangles.
    QPtrListIterator<RenderObject> newIterator(newSelectedInside);
    firstRect = true;
    for (; newIterator.current(); ++newIterator){
        if (!oldSelectedInside.containsRef(newIterator.current())){
            if (firstRect){
                updateRect = enclosingPositionedRect(newIterator.current());
                firstRect = false;
            }
            else
                updateRect = updateRect.unite(enclosingPositionedRect(newIterator.current()));
        }
    }
    if (!firstRect) {
        m_view->updateContents( updateRect );
    }

    // Is the new starting object different, or did the position in the starting
    // element change?  If so we have to draw it.
    if (oldStart != m_selectionStart ||
        (oldStart == oldEnd && (oldStartPos != m_selectionStartPos || oldEndPos != m_selectionEndPos)) ||
        (oldStart == m_selectionStart && oldStartPos != m_selectionStartPos)){
        m_view->updateContents( enclosingPositionedRect(m_selectionStart) );
    }

    // Draw the old selection start object if it's different than the new selection
    // start object.
    if (oldStart && oldStart != m_selectionStart){
        m_view->updateContents( enclosingPositionedRect(oldStart) );
    }

    // Does the selection span objects and is the new end object different, or did the position
    // in the end element change?  If so we have to draw it.
    if (/*(oldStart != oldEnd || !oldEnd) &&*/
        (oldEnd != m_selectionEnd ||
        (oldEnd == m_selectionEnd && oldEndPos != m_selectionEndPos))){
        m_view->updateContents( enclosingPositionedRect(m_selectionEnd) );
    }

    // Draw the old selection end object if it's different than the new selection
    // end object.
    if (oldEnd && oldEnd != m_selectionEnd){
        m_view->updateContents( enclosingPositionedRect(oldEnd) );
    }
}
Beispiel #6
0
void KWDocStructTextFrameItem::setupTextParags()
{
    // Build a list of pointers to paragraphs.
    QPtrList<KWTextParag> paragPtrs;
    paragPtrs.setAutoDelete(false);
    KoTextParag* textParag = 0;
    KoTextParag* lastParag = 0;
    int index = 0;
    // Get upper left corner of the frame and get coordinates just inside it.
    KoPoint dPoint = m_frame->topLeft() + KoPoint(2,2);
    // Get the first paragraph of the frame.
    m_frameset->findPosition(dPoint, textParag, index);
    // Get lower right corner of the frame and get coordinate just inside it.
    dPoint = m_frame->bottomRight() - KoPoint(2,2);
    // Get the last paragraph of the frame.
    m_frameset->findPosition(dPoint, lastParag, index);
    if (lastParag) {
        while (textParag) {
            KWTextParag* parag = dynamic_cast<KWTextParag *>(textParag);
            if (parag) {
                // Don't display an empty paragraph.
                QString text = parag->toString().stripWhiteSpace();
                if ( text.length() > 0)
                    paragPtrs.append(parag);
            }
            if (textParag == lastParag)
                textParag = 0;
            else
                textParag = textParag->next();
        }
    }

    // Remove deleted paragraphs from the listview.
    KWDocStructParagItem* item = dynamic_cast<KWDocStructParagItem *>(firstChild());
    KWDocStructParagItem* delItem;
    while (item) {
        delItem = item;
        item = dynamic_cast<KWDocStructParagItem *>(item->nextSibling());
        if (paragPtrs.containsRef(delItem->parag()) == 0) delete delItem;
    }

    // Add new paragraphs to the list or update existing ones.
    KWDocStructParagItem* after = 0;
    for (uint j = 0; j < paragPtrs.count(); j++) {
        KWTextParag* parag = paragPtrs.at(j);
        QString text = parag->toString().stripWhiteSpace();
        QString name = text.left(20);
        KoParagCounter* tmpCounter = parag->counter();
        if (tmpCounter)
            name.prepend(tmpCounter->text(parag) + " ");
        KWDocStructParagItem* child = findTextParagItem(parag);
        if (child)
            child->setText(0, name);
        else {
            if (after)
                child = new KWDocStructParagItem(this, after, name, parag);
            else
                child = new KWDocStructParagItem(this, name, parag);
        }
        after = child;
    }
}