Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat: create widget for search settings
Browse files Browse the repository at this point in the history
  • Loading branch information
TriKriSta committed Jun 16, 2018
1 parent 535ffb5 commit 87b340f
Show file tree
Hide file tree
Showing 10 changed files with 368 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ qt5_wrap_ui(${PROJECT_NAME}_FORMS
src/widget/form/loadhistorydialog.ui
src/widget/form/profileform.ui
src/widget/form/removefrienddialog.ui
src/widget/form/searchsettingsform.ui
src/widget/form/setpassworddialog.ui
src/widget/form/settings/aboutsettings.ui
src/widget/form/settings/advancedsettings.ui
Expand Down Expand Up @@ -368,6 +369,8 @@ set(${PROJECT_NAME}_SOURCES
src/widget/form/loadhistorydialog.h
src/widget/form/profileform.cpp
src/widget/form/profileform.h
src/widget/form/searchsettingsform.cpp
src/widget/form/searchsettingsform.h
src/widget/form/setpassworddialog.cpp
src/widget/form/setpassworddialog.h
src/widget/form/settings/aboutform.cpp
Expand Down
1 change: 1 addition & 0 deletions res.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<file>ui/chatForm/screenshotButton.svg</file>
<file>ui/chatForm/searchDownButton.svg</file>
<file>ui/chatForm/searchHideButton.svg</file>
<file>ui/chatForm/searchSettingsButton.svg</file>
<file>ui/chatForm/searchUpButton.svg</file>
<file>ui/chatForm/sendButton.svg</file>
<file>ui/chatForm/exitFullScreenButton.svg</file>
Expand Down
73 changes: 73 additions & 0 deletions src/widget/form/searchsettingsform.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "searchsettingsform.h"
#include "ui_searchsettingsform.h"
#include "src/widget/style.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("choiceDateButton");
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css")));

ui->startDateLabel->setStyleSheet("QLabel{color: #ddd;}");

connect(ui->startSearchComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &SearchSettingsForm::onStartSearchSelected);
connect(ui->registerCheckBox, &QCheckBox::clicked, this, &SearchSettingsForm::onRegisterClicked);
connect(ui->wordsOnlyCheckBox, &QCheckBox::clicked, this, &SearchSettingsForm::onWordsOnlyClicked);
connect(ui->regularCheckBox, &QCheckBox::clicked, this, &SearchSettingsForm::onRegularClicked);
}

SearchSettingsForm::~SearchSettingsForm()
{
delete ui;
}

void SearchSettingsForm::onStartSearchSelected(const int index)
{
if (index > 1) {
ui->choiceDateButton->setEnabled(true);
ui->startDateLabel->setEnabled(true);

ui->choiceDateButton->setProperty("state", "green");
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css")));

ui->startDateLabel->setStyleSheet("QLabel{color: #000;}");
} else {
ui->choiceDateButton->setEnabled(false);
ui->startDateLabel->setEnabled(false);

ui->choiceDateButton->setProperty("state", "");
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css")));

ui->startDateLabel->setStyleSheet("QLabel{color: #ddd;}");
}
}

void SearchSettingsForm::onRegisterClicked(const bool checked)
{
if (checked) {
ui->regularCheckBox->setChecked(false);
}
}

void SearchSettingsForm::onWordsOnlyClicked(const bool checked)
{
if (checked) {
ui->regularCheckBox->setChecked(false);
}
}

void SearchSettingsForm::onRegularClicked(const bool checked)
{
if (checked) {
ui->registerCheckBox->setChecked(false);
ui->wordsOnlyCheckBox->setChecked(false);
}
}
28 changes: 28 additions & 0 deletions src/widget/form/searchsettingsform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef SEARCHSETTINGSFORM_H
#define SEARCHSETTINGSFORM_H

#include <QWidget>

namespace Ui {
class SearchSettingsForm;
}

class SearchSettingsForm : public QWidget
{
Q_OBJECT

public:
explicit SearchSettingsForm(QWidget *parent = nullptr);
~SearchSettingsForm();

private:
Ui::SearchSettingsForm *ui;

private slots:
void onStartSearchSelected(const int index);
void onRegisterClicked(const bool checked);
void onWordsOnlyClicked(const bool checked);
void onRegularClicked(const bool checked);
};

#endif // SEARCHSETTINGSFORM_H
152 changes: 152 additions & 0 deletions src/widget/form/searchsettingsform.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?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>78</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 searching:</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>with the end</string>
</property>
</item>
<item>
<property name="text">
<string>with the first</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>Choice</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="QCheckBox" name="wordsOnlyCheckBox">
<property name="text">
<string>Whole words only</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="regularCheckBox">
<property name="text">
<string>Use regular expressions</string>
</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>
39 changes: 33 additions & 6 deletions src/widget/searchform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,37 @@
*/

#include "searchform.h"
#include "form/searchsettingsform.h"
#include "src/widget/style.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QKeyEvent>

SearchForm::SearchForm(QWidget* parent) : QWidget(parent)
{
QHBoxLayout *layout = new QHBoxLayout();
QVBoxLayout* layout = new QVBoxLayout();
QHBoxLayout* layoutNavigation = new QHBoxLayout();
searchLine = new LineEdit();
settings = new SearchSettingsForm();
settings->setVisible(false);

isActiveSettings = false;

settingsButton = createButton("searchSettingsButton", "green");
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);
layoutNavigation->setMargin(0);
layoutNavigation->addWidget(settingsButton);
layoutNavigation->addWidget(searchLine);
layoutNavigation->addWidget(upButton);
layoutNavigation->addWidget(downButton);
layoutNavigation->addWidget(hideButton);

layout->addLayout(layoutNavigation);
layout->addWidget(settings);

setLayout(layout);

Expand All @@ -48,6 +60,7 @@ SearchForm::SearchForm(QWidget* parent) : QWidget(parent)
connect(upButton, &QPushButton::clicked, this, &SearchForm::clickedUp);
connect(downButton, &QPushButton::clicked, this, &SearchForm::clickedDown);
connect(hideButton, &QPushButton::clicked, this, &SearchForm::clickedHide);
connect(settingsButton, &QPushButton::clicked, this, &SearchForm::clickedSearch);
}

