void MainWindow::createActions() { openAct = new QAction(tr("&Open"), this); openAct->setToolTip(tr("Open an image")); actionsManager->addAction(openAct, "_open", this, this, SLOT(open()), QKeySequence::Open); saveAct = new QAction(tr("&Save"), this); saveAct->setEnabled(false); actionsManager->addAction(saveAct, "_save", this, this, SLOT(save()), QKeySequence::Save); exitAct = new QAction(tr("&Exit"), this); actionsManager->addAction(exitAct, "_exit", this, this, SLOT(close()), QKeySequence::Quit); filePropertiesAct = new QAction(tr("Properties"), this); filePropertiesAct->setEnabled(false); actionsManager->addAction(filePropertiesAct, "_fileProperties", this, this, SLOT(fileProperties()), QKeySequence("Ctrl+.")); zoomInAct = new QAction(tr("Zoom In"), this); zoomInAct->setEnabled(false); actionsManager->addAction(zoomInAct, "_zoomIn", this, this, SLOT(zoomIn()), QKeySequence("+")); zoomOutAct = new QAction(tr("Zoom Out"), this); zoomOutAct->setEnabled(false); actionsManager->addAction(zoomOutAct, "_zoomOut", this, this, SLOT(zoomOut()), QKeySequence("-")); normalSizeAct = new QAction(tr("Normal Size"), this); normalSizeAct->setEnabled(false); actionsManager->addAction(normalSizeAct, "_normalSize", this, this, SLOT(normalSize()), QKeySequence("1")); adjustSizeAct = new QAction(tr("Best Fit"), this); adjustSizeAct->setEnabled(false); adjustSizeAct->setCheckable(true); actionsManager->addAction(adjustSizeAct, "_adjustSize", this, this, SLOT(adjustSizeSlot()), QKeySequence("0")); rotateRightAct = new QAction(tr("Rotate to right"), this); rotateRightAct->setToolTip(tr("Rotate image in the clockwise clock")); rotateRightAct->setEnabled(false); actionsManager->addAction(rotateRightAct, "_rotateRight", this, this, SLOT(rotateRight())); rotateLeftAct = new QAction(tr("Rotate to Left"), this); rotateLeftAct->setToolTip(tr("Rotate image counter-clockwise to clockwise")); rotateLeftAct->setEnabled(false); actionsManager->addAction(rotateLeftAct, "_rotateLeft", this, this, SLOT(rotateLeft())); flipVerticallyAct = new QAction(tr("Flip vertically"), this); flipVerticallyAct->setToolTip(tr("Turns vertically the image")); flipVerticallyAct->setEnabled(false); actionsManager->addAction(flipVerticallyAct, "_flipVertically", this, this, SLOT(flipVertically())); flipHorizontallyAct = new QAction(tr("Flip horizontally"), this); flipHorizontallyAct->setToolTip(tr("Reflects the image")); flipHorizontallyAct->setEnabled(false); actionsManager->addAction(flipHorizontallyAct, "_flipHorizontally", this, this, SLOT(flipHorizontally())); aboutAct = new QAction(tr("A&bout"), this); actionsManager->addAction(aboutAct, "_about", this, this, SLOT(about()), QKeySequence::HelpContents); nextAct = new QAction(tr("Ne&xt"), this); nextAct->setStatusTip(tr("Loads next image")); nextAct->setEnabled(false); actionsManager->addAction(nextAct, "_next", this, this, SLOT(next()), Qt::Key_Right); goFirstAct = new QAction(tr("Go to the first"), this); goFirstAct->setStatusTip(tr("Loads the first image in the folder")); goFirstAct->setEnabled(false); actionsManager->addAction(goFirstAct, "_goFirst", this, this, SLOT(goFirst()), Qt::Key_Home); prevAct = new QAction(tr("Pre&vious"), this); prevAct->setStatusTip(tr("Loads previous image")); prevAct->setEnabled(false); actionsManager->addAction(prevAct, "_previous", this, this, SLOT(previous()), Qt::Key_Left); goLastAct = new QAction(tr("Go to the last"), this); goLastAct->setStatusTip(tr("Loads the last image in the folder")); goLastAct->setEnabled(false); actionsManager->addAction(goLastAct, "_goLast", this, this, SLOT(goLast()), Qt::Key_End); openDirAct = new QAction(tr("Open &Folder"), this); openDirAct->setStatusTip("Open a folder to explore images inside it"); actionsManager->addAction(openDirAct, "_openFolder", this, this, SLOT(openDir()), QKeySequence("Ctrl+Shift+O")); showMenuBarAct = new QAction(tr("Show Menu Bar"), this); showMenuBarAct->setCheckable(true); actionsManager->addAction(showMenuBarAct, "_showMenuBar", this, this, SLOT(showMenuBar()), QKeySequence("Ctrl+M")); configAct = new QAction(tr("Configuration"), this); configAct->setEnabled(true); actionsManager->addAction(configAct, "_configuration", this, this, SLOT(configureProgram()), QKeySequence("Ctrl+C")); deleteRecentFilesAct = new QAction(tr("Delete list"), this); deleteRecentFilesAct->setIcon(QIcon::fromTheme("edit-clear")); connect(deleteRecentFilesAct, SIGNAL(triggered()), this, SLOT(deleteRecentFiles())); printAct = new QAction(tr("Print"), this); printAct->setEnabled(false); actionsManager->addAction(printAct, "_print", this, this, SLOT(print()), QKeySequence::Print); deleteFileAct = new QAction(tr("Delete"), this); deleteFileAct->setEnabled(false); deleteFileAct->setToolTip(tr("This deletes completly the file from the disk, doesn't move it to the trash")); actionsManager->addAction(deleteFileAct, "_deleteFile", this, this, SLOT(deleteFileSlot()), QKeySequence::Delete); moveToAct = new QAction(tr("Move to..."), this); moveToAct->setEnabled(false); actionsManager->addAction(moveToAct, "_moveTo", this, this, SLOT(moveToSlot())); goToAct = new QAction(tr("Go to"), this); goToAct->setEnabled(false); actionsManager->addAction(goToAct, "_goTo", this, this, SLOT(goToSlot()), QKeySequence("Ctrl+J")); configureToolBarAct = new QAction(tr("Configure toolbar"), this); actionsManager->addAction(configureToolBarAct, "_configureToolBar", this, this, SLOT(configureToolBarSlot())); //set the icons, becouse QIcon::name() was included in Qt4.7 actionsManager->setActionIcon("_about", "help-about"); actionsManager->setActionIcon("_adjustSize", "zoom-fit-best"); actionsManager->setActionIcon("_configuration", "configure"); actionsManager->setActionIcon("_deleteFile", "edit-delete"); actionsManager->setActionIcon("_exit", "application-exit"); actionsManager->setActionIcon("_fileProperties", "document-properties"); actionsManager->setActionIcon("_flipHorizontally", "object-flip-horizontal"); actionsManager->setActionIcon("_flipVertically", "object-flip-vertical"); actionsManager->setActionIcon("_goFirst", "go-first"); actionsManager->setActionIcon("_goLast", "go-last"); actionsManager->setActionIcon("_goTo", "go-jump"); actionsManager->setActionIcon("_moveTo", "none"); actionsManager->setActionIcon("_next", "go-next"); actionsManager->setActionIcon("_normalSize", "zoom-original"); actionsManager->setActionIcon("_open", "document-open"); actionsManager->setActionIcon("_openFolder", "folder-open"); actionsManager->setActionIcon("_previous", "go-previous"); actionsManager->setActionIcon("_print", "document-print"); actionsManager->setActionIcon("_rotateLeft", "object-rotate-left"); actionsManager->setActionIcon("_rotateRight", "object-rotate-right"); actionsManager->setActionIcon("_save", "document-save"); actionsManager->setActionIcon("_showMenuBar", "show-menu"); actionsManager->setActionIcon("_showToolBar", "configure-toolbars"); actionsManager->setActionIcon("_tbMovable", "configure-toolbars"); actionsManager->setActionIcon("_configureToolBar", "configure-toolbars"); actionsManager->setActionIcon("_zoomIn", "zoom-in"); actionsManager->setActionIcon("_zoomOut", "zoom-out"); }
//! called if an event happened. bool CGUIIcon::OnEvent(const SEvent& event) { switch(event.EventType) { case EET_GUI_EVENT: { if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) { if (event.GUIEvent.Caller == (IGUIElement*)this) //Dragging = false; //printf("On h, on focus EET_GUI_EVENT "); return true; } else if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED) { /*if (Parent && ((event.GUIEvent.Caller == this) || isMyChild(event.GUIEvent.Caller))) Parent->bringToFront(this);*/ } } case EET_MOUSE_INPUT_EVENT: { switch(event.MouseInput.Event) { //the mouse left button is pressed case EMIE_LMOUSE_PRESSED_DOWN: { //printf("Press down\n"); //get the move position for dragging DragStart.X = event.MouseInput.X; DragStart.Y = event.MouseInput.Y; //if the icon isn't in focus - put it in focus if (!Environment->hasFocus(this)) { //set the focus Environment->setFocus(this); } { //printf("Dragging\n"); //if the icon is moveable - dragging is enabled Dragging = true*Moveable; if(Parent) { //bring the icon to the front Parent->bringToFront(this); //if the icon is in a slot (if the parent isn't the gui root element) if(!(Parent == Environment->getRootGUIElement())) { //printf("Parent == Environment->getRootGUIElement \n"); //make the icon a child of the root element (removing it from the slot) Environment->getRootGUIElement()->addChild(this); //the current position core::rect<s32> currPos = getAbsolutePosition(); //move the icon the the right position (ready for dragging) move(core::position2d<s32>(event.MouseInput.X - (event.MouseInput.X-currPos.UpperLeftCorner.X), event.MouseInput.Y - (event.MouseInput.Y-currPos.UpperLeftCorner.Y))); } } } return true; } //the mouse left button is released case EMIE_LMOUSE_LEFT_UP: { //printf("Press up\n"); //the icon is no longer being draged Dragging = false; //the icon is no longer in focus Environment->removeFocus(this); if(this->getParent()) Environment->removeFocus(this->getParent()); //bool to check if the icon is dropped in a slot bool movedToSlot = false; //is the icon droped in a useable slot's rect u32 size = UsableSlots->size(); IGUIElement *slot = 0; for(u32 i = 0; i < size; i++) { //get the slot slot = (*UsableSlots)[i]; if(slot) { //get the slot rect core::rect<s32> slotRect = slot->getAbsolutePosition(); //if the position the icon is dropped in, is inside the rect if(slotRect.isPointInside(DragStart)) { //move the icon to the slot moveToSlot(slot); movedToSlot = true; } } } //if the icon is dropped outside a slot, and it's not supposed to if(!movedToSlot && !CanBeOutsideSlot) { if(Slot) { //move it back to where it came from moveToSlot(Slot); } } return true; } //the mouse is moved case EMIE_MOUSE_MOVED: { //printf("Mouse move\n"); //if the icon is being dragged if (Dragging) { //printf("Draging when mouse move\n"); //move the icon move(core::position2d<s32>(event.MouseInput.X - DragStart.X, event.MouseInput.Y - DragStart.Y)); //update the position DragStart.X = event.MouseInput.X; DragStart.Y = event.MouseInput.Y; return true; } break; } //just to keep the compiler from posting warnings default:{} }//switch mouse input break; }//case mouse input event //just to keep the compiler from posting warnings default:{} }//switch event type return Parent ? Parent->OnEvent(event) : false; }//end function OnEvent