mirror of https://github.com/qTox/qTox.git
Browse Source
TriKriSta (20): feat: create widget for search settings feat: use search settings feat: add functions for change title and info in LoadHistoryDialog feat: add startButton in SearchForm chore: install sqlite in travis refactor: remove commented code, use QStringLiteral docs: add documentation for some new functions refactor: change QRegExp on QRegularExpression for some search functions feat: add function for generating a filter for search word only refactor: use const and QStringLiteral style: add labels.css refactor: edit generateFilterWordsOnly refactor: delete sqlite in travis, edit some functions chore: install Qt 5.6 in travis refactor: use Settings, add const refactor: add code for work in Qt5.5 refactor: change text and icons in search forms feat: add message if text not found refactor: add SearchDirection Merge branch 'master' into searchreviewable/pr5305/r1
32 changed files with 1448 additions and 191 deletions
@ -0,0 +1,149 @@
@@ -0,0 +1,149 @@
|
||||
#include "searchsettingsform.h" |
||||
#include "ui_searchsettingsform.h" |
||||
#include "src/persistence/settings.h" |
||||
#include "src/widget/style.h" |
||||
#include "src/widget/form/loadhistorydialog.h" |
||||
|
||||
SearchSettingsForm::SearchSettingsForm(QWidget *parent) : |
||||
QWidget(parent), |
||||
ui(new Ui::SearchSettingsForm) |
||||
{ |
||||
ui->setupUi(this); |
||||
|
||||
ui->choiceDateButton->setEnabled(false); |
||||
ui->startDateLabel->setEnabled(false); |
||||
|
||||
ui->choiceDateButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); |
||||
ui->choiceDateButton->setObjectName(QStringLiteral("choiceDateButton")); |
||||
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css"))); |
||||
|
||||
ui->startDateLabel->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/labels.css"))); |
||||
|
||||
connect(ui->startSearchComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), |
||||
this, &SearchSettingsForm::onStartSearchSelected); |
||||
connect(ui->registerCheckBox, &QCheckBox::clicked, this, &SearchSettingsForm::onRegisterClicked); |
||||
connect(ui->wordsOnlyRadioButton, &QCheckBox::clicked, this, &SearchSettingsForm::onWordsOnlyClicked); |
||||
connect(ui->regularRadioButton, &QCheckBox::clicked, this, &SearchSettingsForm::onRegularClicked); |
||||
connect(ui->choiceDateButton, &QPushButton::clicked, this, &SearchSettingsForm::onChoiceDate); |
||||
} |
||||
|
||||
SearchSettingsForm::~SearchSettingsForm() |
||||
{ |
||||
delete ui; |
||||
} |
||||
|
||||
ParameterSearch SearchSettingsForm::getParameterSearch() |
||||
{ |
||||
ParameterSearch ps; |
||||
|
||||
if (ui->regularRadioButton->isChecked()) { |
||||
ps.filter = FilterSearch::Regular; |
||||
} else if (ui->registerCheckBox->isChecked() && ui->wordsOnlyRadioButton->isChecked()) { |
||||
ps.filter = FilterSearch::RegisterAndWordsOnly; |
||||
} else if (ui->registerCheckBox->isChecked() && ui->regularRadioButton->isChecked()) { |
||||
ps.filter = FilterSearch::RegisterAndRegular; |
||||
} else if (ui->registerCheckBox->isChecked()) { |
||||
ps.filter = FilterSearch::Register; |
||||
} else if (ui->wordsOnlyRadioButton->isChecked()) { |
||||
ps.filter = FilterSearch::WordsOnly; |
||||
} else { |
||||
ps.filter = FilterSearch::None; |
||||
} |
||||
|
||||
switch (ui->startSearchComboBox->currentIndex()) { |
||||
case 0: |
||||
ps.period = PeriodSearch::WithTheEnd; |
||||
break; |
||||
case 1: |
||||
ps.period = PeriodSearch::WithTheFirst; |
||||
break; |
||||
case 2: |
||||
ps.period = PeriodSearch::AfterDate; |
||||
break; |
||||
case 3: |
||||
ps.period = PeriodSearch::BeforeDate; |
||||
break; |
||||
default: |
||||
ps.period = PeriodSearch::WithTheEnd; |
||||
break; |
||||
} |
||||
|
||||
ps.date = startDate; |
||||
ps.isUpdate = isUpdate; |
||||
isUpdate = false; |
||||
|
||||
return ps; |
||||
} |
||||
|
||||
void SearchSettingsForm::updateStartDateLabel() |
||||
{ |
||||
ui->startDateLabel->setText(startDate.toString(Settings::getInstance().getDateFormat())); |
||||
} |
||||
|
||||
void SearchSettingsForm::setUpdate(const bool isUpdate) |
||||
{ |
||||
this->isUpdate = isUpdate; |
||||
emit updateSettings(isUpdate); |
||||
} |
||||
|
||||
void SearchSettingsForm::onStartSearchSelected(const int index) |
||||
{ |
||||
if (index > 1) { |
||||
ui->choiceDateButton->setEnabled(true); |
||||
ui->startDateLabel->setEnabled(true); |
||||
|
||||
ui->choiceDateButton->setProperty("state", QStringLiteral("green")); |
||||
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css"))); |
||||
|
||||
if (startDate.isNull()) { |
||||
startDate = QDate::currentDate(); |
||||
updateStartDateLabel(); |
||||
} |
||||
|
||||
} else { |
||||
ui->choiceDateButton->setEnabled(false); |
||||
ui->startDateLabel->setEnabled(false); |
||||
|
||||
ui->choiceDateButton->setProperty("state", QString()); |
||||
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css"))); |
||||
} |
||||
|
||||
setUpdate(true); |
||||
} |
||||
|
||||
void SearchSettingsForm::onRegisterClicked(const bool checked) |
||||
{ |
||||
Q_UNUSED(checked) |
||||
setUpdate(true); |
||||
} |
||||
|
||||
void SearchSettingsForm::onWordsOnlyClicked(const bool checked) |
||||
{ |
||||
if (checked) { |
||||
ui->regularRadioButton->setChecked(false); |
||||
} |
||||
|
||||
setUpdate(true); |
||||
} |
||||
|
||||
void SearchSettingsForm::onRegularClicked(const bool checked) |
||||
{ |
||||
if (checked) { |
||||
ui->wordsOnlyRadioButton->setChecked(false); |
||||
} |
||||
|
||||
setUpdate(true); |
||||
} |
||||
|
||||
void SearchSettingsForm::onChoiceDate() |
||||
{ |
||||
LoadHistoryDialog dlg; |
||||
dlg.setTitle(tr("Select Date Dialog")); |
||||
dlg.setInfoLabel(tr("Select a date")); |
||||
if (dlg.exec()) { |
||||
startDate = dlg.getFromDate().date(); |
||||
updateStartDateLabel(); |
||||
} |
||||
|
||||
setUpdate(true); |
||||
} |
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
#ifndef SEARCHSETTINGSFORM_H |
||||
#define SEARCHSETTINGSFORM_H |
||||
|
||||
#include <QWidget> |
||||
#include "src/widget/searchtypes.h" |
||||
|
||||
namespace Ui { |
||||
class SearchSettingsForm; |
||||
} |
||||
|
||||
class SearchSettingsForm : public QWidget |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit SearchSettingsForm(QWidget *parent = nullptr); |
||||
~SearchSettingsForm(); |
||||
|
||||
ParameterSearch getParameterSearch(); |
||||
|
||||
private: |
||||
Ui::SearchSettingsForm *ui; |
||||
QDate startDate; |
||||
bool isUpdate{false}; |
||||
|
||||
void updateStartDateLabel(); |
||||
void setUpdate(const bool isUpdate); |
||||
|
||||
private slots: |
||||
void onStartSearchSelected(const int index); |
||||
void onRegisterClicked(const bool checked); |
||||
void onWordsOnlyClicked(const bool checked); |
||||
void onRegularClicked(const bool checked); |
||||
void onChoiceDate(); |
||||
|
||||
signals: |
||||
void updateSettings(const bool isUpdate); |
||||
}; |
||||
|
||||
#endif // SEARCHSETTINGSFORM_H
|
@ -0,0 +1,173 @@
@@ -0,0 +1,173 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>SearchSettingsForm</class> |
||||
<widget class="QWidget" name="SearchSettingsForm"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>473</width> |
||||
<height>84</height> |
||||
</rect> |
||||
</property> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>Form</string> |
||||
</property> |
||||
<layout class="QGridLayout" name="gridLayout"> |
||||
<property name="leftMargin"> |
||||
<number>0</number> |
||||
</property> |
||||
<property name="topMargin"> |
||||
<number>0</number> |
||||
</property> |
||||
<property name="rightMargin"> |
||||
<number>0</number> |
||||
</property> |
||||
<property name="bottomMargin"> |
||||
<number>0</number> |
||||
</property> |
||||
<item row="0" column="0"> |
||||
<widget class="Line" name="line_2"> |
||||
<property name="frameShadow"> |
||||
<enum>QFrame::Plain</enum> |
||||
</property> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="1" column="0"> |
||||
<layout class="QHBoxLayout" name="horizontalLayout_2"> |
||||
<item> |
||||
<widget class="QLabel" name="label"> |
||||
<property name="text"> |
||||
<string>Start search:</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QComboBox" name="startSearchComboBox"> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> |
||||
<horstretch>1</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<item> |
||||
<property name="text"> |
||||
<string>from the end</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>from the beginning</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>after date</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>before date</string> |
||||
</property> |
||||
</item> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QLabel" name="startDateLabel"> |
||||
<property name="text"> |
||||
<string>00.00.0000</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QPushButton" name="choiceDateButton"> |
||||
<property name="text"> |
||||
<string/> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item row="2" column="0"> |
||||
<layout class="QHBoxLayout" name="horizontalLayout"> |
||||
<item> |
||||
<widget class="QCheckBox" name="registerCheckBox"> |
||||
<property name="text"> |
||||
<string>Case sensitive</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QRadioButton" name="wordsOnlyRadioButton"> |
||||
<property name="text"> |
||||
<string>Whole words only</string> |
||||
</property> |
||||
<property name="checkable"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="checked"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<property name="autoRepeat"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<property name="autoExclusive"> |
||||
<bool>false</bool> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QRadioButton" name="regularRadioButton"> |
||||
<property name="text"> |
||||
<string>Use regular expressions</string> |
||||
</property> |
||||
<property name="checkable"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="autoRepeat"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<property name="autoExclusive"> |
||||
<bool>false</bool> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<spacer name="horizontalSpacer"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="sizeHint" stdset="0"> |
||||
<size> |
||||
<width>40</width> |
||||
<height>20</height> |
||||
</size> |
||||
</property> |
||||
</spacer> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item row="3" column="0"> |
||||
<widget class="Line" name="line"> |
||||
<property name="frameShadow"> |
||||
<enum>QFrame::Plain</enum> |
||||
</property> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<resources/> |
||||
<connections/> |
||||
</ui> |
@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
|
||||
#ifndef SEARCHTYPES_H |
||||
#define SEARCHTYPES_H |
||||
|
||||
#include <QDate> |
||||
#include <QRegularExpression> |
||||
|
||||
enum class FilterSearch { |
||||
None, |
||||
Register, |
||||
WordsOnly, |
||||
Regular, |
||||
RegisterAndWordsOnly, |
||||
RegisterAndRegular |
||||
}; |
||||
|
||||
enum class PeriodSearch { |
||||
None, |
||||
WithTheEnd, |
||||
WithTheFirst, |
||||
AfterDate, |
||||
BeforeDate |
||||
}; |
||||
|
||||
enum class SearchDirection { |
||||
Up, |
||||
Down |
||||
}; |
||||
|
||||
struct ParameterSearch { |
||||
FilterSearch filter{FilterSearch::None}; |
||||
PeriodSearch period{PeriodSearch::None}; |
||||
QDate date; |
||||
bool isUpdate{false}; |
||||
|
||||
bool operator ==(const ParameterSearch& other) { |
||||
return filter == other.filter && |
||||
period == other.period && |
||||
date == other.date; |
||||
} |
||||
|
||||
bool operator !=(const ParameterSearch& other) { |
||||
return !(*this == other); |
||||
} |
||||
}; |
||||
|
||||
class SearchExtraFunctions { |
||||
public: |
||||
/**
|
||||
* @brief generateFilterWordsOnly generate string for filter "Whole words only" for correct search phrase |
||||
* containing symbols "\[]/^$.|?*+(){}" |
||||
* @param phrase for search |
||||
* @return new phrase for search |
||||
*/ |
||||
static QString generateFilterWordsOnly(const QString &phrase) { |
||||
QString filter = QRegularExpression::escape(phrase); |
||||
|
||||
const QString symbols = QStringLiteral("\\[]/^$.|?*+(){}"); |
||||
|
||||
if (filter != phrase) { |
||||
if (filter.left(1) != QLatin1String("\\")) { |
||||
filter = QLatin1String("\\b") + filter; |
||||
} else { |
||||
filter = QLatin1String("(^|\\s)") + filter; |
||||
} |
||||
if (!symbols.contains(filter.right(1))) { |
||||
filter += QLatin1String("\\b"); |
||||
} else { |
||||
filter += QLatin1String("($|\\s)"); |
||||
} |
||||
} else { |
||||
filter = QStringLiteral("\\b%1\\b").arg(filter); |
||||
} |
||||
|
||||
return filter; |
||||
} |
||||
}; |
||||
|
||||
#endif //SEARCHTYPES_H
|
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
QLabel |
||||
{ |
||||
color: #000; |
||||
} |
||||
|
||||
QLabel:disabled |
||||
{ |
||||
color: #ddd; |
||||
} |
||||
|
||||
QLabel[state="red"] |
||||
{ |
||||
color: #e84747; |
||||
} |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
Loading…
Reference in new issue