// Restore image from off-screen pixmap long ShutterBug::onCmdSnap(FXObject*,FXSelector,void*){ FXColor *pixels=NULL; // Try grab pixels if(snapRectangle(pixels,rectangle)){ // Construct file dialog FXFileDialog savedialog(this,tr("Save Image")); savedialog.setSelectMode(SELECTFILE_ANY); savedialog.setPatternList(patterns); savedialog.setCurrentPattern(fileformat); savedialog.setFilename(FXPath::absolute(filename)); // Run file dialog if(savedialog.execute()){ filename=savedialog.getFilename(); fileformat=savedialog.getCurrentPattern(); if(FXStat::exists(filename) && FXMessageBox::question(this,MBOX_YES_NO,tr("Overwrite File"),tr("Overwrite existing image file: %s?"),filename.text())!=MBOX_CLICKED_YES) goto x; if(!saveImage(filename,pixels,rectangle.w,rectangle.h)){ FXMessageBox::error(this,MBOX_OK,tr("Error Saving Image"),tr("Unable to save image to file: %s."),filename.text()); } } // Free pixels x: freeElms(pixels); } return 1; }
// Snapshot to clipboard long ShutterBug::onCmdSnapClipboard(FXObject*,FXSelector,void*){ freeElms(clipbuffer); clipwidth=0; clipheight=0; if(acquireClipboard(dndTypes,ARRAYNUMBER(dndTypes))){ if(snapRectangle(clipbuffer,rectangle)){ clipwidth=rectangle.w; clipheight=rectangle.h; } } return 1; }
/*! Create the list of rects and flag if their sides are snappable from top or bottom or left or right, depending on other rects overlapping with the rect. */ void HsSnapToLines::createSnappableRectangles(const QList<QRectF> &inactiveRects) { mInactiveSnapRects.clear(); int i; for (i = 0; i<inactiveRects.count(); ++i) { QRectF rect = inactiveRects[i]; HsSnapRectangle snapRectangle(rect); int j; for (j = 0; j<inactiveRects.count(); ++j) { QRectF rectToCompare = inactiveRects[j]; if (rect != rectToCompare) { //Check if the rectangles being compared intersect each other if (rectToCompare.intersects(rect)) { //As the widgets intersect, check which corner is contained, //The corner that is contained is not snappable, when the moving widget is in the same position if (rectToCompare.contains(rect.topLeft())) { snapRectangle.isLeftSnapableForAbove = false; snapRectangle.isTopSnapableForLeft = false; } if (rectToCompare.contains(rect.topRight())) { snapRectangle.isRightSnapableForAbove = false; snapRectangle.isTopSnapableForRight = false; } if (rectToCompare.contains(rect.bottomRight())) { snapRectangle.isRightSnapableForBelow = false; snapRectangle.isBottomSnapableForRight = false; } if (rectToCompare.contains(rect.bottomLeft())) { snapRectangle.isLeftSnapableForBelow = false; snapRectangle.isBottomSnapableForLeft = false; } } } } if (snapRectangle.isLeftSnapableForAbove || snapRectangle.isLeftSnapableForBelow || snapRectangle.isRightSnapableForAbove || snapRectangle.isRightSnapableForBelow || snapRectangle.isTopSnapableForLeft || snapRectangle.isTopSnapableForRight || snapRectangle.isBottomSnapableForLeft || snapRectangle.isBottomSnapableForRight) { mInactiveSnapRects.append(snapRectangle); } } }