demand

1. Label designer; 2. With text typesetting function; 3. Support six typesetting formats; 4. After typesetting, it can be printed (not included in demo); 5. After typesetting, you can output the specified protocol text of the label in FBD format. 6. You can adjust some positions of corresponding labels, such as X, Y, width, height, horizontal spacing and vertical spacing; 7. Support label preview after typesetting; 8. Error message of label typesetting text;


The Demo v1.6.0

                    

Experience download address

CSDN (fans from integral download) : download.csdn.net/download/qq… QQ group: 1047134658 (click “file” to search for “labelDesigner”, update the group with the blog post)


modular

Modular design framework:


Core source dock file

Widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QTextCodec>
#include <QWidget>
#include <QAbstractButton>
#include <QFileDialog>
#include <QMessageBox>
#include "LabelWidget.h"

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget(a);protected:
    void initControls(a);
    void createLabelWidgets(a);
    void updateLabelWidgets(a);
    void updateScale(a);
    QStringList parseNames(QString content);

protected slots:
    void slot_updateScale(a);
    void slot_buttonClicked(QAbstractButton *pAbstractButton);

protected:
    void resizeEvent(QResizeEvent *event);

private slots:
    void on_spinBox_x_valueChanged(int arg1);
    void on_spinBox_y_valueChanged(int arg1);
    void on_spinBox_xNumber_valueChanged(int arg1);
    void on_spinBox_yNumber_valueChanged(int arg1);
    void on_spinBox_labelWidth_valueChanged(int arg1);
    void on_spinBox_labelHeight_valueChanged(int arg1);
    void on_doubleSpinBox_scale_valueChanged(double arg1);
    void on_spinBox_labelVerticallSpace_valueChanged(int arg1);
    void on_spinBox_labelHorizalSpace_valueChanged(int arg1);
    void on_textEdit_names_textChanged(a);
    void on_pushButton_createLabel_clicked(a);

    void on_pushButton_export_clicked(a);

private:
    Ui::Widget *ui;

private:
    QList<LabelWidget *> _listLabelWidget;
    QStringList _listNames;
    QStringList _listErrorNames;

    int _xMM;
    int _yMM;
    int _widthMM;
    int _heightMM;
    int _widthSpace;
    int _heightSpace;
    int _widthNumber;
    int _heightNumber;
    bool _firstRotate180;
    bool _secondRotate180;
    bool _showFontVertical;
    int _fontPt;
};

#endif // WIDGET_H
Copy the code

ScreenManager.h

#ifndef SCREENMANAGER_H
#define SCREENMANAGER_H

#include <QObject>

class ScreenManager : public QObject
{
    Q_OBJECT
public:
    explicit ScreenManager(QObject *parent = nullptr);

signals:

public slots:

public:
    static float getScreenWidthMM(a);
    static float getScreenHeightMM(a);
    static float getScreenWidthMM(int width);
    static float getScreenHeightMM(int height);
    static int getWidth(a);
    static int getHeight(a);
    static int getWidth(float widthMM);
    static int getHeight(float heightMM);

private:
    static float inchToMMScale;

};

#endif // SCREENMANAGER_H
Copy the code

LabelWidget.h

#ifndef LABELWIDGET_H
#define LABELWIDGET_H

#include <QWidget>
#include <QTimer>
#include <QtMath>

namespace Ui {
class LabelWidget;
}

class LabelWidget : public QWidget
{
    Q_OBJECT

public:
    explicit LabelWidget(QWidget *parent = 0);
    ~LabelWidget(a);public:
    float getXMM(a) const;
    float getYMM(a) const;
    float getLabelWidthMM(a) const;
    float getLabelHeightMM(a) const;
    int getVerticalLabelsNumber(a) const;
    int getHorizalLabelNumber(a) const;
    float getScale(a) const;
    float getLabelHorizalSpaceMM(a) const;
    float getLabelVerticalSpaceMM(a) const;
    QStringList getListName(a) const;
    bool getFirstLabelRotate180(a) const;
    bool getSecondLabelRotate180(a) const;
    int getFontPt(a) const;
    bool getShowFontVertical(a) const;

public:
    void setXMM(float xMM);
    void setYMM(float yMM);
    void setLabelWidthMM(float labelWidthMM);
    void setLabelHeightMM(float labelHeightMM);
    void setVerticalLabelsNumber(int verticalLabelsNumber);
    void setHorizalLabelNumber(int horizalLabelNumber);
    void setScale(float scale);
    void setLabelHorizalSpaceMM(float labelHorizalSpaceMM);
    void setLabelVerticalSpaceMM(float labelVerticalSpaceMM);
    void setLabelsNames(QStringList listName);
    void setFirstLabelRotate180(bool firstLabelRotate180);
    void setSecondLabelRotate180(bool secondLabelRotate180);
    void setFontPt(int fontPt);
    void setShowFontVertical(bool showFontVertical);


protected:
    void initControls(a);
    void updateSize(a);

protected slots:
    void slot_initScale(a);       // Used to avoid initialization location bias

protected:
    void paintEvent(QPaintEvent *event);
    void resizeEvent(QResizeEvent *event);

protected:
    void drawBackground(QPainter *painter);
    void drawLabelBorder(QPainter *painter);
    void drawLabel(QPainter *painter);

private:
    Ui::LabelWidget *ui;

private:
    QColor _backgroundColor;
    QColor _labelBorderColor;
    int _labelBorderWidth;

    float _labelWidthMM;
    float _labelHeightMM;
    float _labelHorizalSpaceMM;
    float _labelVerticalSpaceMM;
    int _verticalLabelsNumber;
    int _horizalLabelNumber;
    float _xMM;
    float _yMM;
    float _pageWidthMM;
    float _pageHeightMM;
    float _scale;

    int _x;
    int _y;
    int _labelWidth;
    int _labelHeight;
    int _pageWidth;
    int _pageHeight;
    int _labelHorizalSpace;
    int _labelVerticalSpace;

    bool _firstLabelRotate180;
    bool _secondLabelRotate180;
    int _fontPt;
    bool _showFontVertical;

    QStringList _listName;
};

#endif
Copy the code


If the paper is original articles, reprint please indicate the original source This article blog: hpzwl.blog.csdn.net/article/det…