From 308a889c69e681efc6291369afdf6d23c128c853 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Mon, 21 Oct 2024 09:58:09 +0200 Subject: [PATCH] test --- src/TestDelegate.cpp | 10 ++- src/TestWidget.cpp | 66 ++++++++++++++++++- src/TestWidget.hpp | 10 +++ .../settingspages/HighlightingPage.cpp | 44 ++++++------- 4 files changed, 105 insertions(+), 25 deletions(-) diff --git a/src/TestDelegate.cpp b/src/TestDelegate.cpp index 881fd7cd450..b5753e5932e 100644 --- a/src/TestDelegate.cpp +++ b/src/TestDelegate.cpp @@ -17,6 +17,11 @@ TestDelegate::TestDelegate(QObject *parent) auto *factory = new TestWidgetCreator(); this->setItemEditorFactory(factory); this->btn = new QPushButton("xd"); + QObject::connect(this->btn, &QPushButton::clicked, [this] { + qInfo() << "XXX: btn press"; + this->commitData(this->btn); + // + }); } TestDelegate::~TestDelegate() @@ -101,12 +106,14 @@ void TestDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, } painter->restore(); + this->btn->render(painter); // return QStyledItemDelegate::paint(painter, option, index); } void TestDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { + qInfo() << "XXX: setEditorData" << index; auto *realEditor = dynamic_cast(editor); realEditor->update(index.data().value()); assert(realEditor); @@ -117,7 +124,8 @@ bool TestDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QModelIndex &index) { auto *view = qobject_cast(this->parent()); - view->openPersistentEditor(index); + qInfo() << "XXX: editor event" << event << view; + // view->openPersistentEditor(index); return QStyledItemDelegate::editorEvent(event, model, option, index); } diff --git a/src/TestWidget.cpp b/src/TestWidget.cpp index 26d3aaa1d1a..1bd574ed0df 100644 --- a/src/TestWidget.cpp +++ b/src/TestWidget.cpp @@ -1,15 +1,22 @@ #include "TestWidget.hpp" +#include "controllers/highlights/HighlightPhrase.hpp" +#include "widgets/helper/color/ColorButton.hpp" + #include +#include +#include +#include #include #include +#include namespace chatterino { class TestWidgetImpl { public: TestWidgetImpl(QWidget *parent) - : btn(new QPushButton("xd", parent)) + : btn(new QPushButton("xd5", parent)) { } @@ -30,4 +37,61 @@ void TestWidget::update(const QString &data) this->impl->btn->setText("AAAAA" % data); } +TestWidget2::TestWidget2(QWidget *parent, const HighlightPhrase &data) + : QWidget(parent) +{ + auto *layout = new QGridLayout(this); + + auto *lbl = new QLineEdit(data.getPattern()); + layout->addWidget(lbl, 0, 0, 1, 2); + + { + auto *cb = new ColorButton(*data.getColor()); + layout->addWidget(cb, 0, 3); + } + + int row = 0; + int column = 0; + + { + auto *cb = new QCheckBox("Show in mentions"); + cb->setChecked(data.showInMentions()); + layout->addWidget(cb, 1, 0); + } + + { + auto *cb = new QCheckBox("Flash taskbar"); + cb->setChecked(data.hasAlert()); + layout->addWidget(cb, 1, 1); + } + + { + auto *cb = new QCheckBox("Enable regex"); + cb->setChecked(data.isRegex()); + layout->addWidget(cb, 2, 0); + } + + { + auto *cb = new QCheckBox("Case-sensitive"); + cb->setChecked(data.isCaseSensitive()); + layout->addWidget(cb, 2, 1); + } + + { + auto *cb = new QCheckBox("Play sound"); + cb->setChecked(data.hasSound()); + layout->addWidget(cb, 3, 0); + } + + { + auto *cb = new QCheckBox("Custom sound"); + // cb->setChecked(data.hasSound()); + layout->addWidget(cb, 3, 1); + } + + // layout->addLayout(gridLayout); + + layout->setSizeConstraint(QLayout::SetFixedSize); +} + } // namespace chatterino diff --git a/src/TestWidget.hpp b/src/TestWidget.hpp index 00dc765b900..2c215a36576 100644 --- a/src/TestWidget.hpp +++ b/src/TestWidget.hpp @@ -1,5 +1,7 @@ #pragma once +#include "controllers/highlights/HighlightPhrase.hpp" + #include #include #include @@ -37,6 +39,14 @@ class TestWidgetCreator : public QItemEditorFactory } }; +class TestWidget2 : public QWidget +{ + Q_OBJECT + +public: + TestWidget2(QWidget *parent, const HighlightPhrase &data); +}; + } // namespace chatterino Q_DECLARE_METATYPE(chatterino::TestWidget *); diff --git a/src/widgets/settingspages/HighlightingPage.cpp b/src/widgets/settingspages/HighlightingPage.cpp index fa7cf2adea9..f29c3f4067c 100644 --- a/src/widgets/settingspages/HighlightingPage.cpp +++ b/src/widgets/settingspages/HighlightingPage.cpp @@ -72,34 +72,32 @@ HighlightingPage::HighlightingPage() auto *model = (new HighlightModel(nullptr)) ->initialized(&getSettings()->highlightedMessages); - auto *view = highlights.emplace(this).getElement(); - view->setHorizontalScrollBarPolicy( + auto *scrollArea = + highlights.emplace(this).getElement(); + scrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarPolicy::ScrollBarAlwaysOff); - view->setVerticalScrollBarPolicy( + scrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarPolicy::ScrollBarAlwaysOn); - auto *box = new QVBoxLayout; - view->setLayout(box); - - box->setSizeConstraint( - QLayout::SizeConstraint::SetMinAndMaxSize); + scrollArea->setWidgetResizable(true); + auto *layout = new QVBoxLayout; + auto *layoutWidget = new QWidget; + scrollArea->setWidget(layoutWidget); + layoutWidget->setLayout(layout); + + layout->setSizeConstraint( + QLayout::SizeConstraint::SetMaximumSize); 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", + "1", "2", "3", "4", "5", "6", "7", "8", "9", }; - for (const auto &xd : data) + auto values = getSettings()->highlightedMessages.readOnly(); + for (const auto &xd : *values) { - // auto *w = new TestWidget(this); + auto *w = new TestWidget2(this, xd); // w->setMinimumHeight(50); - auto *w = new QPushButton("xd"); - /* + // auto *w = new QPushButton("xd"); w->setSizePolicy( - {QSizePolicy::Maximum, QSizePolicy::Minimum}); - */ - box->addWidget(w, 1); + {QSizePolicy::Minimum, QSizePolicy::Minimum}); + layout->addWidget(w, 1); } } @@ -118,7 +116,7 @@ HighlightingPage::HighlightingPage() [view, model](const QModelIndex &index) { qInfo() << "XXX: ITEM CLICKED?" << index.data(Qt::UserRole + 1).type(); - view->openPersistentEditor(index); + // view->openPersistentEditor(index); if (index.data(Qt::UserRole + 1).value()) { auto res = @@ -144,7 +142,7 @@ HighlightingPage::HighlightingPage() view->setModel(model); view->setHorizontalScrollBarPolicy( Qt::ScrollBarPolicy::ScrollBarAlwaysOff); - view->setItemDelegate(new TestDelegate(this)); + view->setItemDelegate(new TestDelegate(view)); } // HIGHLIGHTS