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

View file

@ -114,7 +114,8 @@ SOURCES += \
src/singletons/helper/completionmodel.cpp \ src/singletons/helper/completionmodel.cpp \
src/singletons/resourcemanager.cpp \ src/singletons/resourcemanager.cpp \
src/singletons/helper/ircmessagehandler.cpp \ src/singletons/helper/ircmessagehandler.cpp \
src/singletons/pathmanager.cpp src/singletons/pathmanager.cpp \
src/widgets/helper/searchpopup.cpp
HEADERS += \ HEADERS += \
src/precompiled_headers.hpp \ src/precompiled_headers.hpp \
@ -198,7 +199,8 @@ HEADERS += \
src/util/serialize-custom.hpp \ src/util/serialize-custom.hpp \
src/messages/highlightphrase.hpp \ src/messages/highlightphrase.hpp \
src/messages/selection.hpp \ src/messages/selection.hpp \
src/singletons/pathmanager.hpp src/singletons/pathmanager.hpp \
src/widgets/helper/searchpopup.hpp
PRECOMPILED_HEADER = PRECOMPILED_HEADER =

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <cassert>
#include <memory> #include <memory>
#include <vector> #include <vector>

View file

@ -38,6 +38,10 @@ int Message::getTimeoutCount() const
const QString &Message::getContent() const const QString &Message::getContent() const
{ {
if (this->content.isNull()) {
this->updateContent();
}
return this->content; return this->content;
} }
@ -86,6 +90,24 @@ void Message::setDisableCompactEmotes(bool value)
this->disableCompactEmotes = value; this->disableCompactEmotes = value;
} }
void Message::updateContent() const
{
QString _content("");
bool first;
for (const Word &word : this->words) {
if (!first) {
_content += "";
}
_content += word.getCopyText();
first = false;
}
this->content = _content;
}
namespace { namespace {
void AddCurrentTimestamp(Message *message) void AddCurrentTimestamp(Message *message)

View file

@ -32,6 +32,7 @@ public:
void setCollapsedDefault(bool value); void setCollapsedDefault(bool value);
bool getDisableCompactEmotes() const; bool getDisableCompactEmotes() const;
void setDisableCompactEmotes(bool value); void setDisableCompactEmotes(bool value);
void updateContent() const;
QString loginName; QString loginName;
QString displayName; QString displayName;
@ -68,7 +69,7 @@ private:
std::chrono::time_point<std::chrono::system_clock> parseTime; std::chrono::time_point<std::chrono::system_clock> parseTime;
QString content; mutable QString content;
QString id = ""; QString id = "";
std::vector<Word> words; std::vector<Word> words;

View file

@ -26,7 +26,6 @@
#define LAYOUT_WIDTH \ #define LAYOUT_WIDTH \
(this->width() - (this->scrollBar.isVisible() ? 16 : 4) * this->getDpiMultiplier()) (this->width() - (this->scrollBar.isVisible() ? 16 : 4) * this->getDpiMultiplier())
#define PAUSE_TIME 1000
using namespace chatterino::messages; using namespace chatterino::messages;
@ -443,6 +442,7 @@ void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
this->channel = newChannel; this->channel = newChannel;
this->userPopupWidget.setChannel(newChannel); this->userPopupWidget.setChannel(newChannel);
this->layoutMessages();
} }
void ChannelView::detachChannel() void ChannelView::detachChannel()

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);
}
}
}

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();
};
}
}

View file

@ -5,6 +5,7 @@
#include "singletons/windowmanager.hpp" #include "singletons/windowmanager.hpp"
#include "twitch/twitchmessagebuilder.hpp" #include "twitch/twitchmessagebuilder.hpp"
#include "util/urlfetch.hpp" #include "util/urlfetch.hpp"
#include "widgets/helper/searchpopup.hpp"
#include "widgets/qualitypopup.hpp" #include "widgets/qualitypopup.hpp"
#include "widgets/splitcontainer.hpp" #include "widgets/splitcontainer.hpp"
#include "widgets/textinputdialog.hpp" #include "widgets/textinputdialog.hpp"
@ -76,6 +77,9 @@ Split::Split(SplitContainer *parent, const std::string &_uuid)
// CTRL+R: Change Channel // CTRL+R: Change Channel
ezShortcut(this, "CTRL+R", &Split::doChangeChannel); ezShortcut(this, "CTRL+R", &Split::doChangeChannel);
// CTRL+F: Search
ezShortcut(this, "CTRL+F", &Split::doSearch);
// xd // xd
// ezShortcut(this, "ALT+SHIFT+RIGHT", &Split::doIncFlexX); // ezShortcut(this, "ALT+SHIFT+RIGHT", &Split::doIncFlexX);
// ezShortcut(this, "ALT+SHIFT+LEFT", &Split::doDecFlexX); // ezShortcut(this, "ALT+SHIFT+LEFT", &Split::doDecFlexX);
@ -473,6 +477,14 @@ void Split::doCopy()
QApplication::clipboard()->setText(this->view.getSelectedText()); QApplication::clipboard()->setText(this->view.getSelectedText());
} }
void Split::doSearch()
{
SearchPopup *popup = new SearchPopup();
popup->setChannel(this->getChannel());
popup->show();
}
template <typename Iter, typename RandomGenerator> template <typename Iter, typename RandomGenerator>
static Iter select_randomly(Iter start, Iter end, RandomGenerator &g) static Iter select_randomly(Iter start, Iter end, RandomGenerator &g)
{ {

View file

@ -118,6 +118,9 @@ public slots:
// Copy text from chat // Copy text from chat
void doCopy(); void doCopy();
// Open a search popup
void doSearch();
// Open viewer list of the channel // Open viewer list of the channel
void doOpenViewerList(); void doOpenViewerList();