mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
play around with custom rendering
This commit is contained in:
parent
61b04dbe7b
commit
35d5e7fb63
|
@ -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
|
||||
|
|
72
src/TestDelegate.cpp
Normal file
72
src/TestDelegate.cpp
Normal file
|
@ -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<bool>();
|
||||
|
||||
if (index.data(Qt::UserRole + 1).value<bool>())
|
||||
{
|
||||
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<QString>());
|
||||
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<QColor>();
|
||||
|
||||
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
|
20
src/TestDelegate.hpp
Normal file
20
src/TestDelegate.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include <QSize>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
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
|
52
src/TestModel.cpp
Normal file
52
src/TestModel.cpp
Normal file
|
@ -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<int> roles = QVector<int>();
|
||||
roles.append(role);
|
||||
emit dataChanged(index, index, roles);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
14
src/TestModel.hpp
Normal file
14
src/TestModel.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QVariant>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class TestModel
|
||||
{
|
||||
public:
|
||||
TestModel() = default;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
57
src/TestView.cpp
Normal file
57
src/TestView.cpp
Normal file
|
@ -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
|
39
src/TestView.hpp
Normal file
39
src/TestView.hpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#pragma once
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QAbstractItemView>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QPoint>
|
||||
#include <QRect>
|
||||
#include <QRegion>
|
||||
#include <QWidget>
|
||||
|
||||
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
|
57
src/TestView2.cpp
Normal file
57
src/TestView2.cpp
Normal file
|
@ -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
|
39
src/TestView2.hpp
Normal file
39
src/TestView2.hpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#pragma once
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QAbstractItemView>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QPoint>
|
||||
#include <QRect>
|
||||
#include <QRegion>
|
||||
#include <QWidget>
|
||||
|
||||
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
|
|
@ -161,6 +161,7 @@ public:
|
|||
if (rowItem.isCustomRow)
|
||||
{
|
||||
this->customRowSetData(rowItem.items, column, value, role, row);
|
||||
emit dataChanged(index, index, {role});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -17,6 +17,7 @@ enum class SettingsTabId {
|
|||
None,
|
||||
General,
|
||||
Accounts,
|
||||
Highlights,
|
||||
Moderation,
|
||||
About,
|
||||
};
|
||||
|
|
|
@ -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 <QFileDialog>
|
||||
#include <QHeaderView>
|
||||
#include <QListView>
|
||||
#include <QPushButton>
|
||||
#include <QStandardItemModel>
|
||||
#include <QTableView>
|
||||
#include <QTabWidget>
|
||||
#include <QTreeView>
|
||||
|
||||
#include "TestView2.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
|
@ -55,6 +62,47 @@ HighlightingPage::HighlightingPage()
|
|||
// TABS
|
||||
auto tabs = layout.emplace<QTabWidget>();
|
||||
{
|
||||
// TEST
|
||||
{
|
||||
auto highlights = tabs.appendTab(new QVBoxLayout, "TEST");
|
||||
|
||||
auto *model =
|
||||
(new HighlightModel(nullptr))
|
||||
->initialized(&getSettings()->highlightedMessages);
|
||||
auto *view = highlights.emplace<QListView>(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<bool>())
|
||||
{
|
||||
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");
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue