ff7tk  0.02
Toolkit for making FF7 Tools
ItemSelector.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // copyright 2012 -2016 Chris Rizzitello <sithlord48@gmail.com> //
3 // //
4 // This file is part of FF7tk //
5 // //
6 // FF7tk is free software: you can redistribute it and/or modify //
7 // it under the terms of the GNU General Public License as published by //
8 // the Free Software Foundation, either version 3 of the License, or //
9 // (at your option) any later version. //
10 // //
11 // FF7tk is distributed in the hope that it will be useful, //
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
14 // GNU General Public License for more details. //
15 /****************************************************************************/
16 #include "ItemSelector.h"
17 
18 ItemSelector::ItemSelector(qreal Scale,QWidget *parent): QWidget(parent)
19 {
20  scale=Scale;
21  Items = new FF7Item;
22  init_display();
24 }
26 {
27  combo_type = new QComboBox;
28  combo_item = new QComboBox;
29 
30  sb_qty = new QSpinBox;
31  sb_qty->setAlignment(Qt::AlignCenter);
32  sb_qty->setMinimum(1);
33  sb_qty->setMaximum(127);
34  sb_qty->setToolTip("");
35  sb_qty->setWrapping(true);
36 
37  btn_remove = new QPushButton();
38  btn_remove->setIcon(QIcon::fromTheme(QString("edit-clear"),QPixmap(":/common/edit-clear")));
39  btn_remove->setToolTip(tr("Empty Item"));
40  btn_remove->setFixedWidth(fontMetrics().width(QString("WW")));
41  btn_remove->setShortcut(QKeySequence::Delete);
42 
43  init_data(); //before setting layout set dat
44  QHBoxLayout *layout = new QHBoxLayout;
45  layout->setContentsMargins(0,0,0,0);
46  layout->setSpacing(0);
47  layout->addWidget(combo_type);
48  layout->addWidget(combo_item);
49  layout->addWidget(sb_qty);
50  layout->addWidget(btn_remove);
51  this->setLayout(layout);
52  this->adjustSize();
53 }
54 void ItemSelector::setMaximumQty(int maxQty){sb_qty->setMaximum(maxQty);}
55 
57 {
58  connect(combo_type,SIGNAL(currentIndexChanged(int)),this,SLOT(setFilter(int)));
59  connect(combo_item,SIGNAL(currentIndexChanged(int)),this,SLOT(comboItem_changed(int)));
60  connect(sb_qty,SIGNAL(valueChanged(int)),this,SLOT(sb_qty_changed(int)));
61  connect(btn_remove,SIGNAL(clicked()),this,SLOT(btn_remove_clicked()));
62 }
64 {
65  combo_type->addItem(Items->icon(FF7Item::Potion),tr(""));
66  combo_type->addItem(Items->icon(FF7Item::BronzeBangle),tr(""));
67  combo_type->addItem(Items->icon(FF7Item::Ribbon),tr(""));
68  combo_type->addItem(Items->icon(FF7Item::BusterSword),tr(""));
69  combo_type->addItem(Items->icon(FF7Item::GatlingGun),tr(""));
70  combo_type->addItem(Items->icon(FF7Item::GodsHand),tr(""));
71  combo_type->addItem(Items->icon(FF7Item::AdamanClip),tr(""));
72  combo_type->addItem(Items->icon(FF7Item::StrikingStaff),tr(""));
73  combo_type->addItem(Items->icon(FF7Item::Mop),tr(""));
75  combo_type->addItem(Items->icon(FF7Item::CrystalMphone),tr(""));
76  combo_type->addItem(Items->icon(FF7Item::SupershotST),tr(""));
77  sb_qty->setEnabled(false);
78  //Fill Combo_Item (all items type is 0 or no filter defalut)
79  for(int i=0;i<320;i++){combo_item->addItem(Items->icon(i),Items->name(i));}
80  combo_type->setCurrentIndex(-1);
81  combo_item->setCurrentIndex(-1);
83 }
85 {
86  combo_item->blockSignals(true);
87  combo_type->setCurrentIndex(-1);
88  combo_item->setCurrentIndex(-1);
89  combo_item->blockSignals(false);
90  sb_qty->setEnabled(false);
93 }
95 {
96  type++;//for hiding no filter.
97  int id = Items->itemId(current_item);
98  combo_item->blockSignals(true);
99  combo_item->clear();
100  for(int i=0;i<320;i++)
101  {
102  if(type !=FF7Item::Unknown){if(Items->type(i) == type){combo_item->addItem(Items->icon(i),Items->name(i));}}
103  else{combo_item->addItem(Items->icon(i),Items->name(i));}
104  }
105 
108  else{combo_item->setCurrentIndex(-1);}
109  this->layout()->update();
110  combo_item->blockSignals(false);
111 }
113 {
114  if(sb_qty->maximum()==127)
115  {
116  if(combo_item->currentText()==Items->name(FF7Item::Masamune)){sb_qty->setMaximum(126);}
117  else{sb_qty->setMaximum(127);}
118  }
119 
120  int offset = type_offset(combo_type->currentIndex()+1);
121  if(index+offset != Items->itemId(current_item))
122  {
124  else{current_item=Items->itemEncode(index+offset,Items->itemQty(current_item));}
125  if(current_item ==FF7Item::EmptyItemData){sb_qty->setEnabled(false);}
126  else{sb_qty->setEnabled(true);}
127  emit(item_changed(current_item));
128  }
129 }
130 void ItemSelector::setCurrentItem(int id,int qty)
131 {
132 
133  if(id<0 || id >319 || qty <0 || qty >127){if(id!=FF7Item::EmptyItem){return;}}
134  this->blockSignals(true);
135  if(id == FF7Item::Masamune && qty == 127){qty =126;}
136  if(id == FF7Item::EmptyItem)
137  {
138  btn_remove->blockSignals(true);
140  btn_remove->blockSignals(false);
141  }
142  else
143  {
144  combo_type->setCurrentIndex(Items->type(id)-1);
145  combo_item->setCurrentIndex(id-type_offset(Items->type(id)));
146  sb_qty->setValue(qty);
147  current_item=Items->itemEncode(id,qty);
148  }
149  this->blockSignals(false);
150 
151 }
152 void ItemSelector::setCurrentItem(quint16 ff7item)
153 {
154  this->blockSignals(true);
155  if((Items->itemId(ff7item) == FF7Item::Masamune) && (Items->itemQty(ff7item) ==127)){ ff7item = Items->itemEncode(FF7Item::Masamune,126);}
156 
157  if(ff7item ==FF7Item::EmptyItemData)
158  {
159  btn_remove->blockSignals(true);
161  btn_remove->blockSignals(false);
162  }
163  else
164  {
165  combo_type->setCurrentIndex(Items->type(Items->itemId(ff7item))-1);
166  combo_item->setCurrentIndex(Items->itemId(ff7item) - type_offset(Items->type(Items->itemId(ff7item))));
167  sb_qty->setValue(Items->itemQty(ff7item));
168  current_item=ff7item;
169  }
170  this->blockSignals(false);
171 }
173 {
174  if(qty != Items->itemQty(current_item))
175  {
177  emit(item_changed(current_item));
178  }
179 }
180 
181 
183 {
184  int offset = 0;
185  switch(type)
186  {//set offset for type.
187  case FF7Item::Unknown: offset =0; break;
188  case FF7Item::Item: offset =0; break;
189  case FF7Item::Armor: offset =256; break;
190  case FF7Item::Accessory: offset =288; break;
191  case FF7Item::WeaponCloud: offset =128; break;
192  case FF7Item::WeaponBarret: offset =160; break;
193  case FF7Item::WeaponTifa: offset =144; break;
194  case FF7Item::WeaponRed: offset =176; break;
195  case FF7Item::WeaponAerith: offset =190; break;
196  case FF7Item::WeaponCid: offset =201; break;
197  case FF7Item::WeaponYuffie: offset=215; break;
198  case FF7Item::WeaponCait: offset=229; break;
199  case FF7Item::WeaponVincent: offset=242; break;
200  default: offset= -1; break;//ERROR INVALID TYPE.
201  }
202  return offset;
203 }
204 int ItemSelector::id(void){return (int)Items->itemId(current_item);}
207 int ItemSelector::qty_width(){return sb_qty->width()+btn_remove->width();}
208 
210 {
211  sb_qty->setFixedHeight(h);
212  combo_type->setFixedHeight(h);
213  combo_item->setFixedHeight(h);
214  btn_remove->setFixedHeight(h);
215 }
217 {
218  combo_item->setEditable(editable);
219  combo_item->setInsertPolicy(QComboBox::NoInsert);
220 }
void setFilter(int type)
void setCurrentItem(quint16 ff7item)
void init_display()
qint8 type(int id)
get an items type
Definition: FF7Item.cpp:21
void item_changed(quint16)
QSpinBox * sb_qty
Definition: ItemSelector.h:59
Class containg all kinds of info about items in FF7.
Definition: FF7Item.h:99
void sb_qty_changed(int qty)
quint8 itemQty(quint16 item)
get item id from item
Definition: FF7Item.cpp:157
quint16 current_item
Definition: ItemSelector.h:61
int combo_item_width()
FF7Item * Items
Definition: ItemSelector.h:56
void setEditableItemCombo(bool editable)
int type_offset(int type)
QString name(int id)
get an items name
Definition: FF7Item.cpp:19
void init_data()
quint16 itemId(quint16 item)
get item id from item
Definition: FF7Item.cpp:151
quint16 itemEncode(quint16 id, quint8 qty)
Encode quint16 in to a rawitem.
Definition: FF7Item.cpp:111
QComboBox * combo_item
Definition: ItemSelector.h:58
QPushButton * btn_remove
Definition: ItemSelector.h:60
void setFixedHeight(int h)
void setMaximumQty(int maxQty)
void comboItem_changed(int index)
ItemSelector(qreal Scale=1, QWidget *parent=0)
void btn_remove_clicked()
QIcon icon(int id)
get an items picture as qicon
Definition: FF7Item.cpp:23
int combo_type_width()
void init_connections()
QComboBox * combo_type
Definition: ItemSelector.h:57