├── icons ├── textbold.png ├── textleft.png ├── doublesize.png ├── textcenter.png ├── textright.png └── textunder.png ├── .gitignore ├── qescpos.pri ├── qescpos_icons.qrc ├── example ├── main.cpp ├── dialogprinttemplate.h ├── dialogprinttemplate.cpp └── dialogprinttemplate.ui ├── qescpos.pro ├── qibm852codec.h ├── escposconverter.h ├── README.md ├── qibm852codec.cpp ├── escposconverter.cpp ├── escpostexteditwidgets.h ├── escpostexteditwidgets.cpp ├── LICENSE └── qescpos.pro.user /icons/textbold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martonmiklos/qescpos/HEAD/icons/textbold.png -------------------------------------------------------------------------------- /icons/textleft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martonmiklos/qescpos/HEAD/icons/textleft.png -------------------------------------------------------------------------------- /icons/doublesize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martonmiklos/qescpos/HEAD/icons/doublesize.png -------------------------------------------------------------------------------- /icons/textcenter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martonmiklos/qescpos/HEAD/icons/textcenter.png -------------------------------------------------------------------------------- /icons/textright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martonmiklos/qescpos/HEAD/icons/textright.png -------------------------------------------------------------------------------- /icons/textunder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martonmiklos/qescpos/HEAD/icons/textunder.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Compiled Dynamic libraries 8 | *.so 9 | *.dylib 10 | *.dll 11 | 12 | # Compiled Static libraries 13 | *.lai 14 | *.la 15 | *.a 16 | *.lib 17 | 18 | # Executables 19 | *.exe 20 | *.out 21 | *.app 22 | -------------------------------------------------------------------------------- /qescpos.pri: -------------------------------------------------------------------------------- 1 | INCLUDEPATH += $$PWD 2 | 3 | HEADERS += \ 4 | $$PWD/qibm852codec.h \ 5 | $$PWD/escposconverter.h \ 6 | $$PWD/escpostexteditwidgets.h 7 | 8 | SOURCES += \ 9 | $$PWD/qibm852codec.cpp \ 10 | $$PWD/escposconverter.cpp \ 11 | $$PWD/escpostexteditwidgets.cpp 12 | 13 | RESOURCES += \ 14 | $$PWD/qescpos_icons.qrc 15 | -------------------------------------------------------------------------------- /qescpos_icons.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | icons/doublesize.png 4 | icons/textbold.png 5 | icons/textcenter.png 6 | icons/textleft.png 7 | icons/textright.png 8 | icons/textunder.png 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/main.cpp: -------------------------------------------------------------------------------- 1 | #include "dialogprinttemplate.h" 2 | #include "qibm852codec.h" 3 | 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QIBM852Codec *codec = new QIBM852Codec(); 10 | QApplication a(argc, argv); 11 | 12 | QCoreApplication::setOrganizationName("MM"); 13 | QCoreApplication::setApplicationName("QESCPOS test app"); 14 | QCoreApplication::setApplicationVersion("1.0"); 15 | 16 | DialogPrintTemplate w; 17 | w.show(); 18 | return a.exec(); 19 | } 20 | -------------------------------------------------------------------------------- /qescpos.pro: -------------------------------------------------------------------------------- 1 | QT += core gui sql 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | TARGET = drive_tester 6 | TEMPLATE = app 7 | 8 | OBJECTS_DIR = build 9 | MOC_DIR = build 10 | RCC_DIR = build 11 | UI_DIR = build 12 | DESTDIR = bin 13 | 14 | include(qescpos.pri) 15 | 16 | FORMS += \ 17 | example/dialogprinttemplate.ui 18 | 19 | HEADERS += \ 20 | example/dialogprinttemplate.h 21 | 22 | SOURCES += \ 23 | example/main.cpp \ 24 | example/dialogprinttemplate.cpp 25 | 26 | 27 | greaterThan(QT_MAJOR_VERSION, 4) { 28 | LIBS += -lQt5SerialPort 29 | } else { 30 | LIBS += -lqtserialport 31 | } 32 | -------------------------------------------------------------------------------- /qibm852codec.h: -------------------------------------------------------------------------------- 1 | #ifndef QIBM852CODEC_H 2 | #define QIBM852CODEC_H 3 | 4 | #include 5 | #include 6 | 7 | class QIBM852Codec : public QTextCodec 8 | { 9 | public: 10 | QIBM852Codec(); 11 | ~QIBM852Codec(); 12 | QByteArray name() const {return "IBM852";} 13 | QStringList aliases(); 14 | int mibEnum() const {return 2010;} 15 | QString convertToUnicode(const char *in, int length, ConverterState *state) const ; 16 | QByteArray convertFromUnicode(const QChar *in, int length, ConverterState *state) const ; 17 | private: 18 | QTextCodec *IBM850Codec; 19 | 20 | }; 21 | 22 | #endif // QIBM852CODEC_H 23 | -------------------------------------------------------------------------------- /example/dialogprinttemplate.h: -------------------------------------------------------------------------------- 1 | #ifndef DIALOGPRINTTEMPLATE_H 2 | #define DIALOGPRINTTEMPLATE_H 3 | 4 | #include 5 | #include 6 | 7 | #include "escposconverter.h" 8 | 9 | namespace Ui { 10 | class DialogPrintTemplate; 11 | } 12 | 13 | class DialogPrintTemplate : public QDialog 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit DialogPrintTemplate(QWidget *parent = 0); 19 | ~DialogPrintTemplate(); 20 | 21 | private slots: 22 | void on_pushButtonPrint_clicked(); 23 | 24 | private: 25 | Ui::DialogPrintTemplate *ui; 26 | QSerialPort *m_port; 27 | ESCPOSDirectConverter m_converter; 28 | }; 29 | 30 | #endif // DIALOGPRINTTEMPLATE_H 31 | -------------------------------------------------------------------------------- /escposconverter.h: -------------------------------------------------------------------------------- 1 | #ifndef ESCPOSCONVERTER_H 2 | #define ESCPOSCONVERTER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "qibm852codec.h" 11 | 12 | 13 | class ESCPOSConverter : public QObject 14 | { 15 | Q_OBJECT 16 | public: 17 | ESCPOSConverter(QObject *parent = 0); 18 | virtual QByteArray convert(QTextDocument *doc) = 0; 19 | 20 | protected: 21 | QByteArray setAlignment(Qt::Alignment); 22 | QByteArray setFormat(QTextFragment fragment); 23 | QIBM852Codec *codec; 24 | }; 25 | 26 | class ESCPOSDirectConverter : public ESCPOSConverter 27 | { 28 | Q_OBJECT 29 | public: 30 | ESCPOSDirectConverter(QObject *parent = 0); 31 | QByteArray convert(QTextDocument *doc); 32 | }; 33 | 34 | 35 | #endif // ESCPOSCONVERTER_H 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | qescpos 2 | ======= 3 | 4 | Some classes for Qt to interact with ESC/POS printers: 5 | 6 | - ESCPOSDirectConverter: a converter class which takes a QTextDocument and produces a QByteArray which can be sent to the printer. 7 | - ESCPOSTextEdit - toolbuttons (escpostexteditwidgets.h): 8 | These toolbuttons can be added to your GUI where your QTextEdit lives and if you point to the editor with the setTextEdit method these controls will allow you to format your document with the limited formatting options what the printer supports. 9 | - QIBM852Codec: a code which is a wrapped around the IBM850 codec to translate the hungarian accented characters to fit best similar character from the printer's available characters. **Warning** : this codec is designed only for this purpose, not all the codepage mapped/verified. 10 | - example: 11 | A basic example dialog which showcases the functionality of the classes above. It uses QSerialPort for sending data to the printer. 12 | 13 | TODO: 14 | 15 | - QIBM852Codec cleanup 16 | - Figure out a better method for the text editing, 17 | because the QTextEdit has a lot of limitations which can be a trivial 18 | use case. For e.g.: two textblocks in one row one aligned to left 19 | another aligned to right is not supported. Some webkit based approach 20 | would eliminate this problem. 21 | - Image support [possibly usable code snipplet here](http://madsdyd.wordpress.com/2010/10/19/printing-a-bitmap-with-the-pos-104-prp-085iiit-receipt-printer/#comments) 22 | -------------------------------------------------------------------------------- /example/dialogprinttemplate.cpp: -------------------------------------------------------------------------------- 1 | #include "dialogprinttemplate.h" 2 | #include "ui_dialogprinttemplate.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | DialogPrintTemplate::DialogPrintTemplate(QWidget *parent) : 9 | QDialog(parent), 10 | ui(new Ui::DialogPrintTemplate) 11 | { 12 | ui->setupUi(this); 13 | ui->toolButtonAlignLeft->setTextEdit(ui->textEditBody); 14 | ui->toolButtonAlignRight->setTextEdit(ui->textEditBody); 15 | ui->toolButtonAlignCenter->setTextEdit(ui->textEditBody); 16 | ui->toolButtonBold->setTextEdit(ui->textEditBody); 17 | ui->toolButtonUnderLine->setTextEdit(ui->textEditBody); 18 | ui->comboBoxFontType->setTextEdit(ui->textEditBody); 19 | 20 | m_port = new QSerialPort(this); 21 | m_port->setBaudRate(115200); 22 | m_port->setDataBits(QSerialPort::Data8); 23 | m_port->setParity(QSerialPort::NoParity); 24 | m_port->setStopBits(QSerialPort::OneStop); 25 | m_port->setPortName("/dev/ttyS0"); 26 | if (!m_port->open(QSerialPort::ReadWrite)) { 27 | QMessageBox::warning(this, 28 | tr("Unable to open the port!"), 29 | tr("Unable to open the %1 serial port!\nError:%2").arg(m_port->portName()).arg(m_port->errorString()) 30 | ); 31 | } 32 | } 33 | 34 | DialogPrintTemplate::~DialogPrintTemplate() 35 | { 36 | delete ui; 37 | } 38 | 39 | 40 | void DialogPrintTemplate::on_pushButtonPrint_clicked() 41 | { 42 | if (!m_port->isOpen()) { 43 | if (!m_port->open(QSerialPort::ReadWrite)) { 44 | QMessageBox::warning(this, 45 | tr("Port is not open!").arg(m_port->portName()), 46 | tr("The serial port is closed") 47 | ); 48 | } 49 | } else { 50 | m_port->write(m_converter.convert(ui->textEditBody->document())); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /qibm852codec.cpp: -------------------------------------------------------------------------------- 1 | #include "qibm852codec.h" 2 | #include 3 | QIBM852Codec::QIBM852Codec() : 4 | QTextCodec() 5 | { 6 | IBM850Codec = QTextCodec::codecForName("IBM850"); 7 | } 8 | 9 | QStringList QIBM852Codec::aliases() 10 | { 11 | QStringList ret; 12 | ret << "ibm-852_P100-1995" 13 | << "ibm-852" 14 | << "IBM852" 15 | << "cp852" 16 | << "852" 17 | << "csPCp852" 18 | << "windows-852"; 19 | return ret; 20 | } 21 | 22 | QString QIBM852Codec::convertToUnicode(const char *in, int length, ConverterState *state) const 23 | { 24 | if (IBM850Codec == nullptr) { 25 | return ""; 26 | } else { 27 | return IBM850Codec->toUnicode(in, length, state); 28 | } 29 | } 30 | 31 | QByteArray QIBM852Codec::convertFromUnicode(const QChar *in, int length, ConverterState *state) const 32 | { 33 | Q_UNUSED(state) 34 | if (IBM850Codec == nullptr) { 35 | return ""; 36 | } else { 37 | QByteArray ret; 38 | for (int i = 0; ifromUnicode(&in[i], 1)); 66 | break; 67 | } 68 | } 69 | return ret; 70 | } 71 | 72 | } 73 | 74 | 75 | QIBM852Codec::~QIBM852Codec() 76 | { 77 | 78 | } 79 | -------------------------------------------------------------------------------- /escposconverter.cpp: -------------------------------------------------------------------------------- 1 | #include "escposconverter.h" 2 | 3 | 4 | ESCPOSConverter::ESCPOSConverter(QObject *parent) : 5 | QObject(parent) 6 | { 7 | codec = new QIBM852Codec(); 8 | } 9 | 10 | ESCPOSDirectConverter::ESCPOSDirectConverter(QObject *parent) : 11 | ESCPOSConverter(parent) 12 | { 13 | } 14 | 15 | 16 | QByteArray ESCPOSDirectConverter::convert(QTextDocument* doc) 17 | { 18 | QByteArray ret; 19 | for (QTextBlock block = doc->begin(); block != doc->end(); block = block.next()) { 20 | ret.append(setAlignment(block.blockFormat().alignment())); 21 | QTextBlock::iterator it = block.begin(); 22 | for(;!(it.atEnd()); ++it) { 23 | ret.append(setFormat(it.fragment())); 24 | //ret.append(codec->fromUnicode(it.fragment().text())); 25 | ret.append(codec->convertFromUnicode(it.fragment().text().data(), it.fragment().length(), nullptr)); 26 | } 27 | ret.append(0x1B); 28 | ret.append(0x64); 29 | ret.append(0x01); 30 | } 31 | return ret; 32 | } 33 | 34 | QByteArray ESCPOSConverter::setAlignment(Qt::Alignment align) 35 | { 36 | QByteArray ret; 37 | ret.append(0x1B); 38 | ret.append(0x61); 39 | if (align & Qt::AlignHCenter) 40 | ret.append(49); 41 | else if (align & Qt::AlignRight) 42 | ret.append(50); 43 | else 44 | ret.append(48); // left by default 45 | 46 | return ret; 47 | } 48 | 49 | QByteArray ESCPOSConverter::setFormat(QTextFragment fragment) 50 | { 51 | QByteArray ret; 52 | ret.append(0x1B); 53 | ret.append(0x21); 54 | quint8 formatByte = 0; 55 | 56 | if (fragment.charFormat().fontPointSize() == 9) { 57 | formatByte |= 1; 58 | //qWarning() << "font: 9pt "; 59 | } 60 | 61 | if (fragment.charFormat().fontWeight() > 50) { 62 | formatByte |= 8; 63 | //qWarning() << "font: bold " << fragment.charFormat().fontWeight(); 64 | } 65 | 66 | if (fragment.charFormat().underlineStyle() != QTextCharFormat::NoUnderline) { 67 | formatByte |= 128; 68 | //qWarning() << "font: underline "; 69 | } 70 | 71 | ret.append(formatByte); 72 | return ret; 73 | } 74 | -------------------------------------------------------------------------------- /escpostexteditwidgets.h: -------------------------------------------------------------------------------- 1 | #ifndef ESCPOSTEXTEDITWIDGETS_H 2 | #define ESCPOSTEXTEDITWIDGETS_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class ESCPOSToolWidgetCharm; 9 | 10 | class ESCPOSToolWidget 11 | { 12 | public: 13 | ESCPOSToolWidget(); 14 | ~ESCPOSToolWidget(); 15 | void setTextEdit(QTextEdit* textEdit); 16 | void unsetCurrentTextEdit(); 17 | 18 | virtual void setStateFromFormat(const QTextCharFormat & format); 19 | 20 | protected: 21 | QTextEdit* m_textEdit; 22 | ESCPOSToolWidgetCharm *m_charm; 23 | }; 24 | 25 | class ESCPOSToolWidgetCharm : public QObject 26 | { 27 | Q_OBJECT 28 | public: 29 | ESCPOSToolWidgetCharm(ESCPOSToolWidget *widget); 30 | public slots: 31 | void setStateFromFormat(const QTextCharFormat & format); 32 | 33 | void setTextEdit(QTextEdit* textEdit); 34 | void unsetCurrentTextEdit(); 35 | 36 | private: 37 | ESCPOSToolWidget *m_widget = nullptr; 38 | QTextEdit *m_textEdit = nullptr; 39 | }; 40 | 41 | class ESCPOSToolButton : public QToolButton, public ESCPOSToolWidget 42 | { 43 | Q_OBJECT 44 | public: 45 | ESCPOSToolButton(QWidget *parent = nullptr); 46 | 47 | protected slots: 48 | virtual void clicked() = 0; 49 | }; 50 | 51 | class ESCPOSTextEditAlignLeft : public ESCPOSToolButton 52 | { 53 | Q_OBJECT 54 | public: 55 | ESCPOSTextEditAlignLeft(QWidget *parent = nullptr) : ESCPOSToolButton(parent) {} 56 | private slots: 57 | void clicked() override; 58 | }; 59 | 60 | class ESCPOSTextEditAlignRight : public ESCPOSToolButton 61 | { 62 | Q_OBJECT 63 | public: 64 | ESCPOSTextEditAlignRight(QWidget *parent = nullptr) : ESCPOSToolButton(parent) {} 65 | private slots: 66 | void clicked() override; 67 | }; 68 | 69 | class ESCPOSTextEditAlignCenter : public ESCPOSToolButton 70 | { 71 | Q_OBJECT 72 | public: 73 | ESCPOSTextEditAlignCenter(QWidget *parent = nullptr) : ESCPOSToolButton(parent) {} 74 | private slots: 75 | void clicked() override; 76 | }; 77 | 78 | class ESCPOSTextEditBold : public ESCPOSToolButton 79 | { 80 | Q_OBJECT 81 | public: 82 | ESCPOSTextEditBold(QWidget *parent = nullptr) : ESCPOSToolButton(parent) {} 83 | virtual void setStateFromFormat(const QTextCharFormat & format) override; 84 | 85 | private slots: 86 | void clicked() override; 87 | }; 88 | 89 | class ESCPOSTextEditUnderLine : public ESCPOSToolButton 90 | { 91 | Q_OBJECT 92 | public: 93 | ESCPOSTextEditUnderLine(QWidget *parent = nullptr) : ESCPOSToolButton(parent) {} 94 | virtual void setStateFromFormat(const QTextCharFormat & format) override; 95 | 96 | private slots: 97 | void clicked() override; 98 | }; 99 | 100 | class ESCPOSFontSizeComboBox : public QComboBox, public ESCPOSToolWidget 101 | { 102 | Q_OBJECT 103 | public: 104 | ESCPOSFontSizeComboBox(QWidget *parent = nullptr); 105 | void setStateFromFormat(const QTextCharFormat & format) override; 106 | private slots: 107 | void activatedSlot(int index); 108 | }; 109 | 110 | #endif // ESCPOSTEXTEDITWIDGETS_H 111 | -------------------------------------------------------------------------------- /escpostexteditwidgets.cpp: -------------------------------------------------------------------------------- 1 | #include "escpostexteditwidgets.h" 2 | 3 | #include 4 | 5 | ESCPOSToolButton::ESCPOSToolButton(QWidget *parent) 6 | : QToolButton(parent), ESCPOSToolWidget() 7 | { 8 | setCheckable(true); 9 | connect(this, &QToolButton::clicked, this, &ESCPOSToolButton::clicked); 10 | } 11 | 12 | void ESCPOSTextEditAlignLeft::clicked() 13 | { 14 | if (m_textEdit != nullptr) 15 | m_textEdit->setAlignment(Qt::AlignLeft); 16 | } 17 | 18 | void ESCPOSTextEditAlignRight::clicked() 19 | { 20 | if (m_textEdit != nullptr) 21 | m_textEdit->setAlignment(Qt::AlignRight); 22 | } 23 | 24 | 25 | 26 | void ESCPOSTextEditAlignCenter::clicked() 27 | { 28 | if (m_textEdit != nullptr) 29 | m_textEdit->setAlignment(Qt::AlignCenter); 30 | } 31 | 32 | 33 | void ESCPOSTextEditBold::setStateFromFormat(const QTextCharFormat &format) 34 | { 35 | setChecked(format.fontWeight() == QFont::Bold); 36 | } 37 | 38 | void ESCPOSTextEditBold::clicked() 39 | { 40 | if (m_textEdit != nullptr) { 41 | QTextCursor cursor = m_textEdit->textCursor(); 42 | if (!cursor.hasSelection()) 43 | cursor.select(QTextCursor::WordUnderCursor); 44 | QTextCharFormat format = cursor.charFormat(); 45 | if (format.fontWeight() == QFont::Bold) 46 | format.setFontWeight(QFont::Normal); 47 | else 48 | format.setFontWeight(QFont::Bold); 49 | m_textEdit->mergeCurrentCharFormat(format); 50 | } 51 | } 52 | 53 | void ESCPOSTextEditUnderLine::setStateFromFormat(const QTextCharFormat &format) 54 | { 55 | setChecked(format.underlineStyle() == QTextCharFormat::SingleUnderline); 56 | } 57 | 58 | void ESCPOSTextEditUnderLine::clicked() 59 | { 60 | if (m_textEdit != nullptr) { 61 | QTextCursor cursor = m_textEdit->textCursor(); 62 | if (!cursor.hasSelection()) 63 | cursor.select(QTextCursor::WordUnderCursor); 64 | QTextCharFormat format = cursor.charFormat(); 65 | if (format.underlineStyle() == QTextCharFormat::NoUnderline) 66 | format.setUnderlineStyle(QTextCharFormat::SingleUnderline); 67 | else 68 | format.setUnderlineStyle(QTextCharFormat::NoUnderline); 69 | m_textEdit->mergeCurrentCharFormat(format); 70 | } 71 | } 72 | 73 | 74 | ESCPOSFontSizeComboBox::ESCPOSFontSizeComboBox(QWidget *parent) : 75 | QComboBox(parent), ESCPOSToolWidget() 76 | { 77 | addItem(tr("Font B (~ 9pt)")); 78 | addItem(tr("Font A (~ 12pt)")); 79 | connect(this, SIGNAL(activated(int)), this, SLOT(activatedSlot(int))); 80 | } 81 | 82 | void ESCPOSFontSizeComboBox::setStateFromFormat(const QTextCharFormat &format) 83 | { 84 | setCurrentIndex(qFuzzyCompare(format.fontPointSize(), 9.0) ? 0 : 1); 85 | } 86 | 87 | void ESCPOSFontSizeComboBox::activatedSlot(int index) 88 | { 89 | if (m_textEdit != nullptr) { 90 | QTextCursor cursor = m_textEdit->textCursor(); 91 | if (!cursor.hasSelection()) 92 | cursor.select(QTextCursor::WordUnderCursor); 93 | QTextCharFormat format = cursor.charFormat(); 94 | format.setFontPointSize(index == 0?9:12); 95 | m_textEdit->mergeCurrentCharFormat(format); 96 | } 97 | } 98 | 99 | ESCPOSToolWidget::ESCPOSToolWidget() : 100 | m_textEdit(nullptr) 101 | { 102 | m_charm = new ESCPOSToolWidgetCharm(this); 103 | } 104 | 105 | ESCPOSToolWidget::~ESCPOSToolWidget() 106 | { 107 | delete m_charm; 108 | } 109 | 110 | void ESCPOSToolWidget::setTextEdit(QTextEdit *textEdit) 111 | { 112 | m_textEdit = textEdit; 113 | m_charm->setTextEdit(textEdit); 114 | } 115 | 116 | void ESCPOSToolWidget::unsetCurrentTextEdit() 117 | { 118 | m_charm->unsetCurrentTextEdit(); 119 | m_textEdit = nullptr; 120 | } 121 | 122 | void ESCPOSToolWidget::setStateFromFormat(const QTextCharFormat &format) 123 | { 124 | Q_UNUSED(format); 125 | } 126 | 127 | ESCPOSToolWidgetCharm::ESCPOSToolWidgetCharm(ESCPOSToolWidget *widget) : 128 | QObject (nullptr), 129 | m_widget(widget) 130 | { 131 | 132 | } 133 | 134 | void ESCPOSToolWidgetCharm::setStateFromFormat(const QTextCharFormat &format) 135 | { 136 | m_widget->setStateFromFormat(format); 137 | } 138 | 139 | void ESCPOSToolWidgetCharm::setTextEdit(QTextEdit *textEdit) 140 | { 141 | m_textEdit = textEdit; 142 | connect(m_textEdit, &QTextEdit::currentCharFormatChanged, this, &ESCPOSToolWidgetCharm::setStateFromFormat); 143 | } 144 | 145 | void ESCPOSToolWidgetCharm::unsetCurrentTextEdit() 146 | { 147 | if (m_textEdit) 148 | disconnect(m_textEdit, &QTextEdit::currentCharFormatChanged, this, &ESCPOSToolWidgetCharm::setStateFromFormat); 149 | m_textEdit = nullptr; 150 | } 151 | -------------------------------------------------------------------------------- /example/dialogprinttemplate.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | DialogPrintTemplate 4 | 5 | 6 | 7 | 0 8 | 0 9 | 521 10 | 416 11 | 12 | 13 | 14 | Print template 15 | 16 | 17 | 18 | 19 | 20 | QDialogButtonBox::Cancel|QDialogButtonBox::Reset|QDialogButtonBox::Save 21 | 22 | 23 | 24 | 25 | 26 | 27 | Test print 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | Courier New 36 | 37 | 38 | 39 | QTextEdit::FixedPixelWidth 40 | 41 | 42 | 410 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | Left align 55 | 56 | 57 | ... 58 | 59 | 60 | 61 | :/icons/textleft.png:/icons/textleft.png 62 | 63 | 64 | 65 | 66 | 67 | 68 | Center align 69 | 70 | 71 | ... 72 | 73 | 74 | 75 | :/icons/textcenter.png:/icons/textcenter.png 76 | 77 | 78 | 79 | 80 | 81 | 82 | Right align 83 | 84 | 85 | ... 86 | 87 | 88 | 89 | :/icons/textright.png:/icons/textright.png 90 | 91 | 92 | 93 | 94 | 95 | 96 | ... 97 | 98 | 99 | 100 | :/icons/textbold.png:/icons/textbold.png 101 | 102 | 103 | 104 | 105 | 106 | 107 | ... 108 | 109 | 110 | 111 | :/icons/textunder.png:/icons/textunder.png 112 | 113 | 114 | 115 | 116 | 117 | 118 | Qt::Horizontal 119 | 120 | 121 | 122 | 40 123 | 20 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | ESCPOSTextEditAlignLeft 135 | QToolButton 136 |
escpostexteditwidgets.h
137 |
138 | 139 | ESCPOSTextEditAlignRight 140 | QToolButton 141 |
escpostexteditwidgets.h
142 |
143 | 144 | ESCPOSTextEditAlignCenter 145 | QToolButton 146 |
escpostexteditwidgets.h
147 |
148 | 149 | ESCPOSTextEditBold 150 | QToolButton 151 |
escpostexteditwidgets.h
152 |
153 | 154 | ESCPOSTextEditUnderLine 155 | QToolButton 156 |
escpostexteditwidgets.h
157 |
158 | 159 | ESCPOSFontSizeComboBox 160 | QComboBox 161 |
escpostexteditwidgets.h
162 |
163 |
164 | 165 | 166 | 167 | 168 |
169 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /qescpos.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ProjectExplorer.Project.ActiveTarget 7 | 0 8 | 9 | 10 | ProjectExplorer.Project.EditorSettings 11 | 12 | true 13 | false 14 | true 15 | 16 | Cpp 17 | 18 | CppGlobal 19 | 20 | 21 | 22 | QmlJS 23 | 24 | QmlJSGlobal 25 | 26 | 27 | 2 28 | UTF-8 29 | false 30 | 4 31 | false 32 | 80 33 | true 34 | true 35 | 1 36 | true 37 | false 38 | 0 39 | true 40 | 0 41 | 8 42 | true 43 | 1 44 | true 45 | true 46 | true 47 | false 48 | 49 | 50 | 51 | ProjectExplorer.Project.PluginSettings 52 | 53 | 54 | 55 | ProjectExplorer.Project.Target.0 56 | 57 | Desktop (5.0.1) 58 | Desktop (5.0.1) 59 | {a1177b84-fe07-4ba1-9e50-c17187dceb08} 60 | 0 61 | 0 62 | 0 63 | 64 | /home/mm/Projektek/eagle/pbcoop_merleg/src/configurator/build-qescpos-Desktop_5_0_1-Debug 65 | 66 | 67 | true 68 | qmake 69 | 70 | QtProjectManager.QMakeBuildStep 71 | false 72 | true 73 | 74 | false 75 | 76 | 77 | true 78 | Make 79 | 80 | Qt4ProjectManager.MakeStep 81 | 82 | -w 83 | -r 84 | 85 | false 86 | 87 | 88 | 89 | 2 90 | Build 91 | 92 | ProjectExplorer.BuildSteps.Build 93 | 94 | 95 | 96 | true 97 | Make 98 | 99 | Qt4ProjectManager.MakeStep 100 | 101 | -w 102 | -r 103 | 104 | true 105 | clean 106 | 107 | 108 | 1 109 | Clean 110 | 111 | ProjectExplorer.BuildSteps.Clean 112 | 113 | 2 114 | false 115 | 116 | Debug 117 | 118 | Qt4ProjectManager.Qt4BuildConfiguration 119 | 2 120 | true 121 | 122 | 123 | /home/mm/Projektek/eagle/pbcoop_merleg/src/configurator/build-qescpos-Desktop_5_0_1-Release 124 | 125 | 126 | true 127 | qmake 128 | 129 | QtProjectManager.QMakeBuildStep 130 | false 131 | true 132 | 133 | false 134 | 135 | 136 | true 137 | Make 138 | 139 | Qt4ProjectManager.MakeStep 140 | 141 | -w 142 | -r 143 | 144 | false 145 | 146 | 147 | 148 | 2 149 | Build 150 | 151 | ProjectExplorer.BuildSteps.Build 152 | 153 | 154 | 155 | true 156 | Make 157 | 158 | Qt4ProjectManager.MakeStep 159 | 160 | -w 161 | -r 162 | 163 | true 164 | clean 165 | 166 | 167 | 1 168 | Clean 169 | 170 | ProjectExplorer.BuildSteps.Clean 171 | 172 | 2 173 | false 174 | 175 | Release 176 | 177 | Qt4ProjectManager.Qt4BuildConfiguration 178 | 0 179 | true 180 | 181 | 2 182 | 183 | 184 | 0 185 | Deploy 186 | 187 | ProjectExplorer.BuildSteps.Deploy 188 | 189 | 1 190 | Deploy locally 191 | 192 | ProjectExplorer.DefaultDeployConfiguration 193 | 194 | 1 195 | 196 | 197 | 198 | false 199 | false 200 | false 201 | false 202 | true 203 | 0.01 204 | 10 205 | true 206 | 1 207 | 25 208 | 209 | 1 210 | true 211 | false 212 | true 213 | valgrind 214 | 215 | 0 216 | 1 217 | 2 218 | 3 219 | 4 220 | 5 221 | 6 222 | 7 223 | 8 224 | 9 225 | 10 226 | 11 227 | 12 228 | 13 229 | 14 230 | 231 | 2 232 | 233 | qescpos 234 | qescpos2 235 | Qt4ProjectManager.Qt4RunConfiguration:/home/mm/Projektek/qt/qescpos/qescpos.pro 236 | 237 | qescpos.pro 238 | false 239 | false 240 | 241 | 3768 242 | false 243 | true 244 | false 245 | false 246 | true 247 | 248 | 1 249 | 250 | 251 | 252 | ProjectExplorer.Project.TargetCount 253 | 1 254 | 255 | 256 | ProjectExplorer.Project.Updater.EnvironmentId 257 | {f3429c64-21f5-4580-b39f-af8f9fb0c5ef} 258 | 259 | 260 | ProjectExplorer.Project.Updater.FileVersion 261 | 15 262 | 263 | 264 | --------------------------------------------------------------------------------