[img-editor] Fixed contrast text color in edit proxy for framed type.

This commit is contained in:
23rd
2026-04-20 10:34:34 +03:00
parent 085f139abd
commit e99442cb1c
4 changed files with 27 additions and 3 deletions
+15 -3
View File
@@ -396,7 +396,9 @@ void Scene::setTextDefaults(
void Scene::setTextColor(const QColor &color) {
_textColor = color;
if (_textEdit.proxy) {
_textEdit.proxy->setDefaultTextColor(color);
_textEdit.proxy->setDefaultTextColor(EffectiveTextColor(
color,
static_cast<TextStyle>(_textEditStyle)));
}
}
@@ -593,10 +595,16 @@ void Scene::createTextAtCenter() {
clearSelection();
cancelDrawing();
setTextEditing(true);
_textEditStyle = _textStyle;
_textEdit.proxy.reset(new TextEditProxy());
const auto proxy = _textEdit.proxy.get();
setupTextProxy(proxy, _textColor, _textFontSize);
setupTextProxy(
proxy,
EffectiveTextColor(
_textColor,
static_cast<TextStyle>(_textEditStyle)),
_textFontSize);
const auto emojiDoc = proxy->document();
const auto shortSide = std::min(
@@ -663,10 +671,14 @@ void Scene::startTextEditing(ItemText *item) {
cancelDrawing();
setTextEditing(true);
_textEditStyle = int(item->textStyle());
_textEdit.proxy.reset(new TextEditProxy());
const auto proxy = _textEdit.proxy.get();
setupTextProxy(proxy, item->color(), item->fontSize());
setupTextProxy(
proxy,
EffectiveTextColor(item->color(), item->textStyle()),
item->fontSize());
proxy->setPlainText(item->text());
ReplaceEmoji(proxy->document());
@@ -96,6 +96,7 @@ private:
QColor _textColor;
float64 _textFontSize = 0.;
int _textStyle = 0;
int _textEditStyle = 0;
struct {
std::weak_ptr<NumberedItem> item;
@@ -257,6 +257,15 @@ QPainterPath BuildConnectedBackground(
} // namespace
QColor EffectiveTextColor(const QColor &color, TextStyle style) {
if (style != TextStyle::Framed) {
return color;
}
return (ComputeBrightness(color) >= kBrightnessFramedThreshold)
? QColor(0, 0, 0)
: QColor(255, 255, 255);
}
ItemText::ItemText(
const QString &text,
const QColor &color,
@@ -22,6 +22,8 @@ enum class TextStyle : uchar {
Plain,
};
[[nodiscard]] QColor EffectiveTextColor(const QColor &color, TextStyle style);
class ItemText : public ItemBase {
public:
enum { Type = ItemBase::Type + 2 };