Crossfire Server, Trunk
FaceComboBox.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include "FaceComboBox.h"
14 #include "CREPixmap.h"
15 #include "AssetsManager.h"
16 #include "assets.h"
17 
18 FaceComboBox::FaceComboBox(QWidget* parent, bool allowNone) : QComboBox(parent)
19 {
20  QStringList names;
21  if (allowNone)
22  {
23  names << "(none)";
24  addItem(QIcon(), "(none)", QVariant::fromValue<void*>(nullptr));
25  }
26 
27  getManager()->faces()->each([this, &names] (const Face* face) {
28  if (face->number == 0)
29  return;
30  addItem(CREPixmap::getIcon(face->number), face->name, QVariant::fromValue(static_cast<void*>(const_cast<Face*>(face))));
31  names << face->name;
32  });
33 
34  setEditable(true);
35  setInsertPolicy(QComboBox::NoInsert);
36  setCompleter(new QCompleter(names, this));
37  completer()->setFilterMode(Qt::MatchContains);
38  completer()->setCaseSensitivity(Qt::CaseInsensitive);
39 }
40 
42 {
43 }
44 
45 void FaceComboBox::setFace(const Face* face)
46 {
47  setCurrentIndex(findData(QVariant::fromValue(static_cast<void*>(const_cast<Face*>(face)))));
48 }
49 
50 const Face* FaceComboBox::face() const
51 {
52  return static_cast<const Face*>(currentData().value<void*>());
53 }
Face::name
sstring name
Definition: face.h:19
Face
Definition: face.h:14
FaceComboBox::FaceComboBox
FaceComboBox(QWidget *parent, bool allowNone)
Definition: FaceComboBox.cpp:18
AssetsManager.h
CREPixmap::getIcon
static QIcon getIcon(uint16_t faceNumber)
Definition: CREPixmap.cpp:65
getManager
AssetsManager * getManager()
Definition: assets.cpp:305
Face::number
uint16_t number
Definition: face.h:15
FaceComboBox::setFace
void setFace(const Face *face)
Definition: FaceComboBox.cpp:45
AssetsManager::faces
Faces * faces()
Definition: AssetsManager.h:39
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:158
assets.h
FaceComboBox::face
const Face face
Definition: FaceComboBox.h:27
FaceComboBox.h
FaceComboBox::~FaceComboBox
virtual ~FaceComboBox()
Definition: FaceComboBox.cpp:41
names
const char *const names[]
Definition: AssetOriginAndCreationDialog.cpp:24
CREPixmap.h