diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 59970a7..db5b60f 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -15,6 +15,7 @@ set (glabels_sources MergeField.cpp MergeRecord.cpp TemplatePicker.cpp + TemplatePickerItem.cpp TextNode.cpp NewLabelDialog.cpp ) @@ -45,6 +46,7 @@ include (${QT_USE_FILE}) include_directories ( ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} ${glabels_qt_SOURCE_DIR} ) diff --git a/app/NewLabelDialog.cpp b/app/NewLabelDialog.cpp index e31f49b..c8fde2a 100644 --- a/app/NewLabelDialog.cpp +++ b/app/NewLabelDialog.cpp @@ -32,6 +32,15 @@ namespace gLabels QList tmplates = libglabels::Db::templates(); templatePicker->setTemplates( tmplates ); + + connect( searchEntry, SIGNAL(textChanged(const QString &)), + this, SLOT(searchEntryTextChanged(const QString &)) ); + } + + + void NewLabelDialog::searchEntryTextChanged( const QString &text ) + { + templatePicker->applyFilter( text ); } } diff --git a/app/NewLabelDialog.h b/app/NewLabelDialog.h index d4e59bc..9c0e9cc 100644 --- a/app/NewLabelDialog.h +++ b/app/NewLabelDialog.h @@ -34,8 +34,8 @@ namespace gLabels public: NewLabelDialog( QWidget *parent ); - private: - + private slots: + void searchEntryTextChanged( const QString &text ); }; diff --git a/app/TemplatePicker.cpp b/app/TemplatePicker.cpp index ef2ac86..9cf6b05 100644 --- a/app/TemplatePicker.cpp +++ b/app/TemplatePicker.cpp @@ -20,9 +20,10 @@ #include "TemplatePicker.h" -#include #include +#include "TemplatePickerItem.h" + namespace gLabels { @@ -42,9 +43,28 @@ namespace gLabels { foreach (libglabels::Template *tmplate, tmplates) { - QListWidgetItem *item = new QListWidgetItem( tmplate->name(), this ); - item->setIcon( QIcon(tmplate->preview()) ); + TemplatePickerItem *item = new TemplatePickerItem( tmplate, this ); } } + + + void TemplatePicker::applyFilter( const QString &searchString ) + { + foreach ( QListWidgetItem *item, findItems( "*", Qt::MatchWildcard ) ) + { + TemplatePickerItem *tPitem = dynamic_cast(item); + + if ( tPitem->tmplate()->name().contains( searchString, Qt::CaseInsensitive ) ) + { + item->setHidden( false ); + + } + else + { + item->setHidden( true ); + } + } + } + } diff --git a/app/TemplatePicker.h b/app/TemplatePicker.h index 75762f7..afe3563 100644 --- a/app/TemplatePicker.h +++ b/app/TemplatePicker.h @@ -40,6 +40,8 @@ namespace gLabels void setTemplates( const QList &tmplates ); + void applyFilter( const QString &searchString ); + private: diff --git a/app/TemplatePickerItem.cpp b/app/TemplatePickerItem.cpp new file mode 100644 index 0000000..c40f855 --- /dev/null +++ b/app/TemplatePickerItem.cpp @@ -0,0 +1,42 @@ +/* TemplatePickerItem.cpp + * + * Copyright (C) 2013 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free 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. + * + * gLabels-qt 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 gLabels-qt. If not, see . + */ + +#include "TemplatePickerItem.h" + +#include +#include +#include + + +namespace gLabels +{ + + TemplatePickerItem::TemplatePickerItem( libglabels::Template *tmplate, + QListWidget *parent = 0 ) + : QListWidgetItem(parent) + { + mTmplate = tmplate; + + setIcon( QIcon(tmplate->preview()) ); + setText( tmplate->name() ); + } + +} + diff --git a/app/TemplatePickerItem.h b/app/TemplatePickerItem.h new file mode 100644 index 0000000..87b5897 --- /dev/null +++ b/app/TemplatePickerItem.h @@ -0,0 +1,49 @@ +/* TemplatePickerItem.h + * + * Copyright (C) 2013 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free 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. + * + * gLabels-qt 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 gLabels-qt. If not, see . + */ + +#ifndef glabels_TemplatePickerItem_h +#define glabels_TemplatePickerItem_h + +#include + +#include + +#include "libglabels/Template.h" + + +namespace gLabels +{ + + class TemplatePickerItem : public QListWidgetItem + { + + public: + TemplatePickerItem( libglabels::Template *tmplate, QListWidget *parent ); + + inline const libglabels::Template *tmplate() const { return mTmplate; } + + private: + libglabels::Template *mTmplate; + + }; + +} + +#endif // glabels_TemplatePickerItem_h diff --git a/app/glabels_main.cpp b/app/glabels_main.cpp index 868a6f5..339009d 100644 --- a/app/glabels_main.cpp +++ b/app/glabels_main.cpp @@ -38,10 +38,12 @@ int main( int argc, char **argv ) Db::init(); ////// TEMPORARY TESTING //////// +#if 0 Db::printKnownPapers(); Db::printKnownCategories(); Db::printKnownVendors(); Db::printKnownTemplates(); +#endif ///////////////////////////////// MainWindow mainWin; diff --git a/app/ui/NewLabelDialog.ui b/app/ui/NewLabelDialog.ui index 604af05..f8bf6a7 100644 --- a/app/ui/NewLabelDialog.ui +++ b/app/ui/NewLabelDialog.ui @@ -271,7 +271,7 @@ gLabels::TemplatePicker QListWidget -
../../app/TemplatePicker.h
+
TemplatePicker.h