mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
fixed issues for gcc
This commit is contained in:
parent
d078ef5fe0
commit
ea7fcf260c
|
@ -183,7 +183,6 @@ SOURCES += \
|
||||||
src/singletons/updatemanager.cpp \
|
src/singletons/updatemanager.cpp \
|
||||||
src/widgets/lastruncrashdialog.cpp \
|
src/widgets/lastruncrashdialog.cpp \
|
||||||
src/widgets/attachedwindow.cpp \
|
src/widgets/attachedwindow.cpp \
|
||||||
src/util/tupletablemodel.cpp \
|
|
||||||
src/widgets/settingspages/externaltoolspage.cpp
|
src/widgets/settingspages/externaltoolspage.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
@ -310,7 +309,6 @@ HEADERS += \
|
||||||
src/singletons/updatemanager.hpp \
|
src/singletons/updatemanager.hpp \
|
||||||
src/widgets/lastruncrashdialog.hpp \
|
src/widgets/lastruncrashdialog.hpp \
|
||||||
src/widgets/attachedwindow.hpp \
|
src/widgets/attachedwindow.hpp \
|
||||||
src/util/tupletablemodel.hpp \
|
|
||||||
src/widgets/settingspages/externaltoolspage.hpp \
|
src/widgets/settingspages/externaltoolspage.hpp \
|
||||||
src/util/removescrollareabackground.hpp \
|
src/util/removescrollareabackground.hpp \
|
||||||
src/util/assertinguithread.h
|
src/util/assertinguithread.h
|
||||||
|
|
|
@ -161,10 +161,12 @@ void NativeMessagingManager::ReceiverThread::handleMessage(const QJsonObject &ro
|
||||||
ts.watchingChannel.update(ts.getOrAddChannel(name));
|
ts.watchingChannel.update(ts.getOrAddChannel(name));
|
||||||
|
|
||||||
if (attach) {
|
if (attach) {
|
||||||
|
#ifdef USEWINSDK
|
||||||
auto *window =
|
auto *window =
|
||||||
widgets::AttachedWindow::get(::GetForegroundWindow(), winId, yOffset);
|
widgets::AttachedWindow::get(::GetForegroundWindow(), winId, yOffset);
|
||||||
window->setChannel(ts.getOrAddChannel(name));
|
window->setChannel(ts.getOrAddChannel(name));
|
||||||
window->show();
|
window->show();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -179,7 +181,9 @@ void NativeMessagingManager::ReceiverThread::handleMessage(const QJsonObject &ro
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USEWINSDK
|
||||||
util::postToThread([winId] { widgets::AttachedWindow::detach(winId); });
|
util::postToThread([winId] { widgets::AttachedWindow::detach(winId); });
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "NM unknown action " + action;
|
qDebug() << "NM unknown action " + action;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
#include "tupletablemodel.hpp"
|
|
||||||
|
|
||||||
namespace chatterino {
|
|
||||||
namespace util {
|
|
||||||
|
|
||||||
} // namespace util
|
|
||||||
} // namespace chatterino
|
|
|
@ -1,211 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <QAbstractTableModel>
|
|
||||||
|
|
||||||
#include <pajlada/signals/signal.hpp>
|
|
||||||
|
|
||||||
namespace chatterino {
|
|
||||||
namespace util {
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
template <int I>
|
|
||||||
struct TupleConverter {
|
|
||||||
template <typename... Args>
|
|
||||||
static void tupleToVariants(const std::tuple<Args...> &t, std::vector<QVariant> &row)
|
|
||||||
{
|
|
||||||
row[I - 1] = QVariant(std::get<I - 1>(t));
|
|
||||||
TupleConverter<I - 1>::tupleToVariants<Args...>(t, row);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
static void variantsToTuple(std::vector<QVariant> &row, std::tuple<Args...> &t)
|
|
||||||
{
|
|
||||||
std::get<I - 1>(t) = (decltype(std::get<I - 1>(t))) row[I - 1];
|
|
||||||
TupleConverter<I - 1>::variantsToTuple<Args...>(row, t);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct TupleConverter<0> {
|
|
||||||
template <typename... Args>
|
|
||||||
static void tupleToVariants(const std::tuple<Args...> &t, std::vector<QVariant> &row)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
static void variantsToTuple(std::vector<QVariant> &row, std::tuple<Args...> &t)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
template <typename... Args>
|
|
||||||
class TupleTableModel : public QAbstractTableModel
|
|
||||||
{
|
|
||||||
std::vector<std::vector<QVariant>> rows;
|
|
||||||
std::vector<QMap<int, QVariant>> titleData;
|
|
||||||
|
|
||||||
public:
|
|
||||||
pajlada::Signals::NoArgSignal itemsChanged;
|
|
||||||
|
|
||||||
TupleTableModel()
|
|
||||||
{
|
|
||||||
titleData.resize(sizeof...(Args));
|
|
||||||
}
|
|
||||||
|
|
||||||
void addRow(const std::tuple<Args...> &row)
|
|
||||||
{
|
|
||||||
this->beginInsertRows(QModelIndex(), this->rows.size(), this->rows.size());
|
|
||||||
std::vector<QVariant> variants;
|
|
||||||
variants.resize(sizeof...(Args));
|
|
||||||
TupleConverter<sizeof...(Args)>::tupleToVariants<Args...>(row, variants);
|
|
||||||
this->rows.push_back(variants);
|
|
||||||
this->endInsertRows();
|
|
||||||
this->itemsChanged.invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
void addRow(Args... args)
|
|
||||||
{
|
|
||||||
this->beginInsertRows(QModelIndex(), this->rows.size(), this->rows.size());
|
|
||||||
std::vector<QVariant> variants;
|
|
||||||
variants.resize(sizeof...(Args));
|
|
||||||
TupleConverter<sizeof...(Args)>::tupleToVariants<Args...>(std::tuple<Args...>(args...),
|
|
||||||
variants);
|
|
||||||
this->rows.push_back(variants);
|
|
||||||
this->endInsertRows();
|
|
||||||
this->itemsChanged.invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::tuple<Args...> getRow(int index)
|
|
||||||
{
|
|
||||||
std::tuple<Args...> row;
|
|
||||||
TupleConverter<sizeof...(Args)>::variantsToTuple<Args...>(this->rows[index], row);
|
|
||||||
return row;
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeRow(int index)
|
|
||||||
{
|
|
||||||
this->beginRemoveRows(QModelIndex(), index, index);
|
|
||||||
this->rows.erase(this->rows.begin() + index);
|
|
||||||
this->endRemoveRows();
|
|
||||||
this->itemsChanged.invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setTitles(std::initializer_list<QString> titles)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
for (const QString &title : titles) {
|
|
||||||
this->setHeaderData(i++, Qt::Horizontal, title, Qt::DisplayRole);
|
|
||||||
|
|
||||||
if (i >= sizeof...(Args))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int getRowCount() const
|
|
||||||
{
|
|
||||||
return this->rows.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override
|
|
||||||
{
|
|
||||||
return this->rows.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override
|
|
||||||
{
|
|
||||||
return sizeof...(Args);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
|
|
||||||
{
|
|
||||||
QVariant data = this->rows[index.row()][index.column()];
|
|
||||||
|
|
||||||
switch (role) {
|
|
||||||
case Qt::DisplayRole: {
|
|
||||||
if (data.type() == QVariant::Bool)
|
|
||||||
return QVariant();
|
|
||||||
else
|
|
||||||
return data;
|
|
||||||
} break;
|
|
||||||
case Qt::EditRole: {
|
|
||||||
return data;
|
|
||||||
} break;
|
|
||||||
case Qt::CheckStateRole: {
|
|
||||||
if (data.type() == QVariant::Bool)
|
|
||||||
return data;
|
|
||||||
else
|
|
||||||
return QVariant();
|
|
||||||
} break;
|
|
||||||
}
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool setData(const QModelIndex &index, const QVariant &value,
|
|
||||||
int role = Qt::EditRole) override
|
|
||||||
{
|
|
||||||
QVariant data = this->rows[index.row()][index.column()];
|
|
||||||
|
|
||||||
switch (role) {
|
|
||||||
case (Qt::EditRole): {
|
|
||||||
this->rows[index.row()][index.column()] = value;
|
|
||||||
this->itemsChanged.invoke();
|
|
||||||
return true;
|
|
||||||
} break;
|
|
||||||
case (Qt::CheckStateRole): {
|
|
||||||
if (data.type() == QVariant::Bool) {
|
|
||||||
this->rows[index.row()][index.column()] = !data.toBool();
|
|
||||||
this->itemsChanged.invoke();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
|
|
||||||
{
|
|
||||||
if (orientation != Qt::Horizontal)
|
|
||||||
return QVariant();
|
|
||||||
if (section < 0 || section >= sizeof...(Args))
|
|
||||||
return QVariant();
|
|
||||||
|
|
||||||
auto it = this->titleData[section].find(role);
|
|
||||||
return it == this->titleData[section].end() ? QVariant() : it.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
|
|
||||||
int role)
|
|
||||||
{
|
|
||||||
if (orientation != Qt::Horizontal)
|
|
||||||
return false;
|
|
||||||
if (section < 0 || section >= sizeof...(Args))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
this->titleData[section][role] = value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
QVariant data = this->rows[index.row()][index.column()];
|
|
||||||
|
|
||||||
if (data.type() == QVariant::Bool) {
|
|
||||||
return Qt::ItemIsUserCheckable | Qt::ItemIsEditable | Qt::ItemIsEnabled |
|
|
||||||
Qt::ItemIsSelectable;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace util
|
|
||||||
} // namespace chatterino
|
|
|
@ -5,8 +5,10 @@
|
||||||
|
|
||||||
#include "widgets/split.hpp"
|
#include "widgets/split.hpp"
|
||||||
|
|
||||||
|
#ifdef USEWINSDK
|
||||||
#include "Windows.h"
|
#include "Windows.h"
|
||||||
#pragma comment(lib, "Dwmapi.lib")
|
#pragma comment(lib, "Dwmapi.lib")
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace widgets {
|
namespace widgets {
|
||||||
|
@ -70,6 +72,7 @@ void AttachedWindow::showEvent(QShowEvent *)
|
||||||
|
|
||||||
void AttachedWindow::attachToHwnd(void *_hwnd)
|
void AttachedWindow::attachToHwnd(void *_hwnd)
|
||||||
{
|
{
|
||||||
|
#ifdef USEWINSDK
|
||||||
QTimer *timer = new QTimer(this);
|
QTimer *timer = new QTimer(this);
|
||||||
timer->setInterval(1);
|
timer->setInterval(1);
|
||||||
|
|
||||||
|
@ -96,6 +99,7 @@ void AttachedWindow::attachToHwnd(void *_hwnd)
|
||||||
// false);
|
// false);
|
||||||
});
|
});
|
||||||
timer->start();
|
timer->start();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// void AttachedWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
// void AttachedWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QStandardItemModel>
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
@ -10,7 +11,6 @@
|
||||||
#include "debug/log.hpp"
|
#include "debug/log.hpp"
|
||||||
#include "singletons/settingsmanager.hpp"
|
#include "singletons/settingsmanager.hpp"
|
||||||
#include "util/layoutcreator.hpp"
|
#include "util/layoutcreator.hpp"
|
||||||
#include "util/tupletablemodel.hpp"
|
|
||||||
|
|
||||||
#define ENABLE_HIGHLIGHTS "Enable Highlighting"
|
#define ENABLE_HIGHLIGHTS "Enable Highlighting"
|
||||||
#define HIGHLIGHT_MSG "Highlight messages containing your name"
|
#define HIGHLIGHT_MSG "Highlight messages containing your name"
|
||||||
|
@ -57,13 +57,23 @@ HighlightingPage::HighlightingPage()
|
||||||
auto highlights = tabs.appendTab(new QVBoxLayout, "Highlights");
|
auto highlights = tabs.appendTab(new QVBoxLayout, "Highlights");
|
||||||
{
|
{
|
||||||
QTableView *view = *highlights.emplace<QTableView>();
|
QTableView *view = *highlights.emplace<QTableView>();
|
||||||
auto *model = new util::TupleTableModel<QString, bool, bool, bool>;
|
auto *model = new QStandardItemModel(0, 4, view);
|
||||||
model->setTitles({"Pattern", "Flash taskbar", "Play sound", "Regex"});
|
// model->setTitles({"Pattern", "Flash taskbar", "Play sound", "Regex"});
|
||||||
|
|
||||||
// fourtf: could crash
|
// fourtf: could crash
|
||||||
for (const messages::HighlightPhrase &phrase :
|
for (const messages::HighlightPhrase &phrase :
|
||||||
settings.highlightProperties.getValue()) {
|
settings.highlightProperties.getValue()) {
|
||||||
model->addRow(phrase.key, phrase.alert, phrase.sound, phrase.regex);
|
auto *item1 = new QStandardItem(phrase.key);
|
||||||
|
auto *item2 = new QStandardItem();
|
||||||
|
item2->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
|
||||||
|
item2->setData(phrase.alert, Qt::CheckStateRole);
|
||||||
|
auto *item3 = new QStandardItem();
|
||||||
|
item3->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
|
||||||
|
item3->setData(phrase.sound, Qt::CheckStateRole);
|
||||||
|
auto *item4 = new QStandardItem();
|
||||||
|
item4->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
|
||||||
|
item4->setData(phrase.regex, Qt::CheckStateRole);
|
||||||
|
model->appendRow({item1, item2, item3, item4});
|
||||||
}
|
}
|
||||||
|
|
||||||
view->setModel(model);
|
view->setModel(model);
|
||||||
|
@ -79,20 +89,36 @@ HighlightingPage::HighlightingPage()
|
||||||
|
|
||||||
auto buttons = highlights.emplace<QHBoxLayout>();
|
auto buttons = highlights.emplace<QHBoxLayout>();
|
||||||
|
|
||||||
model->itemsChanged.connect([model] {
|
QObject::connect(
|
||||||
|
model, &QStandardItemModel::dataChanged,
|
||||||
|
[model](const QModelIndex &topLeft, const QModelIndex &bottomRight,
|
||||||
|
const QVector<int> &roles) {
|
||||||
std::vector<messages::HighlightPhrase> phrases;
|
std::vector<messages::HighlightPhrase> phrases;
|
||||||
for (int i = 0; i < model->getRowCount(); i++) {
|
for (int i = 0; i < model->rowCount(); i++) {
|
||||||
auto t = model->getRow(i);
|
|
||||||
phrases.push_back(messages::HighlightPhrase{
|
phrases.push_back(messages::HighlightPhrase{
|
||||||
std::get<0>(t), std::get<1>(t), std::get<2>(t), std::get<3>(t),
|
model->item(i, 0)->data(Qt::DisplayRole).toString(),
|
||||||
});
|
model->item(i, 1)->data(Qt::CheckStateRole).toBool(),
|
||||||
|
model->item(i, 2)->data(Qt::CheckStateRole).toBool(),
|
||||||
|
model->item(i, 3)->data(Qt::CheckStateRole).toBool()});
|
||||||
}
|
}
|
||||||
singletons::SettingManager::getInstance().highlightProperties.setValue(phrases);
|
singletons::SettingManager::getInstance().highlightProperties.setValue(
|
||||||
|
phrases);
|
||||||
});
|
});
|
||||||
|
|
||||||
auto add = buttons.emplace<QPushButton>("Add");
|
auto add = buttons.emplace<QPushButton>("Add");
|
||||||
QObject::connect(*add, &QPushButton::clicked,
|
QObject::connect(*add, &QPushButton::clicked, [model] {
|
||||||
[model] { model->addRow("", true, false, false); });
|
auto *item1 = new QStandardItem();
|
||||||
|
auto *item2 = new QStandardItem();
|
||||||
|
item2->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
|
||||||
|
item2->setData(true, Qt::CheckStateRole);
|
||||||
|
auto *item3 = new QStandardItem();
|
||||||
|
item3->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
|
||||||
|
item3->setData(true, Qt::CheckStateRole);
|
||||||
|
auto *item4 = new QStandardItem();
|
||||||
|
item4->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
|
||||||
|
item4->setData(false, Qt::CheckStateRole);
|
||||||
|
model->appendRow({item1, item2, item3, item4});
|
||||||
|
});
|
||||||
auto remove = buttons.emplace<QPushButton>("Remove");
|
auto remove = buttons.emplace<QPushButton>("Remove");
|
||||||
QObject::connect(*remove, &QPushButton::clicked, [view, model] {
|
QObject::connect(*remove, &QPushButton::clicked, [view, model] {
|
||||||
if (view->selectionModel()->hasSelection()) {
|
if (view->selectionModel()->hasSelection()) {
|
||||||
|
|
Loading…
Reference in a new issue