qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
searchsettingsform.cpp
Go to the documentation of this file.
1 /*
2  Copyright © 2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "searchsettingsform.h"
21 #include "ui_searchsettingsform.h"
23 #include "src/widget/style.h"
25 
27  QWidget(parent),
28  ui(new Ui::SearchSettingsForm)
29 {
30  ui->setupUi(this);
31 
32  ui->choiceDateButton->setEnabled(false);
33  ui->startDateLabel->setEnabled(false);
34 
35  ui->choiceDateButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
36  ui->choiceDateButton->setObjectName(QStringLiteral("choiceDateButton"));
37 
38  reloadTheme();
39 
40 #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
41  connect(ui->startSearchComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
42 #else
43  connect(ui->startSearchComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
44 #endif
46  connect(ui->registerCheckBox, &QCheckBox::clicked, this, &SearchSettingsForm::onRegisterClicked);
47  connect(ui->wordsOnlyRadioButton, &QCheckBox::clicked, this, &SearchSettingsForm::onWordsOnlyClicked);
48  connect(ui->regularRadioButton, &QCheckBox::clicked, this, &SearchSettingsForm::onRegularClicked);
49  connect(ui->choiceDateButton, &QPushButton::clicked, this, &SearchSettingsForm::onChoiceDate);
50 }
51 
53 {
54  delete ui;
55 }
56 
58 {
59  ParameterSearch ps;
60 
61  if (ui->regularRadioButton->isChecked()) {
63  } else if (ui->registerCheckBox->isChecked() && ui->wordsOnlyRadioButton->isChecked()) {
65  } else if (ui->registerCheckBox->isChecked() && ui->regularRadioButton->isChecked()) {
67  } else if (ui->registerCheckBox->isChecked()) {
69  } else if (ui->wordsOnlyRadioButton->isChecked()) {
71  } else {
73  }
74 
75  switch (ui->startSearchComboBox->currentIndex()) {
76  case 0:
78  break;
79  case 1:
81  break;
82  case 2:
84  break;
85  case 3:
87  break;
88  default:
90  break;
91  }
92 
93  ps.date = startDate;
94  ps.isUpdate = isUpdate;
95  isUpdate = false;
96 
97  return ps;
98 }
99 
101 {
102  ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css")));
103  ui->startDateLabel->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/labels.css")));
104 }
105 
107 {
108  ui->startDateLabel->setText(startDate.toString(Settings::getInstance().getDateFormat()));
109 }
110 
111 void SearchSettingsForm::setUpdate(const bool isUpdate)
112 {
113  this->isUpdate = isUpdate;
114  emit updateSettings(isUpdate);
115 }
116 
118 {
119  if (index > 1) {
120  ui->choiceDateButton->setEnabled(true);
121  ui->startDateLabel->setEnabled(true);
122 
123  ui->choiceDateButton->setProperty("state", QStringLiteral("green"));
124  ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css")));
125 
126  if (startDate.isNull()) {
127  startDate = QDate::currentDate();
129  }
130 
131  } else {
132  ui->choiceDateButton->setEnabled(false);
133  ui->startDateLabel->setEnabled(false);
134 
135  ui->choiceDateButton->setProperty("state", QString());
136  ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css")));
137  }
138 
139  setUpdate(true);
140 }
141 
143 {
144  Q_UNUSED(checked)
145  setUpdate(true);
146 }
147 
149 {
150  if (checked) {
151  ui->regularRadioButton->setChecked(false);
152  }
153 
154  setUpdate(true);
155 }
156 
157 void SearchSettingsForm::onRegularClicked(const bool checked)
158 {
159  if (checked) {
160  ui->wordsOnlyRadioButton->setChecked(false);
161  }
162 
163  setUpdate(true);
164 }
165 
167 {
168  LoadHistoryDialog dlg;
169  dlg.setTitle(tr("Select Date Dialog"));
170  dlg.setInfoLabel(tr("Select a date"));
171  if (dlg.exec()) {
172  startDate = dlg.getFromDate().date();
174  }
175 
176  setUpdate(true);
177 }
SearchSettingsForm::onWordsOnlyClicked
void onWordsOnlyClicked(const bool checked)
Definition: searchsettingsform.cpp:148
loadhistorydialog.h
style.h
FilterSearch::Register
@ Register
ParameterSearch::date
QDate date
Definition: searchtypes.h:50
SearchSettingsForm::onChoiceDate
void onChoiceDate()
Definition: searchsettingsform.cpp:166
SearchSettingsForm::onStartSearchSelected
void onStartSearchSelected(const int index)
Definition: searchsettingsform.cpp:117
SearchSettingsForm::ui
Ui::SearchSettingsForm * ui
Definition: searchsettingsform.h:41
FilterSearch::RegisterAndWordsOnly
@ RegisterAndWordsOnly
settings.h
ParameterSearch::filter
FilterSearch filter
Definition: searchtypes.h:48
PeriodSearch::AfterDate
@ AfterDate
PeriodSearch::BeforeDate
@ BeforeDate
ParameterSearch
Definition: searchtypes.h:47
SearchSettingsForm::onRegularClicked
void onRegularClicked(const bool checked)
Definition: searchsettingsform.cpp:157
Settings::getDateFormat
const QString & getDateFormat() const
Definition: settings.cpp:1494
SearchSettingsForm::reloadTheme
void reloadTheme()
Definition: searchsettingsform.cpp:100
SearchSettingsForm::SearchSettingsForm
SearchSettingsForm(QWidget *parent=nullptr)
Definition: searchsettingsform.cpp:26
searchsettingsform.h
PeriodSearch::WithTheEnd
@ WithTheEnd
FilterSearch::None
@ None
Ui
Definition: filetransferwidget.h:30
SearchSettingsForm::getParameterSearch
ParameterSearch getParameterSearch()
Definition: searchsettingsform.cpp:57
ParameterSearch::period
PeriodSearch period
Definition: searchtypes.h:49
SearchSettingsForm::setUpdate
void setUpdate(const bool isUpdate)
Definition: searchsettingsform.cpp:111
SearchSettingsForm::isUpdate
bool isUpdate
Definition: searchsettingsform.h:43
PeriodSearch::WithTheFirst
@ WithTheFirst
LoadHistoryDialog::setInfoLabel
void setInfoLabel(const QString &info)
Definition: loadhistorydialog.cpp:74
Settings::getInstance
static Settings & getInstance()
Returns the singleton instance.
Definition: settings.cpp:88
FilterSearch::WordsOnly
@ WordsOnly
SearchSettingsForm::onRegisterClicked
void onRegisterClicked(const bool checked)
Definition: searchsettingsform.cpp:142
Style::getStylesheet
static const QString getStylesheet(const QString &filename, const QFont &baseFont=QFont())
Definition: style.cpp:165
ParameterSearch::isUpdate
bool isUpdate
Definition: searchtypes.h:51
FilterSearch::RegisterAndRegular
@ RegisterAndRegular
LoadHistoryDialog
Definition: loadhistorydialog.h:31
SearchSettingsForm
Definition: searchsettingsform.h:29
LoadHistoryDialog::setTitle
void setTitle(const QString &title)
Definition: loadhistorydialog.cpp:69
LoadHistoryDialog::getFromDate
QDateTime getFromDate()
Definition: loadhistorydialog.cpp:53
SearchSettingsForm::updateStartDateLabel
void updateStartDateLabel()
Definition: searchsettingsform.cpp:106
SearchSettingsForm::startDate
QDate startDate
Definition: searchsettingsform.h:42
FilterSearch::Regular
@ Regular
SearchSettingsForm::~SearchSettingsForm
~SearchSettingsForm()
Definition: searchsettingsform.cpp:52
SearchSettingsForm::updateSettings
void updateSettings(const bool isUpdate)