From a48a233785b69362e59b9333a47f87414cf3aab9 Mon Sep 17 00:00:00 2001 From: fourtf Date: Sat, 26 May 2018 17:11:09 +0200 Subject: [PATCH] changed scrollbar highlight color --- src/singletons/thememanager.cpp | 3 ++ src/singletons/thememanager.hpp | 5 +-- src/widgets/basewindow.cpp | 31 +++++++++--------- src/widgets/basewindow.hpp | 2 +- src/widgets/helper/splitheader.cpp | 2 +- src/widgets/scrollbar.cpp | 50 +++++++++++++++++++----------- src/widgets/scrollbar.hpp | 2 +- src/widgets/tooltipwidget.cpp | 11 ++++++- src/widgets/tooltipwidget.hpp | 13 ++------ 9 files changed, 69 insertions(+), 50 deletions(-) diff --git a/src/singletons/thememanager.cpp b/src/singletons/thememanager.cpp index c2a81860d..6d4c60435 100644 --- a/src/singletons/thememanager.cpp +++ b/src/singletons/thememanager.cpp @@ -115,6 +115,9 @@ void ThemeManager::actuallyUpdate(double hue, double multiplier) {QColor("#00aeef"), QColor("#00aeef"), QColor("#00aeef")}}; } + // scrollbar + this->scrollbars.highlights.highlight = QColor("#ee6166"); + // this->tabs.newMessage = { // fg, // {QBrush(blendColors(themeColor, "#ccc", 0.9), Qt::FDiagPattern), diff --git a/src/singletons/thememanager.hpp b/src/singletons/thememanager.hpp index 5165600ad..b3cda6acd 100644 --- a/src/singletons/thememanager.hpp +++ b/src/singletons/thememanager.hpp @@ -109,8 +109,9 @@ public: QColor background; QColor thumb; QColor thumbSelected; - // const int highlightsCount = 3; - // QColor highlights[3]; + struct { + QColor highlight; + } highlights; } scrollbars; /// TOOLTIP diff --git a/src/widgets/basewindow.cpp b/src/widgets/basewindow.cpp index 2e8abe3be..c832597fa 100644 --- a/src/widgets/basewindow.cpp +++ b/src/widgets/basewindow.cpp @@ -54,8 +54,6 @@ BaseWindow::Flags BaseWindow::getFlags() void BaseWindow::init() { - auto app = getApp(); - this->setWindowIcon(QIcon(":/images/icon.png")); #ifdef USEWINSDK @@ -132,14 +130,14 @@ void BaseWindow::init() #ifdef USEWINSDK // fourtf: don't ask me why we need to delay this - QTimer::singleShot(1, this, [this] { - if (!(this->flags & Flags::TopMost)) { + if (!(this->flags & Flags::TopMost)) { + QTimer::singleShot(1, this, [this] { getApp()->settings->windowTopMost.connect([this](bool topMost, auto) { - ::SetWindowPos((HWND)this->winId(), topMost ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, - 0, 0, SWP_NOMOVE | SWP_NOSIZE); + ::SetWindowPos(HWND(this->winId()), topMost ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, + 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); }); - } - }); + }); + } #else // if (getApp()->settings->windowTopMost.getValue()) { // this->setWindowFlag(Qt::WindowStaysOnTopHint); @@ -251,10 +249,12 @@ void BaseWindow::leaveEvent(QEvent *) TooltipWidget::getInstance()->hide(); } -void BaseWindow::moveTo(QWidget *parent, QPoint point) +void BaseWindow::moveTo(QWidget *parent, QPoint point, bool offset) { - // point.rx() += 16; - // point.ry() += 16; + if (offset) { + point.rx() += 16; + point.ry() += 16; + } this->move(point); this->moveIntoDesktopRect(parent); @@ -343,14 +343,13 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r } else { return QWidget::nativeEvent(eventType, message, result); } - break; - } + } break; case WM_NCHITTEST: { if (this->hasCustomWindowFrame()) { *result = 0; const LONG border_width = 8; // in pixels RECT winrect; - GetWindowRect((HWND)winId(), &winrect); + GetWindowRect(HWND(winId()), &winrect); long x = GET_X_LPARAM(msg->lParam); long y = GET_Y_LPARAM(msg->lParam); @@ -442,13 +441,13 @@ void BaseWindow::showEvent(QShowEvent *event) // WS_MINIMIZEBOX); const MARGINS shadow = {8, 8, 8, 8}; - DwmExtendFrameIntoClientArea((HWND)this->winId(), &shadow); + DwmExtendFrameIntoClientArea(HWND(this->winId()), &shadow); } BaseWidget::showEvent(event); } -void BaseWindow::paintEvent(QPaintEvent *event) +void BaseWindow::paintEvent(QPaintEvent *) { if (this->hasCustomWindowFrame()) { QPainter painter(this); diff --git a/src/widgets/basewindow.hpp b/src/widgets/basewindow.hpp index 2aef90203..ec5776b6c 100644 --- a/src/widgets/basewindow.hpp +++ b/src/widgets/basewindow.hpp @@ -31,7 +31,7 @@ public: void setStayInScreenRect(bool value); bool getStayInScreenRect() const; - void moveTo(QWidget *widget, QPoint point); + void moveTo(QWidget *widget, QPoint point, bool offset = true); Flags getFlags(); diff --git a/src/widgets/helper/splitheader.cpp b/src/widgets/helper/splitheader.cpp index f7fb6af19..150e15e85 100644 --- a/src/widgets/helper/splitheader.cpp +++ b/src/widgets/helper/splitheader.cpp @@ -353,7 +353,7 @@ void SplitHeader::enterEvent(QEvent *event) { if (!this->tooltip.isEmpty()) { auto tooltipWidget = TooltipWidget::getInstance(); - tooltipWidget->moveTo(this, this->mapToGlobal(this->rect().bottomLeft())); + tooltipWidget->moveTo(this, this->mapToGlobal(this->rect().bottomLeft()), false); tooltipWidget->setText(this->tooltip); tooltipWidget->show(); tooltipWidget->raise(); diff --git a/src/widgets/scrollbar.cpp b/src/widgets/scrollbar.cpp index 039d9a209..422fdeedb 100644 --- a/src/widgets/scrollbar.cpp +++ b/src/widgets/scrollbar.cpp @@ -20,7 +20,7 @@ Scrollbar::Scrollbar(ChannelView *parent) : BaseWidget(parent) , currentValueAnimation(this, "currentValue") { - resize((int)(16 * this->getScale()), 100); + resize(int(16 * this->getScale()), 100); this->currentValueAnimation.setDuration(150); this->currentValueAnimation.setEasingCurve(QEasingCurve(QEasingCurve::OutCubic)); @@ -31,7 +31,7 @@ Scrollbar::Scrollbar(ChannelView *parent) timer->setSingleShot(true); connect(timer, &QTimer::timeout, [=]() { - resize((int)(16 * this->getScale()), 100); + resize(int(16 * this->getScale()), 100); timer->deleteLater(); }); @@ -98,7 +98,7 @@ void Scrollbar::setDesiredValue(qreal value, bool animated) animated &= app->settings->enableSmoothScrolling.getValue(); value = std::max(this->minimum, std::min(this->maximum - this->largeChange, value)); - if (this->desiredValue + this->smoothScrollingOffset != value) { + if (std::abs(this->desiredValue + this->smoothScrollingOffset - value) > 0.0001) { if (animated) { this->currentValueAnimation.stop(); this->currentValueAnimation.setStartValue(this->currentValue + @@ -196,8 +196,10 @@ void Scrollbar::printCurrentState(const QString &prefix) const void Scrollbar::paintEvent(QPaintEvent *) { + auto *app = getApp(); + bool mouseOver = this->mouseOverIndex != -1; - int xOffset = mouseOver ? 0 : width() - (int)(4 * this->getScale()); + int xOffset = mouseOver ? 0 : width() - int(4 * this->getScale()); QPainter painter(this); // painter.fillRect(rect(), this->themeManager->ScrollbarBG); @@ -221,7 +223,7 @@ void Scrollbar::paintEvent(QPaintEvent *) // draw highlights auto snapshot = this->highlights.getSnapshot(); - int snapshotLength = (int)snapshot.getLength(); + size_t snapshotLength = snapshot.getLength(); if (snapshotLength == 0) { return; @@ -229,19 +231,31 @@ void Scrollbar::paintEvent(QPaintEvent *) int w = this->width(); float y = 0; - float dY = (float)(this->height()) / (float)snapshotLength; - int highlightHeight = std::ceil(dY); + float dY = float(this->height()) / float(snapshotLength); + int highlightHeight = int(std::ceil(dY)); - for (int i = 0; i < snapshotLength; i++) { + for (size_t i = 0; i < snapshotLength; i++) { ScrollbarHighlight const &highlight = snapshot[i]; if (!highlight.isNull()) { - if (highlight.getStyle() == ScrollbarHighlight::Default) { - painter.fillRect(w / 8 * 3, (int)y, w / 4, highlightHeight, - this->themeManager->tabs.selected.backgrounds.regular.color()); - } else { - painter.fillRect(0, (int)y, w, 1, - this->themeManager->tabs.selected.backgrounds.regular.color()); + QColor color = [&] { + switch (highlight.getColor()) { + case ScrollbarHighlight::Highlight: + return app->themes->scrollbars.highlights.highlight; + } + return QColor(); + }(); + + switch (highlight.getStyle()) { + case ScrollbarHighlight::Default: { + painter.fillRect(w / 8 * 3, int(y), w / 4, highlightHeight, color); + } break; + + case ScrollbarHighlight::Line: { + painter.fillRect(0, int(y), w, 1, color); + } break; + + case ScrollbarHighlight::None:; } } @@ -251,7 +265,7 @@ void Scrollbar::paintEvent(QPaintEvent *) void Scrollbar::resizeEvent(QResizeEvent *) { - this->resize((int)(16 * this->getScale()), this->height()); + this->resize(int(16 * this->getScale()), this->height()); } void Scrollbar::mouseMoveEvent(QMouseEvent *event) @@ -279,7 +293,7 @@ void Scrollbar::mouseMoveEvent(QMouseEvent *event) } 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(); @@ -342,8 +356,8 @@ void Scrollbar::updateScroll() this->trackHeight = 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); + 0, int(this->currentValue / this->maximum * this->trackHeight) + 1 + this->buttonHeight, + width(), int(this->largeChange / this->maximum * this->trackHeight) + MIN_THUMB_HEIGHT); update(); } diff --git a/src/widgets/scrollbar.hpp b/src/widgets/scrollbar.hpp index 6d5166837..21f7f9718 100644 --- a/src/widgets/scrollbar.hpp +++ b/src/widgets/scrollbar.hpp @@ -21,7 +21,7 @@ class Scrollbar : public BaseWidget Q_OBJECT public: - Scrollbar(ChannelView *parent = 0); + Scrollbar(ChannelView *parent = nullptr); void addHighlight(ScrollbarHighlight highlight); void addHighlightsAtStart(const std::vector &highlights); diff --git a/src/widgets/tooltipwidget.cpp b/src/widgets/tooltipwidget.cpp index e960bbd4f..4d69c66e1 100644 --- a/src/widgets/tooltipwidget.cpp +++ b/src/widgets/tooltipwidget.cpp @@ -16,6 +16,15 @@ namespace chatterino { namespace widgets { +TooltipWidget *TooltipWidget::getInstance() +{ + static TooltipWidget *tooltipWidget = nullptr; + if (tooltipWidget == nullptr) { + tooltipWidget = new TooltipWidget(); + } + return tooltipWidget; +} + TooltipWidget::TooltipWidget(BaseWidget *parent) : BaseWindow(parent, BaseWindow::TopMost) , displayText(new QLabel()) @@ -49,7 +58,7 @@ TooltipWidget::~TooltipWidget() #ifdef USEWINSDK void TooltipWidget::raise() { - ::SetWindowPos((HWND)this->winId(), HWND_TOPMOST, 0, 0, 0, 0, + ::SetWindowPos(HWND(this->winId()), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); } #endif diff --git a/src/widgets/tooltipwidget.hpp b/src/widgets/tooltipwidget.hpp index fd7aa41d9..20a62c368 100644 --- a/src/widgets/tooltipwidget.hpp +++ b/src/widgets/tooltipwidget.hpp @@ -14,20 +14,13 @@ class TooltipWidget : public BaseWindow Q_OBJECT public: + static TooltipWidget *getInstance(); + TooltipWidget(BaseWidget *parent = nullptr); - ~TooltipWidget(); + virtual ~TooltipWidget() override; void setText(QString text); - static TooltipWidget *getInstance() - { - static TooltipWidget *tooltipWidget = nullptr; - if (tooltipWidget == nullptr) { - tooltipWidget = new TooltipWidget(); - } - return tooltipWidget; - } - #ifdef USEWINSDK void raise(); #endif