mirror of
https://github.com/leozide/leocad
synced 2024-11-17 07:47:55 +01:00
Support dragging colors from the color palette to paint pieces. Closes #177.
This commit is contained in:
parent
a4a97db568
commit
769b80b22d
6 changed files with 112 additions and 54 deletions
|
@ -19,7 +19,7 @@ View::View(lcModel* Model)
|
|||
mHighlight = false;
|
||||
memset(mGridSettings, 0, sizeof(mGridSettings));
|
||||
|
||||
mDragState = LC_DRAGSTATE_NONE;
|
||||
mDragState = lcDragState::NONE;
|
||||
mTrackButton = LC_TRACKBUTTON_NONE;
|
||||
mTrackTool = LC_TRACKTOOL_NONE;
|
||||
mTrackToolFromOverlay = false;
|
||||
|
@ -1789,18 +1789,32 @@ float View::GetOverlayScale() const
|
|||
return Dist.Length() * 5.0f;
|
||||
}
|
||||
|
||||
void View::BeginPieceDrag()
|
||||
void View::BeginDrag(lcDragState DragState)
|
||||
{
|
||||
mDragState = LC_DRAGSTATE_PIECE;
|
||||
mDragState = DragState;
|
||||
UpdateTrackTool();
|
||||
}
|
||||
|
||||
void View::EndPieceDrag(bool Accept)
|
||||
void View::EndDrag(bool Accept)
|
||||
{
|
||||
if (Accept)
|
||||
mModel->InsertPieceToolClicked(GetPieceInsertPosition(false, gMainWindow->GetCurrentPieceInfo()));
|
||||
{
|
||||
switch (mDragState)
|
||||
{
|
||||
case lcDragState::NONE:
|
||||
break;
|
||||
|
||||
mDragState = LC_DRAGSTATE_NONE;
|
||||
case lcDragState::PIECE:
|
||||
mModel->InsertPieceToolClicked(GetPieceInsertPosition(false, gMainWindow->GetCurrentPieceInfo()));
|
||||
break;
|
||||
|
||||
case lcDragState::COLOR:
|
||||
mModel->PaintToolClicked(FindObjectUnderPointer(true, false).Object);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mDragState = lcDragState::NONE;
|
||||
UpdateTrackTool();
|
||||
}
|
||||
|
||||
|
@ -2254,13 +2268,17 @@ void View::UpdateTrackTool()
|
|||
|
||||
switch (mDragState)
|
||||
{
|
||||
case LC_DRAGSTATE_NONE:
|
||||
case lcDragState::NONE:
|
||||
break;
|
||||
|
||||
case LC_DRAGSTATE_PIECE:
|
||||
case lcDragState::PIECE:
|
||||
NewTrackTool = LC_TRACKTOOL_INSERT;
|
||||
Redraw = true;
|
||||
break;
|
||||
|
||||
case lcDragState::COLOR:
|
||||
NewTrackTool = LC_TRACKTOOL_PAINT;
|
||||
break;
|
||||
}
|
||||
|
||||
if (NewTrackTool != mTrackTool)
|
||||
|
|
|
@ -45,11 +45,11 @@ enum lcTrackTool
|
|||
LC_TRACKTOOL_ZOOM_REGION
|
||||
};
|
||||
|
||||
enum lcDragState
|
||||
enum class lcDragState
|
||||
{
|
||||
LC_DRAGSTATE_NONE,
|
||||
LC_DRAGSTATE_PIECE
|
||||
// LC_DRAGSTATE_COLOR
|
||||
NONE,
|
||||
PIECE,
|
||||
COLOR
|
||||
};
|
||||
|
||||
class View : public lcGLWidget
|
||||
|
@ -82,8 +82,8 @@ public:
|
|||
void OnMouseWheel(float Direction);
|
||||
|
||||
void CancelTrackingOrClearSelection();
|
||||
void BeginPieceDrag();
|
||||
void EndPieceDrag(bool Accept);
|
||||
void BeginDrag(lcDragState DragState);
|
||||
void EndDrag(bool Accept);
|
||||
|
||||
void SetProjection(bool Ortho);
|
||||
void LookAt();
|
||||
|
|
|
@ -130,11 +130,11 @@ bool lcQColorList::event(QEvent *event)
|
|||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
void lcQColorList::mousePressEvent(QMouseEvent *event)
|
||||
void lcQColorList::mousePressEvent(QMouseEvent* MouseEvent)
|
||||
{
|
||||
for (int CellIdx = 0; CellIdx < mNumCells; CellIdx++)
|
||||
{
|
||||
if (!mCellRects[CellIdx].contains(event->pos()))
|
||||
if (!mCellRects[CellIdx].contains(MouseEvent->pos()))
|
||||
continue;
|
||||
|
||||
SelectCell(CellIdx);
|
||||
|
@ -142,6 +142,25 @@ void lcQColorList::mousePressEvent(QMouseEvent *event)
|
|||
|
||||
break;
|
||||
}
|
||||
|
||||
mDragStartPosition = MouseEvent->pos();
|
||||
}
|
||||
|
||||
void lcQColorList::mouseMoveEvent(QMouseEvent* MouseEvent)
|
||||
{
|
||||
if (!(MouseEvent->buttons() & Qt::LeftButton))
|
||||
return;
|
||||
|
||||
if ((MouseEvent->pos() - mDragStartPosition).manhattanLength() < QApplication::startDragDistance())
|
||||
return;
|
||||
|
||||
QMimeData* MimeData = new QMimeData;
|
||||
MimeData->setData("application/vnd.leocad-color", QString::number(mCellColors[mCurCell]).toLatin1());
|
||||
|
||||
QDrag* Drag = new QDrag(this);
|
||||
Drag->setMimeData(MimeData);
|
||||
|
||||
Drag->exec(Qt::CopyAction);
|
||||
}
|
||||
|
||||
void lcQColorList::keyPressEvent(QKeyEvent *event)
|
||||
|
|
|
@ -20,11 +20,12 @@ signals:
|
|||
void colorSelected(int colorIndex);
|
||||
|
||||
protected:
|
||||
bool event(QEvent *event);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
virtual bool event(QEvent* Event) override;
|
||||
virtual void paintEvent(QPaintEvent* PaintEvent) override;
|
||||
virtual void resizeEvent(QResizeEvent* ResizeEvent) override;
|
||||
virtual void mousePressEvent(QMouseEvent* MouseEvent) override;
|
||||
virtual void mouseMoveEvent(QMouseEvent* MouseEvent) override;
|
||||
virtual void keyPressEvent(QKeyEvent* KeyEvent) override;
|
||||
|
||||
void SelectCell(int CellIdx);
|
||||
|
||||
|
@ -40,5 +41,6 @@ protected:
|
|||
int mPreferredHeight;
|
||||
|
||||
int mCurCell;
|
||||
QPoint mDragStartPosition;
|
||||
};
|
||||
|
||||
|
|
|
@ -117,8 +117,8 @@ lcQGLWidget::lcQGLWidget(QWidget *parent, lcGLWidget *owner, bool view)
|
|||
preferredSize = QSize(0, 0);
|
||||
setMouseTracking(true);
|
||||
|
||||
isView = view;
|
||||
if (isView)
|
||||
mIsView = view;
|
||||
if (mIsView)
|
||||
{
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
setAcceptDrops(true);
|
||||
|
@ -174,7 +174,7 @@ void lcQGLWidget::paintGL()
|
|||
|
||||
void lcQGLWidget::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (isView && (event->key() == Qt::Key_Control || event->key() == Qt::Key_Shift))
|
||||
if (mIsView && (event->key() == Qt::Key_Control || event->key() == Qt::Key_Shift))
|
||||
{
|
||||
widget->mInputState.Modifiers = event->modifiers();
|
||||
widget->OnUpdateCursor();
|
||||
|
@ -185,7 +185,7 @@ void lcQGLWidget::keyPressEvent(QKeyEvent *event)
|
|||
|
||||
void lcQGLWidget::keyReleaseEvent(QKeyEvent *event)
|
||||
{
|
||||
if (isView && (event->key() == Qt::Key_Control || event->key() == Qt::Key_Shift))
|
||||
if (mIsView && (event->key() == Qt::Key_Control || event->key() == Qt::Key_Shift))
|
||||
{
|
||||
widget->mInputState.Modifiers = event->modifiers();
|
||||
widget->OnUpdateCursor();
|
||||
|
@ -327,57 +327,76 @@ void lcQGLWidget::wheelEvent(QWheelEvent *event)
|
|||
event->accept();
|
||||
}
|
||||
|
||||
void lcQGLWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||
void lcQGLWidget::dragEnterEvent(QDragEnterEvent* DragEnterEvent)
|
||||
{
|
||||
if (isView && event->mimeData()->hasFormat("application/vnd.leocad-part"))
|
||||
if (mIsView)
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
const QMimeData* MimeData = DragEnterEvent->mimeData();
|
||||
|
||||
QByteArray pieceData = event->mimeData()->data("application/vnd.leocad-part");
|
||||
QDataStream dataStream(&pieceData, QIODevice::ReadOnly);
|
||||
QString id;
|
||||
|
||||
dataStream >> id;
|
||||
|
||||
((View*)widget)->BeginPieceDrag();
|
||||
if (MimeData->hasFormat("application/vnd.leocad-part"))
|
||||
{
|
||||
DragEnterEvent->acceptProposedAction();
|
||||
((View*)widget)->BeginDrag(lcDragState::PIECE);
|
||||
}
|
||||
else if (MimeData->hasFormat("application/vnd.leocad-color"))
|
||||
{
|
||||
DragEnterEvent->acceptProposedAction();
|
||||
((View*)widget)->BeginDrag(lcDragState::COLOR);
|
||||
}
|
||||
}
|
||||
else
|
||||
event->ignore();
|
||||
DragEnterEvent->ignore();
|
||||
}
|
||||
|
||||
void lcQGLWidget::dragLeaveEvent(QDragLeaveEvent *event)
|
||||
{
|
||||
if (!isView)
|
||||
if (!mIsView)
|
||||
return;
|
||||
|
||||
((View*)widget)->EndPieceDrag(false);
|
||||
((View*)widget)->EndDrag(false);
|
||||
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void lcQGLWidget::dragMoveEvent(QDragMoveEvent *event)
|
||||
void lcQGLWidget::dragMoveEvent(QDragMoveEvent* DragMoveEvent)
|
||||
{
|
||||
if (!isView || !event->mimeData()->hasFormat("application/vnd.leocad-part"))
|
||||
return;
|
||||
if (mIsView)
|
||||
{
|
||||
const QMimeData* MimeData = DragMoveEvent->mimeData();
|
||||
|
||||
float scale = deviceScale();
|
||||
if (MimeData->hasFormat("application/vnd.leocad-part") || MimeData->hasFormat("application/vnd.leocad-color"))
|
||||
{
|
||||
float scale = deviceScale();
|
||||
|
||||
widget->mInputState.x = event->pos().x() * scale;
|
||||
widget->mInputState.y = widget->mHeight - event->pos().y() * scale - 1;
|
||||
widget->mInputState.Modifiers = event->keyboardModifiers();
|
||||
widget->mInputState.x = DragMoveEvent->pos().x() * scale;
|
||||
widget->mInputState.y = widget->mHeight - DragMoveEvent->pos().y() * scale - 1;
|
||||
widget->mInputState.Modifiers = DragMoveEvent->keyboardModifiers();
|
||||
|
||||
widget->OnMouseMove();
|
||||
widget->OnMouseMove();
|
||||
|
||||
event->accept();
|
||||
DragMoveEvent->accept();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QGLWidget::dragMoveEvent(DragMoveEvent);
|
||||
}
|
||||
|
||||
void lcQGLWidget::dropEvent(QDropEvent *event)
|
||||
void lcQGLWidget::dropEvent(QDropEvent* DropEvent)
|
||||
{
|
||||
if (!isView || !event->mimeData()->hasFormat("application/vnd.leocad-part"))
|
||||
return;
|
||||
if (mIsView)
|
||||
{
|
||||
const QMimeData* MimeData = DropEvent->mimeData();
|
||||
|
||||
((View*)widget)->EndPieceDrag(true);
|
||||
setFocus(Qt::MouseFocusReason);
|
||||
if (MimeData->hasFormat("application/vnd.leocad-part") || MimeData->hasFormat("application/vnd.leocad-color"))
|
||||
{
|
||||
((View*)widget)->EndDrag(true);
|
||||
setFocus(Qt::MouseFocusReason);
|
||||
|
||||
event->accept();
|
||||
DropEvent->accept();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QGLWidget::dropEvent(DropEvent);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ public:
|
|||
|
||||
lcGLWidget *widget;
|
||||
QSize preferredSize;
|
||||
bool isView;
|
||||
bool mIsView;
|
||||
|
||||
float deviceScale()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue