added search popup

This commit is contained in:
fourtf
2018-01-05 13:42:23 +01:00
parent 02b73cfa27
commit 47a813d5d6
9 changed files with 163 additions and 4 deletions
+1 -1
View File
@@ -26,7 +26,6 @@
#define LAYOUT_WIDTH \
(this->width() - (this->scrollBar.isVisible() ? 16 : 4) * this->getDpiMultiplier())
#define PAUSE_TIME 1000
using namespace chatterino::messages;
@@ -443,6 +442,7 @@ void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
this->channel = newChannel;
this->userPopupWidget.setChannel(newChannel);
this->layoutMessages();
}
void ChannelView::detachChannel()
+87
View File
@@ -0,0 +1,87 @@
#include "searchpopup.hpp"
#include <QHBoxLayout>
#include <QLineEdit>
#include <QVBoxLayout>
#include "channel.hpp"
#include "widgets/helper/channelview.hpp"
namespace chatterino {
namespace widgets {
SearchPopup::SearchPopup()
{
this->initAsWindow();
this->initLayout();
this->resize(400, 600);
}
void SearchPopup::initLayout()
{
// VBOX
{
QVBoxLayout *layout1 = new QVBoxLayout(this);
layout1->setMargin(0);
// HBOX
{
QHBoxLayout *layout2 = new QHBoxLayout(this);
layout2->setMargin(6);
// SEARCH INPUT
{
this->searchInput = new QLineEdit(this);
layout2->addWidget(this->searchInput);
QObject::connect(this->searchInput, &QLineEdit::returnPressed,
[this] { this->performSearch(); });
}
// SEARCH BUTTON
{
QPushButton *searchButton = new QPushButton(this);
searchButton->setText("Search");
layout2->addWidget(searchButton);
QObject::connect(searchButton, &QPushButton::clicked,
[this] { this->performSearch(); });
}
layout1->addLayout(layout2);
}
// CHANNELVIEW
{
this->channelView = new ChannelView(this);
layout1->addWidget(this->channelView);
}
this->setLayout(layout1);
}
}
void SearchPopup::setChannel(std::shared_ptr<Channel> channel)
{
this->snapshot = channel->getMessageSnapshot();
this->performSearch();
this->setWindowTitle("Searching in " + channel->name + "s history");
}
void SearchPopup::performSearch()
{
QString text = searchInput->text();
std::shared_ptr<Channel> channel(new Channel("search"));
for (size_t i = 0; i < this->snapshot.getLength(); i++) {
messages::SharedMessage message = this->snapshot[i];
if (text.isEmpty() || message->getContent().indexOf(this->searchInput->text()) != -1) {
channel->addMessage(message);
}
}
this->channelView->setChannel(channel);
}
}
}
+31
View File
@@ -0,0 +1,31 @@
#pragma once
#include <memory>
#include "messages/limitedqueuesnapshot.hpp"
#include "messages/message.hpp"
#include "widgets/basewidget.hpp"
class QLineEdit;
namespace chatterino {
class Channel;
namespace widgets {
class ChannelView;
class SearchPopup : public BaseWidget
{
public:
SearchPopup();
void setChannel(std::shared_ptr<Channel> channel);
private:
messages::LimitedQueueSnapshot<messages::SharedMessage> snapshot;
QLineEdit *searchInput;
ChannelView *channelView;
void initLayout();
void performSearch();
};
}
}
+12
View File
@@ -5,6 +5,7 @@
#include "singletons/windowmanager.hpp"
#include "twitch/twitchmessagebuilder.hpp"
#include "util/urlfetch.hpp"
#include "widgets/helper/searchpopup.hpp"
#include "widgets/qualitypopup.hpp"
#include "widgets/splitcontainer.hpp"
#include "widgets/textinputdialog.hpp"
@@ -76,6 +77,9 @@ Split::Split(SplitContainer *parent, const std::string &_uuid)
// CTRL+R: Change Channel
ezShortcut(this, "CTRL+R", &Split::doChangeChannel);
// CTRL+F: Search
ezShortcut(this, "CTRL+F", &Split::doSearch);
// xd
// ezShortcut(this, "ALT+SHIFT+RIGHT", &Split::doIncFlexX);
// ezShortcut(this, "ALT+SHIFT+LEFT", &Split::doDecFlexX);
@@ -473,6 +477,14 @@ void Split::doCopy()
QApplication::clipboard()->setText(this->view.getSelectedText());
}
void Split::doSearch()
{
SearchPopup *popup = new SearchPopup();
popup->setChannel(this->getChannel());
popup->show();
}
template <typename Iter, typename RandomGenerator>
static Iter select_randomly(Iter start, Iter end, RandomGenerator &g)
{
+3
View File
@@ -118,6 +118,9 @@ public slots:
// Copy text from chat
void doCopy();
// Open a search popup
void doSearch();
// Open viewer list of the channel
void doOpenViewerList();