more updates
This commit is contained in:
83
tierrow.cpp
83
tierrow.cpp
@@ -1,5 +1,4 @@
|
||||
#include "tierrow.hpp"
|
||||
// #include "fullsizelayout.hpp"
|
||||
#include "qmimedata.h"
|
||||
#include "utils.hpp"
|
||||
#include "settings.hpp"
|
||||
@@ -130,7 +129,6 @@ void TierRow::dropEvent(QDropEvent* event)
|
||||
{
|
||||
if (event->proposedAction() == Qt::MoveAction)
|
||||
{
|
||||
clearPlaceholder();
|
||||
auto data = event->mimeData()->data(TierCard::MimeType);
|
||||
QDataStream stream(&data, QIODevice::ReadOnly);
|
||||
TierCard::IdType cardId;
|
||||
@@ -139,7 +137,12 @@ void TierRow::dropEvent(QDropEvent* event)
|
||||
if (!card)
|
||||
throw InvalidCardIdException(cardId);
|
||||
// addCard(card);
|
||||
cardLayout->setIndex(card, calculateIndex(event->position()));
|
||||
// auto index = calculateIndex(event->position());
|
||||
// if (index > placeholderIndex)
|
||||
// index--;
|
||||
const auto index = placeholderIndex;
|
||||
clearPlaceholder();
|
||||
cardLayout->setIndex(card, index);
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
else
|
||||
@@ -156,22 +159,21 @@ void TierRow::dropEvent(QDropEvent* event)
|
||||
|
||||
void TierRow::dragEnterEvent(QDragEnterEvent* event)
|
||||
{
|
||||
qDebug() << "drag enter event";
|
||||
if (cardCount() == 0)
|
||||
{
|
||||
qDebug() << "enter empty";
|
||||
}
|
||||
qInfo() << "DRAG ENTER EVENT";
|
||||
if (event->mimeData()->hasFormat(TierCard::MimeType))
|
||||
{
|
||||
if (event->proposedAction() == Qt::MoveAction)
|
||||
{
|
||||
if (placeholder != nullptr)
|
||||
if (placeholder)
|
||||
{
|
||||
qDebug() << "placeholder not previously cleared";
|
||||
clearPlaceholder();
|
||||
qWarning() << "placeholder not previously cleared";
|
||||
}
|
||||
placeholder = new TierPlaceholder();
|
||||
cardLayout->setIndex(placeholder, calculateIndex(event->position()));
|
||||
else
|
||||
{
|
||||
placeholder = new TierPlaceholder();
|
||||
}
|
||||
placeholderIndex = calculateIndex(event->position());
|
||||
cardLayout->setIndex(placeholder, placeholderIndex);
|
||||
event->setDropAction(Qt::MoveAction);
|
||||
event->accept(cardContainer->rect());
|
||||
}
|
||||
@@ -184,25 +186,33 @@ void TierRow::dragEnterEvent(QDragEnterEvent* event)
|
||||
else if (event->mimeData()->hasImage())
|
||||
{
|
||||
event->setDropAction(Qt::CopyAction);
|
||||
event->accept();
|
||||
//TODO event->accept();
|
||||
event->ignore();
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void TierRow::dragMoveEvent(QDragMoveEvent* event)
|
||||
{
|
||||
qInfo() << "DRAG MOVE EVENT";
|
||||
if (event->mimeData()->hasFormat(TierCard::MimeType))
|
||||
{
|
||||
if (event->proposedAction() == Qt::MoveAction)
|
||||
{
|
||||
if (cardCount() == 1)
|
||||
{
|
||||
qDebug() << "moving in empty";
|
||||
}
|
||||
if (placeholder)
|
||||
cardLayout->setIndex(placeholder, calculateIndex(event->position()));
|
||||
{
|
||||
if (!placeholder->rect().contains(event->position().toPoint()))
|
||||
{
|
||||
auto newPlaceholderIndex = calculateIndex(event->position());
|
||||
if (newPlaceholderIndex >= placeholderIndex)
|
||||
newPlaceholderIndex--;
|
||||
placeholderIndex = newPlaceholderIndex;
|
||||
cardLayout->setIndex(placeholder, placeholderIndex);
|
||||
}
|
||||
}
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
else
|
||||
@@ -230,6 +240,7 @@ void TierRow::dragLeaveEvent(QDragLeaveEvent* event)
|
||||
|
||||
void TierRow::clearPlaceholder()
|
||||
{
|
||||
placeholderIndex = 0;
|
||||
placeholder->setParent(nullptr);
|
||||
placeholder->deleteLater();
|
||||
placeholder = nullptr;
|
||||
@@ -237,22 +248,38 @@ void TierRow::clearPlaceholder()
|
||||
|
||||
int TierRow::calculateIndex(QPointF loc)
|
||||
{
|
||||
qInfo() << "Starting calculate index";
|
||||
qInfo() << "location" << loc;
|
||||
auto settings = Settings::get();
|
||||
auto cardSize = settings->cardSize();
|
||||
auto cardCenter = loc + QPointF(cardSize.width() / 2,
|
||||
cardSize.height() / 2);
|
||||
auto lastBefore = 0;
|
||||
for (int i = 0; i < cardLayout->count(); i++)
|
||||
qInfo() << "card size" << cardSize;
|
||||
// auto cardCenter = loc + QPointF(cardSize.width() / 2,
|
||||
// cardSize.height() / 2);
|
||||
auto cardCenter = loc;
|
||||
auto offset = QPoint(midpoint(cardSize).x(), 0);
|
||||
qInfo() << "card center" << cardCenter;
|
||||
auto lastBefore = -1;
|
||||
qInfo() << "card layout ptr" << cardLayout;
|
||||
const auto size = cardLayout->count();
|
||||
const auto useLoc = loc + QPoint(cardSize.width() / 2,
|
||||
cardSize.height() / 2);
|
||||
qInfo() << "size" << size;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
qInfo() << "getting item at index" << i;
|
||||
auto refCard = cardLayout->itemAt(i);
|
||||
auto refPos = refCard->widget()->pos();
|
||||
if (cardCenter.y() > refPos.y()
|
||||
&& cardCenter.x() > refPos.x())
|
||||
qInfo() << "index" << i << "geometry" << refCard->geometry();
|
||||
// auto refPos = refCard->widget()->pos() + offset;
|
||||
if (isAfter(refCard->widget(), useLoc, ComparePoint::TopCenter))
|
||||
lastBefore = i;
|
||||
else
|
||||
break;
|
||||
}
|
||||
return lastBefore;
|
||||
// qInfo() << "last before" << cardLayout->itemAt(lastBefore)->widget()->pos()
|
||||
// << "index" << lastBefore;
|
||||
const auto retVal = lastBefore+1;
|
||||
qInfo() << "calculated index" << retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void TierRow::cardResize(QSize newSize)
|
||||
|
||||
Reference in New Issue
Block a user