diff --git a/qss/settings.qss b/qss/settings.qss index 4dfdf32f..5ddacf46 100644 --- a/qss/settings.qss +++ b/qss/settings.qss @@ -6,14 +6,10 @@ font-size: 14px; } -SettingsDialogTab { - color: #FFF; -} - SettingsDialogTab:hover { border: 1px solid grey; } -QLabel, QCheckBox, QGroupBox { +QLabel, QCheckBox, QGroupBox, SettingsDialogTab { color: white; } diff --git a/widgets/chatwidgetview.cpp b/widgets/chatwidgetview.cpp index 74c6b675..879d3107 100644 --- a/widgets/chatwidgetview.cpp +++ b/widgets/chatwidgetview.cpp @@ -24,7 +24,7 @@ ChatWidgetView::ChatWidgetView(ChatWidget *parent) QObject::connect(&Settings::getInstance(), &Settings::wordTypeMaskChanged, this, &ChatWidgetView::wordTypeMaskChanged); - this->scrollbar.getValueChanged().connect([this] { update(); }); + this->scrollbar.getCurrentValueChanged().connect([this] { update(); }); } ChatWidgetView::~ChatWidgetView() @@ -62,13 +62,12 @@ ChatWidgetView::layoutMessages() message->layout(this->width(), true); - qDebug() << message->getHeight(); h -= message->getHeight(); if (h < 0) { this->scrollbar.setLargeChange((messages.size() - i) + (qreal)h / message->getHeight()); - this->scrollbar.setValue(this->scrollbar.getValue()); + this->scrollbar.setDesiredValue(this->scrollbar.getDesiredValue()); showScrollbar = true; break; @@ -141,14 +140,14 @@ ChatWidgetView::paintEvent(QPaintEvent *) auto messages = c->getMessagesClone(); - int start = this->scrollbar.getValue(); + int start = this->scrollbar.getCurrentValue(); if (start >= messages.length()) { return; } int y = -(messages[start].get()->getHeight() * - (fmod(this->scrollbar.getValue(), 1))); + (fmod(this->scrollbar.getCurrentValue(), 1))); for (int i = start; i < messages.size(); ++i) { messages::Message *message = messages[i].get(); @@ -198,8 +197,8 @@ ChatWidgetView::paintEvent(QPaintEvent *) void ChatWidgetView::wheelEvent(QWheelEvent *event) { - this->scrollbar.setValue( - this->scrollbar.getValue() - + this->scrollbar.setDesiredValue( + this->scrollbar.getDesiredValue() - event->delta() / 10.0 * Settings::getInstance().mouseScrollMultiplier.get(), true); diff --git a/widgets/scrollbar.cpp b/widgets/scrollbar.cpp index 9fc66cd8..114f73d2 100644 --- a/widgets/scrollbar.cpp +++ b/widgets/scrollbar.cpp @@ -12,7 +12,7 @@ namespace widgets { ScrollBar::ScrollBar(QWidget *widget) : QWidget(widget) , mutex() - , valueAnimation(this, "value") + , currentValueAnimation(this, "currentValue") , highlights(NULL) , mouseOverIndex(-1) , mouseDownIndex(-1) @@ -24,13 +24,14 @@ ScrollBar::ScrollBar(QWidget *widget) , minimum() , largeChange() , smallChange() - , value() - , valueChanged() + , desiredValue() + , currentValueChanged() + , currentValue() { resize(16, 100); - valueAnimation.setDuration(300); - valueAnimation.setEasingCurve(QEasingCurve(QEasingCurve::OutCubic)); + currentValueAnimation.setDuration(300); + currentValueAnimation.setEasingCurve(QEasingCurve(QEasingCurve::OutCubic)); this->setMouseTracking(true); } @@ -140,8 +141,8 @@ ScrollBar::mouseMoveEvent(QMouseEvent *event) } else if (this->mouseDownIndex == 2) { int delta = event->pos().y() - lastMousePosition.y(); - this->setValue(this->value + - (qreal)delta / this->trackHeight * maximum); + this->setDesiredValue(this->desiredValue + + (qreal)delta / this->trackHeight * maximum); } this->lastMousePosition = event->pos(); @@ -172,21 +173,21 @@ ScrollBar::mouseReleaseEvent(QMouseEvent *event) if (y < this->buttonHeight) { if (this->mouseDownIndex == 0) { - this->setValue(this->value - this->smallChange, true); + this->setDesiredValue(this->desiredValue - this->smallChange, true); } } else if (y < this->thumbRect.y()) { if (this->mouseDownIndex == 1) { - this->setValue(this->value - this->smallChange, true); + this->setDesiredValue(this->desiredValue - this->smallChange, true); } } else if (this->thumbRect.contains(2, y)) { // do nothing } else if (y < height() - this->buttonHeight) { if (this->mouseDownIndex == 3) { - this->setValue(this->value + this->smallChange, true); + this->setDesiredValue(this->desiredValue + this->smallChange, true); } } else { if (this->mouseDownIndex == 4) { - this->setValue(this->value + this->smallChange, true); + this->setDesiredValue(this->desiredValue + this->smallChange, true); } } @@ -210,8 +211,8 @@ ScrollBar::updateScroll() this->thumbRect = QRect(0, - (int)(this->value / this->maximum * this->trackHeight) + 1 + - this->buttonHeight, + (int)(this->desiredValue / this->maximum * this->trackHeight) + + 1 + this->buttonHeight, width(), (int)(this->largeChange / this->maximum * this->trackHeight) + MIN_THUMB_HEIGHT); diff --git a/widgets/scrollbar.h b/widgets/scrollbar.h index d814e04e..e20345cb 100644 --- a/widgets/scrollbar.h +++ b/widgets/scrollbar.h @@ -23,7 +23,7 @@ public: void removeHighlightsWhere(std::function func); void addHighlight(ScrollBarHighlight *highlight); - Q_PROPERTY(qreal value READ getValue WRITE setValue) + Q_PROPERTY(qreal desiredValue READ getDesiredValue WRITE setDesiredValue) void setMaximum(qreal value) @@ -58,26 +58,25 @@ public: } void - setValue(qreal value, bool animated = false) + setDesiredValue(qreal value, bool animated = false) { value = std::max(this->minimum, std::min(this->maximum - this->largeChange, value)); - if (this->value != value) { + this->desiredValue = value; + + if (this->desiredValue != value) { if (animated) { - this->valueAnimation.stop(); - this->valueAnimation.setStartValue(this->value); + this->currentValueAnimation.stop(); + this->currentValueAnimation.setStartValue(this->currentValue); - this->valueAnimation.setEndValue(value); - this->valueAnimation.start(); + this->currentValueAnimation.setEndValue(value); + this->currentValueAnimation.start(); } else { - this->value = value; + this->currentValueAnimation.stop(); + + this->setCurrentValue(value); } - - this->updateScroll(); - this->valueChanged(); - - this->update(); } } @@ -106,22 +105,46 @@ public: } qreal - getValue() const + getDesiredValue() const { - return this->value; + return this->desiredValue; + } + + qreal + getCurrentValue() const + { + return this->currentValue; } boost::signals2::signal & - getValueChanged() + getCurrentValueChanged() { - return valueChanged; + return currentValueChanged; + } + + void + setCurrentValue(qreal value) + { + value = std::max(this->minimum, + std::min(this->maximum - this->largeChange, value)); + + if (this->currentValue != value) { + this->currentValue = value; + + this->updateScroll(); + this->currentValueChanged(); + + this->update(); + } } private: + Q_PROPERTY(qreal currentValue READ getCurrentValue WRITE setCurrentValue) + QMutex mutex; ScrollBarHighlight *highlights; - QPropertyAnimation valueAnimation; + QPropertyAnimation currentValueAnimation; void paintEvent(QPaintEvent *); void mouseMoveEvent(QMouseEvent *event); @@ -142,9 +165,10 @@ private: qreal minimum; qreal largeChange; qreal smallChange; - qreal value; + qreal desiredValue; + qreal currentValue; - boost::signals2::signal valueChanged; + boost::signals2::signal currentValueChanged; void updateScroll(); }; diff --git a/widgets/settingsdialog.cpp b/widgets/settingsdialog.cpp index c754d2c4..b5f59f17 100644 --- a/widgets/settingsdialog.cpp +++ b/widgets/settingsdialog.cpp @@ -225,14 +225,11 @@ SettingsDialog::select(SettingsDialogTab *tab) if (selectedTab != NULL) { selectedTab->setSelected(false); - selectedTab->setStyleSheet(""); + selectedTab->setStyleSheet("color: #FFF"); } tab->setSelected(true); - tab->setStyleSheet("background: #F00;" - "background: qlineargradient( x1:0 y1:0, x2:1 y2:0, " - "stop:0 #333, stop:1 #555);" - "border-right: none;"); + tab->setStyleSheet("background: #555; color: #FFF"); selectedTab = tab; } diff --git a/widgets/settingsdialogtab.cpp b/widgets/settingsdialogtab.cpp index aaac172a..a46fc9c8 100644 --- a/widgets/settingsdialogtab.cpp +++ b/widgets/settingsdialogtab.cpp @@ -17,6 +17,8 @@ SettingsDialogTab::SettingsDialogTab(SettingsDialog *dialog, QString label, setFixedHeight(32); setCursor(QCursor(Qt::PointingHandCursor)); + + setStyleSheet("color: #FFF"); } void