mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
fixed compiling
This commit is contained in:
parent
d045f6963a
commit
6701c3d0b2
|
@ -275,80 +275,7 @@ int MessageLayout::getLastCharacterIndex() const
|
|||
|
||||
int MessageLayout::getSelectionIndex(QPoint position)
|
||||
{
|
||||
// if (this->wordParts.size() == 0) {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// // find out in which line the cursor is
|
||||
// int lineNumber = 0, lineStart = 0, lineEnd = 0;
|
||||
|
||||
// for (size_t i = 0; i < this->wordParts.size(); i++) {
|
||||
// LayoutItem &part = this->wordParts[i];
|
||||
|
||||
// if (part.getLineNumber() != 0 && position.y() < part.getY()) {
|
||||
// break;
|
||||
// }
|
||||
|
||||
// if (part.getLineNumber() != lineNumber) {
|
||||
// lineStart = i;
|
||||
// lineNumber = part.getLineNumber();
|
||||
// }
|
||||
|
||||
// lineEnd = i + 1;
|
||||
// }
|
||||
|
||||
// // count up to the cursor
|
||||
// int index = 0;
|
||||
|
||||
// for (int i = 0; i < lineStart; i++) {
|
||||
// LayoutItem &part = this->wordParts[i];
|
||||
|
||||
// index += part.getWord().isImage() ? 2 : part.getText().length() + 1;
|
||||
// }
|
||||
|
||||
// for (int i = lineStart; i < lineEnd; i++) {
|
||||
// LayoutItem &part = this->wordParts[i];
|
||||
|
||||
// // curser is left of the word part
|
||||
// if (position.x() < part.getX()) {
|
||||
// break;
|
||||
// }
|
||||
|
||||
// // cursor is right of the word part
|
||||
// if (position.x() > part.getX() + part.getWidth()) {
|
||||
// index += part.getCharacterLength();
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// // cursor is over the word part
|
||||
// if (part.getWord().isImage()) {
|
||||
// if (position.x() - part.getX() > part.getWidth() / 2) {
|
||||
// index++;
|
||||
// }
|
||||
// } else {
|
||||
// // TODO: use word.getCharacterWidthCache();
|
||||
|
||||
// auto text = part.getText();
|
||||
|
||||
// int x = part.getX();
|
||||
|
||||
// for (int j = 0; j < text.length(); j++) {
|
||||
// if (x > position.x()) {
|
||||
// break;
|
||||
// }
|
||||
|
||||
// index++;
|
||||
// x = part.getX() + part.getWord().getFontMetrics(this->scale).width(text, j +
|
||||
// 1);
|
||||
// }
|
||||
// }
|
||||
|
||||
// break;
|
||||
// }
|
||||
|
||||
// return index;
|
||||
|
||||
return 0;
|
||||
return this->container.getSelectionIndex(position);
|
||||
}
|
||||
} // namespace layouts
|
||||
} // namespace messages
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "messages/selection.hpp"
|
||||
#include "singletons/settingsmanager.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
|
||||
#define COMPACT_EMOTES_OFFSET 6
|
||||
|
@ -105,6 +106,8 @@ void MessageLayoutContainer::breakLine()
|
|||
element->getRect().y() + this->lineHeight + yExtra));
|
||||
}
|
||||
|
||||
this->lines.push_back({(int)lineStart, QRect(0, this->currentY, this->width, lineHeight)});
|
||||
|
||||
this->lineStart = this->elements.size();
|
||||
this->currentX = 0;
|
||||
this->currentY += this->lineHeight;
|
||||
|
@ -127,6 +130,11 @@ void MessageLayoutContainer::finish()
|
|||
if (!this->atStartOfLine()) {
|
||||
this->breakLine();
|
||||
}
|
||||
|
||||
if (this->lines.size() != 0) {
|
||||
this->lines[0].rect.setTop(0);
|
||||
this->lines.back().rect.setBottom(this->height);
|
||||
}
|
||||
}
|
||||
|
||||
MessageLayoutElement *MessageLayoutContainer::getElementAt(QPoint point)
|
||||
|
@ -159,6 +167,53 @@ void MessageLayoutContainer::paintSelection(QPainter &painter, int messageIndex,
|
|||
Selection &selection)
|
||||
{
|
||||
}
|
||||
|
||||
// selection
|
||||
int MessageLayoutContainer::getSelectionIndex(QPoint point)
|
||||
{
|
||||
if (this->elements.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto line = this->lines.begin();
|
||||
|
||||
for (; line != this->lines.end(); line++) {
|
||||
if (line->rect.contains(point)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(line != this->lines.end());
|
||||
|
||||
int lineStart = line->startIndex;
|
||||
line++;
|
||||
int lineEnd = line == this->lines.end() ? this->elements.size() : line->startIndex;
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (int i = 0; i < lineEnd; i++) {
|
||||
// end of line
|
||||
if (i == lineEnd) {
|
||||
break;
|
||||
}
|
||||
|
||||
// before line
|
||||
if (i < lineStart) {
|
||||
index += this->elements[i]->getSelectionIndexCount();
|
||||
continue;
|
||||
}
|
||||
|
||||
// this is the word
|
||||
if (point.x() > this->elements[i]->getRect().left()) {
|
||||
index += this->elements[i]->getMouseOverIndex(point);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << index;
|
||||
|
||||
return index;
|
||||
}
|
||||
} // namespace layouts
|
||||
} // namespace messages
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include <QPoint>
|
||||
#include <QRect>
|
||||
|
||||
class QPainter;
|
||||
|
||||
|
@ -67,6 +68,9 @@ public:
|
|||
void paintAnimatedElements(QPainter &painter, int yOffset);
|
||||
void paintSelection(QPainter &painter, int messageIndex, Selection &selection);
|
||||
|
||||
// selection
|
||||
int getSelectionIndex(QPoint point);
|
||||
|
||||
private:
|
||||
// helpers
|
||||
void _addElement(MessageLayoutElement *element);
|
||||
|
@ -79,6 +83,13 @@ private:
|
|||
int lineHeight = 0;
|
||||
int spaceWidth = 4;
|
||||
std::vector<std::unique_ptr<MessageLayoutElement>> elements;
|
||||
|
||||
struct Line {
|
||||
int startIndex;
|
||||
QRect rect;
|
||||
};
|
||||
|
||||
std::vector<Line> lines;
|
||||
};
|
||||
} // namespace layouts
|
||||
} // namespace messages
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include "widgets/helper/rippleeffectlabel.hpp"
|
||||
|
||||
#define WM_DPICHANGED 0x02E0
|
||||
#endif
|
||||
|
||||
#include "widgets/helper/rippleeffectlabel.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
|
@ -114,7 +115,7 @@ void BaseWindow::init()
|
|||
|
||||
QWidget *BaseWindow::getLayoutContainer()
|
||||
{
|
||||
if (this->enableCustomFrame) {
|
||||
if (this->hasCustomWindowFrame()) {
|
||||
return this->layoutBase;
|
||||
} else {
|
||||
return this;
|
||||
|
|
|
@ -50,11 +50,7 @@ Window::Window(const QString &windowName, singletons::ThemeManager &_themeManage
|
|||
this->getLayoutContainer()->setLayout(layout);
|
||||
|
||||
// set margin
|
||||
// if (SettingsManager::getInstance().useCustomWindowFrame.get()) {
|
||||
// layout->setMargin(1);
|
||||
// } else {
|
||||
layout->setMargin(0);
|
||||
// }
|
||||
|
||||
this->refreshTheme();
|
||||
|
||||
|
|
Loading…
Reference in a new issue