various improvements
This commit is contained in:
+73
-7
@@ -10,7 +10,9 @@
|
||||
#include <QApplication>
|
||||
|
||||
LabelSlider::LabelSlider(QWidget* parent) : QLabel(parent) {
|
||||
// set a default frame rate - fallback, shouldn't ever really be used
|
||||
frame_rate = 30;
|
||||
|
||||
decimal_places = 1;
|
||||
drag_start = false;
|
||||
drag_proc = false;
|
||||
@@ -96,7 +98,7 @@ void LabelSlider::set_default_value(double v) {
|
||||
}
|
||||
|
||||
void LabelSlider::set_minimum_value(double v) {
|
||||
min_value = v;
|
||||
min_value = v;
|
||||
min_enabled = true;
|
||||
}
|
||||
|
||||
@@ -106,47 +108,102 @@ void LabelSlider::set_maximum_value(double v) {
|
||||
}
|
||||
|
||||
void LabelSlider::mousePressEvent(QMouseEvent *ev) {
|
||||
// if primary button is clicked
|
||||
if (ev->button() == Qt::LeftButton) {
|
||||
|
||||
// store initial value to be compared while dragging
|
||||
drag_start_value = internal_value;
|
||||
if (ev->modifiers() & Qt::AltModifier) {
|
||||
|
||||
// alt + click sets labelslider to default value
|
||||
if (ev->modifiers() & Qt::AltModifier) {
|
||||
|
||||
// if the value is not already default, and there is a default to set
|
||||
if (internal_value != default_value && !qIsNaN(default_value)) {
|
||||
|
||||
// cache current value
|
||||
set_previous_value();
|
||||
|
||||
// set back to default
|
||||
set_value(default_value, true);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// if value isn't valid, we set to a "default" of 0
|
||||
if (qIsNaN(internal_value)) internal_value = 0;
|
||||
|
||||
// hide the cursor and store information about it for dragging
|
||||
qApp->setOverrideCursor(Qt::BlankCursor);
|
||||
drag_start = true;
|
||||
drag_start_x = cursor().pos().x();
|
||||
drag_start_y = cursor().pos().y();
|
||||
}
|
||||
|
||||
emit clicked();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// handler if the user clicks with a non-primary button
|
||||
// prevents mouse from getting stuck in "dragging" mode
|
||||
mouseReleaseEvent(ev);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void LabelSlider::mouseMoveEvent(QMouseEvent* event) {
|
||||
if (drag_start) {
|
||||
// if we're dragging
|
||||
|
||||
// we don't actually start fully dragging until the cursor has moved
|
||||
// while the mouse is down, this helps prevent accidental drags
|
||||
drag_proc = true;
|
||||
|
||||
// get amount cursor moved by
|
||||
double diff = (cursor().pos().x()-drag_start_x) + (drag_start_y-cursor().pos().y());
|
||||
|
||||
// ctrl + drag drags in smaller increments
|
||||
if (event->modifiers() & Qt::ControlModifier) diff *= 0.01;
|
||||
|
||||
// we'll also need to drag in smaller increments for a percent value
|
||||
if (display_type == LABELSLIDER_PERCENT) diff *= 0.01;
|
||||
|
||||
// sets the value
|
||||
set_value(internal_value + diff, true);
|
||||
|
||||
// keep the cursor in the same location while dragging
|
||||
cursor().setPos(drag_start_x, drag_start_y);
|
||||
}
|
||||
}
|
||||
|
||||
void LabelSlider::mouseReleaseEvent(QMouseEvent* ev) {
|
||||
void LabelSlider::mouseReleaseEvent(QMouseEvent*) {
|
||||
if (drag_start) {
|
||||
|
||||
// unhide cursor
|
||||
qApp->restoreOverrideCursor();
|
||||
|
||||
drag_start = false;
|
||||
if (drag_proc) {
|
||||
|
||||
if (drag_proc) {
|
||||
// if we just finished fully dragging
|
||||
|
||||
drag_proc = false;
|
||||
|
||||
previous_value = drag_start_value;
|
||||
|
||||
emit valueChanged();
|
||||
|
||||
} else {
|
||||
|
||||
// if the user didn't actually drag, and just clicked in one place,
|
||||
// we instead present a dialog prompt for the user to enter a
|
||||
// specific value
|
||||
|
||||
double d = internal_value;
|
||||
if (display_type == LABELSLIDER_FRAMENUMBER) {
|
||||
|
||||
if (display_type == LABELSLIDER_FRAMENUMBER) {
|
||||
|
||||
// ask the user to enter a timecode
|
||||
QString s = QInputDialog::getText(
|
||||
this,
|
||||
tr("Set Value"),
|
||||
@@ -155,9 +212,16 @@ void LabelSlider::mouseReleaseEvent(QMouseEvent* ev) {
|
||||
valueToString(internal_value)
|
||||
);
|
||||
if (s.isEmpty()) return;
|
||||
d = timecode_to_frame(s, config.timecode_view, frame_rate); // string to frame number
|
||||
|
||||
// parse string timecode to a frame number
|
||||
d = timecode_to_frame(s, config.timecode_view, frame_rate);
|
||||
|
||||
} else {
|
||||
|
||||
// ask the user to enter a normal number value
|
||||
bool ok;
|
||||
|
||||
// percentages are stored 0.0 - 1.0 but displayed as 0% - 100%
|
||||
d = QInputDialog::getDouble(
|
||||
this,
|
||||
tr("Set Value"),
|
||||
@@ -171,6 +235,8 @@ void LabelSlider::mouseReleaseEvent(QMouseEvent* ev) {
|
||||
if (!ok) return;
|
||||
if (display_type == LABELSLIDER_PERCENT) d *= 0.01;
|
||||
}
|
||||
|
||||
// if the value actually changed, trigger a change event
|
||||
if (d != internal_value) {
|
||||
set_previous_value();
|
||||
set_value(d, true);
|
||||
|
||||
Reference in New Issue
Block a user