Update to v098r09 release.

byuu says:

Changelog:
- fixed major nall/vector/prepend bug
- renamed hiro/ListView to hiro/TableView
- added new hiro/ListView control which is a simplified abstraction of
  hiro/TableView
- updated higan's cheat database window and icarus' scan dialog to use
  the new ListView control
- compilation works once again on all platforms (Windows, Cocoa, GTK,
  Qt)
- the loki skeleton compiles once again (removed nall/DSP references;
  updated port/device ID names)

Small catch: need to capture layout resize events internally in Windows
to call resizeColumns. For now, just resize the icarus window to get it
to use the full window width for list view items.
This commit is contained in:
Tim Allen
2016-05-04 20:07:13 +10:00
parent 0955295475
commit 6ae0abe3d3
108 changed files with 2299 additions and 2081 deletions

View File

@@ -47,16 +47,16 @@
#include "widget/icon-view.cpp"
#include "widget/label.cpp"
#include "widget/line-edit.cpp"
#include "widget/list-view.cpp"
#include "widget/list-view-header.cpp"
#include "widget/list-view-column.cpp"
#include "widget/list-view-item.cpp"
#include "widget/list-view-cell.cpp"
#include "widget/progress-bar.cpp"
#include "widget/radio-button.cpp"
#include "widget/radio-label.cpp"
#include "widget/tab-frame.cpp"
#include "widget/tab-frame-item.cpp"
#include "widget/table-view.cpp"
#include "widget/table-view-header.cpp"
#include "widget/table-view-column.cpp"
#include "widget/table-view-item.cpp"
#include "widget/table-view-cell.cpp"
#include "widget/text-edit.cpp"
#include "widget/vertical-scroll-bar.cpp"
#include "widget/vertical-slider.cpp"

View File

@@ -48,16 +48,16 @@
#include "widget/horizontal-slider.hpp"
#include "widget/label.hpp"
#include "widget/line-edit.hpp"
#include "widget/list-view.hpp"
#include "widget/list-view-header.hpp"
#include "widget/list-view-column.hpp"
#include "widget/list-view-item.hpp"
#include "widget/list-view-cell.hpp"
#include "widget/progress-bar.hpp"
#include "widget/radio-button.hpp"
#include "widget/radio-label.hpp"
#include "widget/tab-frame.hpp"
#include "widget/tab-frame-item.hpp"
#include "widget/table-view.hpp"
#include "widget/table-view-header.hpp"
#include "widget/table-view-column.hpp"
#include "widget/table-view-item.hpp"
#include "widget/table-view-cell.hpp"
#include "widget/text-edit.hpp"
#include "widget/vertical-scroll-bar.hpp"
#include "widget/vertical-slider.hpp"

View File

