2,新增“Apps”; 3,新增“Common”; 4,新增“FileList”; 5,新增“MediaX”; 6,新增“OpenSource”; 7,新增“Samples”; 8,新增“SoftwareBusinessLines”.
153 lines
4.3 KiB
C++
153 lines
4.3 KiB
C++
//#if _MSC_VER >= 1600
|
|
//#pragma execution_character_set("utf-8")
|
|
//#endif
|
|
|
|
#ifndef COMMONHELPER_H
|
|
#define COMMONHELPER_H
|
|
|
|
#include <QtCore>
|
|
#include <QtGui>
|
|
#include <QDesktopWidget>
|
|
#include "frmmessagebox.h"
|
|
|
|
class CommonHelper: public QObject
|
|
{
|
|
signals:
|
|
void sigCurrentStyleIndex(int index); // 主题切换信号
|
|
|
|
public:
|
|
|
|
//设置为开机启动
|
|
static void AutoRunWithSystem(bool IsAutoRun, QString AppName, QString AppPath)
|
|
{
|
|
QSettings* reg = new QSettings(
|
|
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
|
|
QSettings::NativeFormat);
|
|
|
|
if (IsAutoRun)
|
|
{
|
|
reg->setValue(AppName, AppPath);
|
|
}
|
|
else
|
|
{
|
|
reg->setValue(AppName, "");
|
|
}
|
|
}
|
|
|
|
//设置编码为UTF8
|
|
static void SetUTF8Code()
|
|
{
|
|
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
|
|
QTextCodec* codec = QTextCodec::codecForName("UTF-8");
|
|
QTextCodec::setCodecForLocale(codec);
|
|
QTextCodec::setCodecForCStrings(codec);
|
|
QTextCodec::setCodecForTr(codec);
|
|
#endif
|
|
}
|
|
|
|
//设置皮肤样式
|
|
static void SetStyle(const QString& styleName)
|
|
{
|
|
// 使用资源路径加载
|
|
QFile file(QString(":/skin/stylesheet/%1.qss").arg(styleName));
|
|
file.open(QFile::ReadOnly);
|
|
QString qss = QLatin1String(file.readAll());
|
|
|
|
// 设置样式表
|
|
qApp->setStyleSheet(qss);
|
|
}
|
|
|
|
//加载中文字符
|
|
static void SetChinese()
|
|
{
|
|
QTranslator* translator = new QTranslator(qApp);
|
|
translator->load(":/skin/image/qt_zh_CN.qm");
|
|
qApp->installTranslator(translator);
|
|
}
|
|
|
|
//判断是否是IP地址
|
|
static bool IsIP(QString IP)
|
|
{
|
|
QRegExp RegExp("((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)");
|
|
return RegExp.exactMatch(IP);
|
|
}
|
|
|
|
//显示信息框,仅确定按钮
|
|
static void ShowMessageBoxInfo(QString info, QWidget* parent)
|
|
{
|
|
frmMessageBox* msg = new frmMessageBox(nullptr);
|
|
msg->SetMessage(info, 0);
|
|
|
|
if (nullptr != parent)
|
|
{
|
|
QRect rcParent = parent->geometry();
|
|
QPoint ptParent = parent->mapToGlobal(QPoint(0, 0));
|
|
ptParent.setX(ptParent.x() + rcParent.width() / 2 - msg->width() / 2);
|
|
ptParent.setY(ptParent.y() + rcParent.height() / 2 - msg->height() / 2);
|
|
msg->move(ptParent);
|
|
}
|
|
|
|
msg->exec();
|
|
}
|
|
|
|
//显示错误框,仅确定按钮
|
|
static void ShowMessageBoxError(QString info, QWidget* parent)
|
|
{
|
|
frmMessageBox* msg = new frmMessageBox(nullptr);
|
|
msg->SetMessage(info, 2);
|
|
|
|
if (nullptr != parent)
|
|
{
|
|
QRect rcParent = parent->geometry();
|
|
QPoint ptParent = parent->mapToGlobal(QPoint(0, 0));
|
|
ptParent.setX(ptParent.x() + rcParent.width() / 2 - msg->width() / 2);
|
|
ptParent.setY(ptParent.y() + rcParent.height() / 2 - msg->height() / 2);
|
|
msg->move(ptParent);
|
|
}
|
|
|
|
msg->exec();
|
|
}
|
|
|
|
//显示询问框,确定和取消按钮
|
|
static int ShowMessageBoxQuesion(QString info, QWidget* parent, QString strOK = "确定", QString strCancel = "取消")
|
|
{
|
|
frmMessageBox* msg = new frmMessageBox(nullptr, strOK, strCancel);
|
|
msg->SetMessage(info, 1);
|
|
|
|
if (nullptr != parent)
|
|
{
|
|
QRect rcParent = parent->geometry();
|
|
QPoint ptParent = parent->mapToGlobal(QPoint(0, 0));
|
|
ptParent.setX(ptParent.x() + rcParent.width() / 2 - msg->width() / 2);
|
|
ptParent.setY(ptParent.y() + rcParent.height() / 2 - msg->height() / 2);
|
|
msg->move(ptParent);
|
|
}
|
|
|
|
return msg->exec();
|
|
}
|
|
|
|
//延时
|
|
static void Sleep(int sec)
|
|
{
|
|
QTime dieTime = QTime::currentTime().addMSecs(sec);
|
|
while (QTime::currentTime() < dieTime)
|
|
{
|
|
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
|
|
}
|
|
}
|
|
|
|
//窗体居中显示
|
|
static void FormInCenter(QWidget* frm)
|
|
{
|
|
int frmX = frm->width();
|
|
int frmY = frm->height();
|
|
QDesktopWidget w;
|
|
int deskWidth = w.width();
|
|
int deskHeight = w.height();
|
|
QPoint movePoint(deskWidth / 2 - frmX / 2, deskHeight / 2 - frmY / 2);
|
|
frm->move(movePoint);
|
|
}
|
|
};
|
|
|
|
#endif // COMMONHELPER_H
|