void BookmarksSidebarPage::connectToActiveView()
{
    DolphinView* view = Dolphin::mainWin().activeView();
    adjustSelection(view->url());
    connect(view, SIGNAL(signalURLChanged(const KURL&)),
            this, SLOT(slotURLChanged(const KURL&)));
}
Exemplo n.º 2
0
void roomEditorCursor(selection_struct* sel)
{
	if(!sel)sel=&editorSelection;
	if((keysDown() & KEY_TOUCH) && !(sel->entity && !sel->entity->placed))
	{
		u8 type;
		void* ptr=getBlockEntityTouch(&type);
		if(sel->entity && sel->selectingTarget)
		{
			if(type)
			{
				sel->selectingTarget=false;
				sel->entity->target=(entity_struct*)ptr;
				cleanUpContextButtons();
			}
		}else{
			if(type)
			{
				//entity
				entity_struct* e=(entity_struct*)ptr;

				undoSelection(sel);
				sel->active=true;
				sel->selecting=false;
				sel->selectingTarget=false;
				sel->entity=e;
			}else{
				//blockface
				blockFace_struct* bf=(blockFace_struct*)ptr;

				if(bf)
				{
					if(sel->active && isFaceInSelection(bf, sel))
					{
						sel->currentFace=bf;
						sel->currentPosition=vect(bf->x,bf->y,bf->z);
						sel->selecting=false;
						sel->selectingTarget=false;
					}else{
						undoSelection(sel);
						sel->firstFace=sel->secondFace=bf;
						sel->active=true;
						sel->selecting=true;
						sel->selectingTarget=false;
					}
					sel->entity=NULL;
				}else{
					undoSelection(sel);
				}
			}			
		}
	}else if(keysHeld() & KEY_TOUCH)
	{
		if(sel->active && !(sel->entity && sel->selectingTarget))
		{
			if(sel->entity)
			{
				blockFace_struct* bf=getBlockFaceTouch(NULL);
				if(bf)
				{
					sel->error=!moveEntityToBlockFace(sel->entity, bf);
				}
			}else{
				if(sel->selecting)
				{
					blockFace_struct* bf=getBlockFaceTouch(NULL);
					if(bf)sel->secondFace=bf;
				}else{
					blockFace_struct* bf=sel->currentFace;
					bool fill=true;
					vect3D p=getDragPosition(bf, lineOfTouchOrigin, lineOfTouchVector, lineOfTouchVector);
					p=vect((p.x+(ROOMARRAYSIZEX*BLOCKSIZEX+BLOCKSIZEX)/2)/BLOCKSIZEX,(p.y+(ROOMARRAYSIZEY*BLOCKSIZEY+BLOCKSIZEY)/2)/BLOCKSIZEY,(p.z+(ROOMARRAYSIZEZ*BLOCKSIZEZ+BLOCKSIZEZ)/2)/BLOCKSIZEZ);
					
					switch(bf->direction)
					{
						case 0:  p.y=bf->y; p.z=bf->z; fill=p.x>sel->currentPosition.x; break;
						case 1:  p.y=bf->y; p.z=bf->z; fill=p.x<sel->currentPosition.x; break;
						case 2:  p.x=bf->x; p.z=bf->z; fill=p.y>sel->currentPosition.y; break;
						case 3:  p.x=bf->x; p.z=bf->z; fill=p.y<sel->currentPosition.y; break;
						case 4:  p.x=bf->x; p.y=bf->y; fill=p.z>sel->currentPosition.z; break;
						default: p.x=bf->x; p.y=bf->y; fill=p.z<sel->currentPosition.z; break;
					}

					if(p.x!=sel->currentPosition.x || p.y!=sel->currentPosition.y || p.z!=sel->currentPosition.z)
					{
						blockFace_struct oldFirstFace=*sel->firstFace;
						blockFace_struct oldSecondFace=*sel->secondFace;
						blockFace_struct oldCurrentFace=*sel->currentFace;

						vect3D v=vectDifference(p, sel->currentPosition);
						vect3D o=(bf->direction%2)?(sel->origin):(adjustVectForNormal(bf->direction, sel->origin)); vect3D s=v;
						fixOriginSize(&o, &s); s=adjustVectForNormal((bf->direction%2)?(bf->direction):(oppositeDirection[bf->direction]), addVect(s,sel->size));
						vect3D oe=adjustVectForNormal(bf->direction, sel->origin); vect3D se=sel->size;

						moveEntitiesRange(oe, se, v);
						if(fill)fillBlockArrayRange(editorRoom.blockArray, &editorRoom.blockFaceList, o, s);
						else emptyBlockArrayRange(editorRoom.blockArray, &editorRoom.blockFaceList, o, s);
						getEntityBlockFacesRange(editorRoom.blockFaceList, addVect(oe,v), se, true);

						adjustSelection(&editorRoom, sel, oldFirstFace, oldSecondFace, oldCurrentFace, v);
						sel->currentPosition=p;
					}
				}
			}
		}else{
			if(abs(oldTouch.px-currentTouch.px)>2)rotateMatrixY(editorCamera.transformationMatrix, -TOUCHSPEEDX*(oldTouch.px-currentTouch.px), true);
			if(abs(oldTouch.py-currentTouch.py)>2)rotateMatrixX(editorCamera.transformationMatrix, -TOUCHSPEEDY*(oldTouch.py-currentTouch.py), false);
		}
	}else if(keysUp() & KEY_TOUCH)
	{
		if(sel->active)
		{
			if(sel->entity && sel->entity->type)
			{
				if(!sel->selectingTarget)setupContextButtons(sel->entity->type->contextButtonsArray, sel->entity->type->numButtons);
				else setupContextButtons(targetSelectionButtonArray, 2);
			}else if(sel->planar && sel->firstFace && (sel->firstFace->direction==2 || sel->firstFace->direction==3))setupContextButtons(groundSelectionButtonArray, 4);
			else if(sel->planar)setupContextButtons(planarSelectionButtonArray, 2);
			else setupContextButtons(nonplanarSelectionButtonArray, 4);
		}
	}
}
void BookmarksSidebarPage::slotContextMenuRequested(QListBoxItem* item,
                                                    const QPoint& pos)
{
    const int insertID = 1;
    const int editID = 2;
    const int deleteID = 3;
    const int addID = 4;

    QPopupMenu* popup = new QPopupMenu();
    if (item == 0) {
        popup->insertItem(SmallIcon("filenew"), i18n("Add Bookmark..."), addID);
    }
    else {
        popup->insertItem(SmallIcon("filenew"), i18n("Insert Bookmark..."), insertID);
        popup->insertItem(SmallIcon("edit"), i18n("Edit..."), editID);
        popup->insertItem(SmallIcon("editdelete"), i18n("Delete"), deleteID);
    }

    KBookmarkManager* manager = DolphinSettings::instance().bookmarkManager();
    KBookmarkGroup root = manager->root();
    const int index = m_bookmarksList->index(m_bookmarksList->selectedItem());

    const int result = popup->exec(pos);
    switch (result) {
        case insertID: {
            KBookmark newBookmark = EditBookmarkDialog::getBookmark(i18n("Insert Bookmark"),
                                                                    i18n("New bookmark"),
                                                                    KURL(),
                                                                    "bookmark");
            if (!newBookmark.isNull()) {
                root.addBookmark(manager, newBookmark);
                if (index > 0) {
                    KBookmark prevBookmark = DolphinSettings::instance().bookmark(index - 1);
                    root.moveItem(newBookmark, prevBookmark);
                }
                else {
                    // insert bookmark at first position (is a little bit tricky as KBookmarkGroup
                    // only allows to move items after existing items)
                    KBookmark firstBookmark = root.first();
                    root.moveItem(newBookmark, firstBookmark);
                    root.moveItem(firstBookmark, newBookmark);
                }
                manager->emitChanged(root);
            }
            break;
        }

        case editID: {
            KBookmark oldBookmark = DolphinSettings::instance().bookmark(index);
            KBookmark newBookmark = EditBookmarkDialog::getBookmark(i18n("Edit Bookmark"),
                                                                    oldBookmark.text(),
                                                                    oldBookmark.url(),
                                                                    oldBookmark.icon());
            if (!newBookmark.isNull()) {
                root.addBookmark(manager, newBookmark);
                root.moveItem(newBookmark, oldBookmark);
                root.deleteBookmark(oldBookmark);
                manager->emitChanged(root);
            }
            break;
        }

        case deleteID: {
            KBookmark bookmark = DolphinSettings::instance().bookmark(index);
            root.deleteBookmark(bookmark);
            manager->emitChanged(root);
            break;
        }

        case addID: {
            KBookmark bookmark = EditBookmarkDialog::getBookmark(i18n("Add Bookmark"),
                                                                 "New bookmark",
                                                                 KURL(),
                                                                 "bookmark");
            if (!bookmark.isNull()) {
                root.addBookmark(manager, bookmark);
                manager->emitChanged(root);
            }
        }

        default: break;
    }

    delete popup;
    popup = 0;

    DolphinView* view = Dolphin::mainWin().activeView();
    adjustSelection(view->url());
}
void BookmarksSidebarPage::slotURLChanged(const KURL& url)
{
    adjustSelection(url);
}