qt_demoe/ui/core_common/quihelper.h

131 lines
5.1 KiB
C
Raw Normal View History

2021-11-17 07:33:19 +00:00
#ifndef QUIHELPER2_H
#define QUIHELPER2_H
#include "head.h"
class QUIHelper
{
public:
//获取当前鼠标所在屏幕索引+尺寸
static int getScreenIndex();
static QRect getScreenRect(bool available = true);
//获取桌面宽度高度+居中显示
static int deskWidth();
static int deskHeight();
2022-04-05 12:54:45 +00:00
static QSize deskSize();
2021-11-17 07:33:19 +00:00
//居中显示窗体
//定义标志位指定是以桌面为参照还是主程序界面为参照
static QWidget *centerBaseForm;
static void setFormInCenter(QWidget *form);
2022-04-05 12:54:45 +00:00
static void showForm(QWidget *form);
2021-11-17 07:33:19 +00:00
//程序文件名称+当前所在路径
static QString appName();
static QString appPath();
2022-04-05 12:54:45 +00:00
//获取本地网卡IP集合
static QStringList getLocalIPs();
//获取内置颜色集合
static QList<QColor> colors;
static QList<QColor> getColorList();
static QStringList getColorNames();
//随机获取颜色集合中的颜色
static QColor getRandColor();
//初始化随机数种子
2021-11-17 07:33:19 +00:00
static void initRand();
2022-04-05 12:54:45 +00:00
//获取随机小数
static float getRandFloat(float min, float max);
//获取随机数,指定最小值和最大值
static double getRandValue(int min, int max, bool contansMin = false, bool contansMax = false);
//获取范围值随机经纬度集合
static QStringList getRandPoint(int count, float mainLng, float mainLat, float dotLng, float dotLat);
//获取uuid
static QString getUuid();
//可执行文件目录下新建目录
2021-11-17 07:33:19 +00:00
static void newDir(const QString &dirName);
2022-04-05 12:54:45 +00:00
//延时
2021-11-17 07:33:19 +00:00
static void sleep(int msec);
2022-04-05 12:54:45 +00:00
//设置Qt自带样式
2021-11-17 07:33:19 +00:00
static void setStyle();
2022-04-05 12:54:45 +00:00
//设置字体
static QFont addFont(const QString &fontFile, const QString &fontName);
static void setFont(int fontSize = 12);
//设置编码
2021-11-17 07:33:19 +00:00
static void setCode(bool utf8 = true);
2022-04-05 12:54:45 +00:00
//设置翻译文件
2021-11-17 07:33:19 +00:00
static void setTranslator(const QString &qmFile);
2022-04-05 12:54:45 +00:00
2022-05-01 03:38:30 +00:00
//一次性设置所有包括编码样式字体等
static void initAll(bool utf8 = true, bool style = true, int fontSize = 13);
2022-04-05 12:54:45 +00:00
//初始化main函数最前面执行的一段代码
static void initMain(bool on = true);
//插入消息
static QVector<int> msgTypes;
static QVector<QString> msgKeys;
static QVector<QColor> msgColors;
static QString appendMsg(QTextEdit *textEdit, int type, const QString &data,
int maxCount, int &currentCount,
bool clear = false, bool pause = false);
2021-11-17 07:33:19 +00:00
//设置无边框
static void setFramelessForm(QWidget *widgetMain, bool tool = false, bool top = false, bool menu = true);
//弹出框
static int showMessageBox(const QString &info, int type = 0, int closeSec = 0, bool exec = false);
//弹出消息框
static void showMessageBoxInfo(const QString &info, int closeSec = 0, bool exec = false);
//弹出错误框
static void showMessageBoxError(const QString &info, int closeSec = 0, bool exec = false);
//弹出询问框
static int showMessageBoxQuestion(const QString &info);
2022-04-05 12:54:45 +00:00
//为什么还要自定义对话框因为可控宽高和汉化对应文本等
//初始化对话框文本
static void initDialog(QFileDialog *dialog, const QString &title, const QString &acceptName,
const QString &dirName, bool native, int width, int height);
//拿到对话框结果
static QString getDialogResult(QFileDialog *dialog);
//选择文件对话框
static QString getOpenFileName(const QString &filter = QString(),
const QString &dirName = QString(),
const QString &fileName = QString(),
bool native = false, int width = 900, int height = 600);
//保存文件对话框
static QString getSaveFileName(const QString &filter = QString(),
const QString &dirName = QString(),
const QString &fileName = QString(),
bool native = false, int width = 900, int height = 600);
//选择目录对话框
static QString getExistingDirectory(const QString &dirName = QString(),
bool native = false, int width = 900, int height = 600);
2021-11-17 07:33:19 +00:00
//异或加密-只支持字符,如果是中文需要将其转换base64编码
static QString getXorEncryptDecrypt(const QString &value, char key);
//异或校验
static uchar getOrCode(const QByteArray &data);
//计算校验码
static uchar getCheckCode(const QByteArray &data);
//初始化表格
static void initTableView(QTableView *tableView, int rowHeight = 25,
bool headVisible = false, bool edit = false,
bool stretchLast = true);
//打开文件带提示框
static void openFile(const QString &fileName, const QString &msg);
//检查ini配置文件
static bool checkIniFile(const QString &iniFile);
2022-05-01 03:38:30 +00:00
//首尾截断字符串显示
static QString cutString(const QString &text, int len, int left, int right, const QString &mid = "...");
2021-11-17 07:33:19 +00:00
};
#endif // QUIHELPER2_H