diff --git a/chatterino.pro b/chatterino.pro index 8a5fc489..9cab5091 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -1,167 +1,168 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2016-12-28T18:23:35 -# -#------------------------------------------------- - -QT += core gui network -CONFIG += communi -COMMUNI += core model util -CONFIG += c++14 - -include(lib/libcommuni/src/src.pri) - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -TARGET = chatterino -TEMPLATE = app - -DEFINES += QT_DEPRECATED_WARNINGS -DEFINES += IRC_NAMESPACE=Communi - -# do not use windows min/max macros -win32 { - DEFINES += NOMINMAX -} - -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -SOURCES += main.cpp\ - channel.cpp \ - colorscheme.cpp \ - emojis.cpp \ - ircmanager.cpp \ - messages/lazyloadedimage.cpp \ - messages/link.cpp \ - messages/message.cpp \ - messages/word.cpp \ - messages/wordpart.cpp \ - resources.cpp \ - widgets/chatwidget.cpp \ - widgets/chatwidgetheader.cpp \ - widgets/chatwidgetheaderbutton.cpp \ - widgets/chatwidgetinput.cpp \ - widgets/chatwidgetview.cpp \ - widgets/mainwindow.cpp \ - widgets/notebook.cpp \ - widgets/notebookbutton.cpp \ - widgets/notebookpage.cpp \ - widgets/notebookpagedroppreview.cpp \ - widgets/notebooktab.cpp \ - widgets/scrollbar.cpp \ - widgets/scrollbarhighlight.cpp \ - widgets/settingsdialog.cpp \ - widgets/settingsdialogtab.cpp \ - widgets/textinputdialog.cpp \ - messages/messageref.cpp \ - logging/loggingmanager.cpp \ - logging/loggingchannel.cpp \ - windowmanager.cpp \ - channelmanager.cpp \ - fontmanager.cpp \ - settingsmanager.cpp \ - emotemanager.cpp \ - messages/messagebuilder.cpp \ - twitch/twitchmessagebuilder.cpp \ - twitch/twitchparsemessage.cpp \ - widgets/fancybutton.cpp \ - widgets/titlebar.cpp \ - appdatapath.cpp \ - accountmanager.cpp \ - twitch/twitchaccount.cpp \ - ircaccount.cpp \ - widgets/accountpopup.cpp - -HEADERS += \ - asyncexec.h \ - channel.h \ - colorscheme.h \ - common.h \ - concurrentmap.h \ - emojis.h \ - ircmanager.h \ - messages/lazyloadedimage.h \ - messages/link.h \ - messages/message.h \ - messages/word.h \ - messages/wordpart.h \ - resources.h \ - setting.h \ - twitch/emotevalue.h \ - widgets/chatwidget.h \ - widgets/chatwidgetheader.h \ - widgets/chatwidgetheaderbutton.h \ - widgets/chatwidgetinput.h \ - widgets/chatwidgetview.h \ - widgets/mainwindow.h \ - widgets/notebook.h \ - widgets/notebookbutton.h \ - widgets/notebookpage.h \ - widgets/notebookpagedroppreview.h \ - widgets/notebooktab.h \ - widgets/scrollbar.h \ - widgets/scrollbarhighlight.h \ - widgets/settingsdialog.h \ - widgets/settingsdialogtab.h \ - widgets/signallabel.h \ - widgets/textinputdialog.h \ - widgets/resizingtextedit.h \ - settingssnapshot.h \ - messages/limitedqueue.h \ - messages/limitedqueuesnapshot.h \ - messages/messageref.h \ - logging/loggingmanager.h \ - logging/loggingchannel.h \ - channelmanager.h \ - windowmanager.h \ - settingsmanager.h \ - fontmanager.h \ - emotemanager.h \ - util/urlfetch.h \ - messages/messageparseargs.h \ - messages/messagebuilder.h \ - twitch/twitchmessagebuilder.h \ - twitch/twitchparsemessage.h \ - widgets/fancybutton.h \ - widgets/titlebar.h \ - appdatapath.h \ - accountmanager.h \ - twitch/twitchaccount.h \ - ircaccount.h \ - widgets/accountpopup.h - -PRECOMPILED_HEADER = - -RESOURCES += \ - resources.qrc - -DISTFILES += - -# Include boost -win32 { - INCLUDEPATH += C:\local\boost\ -} - -# Optional dependency on windows sdk 7.1 -win32:exists(C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\Windows.h) { - LIBS += -L"C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib" \ - -ldwmapi \ - -lgdi32 - - SOURCES += platform/borderless/qwinwidget.cpp \ - platform/borderless/winnativewindow.cpp \ - platform/borderless/widget.cpp - - HEADERS += platform/borderless/qwinwidget.h \ - platform/borderless/winnativewindow.h \ - platform/borderless/widget.h - - DEFINES += "USEWINSDK" -} - -macx { - INCLUDEPATH += /usr/local/include -} - -FORMS += \ - forms/accountpopupform.ui +#------------------------------------------------- +# +# Project created by QtCreator 2016-12-28T18:23:35 +# +#------------------------------------------------- + +QT += core gui network +CONFIG += communi +COMMUNI += core model util +CONFIG += c++14 + +include(lib/libcommuni/src/src.pri) + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = chatterino +TEMPLATE = app + +DEFINES += QT_DEPRECATED_WARNINGS +DEFINES += IRC_NAMESPACE=Communi + +# do not use windows min/max macros +win32 { + DEFINES += NOMINMAX +} + +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += main.cpp\ + channel.cpp \ + colorscheme.cpp \ + emojis.cpp \ + ircmanager.cpp \ + messages/lazyloadedimage.cpp \ + messages/link.cpp \ + messages/message.cpp \ + messages/word.cpp \ + messages/wordpart.cpp \ + resources.cpp \ + widgets/chatwidget.cpp \ + widgets/chatwidgetheader.cpp \ + widgets/chatwidgetheaderbutton.cpp \ + widgets/chatwidgetinput.cpp \ + widgets/chatwidgetview.cpp \ + widgets/mainwindow.cpp \ + widgets/notebook.cpp \ + widgets/notebookbutton.cpp \ + widgets/notebookpage.cpp \ + widgets/notebookpagedroppreview.cpp \ + widgets/notebooktab.cpp \ + widgets/scrollbar.cpp \ + widgets/scrollbarhighlight.cpp \ + widgets/settingsdialog.cpp \ + widgets/settingsdialogtab.cpp \ + widgets/textinputdialog.cpp \ + messages/messageref.cpp \ + logging/loggingmanager.cpp \ + logging/loggingchannel.cpp \ + windowmanager.cpp \ + channelmanager.cpp \ + fontmanager.cpp \ + settingsmanager.cpp \ + emotemanager.cpp \ + messages/messagebuilder.cpp \ + twitch/twitchmessagebuilder.cpp \ + twitch/twitchparsemessage.cpp \ + widgets/fancybutton.cpp \ + widgets/titlebar.cpp \ + appdatapath.cpp \ + accountmanager.cpp \ + twitch/twitchaccount.cpp \ + ircaccount.cpp \ + widgets/accountpopup.cpp + +HEADERS += \ + asyncexec.h \ + channel.h \ + colorscheme.h \ + common.h \ + concurrentmap.h \ + emojis.h \ + ircmanager.h \ + messages/lazyloadedimage.h \ + messages/link.h \ + messages/message.h \ + messages/word.h \ + messages/wordpart.h \ + resources.h \ + setting.h \ + twitch/emotevalue.h \ + widgets/chatwidget.h \ + widgets/chatwidgetheader.h \ + widgets/chatwidgetheaderbutton.h \ + widgets/chatwidgetinput.h \ + widgets/chatwidgetview.h \ + widgets/mainwindow.h \ + widgets/notebook.h \ + widgets/notebookbutton.h \ + widgets/notebookpage.h \ + widgets/notebookpagedroppreview.h \ + widgets/notebooktab.h \ + widgets/scrollbar.h \ + widgets/scrollbarhighlight.h \ + widgets/settingsdialog.h \ + widgets/settingsdialogtab.h \ + widgets/signallabel.h \ + widgets/textinputdialog.h \ + widgets/resizingtextedit.h \ + settingssnapshot.h \ + messages/limitedqueue.h \ + messages/limitedqueuesnapshot.h \ + messages/messageref.h \ + logging/loggingmanager.h \ + logging/loggingchannel.h \ + channelmanager.h \ + windowmanager.h \ + settingsmanager.h \ + fontmanager.h \ + emotemanager.h \ + util/urlfetch.h \ + messages/messageparseargs.h \ + messages/messagebuilder.h \ + twitch/twitchmessagebuilder.h \ + twitch/twitchparsemessage.h \ + widgets/fancybutton.h \ + widgets/titlebar.h \ + appdatapath.h \ + accountmanager.h \ + twitch/twitchaccount.h \ + ircaccount.h \ + widgets/accountpopup.h \ + util/distancebetweenpoints.h + +PRECOMPILED_HEADER = + +RESOURCES += \ + resources.qrc + +DISTFILES += + +# Include boost +win32 { + INCLUDEPATH += C:\local\boost\ +} + +# Optional dependency on windows sdk 7.1 +win32:exists(C:\Program Files\Microsoft SDKs\Windows\v7.1\Include\Windows.h) { + LIBS += -L"C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib" \ + -ldwmapi \ + -lgdi32 + + SOURCES += platform/borderless/qwinwidget.cpp \ + platform/borderless/winnativewindow.cpp \ + platform/borderless/widget.cpp + + HEADERS += platform/borderless/qwinwidget.h \ + platform/borderless/winnativewindow.h \ + platform/borderless/widget.h + + DEFINES += "USEWINSDK" +} + +macx { + INCLUDEPATH += /usr/local/include +} + +FORMS += \ + forms/accountpopupform.ui diff --git a/messages/link.h b/messages/link.h index 99dfd7ec..a74b2235 100644 --- a/messages/link.h +++ b/messages/link.h @@ -23,9 +23,9 @@ public: Link(); Link(Type getType, const QString &getValue); - bool getIsValid() const + bool isValid() const { - return type == None; + return type != None; } Type getType() const diff --git a/messages/messageref.cpp b/messages/messageref.cpp index 145bc6d4..0f54912f 100644 --- a/messages/messageref.cpp +++ b/messages/messageref.cpp @@ -94,7 +94,7 @@ bool MessageRef::layout(int width, bool enableEmoteMargins) int x = MARGIN_LEFT; int y = MARGIN_TOP; - int right = width - MARGIN_RIGHT - MARGIN_LEFT; + int right = width - MARGIN_RIGHT; int lineNumber = 0; int lineStart = 0; @@ -258,17 +258,16 @@ int MessageRef::getSelectionIndex(QPoint position) for (int i = 0; i < _wordParts.size(); i++) { WordPart &part = _wordParts[i]; - // return if curser under the word - if (position.y() >= part.getBottom()) { + if (part.getLineNumber() != 0 && position.y() < part.getY()) { break; } if (part.getLineNumber() != lineNumber) { - lineStart = i; + lineStart = i - 1; lineNumber = part.getLineNumber(); } - lineEnd = i; + lineEnd = part.getLineNumber() == 0 ? i : i + 1; } // count up to the cursor @@ -289,7 +288,7 @@ int MessageRef::getSelectionIndex(QPoint position) } // cursor is right of the word part - if (position.x() > part.getX()) { + if (position.x() > part.getX() + part.getWidth()) { index += part.getWord().isImage() ? 2 : part.getText().length() + 1; continue; } @@ -316,26 +315,6 @@ int MessageRef::getSelectionIndex(QPoint position) } return index; - - // go through all the wordparts - // for (int i = 0; i < wordParts; i < wordParts.size()) { - - // WordPart &part = wordParts[i]; - - // // return if curser under the word - // if (position.y() >= part.getBottom()) { - // break; - // } - - // // increment index and continue if the curser x is bigger than the - // words - // // right edge - // if (position.x() > part.getRight()) { - // index += part.getWord().isImage() ? 2 + - // part.getText().length() + 1; - // continue; - // } - // } } } } diff --git a/twitch/twitchmessagebuilder.cpp b/twitch/twitchmessagebuilder.cpp index 0835577d..ace9d233 100644 --- a/twitch/twitchmessagebuilder.cpp +++ b/twitch/twitchmessagebuilder.cpp @@ -134,8 +134,8 @@ SharedMessage TwitchMessageBuilder::parse(const Communi::IrcPrivateMessage *ircM userDisplayString += ": "; } - b.appendWord( - Word(userDisplayString, Word::Username, usernameColor, userDisplayString, QString())); + b.appendWord(Word(userDisplayString, Word::Username, usernameColor, userDisplayString, + QString(), Link(Link::UserInfo, b.userName))); // highlights // TODO: implement this xD diff --git a/util/distancebetweenpoints.h b/util/distancebetweenpoints.h new file mode 100644 index 00000000..f4513d35 --- /dev/null +++ b/util/distancebetweenpoints.h @@ -0,0 +1,22 @@ +#ifndef DISTANCEBETWEENPOINTS_H +#define DISTANCEBETWEENPOINTS_H + +#include + +namespace chatterino { +namespace util { + +static float distanceBetweenPoints(const QPointF &p1, const QPointF &p2) +{ + QPointF tmp = p1 - p2; + + float distance = 0.f; + distance += tmp.x() * tmp.x(); + distance += tmp.y() * tmp.y(); + + return sqrt(distance); +} +} +} + +#endif // DISTANCEBETWEENPOINTS_H diff --git a/widgets/chatwidgetview.cpp b/widgets/chatwidgetview.cpp index c267e89f..467d2569 100644 --- a/widgets/chatwidgetview.cpp +++ b/widgets/chatwidgetview.cpp @@ -5,6 +5,7 @@ #include "messages/wordpart.h" #include "settingsmanager.h" #include "ui_accountpopupform.h" +#include "util/distancebetweenpoints.h" #include "widgets/chatwidget.h" #include @@ -55,6 +56,7 @@ bool ChatWidgetView::layoutMessages() bool showScrollbar = false, redraw = false; int start = _scrollbar.getCurrentValue(); + int layoutWidth = _scrollbar.isVisible() ? width() - _scrollbar.width() : width(); // layout the visible messages in the view if (messages.getSize() > start) { @@ -63,7 +65,7 @@ bool ChatWidgetView::layoutMessages() for (int i = start; i < messages.getSize(); ++i) { auto message = messages[i]; - redraw |= message->layout(width(), true); + redraw |= message->layout(layoutWidth, true); y += message->getHeight(); @@ -79,7 +81,7 @@ bool ChatWidgetView::layoutMessages() for (int i = messages.getSize() - 1; i >= 0; i--) { auto *message = messages[i].get(); - message->layout(width(), true); + message->layout(layoutWidth, true); h -= message->getHeight(); @@ -298,6 +300,9 @@ void ChatWidgetView::mouseMoveEvent(QMouseEvent *event) return; } + int index = message->getSelectionIndex(relativePos); + qDebug() << index; + messages::Word hoverWord; if (!message->tryGetWordPart(relativePos, hoverWord)) { @@ -305,11 +310,7 @@ void ChatWidgetView::mouseMoveEvent(QMouseEvent *event) return; } - int index = message->getSelectionIndex(relativePos); - - qDebug() << index; - - if (hoverWord.getLink().getIsValid()) { + if (hoverWord.getLink().isValid()) { setCursor(Qt::PointingHandCursor); } else { setCursor(Qt::ArrowCursor); @@ -322,17 +323,6 @@ void ChatWidgetView::mousePressEvent(QMouseEvent *event) _lastPressPosition = event->screenPos(); } -static float distanceBetweenPoints(const QPointF &p1, const QPointF &p2) -{ - QPointF tmp = p1 - p2; - - float distance = 0.f; - distance += tmp.x() * tmp.x(); - distance += tmp.y() * tmp.y(); - - return std::sqrt(distance); -} - void ChatWidgetView::mouseReleaseEvent(QMouseEvent *event) { if (!_mouseDown) { @@ -343,7 +333,7 @@ void ChatWidgetView::mouseReleaseEvent(QMouseEvent *event) _mouseDown = false; - float distance = distanceBetweenPoints(_lastPressPosition, event->screenPos()); + float distance = util::distanceBetweenPoints(_lastPressPosition, event->screenPos()); qDebug() << "Distance: " << distance; @@ -366,15 +356,25 @@ void ChatWidgetView::mouseReleaseEvent(QMouseEvent *event) return; } - auto _message = message->getMessage(); - auto user = _message->getUserName(); + messages::Word hoverWord; - qDebug() << "Clicked " << user << "s message"; + if (!message->tryGetWordPart(relativePos, hoverWord)) { + return; + } - _userPopupWidget.setName(user); - _userPopupWidget.move(event->screenPos().toPoint()); - _userPopupWidget.show(); - _userPopupWidget.setFocus(); + auto &link = hoverWord.getLink(); + + switch (link.getType()) { + case messages::Link::UserInfo: + auto user = message->getMessage()->getUserName(); + _userPopupWidget.setName(user); + _userPopupWidget.move(event->screenPos().toPoint()); + _userPopupWidget.show(); + _userPopupWidget.setFocus(); + + qDebug() << "Clicked " << user << "s message"; + break; + } } bool ChatWidgetView::tryGetMessageAt(QPoint p, std::shared_ptr &_message, @@ -388,18 +388,18 @@ bool ChatWidgetView::tryGetMessageAt(QPoint p, std::shared_ptrgetHeight() * (fmod(_scrollbar.getCurrentValue(), 1))) + 12; + int y = -(messages[start]->getHeight() * (fmod(_scrollbar.getCurrentValue(), 1))); for (int i = start; i < messages.getSize(); ++i) { auto message = messages[i]; - y += message->getHeight(); - - if (p.y() < y) { - relativePos = QPoint(p.x(), y - p.y()); + if (p.y() < y + message->getHeight()) { + relativePos = QPoint(p.x(), p.y() - y); _message = message; return true; } + + y += message->getHeight(); } return false;