diff --git a/app/NewLabelDialog.cpp b/app/NewLabelDialog.cpp index c8fde2a..f6e2fed 100644 --- a/app/NewLabelDialog.cpp +++ b/app/NewLabelDialog.cpp @@ -30,17 +30,45 @@ namespace gLabels { setupUi( this ); + // TODO: Set default based on locale + pageSizeIsoRadio->setChecked( true ); + QList tmplates = libglabels::Db::templates(); templatePicker->setTemplates( tmplates ); + templatePicker->applyFilter( searchEntry->text(), + pageSizeIsoRadio->isChecked(), + pageSizeUsRadio->isChecked(), + pageSizeOtherRadio->isChecked() ); + connect( searchEntry, SIGNAL(textChanged(const QString &)), this, SLOT(searchEntryTextChanged(const QString &)) ); + + connect( pageSizeIsoRadio, SIGNAL(toggled(bool)), this, SLOT(pageSizeRadioToggled(bool)) ); + connect( pageSizeUsRadio, SIGNAL(toggled(bool)), this, SLOT(pageSizeRadioToggled(bool)) ); + connect( pageSizeOtherRadio, SIGNAL(toggled(bool)), this, SLOT(pageSizeRadioToggled(bool)) ); + } void NewLabelDialog::searchEntryTextChanged( const QString &text ) { - templatePicker->applyFilter( text ); + templatePicker->applyFilter( text, + pageSizeIsoRadio->isChecked(), + pageSizeUsRadio->isChecked(), + pageSizeOtherRadio->isChecked() ); + } + + + void NewLabelDialog::pageSizeRadioToggled( bool checked ) + { + if ( checked ) + { + templatePicker->applyFilter( searchEntry->text(), + pageSizeIsoRadio->isChecked(), + pageSizeUsRadio->isChecked(), + pageSizeOtherRadio->isChecked() ); + } } } diff --git a/app/NewLabelDialog.h b/app/NewLabelDialog.h index 9c0e9cc..d2d1d69 100644 --- a/app/NewLabelDialog.h +++ b/app/NewLabelDialog.h @@ -36,6 +36,7 @@ namespace gLabels private slots: void searchEntryTextChanged( const QString &text ); + void pageSizeRadioToggled( bool checked ); }; diff --git a/app/TemplatePicker.cpp b/app/TemplatePicker.cpp index 9cf6b05..d4f1fae 100644 --- a/app/TemplatePicker.cpp +++ b/app/TemplatePicker.cpp @@ -48,13 +48,17 @@ namespace gLabels } - void TemplatePicker::applyFilter( const QString &searchString ) + void TemplatePicker::applyFilter( const QString &searchString, + bool isoMask, bool usMask, bool otherMask ) { foreach ( QListWidgetItem *item, findItems( "*", Qt::MatchWildcard ) ) { - TemplatePickerItem *tPitem = dynamic_cast(item); + TemplatePickerItem *tItem = dynamic_cast(item); - if ( tPitem->tmplate()->name().contains( searchString, Qt::CaseInsensitive ) ) + if ( tItem->tmplate()->name().contains( searchString, Qt::CaseInsensitive ) && + (isoMask == tItem->tmplate()->isSizeIso()) && + (usMask == tItem->tmplate()->isSizeUs()) && + (otherMask == tItem->tmplate()->isSizeOther()) ) { item->setHidden( false ); diff --git a/app/TemplatePicker.h b/app/TemplatePicker.h index afe3563..b849e73 100644 --- a/app/TemplatePicker.h +++ b/app/TemplatePicker.h @@ -40,7 +40,7 @@ namespace gLabels void setTemplates( const QList &tmplates ); - void applyFilter( const QString &searchString ); + void applyFilter( const QString &searchString, bool isoMask, bool usMask, bool otherMask ); private: diff --git a/libglabels/Paper.h b/libglabels/Paper.h index 2a905fb..e8162e5 100644 --- a/libglabels/Paper.h +++ b/libglabels/Paper.h @@ -52,6 +52,9 @@ namespace libglabels /* PWG 5101.1-2002 size name */ inline QString pwgSize() const { return mPwgSize; } + inline bool isSizeIso() const { return mPwgSize.startsWith( "iso_" ); } + inline bool isSizeUs() const { return mPwgSize.startsWith( "na_" ); } + private: QString mId; QString mName; diff --git a/libglabels/Template.cpp b/libglabels/Template.cpp index c2ed15f..cb8b9e6 100644 --- a/libglabels/Template.cpp +++ b/libglabels/Template.cpp @@ -28,6 +28,33 @@ namespace libglabels { + Template::Template( const QString &brand, + const QString &part, + const QString &description, + const QString &paperId, + double pageWidth = 0, + double pageHeight = 0 ) + : mBrand(brand), + mPart(part), + mDescription(description), + mPaperId(paperId), + mPageWidth(pageWidth), + mPageHeight(pageHeight), + mIsSizeIso(false), + mIsSizeUs(false), + mName("") + { + mName.append( brand ).append( " " ).append( part ); + + if ( Db::isPaperIdKnown( paperId ) ) + { + const Paper *paper = Db::lookupPaperFromId( paperId ); + mIsSizeIso = paper->isSizeIso(); + mIsSizeUs = paper->isSizeUs(); + } + } + + Template::Template( const Template &other ) { mBrand = other.mBrand; @@ -36,6 +63,8 @@ namespace libglabels mPaperId = other.mPaperId; mPageWidth = other.mPageWidth; mPageHeight = other.mPageHeight; + mIsSizeIso = other.mIsSizeIso; + mIsSizeUs = other.mIsSizeUs; mEquivPart = other.mEquivPart; mName = other.mName; mProductUrl = other.mProductUrl; diff --git a/libglabels/Template.h b/libglabels/Template.h index 8d90cfa..a0d4b32 100644 --- a/libglabels/Template.h +++ b/libglabels/Template.h @@ -50,18 +50,8 @@ namespace libglabels const QString &part, const QString &description, const QString &paperId, - double pageWidth = 0, - double pageHeight = 0 ) - : mBrand(brand), - mPart(part), - mDescription(description), - mPaperId(paperId), - mPageWidth(pageWidth), - mPageHeight(pageHeight), - mName("") - { - mName.append( brand ).append( " " ).append( part ); - } + double pageWidth, + double pageHeight ); Template( const Template &other ); @@ -84,6 +74,9 @@ namespace libglabels inline const QString &paperId() const { return mPaperId; } inline double pageWidth() const { return mPageWidth; } inline double pageHeight() const { return mPageHeight; } + inline bool isSizeIso() const { return mIsSizeIso; } + inline bool isSizeUs() const { return mIsSizeUs; } + inline bool isSizeOther() const { return !mIsSizeIso && !mIsSizeUs; } inline const QString &equivPart() const { return mEquivPart; } inline void setEquivPart( const QString &value ) { mEquivPart = value; } @@ -115,6 +108,8 @@ namespace libglabels QString mPaperId; double mPageWidth; double mPageHeight; + bool mIsSizeIso; + bool mIsSizeUs; QString mEquivPart; QString mName;