Files
Renderive/Widget/component/Table/Base_Table_Data.cpp
T
2026-08-01 20:09:45 +08:00

57 lines
1.8 KiB
C++

#include "Base_Table_Data.h"
#include "Table_View.h"
#include "third_party/Renderive/Widget/base/Generate_Mock_Data.h"
namespace Flex_Qt {
Base_Table_Data::Base_Table_Data() {
parent = this;
}
Table_Paint_Data::Table_Paint_Data(QIcon ic, QString t) {
Range r{155, 255};
QColor random_color(get_data(r), get_data(r), get_data(r));
background_color = random_color;
icon = Icon2(ic);
text.text = t;
layout.items.push_back(&icon.value());
layout.items.push_back(&text);
}
Table_Paint_Data::Table_Paint_Data(QString t) {
Range r{155, 255};
QColor random_color(get_data(r), get_data(r), get_data(r));
background_color = random_color;
text.text = t;
layout.items.push_back(&text);
}
void Table_Paint_Data::update(bool show, Table_View* view, QPainter* painter, QRect rect) {
painter->fillRect(rect, background_color);
layout.set_x(rect.left());
layout.set_y(rect.top());
layout.set_w(rect.width());
layout.set_h(rect.height());
layout.layout();
text.paint(painter, text.rect(), nullptr);
if (icon.has_value()) {
icon.value().paint(painter, icon.value().rect(), nullptr);
}
// painter->drawText(text.rect(), Qt::AlignCenter, text.text);
}
void Widget_Data::update(bool show, Table_View* view, QPainter* painter, QRect rect) {
// auto tl = view->to_inside_pos(rect.topLeft());
// auto br = view->to_inside_pos(rect.bottomRight());
auto tl = rect.topLeft() - view->get_view_rect().topLeft();
auto br = tl + QPoint(rect.width(), rect.height());
QRect r(tl, br);
// std::cout << r << "\n";
if (show) {
widget->setParent(view->container);
widget->show();
widget->installEventFilter(view);
widget->setGeometry(r);
}
else {
widget->setParent(nullptr);
widget->hide();
widget->removeEventFilter(view);
}
}
}