mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
more tests
This commit is contained in:
parent
35d5e7fb63
commit
3996bf01ca
|
@ -21,6 +21,8 @@ set(SOURCE_FILES
|
||||||
TestView2.hpp
|
TestView2.hpp
|
||||||
TestDelegate.cpp
|
TestDelegate.cpp
|
||||||
TestDelegate.hpp
|
TestDelegate.hpp
|
||||||
|
TestWidget.cpp
|
||||||
|
TestWidget.hpp
|
||||||
|
|
||||||
common/Args.cpp
|
common/Args.cpp
|
||||||
common/Args.hpp
|
common/Args.hpp
|
||||||
|
|
|
@ -1,13 +1,27 @@
|
||||||
#include "TestDelegate.hpp"
|
#include "TestDelegate.hpp"
|
||||||
|
|
||||||
#include "controllers/highlights/HighlightPhrase.hpp"
|
#include "controllers/highlights/HighlightPhrase.hpp"
|
||||||
|
#include "TestWidget.hpp"
|
||||||
#include "widgets/helper/color/Checkerboard.hpp"
|
#include "widgets/helper/color/Checkerboard.hpp"
|
||||||
|
|
||||||
|
#include <QItemEditorFactory>
|
||||||
|
#include <qlistview.h>
|
||||||
|
#include <QPainterPath>
|
||||||
|
#include <qstyleditemdelegate.h>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
TestDelegate::TestDelegate(QObject *parent)
|
TestDelegate::TestDelegate(QObject *parent)
|
||||||
: QStyledItemDelegate(parent)
|
: QStyledItemDelegate(parent)
|
||||||
{
|
{
|
||||||
|
auto *factory = new TestWidgetCreator();
|
||||||
|
this->setItemEditorFactory(factory);
|
||||||
|
this->btn = new QPushButton("xd");
|
||||||
|
}
|
||||||
|
|
||||||
|
TestDelegate::~TestDelegate()
|
||||||
|
{
|
||||||
|
this->btn->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize TestDelegate::sizeHint(const QStyleOptionViewItem &option,
|
QSize TestDelegate::sizeHint(const QStyleOptionViewItem &option,
|
||||||
|
@ -15,15 +29,13 @@ QSize TestDelegate::sizeHint(const QStyleOptionViewItem &option,
|
||||||
{
|
{
|
||||||
auto base = QStyledItemDelegate::sizeHint(option, index);
|
auto base = QStyledItemDelegate::sizeHint(option, index);
|
||||||
|
|
||||||
qInfo() << "XXX: size hint when userrole+1 value is"
|
|
||||||
<< index.data(Qt::UserRole + 1).value<bool>();
|
|
||||||
|
|
||||||
if (index.data(Qt::UserRole + 1).value<bool>())
|
if (index.data(Qt::UserRole + 1).value<bool>())
|
||||||
{
|
{
|
||||||
base.setHeight(base.height() * 2);
|
base.setHeight(base.height() * 5);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
base.setHeight(base.height() * 5);
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,39 +46,79 @@ void TestDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||||
const QModelIndex &index) const
|
const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
auto data = index.data(Qt::DisplayRole);
|
auto data = index.data(Qt::DisplayRole);
|
||||||
|
auto expanded = index.data(Qt::UserRole + 1).value<bool>();
|
||||||
|
|
||||||
|
// auto *view = qobject_cast<QListView *>(this->parent());
|
||||||
|
// view->openPersistentEditor(index);
|
||||||
|
// if (view->isPersistentEditorOpen(index)) {
|
||||||
|
// } else {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// painter->begin(this->btn->paintEngine)
|
||||||
|
// this->btn->paint()
|
||||||
|
|
||||||
HighlightPhrase phrase("my phrase", true, false, true, true, true, "",
|
HighlightPhrase phrase("my phrase", true, false, true, true, true, "",
|
||||||
QColor{});
|
QColor{});
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
||||||
if (data.typeId() != QMetaType::QColor)
|
|
||||||
#else
|
|
||||||
if (data.type() != QVariant::Color)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
qInfo() << "XXX:" << data.typeId();
|
|
||||||
qInfo() << "XXX:" << data.type();
|
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
painter->setBrush(Qt::white);
|
painter->setBrush(Qt::white);
|
||||||
painter->drawText(option.rect, data.value<QString>());
|
painter->drawText(option.rect, data.value<QString>());
|
||||||
painter->setBrush(QColor{255, 0, 255, 20});
|
painter->setBrush(QColor{255, 0, 255, 20});
|
||||||
painter->setPen(QColor{255, 0, 255});
|
painter->setPen(QColor{255, 0, 255});
|
||||||
painter->drawRect(option.rect);
|
// painter->drawRect(option.rect);
|
||||||
|
|
||||||
|
QPoint dist(10, 10);
|
||||||
|
|
||||||
|
// painter->setPen(Qt::PenStyle::DotLine);
|
||||||
|
|
||||||
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
|
QPen pen;
|
||||||
|
|
||||||
|
pen.setWidth(2);
|
||||||
|
pen.setColor(QColor{255, 0, 255, 255});
|
||||||
|
|
||||||
|
painter->setPen(pen);
|
||||||
|
|
||||||
|
if (expanded)
|
||||||
|
{
|
||||||
|
QPainterPath path;
|
||||||
|
path.moveTo(option.rect.topRight());
|
||||||
|
path.lineTo(option.rect.topRight() - QPoint{10, -10});
|
||||||
|
|
||||||
|
auto tr = QRect(option.rect.right() - 10, option.rect.top(), 5,
|
||||||
|
option.rect.height() / 2);
|
||||||
|
|
||||||
|
painter->drawPath(path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto tr = QRect(option.rect.right() - 10, option.rect.top(), 5,
|
||||||
|
option.rect.height());
|
||||||
|
painter->drawEllipse(tr);
|
||||||
|
}
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
// return QStyledItemDelegate::paint(painter, option, index);
|
// return QStyledItemDelegate::paint(painter, option, index);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
auto color = data.value<QColor>();
|
|
||||||
|
|
||||||
painter->save();
|
void TestDelegate::setEditorData(QWidget *editor,
|
||||||
if (color.alpha() != 255)
|
const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
drawCheckerboard(*painter, option.rect,
|
auto *realEditor = dynamic_cast<TestWidget *>(editor);
|
||||||
std::min(option.rect.height() / 2, 10));
|
realEditor->update(index.data().value<QString>());
|
||||||
|
assert(realEditor);
|
||||||
}
|
}
|
||||||
painter->setBrush(color);
|
|
||||||
painter->drawRect(option.rect);
|
bool TestDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
||||||
painter->restore();
|
const QStyleOptionViewItem &option,
|
||||||
|
const QModelIndex &index)
|
||||||
|
{
|
||||||
|
auto *view = qobject_cast<QListView *>(this->parent());
|
||||||
|
view->openPersistentEditor(index);
|
||||||
|
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <qpushbutton.h>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
|
@ -9,12 +10,23 @@ class TestDelegate : public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit TestDelegate(QObject *parent);
|
explicit TestDelegate(QObject *parent);
|
||||||
|
~TestDelegate();
|
||||||
|
|
||||||
QSize sizeHint(const QStyleOptionViewItem &option,
|
QSize sizeHint(const QStyleOptionViewItem &option,
|
||||||
const QModelIndex &index) const override;
|
const QModelIndex &index) const override;
|
||||||
|
|
||||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||||
const QModelIndex &index) const override;
|
const QModelIndex &index) const override;
|
||||||
|
|
||||||
|
void setEditorData(QWidget *editor,
|
||||||
|
const QModelIndex &index) const override;
|
||||||
|
|
||||||
|
bool editorEvent(QEvent *event, QAbstractItemModel *model,
|
||||||
|
const QStyleOptionViewItem &option,
|
||||||
|
const QModelIndex &index) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPushButton *btn;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
33
src/TestWidget.cpp
Normal file
33
src/TestWidget.cpp
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#include "TestWidget.hpp"
|
||||||
|
|
||||||
|
#include <qboxlayout.h>
|
||||||
|
#include <qpushbutton.h>
|
||||||
|
#include <QStringBuilder>
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
class TestWidgetImpl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestWidgetImpl(QWidget *parent)
|
||||||
|
: btn(new QPushButton("xd", parent))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QPushButton *btn;
|
||||||
|
};
|
||||||
|
|
||||||
|
TestWidget::TestWidget(QWidget *parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
, impl(new TestWidgetImpl(this))
|
||||||
|
{
|
||||||
|
auto *layout = new QVBoxLayout(this);
|
||||||
|
|
||||||
|
layout->addWidget(impl->btn);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestWidget::update(const QString &data)
|
||||||
|
{
|
||||||
|
this->impl->btn->setText("AAAAA" % data);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace chatterino
|
42
src/TestWidget.hpp
Normal file
42
src/TestWidget.hpp
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QItemEditorFactory>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
class TestWidgetImpl;
|
||||||
|
|
||||||
|
class TestWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
TestWidget(QWidget *parent);
|
||||||
|
|
||||||
|
void update(const QString &data);
|
||||||
|
|
||||||
|
private:
|
||||||
|
TestWidgetImpl *impl;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TestWidgetCreator : public QItemEditorFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QWidget *createEditor(int userType, QWidget *parent) const override
|
||||||
|
{
|
||||||
|
qInfo() << "XXX: USER TYPE" << userType;
|
||||||
|
return new TestWidget(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray valuePropertyName(int userType) const override
|
||||||
|
{
|
||||||
|
return "data";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace chatterino
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(chatterino::TestWidget *);
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <pajlada/serialize.hpp>
|
#include <pajlada/serialize.hpp>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include <QObject>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
@ -18,6 +19,8 @@ class HighlightPhrase
|
||||||
public:
|
public:
|
||||||
bool operator==(const HighlightPhrase &other) const;
|
bool operator==(const HighlightPhrase &other) const;
|
||||||
|
|
||||||
|
HighlightPhrase(const HighlightPhrase &other) = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a new HighlightPhrase.
|
* @brief Create a new HighlightPhrase.
|
||||||
*
|
*
|
||||||
|
@ -102,6 +105,8 @@ private:
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(chatterino::HighlightPhrase *);
|
||||||
|
|
||||||
namespace pajlada {
|
namespace pajlada {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include <pajlada/settings/settinglistener.hpp>
|
#include <pajlada/settings/settinglistener.hpp>
|
||||||
#include <pajlada/signals/signalholder.hpp>
|
#include <pajlada/signals/signalholder.hpp>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
using TimeoutButton = std::pair<QString, int>;
|
using TimeoutButton = std::pair<QString, int>;
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "TestDelegate.hpp"
|
#include "TestDelegate.hpp"
|
||||||
#include "TestModel.hpp"
|
#include "TestModel.hpp"
|
||||||
#include "TestView.hpp"
|
#include "TestView.hpp"
|
||||||
|
#include "TestWidget.hpp"
|
||||||
#include "util/Helpers.hpp"
|
#include "util/Helpers.hpp"
|
||||||
#include "util/LayoutCreator.hpp"
|
#include "util/LayoutCreator.hpp"
|
||||||
#include "widgets/dialogs/BadgePickerDialog.hpp"
|
#include "widgets/dialogs/BadgePickerDialog.hpp"
|
||||||
|
@ -20,10 +21,12 @@
|
||||||
#include "widgets/helper/color/ColorItemDelegate.hpp"
|
#include "widgets/helper/color/ColorItemDelegate.hpp"
|
||||||
#include "widgets/helper/EditableModelView.hpp"
|
#include "widgets/helper/EditableModelView.hpp"
|
||||||
|
|
||||||
|
#include <qabstractitemview.h>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QListView>
|
#include <QListView>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <qscrollarea.h>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
|
@ -62,6 +65,44 @@ HighlightingPage::HighlightingPage()
|
||||||
// TABS
|
// TABS
|
||||||
auto tabs = layout.emplace<QTabWidget>();
|
auto tabs = layout.emplace<QTabWidget>();
|
||||||
{
|
{
|
||||||
|
// TEST 2
|
||||||
|
{
|
||||||
|
auto highlights = tabs.appendTab(new QVBoxLayout, "TEST 2");
|
||||||
|
|
||||||
|
auto *model =
|
||||||
|
(new HighlightModel(nullptr))
|
||||||
|
->initialized(&getSettings()->highlightedMessages);
|
||||||
|
auto *view = highlights.emplace<QScrollArea>(this).getElement();
|
||||||
|
view->setHorizontalScrollBarPolicy(
|
||||||
|
Qt::ScrollBarPolicy::ScrollBarAlwaysOff);
|
||||||
|
view->setVerticalScrollBarPolicy(
|
||||||
|
Qt::ScrollBarPolicy::ScrollBarAlwaysOn);
|
||||||
|
auto *box = new QVBoxLayout;
|
||||||
|
view->setLayout(box);
|
||||||
|
|
||||||
|
box->setSizeConstraint(
|
||||||
|
QLayout::SizeConstraint::SetMinAndMaxSize);
|
||||||
|
QStringList data{
|
||||||
|
"1", "2", "3", "4", "5", "6", "7", "8", "9",
|
||||||
|
"10", "11", "12", "13", "14", "15", "16", "17", "18",
|
||||||
|
"19", "20", "21", "22", "23", "24", "25", "26", "27",
|
||||||
|
"19", "20", "21", "22", "23", "24", "25", "26", "27",
|
||||||
|
"19", "20", "21", "22", "23", "24", "25", "26", "27",
|
||||||
|
"19", "20", "21", "22", "23", "24", "25", "26", "27",
|
||||||
|
};
|
||||||
|
for (const auto &xd : data)
|
||||||
|
{
|
||||||
|
// auto *w = new TestWidget(this);
|
||||||
|
// w->setMinimumHeight(50);
|
||||||
|
auto *w = new QPushButton("xd");
|
||||||
|
/*
|
||||||
|
w->setSizePolicy(
|
||||||
|
{QSizePolicy::Maximum, QSizePolicy::Minimum});
|
||||||
|
*/
|
||||||
|
box->addWidget(w, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TEST
|
// TEST
|
||||||
{
|
{
|
||||||
auto highlights = tabs.appendTab(new QVBoxLayout, "TEST");
|
auto highlights = tabs.appendTab(new QVBoxLayout, "TEST");
|
||||||
|
@ -71,16 +112,19 @@ HighlightingPage::HighlightingPage()
|
||||||
->initialized(&getSettings()->highlightedMessages);
|
->initialized(&getSettings()->highlightedMessages);
|
||||||
auto *view = highlights.emplace<QListView>(this).getElement();
|
auto *view = highlights.emplace<QListView>(this).getElement();
|
||||||
view->setSpacing(2);
|
view->setSpacing(2);
|
||||||
|
// view->setEditTriggers(QAbstractItemView::AllEditTriggers);
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
view, &QAbstractItemView::clicked,
|
view, &QAbstractItemView::clicked,
|
||||||
[view, model](const QModelIndex &index) {
|
[view, model](const QModelIndex &index) {
|
||||||
qInfo() << "XXX: ITEM CLICKED?"
|
qInfo() << "XXX: ITEM CLICKED?"
|
||||||
<< index.data(Qt::UserRole + 1).type();
|
<< index.data(Qt::UserRole + 1).type();
|
||||||
|
view->openPersistentEditor(index);
|
||||||
if (index.data(Qt::UserRole + 1).value<bool>())
|
if (index.data(Qt::UserRole + 1).value<bool>())
|
||||||
{
|
{
|
||||||
auto res =
|
auto res =
|
||||||
model->setData(index, false, Qt::UserRole + 1);
|
model->setData(index, false, Qt::UserRole + 1);
|
||||||
qInfo() << "XXX: ITEM CLICKED? Set to false" << res;
|
qInfo() << "XXX: ITEM CLICKED? Set to false" << res;
|
||||||
|
view->edit(index);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue