more updates
This commit is contained in:
@@ -4,7 +4,8 @@
|
|||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
|
|
||||||
#include "flowlayout.h"
|
#include "flowlayout.h"
|
||||||
//! [1]
|
#include "utils.hpp"
|
||||||
|
|
||||||
FlowLayout::FlowLayout(QWidget* parent, int margin, int hSpacing, int vSpacing)
|
FlowLayout::FlowLayout(QWidget* parent, int margin, int hSpacing, int vSpacing)
|
||||||
: QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)
|
: QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)
|
||||||
{
|
{
|
||||||
@@ -34,24 +35,33 @@ void FlowLayout::addItem(QLayoutItem *item)
|
|||||||
|
|
||||||
int FlowLayout::horizontalSpacing() const
|
int FlowLayout::horizontalSpacing() const
|
||||||
{
|
{
|
||||||
if (m_hSpace >= 0) {
|
if (m_hSpace >= 0)
|
||||||
|
{
|
||||||
return m_hSpace;
|
return m_hSpace;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return smartSpacing(QStyle::PM_LayoutHorizontalSpacing);
|
return smartSpacing(QStyle::PM_LayoutHorizontalSpacing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FlowLayout::verticalSpacing() const
|
int FlowLayout::verticalSpacing() const
|
||||||
{
|
{
|
||||||
if (m_vSpace >= 0) {
|
if (m_vSpace >= 0)
|
||||||
|
{
|
||||||
return m_vSpace;
|
return m_vSpace;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
|
return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FlowLayout::count() const
|
int FlowLayout::count() const
|
||||||
{
|
{
|
||||||
|
qInfo() << "getting item list size";
|
||||||
|
if (itemList.isEmpty())
|
||||||
|
return 0;
|
||||||
return itemList.size();
|
return itemList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,12 +108,16 @@ QSize FlowLayout::minimumSize() const
|
|||||||
{
|
{
|
||||||
QSize size;
|
QSize size;
|
||||||
for (const QLayoutItem* item : std::as_const(itemList))
|
for (const QLayoutItem* item : std::as_const(itemList))
|
||||||
|
{
|
||||||
size = size.expandedTo(item->minimumSize());
|
size = size.expandedTo(item->minimumSize());
|
||||||
|
}
|
||||||
const QMargins margins = contentsMargins();
|
const QMargins margins = contentsMargins();
|
||||||
size += QSize(margins.left() + margins.right(), margins.top() + margins.bottom());
|
size += QSize(margins.left() + margins.right(), margins.top() + margins.bottom());
|
||||||
if (size.height() < minimumHeight())
|
auto minh = minimumHeight();
|
||||||
size.rheight() = minimumHeight();
|
if (size.height() < minh)
|
||||||
|
{
|
||||||
|
size.rheight() = minh;
|
||||||
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,27 +129,33 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
|
|||||||
int x = effectiveRect.x();
|
int x = effectiveRect.x();
|
||||||
int y = effectiveRect.y();
|
int y = effectiveRect.y();
|
||||||
int lineHeight = 0;
|
int lineHeight = 0;
|
||||||
for (QLayoutItem* item : std::as_const(itemList)) {
|
for (QLayoutItem* item : std::as_const(itemList))
|
||||||
|
{
|
||||||
const QWidget* wid = item->widget();
|
const QWidget* wid = item->widget();
|
||||||
int spaceX = horizontalSpacing();
|
int spaceX = horizontalSpacing();
|
||||||
if (spaceX == -1)
|
if (spaceX == -1)
|
||||||
|
{
|
||||||
spaceX = wid->style()->layoutSpacing(
|
spaceX = wid->style()->layoutSpacing(
|
||||||
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
|
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
|
||||||
|
}
|
||||||
int spaceY = verticalSpacing();
|
int spaceY = verticalSpacing();
|
||||||
if (spaceY == -1)
|
if (spaceY == -1)
|
||||||
|
{
|
||||||
spaceY = wid->style()->layoutSpacing(
|
spaceY = wid->style()->layoutSpacing(
|
||||||
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
|
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
|
||||||
|
}
|
||||||
int nextX = x + item->sizeHint().width() + spaceX;
|
int nextX = x + item->sizeHint().width() + spaceX;
|
||||||
if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
|
if (nextX - spaceX > effectiveRect.right() && lineHeight > 0)
|
||||||
|
{
|
||||||
x = effectiveRect.x();
|
x = effectiveRect.x();
|
||||||
y = y + lineHeight + spaceY;
|
y = y + lineHeight + spaceY;
|
||||||
nextX = x + item->sizeHint().width() + spaceX;
|
nextX = x + item->sizeHint().width() + spaceX;
|
||||||
lineHeight = 0;
|
lineHeight = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!testOnly)
|
if (!testOnly)
|
||||||
|
{
|
||||||
item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
|
item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
|
||||||
|
}
|
||||||
x = nextX;
|
x = nextX;
|
||||||
lineHeight = qMax(lineHeight, item->sizeHint().height());
|
lineHeight = qMax(lineHeight, item->sizeHint().height());
|
||||||
}
|
}
|
||||||
@@ -162,14 +182,23 @@ int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
|
|||||||
|
|
||||||
void FlowLayout::setIndex(QWidget* wid, int index)
|
void FlowLayout::setIndex(QWidget* wid, int index)
|
||||||
{
|
{
|
||||||
if (itemAt(index)->widget() == wid)
|
qInfo() << "set index" << index;
|
||||||
|
if (index < count() && itemAt(index)->widget() == wid)
|
||||||
return;
|
return;
|
||||||
|
qInfo() << "past first check";
|
||||||
|
IndexOutOfRangeException::ThrowIf(index, 0, {});
|
||||||
|
qInfo() << "past second check";
|
||||||
wid->setParent(nullptr);
|
wid->setParent(nullptr);
|
||||||
|
qInfo() << "cleared parent";
|
||||||
addWidget(wid);
|
addWidget(wid);
|
||||||
if (index < 0)
|
qInfo() << "added widget";
|
||||||
return;
|
IndexOutOfRangeException::ThrowIf(index, {}, count()-1);
|
||||||
for (int i = count()-1; i > index; i--)
|
qInfo() << "past third check";
|
||||||
|
for (int i = count()-1; i > +1; i--)
|
||||||
{
|
{
|
||||||
|
qInfo() << "about to swap" << i-1 << "and" << i;
|
||||||
|
//TODO excessive, should remove later
|
||||||
|
IndexOutOfRangeException::ThrowIf(index, 0, count()-1);
|
||||||
itemList.swapItemsAt(i-1, i);
|
itemList.swapItemsAt(i-1, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,8 +133,10 @@ void TierCard::mousePressEvent(QMouseEvent* event)
|
|||||||
render(&pix);
|
render(&pix);
|
||||||
QDrag drag(this);
|
QDrag drag(this);
|
||||||
drag.setPixmap(pix);
|
drag.setPixmap(pix);
|
||||||
drag.setHotSpot(QPoint(pix.size().width() / 2,
|
// const auto scale = compareMultiplier(ComparePoint::MiddleCenter);
|
||||||
pix.size().height() / 2));
|
// drag.setHotSpot(QPoint(pix.size().width() * std::get<0>(scale),
|
||||||
|
// pix.size().height() * std::get<1>(scale)));
|
||||||
|
drag.setHotSpot(getPoint(this, ComparePoint::MiddleCenter));
|
||||||
QByteArray itemData;
|
QByteArray itemData;
|
||||||
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
|
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
|
||||||
TierCard::IdType _id = getId();
|
TierCard::IdType _id = getId();
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ class TierPlaceholder : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit TierPlaceholder(QWidget *parent = nullptr);
|
explicit TierPlaceholder(QWidget *parent = nullptr);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void cardResize(QSize newSize);
|
void cardResize(QSize newSize);
|
||||||
|
|
||||||
|
|||||||
83
tierrow.cpp
83
tierrow.cpp
@@ -1,5 +1,4 @@
|
|||||||
#include "tierrow.hpp"
|
#include "tierrow.hpp"
|
||||||
// #include "fullsizelayout.hpp"
|
|
||||||
#include "qmimedata.h"
|
#include "qmimedata.h"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
#include "settings.hpp"
|
#include "settings.hpp"
|
||||||
@@ -130,7 +129,6 @@ void TierRow::dropEvent(QDropEvent* event)
|
|||||||
{
|
{
|
||||||
if (event->proposedAction() == Qt::MoveAction)
|
if (event->proposedAction() == Qt::MoveAction)
|
||||||
{
|
{
|
||||||
clearPlaceholder();
|
|
||||||
auto data = event->mimeData()->data(TierCard::MimeType);
|
auto data = event->mimeData()->data(TierCard::MimeType);
|
||||||
QDataStream stream(&data, QIODevice::ReadOnly);
|
QDataStream stream(&data, QIODevice::ReadOnly);
|
||||||
TierCard::IdType cardId;
|
TierCard::IdType cardId;
|
||||||
@@ -139,7 +137,12 @@ void TierRow::dropEvent(QDropEvent* event)
|
|||||||
if (!card)
|
if (!card)
|
||||||
throw InvalidCardIdException(cardId);
|
throw InvalidCardIdException(cardId);
|
||||||
// addCard(card);
|
// 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();
|
event->acceptProposedAction();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -156,22 +159,21 @@ void TierRow::dropEvent(QDropEvent* event)
|
|||||||
|
|
||||||
void TierRow::dragEnterEvent(QDragEnterEvent* event)
|
void TierRow::dragEnterEvent(QDragEnterEvent* event)
|
||||||
{
|
{
|
||||||
qDebug() << "drag enter event";
|
qInfo() << "DRAG ENTER EVENT";
|
||||||
if (cardCount() == 0)
|
|
||||||
{
|
|
||||||
qDebug() << "enter empty";
|
|
||||||
}
|
|
||||||
if (event->mimeData()->hasFormat(TierCard::MimeType))
|
if (event->mimeData()->hasFormat(TierCard::MimeType))
|
||||||
{
|
{
|
||||||
if (event->proposedAction() == Qt::MoveAction)
|
if (event->proposedAction() == Qt::MoveAction)
|
||||||
{
|
{
|
||||||
if (placeholder != nullptr)
|
if (placeholder)
|
||||||
{
|
{
|
||||||
qDebug() << "placeholder not previously cleared";
|
qWarning() << "placeholder not previously cleared";
|
||||||
clearPlaceholder();
|
|
||||||
}
|
}
|
||||||
placeholder = new TierPlaceholder();
|
else
|
||||||
cardLayout->setIndex(placeholder, calculateIndex(event->position()));
|
{
|
||||||
|
placeholder = new TierPlaceholder();
|
||||||
|
}
|
||||||
|
placeholderIndex = calculateIndex(event->position());
|
||||||
|
cardLayout->setIndex(placeholder, placeholderIndex);
|
||||||
event->setDropAction(Qt::MoveAction);
|
event->setDropAction(Qt::MoveAction);
|
||||||
event->accept(cardContainer->rect());
|
event->accept(cardContainer->rect());
|
||||||
}
|
}
|
||||||
@@ -184,25 +186,33 @@ void TierRow::dragEnterEvent(QDragEnterEvent* event)
|
|||||||
else if (event->mimeData()->hasImage())
|
else if (event->mimeData()->hasImage())
|
||||||
{
|
{
|
||||||
event->setDropAction(Qt::CopyAction);
|
event->setDropAction(Qt::CopyAction);
|
||||||
event->accept();
|
//TODO event->accept();
|
||||||
|
event->ignore();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
event->ignore();
|
event->ignore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TierRow::dragMoveEvent(QDragMoveEvent* event)
|
void TierRow::dragMoveEvent(QDragMoveEvent* event)
|
||||||
{
|
{
|
||||||
|
qInfo() << "DRAG MOVE EVENT";
|
||||||
if (event->mimeData()->hasFormat(TierCard::MimeType))
|
if (event->mimeData()->hasFormat(TierCard::MimeType))
|
||||||
{
|
{
|
||||||
if (event->proposedAction() == Qt::MoveAction)
|
if (event->proposedAction() == Qt::MoveAction)
|
||||||
{
|
{
|
||||||
if (cardCount() == 1)
|
|
||||||
{
|
|
||||||
qDebug() << "moving in empty";
|
|
||||||
}
|
|
||||||
if (placeholder)
|
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();
|
event->acceptProposedAction();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -230,6 +240,7 @@ void TierRow::dragLeaveEvent(QDragLeaveEvent* event)
|
|||||||
|
|
||||||
void TierRow::clearPlaceholder()
|
void TierRow::clearPlaceholder()
|
||||||
{
|
{
|
||||||
|
placeholderIndex = 0;
|
||||||
placeholder->setParent(nullptr);
|
placeholder->setParent(nullptr);
|
||||||
placeholder->deleteLater();
|
placeholder->deleteLater();
|
||||||
placeholder = nullptr;
|
placeholder = nullptr;
|
||||||
@@ -237,22 +248,38 @@ void TierRow::clearPlaceholder()
|
|||||||
|
|
||||||
int TierRow::calculateIndex(QPointF loc)
|
int TierRow::calculateIndex(QPointF loc)
|
||||||
{
|
{
|
||||||
|
qInfo() << "Starting calculate index";
|
||||||
|
qInfo() << "location" << loc;
|
||||||
auto settings = Settings::get();
|
auto settings = Settings::get();
|
||||||
auto cardSize = settings->cardSize();
|
auto cardSize = settings->cardSize();
|
||||||
auto cardCenter = loc + QPointF(cardSize.width() / 2,
|
qInfo() << "card size" << cardSize;
|
||||||
cardSize.height() / 2);
|
// auto cardCenter = loc + QPointF(cardSize.width() / 2,
|
||||||
auto lastBefore = 0;
|
// cardSize.height() / 2);
|
||||||
for (int i = 0; i < cardLayout->count(); i++)
|
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 refCard = cardLayout->itemAt(i);
|
||||||
auto refPos = refCard->widget()->pos();
|
qInfo() << "index" << i << "geometry" << refCard->geometry();
|
||||||
if (cardCenter.y() > refPos.y()
|
// auto refPos = refCard->widget()->pos() + offset;
|
||||||
&& cardCenter.x() > refPos.x())
|
if (isAfter(refCard->widget(), useLoc, ComparePoint::TopCenter))
|
||||||
lastBefore = i;
|
lastBefore = i;
|
||||||
else
|
else
|
||||||
break;
|
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)
|
void TierRow::cardResize(QSize newSize)
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ private:
|
|||||||
QColor _color;
|
QColor _color;
|
||||||
const IdType _id;
|
const IdType _id;
|
||||||
TierPlaceholder* placeholder = nullptr;
|
TierPlaceholder* placeholder = nullptr;
|
||||||
|
int placeholderIndex;
|
||||||
void recalcMaxHeight();
|
void recalcMaxHeight();
|
||||||
void clearPlaceholder();
|
void clearPlaceholder();
|
||||||
int calculateIndex(QPointF loc);
|
int calculateIndex(QPointF loc);
|
||||||
|
|||||||
167
utils.hpp
167
utils.hpp
@@ -3,8 +3,11 @@
|
|||||||
|
|
||||||
// #include "tierrow.hpp"
|
// #include "tierrow.hpp"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QException>
|
||||||
|
|
||||||
//change this stupid name
|
//change this stupid name
|
||||||
inline void callOnMeAndChildren(QObject* obj, void (*func)(QObject*))
|
inline void callOnMeAndChildren(QObject* obj, void (*func)(QObject*))
|
||||||
@@ -64,4 +67,168 @@ inline QColor blend(QColor first, QColor second, float portionFirst)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline QPoint midpoint(QWidget* wid)
|
||||||
|
{
|
||||||
|
const auto& size = wid->size();
|
||||||
|
return QPoint(size.width() / 2,
|
||||||
|
size.height() / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline QPoint midpoint(QSize size)
|
||||||
|
{
|
||||||
|
return QPoint(size.width() / 2,
|
||||||
|
size.height() / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
class InvalidEnumException : public QException
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
InvalidEnumException(int value, QString type = "")
|
||||||
|
: type(type), value(value)
|
||||||
|
{
|
||||||
|
_what = InvalidEnumException::_makeWhat(value, type).toLocal8Bit();
|
||||||
|
}
|
||||||
|
template<typename T,
|
||||||
|
typename = std::enable_if<std::is_enum_v<T>>>
|
||||||
|
InvalidEnumException(T value, QString type)
|
||||||
|
: InvalidEnumException(static_cast<int>(value), type)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
const char* what() const noexcept override
|
||||||
|
{
|
||||||
|
return _what.data();
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
const QString type;
|
||||||
|
const int value;
|
||||||
|
QByteArray _what;
|
||||||
|
inline static QString _makeWhat(int value, QString type)
|
||||||
|
{
|
||||||
|
QString str;
|
||||||
|
if (!type.isEmpty())
|
||||||
|
str = "Type: " + type + " ";
|
||||||
|
str += "Value: " + QString::number(value);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class ComparePoint
|
||||||
|
{
|
||||||
|
TopLeft,
|
||||||
|
TopCenter,
|
||||||
|
TopRight,
|
||||||
|
MiddleLeft,
|
||||||
|
MiddleCenter,
|
||||||
|
MiddleRight,
|
||||||
|
BottomLeft,
|
||||||
|
BottomCenter,
|
||||||
|
BottomRight,
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr std::tuple<float, float> compareMultiplier(ComparePoint point)
|
||||||
|
{
|
||||||
|
switch (point)
|
||||||
|
{
|
||||||
|
case ComparePoint::TopLeft: return {0, 0};
|
||||||
|
case ComparePoint::TopCenter: return {0.5, 0};
|
||||||
|
case ComparePoint::TopRight: return {1, 0};
|
||||||
|
case ComparePoint::MiddleLeft: return {0, 0.5};
|
||||||
|
case ComparePoint::MiddleCenter: return {0.5, 0.5};
|
||||||
|
case ComparePoint::MiddleRight: return {1, 0.5};
|
||||||
|
case ComparePoint::BottomLeft: return {0, 1};
|
||||||
|
case ComparePoint::BottomCenter: return {0.5, 1};
|
||||||
|
case ComparePoint::BottomRight: return {1, 1};
|
||||||
|
default: throw InvalidEnumException(point, "ComparePoint");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr QPoint getPoint(QSize size, ComparePoint point)
|
||||||
|
{
|
||||||
|
const auto scale = compareMultiplier(point);
|
||||||
|
return QPoint(size.width() * std::get<0>(scale),
|
||||||
|
size.height() * std::get<1>(scale));
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr QPoint getPoint(QRect rect, ComparePoint point)
|
||||||
|
{
|
||||||
|
return rect.topLeft() + getPoint(rect.size(), point);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr QPoint getPoint(QWidget* wid, ComparePoint point)
|
||||||
|
{
|
||||||
|
return getPoint(wid->geometry(), point);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr bool isAfter(QPointF reference, QPointF test,
|
||||||
|
[[maybe_unused]] ComparePoint point)
|
||||||
|
{
|
||||||
|
if (test.y() > reference.y())
|
||||||
|
return true;
|
||||||
|
return test.x() > reference.x();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool isAfter(QWidget* reference, QPointF test, ComparePoint point)
|
||||||
|
{
|
||||||
|
// const auto scale = compareMultiplier(point);
|
||||||
|
// const auto ref = reference->pos() + QPoint(reference->size().width() * std::get<0>(scale),
|
||||||
|
// reference->size().height() * std::get<1>(scale));
|
||||||
|
const auto ref = getPoint(reference, point);
|
||||||
|
return isAfter(ref, test, point);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool isAfter(QPointF reference, QWidget* test, ComparePoint point)
|
||||||
|
{
|
||||||
|
// const auto scale = compareMultiplier(point);
|
||||||
|
// const auto tst = test->pos() + QPoint(test->size().width() * std::get<0>(scale),
|
||||||
|
// test->size().height() * std::get<1>(scale));
|
||||||
|
const auto tst = getPoint(test, point);
|
||||||
|
return isAfter(reference, tst, point);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool isAfter(QWidget* reference, QWidget* test, ComparePoint point)
|
||||||
|
{
|
||||||
|
// const auto scale = compareMultiplier(point);
|
||||||
|
// const auto tst = test->pos() + QPoint(test->size().width() * std::get<0>(scale),
|
||||||
|
// test->size().height() * std::get<1>(scale));
|
||||||
|
const auto tst = getPoint(test, point);
|
||||||
|
return isAfter(reference, tst, point);
|
||||||
|
}
|
||||||
|
|
||||||
|
class IndexOutOfRangeException : public QException
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IndexOutOfRangeException(qsizetype index,
|
||||||
|
std::optional<qsizetype> min, std::optional<qsizetype> max)
|
||||||
|
: index(index), min(min), max(max)
|
||||||
|
{
|
||||||
|
QString str = "";
|
||||||
|
str += "Value: " + QString::number(index);
|
||||||
|
if (min.has_value())
|
||||||
|
str += " Min: " + QString::number(min.value());
|
||||||
|
if (max.has_value())
|
||||||
|
str += " Max: " + QString::number(max.value());
|
||||||
|
_what = str.toLocal8Bit();
|
||||||
|
}
|
||||||
|
const char* what() const noexcept override
|
||||||
|
{
|
||||||
|
return _what.data();
|
||||||
|
}
|
||||||
|
//assumes inclusive
|
||||||
|
static void ThrowIf(qsizetype index,
|
||||||
|
std::optional<qsizetype> min, std::optional<qsizetype> max)
|
||||||
|
{
|
||||||
|
if ((min.has_value() && index < min.value()) ||
|
||||||
|
(max.has_value() && index > max.value()))
|
||||||
|
{
|
||||||
|
throw IndexOutOfRangeException(index, min, max);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
const qsizetype index;
|
||||||
|
const std::optional<qsizetype> min;
|
||||||
|
const std::optional<qsizetype> max;
|
||||||
|
QByteArray _what;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // UTILS_HPP
|
#endif // UTILS_HPP
|
||||||
|
|||||||
Reference in New Issue
Block a user