BOOL CGauge::OnDragStart(int nHitTest,CPointF point) { REAL dx = m_pWnd->GetStartPos().x; REAL dy = m_pWnd->GetStartPos().y; CRectF rc; GetBoundsRect(rc); rc.OffsetRect(-dx,-dy); BOOL bRet = FALSE; CClientDC dc(m_pWnd); CElastic elastic(&dc,this); CPoints pts; switch (nHitTest) { case TopLeft: PointHelper::RecalcPoints(m_rcBounds,CRectF(point.x,point.y,rc.right,rc.bottom),m_pts,pts); break; case Top: PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left,point.y,rc.right,rc.bottom),m_pts,pts); break; case TopRight: PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left,point.y,point.x,rc.bottom),m_pts,pts); break; case Right: PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left,rc.top,point.x,rc.bottom),m_pts,pts); break; case BottomRight: PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left,rc.top,point.x,point.y),m_pts,pts); break; case Bottom: PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left,rc.top,rc.right,point.y),m_pts,pts); break; case BottomLeft: PointHelper::RecalcPoints(m_rcBounds,CRectF(point.x,rc.top,rc.right,point.y),m_pts,pts); break; case Left: PointHelper::RecalcPoints(m_rcBounds,CRectF(point.x,rc.top,rc.right,rc.bottom),m_pts,pts); break; case Body: PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left,rc.top,rc.right,rc.bottom),m_pts,pts); bRet = TRUE; break; default: GetPoints(pts); PointHelper::OffsetPoints(pts,-dx,-dy); pts[nHitTest-HtIndex] = CPoint((int)point.x,(int)point.y); break; } dc.Polyline(pts.GetData(),(int)pts.GetCount()); return bRet; }
void CGridLabel::deselect( void ) { CRectF r ; r.setLeft(-2); r.setRight(-2); r.setTop(-1); r.setBottom(-1); m_pEditData->setCatchRect(r); update() ; }
// ドラッグアンドドロップ開始 void CGridLabel::startDragAndDrop( QMouseEvent *ev ) { Q_UNUSED(ev) ; CEditData::ImageData *p = m_pEditData->getImageDataFromNo(m_Index) ; if ( !p ) { return ; } QImage img = p->Image.copy(m_pEditData->getCatchRect().toRect()) ; QPixmap pix = QPixmap::fromImage(img); QByteArray itemData ; QDataStream stream(&itemData, QIODevice::WriteOnly) ; CRectF rect = m_pEditData->getCatchRect() ; // stream << rect << mScale << m_Index ; stream << rect.left() << rect.top() << rect.right() << rect.bottom() << mScale << m_Index ; QMimeData *mimeData = new QMimeData ; mimeData->setData("editor/selected-image", itemData); QPainter painter ; painter.begin(&pix) ; painter.fillRect(pix.rect(), QColor(127, 127, 127, 127)); painter.end() ; QDrag *drag = new QDrag(this) ; drag->setMimeData(mimeData); drag->setPixmap(pix); drag->setHotSpot(QPoint((rect.right()-rect.left())/2, (rect.bottom()-rect.top())/2)); // qDebug() << "x:" << ev->pos().x() << " y:" << ev->pos().y() ; m_pEditData->setDraggingImage(true); drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) ; m_pEditData->setDraggingImage(false); }
BOOL CGauge::OnDragEnd(int nHitTest,CPointF point) { CRectF rc; GetBoundsRect(rc); REAL dx = m_pWnd->GetStartPos().x; REAL dy = m_pWnd->GetStartPos().y; switch (nHitTest) { case TopLeft: rc.left = point.x + dx; rc.top = point.y + dy; break; case Top: rc.top = point.y + dy; break; case TopRight: rc.right = point.x + dx; rc.top = point.y + dy; break; case Right: rc.right = point.x + dx; break; case BottomRight: rc.right = point.x + dx; rc.bottom = point.y + dy; break; case Bottom: rc.bottom = point.y + dy; break; case BottomLeft: rc.left = point.x + dx; rc.bottom = point.y + dy; break; case Left: rc.left = point.x + dx; break; case Body: rc.MoveToXY(rc.left+point.x-m_pWnd->GetMarkPos().x, rc.top+point.y-m_pWnd->GetMarkPos().y); break; default: m_pts[nHitTest-HtIndex] = point + m_pWnd->GetStartPos(); PointHelper::CalcPointsBoundsRect(m_pts,m_rcBounds); FormatDesc(); return TRUE; } SetBoundsRect(rc); FormatDesc(); return TRUE; }
void CGridLabel::selectAll( void ) { CRectF r ; CEditData::ImageData *p = m_pEditData->getImageDataFromNo(m_Index) ; if ( !p ) { return ; } int img_w = p->Image.width() ; int img_h = p->Image.height() ; r.setLeft(0); r.setRight(img_w); r.setTop(0); r.setBottom(img_h); m_pEditData->setCatchRect(r); update() ; }
////////////////////////////////////////////////////////////////// //功能: 移动对象 ////////////////////////////////////////////////////////////////// void CFormObj::MoveTo(const CRectF &position, BOOL bUniformScale, CLayoutView* pView) { ASSERT_VALID(this); if (m_bUniformScale) bUniformScale = TRUE; CRectF rcObj; Invalidate(pView); float fScaleX = position.Width() / m_position.Width(); float fScaleY = position.Height() / m_position.Height(); if (bUniformScale) { if (ABSOLUTEVALUE(fScaleX) < ABSOLUTEVALUE(fScaleY)) fScaleX = fScaleX >= 0 ? ABSOLUTEVALUE(fScaleY) : -ABSOLUTEVALUE(fScaleY); else fScaleY = fScaleY >= 0 ? ABSOLUTEVALUE(fScaleX) : -ABSOLUTEVALUE(fScaleX); } CDevObjList* pObjects = m_pFormDoc->GetObjects(); POSITION posObj = pObjects->GetHeadPosition(); CDevObj* pObj; while (posObj != NULL) { pObj = pObjects->GetNext(posObj); rcObj = pObj->GetPositionRect(); rcObj.OffsetRect(-m_position.TopLeft()); rcObj.left = rcObj.left * fScaleX; rcObj.right = rcObj.right * fScaleX; rcObj.top = rcObj.top * fScaleY; rcObj.bottom = rcObj.bottom * fScaleY; rcObj.OffsetRect(position.TopLeft()); pObj->MoveTo(rcObj, bUniformScale, pView); } m_ptRotateBase.x = position.left + (m_ptRotateBase.x - m_position.left) * fScaleX; m_ptRotateBase.y = position.top + (m_ptRotateBase.y - m_position.top) * fScaleY; m_position = position; // m_position.NormalizeRect(); RecalcPosition(); m_pFormDoc->SetDocSize(0, 0, TRUE); Invalidate(pView); }
// 描画イベント void CGridLabel::paintEvent(QPaintEvent *event) { QPainter painter(this) ; QPen pen, penCenter ; pen.setColor(QColor(64, 64, 64, 255)); pen.setWidth(mScale); penCenter.setColor(QColor(255, 255, 0, 255)); penCenter.setWidth(mScale); CEditData::ImageData *p = m_pEditData->getImageDataFromNo(m_Index) ; if ( !p ) { return ; } if ( m_pEditData ) { QSize size = p->Image.size()*mScale ; size += QSize(mScale, mScale) ; resize(size) ; } if ( m_bDrawGrid ) { painter.setPen(pen); for ( int x = 0 ; x <= size().width() ; x += m_GridSize.x() * mScale ) { if ( x == size().width()/2 ) { painter.setPen(penCenter); } painter.drawLine(x, event->rect().top(), x, event->rect().bottom()); if ( x == size().width()/2 ) { painter.setPen(pen); } } for ( int y = 0 ; y <= size().height() ; y += m_GridSize.y() * mScale ) { if ( y == size().height()/2 ) { painter.setPen(penCenter); } painter.drawLine(event->rect().left(), y, event->rect().right(), y); if ( y == size().height()/2 ) { painter.setPen(pen); } } } // 選択中範囲 if ( m_pEditData && m_bCatchable ) { if ( m_bPressCtrl ) { pen.setColor(QColor(0, 255, 0, 255)); } else { pen.setColor(QColor(255, 0, 0, 255)); } painter.setPen(pen); CRectF rect = m_pEditData->getCatchRect() ; QRect r = QRect(rect.left(), rect.top(), rect.right()-rect.left(), rect.bottom()-rect.top()) ; painter.drawRect(r) ; } FrameData data ; if ( m_pEditData->getNowSelectFrameData(data) ) { if ( data.nImage != m_Index ) { return ; } } else { return ; } // センター表示 if ( m_bDrawCenter ) { pen.setColor(QColor(0, 0, 255, 255)); painter.setPen(pen); int x = data.center_x + data.left ; int y = data.center_y + data.top - 1 ; QSize size = p->Image.size() ; painter.drawLine(QPointF(0, y), QPointF(size.width(), y)); painter.drawLine(QPointF(x, 0), QPointF(x, size.height())); } }
// 範囲選択終了 void CGridLabel::mouseReleaseEvent(QMouseEvent *ev) { if ( !m_pEditData || !m_bCatchable ) { return ; } if ( !bCatching ) { return ; } bCatching = false ; if ( m_bRectMove ) { // 範囲移動中 m_bRectMove = false ; return ; } m_bRectMove = false ; CEditData::ImageData *p = m_pEditData->getImageDataFromNo(m_Index) ; if ( !p ) { return ; } int img_w = p->Image.width() ; int img_h = p->Image.height() ; CRectF r = m_pEditData->getCatchRect() ; float x = ev->pos().x() / mScale ; float y = ev->pos().y() / mScale ; if ( x < 0 ) { x = 0 ; } if ( x > img_w ) { x = img_w ; } if ( x < r.left() ) { x = r.left() ; } if ( y < 0 ) { y = 0 ; } if ( y > img_h ) { y = img_h ; } if ( y < r.top() ) { y = r.top() ; } r.setRight(x); r.setBottom(y); if ( r.width() <= 1 || r.height() <= 1 ) { r.setLeft(-2); r.setRight(-2); r.setTop(-1); r.setBottom(-1); } m_pEditData->setCatchRect(r); emit sig_changeCatchRect(r) ; repaint() ; }
// 範囲選択中 void CGridLabel::mouseMoveEvent(QMouseEvent *ev) { if ( !m_pEditData || !m_bCatchable ) { return ; } if ( !bCatching ) { return ; } CRectF r = m_pEditData->getCatchRect() ; CEditData::ImageData *p = m_pEditData->getImageDataFromNo(m_Index) ; if ( !p ) { return ; } int img_w = p->Image.width() ; int img_h = p->Image.height() ; int x = ev->pos().x() / mScale ; int y = ev->pos().y() / mScale ; if ( m_bRectMove ) { // 範囲移動中 if ( !m_bPressCtrl ) { return ; } // Ctrlキー押してたら QPoint add = ev->pos() - m_MovePos ; r.setLeft(r.left()+add.x()); r.setRight(r.right()+add.x()); r.setTop(r.top()+add.y()); r.setBottom(r.bottom()+add.y()); if ( r.left() < 0 ) { r.setRight(r.right()-r.left()); r.setLeft(0); } if ( r.right() > img_w-1 ) { r.setLeft(r.left()-(r.right()-(img_w-1))); r.setRight(img_w-1); } if ( r.top() < 0 ) { r.setBottom(r.bottom()-r.top()); r.setTop(0); } if ( r.bottom() > img_h-1 ) { r.setTop(r.top()-(r.bottom()-(img_h-1))); r.setBottom(img_h-1); } emit sig_changeSelectLayerUV(r) ; m_MovePos = ev->pos() ; } else { if ( x < 0 ) { x = 0 ; } if ( x >= img_w ) { x = img_w ; } if ( x < r.left() ) { x = r.left() ; } if ( y < 0 ) { y = 0 ; } if ( y >= img_h ) { y = img_h ; } if ( y < r.top() ) { y = r.top() ; } r.setRight(x); r.setBottom(y); } m_pEditData->setCatchRect(r); emit sig_changeCatchRect(r) ; repaint() ; }
void CGauge::OnDrag(int nHitTest,CPointF point) { CRectF rc; GetBoundsRect(rc); REAL dx = m_pWnd->GetStartPos().x; REAL dy = m_pWnd->GetStartPos().y; rc.OffsetRect(-dx,-dy); CClientDC dc(m_pWnd); CElastic elastic(&dc,this); CPoints pts1,pts2; switch (nHitTest) { case TopLeft: PointHelper::RecalcPoints(m_rcBounds,CRectF(m_pWnd->GetCapturePos().x,m_pWnd->GetCapturePos().y,rc.right,rc.bottom),m_pts,pts1); PointHelper::RecalcPoints(m_rcBounds,CRectF(point.x,point.y,rc.right,rc.bottom),m_pts,pts2); break; case Top: PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left,m_pWnd->GetCapturePos().y,rc.right,rc.bottom),m_pts,pts1); PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left,point.y,rc.right,rc.bottom),m_pts,pts2); break; case TopRight: PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left,m_pWnd->GetCapturePos().y,m_pWnd->GetCapturePos().x,rc.bottom),m_pts,pts1); PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left,point.y,point.x,rc.bottom),m_pts,pts2); break; case Right: PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left,rc.top,m_pWnd->GetCapturePos().x,rc.bottom),m_pts,pts1); PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left,rc.top,point.x,rc.bottom),m_pts,pts2); break; case BottomRight: PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left,rc.top,m_pWnd->GetCapturePos().x,m_pWnd->GetCapturePos().y),m_pts,pts1); PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left,rc.top,point.x,point.y),m_pts,pts2); break; case Bottom: PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left,rc.top,rc.right,m_pWnd->GetCapturePos().y),m_pts,pts1); PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left,rc.top,rc.right,point.y),m_pts,pts2); break; case BottomLeft: PointHelper::RecalcPoints(m_rcBounds,CRectF(m_pWnd->GetCapturePos().x,rc.top,rc.right,m_pWnd->GetCapturePos().y),m_pts,pts1); PointHelper::RecalcPoints(m_rcBounds,CRectF(point.x,rc.top,rc.right,point.y),m_pts,pts2); break; case Left: PointHelper::RecalcPoints(m_rcBounds,CRectF(m_pWnd->GetCapturePos().x,rc.top,rc.right,rc.bottom),m_pts,pts1); PointHelper::RecalcPoints(m_rcBounds,CRectF(point.x,rc.top,rc.right,rc.bottom),m_pts,pts2); break; case Body: { REAL x = m_pWnd->GetCapturePos().x-m_pWnd->GetMarkPos().x; REAL y = m_pWnd->GetCapturePos().y-m_pWnd->GetMarkPos().y; PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left+x,rc.top+y,rc.right+x,rc.bottom+y),m_pts,pts1); x = point.x-m_pWnd->GetMarkPos().x; y = point.y-m_pWnd->GetMarkPos().y; PointHelper::RecalcPoints(m_rcBounds,CRectF(rc.left+x,rc.top+y,rc.right+x,rc.bottom+y),m_pts,pts2); } break; default: { GetPoints(pts1); PointHelper::OffsetPoints(pts1,-dx,-dy); pts1[nHitTest-HtIndex] = CPoint((int)m_pWnd->GetCapturePos().x,(int)m_pWnd->GetCapturePos().y); pts2.Copy(pts1); pts2[nHitTest-HtIndex] = CPoint((int)point.x,(int)point.y); } break; } dc.Polyline(pts1.GetData(),(int)pts1.GetCount()); dc.Polyline(pts2.GetData(),(int)pts2.GetCount()); }