closes #1: Favorite buttons has been extended with category buttons.
This commit is contained in:
+122
-8
@@ -145,6 +145,7 @@ void ShopForm::loadLast()
|
||||
m_commodityModel->setData(srv.allSellableItems());
|
||||
ui->commodityTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||
ui->commodityTable->setColumnHidden(4, true);
|
||||
ui->commodityTable->setColumnHidden(5, true);
|
||||
ui->commodityTable->setColumnHidden(2, true);
|
||||
ui->commodityTable->setColumnWidth(3, 90);
|
||||
|
||||
@@ -167,22 +168,20 @@ void ShopForm::loadButtons(const ShopSettingsPtr& settings)
|
||||
Service<FavoritItem> srvFav;
|
||||
QMap<QString, FavoritItemPtr> btnMap;
|
||||
|
||||
foreach (QWidget *child, ui->favorites->findChildren<QWidget*>()) {
|
||||
if (child->objectName() != "directSale")
|
||||
{
|
||||
delete child;
|
||||
}
|
||||
}
|
||||
clearFavButtons();
|
||||
|
||||
foreach (FavoritItemPtr item, srvFav.all()) {
|
||||
btnMap[item->favButtonName()] = item;
|
||||
}
|
||||
|
||||
ShopService srv;
|
||||
auto allItems = srv.allSellableItems();
|
||||
|
||||
for (int i = 0; i < settings->favBtnRows(); i++)
|
||||
{
|
||||
for (int j = 0; j < settings->favBtnCols(); j++)
|
||||
{
|
||||
FavButton *btn = new FavButton(ui->favorites);
|
||||
auto *btn = new QToolButton(ui->favorites);
|
||||
QString btnName = QString::number(i) + "_" + QString::number(j);
|
||||
btn->setObjectName(btnName);
|
||||
|
||||
@@ -197,6 +196,16 @@ void ShopForm::loadButtons(const ShopSettingsPtr& settings)
|
||||
if (btnMap[btnName] != nullptr)
|
||||
{
|
||||
btn->setText(btnMap[btnName]->shortName());
|
||||
|
||||
auto shItem = std::find_if(allItems.begin(), allItems.end(),[btnMap, btn](auto it) -> bool {
|
||||
return btnMap[btn->objectName()]->refId() == it->id() && btnMap[btn->objectName()]->pluginId() == it->pluginId();
|
||||
});
|
||||
|
||||
if (shItem != allItems.end()) {
|
||||
btn->setStyleSheet("background: " + shItem->data()->color() + ";");
|
||||
btn->update();
|
||||
}
|
||||
|
||||
connect(btn, &FavButton::clicked, [this, btnMap, btn](bool){
|
||||
FavoritItemPtr item = btnMap[btn->objectName()];
|
||||
|
||||
@@ -249,6 +258,7 @@ void ShopForm::setupForm()
|
||||
loadLast();
|
||||
fillReceiptCombo();
|
||||
loadButtons(settings);
|
||||
loadCatButtons();
|
||||
}
|
||||
|
||||
void ShopForm::on_directSale_clicked()
|
||||
@@ -514,7 +524,7 @@ void ShopForm::recalculate()
|
||||
|
||||
if (m_voucher->status() == Voucher::NEW && m_voucher->id() == 0)
|
||||
{
|
||||
srv.saveVoucher(m_voucher);
|
||||
srv.save(m_voucher);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -664,3 +674,107 @@ void ShopForm::on_actualReceipt_customContextMenuRequested(const QPoint &pos)
|
||||
QPoint globalPos = ui->actualReceipt->mapToGlobal(pos);
|
||||
m_itemCtxMenu->exec(globalPos);
|
||||
}
|
||||
|
||||
void ShopForm::clearFavButtons() {
|
||||
foreach (QWidget *child, ui->favorites->findChildren<QWidget*>()) {
|
||||
if (child->objectName() != "directSale")
|
||||
{
|
||||
delete child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShopForm::loadFavCatButtons(const QString& category) {
|
||||
SettingsService srvSettings("SHOP");
|
||||
ShopSettingsPtr settings = srvSettings.loadSettings<ShopSettings>();
|
||||
|
||||
if (category.isEmpty()) {
|
||||
loadButtons(settings);
|
||||
return;
|
||||
}
|
||||
|
||||
clearFavButtons();
|
||||
|
||||
ShopService srv;
|
||||
auto all = srv.allSellableItems(category);
|
||||
|
||||
if (all.count() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto square = std::sqrt(all.count());
|
||||
int cols = static_cast<int>(square);
|
||||
int rows = cols;
|
||||
|
||||
if (square - cols != 0) {
|
||||
if (cols > 1) {
|
||||
++rows;
|
||||
} else {
|
||||
++cols;
|
||||
}
|
||||
}
|
||||
|
||||
if (cols * rows < all.count()) {
|
||||
++cols;
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for (int i = 0; i < rows; i++) {
|
||||
for (int j = 0; j < cols; j++) {
|
||||
if (index >= all.count()) {
|
||||
break;
|
||||
}
|
||||
|
||||
auto item = all[index];
|
||||
++index;
|
||||
auto *btn = new QToolButton(ui->favorites);
|
||||
|
||||
if (settings->favBtnSize() > 0)
|
||||
{
|
||||
btn->setMinimumHeight(settings->favBtnSize());
|
||||
btn->setMinimumWidth(settings->favBtnSize());
|
||||
}
|
||||
|
||||
btn->setText(item->shortName());
|
||||
btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
((QGridLayout*)ui->favorites->layout())->addWidget(btn, i + 1, j);
|
||||
|
||||
btn->setStyleSheet("background: " + item->color() + ";");
|
||||
btn->update();
|
||||
|
||||
connect(btn, &QToolButton::clicked, [this, item](bool){
|
||||
addItem(item, 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShopForm::loadCatButtons() {
|
||||
ShopService srv;
|
||||
auto allCat = srv.allCategories();
|
||||
|
||||
for (const auto btnFav : ui->widgetCategories->findChildren<QWidget*>()) {
|
||||
if (btnFav->objectName() != "btnFav") {
|
||||
delete btnFav;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& cat : allCat.keys()) {
|
||||
auto catButton = new QToolButton(ui->widgetCategories);
|
||||
catButton->setText(cat);
|
||||
catButton->setMinimumHeight(45);
|
||||
catButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
catButton->setStyleSheet("background: " + allCat[cat] + ";");
|
||||
catButton->update();
|
||||
|
||||
connect(catButton, &QPushButton::clicked, [this, cat](bool){
|
||||
loadFavCatButtons(cat);
|
||||
});
|
||||
|
||||
ui->widgetCategories->layout()->addWidget(catButton);
|
||||
}
|
||||
}
|
||||
|
||||
void ShopForm::on_btnFav_clicked() {
|
||||
loadFavCatButtons("");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user