diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9757ed3e1..45abe21b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,6 +15,13 @@ set(SOURCE_FILES RunGui.cpp RunGui.hpp + TestView.cpp + TestView.hpp + TestView2.cpp + TestView2.hpp + TestDelegate.cpp + TestDelegate.hpp + common/Args.cpp common/Args.hpp common/Channel.cpp diff --git a/src/TestDelegate.cpp b/src/TestDelegate.cpp new file mode 100644 index 000000000..297d21077 --- /dev/null +++ b/src/TestDelegate.cpp @@ -0,0 +1,72 @@ +#include "TestDelegate.hpp" + +#include "controllers/highlights/HighlightPhrase.hpp" +#include "widgets/helper/color/Checkerboard.hpp" + +namespace chatterino { + +TestDelegate::TestDelegate(QObject *parent) + : QStyledItemDelegate(parent) +{ +} + +QSize TestDelegate::sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + auto base = QStyledItemDelegate::sizeHint(option, index); + + qInfo() << "XXX: size hint when userrole+1 value is" + << index.data(Qt::UserRole + 1).value(); + + if (index.data(Qt::UserRole + 1).value()) + { + base.setHeight(base.height() * 2); + } + else + { + // do nothing + } + + return base; +} + +void TestDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const +{ + auto data = index.data(Qt::DisplayRole); + + HighlightPhrase phrase("my phrase", true, false, true, true, true, "", + 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->setBrush(Qt::white); + painter->drawText(option.rect, data.value()); + painter->setBrush(QColor{255, 0, 255, 20}); + painter->setPen(QColor{255, 0, 255}); + painter->drawRect(option.rect); + painter->restore(); + // return QStyledItemDelegate::paint(painter, option, index); + return; + } + auto color = data.value(); + + painter->save(); + if (color.alpha() != 255) + { + drawCheckerboard(*painter, option.rect, + std::min(option.rect.height() / 2, 10)); + } + painter->setBrush(color); + painter->drawRect(option.rect); + painter->restore(); +} + +} // namespace chatterino diff --git a/src/TestDelegate.hpp b/src/TestDelegate.hpp new file mode 100644 index 000000000..e519776fc --- /dev/null +++ b/src/TestDelegate.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +namespace chatterino { + +class TestDelegate : public QStyledItemDelegate +{ +public: + explicit TestDelegate(QObject *parent); + + QSize sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const override; + + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const override; +}; + +} // namespace chatterino diff --git a/src/TestModel.cpp b/src/TestModel.cpp new file mode 100644 index 000000000..b18857a4c --- /dev/null +++ b/src/TestModel.cpp @@ -0,0 +1,52 @@ +#include "TestModel.hpp" + +namespace chatterino { + +bool TestModel::setData(const QModelIndex &index, const QVariant &value, + int role) +{ + int row = index.row(); + int column = index.column(); + if (row < 0 || column < 0 || row >= this->rows_.size() || + column >= this->columnCount_) + { + return false; + } + + Row &rowItem = this->rows_[row]; + + assert(this->columnCount_ == rowItem.items.size()); + + auto &cell = rowItem.items[column]; + + cell->setData(value, role); + + if (rowItem.isCustomRow) + { + this->customRowSetData(rowItem.items, column, value, role, row); + } + else + { + int vecRow = this->getVectorIndexFromModelIndex(row); + // TODO: This is only a safety-thing for when we modify data that's being modified right now. + // It should not be necessary, but it would require some rethinking about this surrounding logic + if (vecRow >= this->vector_->readOnly()->size()) + { + return false; + } + this->vector_->removeAt(vecRow, this); + + assert(this->rows_[row].original); + TVectorItem item = this->getItemFromRow( + this->rows_[row].items, this->rows_[row].original.value()); + this->vector_->insert(item, vecRow, this); + + QVector roles = QVector(); + roles.append(role); + emit dataChanged(index, index, roles); + } + + return true; +} + +} // namespace chatterino diff --git a/src/TestModel.hpp b/src/TestModel.hpp new file mode 100644 index 000000000..b0dfd198f --- /dev/null +++ b/src/TestModel.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include +#include + +namespace chatterino { + +class TestModel +{ +public: + TestModel() = default; +}; + +} // namespace chatterino diff --git a/src/TestView.cpp b/src/TestView.cpp new file mode 100644 index 000000000..bcc43deca --- /dev/null +++ b/src/TestView.cpp @@ -0,0 +1,57 @@ +#include "TestView.hpp" + +namespace chatterino { + +TestView::TestView(QWidget *parent) + : QAbstractItemView(parent) +{ +} + +QModelIndex TestView::indexAt(const QPoint &point) const +{ + return {}; +} + +void TestView::scrollTo(const QModelIndex &index, + QAbstractItemView::ScrollHint hint) +{ +} + +QRect TestView::visualRect(const QModelIndex &index) const +{ + return {}; +} + +int TestView::horizontalOffset() const +{ + return {}; +} + +int TestView::verticalOffset() const +{ + return {}; +} + +bool TestView::isIndexHidden(const QModelIndex &index) const +{ + return {}; +} + +QModelIndex TestView::moveCursor(QAbstractItemView::CursorAction cursorAction, + Qt::KeyboardModifiers modifiers) +{ + return {}; +} + +void TestView::setSelection(const QRect &rect, + QItemSelectionModel::SelectionFlags flags) +{ +} + +QRegion TestView::visualRegionForSelection( + const QItemSelection &selection) const +{ + return {}; +} + +} // namespace chatterino diff --git a/src/TestView.hpp b/src/TestView.hpp new file mode 100644 index 000000000..68a5ed3e1 --- /dev/null +++ b/src/TestView.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +namespace chatterino { + +class TestView : public QAbstractItemView +{ + Q_OBJECT + +public: + TestView(QWidget *parent); + + QModelIndex indexAt(const QPoint &point) const override; + void scrollTo(const QModelIndex &index, + QAbstractItemView::ScrollHint hint = + QAbstractItemView::ScrollHint::EnsureVisible) override; + + QRect visualRect(const QModelIndex &index) const override; + +protected: + int horizontalOffset() const override; + int verticalOffset() const override; + bool isIndexHidden(const QModelIndex &index) const override; + QModelIndex moveCursor(QAbstractItemView::CursorAction cursorAction, + Qt::KeyboardModifiers modifiers) override; + void setSelection(const QRect &rect, + QItemSelectionModel::SelectionFlags flags) override; + QRegion visualRegionForSelection( + const QItemSelection &selection) const override; +}; + +} // namespace chatterino diff --git a/src/TestView2.cpp b/src/TestView2.cpp new file mode 100644 index 000000000..c31ffec8e --- /dev/null +++ b/src/TestView2.cpp @@ -0,0 +1,57 @@ +#include "TestView2.hpp" + +namespace chatterino { + +TestView2::TestView2(QWidget *parent) + : QAbstractItemView(parent) +{ +} + +QModelIndex TestView2::indexAt(const QPoint &point) const +{ + return {}; +} + +void TestView2::scrollTo(const QModelIndex &index, + QAbstractItemView::ScrollHint hint) +{ +} + +QRect TestView2::visualRect(const QModelIndex &index) const +{ + return {}; +} + +int TestView2::horizontalOffset() const +{ + return {}; +} + +int TestView2::verticalOffset() const +{ + return {}; +} + +bool TestView2::isIndexHidden(const QModelIndex &index) const +{ + return {}; +} + +QModelIndex TestView2::moveCursor(QAbstractItemView::CursorAction cursorAction, + Qt::KeyboardModifiers modifiers) +{ + return {}; +} + +void TestView2::setSelection(const QRect &rect, + QItemSelectionModel::SelectionFlags flags) +{ +} + +QRegion TestView2::visualRegionForSelection( + const QItemSelection &selection) const +{ + return {}; +} + +} // namespace chatterino diff --git a/src/TestView2.hpp b/src/TestView2.hpp new file mode 100644 index 000000000..eb4c852c9 --- /dev/null +++ b/src/TestView2.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +namespace chatterino { + +class TestView2 : public QAbstractItemView +{ + Q_OBJECT + +public: + TestView2(QWidget *parent); + + QModelIndex indexAt(const QPoint &point) const override; + void scrollTo(const QModelIndex &index, + QAbstractItemView::ScrollHint hint = + QAbstractItemView::ScrollHint::EnsureVisible) override; + + QRect visualRect(const QModelIndex &index) const override; + +protected: + int horizontalOffset() const override; + int verticalOffset() const override; + bool isIndexHidden(const QModelIndex &index) const override; + QModelIndex moveCursor(QAbstractItemView::CursorAction cursorAction, + Qt::KeyboardModifiers modifiers) override; + void setSelection(const QRect &rect, + QItemSelectionModel::SelectionFlags flags) override; + QRegion visualRegionForSelection( + const QItemSelection &selection) const override; +}; + +} // namespace chatterino diff --git a/src/common/SignalVectorModel.hpp b/src/common/SignalVectorModel.hpp index 620ca452d..0676ff39f 100644 --- a/src/common/SignalVectorModel.hpp +++ b/src/common/SignalVectorModel.hpp @@ -161,6 +161,7 @@ public: if (rowItem.isCustomRow) { this->customRowSetData(rowItem.items, column, value, role, row); + emit dataChanged(index, index, {role}); } else { diff --git a/src/widgets/dialogs/SettingsDialog.cpp b/src/widgets/dialogs/SettingsDialog.cpp index 2a4af662e..d6daf9616 100644 --- a/src/widgets/dialogs/SettingsDialog.cpp +++ b/src/widgets/dialogs/SettingsDialog.cpp @@ -240,7 +240,7 @@ void SettingsDialog::addTabs() this->addTab([]{return new NicknamesPage;}, "Nicknames", ":/settings/accounts.svg"); this->ui_.tabContainer->addSpacing(16); this->addTab([]{return new CommandPage;}, "Commands", ":/settings/commands.svg"); - this->addTab([]{return new HighlightingPage;}, "Highlights", ":/settings/notifications.svg"); + this->addTab([]{return new HighlightingPage;}, "Highlights", ":/settings/notifications.svg", SettingsTabId::Highlights); this->addTab([]{return new IgnoresPage;}, "Ignores", ":/settings/ignore.svg"); this->addTab([]{return new FiltersPage;}, "Filters", ":/settings/filters.svg"); this->ui_.tabContainer->addSpacing(16); @@ -364,6 +364,11 @@ void SettingsDialog::showDialog(QWidget *parent, } break; + case SettingsDialogPreference::Highlights: { + instance->selectTab(SettingsTabId::Highlights); + } + break; + case SettingsDialogPreference::StreamerMode: { instance->selectTab(SettingsTabId::General); } diff --git a/src/widgets/dialogs/SettingsDialog.hpp b/src/widgets/dialogs/SettingsDialog.hpp index 6c32e0ccb..53a0a7ad6 100644 --- a/src/widgets/dialogs/SettingsDialog.hpp +++ b/src/widgets/dialogs/SettingsDialog.hpp @@ -29,6 +29,7 @@ enum class SettingsDialogPreference { NoPreference, StreamerMode, Accounts, + Highlights, ModerationActions, About, }; @@ -40,7 +41,7 @@ class SettingsDialog : public BaseWindow public: static void showDialog(QWidget *parent, SettingsDialogPreference preferredTab = - SettingsDialogPreference::NoPreference); + SettingsDialogPreference::Highlights); protected: void scaleChangedEvent(float newDpi) override; diff --git a/src/widgets/helper/SettingsDialogTab.hpp b/src/widgets/helper/SettingsDialogTab.hpp index 0c60688b2..5ddec5157 100644 --- a/src/widgets/helper/SettingsDialogTab.hpp +++ b/src/widgets/helper/SettingsDialogTab.hpp @@ -17,6 +17,7 @@ enum class SettingsTabId { None, General, Accounts, + Highlights, Moderation, About, }; diff --git a/src/widgets/settingspages/HighlightingPage.cpp b/src/widgets/settingspages/HighlightingPage.cpp index 2a1b6884b..76bfaa49a 100644 --- a/src/widgets/settingspages/HighlightingPage.cpp +++ b/src/widgets/settingspages/HighlightingPage.cpp @@ -10,6 +10,9 @@ #include "controllers/highlights/UserHighlightModel.hpp" #include "providers/colors/ColorProvider.hpp" #include "singletons/Settings.hpp" +#include "TestDelegate.hpp" +#include "TestModel.hpp" +#include "TestView.hpp" #include "util/Helpers.hpp" #include "util/LayoutCreator.hpp" #include "widgets/dialogs/BadgePickerDialog.hpp" @@ -19,10 +22,14 @@ #include #include +#include #include #include #include #include +#include + +#include "TestView2.hpp" namespace chatterino { @@ -55,6 +62,47 @@ HighlightingPage::HighlightingPage() // TABS auto tabs = layout.emplace(); { + // TEST + { + auto highlights = tabs.appendTab(new QVBoxLayout, "TEST"); + + auto *model = + (new HighlightModel(nullptr)) + ->initialized(&getSettings()->highlightedMessages); + auto *view = highlights.emplace(this).getElement(); + view->setSpacing(2); + QObject::connect( + view, &QAbstractItemView::clicked, + [view, model](const QModelIndex &index) { + qInfo() << "XXX: ITEM CLICKED?" + << index.data(Qt::UserRole + 1).type(); + if (index.data(Qt::UserRole + 1).value()) + { + auto res = + model->setData(index, false, Qt::UserRole + 1); + qInfo() << "XXX: ITEM CLICKED? Set to false" << res; + } + else + { + auto res = + model->setData(index, QVariant::fromValue(true), + Qt::UserRole + 1); + qInfo() << "XXX: ITEM CLICKED? Set to true" << res; + } + view->update(); + view->viewport()->update(); + + view->updateGeometry(); + view->viewport()->updateGeometry(); + // view->update(); + // view->repaint(); + }); + view->setModel(model); + view->setHorizontalScrollBarPolicy( + Qt::ScrollBarPolicy::ScrollBarAlwaysOff); + view->setItemDelegate(new TestDelegate(this)); + } + // HIGHLIGHTS auto highlights = tabs.appendTab(new QVBoxLayout, "Messages"); {