search box

This commit is contained in:
lostjared
2018-08-10 14:46:43 -07:00
parent e509a089c7
commit d7724c57b7
5 changed files with 157 additions and 8 deletions

View File

@@ -68,7 +68,8 @@ AC_MainWindow::AC_MainWindow(QWidget *parent) : QMainWindow(parent) {
search_box = new SearchWindow(this);
search_box->setParent(this);
search_box->setFiltersControl(filters, custom_filters);
search_box->main_window = this;
statusBar()->showMessage(tr("Acid Cam v2 Loaded - Use File Menu to Start"));
take_snapshot = false;
disp = new DisplayWindow(this);
@@ -403,6 +404,12 @@ void AC_MainWindow::addClicked() {
}
}
void AC_MainWindow::updateList() {
std::vector<std::pair<int, int>> v;
buildVector(v);
playback->setVector(v);
}
void AC_MainWindow::rmvClicked() {
int item = custom_filters->currentRow();
if(item != -1) {

View File

@@ -14,6 +14,8 @@
#include "playback_thread.h"
#include "search_box.h"
class SearchWindow;
class AC_MainWindow : public QMainWindow {
Q_OBJECT
public:
@@ -36,7 +38,7 @@ public:
QAction *help_about;
QAction *open_search;
QRadioButton *filter_single, *filter_custom;
void updateList();
public slots:
void addClicked();
void rmvClicked();

View File

@@ -1,4 +1,12 @@
#include "search_box.h"
#include"tokenize.h"
std::string lowerString(std::string text) {
std::string new_text;
for(unsigned long i = 0; i < text.length(); ++i)
new_text += tolower(text[i]);
return new_text;
}
SearchWindow::SearchWindow(QWidget *parent) : QDialog(parent) {
setFixedSize(640, 480);
@@ -27,12 +35,32 @@ void SearchWindow::createControls() {
}
void SearchWindow::search_filter() {
while(search_list->count() > 0) {
search_list->takeItem(0);
}
std::string search = lowerString(search_text->text().toStdString());
std::vector<std::string> tokens;
token::tokenize(search, std::string(" "), tokens);
for(int i = 0; i < filters->count(); ++i) {
std::string search_items = lowerString(filters->itemText(i).toStdString());
for(unsigned q = 0; q < tokens.size(); ++q) {
if(search_items.find(tokens[q]) != std::string::npos) {
search_list->addItem(filters->itemText(i));
}
}
}
}
void SearchWindow::add_current() {
int index = search_list->currentRow();
if(index >= 0) {
QListWidgetItem *in = search_list->item(index);
custom_list->addItem(in->text());
main_window->updateList();
}
}
void SearchWindow::setFiltersControl(QComboBox *filter_box, QListWidget *custombox) {
filters = filter_box;
custom_list = custombox;
}

View File

@@ -3,23 +3,24 @@
#define __SEARCHBOX__H__
#include "qtheaders.h"
#include "main_window.h"
class SearchWindow : public QDialog {
Q_OBJECT
public:
AC_MainWindow *main_window;
SearchWindow(QWidget *parent = 0);
void createControls();
void setFiltersControl(QComboBox *filter_box, QListWidget *custom);
public slots:
void search_filter();
void add_current();
private:
QListWidget *search_list;
QListWidget *search_list,*custom_list;
QLineEdit *search_text;
QPushButton *search, *add;
QComboBox *filters;
};
#endif

111
src/tokenize.h Normal file
View File

@@ -0,0 +1,111 @@
/* Acid Cam Functions for OpenCV
* written by Jared Bruni https://github.com/lostjared
This software is dedicated to all the people that struggle with mental illness.
Website: http://lostsidedead.com
YouTube: http://youtube.com/LostSideDead
Instagram: http://instagram.com/jaredbruni
Twitter: http://twitter.com/jaredbruni
Facebook: http://facebook.com/LostSideDead0x
You can use this program free of charge and redistrubute as long
as you do not charge anything for this program. This program is 100%
Free.
BSD 2-Clause License
Copyright (c) 2018, Jared Bruni
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __TOKENIZE_H__
#define __TOKENIZE_H__
#include<iostream>
#include<vector>
#include<string>
namespace token {
template<typename type>
type substr(type t, size_t start, size_t stop) {
type temp;
for(size_t i = start; i < stop; i++)
temp += t[i];
return temp;
}
template<> char* substr(char *t, size_t start, size_t stop) {
char *temp = new char [ stop-start+1 ];
size_t pos = 0;
for(size_t i = start; i < stop; i++)
temp[pos++] = t[i];
temp[pos] = 0;
return temp;
}
template<typename type>
size_t len(type &t) {
size_t c = 0;
for(c = 0; t[c] != 0; c++);
return c;
}
template<typename type>
size_t find(size_t start, type& source, type& sub) {
for(size_t i = start; source[i] != 0; i++) {
bool add = true;
for(size_t z = 0; sub[z] != 0; z++) {
if(source[i+z] != sub[z]) {
add = false;
break;
}
}
if(add == true)
return i;
}
return 0;
}
template<typename type>
size_t tokenize(type source, type delim, std::vector<type> &v) {
size_t i = find<type>(0,source,delim),z=0;
if(i == 0) i = find<type>(i+1, source,delim);
size_t lenz = len<type>(source), dlen = len<type>(delim);
while (i != 0 && i < lenz && z < lenz ) {
type s = substr(source,z,i);
if(len(s) > 0 && s[0] != delim[0])
v.push_back(s);
z = i+dlen;
i = find<type>(i+1, source, delim);
}
if( z < lenz ) v.push_back( substr(source,z,lenz) );
return v.size();
}
}
#endif