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

View file

@ -10,7 +10,7 @@ namespace chatterino {
struct NetworkData; struct NetworkData;
class NetworkRequest class NetworkRequest final
{ {
// Stores all data about the request that needs to be passed around to each // Stores all data about the request that needs to be passed around to each
// part of the request // part of the request

View file

@ -62,9 +62,9 @@ const ImagePtr &ImageSet::getImage(float scale) const
int quality = 1; int quality = 1;
if (scale > 2.999) if (scale > 2.001f)
quality = 3; quality = 3;
else if (scale > 1.5) else if (scale > 1.001f)
quality = 2; quality = 2;
if (!this->imageX3_->isEmpty() && quality == 3) if (!this->imageX3_->isEmpty() && quality == 3)

View file

@ -30,7 +30,7 @@ struct SelectionItem {
bool operator>(const SelectionItem &b) const bool operator>(const SelectionItem &b) const
{ {
return b.operator<(*this); return !this->operator==(b) && b.operator<(*this);
} }
bool operator==(const SelectionItem &b) const bool operator==(const SelectionItem &b) const

View file

@ -96,7 +96,7 @@ void MessageLayoutContainer::_addElement(MessageLayoutElement *element,
// top margin // top margin
if (this->elements_.size() == 0) 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(); int newLineHeight = element->getRect().height();
@ -169,7 +169,8 @@ void MessageLayoutContainer::breakLine()
} }
element->setPosition( 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)); element->getRect().y() + this->lineHeight_ + yExtra));
} }
@ -198,7 +199,7 @@ void MessageLayoutContainer::breakLine()
this->currentX_ = 0; this->currentX_ = 0;
this->currentY_ += this->lineHeight_; 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->lineHeight_ = 0;
this->line_++; this->line_++;
} }
@ -211,7 +212,8 @@ bool MessageLayoutContainer::atStartOfLine()
bool MessageLayoutContainer::fitsInLine(int _width) bool MessageLayoutContainer::fitsInLine(int _width)
{ {
return this->currentX_ + _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_ (this->line_ + 1 == MAX_UNCOLLAPSED_LINES ? this->dotdotdotWidth_
: 0)); : 0));
} }
@ -517,6 +519,8 @@ int MessageLayoutContainer::getSelectionIndex(QPoint point)
for (int i = 0; i < lineEnd; i++) for (int i = 0; i < lineEnd; i++)
{ {
auto &&element = this->elements_[i];
// end of line // end of line
if (i == lineEnd) if (i == lineEnd)
{ {
@ -526,18 +530,20 @@ int MessageLayoutContainer::getSelectionIndex(QPoint point)
// before line // before line
if (i < lineStart) if (i < lineStart)
{ {
index += this->elements_[i]->getSelectionIndexCount(); index += element->getSelectionIndexCount();
continue; continue;
} }
// this is the word // 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; break;
} }
index += this->elements_[i]->getSelectionIndexCount(); index += element->getSelectionIndexCount();
} }
return index; return index;

View file

@ -234,20 +234,17 @@ int TextLayoutElement::getMouseOverIndex(const QPoint &abs) const
auto app = getApp(); auto app = getApp();
QFontMetrics metrics = auto metrics = app->fonts->getFontMetrics(this->style_, this->scale_);
app->fonts->getFontMetrics(this->style_, this->scale_); auto x = this->getRect().left();
int x = this->getRect().left(); for (auto i = 0; i < this->getText().size(); i++)
for (int i = 0; i < this->getText().size(); i++)
{ {
auto &text = this->getText(); auto &&text = this->getText();
auto width = metrics.width(this->getText()[i]); auto width = metrics.width(this->getText()[i]);
if (x + width > abs.x()) if (x + width > abs.x())
{ {
if (text.size() > i + 1 && if (text.size() > i + 1 && QChar::isLowSurrogate(text[i].unicode()))
QChar::isLowSurrogate(text[i].unicode())) //
{ {
i++; i++;
} }
@ -258,7 +255,12 @@ int TextLayoutElement::getMouseOverIndex(const QPoint &abs) const
x += width; 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) int TextLayoutElement::getXFromIndex(int index)

View file

@ -1684,7 +1684,7 @@ bool ChannelView::tryGetMessageAt(QPoint p,
int ChannelView::getLayoutWidth() const int ChannelView::getLayoutWidth() const
{ {
if (this->scrollBar_->isVisible()) if (this->scrollBar_->isVisible())
return int(this->width() - 8 * this->scale()); return int(this->width() - scrollbarPadding * this->scale());
return this->width(); return this->width();
} }

View file

@ -201,6 +201,9 @@ private:
std::unordered_set<std::shared_ptr<MessageLayout>> messagesOnScreen_; std::unordered_set<std::shared_ptr<MessageLayout>> messagesOnScreen_;
static constexpr int leftPadding = 8;
static constexpr int scrollbarPadding = 8;
private slots: private slots:
void wordFlagsChanged() void wordFlagsChanged()
{ {

View file

@ -11,6 +11,7 @@
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
#include "singletons/Theme.hpp" #include "singletons/Theme.hpp"
#include "singletons/WindowManager.hpp" #include "singletons/WindowManager.hpp"
#include "util/Shortcut.hpp"
#include "util/StreamLink.hpp" #include "util/StreamLink.hpp"
#include "widgets/Notebook.hpp" #include "widgets/Notebook.hpp"
#include "widgets/Window.hpp" #include "widgets/Window.hpp"
@ -23,7 +24,6 @@
#include "widgets/helper/NotebookTab.hpp" #include "widgets/helper/NotebookTab.hpp"
#include "widgets/helper/ResizingTextEdit.hpp" #include "widgets/helper/ResizingTextEdit.hpp"
#include "widgets/helper/SearchPopup.hpp" #include "widgets/helper/SearchPopup.hpp"
#include "util/Shortcut.hpp"
#include "widgets/splits/ClosedSplits.hpp" #include "widgets/splits/ClosedSplits.hpp"
#include "widgets/splits/SplitContainer.hpp" #include "widgets/splits/SplitContainer.hpp"
#include "widgets/splits/SplitHeader.hpp" #include "widgets/splits/SplitHeader.hpp"
@ -297,7 +297,7 @@ void Split::showChangeChannelPopup(const char *dialogTitle, bool empty,
return; return;
} }
SelectChannelDialog *dialog = new SelectChannelDialog(this); auto dialog = new SelectChannelDialog(this);
if (!empty) if (!empty)
{ {
dialog->setSelectedChannel(this->getIndirectChannel()); dialog->setSelectedChannel(this->getIndirectChannel());