mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/telegramdesktop/tdesktop
synced 2026-09-20 08:03:45 +08:00
[img-editor] Added baking of text scale into font size on resize finish.
This commit is contained in:
@@ -813,6 +813,12 @@ void Scene::clearRedoList() {
|
||||
|
||||
void Scene::save(SaveState state) {
|
||||
_textEdit->finishEditing(true);
|
||||
for (const auto &item : _items) {
|
||||
if (item->isNormalStatus()
|
||||
&& (item->type() == ItemText::Type)) {
|
||||
static_cast<ItemText*>(item.get())->bakeScale();
|
||||
}
|
||||
}
|
||||
|
||||
removeIf([](const ItemPtr &item) {
|
||||
return item->isRemovedStatus()
|
||||
|
||||
@@ -79,6 +79,7 @@ public:
|
||||
float64 size = 0.;
|
||||
float64 aspectRatio = 1.;
|
||||
float64 bend = 0.;
|
||||
float64 fontSize = 0.;
|
||||
bool flipped = false;
|
||||
|
||||
friend inline bool operator==(
|
||||
|
||||
@@ -481,8 +481,9 @@ void ItemText::renderContent() {
|
||||
const auto handleMargin = std::max(
|
||||
innerRect().width() - contentRect().width(),
|
||||
0.);
|
||||
setAspectRatio(
|
||||
(pixHeight + handleMargin) / float64(pixWidth + handleMargin));
|
||||
applyStretch(
|
||||
pixWidth + handleMargin,
|
||||
pixHeight + handleMargin);
|
||||
}
|
||||
|
||||
QSize ItemText::computeContentSize(
|
||||
@@ -583,6 +584,31 @@ float64 ItemText::editScale() const {
|
||||
return std::max(size() - handleMargin, 1.) / natural.width();
|
||||
}
|
||||
|
||||
void ItemText::bakeScale() {
|
||||
const auto factor = editScale() * scale();
|
||||
if (_text.isEmpty() || (std::abs(factor - 1.) < 0.001)) {
|
||||
return;
|
||||
}
|
||||
_fontSize = std::max(_fontSize * factor, 1.);
|
||||
setScale(1.);
|
||||
renderContent();
|
||||
update();
|
||||
}
|
||||
|
||||
ItemBase::Placement ItemText::placement() const {
|
||||
auto result = ItemBase::placement();
|
||||
result.fontSize = _fontSize;
|
||||
return result;
|
||||
}
|
||||
|
||||
void ItemText::applyPlacement(const Placement &placement) {
|
||||
if ((placement.fontSize > 0.) && (placement.fontSize != _fontSize)) {
|
||||
_fontSize = placement.fontSize;
|
||||
renderContent();
|
||||
}
|
||||
ItemBase::applyPlacement(placement);
|
||||
}
|
||||
|
||||
TextStyle ItemText::textStyle() const {
|
||||
return _textStyle;
|
||||
}
|
||||
@@ -596,6 +622,15 @@ void ItemText::setTextStyle(TextStyle style) {
|
||||
update();
|
||||
}
|
||||
|
||||
void ItemText::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||
const auto resized = isHandling()
|
||||
&& (event->button() == Qt::LeftButton);
|
||||
ItemBase::mouseReleaseEvent(event);
|
||||
if (resized) {
|
||||
bakeScale();
|
||||
}
|
||||
}
|
||||
|
||||
void ItemText::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
|
||||
if ((event->button() != Qt::LeftButton)
|
||||
|| !contentRect().contains(event->pos())) {
|
||||
|
||||
@@ -74,6 +74,10 @@ public:
|
||||
void setTextStyle(TextStyle style);
|
||||
|
||||
[[nodiscard]] float64 editScale() const;
|
||||
void bakeScale();
|
||||
|
||||
[[nodiscard]] Placement placement() const override;
|
||||
void applyPlacement(const Placement &placement) override;
|
||||
|
||||
[[nodiscard]] static QSize computeContentSize(
|
||||
const QString &text,
|
||||
@@ -86,6 +90,7 @@ public:
|
||||
|
||||
protected:
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||
void actionFlip() override;
|
||||
void performFlip() override;
|
||||
|
||||
Reference in New Issue
Block a user