Crossfire Server, Trunk
FaceComboBox.cpp
Go to the documentation of this file.
1 #include "FaceComboBox.h"
2 #include "CREPixmap.h"
3 #include "AssetsManager.h"
4 #include "assets.h"
5 
6 FaceComboBox::FaceComboBox(QWidget* parent, bool allowNone) : QComboBox(parent)
7 {
8  QStringList names;
9  if (allowNone)
10  {
11  names << "(none)";
12  addItem(QIcon(), "(none)", QVariant::fromValue<void*>(nullptr));
13  }
14 
15  getManager()->faces()->each([this, &names] (const Face* face) {
16  if (face->number == 0)
17  return;
18  addItem(CREPixmap::getIcon(face->number), face->name, QVariant::fromValue(static_cast<void*>(const_cast<Face*>(face))));
19  names << face->name;
20  });
21 
22  setEditable(true);
23  setInsertPolicy(QComboBox::NoInsert);
24  setCompleter(new QCompleter(names, this));
25  completer()->setFilterMode(Qt::MatchContains);
26 }
27 
29 {
30 }
31 
32 void FaceComboBox::setFace(const Face* face)
33 {
34  setCurrentIndex(findData(QVariant::fromValue(static_cast<void*>(const_cast<Face*>(face)))));
35 }
36 
37 const Face* FaceComboBox::face() const
38 {
39  return static_cast<const Face*>(currentData().value<void*>());
40 }
Face::name
sstring name
Definition: face.h:19
Face
Definition: face.h:14
FaceComboBox::FaceComboBox
FaceComboBox(QWidget *parent, bool allowNone)
Definition: FaceComboBox.cpp:6
AssetsManager.h
CREPixmap::getIcon
static QIcon getIcon(uint16_t faceNumber)
Definition: CREPixmap.cpp:55
FaceComboBox::face
const Face * face() const
Definition: FaceComboBox.cpp:37
getManager
AssetsManager * getManager()
Definition: assets.cpp:329
Face::number
uint16_t number
Definition: face.h:15
FaceComboBox::setFace
void setFace(const Face *face)
Definition: FaceComboBox.cpp:32
AssetsManager::faces
Faces * faces()
Definition: AssetsManager.h:39
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:135
guildbuy.names
list names
Definition: guildbuy.py:18
assets.h
FaceComboBox.h
FaceComboBox::~FaceComboBox
virtual ~FaceComboBox()
Definition: FaceComboBox.cpp:28
CREPixmap.h