wip changes
This commit is contained in:
+121
-103
@@ -18,76 +18,84 @@ namespace widgets {
|
||||
|
||||
Scrollbar::Scrollbar(ChannelView *parent)
|
||||
: BaseWidget(parent)
|
||||
, currentValueAnimation(this, "currentValue")
|
||||
, currentValueAnimation_(this, "currentValue")
|
||||
{
|
||||
resize(int(16 * this->getScale()), 100);
|
||||
this->currentValueAnimation.setDuration(150);
|
||||
this->currentValueAnimation.setEasingCurve(QEasingCurve(QEasingCurve::OutCubic));
|
||||
this->currentValueAnimation_.setDuration(150);
|
||||
this->currentValueAnimation_.setEasingCurve(QEasingCurve(QEasingCurve::OutCubic));
|
||||
|
||||
setMouseTracking(true);
|
||||
|
||||
// don't do this at home kids
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer->setSingleShot(true);
|
||||
|
||||
connect(timer, &QTimer::timeout, [=]() {
|
||||
resize(int(16 * this->getScale()), 100);
|
||||
timer->deleteLater();
|
||||
});
|
||||
|
||||
timer->start(10);
|
||||
}
|
||||
|
||||
void Scrollbar::addHighlight(ScrollbarHighlight highlight)
|
||||
{
|
||||
ScrollbarHighlight deleted;
|
||||
this->highlights.pushBack(highlight, deleted);
|
||||
this->highlights_.pushBack(highlight, deleted);
|
||||
}
|
||||
|
||||
void Scrollbar::addHighlightsAtStart(const std::vector<ScrollbarHighlight> &_highlights)
|
||||
{
|
||||
this->highlights.pushFront(_highlights);
|
||||
this->highlights_.pushFront(_highlights);
|
||||
}
|
||||
|
||||
void Scrollbar::replaceHighlight(size_t index, ScrollbarHighlight replacement)
|
||||
{
|
||||
this->highlights.replaceItem(index, replacement);
|
||||
this->highlights_.replaceItem(index, replacement);
|
||||
}
|
||||
|
||||
void Scrollbar::pauseHighlights()
|
||||
{
|
||||
this->highlightsPaused_ = true;
|
||||
}
|
||||
|
||||
void Scrollbar::unpauseHighlights()
|
||||
{
|
||||
this->highlightsPaused_ = false;
|
||||
}
|
||||
|
||||
messages::LimitedQueueSnapshot<ScrollbarHighlight> Scrollbar::getHighlightSnapshot()
|
||||
{
|
||||
if (!this->highlightsPaused_) {
|
||||
this->highlightSnapshot_ = this->highlights_.getSnapshot();
|
||||
}
|
||||
|
||||
return this->highlightSnapshot_;
|
||||
}
|
||||
|
||||
void Scrollbar::scrollToBottom(bool animate)
|
||||
{
|
||||
this->setDesiredValue(this->maximum - this->getLargeChange(), animate);
|
||||
this->setDesiredValue(this->maximum_ - this->getLargeChange(), animate);
|
||||
}
|
||||
|
||||
bool Scrollbar::isAtBottom() const
|
||||
{
|
||||
return this->atBottom;
|
||||
return this->atBottom_;
|
||||
}
|
||||
|
||||
void Scrollbar::setMaximum(qreal value)
|
||||
{
|
||||
this->maximum = value;
|
||||
this->maximum_ = value;
|
||||
|
||||
updateScroll();
|
||||
}
|
||||
|
||||
void Scrollbar::setMinimum(qreal value)
|
||||
{
|
||||
this->minimum = value;
|
||||
this->minimum_ = value;
|
||||
|
||||
updateScroll();
|
||||
}
|
||||
|
||||
void Scrollbar::setLargeChange(qreal value)
|
||||
{
|
||||
this->largeChange = value;
|
||||
this->largeChange_ = value;
|
||||
|
||||
updateScroll();
|
||||
}
|
||||
|
||||
void Scrollbar::setSmallChange(qreal value)
|
||||
{
|
||||
this->smallChange = value;
|
||||
this->smallChange_ = value;
|
||||
|
||||
updateScroll();
|
||||
}
|
||||
@@ -96,70 +104,72 @@ void Scrollbar::setDesiredValue(qreal value, bool animated)
|
||||
{
|
||||
auto app = getApp();
|
||||
animated &= app->settings->enableSmoothScrolling.getValue();
|
||||
value = std::max(this->minimum, std::min(this->maximum - this->largeChange, value));
|
||||
value = std::max(this->minimum_, std::min(this->maximum_ - this->largeChange_, value));
|
||||
|
||||
if (std::abs(this->desiredValue + this->smoothScrollingOffset - value) > 0.0001) {
|
||||
if (std::abs(this->desiredValue_ + this->smoothScrollingOffset_ - value) > 0.0001) {
|
||||
if (animated) {
|
||||
this->currentValueAnimation.stop();
|
||||
this->currentValueAnimation.setStartValue(this->currentValue +
|
||||
this->smoothScrollingOffset);
|
||||
this->currentValueAnimation_.stop();
|
||||
this->currentValueAnimation_.setStartValue(this->currentValue_ +
|
||||
this->smoothScrollingOffset_);
|
||||
|
||||
// if (((this->getMaximum() - this->getLargeChange()) - value) <= 0.01) {
|
||||
// value += 1;
|
||||
// }
|
||||
this->currentValueAnimation.setEndValue(value);
|
||||
this->smoothScrollingOffset = 0;
|
||||
this->atBottom = ((this->getMaximum() - this->getLargeChange()) - value) <= 0.0001;
|
||||
this->currentValueAnimation.start();
|
||||
this->currentValueAnimation_.setEndValue(value);
|
||||
this->smoothScrollingOffset_ = 0;
|
||||
this->atBottom_ = ((this->getMaximum() - this->getLargeChange()) - value) <= 0.0001;
|
||||
this->currentValueAnimation_.start();
|
||||
} else {
|
||||
if (this->currentValueAnimation.state() != QPropertyAnimation::Running) {
|
||||
this->smoothScrollingOffset = 0;
|
||||
this->desiredValue = value;
|
||||
this->currentValueAnimation.stop();
|
||||
this->atBottom = ((this->getMaximum() - this->getLargeChange()) - value) <= 0.0001;
|
||||
if (this->currentValueAnimation_.state() != QPropertyAnimation::Running) {
|
||||
this->smoothScrollingOffset_ = 0;
|
||||
this->desiredValue_ = value;
|
||||
this->currentValueAnimation_.stop();
|
||||
this->atBottom_ = ((this->getMaximum() - this->getLargeChange()) - value) <= 0.0001;
|
||||
setCurrentValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->smoothScrollingOffset = 0;
|
||||
this->desiredValue = value;
|
||||
this->smoothScrollingOffset_ = 0;
|
||||
this->desiredValue_ = value;
|
||||
|
||||
this->desiredValueChanged_.invoke();
|
||||
}
|
||||
|
||||
qreal Scrollbar::getMaximum() const
|
||||
{
|
||||
return this->maximum;
|
||||
return this->maximum_;
|
||||
}
|
||||
|
||||
qreal Scrollbar::getMinimum() const
|
||||
{
|
||||
return this->minimum;
|
||||
return this->minimum_;
|
||||
}
|
||||
|
||||
qreal Scrollbar::getLargeChange() const
|
||||
{
|
||||
return this->largeChange;
|
||||
return this->largeChange_;
|
||||
}
|
||||
|
||||
qreal Scrollbar::getSmallChange() const
|
||||
{
|
||||
return this->smallChange;
|
||||
return this->smallChange_;
|
||||
}
|
||||
|
||||
qreal Scrollbar::getDesiredValue() const
|
||||
{
|
||||
return this->desiredValue + this->smoothScrollingOffset;
|
||||
return this->desiredValue_ + this->smoothScrollingOffset_;
|
||||
}
|
||||
|
||||
qreal Scrollbar::getCurrentValue() const
|
||||
{
|
||||
return this->currentValue;
|
||||
return this->currentValue_;
|
||||
}
|
||||
|
||||
void Scrollbar::offset(qreal value)
|
||||
{
|
||||
if (this->currentValueAnimation.state() == QPropertyAnimation::Running) {
|
||||
this->smoothScrollingOffset += value;
|
||||
if (this->currentValueAnimation_.state() == QPropertyAnimation::Running) {
|
||||
this->smoothScrollingOffset_ += value;
|
||||
} else {
|
||||
this->setDesiredValue(this->getDesiredValue() + value);
|
||||
}
|
||||
@@ -167,19 +177,25 @@ void Scrollbar::offset(qreal value)
|
||||
|
||||
pajlada::Signals::NoArgSignal &Scrollbar::getCurrentValueChanged()
|
||||
{
|
||||
return this->currentValueChanged;
|
||||
return this->currentValueChanged_;
|
||||
}
|
||||
|
||||
pajlada::Signals::NoArgSignal &Scrollbar::getDesiredValueChanged()
|
||||
{
|
||||
return this->desiredValueChanged_;
|
||||
}
|
||||
|
||||
void Scrollbar::setCurrentValue(qreal value)
|
||||
{
|
||||
value = std::max(this->minimum, std::min(this->maximum - this->largeChange,
|
||||
value + this->smoothScrollingOffset));
|
||||
value = std::max(this->minimum_, std::min(this->maximum_ - this->largeChange_,
|
||||
value + this->smoothScrollingOffset_));
|
||||
|
||||
if (std::abs(this->currentValue - value) > 0.000001) {
|
||||
this->currentValue = value;
|
||||
if (std::abs(this->currentValue_ - value) > 0.000001) {
|
||||
qDebug() << "setCurrentValue";
|
||||
this->currentValue_ = value;
|
||||
|
||||
this->updateScroll();
|
||||
this->currentValueChanged.invoke();
|
||||
this->currentValueChanged_.invoke();
|
||||
|
||||
this->update();
|
||||
}
|
||||
@@ -198,7 +214,7 @@ void Scrollbar::paintEvent(QPaintEvent *)
|
||||
{
|
||||
auto *app = getApp();
|
||||
|
||||
bool mouseOver = this->mouseOverIndex != -1;
|
||||
bool mouseOver = this->mouseOverIndex_ != -1;
|
||||
int xOffset = mouseOver ? 0 : width() - int(4 * this->getScale());
|
||||
|
||||
QPainter painter(this);
|
||||
@@ -210,19 +226,19 @@ void Scrollbar::paintEvent(QPaintEvent *)
|
||||
// this->buttonHeight),
|
||||
// this->themeManager->ScrollbarArrow);
|
||||
|
||||
this->thumbRect.setX(xOffset);
|
||||
this->thumbRect_.setX(xOffset);
|
||||
|
||||
// mouse over thumb
|
||||
if (this->mouseDownIndex == 2) {
|
||||
painter.fillRect(this->thumbRect, this->themeManager->scrollbars.thumbSelected);
|
||||
if (this->mouseDownIndex_ == 2) {
|
||||
painter.fillRect(this->thumbRect_, this->themeManager->scrollbars.thumbSelected);
|
||||
}
|
||||
// mouse not over thumb
|
||||
else {
|
||||
painter.fillRect(this->thumbRect, this->themeManager->scrollbars.thumb);
|
||||
painter.fillRect(this->thumbRect_, this->themeManager->scrollbars.thumb);
|
||||
}
|
||||
|
||||
// draw highlights
|
||||
auto snapshot = this->highlights.getSnapshot();
|
||||
auto snapshot = this->getHighlightSnapshot();
|
||||
size_t snapshotLength = snapshot.getLength();
|
||||
|
||||
if (snapshotLength == 0) {
|
||||
@@ -272,49 +288,49 @@ void Scrollbar::resizeEvent(QResizeEvent *)
|
||||
|
||||
void Scrollbar::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (this->mouseDownIndex == -1) {
|
||||
if (this->mouseDownIndex_ == -1) {
|
||||
int y = event->pos().y();
|
||||
|
||||
auto oldIndex = this->mouseOverIndex;
|
||||
auto oldIndex = this->mouseOverIndex_;
|
||||
|
||||
if (y < this->buttonHeight) {
|
||||
this->mouseOverIndex = 0;
|
||||
} else if (y < this->thumbRect.y()) {
|
||||
this->mouseOverIndex = 1;
|
||||
} else if (this->thumbRect.contains(2, y)) {
|
||||
this->mouseOverIndex = 2;
|
||||
} else if (y < height() - this->buttonHeight) {
|
||||
this->mouseOverIndex = 3;
|
||||
if (y < this->buttonHeight_) {
|
||||
this->mouseOverIndex_ = 0;
|
||||
} else if (y < this->thumbRect_.y()) {
|
||||
this->mouseOverIndex_ = 1;
|
||||
} else if (this->thumbRect_.contains(2, y)) {
|
||||
this->mouseOverIndex_ = 2;
|
||||
} else if (y < height() - this->buttonHeight_) {
|
||||
this->mouseOverIndex_ = 3;
|
||||
} else {
|
||||
this->mouseOverIndex = 4;
|
||||
this->mouseOverIndex_ = 4;
|
||||
}
|
||||
|
||||
if (oldIndex != this->mouseOverIndex) {
|
||||
if (oldIndex != this->mouseOverIndex_) {
|
||||
update();
|
||||
}
|
||||
} else if (this->mouseDownIndex == 2) {
|
||||
int delta = event->pos().y() - this->lastMousePosition.y();
|
||||
} else if (this->mouseDownIndex_ == 2) {
|
||||
int delta = event->pos().y() - this->lastMousePosition_.y();
|
||||
|
||||
setDesiredValue(this->desiredValue + qreal(delta) / this->trackHeight * this->maximum);
|
||||
setDesiredValue(this->desiredValue_ + qreal(delta) / this->trackHeight_ * this->maximum_);
|
||||
}
|
||||
|
||||
this->lastMousePosition = event->pos();
|
||||
this->lastMousePosition_ = event->pos();
|
||||
}
|
||||
|
||||
void Scrollbar::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
int y = event->pos().y();
|
||||
|
||||
if (y < this->buttonHeight) {
|
||||
this->mouseDownIndex = 0;
|
||||
} else if (y < this->thumbRect.y()) {
|
||||
this->mouseDownIndex = 1;
|
||||
} else if (this->thumbRect.contains(2, y)) {
|
||||
this->mouseDownIndex = 2;
|
||||
} else if (y < height() - this->buttonHeight) {
|
||||
this->mouseDownIndex = 3;
|
||||
if (y < this->buttonHeight_) {
|
||||
this->mouseDownIndex_ = 0;
|
||||
} else if (y < this->thumbRect_.y()) {
|
||||
this->mouseDownIndex_ = 1;
|
||||
} else if (this->thumbRect_.contains(2, y)) {
|
||||
this->mouseDownIndex_ = 2;
|
||||
} else if (y < height() - this->buttonHeight_) {
|
||||
this->mouseDownIndex_ = 3;
|
||||
} else {
|
||||
this->mouseDownIndex = 4;
|
||||
this->mouseDownIndex_ = 4;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,46 +338,48 @@ void Scrollbar::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
int y = event->pos().y();
|
||||
|
||||
if (y < this->buttonHeight) {
|
||||
if (this->mouseDownIndex == 0) {
|
||||
setDesiredValue(this->desiredValue - this->smallChange, true);
|
||||
if (y < this->buttonHeight_) {
|
||||
if (this->mouseDownIndex_ == 0) {
|
||||
setDesiredValue(this->desiredValue_ - this->smallChange_, true);
|
||||
}
|
||||
} else if (y < this->thumbRect.y()) {
|
||||
if (this->mouseDownIndex == 1) {
|
||||
setDesiredValue(this->desiredValue - this->smallChange, true);
|
||||
} else if (y < this->thumbRect_.y()) {
|
||||
if (this->mouseDownIndex_ == 1) {
|
||||
setDesiredValue(this->desiredValue_ - this->smallChange_, true);
|
||||
}
|
||||
} else if (this->thumbRect.contains(2, y)) {
|
||||
} else if (this->thumbRect_.contains(2, y)) {
|
||||
// do nothing
|
||||
} else if (y < height() - this->buttonHeight) {
|
||||
if (this->mouseDownIndex == 3) {
|
||||
setDesiredValue(this->desiredValue + this->smallChange, true);
|
||||
} else if (y < height() - this->buttonHeight_) {
|
||||
if (this->mouseDownIndex_ == 3) {
|
||||
setDesiredValue(this->desiredValue_ + this->smallChange_, true);
|
||||
}
|
||||
} else {
|
||||
if (this->mouseDownIndex == 4) {
|
||||
setDesiredValue(this->desiredValue + this->smallChange, true);
|
||||
if (this->mouseDownIndex_ == 4) {
|
||||
setDesiredValue(this->desiredValue_ + this->smallChange_, true);
|
||||
}
|
||||
}
|
||||
|
||||
this->mouseDownIndex = -1;
|
||||
this->mouseDownIndex_ = -1;
|
||||
update();
|
||||
}
|
||||
|
||||
void Scrollbar::leaveEvent(QEvent *)
|
||||
{
|
||||
this->mouseOverIndex = -1;
|
||||
this->mouseOverIndex_ = -1;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void Scrollbar::updateScroll()
|
||||
{
|
||||
this->trackHeight = height() - this->buttonHeight - this->buttonHeight - MIN_THUMB_HEIGHT - 1;
|
||||
this->trackHeight_ =
|
||||
this->height() - this->buttonHeight_ - this->buttonHeight_ - MIN_THUMB_HEIGHT - 1;
|
||||
|
||||
this->thumbRect = QRect(
|
||||
0, int(this->currentValue / this->maximum * this->trackHeight) + 1 + this->buttonHeight,
|
||||
width(), int(this->largeChange / this->maximum * this->trackHeight) + MIN_THUMB_HEIGHT);
|
||||
this->thumbRect_ = QRect(
|
||||
0, int(this->currentValue_ / this->maximum_ * this->trackHeight_) + 1 + this->buttonHeight_,
|
||||
this->width(),
|
||||
int(this->largeChange_ / this->maximum_ * this->trackHeight_) + MIN_THUMB_HEIGHT);
|
||||
|
||||
update();
|
||||
this->update();
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
|
||||
Reference in New Issue
Block a user