minor improvements

This commit is contained in:
fourtf
2018-12-02 17:49:15 +01:00
parent 52dcc2130e
commit 0e242202a4
8 changed files with 35 additions and 24 deletions
+2 -2
View File
@@ -62,9 +62,9 @@ const ImagePtr &ImageSet::getImage(float scale) const
int quality = 1;
if (scale > 2.999)
if (scale > 2.001f)
quality = 3;
else if (scale > 1.5)
else if (scale > 1.001f)
quality = 2;
if (!this->imageX3_->isEmpty() && quality == 3)
+1 -1
View File
@@ -30,7 +30,7 @@ struct SelectionItem {
bool operator>(const SelectionItem &b) const
{
return b.operator<(*this);
return !this->operator==(b) && b.operator<(*this);
}
bool operator==(const SelectionItem &b) const
@@ -96,7 +96,7 @@ void MessageLayoutContainer::_addElement(MessageLayoutElement *element,
// top margin
if (this->elements_.size() == 0)
{
this->currentY_ = this->margin.top * this->scale_;
this->currentY_ = int(this->margin.top * this->scale_);
}
int newLineHeight = element->getRect().height();
@@ -169,7 +169,8 @@ void MessageLayoutContainer::breakLine()
}
element->setPosition(
QPoint(element->getRect().x() + xOffset + this->margin.left,
QPoint(element->getRect().x() + xOffset +
int(this->margin.left * this->scale_),
element->getRect().y() + this->lineHeight_ + yExtra));
}
@@ -198,7 +199,7 @@ void MessageLayoutContainer::breakLine()
this->currentX_ = 0;
this->currentY_ += this->lineHeight_;
this->height_ = this->currentY_ + (this->margin.bottom * this->scale_);
this->height_ = this->currentY_ + int(this->margin.bottom * this->scale_);
this->lineHeight_ = 0;
this->line_++;
}
@@ -211,7 +212,8 @@ bool MessageLayoutContainer::atStartOfLine()
bool MessageLayoutContainer::fitsInLine(int _width)
{
return this->currentX_ + _width <=
(this->width_ - this->margin.left - this->margin.right -
(this->width_ - int(this->margin.left * this->scale_) -
int(this->margin.right * this->scale_) -
(this->line_ + 1 == MAX_UNCOLLAPSED_LINES ? this->dotdotdotWidth_
: 0));
}
@@ -517,6 +519,8 @@ int MessageLayoutContainer::getSelectionIndex(QPoint point)
for (int i = 0; i < lineEnd; i++)
{
auto &&element = this->elements_[i];
// end of line
if (i == lineEnd)
{
@@ -526,18 +530,20 @@ int MessageLayoutContainer::getSelectionIndex(QPoint point)
// before line
if (i < lineStart)
{
index += this->elements_[i]->getSelectionIndexCount();
index += element->getSelectionIndexCount();
continue;
}
// this is the word
if (point.x() <= this->elements_[i]->getRect().right())
auto rightMargin = element->hasTrailingSpace() ? this->spaceWidth_ : 0;
if (point.x() <= element->getRect().right() + rightMargin)
{
index += this->elements_[i]->getMouseOverIndex(point);
index += element->getMouseOverIndex(point);
break;
}
index += this->elements_[i]->getSelectionIndexCount();
index += element->getSelectionIndexCount();
}
return index;
+11 -9
View File
@@ -234,20 +234,17 @@ int TextLayoutElement::getMouseOverIndex(const QPoint &abs) const
auto app = getApp();
QFontMetrics metrics =
app->fonts->getFontMetrics(this->style_, this->scale_);
auto metrics = app->fonts->getFontMetrics(this->style_, this->scale_);
auto x = this->getRect().left();
int x = this->getRect().left();
for (int i = 0; i < this->getText().size(); i++)
for (auto i = 0; i < this->getText().size(); i++)
{
auto &text = this->getText();
auto &&text = this->getText();
auto width = metrics.width(this->getText()[i]);
if (x + width > abs.x())
{
if (text.size() > i + 1 &&
QChar::isLowSurrogate(text[i].unicode())) //
if (text.size() > i + 1 && QChar::isLowSurrogate(text[i].unicode()))
{
i++;
}
@@ -258,7 +255,12 @@ int TextLayoutElement::getMouseOverIndex(const QPoint &abs) const
x += width;
}
return this->getSelectionIndexCount();
// if (this->hasTrailingSpace() && abs.x() < this->getRect().right())
// {
// return this->getSelectionIndexCount() - 1;
// }
return this->getSelectionIndexCount() - (this->hasTrailingSpace() ? 1 : 0);
}
int TextLayoutElement::getXFromIndex(int index)