diff --git a/src/common/NetworkRequest.hpp b/src/common/NetworkRequest.hpp index f068448a5..cb6407686 100644 --- a/src/common/NetworkRequest.hpp +++ b/src/common/NetworkRequest.hpp @@ -10,7 +10,7 @@ namespace chatterino { struct NetworkData; -class NetworkRequest +class NetworkRequest final { // Stores all data about the request that needs to be passed around to each // part of the request diff --git a/src/messages/ImageSet.cpp b/src/messages/ImageSet.cpp index 3925dc1e7..b6ef9e2ce 100644 --- a/src/messages/ImageSet.cpp +++ b/src/messages/ImageSet.cpp @@ -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) diff --git a/src/messages/Selection.hpp b/src/messages/Selection.hpp index c1ada456a..d9ce2f93d 100644 --- a/src/messages/Selection.hpp +++ b/src/messages/Selection.hpp @@ -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 diff --git a/src/messages/layouts/MessageLayoutContainer.cpp b/src/messages/layouts/MessageLayoutContainer.cpp index 747fcc358..c2b43f357 100644 --- a/src/messages/layouts/MessageLayoutContainer.cpp +++ b/src/messages/layouts/MessageLayoutContainer.cpp @@ -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; diff --git a/src/messages/layouts/MessageLayoutElement.cpp b/src/messages/layouts/MessageLayoutElement.cpp index 97915ae1c..a47922408 100644 --- a/src/messages/layouts/MessageLayoutElement.cpp +++ b/src/messages/layouts/MessageLayoutElement.cpp @@ -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) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 81041bc0e..2843d93a4 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1684,7 +1684,7 @@ bool ChannelView::tryGetMessageAt(QPoint p, int ChannelView::getLayoutWidth() const { if (this->scrollBar_->isVisible()) - return int(this->width() - 8 * this->scale()); + return int(this->width() - scrollbarPadding * this->scale()); return this->width(); } diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 48c253194..33a69f02b 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -201,6 +201,9 @@ private: std::unordered_set> messagesOnScreen_; + static constexpr int leftPadding = 8; + static constexpr int scrollbarPadding = 8; + private slots: void wordFlagsChanged() { diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index ea47056e1..f50d938f3 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -11,6 +11,7 @@ #include "singletons/Settings.hpp" #include "singletons/Theme.hpp" #include "singletons/WindowManager.hpp" +#include "util/Shortcut.hpp" #include "util/StreamLink.hpp" #include "widgets/Notebook.hpp" #include "widgets/Window.hpp" @@ -23,7 +24,6 @@ #include "widgets/helper/NotebookTab.hpp" #include "widgets/helper/ResizingTextEdit.hpp" #include "widgets/helper/SearchPopup.hpp" -#include "util/Shortcut.hpp" #include "widgets/splits/ClosedSplits.hpp" #include "widgets/splits/SplitContainer.hpp" #include "widgets/splits/SplitHeader.hpp" @@ -297,7 +297,7 @@ void Split::showChangeChannelPopup(const char *dialogTitle, bool empty, return; } - SelectChannelDialog *dialog = new SelectChannelDialog(this); + auto dialog = new SelectChannelDialog(this); if (!empty) { dialog->setSelectedChannel(this->getIndirectChannel());