changed scrollbar highlight color

This commit is contained in:
fourtf 2018-05-26 17:11:09 +02:00
parent 6b24f249f7
commit a48a233785
9 changed files with 69 additions and 50 deletions

View file

@ -115,6 +115,9 @@ void ThemeManager::actuallyUpdate(double hue, double multiplier)
{QColor("#00aeef"), QColor("#00aeef"), QColor("#00aeef")}}; {QColor("#00aeef"), QColor("#00aeef"), QColor("#00aeef")}};
} }
// scrollbar
this->scrollbars.highlights.highlight = QColor("#ee6166");
// this->tabs.newMessage = { // this->tabs.newMessage = {
// fg, // fg,
// {QBrush(blendColors(themeColor, "#ccc", 0.9), Qt::FDiagPattern), // {QBrush(blendColors(themeColor, "#ccc", 0.9), Qt::FDiagPattern),

View file

@ -109,8 +109,9 @@ public:
QColor background; QColor background;
QColor thumb; QColor thumb;
QColor thumbSelected; QColor thumbSelected;
// const int highlightsCount = 3; struct {
// QColor highlights[3]; QColor highlight;
} highlights;
} scrollbars; } scrollbars;
/// TOOLTIP /// TOOLTIP

View file

@ -54,8 +54,6 @@ BaseWindow::Flags BaseWindow::getFlags()
void BaseWindow::init() void BaseWindow::init()
{ {
auto app = getApp();
this->setWindowIcon(QIcon(":/images/icon.png")); this->setWindowIcon(QIcon(":/images/icon.png"));
#ifdef USEWINSDK #ifdef USEWINSDK
@ -132,14 +130,14 @@ void BaseWindow::init()
#ifdef USEWINSDK #ifdef USEWINSDK
// fourtf: don't ask me why we need to delay this // 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) { getApp()->settings->windowTopMost.connect([this](bool topMost, auto) {
::SetWindowPos((HWND)this->winId(), topMost ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, ::SetWindowPos(HWND(this->winId()), topMost ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0,
0, 0, SWP_NOMOVE | SWP_NOSIZE); 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
});
}); });
} }
});
#else #else
// if (getApp()->settings->windowTopMost.getValue()) { // if (getApp()->settings->windowTopMost.getValue()) {
// this->setWindowFlag(Qt::WindowStaysOnTopHint); // this->setWindowFlag(Qt::WindowStaysOnTopHint);
@ -251,10 +249,12 @@ void BaseWindow::leaveEvent(QEvent *)
TooltipWidget::getInstance()->hide(); TooltipWidget::getInstance()->hide();
} }
void BaseWindow::moveTo(QWidget *parent, QPoint point) void BaseWindow::moveTo(QWidget *parent, QPoint point, bool offset)
{ {
// point.rx() += 16; if (offset) {
// point.ry() += 16; point.rx() += 16;
point.ry() += 16;
}
this->move(point); this->move(point);
this->moveIntoDesktopRect(parent); this->moveIntoDesktopRect(parent);
@ -343,14 +343,13 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, long *r
} else { } else {
return QWidget::nativeEvent(eventType, message, result); return QWidget::nativeEvent(eventType, message, result);
} }
break; } break;
}
case WM_NCHITTEST: { case WM_NCHITTEST: {
if (this->hasCustomWindowFrame()) { if (this->hasCustomWindowFrame()) {
*result = 0; *result = 0;
const LONG border_width = 8; // in pixels const LONG border_width = 8; // in pixels
RECT winrect; RECT winrect;
GetWindowRect((HWND)winId(), &winrect); GetWindowRect(HWND(winId()), &winrect);
long x = GET_X_LPARAM(msg->lParam); long x = GET_X_LPARAM(msg->lParam);
long y = GET_Y_LPARAM(msg->lParam); long y = GET_Y_LPARAM(msg->lParam);
@ -442,13 +441,13 @@ void BaseWindow::showEvent(QShowEvent *event)
// WS_MINIMIZEBOX); // WS_MINIMIZEBOX);
const MARGINS shadow = {8, 8, 8, 8}; const MARGINS shadow = {8, 8, 8, 8};
DwmExtendFrameIntoClientArea((HWND)this->winId(), &shadow); DwmExtendFrameIntoClientArea(HWND(this->winId()), &shadow);
} }
BaseWidget::showEvent(event); BaseWidget::showEvent(event);
} }
void BaseWindow::paintEvent(QPaintEvent *event) void BaseWindow::paintEvent(QPaintEvent *)
{ {
if (this->hasCustomWindowFrame()) { if (this->hasCustomWindowFrame()) {
QPainter painter(this); QPainter painter(this);

View file

@ -31,7 +31,7 @@ public:
void setStayInScreenRect(bool value); void setStayInScreenRect(bool value);
bool getStayInScreenRect() const; bool getStayInScreenRect() const;
void moveTo(QWidget *widget, QPoint point); void moveTo(QWidget *widget, QPoint point, bool offset = true);
Flags getFlags(); Flags getFlags();

View file

@ -353,7 +353,7 @@ void SplitHeader::enterEvent(QEvent *event)
{ {
if (!this->tooltip.isEmpty()) { if (!this->tooltip.isEmpty()) {
auto tooltipWidget = TooltipWidget::getInstance(); 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->setText(this->tooltip);
tooltipWidget->show(); tooltipWidget->show();
tooltipWidget->raise(); tooltipWidget->raise();

View file

@ -20,7 +20,7 @@ Scrollbar::Scrollbar(ChannelView *parent)
: BaseWidget(parent) : BaseWidget(parent)
, currentValueAnimation(this, "currentValue") , currentValueAnimation(this, "currentValue")
{ {
resize((int)(16 * this->getScale()), 100); resize(int(16 * this->getScale()), 100);
this->currentValueAnimation.setDuration(150); this->currentValueAnimation.setDuration(150);
this->currentValueAnimation.setEasingCurve(QEasingCurve(QEasingCurve::OutCubic)); this->currentValueAnimation.setEasingCurve(QEasingCurve(QEasingCurve::OutCubic));
@ -31,7 +31,7 @@ Scrollbar::Scrollbar(ChannelView *parent)
timer->setSingleShot(true); timer->setSingleShot(true);
connect(timer, &QTimer::timeout, [=]() { connect(timer, &QTimer::timeout, [=]() {
resize((int)(16 * this->getScale()), 100); resize(int(16 * this->getScale()), 100);
timer->deleteLater(); timer->deleteLater();
}); });
@ -98,7 +98,7 @@ void Scrollbar::setDesiredValue(qreal value, bool animated)
animated &= app->settings->enableSmoothScrolling.getValue(); 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 (this->desiredValue + this->smoothScrollingOffset != value) { if (std::abs(this->desiredValue + this->smoothScrollingOffset - value) > 0.0001) {
if (animated) { if (animated) {
this->currentValueAnimation.stop(); this->currentValueAnimation.stop();
this->currentValueAnimation.setStartValue(this->currentValue + this->currentValueAnimation.setStartValue(this->currentValue +
@ -196,8 +196,10 @@ void Scrollbar::printCurrentState(const QString &prefix) const
void Scrollbar::paintEvent(QPaintEvent *) 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()); int xOffset = mouseOver ? 0 : width() - int(4 * this->getScale());
QPainter painter(this); QPainter painter(this);
// painter.fillRect(rect(), this->themeManager->ScrollbarBG); // painter.fillRect(rect(), this->themeManager->ScrollbarBG);
@ -221,7 +223,7 @@ void Scrollbar::paintEvent(QPaintEvent *)
// draw highlights // draw highlights
auto snapshot = this->highlights.getSnapshot(); auto snapshot = this->highlights.getSnapshot();
int snapshotLength = (int)snapshot.getLength(); size_t snapshotLength = snapshot.getLength();
if (snapshotLength == 0) { if (snapshotLength == 0) {
return; return;
@ -229,19 +231,31 @@ void Scrollbar::paintEvent(QPaintEvent *)
int w = this->width(); int w = this->width();
float y = 0; float y = 0;
float dY = (float)(this->height()) / (float)snapshotLength; float dY = float(this->height()) / float(snapshotLength);
int highlightHeight = std::ceil(dY); 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]; ScrollbarHighlight const &highlight = snapshot[i];
if (!highlight.isNull()) { if (!highlight.isNull()) {
if (highlight.getStyle() == ScrollbarHighlight::Default) { QColor color = [&] {
painter.fillRect(w / 8 * 3, (int)y, w / 4, highlightHeight, switch (highlight.getColor()) {
this->themeManager->tabs.selected.backgrounds.regular.color()); case ScrollbarHighlight::Highlight:
} else { return app->themes->scrollbars.highlights.highlight;
painter.fillRect(0, (int)y, w, 1, }
this->themeManager->tabs.selected.backgrounds.regular.color()); 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 *) 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) void Scrollbar::mouseMoveEvent(QMouseEvent *event)
@ -279,7 +293,7 @@ void Scrollbar::mouseMoveEvent(QMouseEvent *event)
} else if (this->mouseDownIndex == 2) { } else if (this->mouseDownIndex == 2) {
int delta = event->pos().y() - this->lastMousePosition.y(); 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();
@ -342,8 +356,8 @@ void Scrollbar::updateScroll()
this->trackHeight = height() - this->buttonHeight - this->buttonHeight - MIN_THUMB_HEIGHT - 1; this->trackHeight = height() - this->buttonHeight - this->buttonHeight - MIN_THUMB_HEIGHT - 1;
this->thumbRect = QRect( this->thumbRect = QRect(
0, (int)(this->currentValue / this->maximum * this->trackHeight) + 1 + this->buttonHeight, 0, int(this->currentValue / this->maximum * this->trackHeight) + 1 + this->buttonHeight,
width(), (int)(this->largeChange / this->maximum * this->trackHeight) + MIN_THUMB_HEIGHT); width(), int(this->largeChange / this->maximum * this->trackHeight) + MIN_THUMB_HEIGHT);
update(); update();
} }

View file

@ -21,7 +21,7 @@ class Scrollbar : public BaseWidget
Q_OBJECT Q_OBJECT
public: public:
Scrollbar(ChannelView *parent = 0); Scrollbar(ChannelView *parent = nullptr);
void addHighlight(ScrollbarHighlight highlight); void addHighlight(ScrollbarHighlight highlight);
void addHighlightsAtStart(const std::vector<ScrollbarHighlight> &highlights); void addHighlightsAtStart(const std::vector<ScrollbarHighlight> &highlights);

View file

@ -16,6 +16,15 @@
namespace chatterino { namespace chatterino {
namespace widgets { namespace widgets {
TooltipWidget *TooltipWidget::getInstance()
{
static TooltipWidget *tooltipWidget = nullptr;
if (tooltipWidget == nullptr) {
tooltipWidget = new TooltipWidget();
}
return tooltipWidget;
}
TooltipWidget::TooltipWidget(BaseWidget *parent) TooltipWidget::TooltipWidget(BaseWidget *parent)
: BaseWindow(parent, BaseWindow::TopMost) : BaseWindow(parent, BaseWindow::TopMost)
, displayText(new QLabel()) , displayText(new QLabel())
@ -49,7 +58,7 @@ TooltipWidget::~TooltipWidget()
#ifdef USEWINSDK #ifdef USEWINSDK
void TooltipWidget::raise() 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); SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
} }
#endif #endif

View file

@ -14,20 +14,13 @@ class TooltipWidget : public BaseWindow
Q_OBJECT Q_OBJECT
public: public:
static TooltipWidget *getInstance();
TooltipWidget(BaseWidget *parent = nullptr); TooltipWidget(BaseWidget *parent = nullptr);
~TooltipWidget(); virtual ~TooltipWidget() override;
void setText(QString text); void setText(QString text);
static TooltipWidget *getInstance()
{
static TooltipWidget *tooltipWidget = nullptr;
if (tooltipWidget == nullptr) {
tooltipWidget = new TooltipWidget();
}
return tooltipWidget;
}
#ifdef USEWINSDK #ifdef USEWINSDK
void raise(); void raise();
#endif #endif