#pragma once
#include "FractoriumPch.h"
///
/// TableWidget class.
///
///
/// The purpose of this subclass is to allow for dragging the contents of a table cell.
/// It's used in the palette preview table.
///
class TableWidget : public QTableWidget
{
Q_OBJECT
public:
///
/// Constructor that passes the parent to the base and installs
/// the event filter.
///
/// The parent widget
explicit TableWidget(QWidget* p = nullptr)
: QTableWidget(p)
{
viewport()->installEventFilter(this);
}
signals:
void MouseDragged(const QPointF& local, const QPoint& global);
void MouseReleased();
protected:
///
/// Event filter to handle dragging and releasing the mouse.
/// Sadly, QTableWidget makes these hard to get to, so we must handle them here.
///
/// The object sending the event
/// The event
/// The result of calling the base fucntion.
bool eventFilter(QObject* obj, QEvent* e) override
{
if (e->type() == QEvent::MouseMove)
{
if (const auto me = dynamic_cast(e))
emit MouseDragged(me->localPos(), me->globalPos());
}
else if (e->type() == QEvent::MouseButtonRelease)
emit MouseReleased();
return QTableWidget::eventFilter(obj, e);
}
};