prison-1.0/0000775000175000017500000000000011561540754011676 5ustar felixfelixprison-1.0/LICENSE0000664000175000017500000000220311561540754012700 0ustar felixfelix Copyright (c) 2010-2011 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. prison-1.0/.gitignore0000664000175000017500000000000311561540754013657 0ustar felixfelix*~ prison-1.0/Mainpage.dox0000664000175000017500000000331011561540754014130 0ustar felixfelix/** * \mainpage prison Prison barcode library * * %prison is a Qt-based barcode abstraction layer/library and provides uniform access * to generation of barcodes with data. * * \section overview Overview * * %prison has a prison::AbstractBarcode, which is the base class for the actual barcode generators, currently prison::QRCodeBarcode * and prison::DataMatrixBarcode is the two implemented barcode generators. * * %prison currently ships a BarcodeWidget, which is a QWidget with a barcode painted upon, as well as a BarcodeItem, which is a * QGraphicsItem with a barcode painted upon. * * \section supported Supported Barcode types * * There is basically two types of barcodes: * \li barcodes that carries the data * \li barcodes that carries a lookup number, and requires a specific server to look up the actual data. * * %prison isn't as such designed for the latter, it will probably work, but patches implementing barcode * support for such barcodes will not be accepted. A example is EZCode. * * %prison is currently using libdmtx for generation of DataMatrix barcodes * * %prison is currently using libqrencode for generation of QRCode barcodes * */ // DOXYGEN_NAME=Prison // DOXYGEN_COPYRIGHT=2010-2011 Sune Vuorela // DOXYGEN_SET_FILE_PATTERNS = *.h // DOXYGEN_SET_RECURSIVE = NO // DOXYGEN_SET_INPUT = @topdir@/lib/ // DOXYGEN_SET_EXCLUDE = @topdir@/testapp/prison.h prison-1.0/CMakeLists.txt0000664000175000017500000000055411561540754014442 0ustar felixfelixproject(prison) cmake_minimum_required(VERSION 2.6) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/") find_package(Qt4 REQUIRED) find_package(QRencode REQUIRED) find_package(Dmtx REQUIRED) include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/lib) add_subdirectory(lib) add_subdirectory(testapp) add_subdirectory(tools)prison-1.0/lib/0000775000175000017500000000000011561540754012444 5ustar felixfelixprison-1.0/lib/CMakeLists.txt0000664000175000017500000000003111561540754015176 0ustar felixfelixadd_subdirectory(prison) prison-1.0/lib/prison/0000775000175000017500000000000011561540754013756 5ustar felixfelixprison-1.0/lib/prison/BarcodeItem0000664000175000017500000000003711561540754016057 0ustar felixfelix#include prison-1.0/lib/prison/barcodeitem.cpp0000664000175000017500000000462511561540754016747 0ustar felixfelix/* Copyright (c) 2010-2011 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "barcodeitem.h" #include #include "abstractbarcode.h" using namespace prison; /** * @cond PRIVATE */ class BarcodeItem::Private { public: AbstractBarcode* m_barcode; Private(AbstractBarcode* barcode) : m_barcode(barcode) {} }; /** * @endcond */ BarcodeItem::BarcodeItem(QGraphicsItem* parent): QGraphicsItem(parent), d(new BarcodeItem::Private(0)) { } BarcodeItem::BarcodeItem(AbstractBarcode* barcode, QGraphicsItem* parent): QGraphicsItem(parent), d(new BarcodeItem::Private(barcode)) { } void BarcodeItem::setData(const QString& data) { if(!d->m_barcode) { return; } prepareGeometryChange(); d->m_barcode->setData(data); update(); } void BarcodeItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { if(!d->m_barcode) { painter->fillRect(boundingRect(),Qt::black); return; } else { d->m_barcode->paint(painter,boundingRect()); } } QRectF BarcodeItem::boundingRect() const { if(d->m_barcode) { return QRectF(QPointF(0.0,0.0),d->m_barcode->minimumSize()); } else { return QRectF(); } } BarcodeItem::~BarcodeItem() { delete d->m_barcode; delete d; } void BarcodeItem::setBarcode(AbstractBarcode* barcode) { delete d->m_barcode; d->m_barcode=barcode; } prison-1.0/lib/prison/DataMatrixBarcode0000664000175000017500000000004511561540754017216 0ustar felixfelix#include prison-1.0/lib/prison/abstractbarcode.h0000664000175000017500000000724111561540754017256 0ustar felixfelix/* Copyright (c) 2010-2011 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef PRISON_ABSTRACTBARCODE_H #define PRISON_ABSTRACTBARCODE_H #include #include #include #include class QPainter; namespace prison { /** * base class for barcode generators * To add your own barcode generator, subclass this class * and reimplement toImage(const QSizeF&) to do the actual * work of generating the barcode. * * The barcode is cached in AbstractBarcode when painting and * the size and the data doesn't change. Using the same AbstractBarcode * to paint on several surfaces, if they aren't of the exact same size * will break the caching */ class PRISON_EXPORT AbstractBarcode { public: /** * creates a barcode generator without any data */ AbstractBarcode(); virtual ~AbstractBarcode(); /** * @return the QString encoded in this barcode. */ QString data() const; /** * sets the data to be drawn by this function * calling this function does not do any repaints of anything, they are * your own responsibility. If you are using the barcodes thru BarcodeWidget or BarcodeItem, you * should rather use their setData function, as they handle the relevant updates. * @param data QString containing the data */ void setData(const QString& data); /** * paints the barcode in the given rectangle. * @param painter The QPainter to paint upon * @param targetrect The rectangle to paint within */ void paint(QPainter* painter, const QRectF& targetrect); /** * Creates a image with a barcode on * This is the function that actually does all the interesting things, the rest is just icing and api. * @return QImage with a barcode on, trying to match the requested size * @param size Requested size for the barcode, if smaller than minimumSize, a image fitting within minimumsize will be returned */ virtual QImage toImage(const QSizeF& size) = 0 ; /** * Note! minimalSize() doesn't work as expected if this is not painting on something. * @return the minimal size for this barcode. */ QSizeF minimumSize() const; protected: /** * Sets the minimum size for this barcode. * Some barcodes have minimum sizes for when they are readable and such * @param minimumSize QSizeF holding the minimum size for this barcode */ void setMinimumSize(const QSizeF& minimumSize); private: class Private; /** * d-pointer */ Private* d; }; }; //namespace #endif // PRISON_ABSTRACTBARCODE_H prison-1.0/lib/prison/datamatrixbarcode.cpp0000664000175000017500000000500611561540754020141 0ustar felixfelix/* Copyright (c) 2010-2011 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "datamatrixbarcode.h" #include using namespace prison; /** * @cond PRIVATE */ class DataMatrixBarcode::Private { public: }; /** * @endcond */ DataMatrixBarcode::DataMatrixBarcode() : d(0) { } DataMatrixBarcode::~DataMatrixBarcode() { delete d; } QImage DataMatrixBarcode::toImage(const QSizeF& size) { const int width = qRound(qMin(size.width(),size.height())); if(data().size()==0 || width == 0 || data().size() > 1200) { return QImage(); } DmtxEncode * enc = dmtxEncodeCreate(); dmtxEncodeSetProp( enc, DmtxPropPixelPacking, DmtxPack32bppRGBX ); dmtxEncodeSetProp( enc, DmtxPropWidth, width ); dmtxEncodeSetProp( enc, DmtxPropHeight, width ); QByteArray trimmedData(data().trimmed().toUtf8()); dmtxEncodeDataMatrix(enc, trimmedData.length(), reinterpret_cast(trimmedData.data())); Q_ASSERT(enc->image->width == enc->image->height); setMinimumSize(QSizeF(enc->image->width,enc->image->height)); QImage tmp(enc->image->pxl,enc->image->width,enc->image->height, QImage::Format_RGB32); //we need to copy, because QImage generated from a char pointer requires the //char pointer to be kept around forever, and manually deleted. QImage ret=tmp.convertToFormat(QImage::Format_Mono); if(ret.width() < width) { ret = ret.scaled(width,width); } dmtxEncodeDestroy(&enc); return ret; } prison-1.0/lib/prison/CMakeLists.txt0000664000175000017500000000273611561540754016526 0ustar felixfelixinclude_directories(${QRENCODE_INCLUDE_DIR} ${DMTX_INCLUDE_DIR}) SET( prison_SRC abstractbarcode.cpp barcodewidget.cpp barcodeitem.cpp datamatrixbarcode.cpp qrcodebarcode.cpp ) add_library(prison SHARED ${prison_SRC}) target_link_libraries(prison ${DMTX_LIBRARIES} ${QRENCODE_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}) set_target_properties(prison PROPERTIES VERSION "0.0.0" SOVERSION "0" LINK_INTERFACE_LIBRARIES "" DEFINE_SYMBOL BUILDING_PRISON) set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" ) install( TARGETS prison DESTINATION ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX} ) install( FILES abstractbarcode.h AbstractBarcode barcodeitem.h BarcodeItem barcodewidget.h BarcodeWidget datamatrixbarcode.h DataMatrixBarcode qrcodebarcode.h QRCodeBarcode prison_export.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/prison COMPONENT devel ) set(INCLUDE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/include) get_target_property(LIB_OUT_NAME prison LOCATION) get_filename_component(LIB_OUT_NAME ${LIB_OUT_NAME} NAME) set(LIBPATH ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}) configure_file( PrisonConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/PrisonConfig.cmake @ONLY ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/PrisonConfig.cmake DESTINATION ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/cmake/Prison ) prison-1.0/lib/prison/abstractbarcode.cpp0000664000175000017500000000475711561540754017622 0ustar felixfelix/* Copyright (c) 2010-2011 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "abstractbarcode.h" #include #include using namespace prison; /** * @cond private */ class AbstractBarcode::Private { public: QString m_data; QSizeF m_size; QPixmap m_cache; QSizeF m_minimum_size; AbstractBarcode* q; Private(AbstractBarcode* barcode) : m_minimum_size(10,10), q(barcode) { } }; /** * @endcond */ AbstractBarcode::AbstractBarcode() : d(new AbstractBarcode::Private(this)) { } QString AbstractBarcode::data() const { return d->m_data; } void AbstractBarcode::paint(QPainter* painter, const QRectF& targetrect) { QSizeF size = targetrect.size(); if(d->m_cache.isNull()||size.toSize()!= d->m_cache.size()) { d->m_cache=QPixmap::fromImage(toImage(size)); } QRectF rect(targetrect.left() + targetrect.width() /2 - d->m_cache.size().width() /2, targetrect.top() + targetrect.height()/2 - d->m_cache.size().height()/2, size.width(), size.height()); painter->drawPixmap(rect.topLeft(),d->m_cache, d->m_cache.rect()); } void AbstractBarcode::setData(const QString& data) { d->m_data=data; d->m_cache=QPixmap(); } QSizeF AbstractBarcode::minimumSize() const { return d->m_minimum_size; } void AbstractBarcode::setMinimumSize(const QSizeF& minimumSize) { d->m_minimum_size = minimumSize; } AbstractBarcode::~AbstractBarcode() { delete d; }prison-1.0/lib/prison/barcodewidget.cpp0000664000175000017500000000574511561540754017300 0ustar felixfelix/* Copyright (c) 2010-2011 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "barcodewidget.h" #include "abstractbarcode.h" #include #include using namespace prison; /** * @cond PRIVATE */ class BarcodeWidget::Private { public: AbstractBarcode* m_barcode; BarcodeWidget* q; Private(AbstractBarcode* barcode,BarcodeWidget* parent) : m_barcode(barcode), q(parent) { } }; /** * @endcond */ BarcodeWidget::BarcodeWidget(QWidget* parent): QWidget(parent), d(new BarcodeWidget::Private(0,this)) { } BarcodeWidget::BarcodeWidget(AbstractBarcode* barcode, QWidget* parent) : QWidget(parent), d(new BarcodeWidget::Private(barcode,this)) { } void BarcodeWidget::setData(QString data) { if(d->m_barcode) d->m_barcode->setData(data); updateGeometry(); repaint(); } void BarcodeWidget::paintEvent(QPaintEvent* event) { QPainter painter(this); if(d->m_barcode) { d->m_barcode->paint(&painter,QRectF(QPointF(0,0),size())); updateGeometry(); } else { painter.fillRect(QRectF(QPointF(0,0),size()),Qt::black); } QWidget::paintEvent(event); } void BarcodeWidget::resizeEvent(QResizeEvent* event) { if(d->m_barcode) { updateGeometry(); repaint(); } QWidget::resizeEvent(event); } void BarcodeWidget::mousePressEvent(QMouseEvent* event) { if(event->buttons() & Qt::LeftButton) { QMimeData* data = new QMimeData(); data->setImageData(d->m_barcode->toImage(size())); QDrag* drag = new QDrag(this); drag->setMimeData(data); drag->exec(); } QWidget::mousePressEvent(event); } QSize BarcodeWidget::minimumSizeHint() const { if(d->m_barcode) { return d->m_barcode->minimumSize().toSize(); } else { return QWidget::minimumSizeHint(); } } prison::BarcodeWidget::~BarcodeWidget() { delete d->m_barcode; delete d; } void BarcodeWidget::setBarcode(AbstractBarcode* barcode) { delete d->m_barcode; d->m_barcode=barcode; } prison-1.0/lib/prison/AbstractBarcode0000664000175000017500000000004411561540754016722 0ustar felixfelix#include prison-1.0/lib/prison/QRCodeBarcode0000664000175000017500000000004111561540754016271 0ustar felixfelix#include prison-1.0/lib/prison/barcodewidget.h0000664000175000017500000000574211561540754016742 0ustar felixfelix/* Copyright (c) 2010-2011 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef PRISON_BARCODEWIDGET_H #define PRISON_BARCODEWIDGET_H #include #include namespace prison { class AbstractBarcode; /** * QWidget with a barcode on */ class PRISON_EXPORT BarcodeWidget : public QWidget { public: /** * Creates a barcodewidget with no barcode generator * use setBarcode() to set the barcode * @param parent the parent in QWidget hierachy */ BarcodeWidget(QWidget* parent=0); /** * Creates a barcode widget with 'barcode' as barcode generator * @param barcode The barcode generator for this widget. Takes ownership over the barcode generator * @param parent the parent in QWidget hierachy */ BarcodeWidget(AbstractBarcode* barcode, QWidget* parent=0); virtual ~BarcodeWidget(); /** * sets the data shown to data, and triggers a repaint and resize if needed * @param data QString holding the data to be shown */ void setData(QString data); /** * sets the barcode generator to barcode, and deletes the existing barcode. * @param barcode USes this barcode generator for this widget, and takes ownership over it */ void setBarcode(AbstractBarcode* barcode); /** * Reimplementation * @return minimumSizeHint for this widget */ virtual QSize minimumSizeHint() const; protected: /** * paintEvent * @param event QPaintEvent */ virtual void paintEvent(QPaintEvent* event ); /** * resizeEvent * @param event QResizeEvent */ virtual void resizeEvent(QResizeEvent* event ); /** * enables drag from the barcodewidget * @param event QMouseEvent */ virtual void mousePressEvent(QMouseEvent* event); private: class Private; /** * d pointer */ Private* d; }; }; //namespace #endif // PRISON_BARCODEWIDGET_H prison-1.0/lib/prison/qrcodebarcode.cpp0000664000175000017500000000614111561540754017261 0ustar felixfelix/* Copyright (c) 2010-2011 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "qrcodebarcode.h" #include using namespace prison; /** @cond PRIVATE */ class QRCodeBarcode::Private { public: }; /** @endcond */ QRCodeBarcode::QRCodeBarcode() : AbstractBarcode(), d(0){ } QRCodeBarcode::~QRCodeBarcode() { delete d; } QImage QRCodeBarcode::toImage(const QSizeF& size) { const int width = qRound(qMin(size.width(),size.height())); if(data().size()==0 || width==0) { return QImage(); } const QByteArray trimmedData(data().trimmed().toUtf8()); QRcode* code = QRcode_encodeString8bit(trimmedData.constData(), 0, QR_ECLEVEL_Q); if(!code) { return QImage(); } const int margin = 2; /*32 bit colors, 8 bit pr byte*/ uchar* img = new uchar[4 *sizeof(char*)*(2*margin + code->width)*(2*margin* + code->width)]; uchar* p = img; const char white = 0xff; const char black = 0x00; for(int row = 0 ; row < code->width+2*margin ; row++) { for(int col = 0 ; col < code->width+2*margin ; col++) { if(row < margin || row >= (code->width+margin) || col < margin || col >= (code->width+margin)) { /*4 bytes for color*/ for(int i =0 ; i<4 ; i++) { *p = white; p++; } } else { int c= (row-margin)*code->width + (col-margin); /*it is bit 1 that is the interesting bit for us from libqrencode*/ if(code->data[c] & 1) { /*4 bytes for color*/ for(int i =0 ; i<4 ; i++) { *p = black; p++; } } else { /*4 bytes for color*/ for(int i =0 ; i<4 ; i++) { *p = white; p++; } } } } } QImage tmp(img,code->width+2*margin,code->width+2*margin,QImage::Format_RGB32); setMinimumSize(QSizeF(tmp.width()*4,tmp.height()*4)); QImage ret = tmp.convertToFormat(QImage::Format_Mono).scaled(qMax(tmp.width()*4,width),qMax(tmp.height()*4,width)); //4 is determined by trial and error. delete[] img; QRcode_free(code); return ret; } prison-1.0/lib/prison/datamatrixbarcode.h0000664000175000017500000000406311561540754017610 0ustar felixfelix/* Copyright (c) 2010-2011 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef PRISON_DATAMATRIXBARCODE_H #define PRISON_DATAMATRIXBARCODE_H #include #include namespace prison { /** * This is a Datamatrix barcode generator that uses libdmtx * for the actual generation of barcodes. */ class PRISON_EXPORT DataMatrixBarcode : public prison::AbstractBarcode { public: /** * creates a datamatrixbarcode generator */ DataMatrixBarcode(); virtual ~DataMatrixBarcode(); /** * This is the function doing the actual work in generating the barcode * @return QImage containing a DataMatrix, trying to approximate the requested sizes * @param size The requested size of the barcode, approximate. if the barcode generator can't get the data to fit in there, it might be larger */ virtual QImage toImage(const QSizeF& size); private: class Private; Private *d; }; }; #endif // PRISON_DATAMATRIXBARCODE_H prison-1.0/lib/prison/BarcodeWidget0000664000175000017500000000004111561540754016377 0ustar felixfelix#include prison-1.0/lib/prison/barcodeitem.h0000664000175000017500000000572311561540754016414 0ustar felixfelix/* Copyright (c) 2010-2011 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef PRISON_BARCODEITEM_H #define PRISON_BARCODEITEM_H #include #include namespace prison { class AbstractBarcode; /** * QGraphicsItem with a barcode */ class PRISON_EXPORT BarcodeItem : public QGraphicsItem { public: /** * Creates a barcodeitem without a barcode generator * use setBarcode() to set a barcode generator * @param parent QGraphicsItem that this item is a child of */ BarcodeItem(QGraphicsItem* parent=0); /** * creates a barcode item with barcode as barcode generator, and parent as parent * @param barcode Barcode generator, this function takes ownership over the barcode * @param parent QGraphicsItem that this item is a child of */ BarcodeItem(prison::AbstractBarcode* barcode, QGraphicsItem* parent=0); virtual ~BarcodeItem(); /** * sets the data on the barcode to data. THis function repaints and changes geometry * if needed. * @param data QString with the data to show on the barcode */ void setData(const QString& data); /** * sets the barcode generator to barcode, and deletes the existing barcode generator if exists. * @param barcode barcode generator to use in this BarcodeItem. This function takes ownership over the barcode generator */ void setBarcode(prison::AbstractBarcode* barcode); /** * Reimpl; * @param painter painter to paint on * @param option styleoption * @param widget */ virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); /** * Reimplementation * @return boundingRect for this item */ virtual QRectF boundingRect() const; private: class Private; /** * d pointer */ Private* d; }; }; //namespace #endif // PRISON_BARCODEITEM_H prison-1.0/lib/prison/qrcodebarcode.h0000664000175000017500000000377211561540754016735 0ustar felixfelix/* Copyright (c) 2010-2011 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef PRISON_QRCODEBARCODE_H #define PRISON_QRCODEBARCODE_H #include namespace prison { /** * QRCode Barcode generator ; uses libqrencode to do the actual encoding * of the barcode. */ class PRISON_EXPORT QRCodeBarcode : public prison::AbstractBarcode { public: /** * creates a QRCode generator */ QRCodeBarcode(); virtual ~QRCodeBarcode(); /** * This is the function doing the actual work in generating the barcode * @return QImage containing a QRCode, trying to approximate the requested sizes * @param size The requested size of the barcode, approximate. if the barcode generator can't get the data to fit in there, it might be larger */ virtual QImage toImage(const QSizeF& size); private: class Private; Private *d; }; }; // namespace #endif // PRISON_QRCODEBARCODE_H prison-1.0/lib/prison/PrisonConfig.cmake.in0000664000175000017500000000032511561540754017765 0ustar felixfelixSET(PRISON_LIBRARIES "@LIBPATH@/@LIB_OUT_NAME@" CACHE FILEPATH "Prison barcode library") SET(PRISON_INCLUDE_DIR "@INCLUDE_DIRECTORY@" CACHE PATH "Include path for prison barcode library") SET(PRISON_FOUND "TRUE") prison-1.0/lib/prison/prison_export.h0000664000175000017500000000270011561540754017041 0ustar felixfelix/* Copyright (c) 2010 Sune Vuorela Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef PRISON_EXPORT_H #define PRISON_EXPORT_H #include #ifndef PRISON_EXPORT # if defined(BUILDING_PRISON) /* We are building this library */ # define PRISON_EXPORT Q_DECL_EXPORT # else /* We are using this library */ # define PRISON_EXPORT Q_DECL_IMPORT # endif #endif #endif // PRISON_EXPORT_H prison-1.0/testapp/0000775000175000017500000000000011561540754013356 5ustar felixfelixprison-1.0/testapp/main.cpp0000664000175000017500000000026011561540754015004 0ustar felixfelix#include #include "prison.h" int main(int argc, char** argv) { QApplication app(argc, argv); main_window foo; foo.show(); return app.exec(); } prison-1.0/testapp/CMakeLists.txt0000664000175000017500000000041211561540754016113 0ustar felixfelix include_directories(${CMAKE_SOURCE_DIR}/lib ${CMAKE_CURRENT_BINARY_DIR}) set(prison_SRCS prison.cpp main.cpp) qt4_automoc(${prison_SRCS}) add_executable(test-prison ${prison_SRCS}) target_link_libraries(test-prison ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} prison) prison-1.0/testapp/prison.h0000664000175000017500000000101711561540754015040 0ustar felixfelix#ifndef prison_H #define prison_H #include namespace prison { class BarcodeWidget; class BarcodeItem; } class QLineEdit; class main_window : public QWidget { Q_OBJECT public: main_window(); public Q_SLOTS: void data_changed(); private: QLineEdit* m_lineedit; prison::BarcodeWidget* m_dmw; prison::BarcodeWidget* m_qrw; prison::BarcodeItem* m_dmi; prison::BarcodeItem* m_qri; prison::BarcodeItem* m_nulli; prison::BarcodeWidget* m_nullw; }; #endif // prison_H prison-1.0/testapp/prison.cpp0000664000175000017500000000371311561540754015400 0ustar felixfelix#include "prison.h" #include #include #include "prison/BarcodeItem" #include "prison/BarcodeWidget" #include "prison/DataMatrixBarcode" #include "prison/QRCodeBarcode" #include #include #include #include #include void main_window::data_changed() { QString result = m_lineedit->text(); m_dmi->setData(result); m_dmw->setData(result); m_qri->setData(result); m_qrw->setData(result); m_nulli->setData(result); m_nullw->setData(result); } main_window::main_window() { QHBoxLayout* lay = new QHBoxLayout(); m_lineedit = new QLineEdit(this); QPushButton* but = new QPushButton(this); connect(but,SIGNAL(clicked()),SLOT(data_changed())); lay->addWidget(m_lineedit); lay->addWidget(but); QVBoxLayout* mainlay = new QVBoxLayout(); m_dmw = new prison::BarcodeWidget(new prison::DataMatrixBarcode(),this); m_qrw = new prison::BarcodeWidget(new prison::QRCodeBarcode(),this); QGraphicsScene* scene = new QGraphicsScene(this); m_dmi = new prison::BarcodeItem(new prison::DataMatrixBarcode()); m_qri = new prison::BarcodeItem(new prison::QRCodeBarcode()); m_nulli = new prison::BarcodeItem(); m_nullw = new prison::BarcodeWidget(); scene->addItem(m_dmi); m_dmi->setPos(0,0); scene->addItem(m_qri); m_qri->setPos(200,200); scene->addItem(m_nulli); m_nulli->setPos(0,200); prison::BarcodeItem* with_value = new prison::BarcodeItem(); with_value->setBarcode(new prison::QRCodeBarcode()); with_value->setData("hello"); scene->addItem(with_value); with_value->setPos(200,0); QGraphicsView* v = new QGraphicsView(this); v->setScene(scene); QSplitter* splitter = new QSplitter(Qt::Vertical); splitter->addWidget(v); splitter->addWidget(m_dmw); splitter->addWidget(m_qrw); splitter->addWidget(m_nullw); mainlay->addLayout(lay); mainlay->addWidget(splitter); setLayout(mainlay); } #include "prison.moc" prison-1.0/cmake/0000775000175000017500000000000011561540754012756 5ustar felixfelixprison-1.0/cmake/modules/0000775000175000017500000000000011617047236014425 5ustar felixfelixprison-1.0/cmake/modules/FindQRencode.cmake0000664000175000017500000000210611561540754017730 0ustar felixfelix# - Try to find the qrencode library # Once done this will define # # QRENCODE_FOUND - system has the qrencode library # QRENCODE_INCLUDE_DIR - the qrencode library include dir # QRENCODE_LIBRARIES - the libraries used to link qrencode # Copyright (C) 2010 Sune Vuorela # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (QRENCODE_INCLUDE_DIR AND QRENCODE_LIBRARIES) # in cache already set(QRENCODE_FOUND TRUE) else (QRENCODE_INCLUDE_DIR AND QRENCODE_LIBRARIES) find_path(QRENCODE_INCLUDE_DIR qrencode.h) find_library(QRENCODE_LIBRARIES NAMES qrencode) if (QRENCODE_INCLUDE_DIR AND QRENCODE_LIBRARIES) set(QRENCODE_FOUND TRUE) else (QRENCODE_INCLUDE_DIR AND QRENCODE_LIBRARIES) message("QRencode library not found, please see http://megaui.net/fukuchi/works/qrencode/index.en.html") endif (QRENCODE_INCLUDE_DIR AND QRENCODE_LIBRARIES) mark_as_advanced(QRENCODE_INCLUDE_DIR QRENCODE_LIBRARIES) endif (QRENCODE_INCLUDE_DIR AND QRENCODE_LIBRARIES) prison-1.0/cmake/modules/COPYING-CMAKE-SCRIPTS0000664000175000017500000000245711617047236017433 0ustar felixfelixRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. prison-1.0/cmake/modules/FindDmtx.cmake0000664000175000017500000000171611561540754017152 0ustar felixfelix# - Try to find the dmtx library # Once done this will define # # DMTX_FOUND - system has the datamatrix library # DMTX_INCLUDE_DIR - the datamatrix library include dir # DMTX_LIBRARIES - the libraries used to link datamatrix # Copyright (C) 2010 Sune Vuorela # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (DMTX_INCLUDE_DIR AND DMTX_LIBRARIES) # in cache already set(DTMX_FOUND TRUE) else (DMTX_INCLUDE_DIR AND DMTX_LIBRARIES) find_path(DMTX_INCLUDE_DIR dmtx.h) find_library(DMTX_LIBRARIES NAMES dmtx) if (DMTX_INCLUDE_DIR AND DMTX_LIBRARIES) set(DMTX_FOUND TRUE) else (DMTX_INCLUDE_DIR AND DMTX_LIBRARIES) message("Datamatrix library not found, please see http://www.libdmtx.org") endif (DMTX_INCLUDE_DIR AND DMTX_LIBRARIES) mark_as_advanced(DMTX_INCLUDE_DIR DMTX_LIBRARIES) endif (DMTX_INCLUDE_DIR AND DMTX_LIBRARIES) prison-1.0/tools/0000775000175000017500000000000011561540754013036 5ustar felixfelixprison-1.0/tools/CMakeLists.txt0000664000175000017500000000030611561540754015575 0ustar felixfelix find_package(Qt4 COMPONENTS QtGui QtCore REQUIRED) add_executable(prison-datamatrix prison-datamatrix.cpp) target_link_libraries(prison-datamatrix prison ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY}) prison-1.0/tools/prison-datamatrix.cpp0000664000175000017500000000434611561540754017217 0ustar felixfelix#include #include #include #include #include #include #include void error(const QString& error, const QString& errormessage) { QTextStream str(stdout); str << error << ": " << errormessage << endl; exit(0); } int main(int argc, char* argv[]) { QCoreApplication app(argc,argv); QString size; QString outputfile; QString outputformat; QStringList arguments = app.arguments(); QString appname = arguments.takeFirst(); while(!arguments.isEmpty()) { QString argument = arguments.takeFirst(); if(argument==QLatin1String("--")) { break; //rest is data } else if(argument==QLatin1String("--size")||argument==QLatin1String("-s")) { size=arguments.takeFirst(); } else if(argument==QLatin1String("--outputfile") || argument==QLatin1String("--output-file") || argument==QLatin1String("-o")) { outputfile = arguments.takeFirst(); } else if(argument==QLatin1String("--output-format") || argument==QLatin1String("--output-format") || argument==QLatin1String("-f")) { outputformat = arguments.takeFirst(); } else if(argument.startsWith(QLatin1String("-"))) { error("unknown argument",argument); } else { break; } } if(outputformat.isEmpty()) { outputformat=QLatin1String("png"); } if(!QImageWriter::supportedImageFormats().contains(outputformat.toLocal8Bit())) { error("unsupported output format", outputformat); } if(outputfile.isEmpty()) { error("outputfile is missing",QString()); } bool ok=false; int intsize = size.toInt(&ok); if(!ok) { error("size not a int",size); } if(intsize < 10) { error("needs a larger output size",size); } QString data = arguments.join(QLatin1String(" ")); if(data.size()==0) { QTextStream in(stdin); data = in.readAll(); if(data.size()==0) { error("No data, neither on commandline nor on stdin",QString()); } } prison::DataMatrixBarcode barcode; barcode.setData(data); QImage result = barcode.toImage(QSizeF(intsize,intsize)); QImageWriter w(outputfile,outputformat.toLocal8Bit()); if(!w.write(result)) { error("writing failed",w.errorString()); } }