diff --git a/docroot/style.css b/docroot/style.css index 8a3295b..45bcb2d 100644 --- a/docroot/style.css +++ b/docroot/style.css @@ -185,3 +185,23 @@ main { background-color: lightgray; margin: 0.1em 0.2em; } +.selectBoxes-drop-down-trigger { + cursor: pointer; +} +.selectBoxes-drop-down-trigger > .selectBoxes-dropdown { + display: none; + position: absolute; + top: 1.2em; + overflow: auto; + background: RGBA(248, 248, 248, 0.8); + max-height: 10em; + z-index: 1; + border: 1px solid #666; + box-shadow: 2px 2px 4px #666; + padding: 2px; + left: 9em; +} +.selectBoxes-drop-down-trigger:hover > .selectBoxes-dropdown { + display: inline-block; +} + diff --git a/src/app.cpp b/src/app.cpp index b4cbdf9..e4a6679 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -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("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 App::setupSearchFields(Wt::WVBoxLayout * return {minAgeEdit, maxAgeEdit}; } -std::pair App::setupCountryDropDown(Wt::WVBoxLayout *contentLayout) { - auto countryDropDown = std::make_unique(); - countryDropDown->setInline(true); - countryDropDown->setStyleClass("countries-drop-down"); - auto countryDropDownContainer = countryDropDown.get(); - auto countryOpenList = addSearchItemLine(contentLayout, "Country", std::move(countryDropDown)); - countryDropDownContainer->hide(); - countryOpenList->clicked().connect([=]() { if (countryDropDownContainer->isHidden()) { countryDropDownContainer->show();} else { countryDropDownContainer->hide(); } }); - countryOpenList->setText("All"); +std::pair App::setupCountryDropDown(Wt::WVBoxLayout *contentLayout) { + auto countryOpenList = addSearchItemLine(contentLayout, "Country"); + countryOpenList->addNew("All"); + countryOpenList->setStyleClass("selectBoxes-drop-down-trigger"); + auto countryDropDown = countryOpenList->addNew(); + countryDropDown->setStyleClass("selectBoxes-dropdown"); + countryOpenList->setToolTip("Select the countries you'll search for"); std::map 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 App::setupGendersDropDown(Wt::WVBoxLayout *contentLayout) { - auto gendersDropDown = std::make_unique(); - gendersDropDown->setInline(true); - gendersDropDown->setStyleClass("countries-drop-down"); - auto gendersDropDownContainer = gendersDropDown.get(); - auto gendersOpenList = addSearchItemLine(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 App::setupGendersDropDown(Wt::WVBoxLayout *contentLayout) { + auto gendersOpenList = addSearchItemLine(contentLayout, "Genders"); + gendersOpenList->addNew("All"); + gendersOpenList->setStyleClass("selectBoxes-drop-down-trigger"); + auto gendersDropDown = gendersOpenList->addNew(); + gendersDropDown->setStyleClass("selectBoxes-dropdown"); + gendersOpenList->setToolTip("Select the genders you'll search for"); + addItem("All", gendersDropDown, gendersOpenList, &searchFields.gender, true); std::map 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 *saveItems, bool isSelected) { + +void App::addItem(const std::string& country, Wt::WContainerWidget *dropDownContainer, Wt::WContainerWidget *container, std::unordered_set *saveItems, bool isSelected) { auto menuItem = dropDownContainer->addNew(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 *saveItems) { +void App::itemChanged(Wt::WCheckBox *item, Wt::WContainerWidget *dropDownContainer, Wt::WContainerWidget *container, std::unordered_set *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 { diff --git a/src/app.h b/src/app.h index a452312..17354d1 100644 --- a/src/app.h +++ b/src/app.h @@ -129,6 +129,7 @@ private: void startSearch(); void showSearch(Wt::Json::Object broadcast); template Class *addSearchItemLine(Wt::WVBoxLayout *layout, std::string label, std::unique_ptr 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 setupGendersDropDown(Wt::WVBoxLayout *contentLayout); - std::pair setupCountryDropDown(Wt::WVBoxLayout *contentLayout); + std::pair setupGendersDropDown(Wt::WVBoxLayout *contentLayout); + std::pair setupCountryDropDown(Wt::WVBoxLayout *contentLayout); std::pair setupSearchFields(Wt::WVBoxLayout *contentLayout); Wt::WVBoxLayout *resetSearchFields(); - void itemChanged(Wt::WCheckBox *item, Wt::WContainerWidget *dropDownContainer, Wt::WPushButton *openButton, std::unordered_set *saveItems); - void addItem(const std::string &country, Wt::WContainerWidget *dropDownContainer, Wt::WPushButton *openListButton, std::unordered_set *saveItems, bool isSelected = false); + void itemChanged(Wt::WCheckBox *item, Wt::WContainerWidget *dropDownContainer, Wt::WContainerWidget *openButton, std::unordered_set *saveItems); + void addItem(const std::string &country, Wt::WContainerWidget *dropDownContainer, Wt::WContainerWidget *container, std::unordered_set *saveItems, bool isSelected = false); void addUserItemToLayout(Wt::WVBoxLayout *layout, Wt::Json::Object userObject); std::unordered_set gendersListToShortGendersList(std::unordered_set gendersList); std::string genderShortOfGender(const std::string incomingGender);