fix: split header "add split" button inconsistency (#6349)

This commit is contained in:
pajlada
2025-07-26 14:23:29 +02:00
committed by GitHub
parent cd7b710d94
commit aa8f8f2e3e
11 changed files with 307 additions and 13 deletions
+2
View File
@@ -148,6 +148,7 @@ void Button::enterEvent(QEvent * /*event*/)
{
this->mouseOver_ = true;
this->update();
this->mouseOverUpdated();
}
}
@@ -157,6 +158,7 @@ void Button::leaveEvent(QEvent * /*event*/)
{
this->mouseOver_ = false;
this->update();
this->mouseOverUpdated();
}
}
+5
View File
@@ -183,6 +183,11 @@ protected:
/// Queue up the click animation at the given position
void addClickEffect(QPoint position);
/// This is fired when the mouse over state changes
virtual void mouseOverUpdated()
{
}
private:
void onMouseEffectTimeout();
void showMenu();
+163
View File
@@ -0,0 +1,163 @@
#include "widgets/buttons/DrawnButton.hpp"
#include "singletons/Theme.hpp"
#include <QPainter>
namespace chatterino {
DrawnButton::DrawnButton(Symbol symbol_, Options options, BaseWidget *parent)
: Button(parent)
, symbol(symbol_)
{
this->setContentCacheEnabled(true);
// Set user-defined options
this->setOptions(options);
// Ensure symbol-specific options are initially set
this->themeChangedEvent();
}
void DrawnButton::setOptions(Options options_)
{
this->options = options_;
this->invalidateContent();
}
void DrawnButton::themeChangedEvent()
{
Button::themeChangedEvent();
auto &o = this->symbolOptions;
switch (this->symbol)
{
case Symbol::Plus: {
o.padding = 3;
o.thickness = 1;
o.foreground = this->theme->messages.textColors.system;
o.foregroundHover = this->theme->messages.textColors.regular;
}
break;
}
this->invalidateContent();
}
void DrawnButton::mouseOverUpdated()
{
this->invalidateContent();
}
void DrawnButton::paintContent(QPainter &painter)
{
QColor fg;
QColor bg;
if (this->mouseOver())
{
bg = this->getBackgroundHover();
fg = this->getForegroundHover();
}
else
{
bg = this->getBackground();
fg = this->getForeground();
}
if (bg.isValid())
{
painter.fillRect(this->rect(), bg);
}
auto thickness = this->getThickness();
auto padding = this->getPadding();
switch (this->symbol)
{
case Symbol::Plus: {
QPen pen;
pen.setColor(fg);
pen.setWidth(thickness);
painter.setPen(pen);
auto innerSize = this->rect().size();
innerSize.setHeight(innerSize.width());
QRect inner;
inner.setSize(innerSize);
inner.moveCenter(this->rect().center());
auto top = inner.top();
auto bottom = inner.bottom();
auto center = inner.center();
auto left = inner.left();
auto right = inner.right();
QLine vertical(center.x(), top + padding, center.x(),
bottom - padding);
painter.drawLine(vertical);
QLine horizontal(left + padding, center.y(), right - padding,
center.y());
painter.drawLine(horizontal);
}
break;
}
}
int DrawnButton::getPadding() const
{
auto v =
this->options.padding.value_or(this->symbolOptions.padding.value_or(0));
return static_cast<int>(std::round(static_cast<float>(v) * this->scale()));
}
int DrawnButton::getThickness() const
{
auto v = this->options.thickness.value_or(
this->symbolOptions.thickness.value_or(1));
return std::max(1, static_cast<int>(
std::round(static_cast<double>(v) * this->scale())));
}
QColor DrawnButton::getBackground() const
{
auto v = this->options.background.value_or(
this->symbolOptions.background.value_or(QColor()));
return v;
}
QColor DrawnButton::getBackgroundHover() const
{
auto v = this->options.backgroundHover.value_or(
this->symbolOptions.backgroundHover.value_or(QColor()));
return v;
}
QColor DrawnButton::getForeground() const
{
auto v = this->options.foreground.value_or(
this->symbolOptions.foreground.value_or(QColor()));
assert(v.isValid());
return v;
}
QColor DrawnButton::getForegroundHover() const
{
auto v = this->options.foregroundHover.value_or(
this->symbolOptions.foregroundHover.value_or(QColor()));
assert(v.isValid());
return v;
}
} // namespace chatterino
+102
View File
@@ -0,0 +1,102 @@
#pragma once
#include "widgets/buttons/Button.hpp"
#include <QWidget>
#include <optional>
namespace chatterino {
/// A button displaying custom-drawn primitive symbols.
class DrawnButton : public Button
{
Q_OBJECT
public:
enum class Symbol : std::uint8_t {
/// +
///
/// Default values:
/// Padding: 2px
/// Thickness: 1px
Plus,
};
struct Options {
/// The horizontal and vertical padding, in unscaled pixels, that will be applied when drawing the symbol
std::optional<int> padding;
/// The base line thickness that will be used when drawing the symbol.
///
/// Each symbol might use the thickness slightly different
std::optional<int> thickness;
std::optional<QColor> background;
std::optional<QColor> backgroundHover;
std::optional<QColor> foreground;
std::optional<QColor> foregroundHover;
};
DrawnButton(Symbol symbol_, Options options_, BaseWidget *parent);
/// Update the override options for this button
void setOptions(Options options_);
protected:
void themeChangedEvent() override;
void mouseOverUpdated() override;
void paintContent(QPainter &painter) override;
private:
/// Returns the padding (horizontal and vertical) to be used when drawing this button, taking the widget scale into consideration.
///
/// Prioritizes the user-defined options over the symbol-defined options.
int getPadding() const;
/// Returns the line thickness to be used when drawing this button, taking the widget scale into consideration.
///
/// Prioritizes the user-defined options over the symbol-defined options.
int getThickness() const;
/// Returns the background to be used when drawing this button.
///
/// The color may be invalid, meaning no background is drawn.
///
/// Prioritizes the user-defined options over the symbol-defined options.
QColor getBackground() const;
/// Returns the background to be used when drawing this button, and the user is hovering over it.
///
/// The color may be invalid, meaning no background is drawn.
///
/// Prioritizes the user-defined options over the symbol-defined options.
QColor getBackgroundHover() const;
/// Returns the foreground color to be used when drawing this button.
///
/// The color must not be invalid.
///
/// Prioritizes the user-defined options over the symbol-defined options.
QColor getForeground() const;
/// Returns the foreground color to be used when drawing this button, and the user is hovering over it.
///
/// The color must not be invalid.
///
/// Prioritizes the user-defined options over the symbol-defined options.
QColor getForegroundHover() const;
/// The options defined by the consumer / class wanting to draw this button
Options options;
/// The default options defined by the symbol
Options symbolOptions;
const Symbol symbol;
};
} // namespace chatterino