first commit
This commit is contained in:
157
project/fm_viewer/ui/rm_slider.cpp
Normal file
157
project/fm_viewer/ui/rm_slider.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
#include "rm_slider.h"
|
||||
|
||||
#include <QStyle>
|
||||
#include <QStyleOption>
|
||||
#include <QMouseEvent>
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QStylePainter>
|
||||
#include "../rm_include.h"
|
||||
|
||||
RMSlider::RMSlider(QWidget *parent):
|
||||
QSlider(parent)
|
||||
{
|
||||
setOrientation(Qt::Horizontal);
|
||||
setFocusPolicy(Qt::NoFocus); // 처리해도 mouse wheel 은 처리안됨
|
||||
}
|
||||
|
||||
RMSlider::~RMSlider()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline int RMSlider::pick(const QPoint &pt) const
|
||||
{
|
||||
return orientation() == Qt::Horizontal ? pt.x() : pt.y();
|
||||
}
|
||||
// Function copied from qslider.cpp and modified to make it compile
|
||||
int RMSlider::pixelPosToRangeValue(int pos) const
|
||||
{
|
||||
QStyleOptionSlider opt;
|
||||
initStyleOption(&opt);
|
||||
QRect gr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, this);
|
||||
QRect sr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
|
||||
int sliderMin, sliderMax, sliderLength;
|
||||
if (orientation() == Qt::Horizontal) {
|
||||
sliderLength = sr.width();
|
||||
sliderMin = gr.x();
|
||||
sliderMax = gr.right() - sliderLength + 1;
|
||||
} else {
|
||||
sliderLength = sr.height();
|
||||
sliderMin = gr.y();
|
||||
sliderMax = gr.bottom() - sliderLength + 1;
|
||||
}
|
||||
return QStyle::sliderValueFromPosition(minimum(), maximum(), pos - sliderMin,
|
||||
sliderMax - sliderMin, opt.upsideDown);
|
||||
}
|
||||
// Based on code from qslider.cpp
|
||||
void RMSlider::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
//LOG_TEST;
|
||||
//qInfo() << e;
|
||||
|
||||
//qDebug("pressed (%d, %d)", e->pos().x(), e->pos().y());
|
||||
if (e->button() == Qt::LeftButton)
|
||||
{
|
||||
QStyleOptionSlider opt;
|
||||
initStyleOption(&opt);
|
||||
const QRect sliderRect = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
|
||||
const QPoint center = sliderRect.center() - sliderRect.topLeft();
|
||||
// to take half of the slider off for the setSliderPosition call we use the center - topLeft
|
||||
|
||||
// DRAG 처리
|
||||
bool bKnob = sliderRect.contains(e->pos());
|
||||
if (!bKnob)
|
||||
{
|
||||
e->accept();
|
||||
int v = pixelPosToRangeValue(pick(e->pos() - center));
|
||||
setSliderPosition(v);
|
||||
setRepeatAction(SliderNoAction);
|
||||
|
||||
// KNOB 영역이 아닌 경우에도 이벤트 발생시키기 위해 처리
|
||||
emit sliderPressed();
|
||||
}
|
||||
else
|
||||
{
|
||||
QSlider::mousePressEvent(e);
|
||||
}
|
||||
|
||||
// KNOB 클릭과 아닌 경우 구분하기 위해 사용 (비디오 이동시 pause 처리 등)
|
||||
emit sliderPressedWithKnob(bKnob);
|
||||
}
|
||||
else
|
||||
{
|
||||
QSlider::mousePressEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
void RMSlider::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
}
|
||||
void RMSlider::mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->button() == Qt::LeftButton)
|
||||
{
|
||||
emit mouseReleased();
|
||||
}
|
||||
QSlider::mouseReleaseEvent(e);
|
||||
}
|
||||
|
||||
RMReleasedSlider::RMReleasedSlider(QWidget *parent) : RMSlider(parent)
|
||||
{
|
||||
|
||||
}
|
||||
void RMReleasedSlider::mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
if (e->button() == Qt::LeftButton)
|
||||
{
|
||||
emit mouseReleased();
|
||||
}
|
||||
QSlider::mousePressEvent(e);
|
||||
}
|
||||
/*
|
||||
void RMReleasedSlider::paintEvent(QPaintEvent *pe)
|
||||
{
|
||||
Q_UNUSED(pe);
|
||||
|
||||
QStylePainter p(this);
|
||||
QStyleOptionSlider opt;
|
||||
initStyleOption(&opt);
|
||||
|
||||
int interval = tickInterval();
|
||||
if (interval == 0)
|
||||
{
|
||||
interval = pageStep();
|
||||
}
|
||||
|
||||
if (tickPosition() != NoTicks && tickStrings.isEmpty() == false)
|
||||
{
|
||||
QFont font = p.font();
|
||||
font.setPixelSize(12);
|
||||
p.setFont(font);
|
||||
QRect handle = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
|
||||
for (int i = minimum(); i <= maximum(); i += interval)
|
||||
{
|
||||
int x = ceil((double)((double)((double)(i - this->minimum()) / (double)(this->maximum() - this->minimum())) * (double)(this->width() - handle.width()) + (double)(handle.width() / 2.0))) - 1;
|
||||
|
||||
p.setPen(QColor("#8F8F8F"));
|
||||
int y = this->rect().top()+4;
|
||||
p.drawLine(x, y, x, y + 10);
|
||||
|
||||
p.setPen(QColor("#FFFFFF"));
|
||||
p.drawText(x-6,y+22,tickStrings[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// draw the slider (this is basically copy/pasted from QSlider::paintEvent)
|
||||
opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle;
|
||||
p.drawComplexControl(QStyle::CC_Slider, opt);
|
||||
|
||||
// 실제 동작하지 않음 draw the slider handle
|
||||
// opt.subControls = QStyle::SC_SliderHandle;
|
||||
// p.drawComplexControl(QStyle::CC_Slider, opt);
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user