void SearchForm::removeSearchPhrase()
Expand Down Expand Up @@ -109,6 +122,20 @@ void SearchForm::clickedHide()
emit visibleChanged();
}

void SearchForm::clickedSearch()
{
isActiveSettings = !isActiveSettings;
settings->setVisible(isActiveSettings);

if (isActiveSettings) {
settingsButton->setProperty("state", "red");
} else {
settingsButton->setProperty("state", "green");
}
settingsButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css")));
settingsButton->update();
}

LineEdit::LineEdit(QWidget* parent) : QLineEdit(parent)
{
}
Expand Down
6 changes: 6 additions & 0 deletions src/widget/searchform.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

class QPushButton;
class LineEdit;
class SearchSettingsForm;

class SearchForm final : public QWidget
{
Expand All @@ -43,18 +44,23 @@ class SearchForm final : public QWidget
// TODO: Merge with 'createButton' from chatformheader.cpp
QPushButton* createButton(const QString& name, const QString& state);

QPushButton* settingsButton;
QPushButton* upButton;
QPushButton* downButton;
QPushButton* hideButton;
LineEdit* searchLine;
SearchSettingsForm* settings;

QString searchPhrase;

bool isActiveSettings;

private slots:
void changedSearchPhrase(const QString& text);
void clickedUp();
void clickedDown();
void clickedHide();
void clickedSearch();

signals:
void searchInBegin(const QString& phrase);
Expand Down
Loading

0 comments on commit 87b340f

Please sign in to comment.