Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada committed Dec 3, 2024
1 parent e6445d4 commit 308a889
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 25 deletions.
10 changes: 9 additions & 1 deletion src/TestDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<TestWidget *>(editor);
realEditor->update(index.data().value<QString>());
assert(realEditor);
Expand All @@ -117,7 +124,8 @@ bool TestDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
const QModelIndex &index)
{
auto *view = qobject_cast<QListView *>(this->parent());
view->openPersistentEditor(index);
qInfo() << "XXX: editor event" << event << view;
// view->openPersistentEditor(index);
return QStyledItemDelegate::editorEvent(event, model, option, index);
}

Expand Down
66 changes: 65 additions & 1 deletion src/TestWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
#include "TestWidget.hpp"

#include "controllers/highlights/HighlightPhrase.hpp"
#include "widgets/helper/color/ColorButton.hpp"

#include <qboxlayout.h>
#include <qcheckbox.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <QStringBuilder>
#include <qtextedit.h>
namespace chatterino {

class TestWidgetImpl
{
public:
TestWidgetImpl(QWidget *parent)
: btn(new QPushButton("xd", parent))
: btn(new QPushButton("xd5", parent))
{
}

Expand All @@ -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
10 changes: 10 additions & 0 deletions src/TestWidget.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "controllers/highlights/HighlightPhrase.hpp"

#include <QByteArray>
#include <QItemEditorFactory>
#include <QObject>
Expand Down Expand Up @@ -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 *);
44 changes: 21 additions & 23 deletions src/widgets/settingspages/HighlightingPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,32 @@ HighlightingPage::HighlightingPage()
auto *model =
(new HighlightModel(nullptr))
->initialized(&getSettings()->highlightedMessages);
auto *view = highlights.emplace<QScrollArea>(this).getElement();
view->setHorizontalScrollBarPolicy(
auto *scrollArea =
highlights.emplace<QScrollArea>(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);
}
}

Expand All @@ -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<bool>())
{
auto res =
Expand All @@ -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
Expand Down

0 comments on commit 308a889

Please sign in to comment.