From 86b2d34dc5c932b70777834cd4e087dfee9fc1dc Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Wed, 18 Nov 2015 22:40:13 +0100 Subject: [PATCH] fix scanner detection, make entrance tab get focus on scan --- plugins/bcs-usb/bcs-plugin.cpp | 1 + plugins/bcs-usb/bcs-plugin.h | 4 +++- plugins/bcs-usb/hidscanner.cpp | 4 +++- src/mwin/entrancetab.cpp | 7 +++++++ src/mwin/entrancetab.h | 6 ++++++ src/mwin/overview.cpp | 2 +- src/widgets/barcodeline.cpp | 23 ++++++++++++++--------- src/widgets/barcodeline.h | 32 +++++++++++++++++++++++++------- 8 files changed, 60 insertions(+), 19 deletions(-) diff --git a/plugins/bcs-usb/bcs-plugin.cpp b/plugins/bcs-usb/bcs-plugin.cpp index c070d5f..9d29369 100644 --- a/plugins/bcs-usb/bcs-plugin.cpp +++ b/plugins/bcs-usb/bcs-plugin.cpp @@ -102,6 +102,7 @@ void MHidBarcodePlugin::restartDetect() void MHidBarcodePlugin::detectScanners() { + mscanners.removeAll(nullptr); if(!misopen)return; qDebug()<<"scanning for scanners..."; hid_device_info *info=hid_enumerate(0,0); diff --git a/plugins/bcs-usb/bcs-plugin.h b/plugins/bcs-usb/bcs-plugin.h index f09e732..7c9d76c 100644 --- a/plugins/bcs-usb/bcs-plugin.h +++ b/plugins/bcs-usb/bcs-plugin.h @@ -15,6 +15,8 @@ #include "barcode-plugin.h" +#include + class QTimer; class MHidBarcodeScanner; class QSettings; @@ -47,7 +49,7 @@ class MHidBarcodePlugin:public QObject,public MBarcodePlugin }; QListmconfig; Config findCfgMatch(int vendor,int product,int iface,QString serial); - QListmscanners; + QList>mscanners; MHidBarcodeScanner*findScanner(QString path); }; diff --git a/plugins/bcs-usb/hidscanner.cpp b/plugins/bcs-usb/hidscanner.cpp index 7835b68..f683e04 100644 --- a/plugins/bcs-usb/hidscanner.cpp +++ b/plugins/bcs-usb/hidscanner.cpp @@ -34,6 +34,7 @@ MHidBarcodeScanner::MHidBarcodeScanner(QString path,QString setGrp, QObject* par MHidBarcodeScanner::~MHidBarcodeScanner() { deactivate(); + qDebug()<<"Deleting Scanner"<addWidget(new QLabel(tr("Enter or scan Ticket-ID:")),0); vl->addWidget(entrancescan=new MBarcodeLine,0); connect(entrancescan,SIGNAL(returnPressed()),this,SLOT(entranceValidate())); + connect(entrancescan,SIGNAL(askForFocus()),this,SLOT(askForFocus())); + qobject_cast< MBarcodeLine* >(entrancescan)->setScanMode(MBarcodeLine::ScanMode::ForceFocus); vl->addWidget(entrancelabel=new QLabel(" "),10); entrancelabel->setAutoFillBackground(true); QFont fnt=entrancelabel->font(); @@ -118,6 +120,11 @@ class METUtility } }; +void MEntranceTab::askForFocus() +{ + emit askForFocus(this); +} + void MEntranceTab::entranceValidate() { //get event ID diff --git a/src/mwin/entrancetab.h b/src/mwin/entrancetab.h index ab25294..6ea3dc3 100644 --- a/src/mwin/entrancetab.h +++ b/src/mwin/entrancetab.h @@ -50,6 +50,12 @@ class MEntranceTab:public QWidget void resetAmounts(); /**configure the entrance*/ void configure(); + ///handles the askForFocus signal from the barcode line + void askForFocus(); + + signals: + ///asks the parent to get focus + void askForFocus(QWidget*); private: friend class METUtility; //the profile associated with this session diff --git a/src/mwin/overview.cpp b/src/mwin/overview.cpp index 426a89e..4c737e3 100644 --- a/src/mwin/overview.cpp +++ b/src/mwin/overview.cpp @@ -174,7 +174,7 @@ MOverview::MOverview(QString pk,std::functioninitUpdate) if(initUpdate)initUpdate(70,tr("Getting Entrance Data...")); entrancetab=new MEntranceTab(pk); addTab(entrancetab,tr("Entrance"),entrancetab->menu()); - + connect(entrancetab,SIGNAL(askForFocus(QWidget*)),this,SLOT(setCurrentTab(QWidget*))); //unused tab disabling... if(!req->hasRight(req->RGetAllEvents)){ diff --git a/src/widgets/barcodeline.cpp b/src/widgets/barcodeline.cpp index 16a50bb..d993a9a 100644 --- a/src/widgets/barcodeline.cpp +++ b/src/widgets/barcodeline.cpp @@ -20,17 +20,22 @@ MBarcodeLine::MBarcodeLine(QWidget* parent): MBarcodeLine(QString(),parent) MBarcodeLine::MBarcodeLine(const QString& cont, QWidget* parent): QLineEdit(cont,parent) { - setToolTip(tr("Type a barcode into this line or scan it with a barcode scanner.")); - setPlaceholderText(tr("Type or scan a barcode.")); - connect(MBarcodeHub::instance(),SIGNAL(newBarcode(QString)), this,SLOT(setBarcode(QString))); + setToolTip(tr("Type a barcode into this line or scan it with a barcode scanner.")); + setPlaceholderText(tr("Type or scan a barcode.")); + connect(MBarcodeHub::instance(),SIGNAL(newBarcode(QString)), this,SLOT(setBarcode(QString))); } void MBarcodeLine::setBarcode(QString bc) { - //do we actually have focus? - //TODO: maybe this should be visibility? - if(!hasFocus())return; - //enter barcode and emit ready signal - setText(bc); - emit returnPressed(); + if(bc.isEmpty())return; + //do we actually have focus? + //TODO: maybe this should be visibility? + if(scanMode()==ScanMode::InFocus && !hasFocus())return; + if(scanMode()==ScanMode::ForceFocus){ + setFocus(); + emit askForFocus(); + } + //enter barcode and emit ready signal + setText(bc); + emit returnPressed(); } diff --git a/src/widgets/barcodeline.h b/src/widgets/barcodeline.h index 6da7b37..dccda13 100644 --- a/src/widgets/barcodeline.h +++ b/src/widgets/barcodeline.h @@ -1,7 +1,7 @@ // // C++ Interface: barcode line edit // -// Description: +// Description: // // // Author: Konrad Rosenbaum , (C) 2014 @@ -17,12 +17,30 @@ class MBarcodeLine:public QLineEdit { - Q_OBJECT - public: - explicit MBarcodeLine(QWidget* parent = 0); - explicit MBarcodeLine(const QString& , QWidget* parent = 0); - private slots: - void setBarcode(QString); + Q_OBJECT + public: + explicit MBarcodeLine(QWidget* parent = 0); + explicit MBarcodeLine(const QString& , QWidget* parent = 0); + + enum class ScanMode{ + InFocus, + InBackground, + ForceFocus, + }; + + ScanMode scanMode()const{return mscanmode;} + + private slots: + void setBarcode(QString); + + public slots: + void setScanMode(ScanMode mode){mscanmode=mode;} + + signals: + void askForFocus(); + + private: + ScanMode mscanmode=ScanMode::InFocus; }; #endif -- 1.7.2.5