improved code style

This commit is contained in:
fourtf 2018-06-13 03:58:52 +02:00
parent 866f868b54
commit ae4cdbd5ab
3 changed files with 42 additions and 39 deletions

View file

@ -13,12 +13,13 @@ If the Project does not build at this point, you might need to add additional Pa
`brew info openssl` `brew info openssl`
`brew info boost` `brew info boost`
If brew doesn't link openssl properly then you should be able to link it yourself using those two commands:
- `ln -s /usr/local/opt/openssl/lib/* /usr/local/lib`
- `ln -s /usr/local/opt/openssl/include/openssl /usr/local/include/openssl`
The lines which you need to add to your project file should look similar to this The lines which you need to add to your project file should look similar to this
``` ```
INCLUDEPATH += /usr/local/opt/openssl/include INCLUDEPATH += /usr/local/opt/openssl/include
LIBS += -L/usr/local/opt/openssl/lib LIBS += -L/usr/local/opt/openssl/lib
INCLUDEPATH += "/usr/local/Cellar/boost/1.67.0_1/include"
LIBS += -L"/usr/local/Cellar/boost/1.67.0_1/lib"
``` ```

View file

@ -27,7 +27,6 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#define LAYOUT_WIDTH (this->width() - (this->scrollBar.isVisible() ? 16 : 2) * this->getScale())
#define DRAW_WIDTH (this->width()) #define DRAW_WIDTH (this->width())
#define SELECTION_RESUME_SCROLLING_MSG_THRESHOLD 3 #define SELECTION_RESUME_SCROLLING_MSG_THRESHOLD 3
#define CHAT_HOVER_PAUSE_DURATION 400 #define CHAT_HOVER_PAUSE_DURATION 400
@ -46,7 +45,7 @@ ChannelView::ChannelView(BaseWidget *parent)
this->setMouseTracking(true); this->setMouseTracking(true);
this->managedConnections.emplace_back(app->settings->wordFlagsChanged.connect([this] { this->connections_.emplace_back(app->settings->wordFlagsChanged.connect([this] {
this->layoutMessages(); this->layoutMessages();
this->update(); this->update();
})); }));
@ -64,25 +63,26 @@ ChannelView::ChannelView(BaseWidget *parent)
this->queueUpdate(); this->queueUpdate();
}); });
this->repaintGifsConnection = app->windows->repaintGifs.connect([&] { this->connections_.push_back(app->windows->repaintGifs.connect([&] {
this->queueUpdate(); // this->queueUpdate(); //
}); }));
this->layoutConnection = app->windows->layout.connect([&](Channel *channel) {
this->connections_.push_back(app->windows->layout.connect([&](Channel *channel) {
if (channel == nullptr || this->channel.get() == channel) { if (channel == nullptr || this->channel.get() == channel) {
this->layoutMessages(); this->layoutMessages();
} }
}); }));
this->goToBottom = new RippleEffectLabel(this, 0); this->goToBottom = new RippleEffectLabel(this, 0);
this->goToBottom->setStyleSheet("background-color: rgba(0,0,0,0.66); color: #FFF;"); this->goToBottom->setStyleSheet("background-color: rgba(0,0,0,0.66); color: #FFF;");
this->goToBottom->getLabel().setText("More messages below"); this->goToBottom->getLabel().setText("More messages below");
this->goToBottom->setVisible(false); this->goToBottom->setVisible(false);
this->managedConnections.emplace_back(app->fonts->fontChanged.connect([this] { this->connections_.emplace_back(app->fonts->fontChanged.connect([this] {
this->layoutMessages(); // this->layoutMessages(); //
})); }));
connect(goToBottom, &RippleEffectLabel::clicked, this, [=] { QObject::connect(goToBottom, &RippleEffectLabel::clicked, this, [=] {
QTimer::singleShot(180, [=] { QTimer::singleShot(180, [=] {
this->scrollBar.scrollToBottom( this->scrollBar.scrollToBottom(
app->settings->enableSmoothScrollingNewMessages.getValue()); app->settings->enableSmoothScrollingNewMessages.getValue());
@ -109,7 +109,7 @@ ChannelView::ChannelView(BaseWidget *parent)
[this](auto, auto) { [this](auto, auto) {
this->update(); // this->update(); //
}, },
this->managedConnections); this->connections_);
this->layoutCooldown = new QTimer(this); this->layoutCooldown = new QTimer(this);
this->layoutCooldown->setSingleShot(true); this->layoutCooldown->setSingleShot(true);
@ -134,12 +134,6 @@ ChannelView::ChannelView(BaseWidget *parent)
ChannelView::~ChannelView() ChannelView::~ChannelView()
{ {
this->messageAppendedConnection.disconnect();
this->messageRemovedConnection.disconnect();
this->repaintGifsConnection.disconnect();
this->layoutConnection.disconnect();
this->messageAddedAtStartConnection.disconnect();
this->messageReplacedConnection.disconnect();
} }
void ChannelView::themeRefreshEvent() void ChannelView::themeRefreshEvent()
@ -199,7 +193,7 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar)
size_t start = this->scrollBar.getCurrentValue(); size_t start = this->scrollBar.getCurrentValue();
// int layoutWidth = // int layoutWidth =
// (this->scrollBar.isVisible() ? width() - this->scrollBar.width() : width()) - 4; // (this->scrollBar.isVisible() ? width() - this->scrollBar.width() : width()) - 4;
int layoutWidth = LAYOUT_WIDTH; int layoutWidth = this->getLayoutWidth();
MessageElement::Flags flags = this->getFlags(); MessageElement::Flags flags = this->getFlags();
@ -365,7 +359,7 @@ void ChannelView::setChannel(ChannelPtr newChannel)
this->messages.clear(); this->messages.clear();
// on new message // on new message
this->messageAppendedConnection = this->channelConnections_.push_back(
newChannel->messageAppended.connect([this](MessagePtr &message) { newChannel->messageAppended.connect([this](MessagePtr &message) {
MessageLayoutPtr deleted; MessageLayoutPtr deleted;
@ -402,9 +396,9 @@ void ChannelView::setChannel(ChannelPtr newChannel)
this->messageWasAdded = true; this->messageWasAdded = true;
this->layoutMessages(); this->layoutMessages();
}); }));
this->messageAddedAtStartConnection = this->channelConnections_.push_back(
newChannel->messagesAddedAtStart.connect([this](std::vector<MessagePtr> &messages) { newChannel->messagesAddedAtStart.connect([this](std::vector<MessagePtr> &messages) {
std::vector<MessageLayoutPtr> messageRefs; std::vector<MessageLayoutPtr> messageRefs;
messageRefs.resize(messages.size()); messageRefs.resize(messages.size());
@ -432,10 +426,10 @@ void ChannelView::setChannel(ChannelPtr newChannel)
this->messageWasAdded = true; this->messageWasAdded = true;
this->layoutMessages(); this->layoutMessages();
}); }));
// on message removed // on message removed
this->messageRemovedConnection = this->channelConnections_.push_back(
newChannel->messageRemovedFromStart.connect([this](MessagePtr &) { newChannel->messageRemovedFromStart.connect([this](MessagePtr &) {
this->selection.selectionMin.messageIndex--; this->selection.selectionMin.messageIndex--;
this->selection.selectionMax.messageIndex--; this->selection.selectionMax.messageIndex--;
@ -443,10 +437,10 @@ void ChannelView::setChannel(ChannelPtr newChannel)
this->selection.end.messageIndex--; this->selection.end.messageIndex--;
this->layoutMessages(); this->layoutMessages();
}); }));
// on message replaced // on message replaced
this->messageReplacedConnection = this->channelConnections_.push_back(
newChannel->messageReplaced.connect([this](size_t index, MessagePtr replacement) { newChannel->messageReplaced.connect([this](size_t index, MessagePtr replacement) {
MessageLayoutPtr newItem(new MessageLayout(replacement)); MessageLayoutPtr newItem(new MessageLayout(replacement));
if (this->messages.getSnapshot()[index]->flags & MessageLayout::AlternateBackground) { if (this->messages.getSnapshot()[index]->flags & MessageLayout::AlternateBackground) {
@ -457,7 +451,7 @@ void ChannelView::setChannel(ChannelPtr newChannel)
this->messages.replaceItem(this->messages.getSnapshot()[index], newItem); this->messages.replaceItem(this->messages.getSnapshot()[index], newItem);
this->layoutMessages(); this->layoutMessages();
}); }));
auto snapshot = newChannel->getMessageSnapshot(); auto snapshot = newChannel->getMessageSnapshot();
@ -482,10 +476,7 @@ void ChannelView::setChannel(ChannelPtr newChannel)
void ChannelView::detachChannel() void ChannelView::detachChannel()
{ {
messageAppendedConnection.disconnect(); this->channelConnections_.clear();
messageAddedAtStartConnection.disconnect();
messageRemovedConnection.disconnect();
messageReplacedConnection.disconnect();
} }
void ChannelView::pause(int msecTimeout) void ChannelView::pause(int msecTimeout)
@ -696,7 +687,8 @@ void ChannelView::wheelEvent(QWheelEvent *event)
if (i == 0) { if (i == 0) {
desired = 0; desired = 0;
} else { } else {
snapshot[i - 1]->layout(LAYOUT_WIDTH, this->getScale(), this->getFlags()); snapshot[i - 1]->layout(this->getLayoutWidth(), this->getScale(),
this->getFlags());
scrollFactor = 1; scrollFactor = 1;
currentScrollLeft = snapshot[i - 1]->getHeight(); currentScrollLeft = snapshot[i - 1]->getHeight();
} }
@ -718,7 +710,8 @@ void ChannelView::wheelEvent(QWheelEvent *event)
if (i == snapshotLength - 1) { if (i == snapshotLength - 1) {
desired = snapshot.getLength(); desired = snapshot.getLength();
} else { } else {
snapshot[i + 1]->layout(LAYOUT_WIDTH, this->getScale(), this->getFlags()); snapshot[i + 1]->layout(this->getLayoutWidth(), this->getScale(),
this->getFlags());
scrollFactor = 1; scrollFactor = 1;
currentScrollLeft = snapshot[i + 1]->getHeight(); currentScrollLeft = snapshot[i + 1]->getHeight();
@ -985,9 +978,9 @@ void ChannelView::addContextMenuItems(const messages::MessageLayoutElement *hove
// TODO: We might want to add direct "Open image" variants alongside the Copy // TODO: We might want to add direct "Open image" variants alongside the Copy
// actions // actions
if (emoteElement.data.image1x != nullptr) { if (emoteElement.data.image1x != nullptr) {
QAction* addEntry = menu->addAction("Copy emote link..."); QAction *addEntry = menu->addAction("Copy emote link...");
QMenu* procmenu = new QMenu; QMenu *procmenu = new QMenu;
addEntry->setMenu(procmenu); addEntry->setMenu(procmenu);
procmenu->addAction("Copy 1x link", [url = emoteElement.data.image1x->getUrl()] { procmenu->addAction("Copy 1x link", [url = emoteElement.data.image1x->getUrl()] {
QApplication::clipboard()->setText(url); // QApplication::clipboard()->setText(url); //
@ -1017,9 +1010,9 @@ void ChannelView::addContextMenuItems(const messages::MessageLayoutElement *hove
} }
} }
if (emoteElement.data.image1x != nullptr) { if (emoteElement.data.image1x != nullptr) {
QAction* addEntry = menu->addAction("Open emote link..."); QAction *addEntry = menu->addAction("Open emote link...");
QMenu* procmenu = new QMenu; QMenu *procmenu = new QMenu;
addEntry->setMenu(procmenu); addEntry->setMenu(procmenu);
procmenu->addAction("Open 1x link", [url = emoteElement.data.image1x->getUrl()] { procmenu->addAction("Open 1x link", [url = emoteElement.data.image1x->getUrl()] {
QDesktopServices::openUrl(QUrl(url)); // QDesktopServices::openUrl(QUrl(url)); //
@ -1200,5 +1193,13 @@ bool ChannelView::tryGetMessageAt(QPoint p, std::shared_ptr<messages::MessageLay
return false; return false;
} }
int ChannelView::getLayoutWidth() const
{
if (this->scrollBar.isVisible())
return int(this->width() - 8 * this->getScale());
return this->width();
}
} // namespace widgets } // namespace widgets
} // namespace chatterino } // namespace chatterino

View file

@ -89,6 +89,7 @@ private:
bool pausedTemporarily = false; bool pausedTemporarily = false;
bool pausedBySelection = false; bool pausedBySelection = false;
int messagesAddedSinceSelectionPause = 0; int messagesAddedSinceSelectionPause = 0;
int getLayoutWidth() const;
QTimer pauseTimeout; QTimer pauseTimeout;
boost::optional<messages::MessageElement::Flags> overrideFlags; boost::optional<messages::MessageElement::Flags> overrideFlags;
@ -143,8 +144,8 @@ private:
pajlada::Signals::Connection repaintGifsConnection; pajlada::Signals::Connection repaintGifsConnection;
pajlada::Signals::Connection layoutConnection; pajlada::Signals::Connection layoutConnection;
std::vector<pajlada::Signals::ScopedConnection> managedConnections; std::vector<pajlada::Signals::ScopedConnection> connections_;
std::vector<pajlada::Signals::ScopedConnection> channelConnections; std::vector<pajlada::Signals::ScopedConnection> channelConnections_;
std::unordered_set<std::shared_ptr<messages::MessageLayout>> messagesOnScreen; std::unordered_set<std::shared_ptr<messages::MessageLayout>> messagesOnScreen;