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  completer()->setCaseSensitivity(Qt::CaseInsensitive);
27 }
28 
30 {
31 }
32 
33 void FaceComboBox::setFace(const Face* face)
34 {
35  setCurrentIndex(findData(QVariant::fromValue(static_cast<void*>(const_cast<Face*>(face)))));
36 }
37 
38 const Face* FaceComboBox::face() const
39 {
40  return static_cast<const Face*>(currentData().value<void*>());
41 }
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
getManager
AssetsManager * getManager()
Definition: assets.cpp:333
Face::number
uint16_t number
Definition: face.h:15
FaceComboBox::setFace
void setFace(const Face *face)
Definition: FaceComboBox.cpp:33
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::face
const Face face
Definition: FaceComboBox.h:15
FaceComboBox.h
FaceComboBox::~FaceComboBox
virtual ~FaceComboBox()
Definition: FaceComboBox.cpp:29
CREPixmap.h