void ZoomInTool::buttonEvent(ButtonType type, bool isPress, int x, int y) { if (!isPress) { // button has been released, stop changing zoom box size if we // were doing that killTimer(); return; } // don't accept additional clicks while timer is active (other than // middle click) if ((timer_id != -1) && ((type == LEFT) || (type == RIGHT))) { return; } intptr_t zoom_dir = 0; if (type == LEFT) { zoom_dir = 1; } else if (type == MIDDLE) { zoom(); } else if (type == RIGHT) { zoom_dir = -1; } if (zoom_dir) { draw_xor_rect(rect); resizeRect(zoom_dir); if (!rectIsValidSize()) { resizeRect(-zoom_dir); } else { timer_id = g_timeout_add(ZOOM_INTERVAL, (GtkFunction)zoom_in_callback, (void*)(2 * zoom_dir)); } draw_xor_rect(rect); } }
void ZoomInTool::timerCallback(int arg) { draw_xor_rect(rect); resizeRect(arg); if (!rectIsValidSize()) { resizeRect(-arg); } draw_xor_rect(rect); }
void SubcomponentMaskLayerItem::setCurrentItem(QGraphicsItem *item) { QGraphicsItem *prevItem = m_currentItem; m_currentItem = item; if (!m_currentItem) return; QRect viewRect = m_inspector->declarativeView()->rect(); viewRect = m_inspector->declarativeView()->mapToScene(viewRect).boundingRect().toRect(); QRectF itemRect = item->boundingRect() | item->childrenBoundingRect(); itemRect = item->mapRectToScene(itemRect); // if updating the same item as before, resize the rectangle only bigger, not smaller. if (prevItem == item && prevItem != 0) { m_itemPolyRect = resizeRect(itemRect, m_itemPolyRect); } else { m_itemPolyRect = itemRect; } QRectF borderRect = m_itemPolyRect; borderRect.adjust(-1, -1, 1, 1); m_borderRect->setRect(borderRect); const QRegion externalRegion = QRegion(viewRect).subtracted(m_itemPolyRect.toRect()); setPolygon(regionToPolygon(externalRegion)); }
void MyView::MouseDown(BPoint where) { SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); int32 buttons; Looper()->CurrentMessage()->FindInt32("buttons", &buttons); fLastPos = where; if (buttons == B_PRIMARY_MOUSE_BUTTON) { fTracking = true; fMovingLayer = FindLayer(topLayer, where); if (fMovingLayer == topLayer) fMovingLayer = NULL; if (fMovingLayer) { BRect bounds(fMovingLayer->Bounds()); fMovingLayer->ConvertToScreen2(&bounds); BRect resizeRect(bounds.right-10, bounds.bottom-10, bounds.right, bounds.bottom); if (resizeRect.Contains(where)) fIsResize = true; else fIsResize = false; } } else if (buttons == B_SECONDARY_MOUSE_BUTTON) { fIs2ndButton = true; } else if (buttons == B_TERTIARY_MOUSE_BUTTON) { DrawSubTree(topLayer); } }
void CMouseZoomMap::mouseReleaseEvent(QMouseEvent * e) { if(e->button() == Qt::LeftButton) { zoomMap = false; resizeRect(e->pos()); rect = rect.normalized(); if(rect.width() < 10) { rect.setWidth(10); } if(rect.height() < 10) { rect.setHeight(10); } double lon1 = rect.left(); double lat1 = rect.top(); double lon2 = rect.right(); double lat2 = rect.bottom(); IMap& map = CMapDB::self().getMap(); map.convertPt2Rad(lon1,lat1); map.convertPt2Rad(lon2,lat2); map.zoom(lon1, lat1, lon2, lat2); canvas->setMouseMode(CCanvas::eMouseMoveArea); } }
/** * Detect objects using cascade detection of haar-wavelets (haar cascade). * A variant of Viola-Jones face detection framework. * * \param currframe Frame that one wants to detect objects. * * \param detectAfterRot Whether to rotate currframe by small angles * during detection phase. Currently detection is done with haar cascade * which is not rotation invariant (can not detect an object if it is * presented rotated). Haar cascade could potentially detect object * rotated by a very small angle (+/-15 degrees). Do detection on rotated * frames and the straight frame in order to detect the object in * much more angular variations. */ std::vector<cv::Rect> ObjDetTrack::haarCascadeDetect(const cv::Mat& currframe, bool detectAfterRot) { cv::Mat frame_gray; bool presuccess = detectPreProcess(currframe, frame_gray); if(!presuccess){ return std::vector<cv::Rect>(); } //put all detection results here std::vector<cv::Rect> detResult; //simple straight (no rotation) cascade face/object detection std::vector<cv::Rect> straightDetResult = runAllCascadeOnFrame(frame_gray, 2, cv::Size(20*shrinkratio,20*shrinkratio)); //std::cout<<"detected =="<<(int)straightDetResult.size()<<"== straight"<<std::endl; detResult.insert(detResult.end(), straightDetResult.begin(), straightDetResult.end()); //implements detection after small angle rotations here. Could be really slow //Maybe only do this if no straight detResults if(detectAfterRot){// && detResult.size() == 0){ std::vector<double> rotAngles; rotAngles.push_back(-30); rotAngles.push_back(30); for(uint32_t ang_ind=0; ang_ind<rotAngles.size(); ang_ind++){ cv::Mat frameAfterRot; cv::Mat revRotM = rotateFrame(frame_gray, frameAfterRot, rotAngles[ang_ind]); std::vector<cv::Rect> rotDetResult = runAllCascadeOnFrame(frameAfterRot, 2, cv::Size(20*shrinkratio,20*shrinkratio)); std::ostringstream strs; strs << rotAngles[ang_ind]; std::string anglestr = strs.str(); //std::cout<<"detected =="<<rotDetResult.size()<<"== sideways angle "<<rotAngles[ang_ind]<<std::endl; std::vector<cv::Rect> revRotDetResult = revRotOnRects(rotDetResult, revRotM, frame_gray.size()); detResult.insert(detResult.end(), revRotDetResult.begin(), revRotDetResult.end()); } } //eliminate duplicates/overlapping detection //they are defined as detection that are overlapping >50% area with other detection rectangles removeOverlapWindows(detResult); //std::cout<<"=post overlap elimination: detected "<<detResult.size()<<" faces/objects"<<std::endl; //reverse downsampling of image, by resizing detection rectangles/windows for(uint32_t i=0; i<detResult.size(); i++){ resizeRect(detResult[i], 1/shrinkratio, 1/shrinkratio); } return detResult; }
void ContentWindowGraphicsItem::drawResizeIndicator_( QPainter* painter ) { float buttonWidth, buttonHeight; getButtonDimensions(buttonWidth, buttonHeight); QRectF resizeRect(coordinates_.x() + coordinates_.width() - buttonWidth, coordinates_.y() + coordinates_.height() - buttonHeight, buttonWidth, buttonHeight); QPen pen; pen.setColor(QColor(128,128,128)); painter->setPen(pen); painter->drawRect(resizeRect); painter->drawLine(QPointF(coordinates_.x() + coordinates_.width(), coordinates_.y() + coordinates_.height() - buttonHeight), QPointF(coordinates_.x() + coordinates_.width() - buttonWidth, coordinates_.y() + coordinates_.height())); }
QRectF UBGraphicsRuler::resizeButtonRect() const { QPixmap resizePixmap(":/images/resizeRuler.svg"); QSizeF resizeRectSize( resizePixmap.rect().width(), rect().height()); qreal ratio = mAntiScaleRatio > 1.0 ? mAntiScaleRatio : 1.0; QPointF resizeRectTopLeft(rect().width() - resizeRectSize.width() * ratio, 0); QRectF resizeRect(resizeRectTopLeft, resizeRectSize); resizeRect.translate(rect().topLeft()); return resizeRect; }
QRectF UBGraphicsCompass::resizeButtonRect() const { QPixmap resizePixmap(":/images/resizeCompass.svg"); QSizeF resizeRectSize( resizePixmap.width() * mAntiScaleRatio, resizePixmap.height() * mAntiScaleRatio); QPointF resizeRectTopLeft( rect().width() - sPencilLength - sPencilBaseLength - resizeRectSize.width() - 4, (rect().height() - resizeRectSize.height()) / 2); QRectF resizeRect(resizeRectTopLeft, resizeRectSize); resizeRect.translate(rect().topLeft()); return resizeRect; }
Decorator::Region TabDecorator::RegionAt(BPoint where, int32& tab) const { // Let the base class version identify hits of the buttons and the tab. Region region = Decorator::RegionAt(where, tab); if (region != REGION_NONE) return region; // check the resize corner if (fTopTab->look == B_DOCUMENT_WINDOW_LOOK && fResizeRect.Contains(where)) return REGION_RIGHT_BOTTOM_CORNER; // hit-test the borders if (fLeftBorder.Contains(where)) return REGION_LEFT_BORDER; if (fTopBorder.Contains(where)) return REGION_TOP_BORDER; // Part of the bottom and right borders may be a resize-region, so we have // to check explicitly, if it has been it. if (fRightBorder.Contains(where)) region = REGION_RIGHT_BORDER; else if (fBottomBorder.Contains(where)) region = REGION_BOTTOM_BORDER; else return REGION_NONE; // check resize area if ((fTopTab->flags & B_NOT_RESIZABLE) == 0 && (fTopTab->look == B_TITLED_WINDOW_LOOK || fTopTab->look == B_FLOATING_WINDOW_LOOK || fTopTab->look == B_MODAL_WINDOW_LOOK || fTopTab->look == kLeftTitledWindowLook)) { BRect resizeRect(BPoint(fBottomBorder.right - kBorderResizeLength, fBottomBorder.bottom - kBorderResizeLength), fBottomBorder.RightBottom()); if (resizeRect.Contains(where)) return REGION_RIGHT_BOTTOM_CORNER; } return region; }
void ContentWindowGraphicsItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { QGraphicsRectItem::paint(painter, option, widget); boost::shared_ptr<ContentWindowManager> contentWindowManager = getContentWindowManager(); if(contentWindowManager != NULL) { // default pen QPen pen; // button dimensions float buttonWidth, buttonHeight; getButtonDimensions(buttonWidth, buttonHeight); // draw close button QRectF closeRect(rect().x() + rect().width() - buttonWidth, rect().y(), buttonWidth, buttonHeight); pen.setColor(QColor(255,0,0)); painter->setPen(pen); painter->drawRect(closeRect); painter->drawLine(QPointF(rect().x() + rect().width() - buttonWidth, rect().y()), QPointF(rect().x() + rect().width(), rect().y() + buttonHeight)); painter->drawLine(QPointF(rect().x() + rect().width(), rect().y()), QPointF(rect().x() + rect().width() - buttonWidth, rect().y() + buttonHeight)); // resize indicator QRectF resizeRect(rect().x() + rect().width() - buttonWidth, rect().y() + rect().height() - buttonHeight, buttonWidth, buttonHeight); pen.setColor(QColor(128,128,128)); painter->setPen(pen); painter->drawRect(resizeRect); painter->drawLine(QPointF(rect().x() + rect().width(), rect().y() + rect().height() - buttonHeight), QPointF(rect().x() + rect().width() - buttonWidth, rect().y() + rect().height())); // text label // set the font float fontSize = 24.; QFont font; font.setPixelSize(fontSize); painter->setFont(font); // color the text black pen.setColor(QColor(0,0,0)); painter->setPen(pen); // scale the text size down to the height of the graphics view // and, calculate the bounding rectangle for the text based on this scale // the dimensions of the view need to be corrected for the tiled display aspect ratio // recall the tiled display UI is only part of the graphics view since we show it at the correct aspect ratio float viewWidth = (float)scene()->views()[0]->width(); float viewHeight = (float)scene()->views()[0]->height(); float tiledDisplayAspect = (float)g_configuration->getTotalWidth() / (float)g_configuration->getTotalHeight(); if(viewWidth / viewHeight > tiledDisplayAspect) { viewWidth = viewHeight * tiledDisplayAspect; } else if(viewWidth / viewHeight <= tiledDisplayAspect) { viewHeight = viewWidth / tiledDisplayAspect; } float verticalTextScale = 1. / viewHeight; float horizontalTextScale = viewHeight / viewWidth * verticalTextScale; painter->scale(horizontalTextScale, verticalTextScale); QRectF textBoundingRect = QRectF(rect().x() / horizontalTextScale, rect().y() / verticalTextScale, rect().width() / horizontalTextScale, rect().height() / verticalTextScale); // get the label and render it QString label(contentWindowManager->getContent()->getURI().c_str()); QString labelSection = label.section("/", -1, -1).prepend(" "); painter->drawText(textBoundingRect, Qt::AlignLeft | Qt::AlignTop, labelSection); // draw window info at smaller scale verticalTextScale *= 0.5; horizontalTextScale *= 0.5; painter->scale(0.5, 0.5); textBoundingRect = QRectF(rect().x() / horizontalTextScale, rect().y() / verticalTextScale, rect().width() / horizontalTextScale, rect().height() / verticalTextScale); QString coordinatesLabel = QString(" (") + QString::number(x_, 'f', 2) + QString(" ,") + QString::number(y_, 'f', 2) + QString(", ") + QString::number(w_, 'f', 2) + QString(", ") + QString::number(h_, 'f', 2) + QString(")\n"); QString zoomCenterLabel = QString(" zoom = ") + QString::number(zoom_, 'f', 2) + QString(" @ (") + QString::number(centerX_, 'f', 2) + QString(", ") + QString::number(centerY_, 'f', 2) + QString(")"); QString interactionLabel = QString(" x: ") + QString::number(interactionState_.mouseX_, 'f', 2) + QString(" y: ") + QString::number(interactionState_.mouseY_, 'f', 2) + QString(" mouseLeft: ") + QString::number((int) interactionState_.mouseLeft_, 'b', 1) + QString(" mouseMiddle: ") + QString::number((int) interactionState_.mouseMiddle_, 'b', 1) + QString(" mouseRight: ") + QString::number((int) interactionState_.mouseRight_, 'b', 1); QString windowInfoLabel = coordinatesLabel + zoomCenterLabel + interactionLabel; painter->drawText(textBoundingRect, Qt::AlignLeft | Qt::AlignBottom, windowInfoLabel); } }
void CMouseZoomMap::mouseMoveEvent(QMouseEvent * e) { if(!zoomMap) return; resizeRect(e->pos()); }