mirror of https://github.com/qTox/qTox.git
Browse Source
TriKriSta (12): feat: add a button to search feat: add form for search feat: add text search feat: edit load history for search feat: remove search button and add line in context menu feat: add search in text in group chats feat: optimise search in history feat: add hot keys for search style: change code in searchInText fix: add search symbol ' in history refactor: rename hideButton to searchHideButton refactor: add/delete checks in search codepull/4953/merge
20 changed files with 805 additions and 5 deletions
@ -0,0 +1,128 @@
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
Copyright © 2015-2016 by The qTox Project Contributors |
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||
|
||||
qTox is libre software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
qTox is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "searchform.h" |
||||
#include "src/widget/style.h" |
||||
#include <QHBoxLayout> |
||||
#include <QPushButton> |
||||
#include <QKeyEvent> |
||||
|
||||
SearchForm::SearchForm(QWidget* parent) : QWidget(parent) |
||||
{ |
||||
QHBoxLayout *layout = new QHBoxLayout(); |
||||
searchLine = new LineEdit(); |
||||
|
||||
upButton = createButton("searchUpButton", "green"); |
||||
downButton = createButton("searchDownButton", "green"); |
||||
hideButton = createButton("searchHideButton", "red"); |
||||
|
||||
layout->setMargin(0); |
||||
layout->addWidget(searchLine); |
||||
layout->addWidget(upButton); |
||||
layout->addWidget(downButton); |
||||
layout->addWidget(hideButton); |
||||
|
||||
setLayout(layout); |
||||
|
||||
connect(searchLine, &LineEdit::textChanged, this, &SearchForm::changedSearchPhrase); |
||||
connect(searchLine, &LineEdit::clickEnter, this, &SearchForm::clickedUp); |
||||
connect(searchLine, &LineEdit::clickShiftEnter, this, &SearchForm::clickedDown); |
||||
connect(searchLine, &LineEdit::clickEsc, this, &SearchForm::clickedHide); |
||||
|
||||
connect(upButton, &QPushButton::clicked, this, &SearchForm::clickedUp); |
||||
connect(downButton, &QPushButton::clicked, this, &SearchForm::clickedDown); |
||||
connect(hideButton, &QPushButton::clicked, this, &SearchForm::clickedHide); |
||||
} |
||||
|
||||
void SearchForm::removeSearchPhrase() |
||||
{ |
||||
searchLine->setText(""); |
||||
} |
||||
|
||||
QString SearchForm::getSearchPhrase() const |
||||
{ |
||||
return searchPhrase; |
||||
} |
||||
|
||||
void SearchForm::setFocusEditor() |
||||
{ |
||||
searchLine->setFocus(); |
||||
} |
||||
|
||||
void SearchForm::showEvent(QShowEvent* event) |
||||
{ |
||||
QWidget::showEvent(event); |
||||
emit visibleChanged(); |
||||
} |
||||
|
||||
QPushButton *SearchForm::createButton(const QString& name, const QString& state) |
||||
{ |
||||
QPushButton* btn = new QPushButton(); |
||||
btn->setAttribute(Qt::WA_LayoutUsesWidgetRect); |
||||
btn->setObjectName(name); |
||||
btn->setProperty("state", state); |
||||
btn->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css"))); |
||||
|
||||
return btn; |
||||
} |
||||
|
||||
void SearchForm::changedSearchPhrase(const QString& text) |
||||
{ |
||||
searchPhrase = text; |
||||
emit searchInBegin(searchPhrase); |
||||
} |
||||
|
||||
void SearchForm::clickedUp() |
||||
{ |
||||
emit searchUp(searchPhrase); |
||||
} |
||||
|
||||
void SearchForm::clickedDown() |
||||
{ |
||||
emit searchDown(searchPhrase); |
||||
} |
||||
|
||||
void SearchForm::clickedHide() |
||||
{ |
||||
hide(); |
||||
emit visibleChanged(); |
||||
} |
||||
|
||||
LineEdit::LineEdit(QWidget* parent) : QLineEdit(parent) |
||||
{ |
||||
} |
||||
|
||||
void LineEdit::keyPressEvent(QKeyEvent* event) |
||||
{ |
||||
int key = event->key(); |
||||
|
||||
if ((key == Qt::Key_Enter || key == Qt::Key_Return)) { |
||||
if ((event->modifiers() & Qt::ShiftModifier)) { |
||||
emit clickShiftEnter(); |
||||
} else { |
||||
emit clickEnter(); |
||||
} |
||||
} else if (key == Qt::Key_Escape) { |
||||
emit clickEsc(); |
||||
} |
||||
|
||||
QLineEdit::keyPressEvent(event); |
||||
} |
||||
|
||||
|
@ -0,0 +1,81 @@
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
Copyright © 2015-2016 by The qTox Project Contributors |
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||
|
||||
qTox is libre software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
qTox is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License |
||||
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef SEARCHFORM_H |
||||
#define SEARCHFORM_H |
||||
|
||||
#include <QWidget> |
||||
#include <QLineEdit> |
||||
|
||||
class QPushButton; |
||||
class LineEdit; |
||||
|
||||
class SearchForm final : public QWidget |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
explicit SearchForm(QWidget* parent = nullptr); |
||||
void removeSearchPhrase(); |
||||
QString getSearchPhrase() const; |
||||
void setFocusEditor(); |
||||
|
||||
protected: |
||||
virtual void showEvent(QShowEvent* event) final override; |
||||
|
||||
private: |
||||
// TODO: Merge with 'createButton' from chatformheader.cpp
|
||||
QPushButton* createButton(const QString& name, const QString& state); |
||||
|
||||
QPushButton* upButton; |
||||
QPushButton* downButton; |
||||
QPushButton* hideButton; |
||||
LineEdit* searchLine; |
||||
|
||||
QString searchPhrase; |
||||
|
||||
private slots: |
||||
void changedSearchPhrase(const QString& text); |
||||
void clickedUp(); |
||||
void clickedDown(); |
||||
void clickedHide(); |
||||
|
||||
signals: |
||||
void searchInBegin(const QString& phrase); |
||||
void searchUp(const QString& phrase); |
||||
void searchDown(const QString& phrase); |
||||
void visibleChanged(); |
||||
}; |
||||
|
||||
class LineEdit : public QLineEdit |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
LineEdit(QWidget* parent = nullptr); |
||||
|
||||
protected: |
||||
virtual void keyPressEvent(QKeyEvent* event) final override; |
||||
|
||||
signals: |
||||
void clickEnter(); |
||||
void clickShiftEnter(); |
||||
void clickEsc(); |
||||
}; |
||||
|
||||
#endif // SEARCHFORM_H
|
Loading…
Reference in new issue