mirror of
https://bitbucket.org/mfeemster/fractorium.git
synced 2025-01-21 21:20:07 -05:00
cd1749fe5f
-Add the ability to drag the rotation of the current palette via the palette preview table.
76 lines
2.4 KiB
C++
76 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include "FractoriumPch.h"
|
|
|
|
/// <summary>
|
|
/// TableWidget class.
|
|
/// </summary>
|
|
|
|
/// <summary>
|
|
/// The entire purpose for this subclass is to overcome a glaring flaw
|
|
/// in the way Qt handles table drawing.
|
|
/// For most of the tables Fractorium uses, it draw the grid lines. Qt draws them
|
|
/// in a very naive manner, whereby it draws lines above the first row and below
|
|
/// the last row. It also draws to the left of the first column and to the right
|
|
/// of the last column. This has the effect of putting an additional border inside
|
|
/// of the specified border. This extra border becomes very noticeable when changing
|
|
/// the background color of a cell.
|
|
/// The workaround is to scrunch the size of the table up by one pixel. However,
|
|
/// since the viewable area is then smaller than the size of the table, it will scroll
|
|
/// by one pixel if the mouse is hovered over the table and the user moves the mouse wheel.
|
|
/// This subclass is done solely to filter out the mouse wheel event.
|
|
/// Note that this filtering only applies to the table as a whole, which means
|
|
/// mouse wheel events still get properly routed to spinners.
|
|
/// </summary>
|
|
class TableWidget : public QTableWidget
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
/// <summary>
|
|
/// Constructor that passes the parent to the base and installs
|
|
/// the event filter.
|
|
/// </summary>
|
|
/// <param name="p">The parent widget</param>
|
|
explicit TableWidget(QWidget* p = nullptr)
|
|
: QTableWidget(p)
|
|
{
|
|
viewport()->installEventFilter(this);
|
|
}
|
|
|
|
|
|
signals:
|
|
void MouseDragged(const QPointF& local, const QPoint& global);
|
|
void MouseReleased();
|
|
|
|
protected:
|
|
|
|
/// <summary>
|
|
/// Event filter to ignore mouse wheel events and also handle others such as mouse move and mouse button release.
|
|
/// Sadly, QTableWidget makes these hard to get to, so we must handle them here.
|
|
/// </summary>
|
|
/// <param name="obj">The object sending the event</param>
|
|
/// <param name="e">The event</param>
|
|
/// <returns>True if mouse wheel, else return the result of calling the base fucntion.</returns>
|
|
bool eventFilter(QObject* obj, QEvent* e)
|
|
{
|
|
if (e->type() == QEvent::Wheel)
|
|
{
|
|
e->ignore();
|
|
return true;
|
|
}
|
|
else if (e->type() == QEvent::MouseMove)
|
|
{
|
|
if (auto me = dynamic_cast<QMouseEvent*>(e))
|
|
{
|
|
emit MouseDragged(me->localPos(), me->globalPos());
|
|
}
|
|
}
|
|
else if (e->type() == QEvent::MouseButtonRelease)
|
|
{
|
|
emit MouseReleased();
|
|
}
|
|
|
|
return QTableWidget::eventFilter(obj, e);
|
|
}
|
|
};
|