Skip to content

Commit

Permalink
fix: ItemListView and Selector style adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
sithlord48 committed Jun 8, 2024
1 parent 06c79dc commit 5c78434
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
29 changes: 28 additions & 1 deletion src/widgets/data/ItemListView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: LGPL-3.0-or-later

#include <ItemListView.h>

#include <QEvent>
#include <QHeaderView>
#include <QScrollBar>
Expand All @@ -18,6 +17,7 @@ ItemListView::ItemListView(QWidget *parent)
setSelectionBehavior(QAbstractItemView::SelectRows);
setEditTriggers(QAbstractItemView::AllEditTriggers);
setItemDelegate(new ItemSelectionDelegate(this));
horizontalHeader()->setStretchLastSection(true);

ItemSelector itemSelector;
m_columnWidth[0] = itemSelector.combo_type_width();
Expand All @@ -31,6 +31,9 @@ ItemListView::ItemListView(QWidget *parent)
itemSelector.close();
itemSelector.deleteLater();

if (style()->name() == "oxygen")
setFixedWidth(width() + 8);

}

void ItemListView::setModel(QAbstractItemModel *model)
Expand Down Expand Up @@ -80,6 +83,30 @@ int ItemListView::sizeHintForColumn(int column)
return m_columnWidth[column];
}

void ItemListView::changeEvent(QEvent *e)
{
if (e->type() == QEvent::StyleChange) {
ItemSelector itemSelector;
m_columnWidth[0] = itemSelector.combo_type_width();
m_columnWidth[1] = itemSelector.combo_item_width();
m_columnWidth[2] = itemSelector.qty_width();
setFixedWidth(itemSelector.sizeHint().width() + verticalScrollBar()->sizeHint().width());
verticalHeader()->setDefaultSectionSize(itemSelector.height());
itemSelector.close();
itemSelector.deleteLater();
setColumnWidth(0, m_columnWidth[0]);
setColumnWidth(1, m_columnWidth[1]);
setColumnWidth(2, m_columnWidth[2]);
if (style()->name() == "breeze")
setFixedWidth(width() + 4);
if (style()->name() == "oxygen")
setFixedWidth(width() + 8);
} else {
QWidget::changeEvent(e);
}
adjustSize();
}

void ItemListView::setMaximumItemQty(int itemQtyLimit)
{
if(m_itemQtyLimit == itemQtyLimit)
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/data/ItemListView.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class FF7TKWIDGETS_EXPORT ItemListView : public QTableView
bool viewportEvent(QEvent *event);
void destroyTooltip();
int sizeHintForColumn(int column);
protected:
void changeEvent(QEvent *e);
private:
int m_itemQtyLimit = 127;
bool m_editableItemCombo = false;
Expand Down
16 changes: 15 additions & 1 deletion src/widgets/data/ItemSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void ItemSelector::init_display()
btn_remove->setIconSize(iconSize);
btn_remove->setIcon(QIcon::fromTheme(QStringLiteral("edit-clear"), QPixmap(":/common/edit-clear")));
btn_remove->setToolTip(tr("Empty Item"));
btn_remove->setFixedWidth((iconSize.width()*2));
btn_remove->setFixedWidth((fontMetrics().height()*2));
btn_remove->setShortcut(QKeySequence::Delete);

init_data(); //before setting layout set dat
Expand Down Expand Up @@ -114,6 +114,19 @@ void ItemSelector::btn_remove_clicked()
Q_EMIT itemChanged(current_item);
}

void ItemSelector::changeEvent(QEvent *e)
{
if (e->type() == QEvent::StyleChange) {
adjustSize();
} else if (e->type() == QEvent::FontChange) {
qDebug() << "Font Change";
sb_qty->setFixedWidth(fontMetrics().horizontalAdvance(QStringLiteral("WWWW")) + 3);
btn_remove->setFixedWidth((fontMetrics().height()*2));
} else {
QWidget::changeEvent(e);
}
}

void ItemSelector::setFilter(int type)
{
type++;//for hiding no filter.
Expand Down Expand Up @@ -263,6 +276,7 @@ void ItemSelector::setFixedHeight(int h)
combo_type->setFixedHeight(h);
combo_item->setFixedHeight(h);
btn_remove->setFixedHeight(h);
QWidget::setFixedHeight(h);
}

void ItemSelector::setFixedWidth(int w)
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/data/ItemSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ private slots:
void comboItem_changed(int index);
void sb_qty_changed(int qty);
void btn_remove_clicked();
protected:
void changeEvent(QEvent *e);
private:
void init_display();
void init_connections();
Expand Down

0 comments on commit 5c78434

Please sign in to comment.