mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
ab42a30108
* change dotted last read message indicator to a line, remove airbrushgrenade * sort emotes in tab completion * implement tabbing usernames * FeelsOkayMan * fix emotes and usernames comparing; formatting * remove private/personal stuff * change lastmessageindicator back to default verpattern
86 lines
2.2 KiB
C++
86 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include <QAbstractListModel>
|
|
#include <set>
|
|
|
|
#include <map>
|
|
#include <string>
|
|
|
|
#include "common.hpp"
|
|
|
|
namespace chatterino {
|
|
namespace singletons {
|
|
class CompletionModel : public QAbstractListModel
|
|
{
|
|
public:
|
|
CompletionModel(const QString &_channelName);
|
|
|
|
virtual int columnCount(const QModelIndex &) const override
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
virtual QVariant data(const QModelIndex &index, int) const override
|
|
{
|
|
// TODO: Implement more safely
|
|
auto it = this->emotes.begin();
|
|
std::advance(it, index.row());
|
|
return QVariant(it->str);
|
|
}
|
|
|
|
virtual int rowCount(const QModelIndex &) const override
|
|
{
|
|
return this->emotes.size();
|
|
}
|
|
|
|
void refresh();
|
|
void addString(const std::string &str);
|
|
void addString(const QString &str);
|
|
|
|
void addUser(const QString &str);
|
|
|
|
private:
|
|
struct TaggedString {
|
|
QString str;
|
|
// emote == true
|
|
// username == false
|
|
bool isEmote = true;
|
|
bool operator<(const TaggedString &that) const
|
|
{
|
|
if (this->isEmote) {
|
|
if (that.isEmote) {
|
|
int k = QString::compare(this->str, that.str, Qt::CaseInsensitive);
|
|
if (k == 0) return this->str > that.str;
|
|
else return k < 0;
|
|
} else
|
|
return true;
|
|
} else {
|
|
if (that.isEmote)
|
|
return false;
|
|
else {
|
|
int k = QString::compare(this->str, that.str, Qt::CaseInsensitive);;
|
|
if (k == 0) return this->str > that.str;
|
|
else return k < 0;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
TaggedString createEmote(const std::string &str)
|
|
{
|
|
return TaggedString{qS(str), true};
|
|
}
|
|
TaggedString createEmote(const QString &str)
|
|
{
|
|
return TaggedString{str, true};
|
|
}
|
|
TaggedString createUser(const QString &str)
|
|
{
|
|
return TaggedString{str, false};
|
|
}
|
|
std::set<TaggedString> emotes;
|
|
|
|
QString channelName;
|
|
};
|
|
} // namespace singletons
|
|
} // namespace chatterino
|