dolphin/Source/Core/DolphinQt2/SearchBar.cpp
Léo Lam 8d0c15bb97 Qt/Search: Simplify placeholder text
A search box is a common UI element. We don't need to explicitly tell
the user that they need to type a search term. Also,

Let's use the common "Search <items>..." placeholder text instead
and make the string shorter for localisation.
2018-03-24 18:02:17 +01:00

55 lines
1.1 KiB
C++

// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "DolphinQt2/SearchBar.h"
#include <QCheckBox>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
SearchBar::SearchBar(QWidget* parent) : QWidget(parent)
{
CreateWidgets();
ConnectWidgets();
setFixedHeight(32);
setHidden(true);
}
void SearchBar::CreateWidgets()
{
m_search_edit = new QLineEdit;
m_close_button = new QPushButton(tr("Close"));
m_search_edit->setPlaceholderText(tr("Search games..."));
auto* layout = new QHBoxLayout;
layout->addWidget(m_search_edit);
layout->addWidget(m_close_button);
layout->setMargin(0);
setLayout(layout);
}
void SearchBar::Toggle()
{
m_search_edit->clear();
setHidden(isVisible());
if (isVisible())
m_search_edit->setFocus();
else
m_search_edit->clearFocus();
}
void SearchBar::ConnectWidgets()
{
connect(m_search_edit, &QLineEdit::textChanged, this, &SearchBar::Search);
connect(m_close_button, &QPushButton::pressed, this, &SearchBar::Toggle);
}