@@ -1,3 +1,5 @@
//moc-qt4 -i -o qt.moc qt.hpp
/*
Qt requires moc in order to bind callbacks, which causes many complications.
@@ -194,30 +196,6 @@ public slots:
};
#endif
#if defined(Hiro_ListView)
struct QtListView : public QTreeWidget {
Q_OBJECT
public:
QtListView(pListView& p) : p(p) {}
auto mousePressEvent(QMouseEvent*) -> void override;
auto resizeEvent(QResizeEvent*) -> void override;
auto showEvent(QShowEvent*) -> void override;
pListView& p;
public slots:
void onActivate();
void onChange();
void onContext();
void onSort(int column);
void onToggle(QTreeWidgetItem* item, int column);
};
struct QtListViewDelegate : public QStyledItemDelegate {
QtListViewDelegate(pListView& p);
auto paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const -> void;
pListView& p;
};
#endif
#if defined(Hiro_RadioLabel)
struct QtRadioLabel : public QRadioButton {
Q_OBJECT
@@ -252,6 +230,30 @@ public slots:
};
#endif
#if defined(Hiro_TableView)
struct QtTableView : public QTreeWidget {
Q_OBJECT
public:
QtTableView(pTableView& p) : p(p) {}
auto mousePressEvent(QMouseEvent*) -> void override;
auto resizeEvent(QResizeEvent*) -> void override;
auto showEvent(QShowEvent*) -> void override;
pTableView& p;
public slots:
void onActivate();
void onChange();
void onContext();
void onSort(int column);
void onToggle(QTreeWidgetItem* item, int column);
};
struct QtTableViewDelegate : public QStyledItemDelegate {
QtTableViewDelegate(pTableView& p);
auto paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const -> void;
pTableView& p;
};
#endif
#if defined(Hiro_TextEdit)
struct QtTextEdit : public QTextEdit {
Q_OBJECT

View File

@@ -1031,90 +1031,6 @@ int hiro::QtLineEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
}
return _id;
}
static const uint qt_meta_data_hiro__QtListView[] = {
// content:
6, // revision
0, // classname
0, 0, // classinfo
5, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
0, // signalCount
// slots: signature, parameters, type, tag, flags
17, 30, 30, 30, 0x0a,
31, 30, 30, 30, 0x0a,
42, 30, 30, 30, 0x0a,
54, 66, 30, 30, 0x0a,
73, 104, 30, 30, 0x0a,
0 // eod
};
static const char qt_meta_stringdata_hiro__QtListView[] = {
"hiro::QtListView\0onActivate()\0\0"
"onChange()\0onContext()\0onSort(int)\0"
"column\0onToggle(QTreeWidgetItem*,int)\0"
"item,column\0"
};
void hiro::QtListView::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
if (_c == QMetaObject::InvokeMetaMethod) {
Q_ASSERT(staticMetaObject.cast(_o));
QtListView *_t = static_cast<QtListView *>(_o);
switch (_id) {
case 0: _t->onActivate(); break;
case 1: _t->onChange(); break;
case 2: _t->onContext(); break;
case 3: _t->onSort((*reinterpret_cast< int(*)>(_a[1]))); break;
case 4: _t->onToggle((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
default: ;
}
}
}
const QMetaObjectExtraData hiro::QtListView::staticMetaObjectExtraData = {
0, qt_static_metacall
};
const QMetaObject hiro::QtListView::staticMetaObject = {
{ &QTreeWidget::staticMetaObject, qt_meta_stringdata_hiro__QtListView,
qt_meta_data_hiro__QtListView, &staticMetaObjectExtraData }
};
#ifdef Q_NO_DATA_RELOCATION
const QMetaObject &hiro::QtListView::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATION
const QMetaObject *hiro::QtListView::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
}
void *hiro::QtListView::qt_metacast(const char *_clname)
{
if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_hiro__QtListView))
return static_cast<void*>(const_cast< QtListView*>(this));
return QTreeWidget::qt_metacast(_clname);
}
int hiro::QtListView::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QTreeWidget::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 5)
qt_static_metacall(this, _c, _id, _a);
_id -= 5;
}
return _id;
}
static const uint qt_meta_data_hiro__QtRadioLabel[] = {
// content:
@@ -1337,6 +1253,90 @@ int hiro::QtTabFrame::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
}
return _id;
}
static const uint qt_meta_data_hiro__QtTableView[] = {
// content:
6, // revision
0, // classname
0, 0, // classinfo
5, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
0, // signalCount
// slots: signature, parameters, type, tag, flags
18, 31, 31, 31, 0x0a,
32, 31, 31, 31, 0x0a,
43, 31, 31, 31, 0x0a,
55, 67, 31, 31, 0x0a,
74, 105, 31, 31, 0x0a,
0 // eod
};
static const char qt_meta_stringdata_hiro__QtTableView[] = {
"hiro::QtTableView\0onActivate()\0\0"
"onChange()\0onContext()\0onSort(int)\0"
"column\0onToggle(QTreeWidgetItem*,int)\0"
"item,column\0"
};
void hiro::QtTableView::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
if (_c == QMetaObject::InvokeMetaMethod) {
Q_ASSERT(staticMetaObject.cast(_o));
QtTableView *_t = static_cast<QtTableView *>(_o);
switch (_id) {
case 0: _t->onActivate(); break;
case 1: _t->onChange(); break;
case 2: _t->onContext(); break;
case 3: _t->onSort((*reinterpret_cast< int(*)>(_a[1]))); break;
case 4: _t->onToggle((*reinterpret_cast< QTreeWidgetItem*(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
default: ;
}
}
}
const QMetaObjectExtraData hiro::QtTableView::staticMetaObjectExtraData = {
0, qt_static_metacall
};
const QMetaObject hiro::QtTableView::staticMetaObject = {
{ &QTreeWidget::staticMetaObject, qt_meta_stringdata_hiro__QtTableView,
qt_meta_data_hiro__QtTableView, &staticMetaObjectExtraData }
};
#ifdef Q_NO_DATA_RELOCATION
const QMetaObject &hiro::QtTableView::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATION
const QMetaObject *hiro::QtTableView::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
}
void *hiro::QtTableView::qt_metacast(const char *_clname)
{
if (!_clname) return 0;
if (!strcmp(_clname, qt_meta_stringdata_hiro__QtTableView))
return static_cast<void*>(const_cast< QtTableView*>(this));
return QTreeWidget::qt_metacast(_clname);
}
int hiro::QtTableView::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QTreeWidget::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 5)
qt_static_metacall(this, _c, _id, _a);
_id -= 5;
}
return _id;
}
static const uint qt_meta_data_hiro__QtTextEdit[] = {
// content:

View File

@@ -1,99 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
auto pListViewColumn::construct() -> void {
}
auto pListViewColumn::destruct() -> void {
}
auto pListViewColumn::setActive() -> void {
//unsupported
}
auto pListViewColumn::setAlignment(Alignment alignment) -> void {
_setState();
}
auto pListViewColumn::setBackgroundColor(Color color) -> void {
_setState();
}
auto pListViewColumn::setEditable(bool editable) -> void {
//unsupported
}
auto pListViewColumn::setExpandable(bool expandable) -> void {
_setState();
}
auto pListViewColumn::setFont(const Font& font) -> void {
_setState();
}
auto pListViewColumn::setForegroundColor(Color color) -> void {
_setState();
}
auto pListViewColumn::setHorizontalAlignment(double alignment) -> void {
_setState();
}
auto pListViewColumn::setIcon(const image& icon) -> void {
//unsupported
}
auto pListViewColumn::setResizable(bool resizable) -> void {
_setState();
}
auto pListViewColumn::setSortable(bool sortable) -> void {
_setState();
}
auto pListViewColumn::setText(const string& text) -> void {
_setState();
}
auto pListViewColumn::setVerticalAlignment(double alignment) -> void {
_setState();
}
auto pListViewColumn::setVisible(bool visible) -> void {
_setState();
}
auto pListViewColumn::setWidth(signed width) -> void {
_setState();
}
auto pListViewColumn::_parent() -> maybe<pListViewHeader&> {
if(auto parent = self().parentListViewHeader()) {
if(auto delegate = parent->self()) return *delegate;
}
return nothing;
}
auto pListViewColumn::_setState() -> void {
if(auto header = _parent()) {
if(auto parent = header->_parent()) {
parent->qtListView->header()->setResizeMode(self().offset(), state().resizable ? QHeaderView::Interactive : QHeaderView::Fixed);
bool clickable = false;
for(auto& column : header->state().columns) clickable |= column->state.sortable;
parent->qtListView->header()->setClickable(clickable);
parent->qtListView->headerItem()->setText(self().offset(), QString::fromUtf8(state().text));
parent->qtListView->setColumnHidden(self().offset(), !self().visible());
for(auto& item : parent->state().items) {
if(auto cell = item->cell(self().offset())) {
if(auto self = cell->self()) self->_setState();
}
}
}
}
}
}
#endif

View File

@@ -1,43 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
auto pListViewHeader::construct() -> void {
}
auto pListViewHeader::destruct() -> void {
}
auto pListViewHeader::append(sListViewColumn column) -> void {
_setState();
}
auto pListViewHeader::remove(sListViewColumn column) -> void {
_setState();
}
auto pListViewHeader::setVisible(bool visible) -> void {
_setState();
}
auto pListViewHeader::_parent() -> maybe<pListView&> {
if(auto parent = self().parentListView()) {
if(auto delegate = parent->self()) return *delegate;
}
return nothing;
}
auto pListViewHeader::_setState() -> void {
if(auto parent = _parent()) {
//parent->qtListView->setAlternatingRowColors(self().columnCount() >= 2);
parent->qtListView->setColumnCount(self().columnCount());
parent->qtListView->setHeaderHidden(!self().visible());
for(auto& column : state().columns) {
if(auto self = column->self()) self->_setState();
}
}
}
}
#endif

View File

@@ -1,18 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
struct pListViewHeader : pObject {
Declare(ListViewHeader, Object)
auto append(sListViewColumn column) -> void;
auto remove(sListViewColumn column) -> void;
auto setVisible(bool visible) -> void override;
auto _parent() -> maybe<pListView&>;
auto _setState() -> void;
};
}
#endif

View File

@@ -1,64 +0,0 @@
#if defined(Hiro_ListView)
namespace hiro {
auto pListViewItem::construct() -> void {
}
auto pListViewItem::destruct() -> void {
if(auto parent = _parent()) parent->lock();
if(qtItem) {
delete qtItem;
qtItem = nullptr;
}
if(auto parent = _parent()) parent->unlock();
}
auto pListViewItem::append(sListViewCell cell) -> void {
}
auto pListViewItem::remove(sListViewCell cell) -> void {
}
auto pListViewItem::setAlignment(Alignment alignment) -> void {
_setState();
}
auto pListViewItem::setBackgroundColor(Color color) -> void {
_setState();
}
auto pListViewItem::setFont(const Font& font) -> void {
_setState();
}
auto pListViewItem::setForegroundColor(Color color) -> void {
_setState();
}
auto pListViewItem::setSelected(bool selected) -> void {
_setState();
}
auto pListViewItem::_parent() -> maybe<pListView&> {
if(auto parent = self().parentListView()) {
if(auto delegate = parent->self()) return *delegate;
}
return nothing;
}
auto pListViewItem::_setState() -> void {
if(auto parent = _parent()) {
qtItem->setSelected(state().selected);
if(state().selected) {
parent->qtListView->setCurrentItem(qtItem);
}
for(auto& cell : state().cells) {
if(auto self = cell->self()) self->_setState();
}
}
}
}
#endif

View File

@@ -1,53 +1,53 @@
#if defined(Hiro_ListView)
#if defined(Hiro_TableView)
namespace hiro {
auto pListViewCell::construct() -> void {
auto pTableViewCell::construct() -> void {
}
auto pListViewCell::destruct() -> void {
auto pTableViewCell::destruct() -> void {
}
auto pListViewCell::setAlignment(Alignment alignment) -> void {
auto pTableViewCell::setAlignment(Alignment alignment) -> void {
_setState();
}
auto pListViewCell::setBackgroundColor(Color color) -> void {
auto pTableViewCell::setBackgroundColor(Color color) -> void {
_setState();
}
auto pListViewCell::setCheckable(bool checkable) -> void {
auto pTableViewCell::setCheckable(bool checkable) -> void {
_setState();
}
auto pListViewCell::setChecked(bool checked) -> void {
auto pTableViewCell::setChecked(bool checked) -> void {
_setState();
}
auto pListViewCell::setFont(const string& font) -> void {
auto pTableViewCell::setFont(const string& font) -> void {
_setState();
}
auto pListViewCell::setForegroundColor(Color color) -> void {
auto pTableViewCell::setForegroundColor(Color color) -> void {
_setState();
}
auto pListViewCell::setIcon(const image& icon) -> void {
auto pTableViewCell::setIcon(const image& icon) -> void {
_setState();
}
auto pListViewCell::setText(const string& text) -> void {
auto pTableViewCell::setText(const string& text) -> void {
_setState();
}
auto pListViewCell::_parent() -> maybe<pListViewItem&> {
if(auto parent = self().parentListViewItem()) {
auto pTableViewCell::_parent() -> maybe<pTableViewItem&> {
if(auto parent = self().parentTableViewItem()) {
if(auto delegate = parent->self()) return *delegate;
}
return nothing;
}
auto pListViewCell::_setState() -> void {
auto pTableViewCell::_setState() -> void {
if(auto parent = _parent()) {
if(auto grandparent = parent->_parent()) {
grandparent->lock();

View File

@@ -1,9 +1,9 @@
#if defined(Hiro_ListView)
#if defined(Hiro_TableView)
namespace hiro {
struct pListViewCell : pObject {
Declare(ListViewCell, Object)
struct pTableViewCell : pObject {
Declare(TableViewCell, Object)
auto setAlignment(Alignment alignment) -> void;
auto setBackgroundColor(Color color) -> void;
@@ -14,7 +14,7 @@ struct pListViewCell : pObject {
auto setIcon(const image& icon) -> void;
auto setText(const string& text) -> void;
auto _parent() -> maybe<pListViewItem&>;
auto _parent() -> maybe<pTableViewItem&>;
auto _setState() -> void;
};

View File

@@ -0,0 +1,99 @@
#if defined(Hiro_TableView)
namespace hiro {
auto pTableViewColumn::construct() -> void {
}
auto pTableViewColumn::destruct() -> void {
}
auto pTableViewColumn::setActive() -> void {
//unsupported
}
auto pTableViewColumn::setAlignment(Alignment alignment) -> void {
_setState();
}
auto pTableViewColumn::setBackgroundColor(Color color) -> void {
_setState();
}
auto pTableViewColumn::setEditable(bool editable) -> void {
//unsupported
}
auto pTableViewColumn::setExpandable(bool expandable) -> void {
_setState();
}
auto pTableViewColumn::setFont(const Font& font) -> void {
_setState();
}
auto pTableViewColumn::setForegroundColor(Color color) -> void {
_setState();
}
auto pTableViewColumn::setHorizontalAlignment(double alignment) -> void {
_setState();
}
auto pTableViewColumn::setIcon(const image& icon) -> void {
//unsupported
}
auto pTableViewColumn::setResizable(bool resizable) -> void {
_setState();
}
auto pTableViewColumn::setSortable(bool sortable) -> void {
_setState();
}
auto pTableViewColumn::setText(const string& text) -> void {
_setState();
}
auto pTableViewColumn::setVerticalAlignment(double alignment) -> void {
_setState();
}
auto pTableViewColumn::setVisible(bool visible) -> void {
_setState();
}
auto pTableViewColumn::setWidth(signed width) -> void {
_setState();
}
auto pTableViewColumn::_parent() -> maybe<pTableViewHeader&> {
if(auto parent = self().parentTableViewHeader()) {
if(auto delegate = parent->self()) return *delegate;
}
return nothing;
}
auto pTableViewColumn::_setState() -> void {
if(auto header = _parent()) {
if(auto parent = header->_parent()) {
parent->qtTableView->header()->setResizeMode(self().offset(), state().resizable ? QHeaderView::Interactive : QHeaderView::Fixed);
bool clickable = false;
for(auto& column : header->state().columns) clickable |= column->state.sortable;
parent->qtTableView->header()->setClickable(clickable);
parent->qtTableView->headerItem()->setText(self().offset(), QString::fromUtf8(state().text));
parent->qtTableView->setColumnHidden(self().offset(), !self().visible());
for(auto& item : parent->state().items) {
if(auto cell = item->cell(self().offset())) {
if(auto self = cell->self()) self->_setState();
}
}
}
}
}
}
#endif

View File

@@ -1,9 +1,9 @@
#if defined(Hiro_ListView)
#if defined(Hiro_TableView)
namespace hiro {
struct pListViewColumn : pObject {
Declare(ListViewColumn, Object)
struct pTableViewColumn : pObject {
Declare(TableViewColumn, Object)
auto setActive() -> void;
auto setAlignment(Alignment alignment) -> void;
@@ -21,7 +21,7 @@ struct pListViewColumn : pObject {
auto setVisible(bool visible) -> void;
auto setWidth(signed width) -> void;
auto _parent() -> maybe<pListViewHeader&>;
auto _parent() -> maybe<pTableViewHeader&>;
auto _setState() -> void;
};

View File

@@ -0,0 +1,43 @@
#if defined(Hiro_TableView)
namespace hiro {
auto pTableViewHeader::construct() -> void {
}
auto pTableViewHeader::destruct() -> void {
}
auto pTableViewHeader::append(sTableViewColumn column) -> void {
_setState();
}
auto pTableViewHeader::remove(sTableViewColumn column) -> void {
_setState();
}
auto pTableViewHeader::setVisible(bool visible) -> void {
_setState();
}
auto pTableViewHeader::_parent() -> maybe<pTableView&> {
if(auto parent = self().parentTableView()) {
if(auto delegate = parent->self()) return *delegate;
}
return nothing;
}
auto pTableViewHeader::_setState() -> void {
if(auto parent = _parent()) {
//parent->qtTableView->setAlternatingRowColors(self().columnCount() >= 2);
parent->qtTableView->setColumnCount(self().columnCount());
parent->qtTableView->setHeaderHidden(!self().visible());
for(auto& column : state().columns) {
if(auto self = column->self()) self->_setState();
}
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
#if defined(Hiro_TableView)
namespace hiro {
struct pTableViewHeader : pObject {
Declare(TableViewHeader, Object)
auto append(sTableViewColumn column) -> void;
auto remove(sTableViewColumn column) -> void;
auto setVisible(bool visible) -> void override;
auto _parent() -> maybe<pTableView&>;
auto _setState() -> void;
};
}
#endif

View File

@@ -0,0 +1,66 @@
#if defined(Hiro_TableView)
namespace hiro {
auto pTableViewItem::construct() -> void {
}
auto pTableViewItem::destruct() -> void {
if(auto parent = _parent()) parent->lock();
if(qtItem) {
delete qtItem;
qtItem = nullptr;
}
if(auto parent = _parent()) parent->unlock();
}
auto pTableViewItem::append(sTableViewCell cell) -> void {
_setState();
}
auto pTableViewItem::remove(sTableViewCell cell) -> void {
_setState();
}
auto pTableViewItem::setAlignment(Alignment alignment) -> void {
_setState();
}
auto pTableViewItem::setBackgroundColor(Color color) -> void {
_setState();
}
auto pTableViewItem::setFont(const Font& font) -> void {
_setState();
}
auto pTableViewItem::setForegroundColor(Color color) -> void {
_setState();
}
auto pTableViewItem::setSelected(bool selected) -> void {
_setState();
}
auto pTableViewItem::_parent() -> maybe<pTableView&> {
if(auto parent = self().parentTableView()) {
if(auto delegate = parent->self()) return *delegate;
}
return nothing;
}
auto pTableViewItem::_setState() -> void {
if(auto parent = _parent()) {
qtItem->setSelected(state().selected);
if(state().selected) {
parent->qtTableView->setCurrentItem(qtItem);
}
for(auto& cell : state().cells) {
if(auto self = cell->self()) self->_setState();
}
}
}
}
#endif

View File

@@ -1,19 +1,19 @@
#if defined(Hiro_ListView)
#if defined(Hiro_TableView)
namespace hiro {
struct pListViewItem : pObject {
Declare(ListViewItem, Object)
struct pTableViewItem : pObject {
Declare(TableViewItem, Object)
auto append(sListViewCell cell) -> void;
auto remove(sListViewCell cell) -> void;
auto append(sTableViewCell cell) -> void;
auto remove(sTableViewCell cell) -> void;
auto setAlignment(Alignment alignment) -> void;
auto setBackgroundColor(Color color) -> void;
auto setFont(const Font& font) -> void override;
auto setForegroundColor(Color color) -> void;
auto setSelected(bool selected) -> void;
auto _parent() -> maybe<pListView&>;
auto _parent() -> maybe<pTableView&>;
auto _setState() -> void;
QTreeWidgetItem* qtItem = nullptr;

View File

@@ -1,23 +1,23 @@
#if defined(Hiro_ListView)
#if defined(Hiro_TableView)
namespace hiro {
auto pListView::construct() -> void {
qtWidget = qtListView = new QtListView(*this);
qtListView->setAllColumnsShowFocus(true);
qtListView->setContextMenuPolicy(Qt::CustomContextMenu);
qtListView->setRootIsDecorated(false);
qtListView->setHeaderHidden(true);
qtListView->header()->setMovable(false);
auto pTableView::construct() -> void {
qtWidget = qtTableView = new QtTableView(*this);
qtTableView->setAllColumnsShowFocus(true);
qtTableView->setContextMenuPolicy(Qt::CustomContextMenu);
qtTableView->setRootIsDecorated(false);
qtTableView->setHeaderHidden(true);
qtTableView->header()->setMovable(false);
qtListViewDelegate = new QtListViewDelegate(*this);
qtListView->setItemDelegate(qtListViewDelegate);
qtTableViewDelegate = new QtTableViewDelegate(*this);
qtTableView->setItemDelegate(qtTableViewDelegate);
qtListView->connect(qtListView, SIGNAL(itemActivated(QTreeWidgetItem*, int)), SLOT(onActivate()));
qtListView->connect(qtListView, SIGNAL(itemSelectionChanged()), SLOT(onChange()));
qtListView->connect(qtListView, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(onContext()));
qtListView->connect(qtListView->header(), SIGNAL(sectionClicked(int)), SLOT(onSort(int)));
qtListView->connect(qtListView, SIGNAL(itemChanged(QTreeWidgetItem*, int)), SLOT(onToggle(QTreeWidgetItem*, int)));
qtTableView->connect(qtTableView, SIGNAL(itemActivated(QTreeWidgetItem*, int)), SLOT(onActivate()));
qtTableView->connect(qtTableView, SIGNAL(itemSelectionChanged()), SLOT(onChange()));
qtTableView->connect(qtTableView, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(onContext()));
qtTableView->connect(qtTableView->header(), SIGNAL(sectionClicked(int)), SLOT(onSort(int)));
qtTableView->connect(qtTableView, SIGNAL(itemChanged(QTreeWidgetItem*, int)), SLOT(onToggle(QTreeWidgetItem*, int)));
setBackgroundColor(state().backgroundColor);
setBatchable(state().batchable);
@@ -27,14 +27,14 @@ auto pListView::construct() -> void {
pWidget::construct();
}
auto pListView::destruct() -> void {
delete qtListViewDelegate;
delete qtListView;
qtWidget = qtListView = nullptr;
qtListViewDelegate = nullptr;
auto pTableView::destruct() -> void {
delete qtTableViewDelegate;
delete qtTableView;
qtWidget = qtTableView = nullptr;
qtTableViewDelegate = nullptr;
}
auto pListView::append(sListViewHeader header) -> void {
auto pTableView::append(sTableViewHeader header) -> void {
lock();
if(auto self = header->self()) {
self->_setState();
@@ -42,22 +42,22 @@ auto pListView::append(sListViewHeader header) -> void {
unlock();
}
auto pListView::append(sListViewItem item) -> void {
auto pTableView::append(sTableViewItem item) -> void {
lock();
if(auto self = item->self()) {
self->qtItem = new QTreeWidgetItem(qtListView);
self->qtItem = new QTreeWidgetItem(qtTableView);
self->_setState();
}
unlock();
}
auto pListView::remove(sListViewHeader header) -> void {
auto pTableView::remove(sTableViewHeader header) -> void {
}
auto pListView::remove(sListViewItem item) -> void {
auto pTableView::remove(sTableViewItem item) -> void {
}
auto pListView::resizeColumns() -> void {
auto pTableView::resizeColumns() -> void {
lock();
if(auto& header = state().header) {
@@ -72,7 +72,7 @@ auto pListView::resizeColumns() -> void {
}
signed maximumWidth = self().geometry().width() - 6;
if(auto scrollBar = qtListView->verticalScrollBar()) {
if(auto scrollBar = qtTableView->verticalScrollBar()) {
if(scrollBar->isVisible()) maximumWidth -= scrollBar->geometry().width();
}
@@ -84,50 +84,50 @@ auto pListView::resizeColumns() -> void {
for(auto column : range(header->columnCount())) {
signed width = widths[column];
if(header->column(column).expandable()) width += expandWidth;
qtListView->setColumnWidth(column, width);
qtTableView->setColumnWidth(column, width);
}
}
unlock();
}
auto pListView::setAlignment(Alignment alignment) -> void {
auto pTableView::setAlignment(Alignment alignment) -> void {
}
auto pListView::setBackgroundColor(Color color) -> void {
auto pTableView::setBackgroundColor(Color color) -> void {
if(color) {
QPalette palette = qtListView->palette();
QPalette palette = qtTableView->palette();
palette.setColor(QPalette::Base, QColor(color.red(), color.green(), color.blue()));
palette.setColor(QPalette::AlternateBase, QColor(max(0, (signed)color.red() - 17), max(0, (signed)color.green() - 17), max(0, (signed)color.blue() - 17)));
qtListView->setPalette(palette);
qtListView->setAutoFillBackground(true);
qtTableView->setPalette(palette);
qtTableView->setAutoFillBackground(true);
} else {
//todo: set default color
}
}
auto pListView::setBatchable(bool batchable) -> void {
auto pTableView::setBatchable(bool batchable) -> void {
lock();
qtListView->setSelectionMode(batchable ? QAbstractItemView::ExtendedSelection : QAbstractItemView::SingleSelection);
qtTableView->setSelectionMode(batchable ? QAbstractItemView::ExtendedSelection : QAbstractItemView::SingleSelection);
unlock();
}
auto pListView::setBordered(bool bordered) -> void {
qtListView->repaint();
auto pTableView::setBordered(bool bordered) -> void {
qtTableView->repaint();
}
auto pListView::setForegroundColor(Color color) -> void {
auto pTableView::setForegroundColor(Color color) -> void {
if(color) {
QPalette palette = qtListView->palette();
QPalette palette = qtTableView->palette();
palette.setColor(QPalette::Text, QColor(color.red(), color.green(), color.blue()));
qtListView->setPalette(palette);
qtTableView->setPalette(palette);
} else {
//todo: set default color
}
}
//called on resize/show events
auto pListView::_onSize() -> void {
auto pTableView::_onSize() -> void {
//resize columns only if at least one column is expandable
if(auto& header = state().header) {
for(auto& column : header->state.columns) {
@@ -136,7 +136,7 @@ auto pListView::_onSize() -> void {
}
}
auto pListView::_width(unsigned column) -> unsigned {
auto pTableView::_width(unsigned column) -> unsigned {
if(auto& header = state().header) {
if(auto width = header->column(column).width()) return width;
unsigned width = 1;
@@ -150,12 +150,12 @@ auto pListView::_width(unsigned column) -> unsigned {
return 1;
}
auto pListView::_widthOfColumn(unsigned _column) -> unsigned {
auto pTableView::_widthOfColumn(unsigned _column) -> unsigned {
unsigned width = 8;
if(auto& header = state().header) {
if(auto column = header->column(_column)) {
if(auto& icon = column->state.icon) {
width += icon.width() + 2;
width += icon.width() + 4;
}
if(auto& text = column->state.text) {
width += pFont::size(column->font(true), text).width();
@@ -165,15 +165,15 @@ auto pListView::_widthOfColumn(unsigned _column) -> unsigned {
return width;
}
auto pListView::_widthOfCell(unsigned _row, unsigned _column) -> unsigned {
auto pTableView::_widthOfCell(unsigned _row, unsigned _column) -> unsigned {
unsigned width = 8;
if(auto item = self().item(_row)) {
if(auto cell = item->cell(_column)) {
if(cell->state.checkable) {
width += 16 + 2;
width += 16 + 4;
}
if(auto& icon = cell->state.icon) {
width += icon.width() + 2;
width += icon.width() + 4;
}
if(auto& text = cell->state.text) {
width += pFont::size(cell->font(true), text).width();
@@ -183,11 +183,11 @@ auto pListView::_widthOfCell(unsigned _row, unsigned _column) -> unsigned {
return width;
}
auto QtListView::onActivate() -> void {
auto QtTableView::onActivate() -> void {
if(!p.locked()) p.self().doActivate();
}
auto QtListView::onChange() -> void {
auto QtTableView::onChange() -> void {
for(auto& item : p.state().items) {
item->state.selected = false;
if(auto self = item->self()) {
@@ -197,11 +197,11 @@ auto QtListView::onChange() -> void {
if(!p.locked()) p.self().doChange();
}
auto QtListView::onContext() -> void {
auto QtTableView::onContext() -> void {
if(!p.locked()) p.self().doContext();
}
auto QtListView::onSort(int columnNumber) -> void {
auto QtTableView::onSort(int columnNumber) -> void {
if(auto& header = p.state().header) {
if(auto column = header->column(columnNumber)) {
if(!p.locked() && column.sortable()) p.self().doSort(column);
@@ -209,7 +209,7 @@ auto QtListView::onSort(int columnNumber) -> void {
}
}
auto QtListView::onToggle(QTreeWidgetItem* qtItem, int column) -> void {
auto QtTableView::onToggle(QTreeWidgetItem* qtItem, int column) -> void {
for(auto& item : p.state().items) {
if(auto self = item->self()) {
if(qtItem == self->qtItem) {
@@ -222,25 +222,25 @@ auto QtListView::onToggle(QTreeWidgetItem* qtItem, int column) -> void {
}
}
auto QtListView::mousePressEvent(QMouseEvent* event) -> void {
auto QtTableView::mousePressEvent(QMouseEvent* event) -> void {
QTreeWidget::mousePressEvent(event);
if(event->button() == Qt::RightButton) onContext();
}
auto QtListView::resizeEvent(QResizeEvent* event) -> void {
auto QtTableView::resizeEvent(QResizeEvent* event) -> void {
QTreeWidget::resizeEvent(event);
p._onSize();
}
auto QtListView::showEvent(QShowEvent* event) -> void {
auto QtTableView::showEvent(QShowEvent* event) -> void {
QTreeWidget::showEvent(event);
p._onSize();
}
QtListViewDelegate::QtListViewDelegate(pListView& p) : QStyledItemDelegate(p.qtListView), p(p) {
QtTableViewDelegate::QtTableViewDelegate(pTableView& p) : QStyledItemDelegate(p.qtTableView), p(p) {
}
auto QtListViewDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const -> void {
auto QtTableViewDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const -> void {
QStyledItemDelegate::paint(painter, option, index);
if(p.state().bordered) {
QPen pen;

View File

@@ -1,14 +1,14 @@
#if defined(Hiro_ListView)
#if defined(Hiro_TableView)
namespace hiro {
struct pListView : pWidget {
Declare(ListView, Widget)
struct pTableView : pWidget {
Declare(TableView, Widget)
auto append(sListViewHeader header) -> void;
auto append(sListViewItem item) -> void;
auto remove(sListViewHeader header) -> void;
auto remove(sListViewItem item) -> void;
auto append(sTableViewHeader header) -> void;
auto append(sTableViewItem item) -> void;
auto remove(sTableViewHeader header) -> void;
auto remove(sTableViewItem item) -> void;
auto resizeColumns() -> void;
auto setAlignment(Alignment alignment) -> void;
auto setBackgroundColor(Color color) -> void;
@@ -21,8 +21,8 @@ struct pListView : pWidget {
auto _widthOfColumn(unsigned column) -> unsigned;
auto _widthOfCell(unsigned row, unsigned column) -> unsigned;
QtListView* qtListView = nullptr;
QtListViewDelegate* qtListViewDelegate = nullptr;
QtTableView* qtTableView = nullptr;
QtTableViewDelegate* qtTableViewDelegate = nullptr;
};
}