mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
feat: add message if text not found
This commit is contained in:
parent
eb92ce15f1
commit
4253301c56
|
@ -557,6 +557,7 @@ void ChatForm::onSearchUp(const QString& phrase, const ParameterSearch& paramete
|
|||
const QDateTime newBaseDate = history->getDateWhereFindPhrase(pk, earliestMessage, phrase, parameter);
|
||||
|
||||
if (!newBaseDate.isValid()) {
|
||||
emit messageNotFoundShow(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -568,7 +569,9 @@ void ChatForm::onSearchUp(const QString& phrase, const ParameterSearch& paramete
|
|||
|
||||
void ChatForm::onSearchDown(const QString& phrase, const ParameterSearch& parameter)
|
||||
{
|
||||
searchInText(phrase, parameter, false);
|
||||
if (!searchInText(phrase, parameter, false)) {
|
||||
emit messageNotFoundShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
void ChatForm::onFileSendFailed(uint32_t friendId, const QString& fname)
|
||||
|
|
|
@ -224,6 +224,7 @@ GenericChatForm::GenericChatForm(const Contact* contact, QWidget* parent)
|
|||
connect(searchForm, &SearchForm::searchUp, this, &GenericChatForm::onSearchUp);
|
||||
connect(searchForm, &SearchForm::searchDown, this, &GenericChatForm::onSearchDown);
|
||||
connect(searchForm, &SearchForm::visibleChanged, this, &GenericChatForm::onSearchTriggered);
|
||||
connect(this, &GenericChatForm::messageNotFoundShow, searchForm, &SearchForm::showMessageNotFound);
|
||||
|
||||
connect(chatWidget, &ChatLog::workerTimeoutFinished, this, &GenericChatForm::onContinueSearch);
|
||||
|
||||
|
|
|
@ -83,6 +83,7 @@ signals:
|
|||
void sendAction(uint32_t, QString);
|
||||
void chatAreaCleared();
|
||||
void messageInserted();
|
||||
void messageNotFoundShow(const bool searchUp);
|
||||
|
||||
public slots:
|
||||
void focusInput();
|
||||
|
|
|
@ -214,12 +214,16 @@ void GroupChatForm::searchInBegin(const QString& phrase, const ParameterSearch&
|
|||
|
||||
void GroupChatForm::onSearchUp(const QString& phrase, const ParameterSearch& parameter)
|
||||
{
|
||||
searchInText(phrase, parameter, true);
|
||||
if (!searchInText(phrase, parameter, true)) {
|
||||
emit messageNotFoundShow(true);
|
||||
}
|
||||
}
|
||||
|
||||
void GroupChatForm::onSearchDown(const QString& phrase, const ParameterSearch& parameter)
|
||||
{
|
||||
searchInText(phrase, parameter, false);
|
||||
if (!searchInText(phrase, parameter, false)) {
|
||||
emit messageNotFoundShow(false);
|
||||
}
|
||||
}
|
||||
|
||||
void GroupChatForm::onScreenshotClicked()
|
||||
|
|
|
@ -23,15 +23,31 @@
|
|||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QKeyEvent>
|
||||
|
||||
const QString STATE_NAME[] = {
|
||||
QString{},
|
||||
QStringLiteral("green"),
|
||||
QStringLiteral("red"),
|
||||
};
|
||||
|
||||
SearchForm::SearchForm(QWidget* parent) : QWidget(parent)
|
||||
{
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
QHBoxLayout* layoutNavigation = new QHBoxLayout();
|
||||
QHBoxLayout* layoutMessage = new QHBoxLayout();
|
||||
QSpacerItem *lSpacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Ignored);
|
||||
QSpacerItem *rSpacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Ignored);
|
||||
searchLine = new LineEdit();
|
||||
settings = new SearchSettingsForm();
|
||||
messageLabel = new QLabel();
|
||||
|
||||
settings->setVisible(false);
|
||||
messageLabel->setProperty("state", QStringLiteral("red"));
|
||||
messageLabel->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/labels.css")));
|
||||
messageLabel->setText(tr("The text could not be found."));
|
||||
messageLabel->setVisible(false);
|
||||
|
||||
settingsButton = createButton("searchSettingsButton", "green");
|
||||
upButton = createButton("searchUpButton", "green");
|
||||
|
@ -51,6 +67,11 @@ SearchForm::SearchForm(QWidget* parent) : QWidget(parent)
|
|||
layout->addLayout(layoutNavigation);
|
||||
layout->addWidget(settings);
|
||||
|
||||
layoutMessage->addSpacerItem(lSpacer);
|
||||
layoutMessage->addWidget(messageLabel);
|
||||
layoutMessage->addSpacerItem(rSpacer);
|
||||
layout->addLayout(layoutMessage);
|
||||
|
||||
startButton->setHidden(true);
|
||||
|
||||
setLayout(layout);
|
||||
|
@ -66,7 +87,7 @@ SearchForm::SearchForm(QWidget* parent) : QWidget(parent)
|
|||
connect(startButton, &QPushButton::clicked, this, &SearchForm::clickedStart);
|
||||
connect(settingsButton, &QPushButton::clicked, this, &SearchForm::clickedSearch);
|
||||
|
||||
connect(settings, &SearchSettingsForm::updateSettings, this, &SearchForm::changedButtons);
|
||||
connect(settings, &SearchSettingsForm::updateSettings, this, &SearchForm::changedState);
|
||||
}
|
||||
|
||||
void SearchForm::removeSearchPhrase()
|
||||
|
@ -128,8 +149,25 @@ ParameterSearch SearchForm::getAndCheckParametrSearch()
|
|||
return ParameterSearch();
|
||||
}
|
||||
|
||||
void SearchForm::setStateName(QPushButton *btn, ToolButtonState state)
|
||||
{
|
||||
const int index = static_cast<int>(state);
|
||||
btn->setProperty("state", STATE_NAME[index]);
|
||||
btn->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css")));
|
||||
btn->setEnabled(index != 0);
|
||||
}
|
||||
|
||||
void SearchForm::useBeginState()
|
||||
{
|
||||
setStateName(upButton, ToolButtonState::Common);
|
||||
setStateName(downButton, ToolButtonState::Common);
|
||||
messageLabel->setVisible(false);
|
||||
}
|
||||
|
||||
void SearchForm::changedSearchPhrase(const QString& text)
|
||||
{
|
||||
useBeginState();
|
||||
|
||||
if (searchPhrase == text) {
|
||||
return;
|
||||
}
|
||||
|
@ -144,16 +182,21 @@ void SearchForm::changedSearchPhrase(const QString& text)
|
|||
isChangedPhrase = true;
|
||||
if (isActiveSettings) {
|
||||
if (startButton->isHidden()) {
|
||||
changedButtons(true);
|
||||
changedState(true);
|
||||
}
|
||||
} else {
|
||||
isSearchInBegin = true;
|
||||
emit searchInBegin(searchPhrase, getAndCheckParametrSearch());
|
||||
}
|
||||
}
|
||||
|
||||
void SearchForm::clickedUp()
|
||||
{
|
||||
setStateName(downButton, ToolButtonState::Common);
|
||||
messageLabel->setVisible(false);
|
||||
|
||||
if (startButton->isHidden()) {
|
||||
isSearchInBegin = false;
|
||||
emit searchUp(searchPhrase, getAndCheckParametrSearch());
|
||||
} else {
|
||||
clickedStart();
|
||||
|
@ -162,7 +205,11 @@ void SearchForm::clickedUp()
|
|||
|
||||
void SearchForm::clickedDown()
|
||||
{
|
||||
setStateName(upButton, ToolButtonState::Common);
|
||||
messageLabel->setVisible(false);
|
||||
|
||||
if (startButton->isHidden()) {
|
||||
isSearchInBegin = false;
|
||||
emit searchDown(searchPhrase, getAndCheckParametrSearch());
|
||||
} else {
|
||||
clickedStart();
|
||||
|
@ -177,7 +224,8 @@ void SearchForm::clickedHide()
|
|||
|
||||
void SearchForm::clickedStart()
|
||||
{
|
||||
changedButtons(false);
|
||||
changedState(false);
|
||||
isSearchInBegin = true;
|
||||
emit searchInBegin(searchPhrase, getAndCheckParametrSearch());
|
||||
}
|
||||
|
||||
|
@ -185,18 +233,17 @@ void SearchForm::clickedSearch()
|
|||
{
|
||||
isActiveSettings = !isActiveSettings;
|
||||
settings->setVisible(isActiveSettings);
|
||||
useBeginState();
|
||||
|
||||
if (isActiveSettings) {
|
||||
settingsButton->setProperty("state", QStringLiteral("red"));
|
||||
setStateName(settingsButton, ToolButtonState::Active);
|
||||
} else {
|
||||
settingsButton->setProperty("state", QStringLiteral("green"));
|
||||
changedButtons(false);
|
||||
setStateName(settingsButton, ToolButtonState::Common);
|
||||
changedState(false);
|
||||
}
|
||||
settingsButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css")));
|
||||
settingsButton->update();
|
||||
}
|
||||
|
||||
void SearchForm::changedButtons(const bool isUpdate)
|
||||
void SearchForm::changedState(const bool isUpdate)
|
||||
{
|
||||
if (isUpdate) {
|
||||
startButton->setHidden(false);
|
||||
|
@ -207,6 +254,21 @@ void SearchForm::changedButtons(const bool isUpdate)
|
|||
upButton->setHidden(false);
|
||||
downButton->setHidden(false);
|
||||
}
|
||||
|
||||
useBeginState();
|
||||
}
|
||||
|
||||
void SearchForm::showMessageNotFound(const bool searchUp)
|
||||
{
|
||||
if (isSearchInBegin) {
|
||||
setStateName(upButton, ToolButtonState::Disabled);
|
||||
setStateName(downButton, ToolButtonState::Disabled);
|
||||
} else if (searchUp) {
|
||||
setStateName(upButton, ToolButtonState::Disabled);
|
||||
} else {
|
||||
setStateName(downButton, ToolButtonState::Disabled);
|
||||
}
|
||||
messageLabel->setVisible(true);
|
||||
}
|
||||
|
||||
LineEdit::LineEdit(QWidget* parent) : QLineEdit(parent)
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "searchtypes.h"
|
||||
|
||||
class QPushButton;
|
||||
class QLabel;
|
||||
class LineEdit;
|
||||
class SearchSettingsForm;
|
||||
|
||||
|
@ -32,6 +33,12 @@ class SearchForm final : public QWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum class ToolButtonState {
|
||||
Disabled = 0, // Grey
|
||||
Common = 1, // Green
|
||||
Active = 2, // Red
|
||||
};
|
||||
|
||||
explicit SearchForm(QWidget* parent = nullptr);
|
||||
void removeSearchPhrase();
|
||||
QString getSearchPhrase() const;
|
||||
|
@ -46,6 +53,8 @@ private:
|
|||
// TODO: Merge with 'createButton' from chatformheader.cpp
|
||||
QPushButton* createButton(const QString& name, const QString& state);
|
||||
ParameterSearch getAndCheckParametrSearch();
|
||||
void setStateName(QPushButton* btn, ToolButtonState state);
|
||||
void useBeginState();
|
||||
|
||||
QPushButton* settingsButton;
|
||||
QPushButton* upButton;
|
||||
|
@ -54,12 +63,14 @@ private:
|
|||
QPushButton* startButton;
|
||||
LineEdit* searchLine;
|
||||
SearchSettingsForm* settings;
|
||||
QLabel* messageLabel;
|
||||
|
||||
QString searchPhrase;
|
||||
ParameterSearch parameter;
|
||||
|
||||
bool isActiveSettings{false};
|
||||
bool isChangedPhrase{false};
|
||||
bool isSearchInBegin{true};
|
||||
|
||||
private slots:
|
||||
void changedSearchPhrase(const QString& text);
|
||||
|
@ -68,7 +79,10 @@ private slots:
|
|||
void clickedHide();
|
||||
void clickedStart();
|
||||
void clickedSearch();
|
||||
void changedButtons(const bool isUpdate);
|
||||
void changedState(const bool isUpdate);
|
||||
|
||||
public slots:
|
||||
void showMessageNotFound(const bool searchUp);
|
||||
|
||||
signals:
|
||||
void searchInBegin(const QString& phrase, const ParameterSearch& parameter);
|
||||
|
|
|
@ -7,3 +7,8 @@ QLabel:disabled
|
|||
{
|
||||
color: #ddd;
|
||||
}
|
||||
|
||||
QLabel[state="red"]
|
||||
{
|
||||
color: #e84747;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user