86 lines
3.0 KiB
C++
86 lines
3.0 KiB
C++
#pragma once
|
|
|
|
#include "Axis.h"
|
|
#include "AbsAxis_p.h"
|
|
#include <cmath>
|
|
|
|
namespace YSG {
|
|
struct AxisRenderState : AbsAxisRenderState{
|
|
|
|
};
|
|
|
|
struct AxisTempData : AbsAxisTempData {
|
|
|
|
};
|
|
|
|
struct AxisPrivate : AbsAxisPrivate {
|
|
D_Ptr(Axis)
|
|
bool useWheel = false;
|
|
bool useDrag = false;
|
|
protected:
|
|
bool selectTest(const QPointF& pos) override {return true;}
|
|
void wheelEvent(QWheelEvent* event) override {
|
|
if(useWheel) {
|
|
SpinLockGuard _guard(&mBufferLock);
|
|
RenderEditGuard _editGuard(this);
|
|
const double delta = event->angleDelta().y();
|
|
double wheelSteps = delta / 120.0;
|
|
double factor = std::pow(0.8, wheelSteps);
|
|
auto rc = renderStateCache();
|
|
double cursor_coord = pixelToCoord(event->position().x(), SRC::Cache);
|
|
double new_coordLength = rc->coordLength * factor;
|
|
double new_coordStart = cursor_coord - new_coordLength * (cursor_coord - rc->coordStart) / rc->coordLength;
|
|
rc->coordStart = new_coordStart;
|
|
rc->coordLength = new_coordLength;
|
|
}
|
|
}
|
|
bool dragging = false;
|
|
QPoint startGlobalPos, startPos;
|
|
double startCoordValue;
|
|
double pixelPreCoord;
|
|
void mousePressEvent(QMouseEvent* event) override {
|
|
if(!useDrag) return;
|
|
if(event->button() != Qt::LeftButton) return;
|
|
if(dragging) return;
|
|
SpinLockGuard _guard(&mBufferLock);
|
|
dragging = true;
|
|
startGlobalPos = QCursor::pos();
|
|
startPos = event->pos();
|
|
auto rc = renderStateCache();
|
|
startCoordValue = rc->coordStart;
|
|
pixelPreCoord = rc->coordLength/static_cast<double>(rc->pixelSize);
|
|
}
|
|
void mouseMoveEvent(QMouseEvent* event) override {
|
|
if(!useDrag) return;
|
|
if(!(event->buttons() & Qt::LeftButton)) return;
|
|
if(!dragging) return;
|
|
SpinLockGuard _guard(&mBufferLock);
|
|
RenderEditGuard _editGuard(this);
|
|
QPoint delt = startGlobalPos - QCursor::pos();
|
|
auto rc = renderStateCache();
|
|
auto coordDelt = pixelPreCoord * (rc->orientation == Qt::Horizontal ? delt.x() :delt.y());
|
|
rc->coordStart = startCoordValue + coordDelt;
|
|
}
|
|
void mouseReleaseEvent(QMouseEvent* event) override {
|
|
if(!useDrag) return;
|
|
if(event->button() != Qt::LeftButton) return;
|
|
if(!dragging) return;
|
|
dragging = false;
|
|
}
|
|
};
|
|
|
|
template <typename That>
|
|
void Axis::BuilderT<That>::set(Axis* ret) {
|
|
AbsAxis::BuilderT<That>::set(ret);
|
|
AxisPrivate* pd = ret->d();
|
|
AxisRenderState* sc = pd->renderStateCache();
|
|
PROP_RT(int, numberPrecision)
|
|
PROP_RT(double, coordStart)
|
|
PROP_RT(double, coordLength)
|
|
pd->useWheel = useWheel;
|
|
pd->useDrag = useDrag;
|
|
}
|
|
}
|
|
|
|
|