Instead of a click button, the lists for genders and country searches

are hovering now
This commit is contained in:
Torsten Schulz
2024-02-23 15:46:05 +01:00
parent 94d2985334
commit 359f379b18
3 changed files with 55 additions and 36 deletions

View File

@@ -539,7 +539,6 @@ Wt::WContainerWidget* App::createSmileyBar(Wt::WContainerWidget* parent, Wt::WLi
}
Wt::WPushButton* App::createSendButton(Wt::WHBoxLayout* inputLayout, Wt::WLineEdit* inputLine) {
setActivity();
auto sendButton = inputLayout->addNew<Wt::WPushButton>("Send");
auto sendMessageFunction = [=, this]() {
sendMessage(inputLine);
@@ -551,6 +550,7 @@ Wt::WPushButton* App::createSendButton(Wt::WHBoxLayout* inputLayout, Wt::WLineEd
}
void App::sendMessage(Wt::WLineEdit *inputLine) {
setActivity();
auto utf8String = inputLine->valueText().trim().toUTF8();
if (utf8String == "") {
return;
@@ -939,49 +939,46 @@ std::pair<Wt::WSpinBox*, Wt::WSpinBox*> App::setupSearchFields(Wt::WVBoxLayout *
return {minAgeEdit, maxAgeEdit};
}
std::pair<Wt::WPushButton*, Wt::WContainerWidget*> App::setupCountryDropDown(Wt::WVBoxLayout *contentLayout) {
auto countryDropDown = std::make_unique<Wt::WContainerWidget>();
countryDropDown->setInline(true);
countryDropDown->setStyleClass("countries-drop-down");
auto countryDropDownContainer = countryDropDown.get();
auto countryOpenList = addSearchItemLine<Wt::WPushButton>(contentLayout, "Country", std::move(countryDropDown));
countryDropDownContainer->hide();
countryOpenList->clicked().connect([=]() { if (countryDropDownContainer->isHidden()) { countryDropDownContainer->show();} else { countryDropDownContainer->hide(); } });
countryOpenList->setText("All");
std::pair<Wt::WContainerWidget*, Wt::WContainerWidget*> App::setupCountryDropDown(Wt::WVBoxLayout *contentLayout) {
auto countryOpenList = addSearchItemLine<Wt::WContainerWidget>(contentLayout, "Country");
countryOpenList->addNew<Wt::WText>("All");
countryOpenList->setStyleClass("selectBoxes-drop-down-trigger");
auto countryDropDown = countryOpenList->addNew<Wt::WContainerWidget>();
countryDropDown->setStyleClass("selectBoxes-dropdown");
countryOpenList->setToolTip("Select the countries you'll search for");
std::map<Wt::WString, Wt::WString> countries = server_.countries();
addItem("All", countryDropDownContainer, countryOpenList, &searchFields.countries, true);
addItem(country, countryDropDownContainer, countryOpenList, &searchFields.countries);
addItem("All", countryDropDown, countryOpenList, &searchFields.countries, true);
addItem(country, countryDropDown, countryOpenList, &searchFields.countries);
for (const auto &itemCountry: countries) {
if (itemCountry.first.toUTF8() != country) {
addItem(itemCountry.first.toUTF8(), countryDropDownContainer, countryOpenList, &searchFields.countries);
addItem(itemCountry.first.toUTF8(), countryDropDown, countryOpenList, &searchFields.countries);
}
}
return {countryOpenList, countryDropDownContainer};
return {countryOpenList, countryDropDown};
}
std::pair<Wt::WPushButton*, Wt::WContainerWidget*> App::setupGendersDropDown(Wt::WVBoxLayout *contentLayout) {
auto gendersDropDown = std::make_unique<Wt::WContainerWidget>();
gendersDropDown->setInline(true);
gendersDropDown->setStyleClass("countries-drop-down");
auto gendersDropDownContainer = gendersDropDown.get();
auto gendersOpenList = addSearchItemLine<Wt::WPushButton>(contentLayout, "Genders", std::move(gendersDropDown));
gendersDropDownContainer->hide();
gendersOpenList->clicked().connect([=]() { if (gendersDropDownContainer->isHidden()) { gendersDropDownContainer->show();} else { gendersDropDownContainer->hide(); } });
gendersOpenList->setText("All");
addItem("All", gendersDropDownContainer, gendersOpenList, &searchFields.gender, true);
std::pair<Wt::WContainerWidget*, Wt::WContainerWidget*> App::setupGendersDropDown(Wt::WVBoxLayout *contentLayout) {
auto gendersOpenList = addSearchItemLine<Wt::WContainerWidget>(contentLayout, "Genders");
gendersOpenList->addNew<Wt::WText>("All");
gendersOpenList->setStyleClass("selectBoxes-drop-down-trigger");
auto gendersDropDown = gendersOpenList->addNew<Wt::WContainerWidget>();
gendersDropDown->setStyleClass("selectBoxes-dropdown");
gendersOpenList->setToolTip("Select the genders you'll search for");
addItem("All", gendersDropDown, gendersOpenList, &searchFields.gender, true);
std::map<Wt::WString, Wt::WString> swappedGenders;
for (const auto& pair : genders_) {
swappedGenders[pair.second] = pair.first;
}
for (const auto &itemGender: swappedGenders) {
addItem(itemGender.first.toUTF8(), gendersDropDownContainer, gendersOpenList, &searchFields.gender);
addItem(itemGender.first.toUTF8(), gendersDropDown, gendersOpenList, &searchFields.gender);
}
return {gendersOpenList, gendersDropDownContainer};
return {gendersOpenList, gendersDropDown};
}
void App::addItem(const std::string& country, Wt::WContainerWidget *dropDownContainer, Wt::WPushButton *openListButton, std::unordered_set<std::string> *saveItems, bool isSelected) {
void App::addItem(const std::string& country, Wt::WContainerWidget *dropDownContainer, Wt::WContainerWidget *container, std::unordered_set<std::string> *saveItems, bool isSelected) {
auto menuItem = dropDownContainer->addNew<Wt::WCheckBox>(country);
menuItem->changed().connect([=, this]() mutable { itemChanged(menuItem, dropDownContainer, openListButton, saveItems); });
menuItem->changed().connect([=, this]() mutable { itemChanged(menuItem, dropDownContainer, container, saveItems); });
menuItem->setInline(false);
if (isSelected) {
menuItem->setChecked();
@@ -1145,7 +1142,7 @@ void App::showPartnerSites() {
}
}
void App::itemChanged(Wt::WCheckBox *item, Wt::WContainerWidget *dropDownContainer, Wt::WPushButton *openButton, std::unordered_set<std::string> *saveItems) {
void App::itemChanged(Wt::WCheckBox *item, Wt::WContainerWidget *dropDownContainer, Wt::WContainerWidget *container, std::unordered_set<std::string> *saveItems) {
saveItems->clear();
bool unselect = (item->text() == "All" && item->isChecked());
for (auto &widgetItem: dropDownContainer->children()) {
@@ -1168,12 +1165,13 @@ void App::itemChanged(Wt::WCheckBox *item, Wt::WContainerWidget *dropDownContain
for (const auto &selected: *saveItems) {
result += (result.empty() ? "" : ", ") + selected;
}
openButton->setText(result);
auto outputWidget = (Wt::WText*)container->children().at(0);
outputWidget->setText(result);
}
void App::restoreSearchFields(Wt::WContainerWidget *searchResultContainer, Wt::WLineEdit *userNameEdit, Wt::WSpinBox *minAgeEdit,
Wt::WSpinBox *maxAgeEdit, Wt::WContainerWidget *countryDropDownContainer, Wt::WContainerWidget *gendersDropDownContainer,
Wt::WPushButton *countryOpenList, Wt::WPushButton *gendersOpenList) {
Wt::WContainerWidget *countryOpenList, Wt::WContainerWidget *gendersOpenList) {
if (!searchFields.set) {
searchFields = Search(searchResultContainer);
} else {

View File

@@ -129,6 +129,7 @@ private:
void startSearch();
void showSearch(Wt::Json::Object broadcast);
template<class Class> Class *addSearchItemLine(Wt::WVBoxLayout *layout, std::string label, std::unique_ptr<Wt::WContainerWidget> additionalItem = nullptr);
Wt::WContainerWidget *addSearchItemContainer(Wt::WVBoxLayout *layout, std::string label);
void openInbox();
bool isNickAllowed(const std::string &nick);
bool compareJsonObjects(const Wt::Json::Object &obj1, const Wt::Json::Object &obj2);
@@ -187,14 +188,14 @@ private:
Wt::WWebWidget *createTextElement(const std::string &writer, const std::string &text, Wt::WContainerWidget *outputContainer, std::string id);
void createImprintContainer(Wt::WVBoxLayout *containerLayout);
Wt::WContainerWidget *setupSearchButton(Wt::WVBoxLayout *contentLayout);
void restoreSearchFields(Wt::WContainerWidget *searchResultContainer, Wt::WLineEdit *userNameEdit, Wt::WSpinBox *minAgeEdit, Wt::WSpinBox *maxAgeEdit, Wt::WContainerWidget *countryDropDownContainer, Wt::WContainerWidget *gendersDropDownContainer, Wt::WPushButton *countryOpenList, Wt::WPushButton *gendersOpenList);
void restoreSearchFields(Wt::WContainerWidget *searchResultContainer, Wt::WLineEdit *userNameEdit, Wt::WSpinBox *minAgeEdit, Wt::WSpinBox *maxAgeEdit, Wt::WContainerWidget *countryDropDownContainer, Wt::WContainerWidget *gendersDropDownContainer, Wt::WContainerWidget *countryOpenList, Wt::WContainerWidget *gendersOpenList);
Wt::WLineEdit *setupNameSearchField(Wt::WVBoxLayout *contentLayout);
std::pair<Wt::WPushButton *, Wt::WContainerWidget *> setupGendersDropDown(Wt::WVBoxLayout *contentLayout);
std::pair<Wt::WPushButton *, Wt::WContainerWidget *> setupCountryDropDown(Wt::WVBoxLayout *contentLayout);
std::pair<Wt::WContainerWidget *, Wt::WContainerWidget *> setupGendersDropDown(Wt::WVBoxLayout *contentLayout);
std::pair<Wt::WContainerWidget *, Wt::WContainerWidget *> setupCountryDropDown(Wt::WVBoxLayout *contentLayout);
std::pair<Wt::WSpinBox*, Wt::WSpinBox*> setupSearchFields(Wt::WVBoxLayout *contentLayout);
Wt::WVBoxLayout *resetSearchFields();
void itemChanged(Wt::WCheckBox *item, Wt::WContainerWidget *dropDownContainer, Wt::WPushButton *openButton, std::unordered_set<std::string> *saveItems);
void addItem(const std::string &country, Wt::WContainerWidget *dropDownContainer, Wt::WPushButton *openListButton, std::unordered_set<std::string> *saveItems, bool isSelected = false);
void itemChanged(Wt::WCheckBox *item, Wt::WContainerWidget *dropDownContainer, Wt::WContainerWidget *openButton, std::unordered_set<std::string> *saveItems);
void addItem(const std::string &country, Wt::WContainerWidget *dropDownContainer, Wt::WContainerWidget *container, std::unordered_set<std::string> *saveItems, bool isSelected = false);
void addUserItemToLayout(Wt::WVBoxLayout *layout, Wt::Json::Object userObject);
std::unordered_set<std::string> gendersListToShortGendersList(std::unordered_set<std::string> gendersList);
std::string genderShortOfGender(const std::string incomingGender);