diff --git a/TreasureFinder.pro b/TreasureFinder.pro index a44a57a..40f401e 100644 --- a/TreasureFinder.pro +++ b/TreasureFinder.pro @@ -8,6 +8,9 @@ CONFIG += c++11 # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 +INCLUDEPATH += $$PWD/core_base +include ($$PWD/core_base/core_base.pri) + SOURCES += \ basedatamanager.cpp \ main.cpp \ @@ -57,3 +60,6 @@ TRANSLATIONS += treasurefinder_zh_CN.ts qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target + +RESOURCES += \ + qss.qrc diff --git a/core_base/appdata.cpp b/core_base/appdata.cpp new file mode 100644 index 0000000..b532a42 --- /dev/null +++ b/core_base/appdata.cpp @@ -0,0 +1,20 @@ +#include "appdata.h" +#include "quihelper.h" + +QString AppData::TitleFlag = "(QQ: 517216493 WX: feiyangqingyun)"; +int AppData::RowHeight = 25; +int AppData::RightWidth = 180; +int AppData::FormWidth = 1200; +int AppData::FormHeight = 750; + +void AppData::checkRatio() +{ + //根据分辨率设定宽高 + int width = QUIHelper::deskWidth(); + if (width >= 1440) { + RowHeight = RowHeight < 25 ? 25 : RowHeight; + RightWidth = RightWidth < 220 ? 220 : RightWidth; + FormWidth = FormWidth < 1200 ? 1200 : FormWidth; + FormHeight = FormHeight < 800 ? 800 : FormHeight; + } +} diff --git a/core_base/appdata.h b/core_base/appdata.h new file mode 100644 index 0000000..197adf4 --- /dev/null +++ b/core_base/appdata.h @@ -0,0 +1,18 @@ +#ifndef APPDATA_H +#define APPDATA_H + +#include "head.h" + +class AppData +{ +public: + static QString TitleFlag; //标题标识 + static int RowHeight; //行高 + static int RightWidth; //右侧宽度 + static int FormWidth; //窗体宽度 + static int FormHeight; //窗体高度 + + static void checkRatio(); //校验分辨率 +}; + +#endif // APPDATA_H diff --git a/core_base/appinit.cpp b/core_base/appinit.cpp new file mode 100644 index 0000000..8ecdb2a --- /dev/null +++ b/core_base/appinit.cpp @@ -0,0 +1,57 @@ +#include "appinit.h" +#include "qmutex.h" +#include "qapplication.h" +#include "qevent.h" +#include "qwidget.h" +#include "qdebug.h" + +QScopedPointer AppInit::self; +AppInit *AppInit::Instance() +{ + if (self.isNull()) { + static QMutex mutex; + QMutexLocker locker(&mutex); + if (self.isNull()) { + self.reset(new AppInit); + } + } + + return self.data(); +} + +AppInit::AppInit(QObject *parent) : QObject(parent) +{ +} + +bool AppInit::eventFilter(QObject *watched, QEvent *event) +{ + QWidget *w = (QWidget *)watched; + if (!w->property("canMove").toBool()) { + return QObject::eventFilter(watched, event); + } + + static QPoint mousePoint; + static bool mousePressed = false; + + QMouseEvent *mouseEvent = static_cast(event); + if (mouseEvent->type() == QEvent::MouseButtonPress) { + if (mouseEvent->button() == Qt::LeftButton) { + mousePressed = true; + mousePoint = mouseEvent->globalPos() - w->pos(); + } + } else if (mouseEvent->type() == QEvent::MouseButtonRelease) { + mousePressed = false; + } else if (mouseEvent->type() == QEvent::MouseMove) { + if (mousePressed) { + w->move(mouseEvent->globalPos() - mousePoint); + return true; + } + } + + return QObject::eventFilter(watched, event); +} + +void AppInit::start() +{ + qApp->installEventFilter(this); +} diff --git a/core_base/appinit.h b/core_base/appinit.h new file mode 100644 index 0000000..467ad84 --- /dev/null +++ b/core_base/appinit.h @@ -0,0 +1,23 @@ +#ifndef APPINIT_H +#define APPINIT_H + +#include + +class AppInit : public QObject +{ + Q_OBJECT +public: + static AppInit *Instance(); + explicit AppInit(QObject *parent = 0); + +protected: + bool eventFilter(QObject *watched, QEvent *event); + +private: + static QScopedPointer self; + +public slots: + void start(); +}; + +#endif // APPINIT_H diff --git a/core_base/base64helper.cpp b/core_base/base64helper.cpp new file mode 100644 index 0000000..e294fcd --- /dev/null +++ b/core_base/base64helper.cpp @@ -0,0 +1,41 @@ +#include "base64helper.h" +#include "qbuffer.h" +#include "qdebug.h" + +QString Base64Helper::imageToBase64(const QImage &image) +{ + return QString(imageToBase64x(image)); +} + +QByteArray Base64Helper::imageToBase64x(const QImage &image) +{ + //这个转换可能比较耗时建议在线程中执行 + QByteArray data; + QBuffer buffer(&data); + image.save(&buffer, "JPG"); + data = data.toBase64(); + return data; +} + +QImage Base64Helper::base64ToImage(const QString &data) +{ + return base64ToImagex(data.toUtf8()); +} + +QImage Base64Helper::base64ToImagex(const QByteArray &data) +{ + //这个转换可能比较耗时建议在线程中执行 + QImage image; + image.loadFromData(QByteArray::fromBase64(data)); + return image; +} + +QString Base64Helper::textToBase64(const QString &text) +{ + return QString(text.toUtf8().toBase64()); +} + +QString Base64Helper::base64ToText(const QString &text) +{ + return QString(QByteArray::fromBase64(text.toUtf8())); +} diff --git a/core_base/base64helper.h b/core_base/base64helper.h new file mode 100644 index 0000000..e17cae6 --- /dev/null +++ b/core_base/base64helper.h @@ -0,0 +1,37 @@ +#ifndef BASE64HELPER_H +#define BASE64HELPER_H + +/** + * base64编码转换类 作者:feiyangqingyun(QQ:517216493) 2016-12-16 + * 1. 图片转base64字符串。 + * 2. base64字符串转图片。 + * 3. 字符转base64字符串。 + * 4. base64字符串转字符。 + * 5. 后期增加数据压缩。 + * 6. Qt6对base64编码转换进行了重写效率提升至少200%。 + */ + +#include + +#ifdef quc +class Q_DECL_EXPORT Base64Helper +#else +class Base64Helper +#endif + +{ +public: + //图片转base64字符串 + static QString imageToBase64(const QImage &image); + static QByteArray imageToBase64x(const QImage &image); + + //base64字符串转图片 + static QImage base64ToImage(const QString &data); + static QImage base64ToImagex(const QByteArray &data); + + //字符串与base64互转 + static QString textToBase64(const QString &text); + static QString base64ToText(const QString &text); +}; + +#endif // BASE64HELPER_H diff --git a/core_base/core_base.pri b/core_base/core_base.pri new file mode 100644 index 0000000..23865b3 --- /dev/null +++ b/core_base/core_base.pri @@ -0,0 +1,65 @@ +QT += network +greaterThan(QT_MAJOR_VERSION, 4) { +lessThan(QT_MAJOR_VERSION, 6) { +android {QT += androidextras} +} else { +QT += core-private +}} + +#指定编译产生的文件分门别类放到对应目录 +MOC_DIR = temp/moc +RCC_DIR = temp/rcc +UI_DIR = temp/ui +OBJECTS_DIR = temp/obj + +#指定编译生成的可执行文件放到源码上一级目录下的bin目录 +!android { +!wasm { +DESTDIR = $$PWD/../bin +}} + +#把所有警告都关掉眼不见为净 +CONFIG += warn_off +#开启大资源支持 +CONFIG += resources_big +#开启后会将打印信息用控制台输出 +#CONFIG += console +#开启后不会生成空的 debug release 目录 +#CONFIG -= debug_and_release + +#引入全志H3芯片依赖 +include ($$PWD/h3.pri) +#将当前目录加入到头文件路径 +INCLUDEPATH += $$PWD + +HEADERS += $$PWD/head.h +HEADERS += $$PWD/appdata.h +SOURCES += $$PWD/appdata.cpp + +HEADERS += $$PWD/appinit.h +SOURCES += $$PWD/appinit.cpp + +HEADERS += $$PWD/base64helper.h +SOURCES += $$PWD/base64helper.cpp + +HEADERS += $$PWD/customstyle.h +SOURCES += $$PWD/customstyle.cpp + +HEADERS += $$PWD/iconhelper.h +SOURCES += $$PWD/iconhelper.cpp + +HEADERS += $$PWD/quihelper.h +SOURCES += $$PWD/quihelper.cpp + +#可以指定不加载对应的资源文件 +!contains(DEFINES, no_qrc_image) { +RESOURCES += $$PWD/qrc/image.qrc +} + +!contains(DEFINES, no_qrc_qm) { +RESOURCES += $$PWD/qrc/qm.qrc +} + +!contains(DEFINES, no_qrc_font) { +RESOURCES += $$PWD/qrc/font.qrc +} diff --git a/core_base/customstyle.cpp b/core_base/customstyle.cpp new file mode 100644 index 0000000..6ea7402 --- /dev/null +++ b/core_base/customstyle.cpp @@ -0,0 +1,66 @@ +#include "customstyle.h" +#include "qapplication.h" +#include "qpalette.h" + +void CustomStyle::initStyle(int fontSize, int radioButtonSize, int checkBoxSize, int sliderHeight) +{ + if (fontSize <= 0) { + return; + } + + QStringList list; + //全局字体 + list << QString("*{font-size:%1px;}").arg(fontSize); + //单选框 + list << QString("QRadioButton::indicator{width:%1px;height:%1px;}").arg(radioButtonSize); + //复选框 + list << QString("QCheckBox::indicator,QGroupBox::indicator,QTreeWidget::indicator,QListWidget::indicator{width:%1px;height:%1px;}").arg(checkBoxSize); + + //滑块颜色 +#if 0 + QString normalColor = "#e3e3e3"; + QString grooveColor = "#0078d7"; + QString handleColor = "#FFFFFF"; + QString borderColor = "#9B9B9B"; +#else + QPalette palette; + for (int i = 0; i < 21; ++i) { + //qDebug() << i << palette.color((QPalette::ColorRole)i).name(); + } + + QString normalColor = palette.color(QPalette::Midlight).name(); + QString grooveColor = palette.color(QPalette::Highlight).name(); + QString handleColor = palette.color(QPalette::Light).name(); + QString borderColor = palette.color(QPalette::Shadow).name(); +#endif + int sliderRadius = sliderHeight / 2; + int handleWidth = (sliderHeight * 3) / 2 + (sliderHeight / 5); + int handleRadius = handleWidth / 2 + 1; + int handleOffset = handleRadius / 2; + + //横向滑块 + list << QString("QSlider::horizontal{min-height:%1px;}").arg(sliderHeight * 2); + list << QString("QSlider::groove:horizontal{background:%1;height:%2px;border-radius:%3px;}") + .arg(normalColor).arg(sliderHeight).arg(sliderRadius); + list << QString("QSlider::add-page:horizontal{background:%1;height:%2px;border-radius:%3px;}") + .arg(normalColor).arg(sliderHeight).arg(sliderRadius); + list << QString("QSlider::sub-page:horizontal{background:%1;height:%2px;border-radius:%3px;}") + .arg(grooveColor).arg(sliderHeight).arg(sliderRadius); + list << QString("QSlider::handle:horizontal{border:1px solid %5;width:%2px;margin-top:-%3px;margin-bottom:-%3px;border-radius:%4px;" + "background:qradialgradient(spread:pad,cx:0.5,cy:0.5,radius:0.5,fx:0.5,fy:0.5,stop:0.6 #FFFFFF,stop:0.8 %1);}") + .arg(handleColor).arg(handleWidth).arg(handleOffset).arg(handleRadius).arg(borderColor); + + //垂直滑块 + list << QString("QSlider::vertical{min-width:%1px;}").arg(sliderHeight * 2); + list << QString("QSlider::groove:vertical{background:%1;width:%2px;border-radius:%3px;}") + .arg(normalColor).arg(sliderHeight).arg(sliderRadius); + list << QString("QSlider::add-page:vertical{background:%1;width:%2px;border-radius:%3px;}") + .arg(grooveColor).arg(sliderHeight).arg(sliderRadius); + list << QString("QSlider::sub-page:vertical{background:%1;width:%2px;border-radius:%3px;}") + .arg(normalColor).arg(sliderHeight).arg(sliderRadius); + list << QString("QSlider::handle:vertical{border:1px solid %5;height:%2px;margin-left:-%3px;margin-right:-%3px;border-radius:%4px;" + "background:qradialgradient(spread:pad,cx:0.5,cy:0.5,radius:0.5,fx:0.5,fy:0.5,stop:0.6 #FFFFFF,stop:0.8 %1);}") + .arg(handleColor).arg(handleWidth).arg(handleOffset).arg(handleRadius).arg(borderColor); + + qApp->setStyleSheet(list.join("")); +} diff --git a/core_base/customstyle.h b/core_base/customstyle.h new file mode 100644 index 0000000..cdad7d5 --- /dev/null +++ b/core_base/customstyle.h @@ -0,0 +1,13 @@ +#ifndef CUSTOMSTYLE_H +#define CUSTOMSTYLE_H + +#include + +class CustomStyle +{ +public: + //全局样式比如放大选择器 + static void initStyle(int fontSize = 15, int radioButtonSize = 18, int checkBoxSize = 16, int sliderHeight = 13); +}; + +#endif // CUSTOMSTYLE_H diff --git a/core_base/h3.pri b/core_base/h3.pri new file mode 100644 index 0000000..65ec6d1 --- /dev/null +++ b/core_base/h3.pri @@ -0,0 +1,7 @@ +unix:!macx { +contains(QT_ARCH, arm) { +contains(DEFINES, arma7) { +INCLUDEPATH += /usr/local/openssl-1.0.2m-h3-gcc-4.9.2/include +LIBS += -L/usr/local/openssl-1.0.2m-h3-gcc-4.9.2/lib -lssl -lcrypto +LIBS += -L/usr/local/h3_rootfsv -lXdmcp +}}} diff --git a/core_base/head.h b/core_base/head.h new file mode 100644 index 0000000..a8d5a79 --- /dev/null +++ b/core_base/head.h @@ -0,0 +1,12 @@ +#include +#include + +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) +#include +#endif + +#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) +#include +#endif + +#pragma execution_character_set("utf-8") diff --git a/core_base/iconhelper.cpp b/core_base/iconhelper.cpp new file mode 100644 index 0000000..1e703e6 --- /dev/null +++ b/core_base/iconhelper.cpp @@ -0,0 +1,387 @@ +#include "iconhelper.h" + +IconHelper *IconHelper::iconFontAliBaBa = 0; +IconHelper *IconHelper::iconFontAwesome = 0; +IconHelper *IconHelper::iconFontAwesome6 = 0; +IconHelper *IconHelper::iconFontWeather = 0; +int IconHelper::iconFontIndex = -1; + +void IconHelper::initFont() +{ + static bool isInit = false; + if (!isInit) { + isInit = true; + if (iconFontAliBaBa == 0) { + iconFontAliBaBa = new IconHelper(":/font/iconfont.ttf", "iconfont"); + } + if (iconFontAwesome == 0) { + iconFontAwesome = new IconHelper(":/font/fontawesome-webfont.ttf", "FontAwesome"); + } + if (iconFontAwesome6 == 0) { + iconFontAwesome6 = new IconHelper(":/font/fa-regular-400.ttf", "Font Awesome 6 Pro Regular"); + } + if (iconFontWeather == 0) { + iconFontWeather = new IconHelper(":/font/pe-icon-set-weather.ttf", "pe-icon-set-weather"); + } + } +} + +void IconHelper::setIconFontIndex(int index) +{ + iconFontIndex = index; +} + +QFont IconHelper::getIconFontAliBaBa() +{ + initFont(); + return iconFontAliBaBa->getIconFont(); +} + +QFont IconHelper::getIconFontAwesome() +{ + initFont(); + return iconFontAwesome->getIconFont(); +} + +QFont IconHelper::getIconFontAwesome6() +{ + initFont(); + return iconFontAwesome6->getIconFont(); +} + +QFont IconHelper::getIconFontWeather() +{ + initFont(); + return iconFontWeather->getIconFont(); +} + +IconHelper *IconHelper::getIconHelper(int icon) +{ + initFont(); + + //指定了字体索引则取对应索引的字体类 + //没指定则自动根据不同的字体的值选择对应的类 + //由于部分值范围冲突所以可以指定索引来取 + //fontawesome 0xf000-0xf2e0 + //fontawesome6 0xe000-0xe33d 0xf000-0xf8ff + //iconfont 0xe501-0xe793 0xe8d5-0xea5d 0xeb00-0xec00 + //weather 0xe900-0xe9cf + + IconHelper *iconHelper = iconFontAwesome; + if (iconFontIndex < 0) { + if ((icon >= 0xe501 && icon <= 0xe793) || (icon >= 0xe8d5 && icon <= 0xea5d) || (icon >= 0xeb00 && icon <= 0xec00)) { + iconHelper = iconFontAliBaBa; + } + } else if (iconFontIndex == 0) { + iconHelper = iconFontAliBaBa; + } else if (iconFontIndex == 1) { + iconHelper = iconFontAwesome; + } else if (iconFontIndex == 2) { + iconHelper = iconFontAwesome6; + } else if (iconFontIndex == 3) { + iconHelper = iconFontWeather; + } + + return iconHelper; +} + +void IconHelper::setIcon(QLabel *lab, int icon, quint32 size) +{ + getIconHelper(icon)->setIcon1(lab, icon, size); +} + +void IconHelper::setIcon(QAbstractButton *btn, int icon, quint32 size) +{ + getIconHelper(icon)->setIcon1(btn, icon, size); +} + +void IconHelper::setPixmap(QAbstractButton *btn, const QColor &color, int icon, quint32 size, + quint32 width, quint32 height, int flags) +{ + getIconHelper(icon)->setPixmap1(btn, color, icon, size, width, height, flags); +} + +QPixmap IconHelper::getPixmap(const QColor &color, int icon, quint32 size, + quint32 width, quint32 height, int flags) +{ + return getIconHelper(icon)->getPixmap1(color, icon, size, width, height, flags); +} + +void IconHelper::setStyle(QWidget *widget, QList btns, + QList icons, const IconHelper::StyleColor &styleColor) +{ + int icon = icons.first(); + getIconHelper(icon)->setStyle1(widget, btns, icons, styleColor); +} + +void IconHelper::setStyle(QWidget *widget, QList btns, + QList icons, const IconHelper::StyleColor &styleColor) +{ + int icon = icons.first(); + getIconHelper(icon)->setStyle1(widget, btns, icons, styleColor); +} + +void IconHelper::setStyle(QWidget *widget, QList btns, + QList icons, const IconHelper::StyleColor &styleColor) +{ + int icon = icons.first(); + getIconHelper(icon)->setStyle1(widget, btns, icons, styleColor); +} + + +IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject *parent) : QObject(parent) +{ + //判断图形字体是否存在,不存在则加入 + QFontDatabase fontDb; + if (!fontDb.families().contains(fontName) && QFile(fontFile).exists()) { + int fontId = fontDb.addApplicationFont(fontFile); + QStringList listName = fontDb.applicationFontFamilies(fontId); + if (listName.count() == 0) { + qDebug() << QString("load %1 error").arg(fontName); + } + } + + //再次判断是否包含字体名称防止加载失败 + if (fontDb.families().contains(fontName)) { + iconFont = QFont(fontName); +#if (QT_VERSION >= QT_VERSION_CHECK(4,8,0)) + iconFont.setHintingPreference(QFont::PreferNoHinting); +#endif + } +} + +bool IconHelper::eventFilter(QObject *watched, QEvent *event) +{ + //根据不同的 + if (watched->inherits("QAbstractButton")) { + QAbstractButton *btn = (QAbstractButton *)watched; + int index = btns.indexOf(btn); + if (index >= 0) { + //不同的事件设置不同的图标,同时区分选中的和没有选中的 + if (btn->isChecked()) { + if (event->type() == QEvent::MouseButtonPress) { + QMouseEvent *mouseEvent = (QMouseEvent *)event; + if (mouseEvent->button() == Qt::LeftButton) { + btn->setIcon(QIcon(pixChecked.at(index))); + } + } else if (event->type() == QEvent::Enter) { + btn->setIcon(QIcon(pixChecked.at(index))); + } else if (event->type() == QEvent::Leave) { + btn->setIcon(QIcon(pixChecked.at(index))); + } + } else { + if (event->type() == QEvent::MouseButtonPress) { + QMouseEvent *mouseEvent = (QMouseEvent *)event; + if (mouseEvent->button() == Qt::LeftButton) { + btn->setIcon(QIcon(pixPressed.at(index))); + } + } else if (event->type() == QEvent::Enter) { + btn->setIcon(QIcon(pixHover.at(index))); + } else if (event->type() == QEvent::Leave) { + btn->setIcon(QIcon(pixNormal.at(index))); + } + } + } + } + + return QObject::eventFilter(watched, event); +} + +void IconHelper::toggled(bool checked) +{ + //选中和不选中设置不同的图标 + QAbstractButton *btn = (QAbstractButton *)sender(); + int index = btns.indexOf(btn); + if (checked) { + btn->setIcon(QIcon(pixChecked.at(index))); + } else { + btn->setIcon(QIcon(pixNormal.at(index))); + } +} + +QFont IconHelper::getIconFont() +{ + return this->iconFont; +} + +void IconHelper::setIcon1(QLabel *lab, int icon, quint32 size) +{ + iconFont.setPixelSize(size); + lab->setFont(iconFont); + lab->setText((QChar)icon); +} + +void IconHelper::setIcon1(QAbstractButton *btn, int icon, quint32 size) +{ + iconFont.setPixelSize(size); + btn->setFont(iconFont); + btn->setText((QChar)icon); +} + +void IconHelper::setPixmap1(QAbstractButton *btn, const QColor &color, int icon, quint32 size, + quint32 width, quint32 height, int flags) +{ + btn->setIcon(getPixmap1(color, icon, size, width, height, flags)); +} + +QPixmap IconHelper::getPixmap1(const QColor &color, int icon, quint32 size, + quint32 width, quint32 height, int flags) +{ + //主动绘制图形字体到图片 + QPixmap pix(width, height); + pix.fill(Qt::transparent); + + QPainter painter; + painter.begin(&pix); + painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); + painter.setPen(color); + + iconFont.setPixelSize(size); + painter.setFont(iconFont); + painter.drawText(pix.rect(), flags, (QChar)icon); + painter.end(); + return pix; +} + +void IconHelper::setStyle1(QWidget *widget, QList btns, QList icons, const IconHelper::StyleColor &styleColor) +{ + QList list; + foreach (QPushButton *btn, btns) { + list << btn; + } + + setStyle(widget, list, icons, styleColor); +} + +void IconHelper::setStyle1(QWidget *widget, QList btns, QList icons, const IconHelper::StyleColor &styleColor) +{ + QList list; + foreach (QToolButton *btn, btns) { + list << btn; + } + + setStyle(widget, list, icons, styleColor); +} + +void IconHelper::setStyle1(QWidget *widget, QList btns, QList icons, const IconHelper::StyleColor &styleColor) +{ + int btnCount = btns.count(); + int iconCount = icons.count(); + if (btnCount <= 0 || iconCount <= 0 || btnCount != iconCount) { + return; + } + + QString position = styleColor.position; + quint32 btnWidth = styleColor.btnWidth; + quint32 btnHeight = styleColor.btnHeight; + quint32 iconSize = styleColor.iconSize; + quint32 iconWidth = styleColor.iconWidth; + quint32 iconHeight = styleColor.iconHeight; + quint32 borderWidth = styleColor.borderWidth; + + //根据不同的位置计算边框 + QString strBorder; + if (position == "top") { + strBorder = QString("border-width:%1px 0px 0px 0px;padding-top:%1px;padding-bottom:%2px;") + .arg(borderWidth).arg(borderWidth * 2); + } else if (position == "right") { + strBorder = QString("border-width:0px %1px 0px 0px;padding-right:%1px;padding-left:%2px;") + .arg(borderWidth).arg(borderWidth * 2); + } else if (position == "bottom") { + strBorder = QString("border-width:0px 0px %1px 0px;padding-bottom:%1px;padding-top:%2px;") + .arg(borderWidth).arg(borderWidth * 2); + } else if (position == "left") { + strBorder = QString("border-width:0px 0px 0px %1px;padding-left:%1px;padding-right:%2px;") + .arg(borderWidth).arg(borderWidth * 2); + } + + //如果图标是左侧显示则需要让没有选中的按钮左侧也有加深的边框,颜色为背景颜色 + //如果图标在文字上面而设置的边框是 top bottom 也需要启用加深边框 + QStringList qss; + if (styleColor.defaultBorder) { + qss << QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:solid;border-radius:0px;%2border-color:%3;color:%4;background:%5;}") + .arg(position).arg(strBorder).arg(styleColor.normalBgColor).arg(styleColor.normalTextColor).arg(styleColor.normalBgColor); + } else { + qss << QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:none;border-radius:0px;padding:5px;color:%2;background:%3;}") + .arg(position).arg(styleColor.normalTextColor).arg(styleColor.normalBgColor); + } + + //悬停+按下+选中 + qss << QString("QWidget[flag=\"%1\"] QAbstractButton:hover{border-style:solid;%2border-color:%3;color:%4;background:%5;}") + .arg(position).arg(strBorder).arg(styleColor.borderColor).arg(styleColor.hoverTextColor).arg(styleColor.hoverBgColor); + qss << QString("QWidget[flag=\"%1\"] QAbstractButton:pressed{border-style:solid;%2border-color:%3;color:%4;background:%5;}") + .arg(position).arg(strBorder).arg(styleColor.borderColor).arg(styleColor.pressedTextColor).arg(styleColor.pressedBgColor); + qss << QString("QWidget[flag=\"%1\"] QAbstractButton:checked{border-style:solid;%2border-color:%3;color:%4;background:%5;}") + .arg(position).arg(strBorder).arg(styleColor.borderColor).arg(styleColor.checkedTextColor).arg(styleColor.checkedBgColor); + + //窗体背景颜色+按钮背景颜色 + qss << QString("QWidget#%1{background:%2;}") + .arg(widget->objectName()).arg(styleColor.normalBgColor); + qss << QString("QWidget>QAbstractButton{border-width:0px;background-color:%1;color:%2;}") + .arg(styleColor.normalBgColor).arg(styleColor.normalTextColor); + qss << QString("QWidget>QAbstractButton:hover{background-color:%1;color:%2;}") + .arg(styleColor.hoverBgColor).arg(styleColor.hoverTextColor); + qss << QString("QWidget>QAbstractButton:pressed{background-color:%1;color:%2;}") + .arg(styleColor.pressedBgColor).arg(styleColor.pressedTextColor); + qss << QString("QWidget>QAbstractButton:checked{background-color:%1;color:%2;}") + .arg(styleColor.checkedBgColor).arg(styleColor.checkedTextColor); + + //按钮宽度高度 + if (btnWidth > 0) { + qss << QString("QWidget>QAbstractButton{min-width:%1px;}").arg(btnWidth); + } + if (btnHeight > 0) { + qss << QString("QWidget>QAbstractButton{min-height:%1px;}").arg(btnHeight); + } + + //设置样式表 + widget->setStyleSheet(qss.join("")); + + //可能会重复调用设置所以先要移除上一次的 + for (int i = 0; i < btnCount; ++i) { + for (int j = 0; j < this->btns.count(); j++) { + if (this->btns.at(j) == btns.at(i)) { + disconnect(btns.at(i), SIGNAL(toggled(bool)), this, SLOT(toggled(bool))); + this->btns.at(j)->removeEventFilter(this); + this->btns.removeAt(j); + this->pixNormal.removeAt(j); + this->pixHover.removeAt(j); + this->pixPressed.removeAt(j); + this->pixChecked.removeAt(j); + break; + } + } + } + + //存储对应按钮对象,方便鼠标移上去的时候切换图片 + int checkedIndex = -1; + for (int i = 0; i < btnCount; ++i) { + int icon = icons.at(i); + QPixmap pixNormal = getPixmap1(styleColor.normalTextColor, icon, iconSize, iconWidth, iconHeight); + QPixmap pixHover = getPixmap1(styleColor.hoverTextColor, icon, iconSize, iconWidth, iconHeight); + QPixmap pixPressed = getPixmap1(styleColor.pressedTextColor, icon, iconSize, iconWidth, iconHeight); + QPixmap pixChecked = getPixmap1(styleColor.checkedTextColor, icon, iconSize, iconWidth, iconHeight); + + //记住最后选中的按钮 + QAbstractButton *btn = btns.at(i); + if (btn->isChecked()) { + checkedIndex = i; + } + + btn->setIcon(QIcon(pixNormal)); + btn->setIconSize(QSize(iconWidth, iconHeight)); + btn->installEventFilter(this); + connect(btn, SIGNAL(toggled(bool)), this, SLOT(toggled(bool))); + + this->btns << btn; + this->pixNormal << pixNormal; + this->pixHover << pixHover; + this->pixPressed << pixPressed; + this->pixChecked << pixChecked; + } + + //主动触发一下选中的按钮 + if (checkedIndex >= 0) { + QMetaObject::invokeMethod(btns.at(checkedIndex), "toggled", Q_ARG(bool, true)); + } +} diff --git a/core_base/iconhelper.h b/core_base/iconhelper.h new file mode 100644 index 0000000..adcf69e --- /dev/null +++ b/core_base/iconhelper.h @@ -0,0 +1,189 @@ +#ifndef ICONHELPER_H +#define ICONHELPER_H + +/** + * 超级图形字体类 作者:feiyangqingyun(QQ:517216493) 2016-11-23 + * 1. 可传入多种图形字体文件,一个类通用所有图形字体。 + * 2. 默认已经内置了阿里巴巴图形字体FontAliBaBa、国际知名图形字体FontAwesome、天气图形字体FontWeather。 + * 3. 可设置 QLabel、QAbstractButton 文本为图形字体。 + * 4. 可设置图形字体作为 QAbstractButton 按钮图标。 + * 5. 内置万能的方法 getPixmap 将图形字体值转换为图片。 + * 6. 无论是设置文本、图标、图片等都可以设置图标的大小、尺寸、颜色等参数。 + * 7. 内置超级导航栏样式设置,将图形字体作为图标设置到按钮。 + * 8. 支持各种颜色设置比如正常颜色、悬停颜色、按下颜色、选中颜色。 + * 9. 可设置导航的位置为 left、right、top、bottom 四种。 + * 10. 可设置导航加深边框颜色和粗细大小。 + * 11. 导航面板的各种切换效果比如鼠标悬停、按下、选中等都自动处理掉样式设置。 + * 12. 全局静态方法,接口丰富,使用极其简单方便。 + */ + +#include +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) +#include +#endif + +#ifdef quc +class Q_DECL_EXPORT IconHelper : public QObject +#else +class IconHelper : public QObject +#endif + +{ + Q_OBJECT + +private: + //阿里巴巴图形字体类 + static IconHelper *iconFontAliBaBa; + //FontAwesome图形字体类 + static IconHelper *iconFontAwesome; + //FontAwesome6图形字体类 + static IconHelper *iconFontAwesome6; + //天气图形字体类 + static IconHelper *iconFontWeather; + //图形字体索引 + static int iconFontIndex; + +public: + //样式颜色结构体 + struct StyleColor { + QString position; //位置 left right top bottom + bool defaultBorder; //默认有边框 + + quint32 btnWidth; //按钮宽度 + quint32 btnHeight; //按钮高度 + + quint32 iconSize; //图标字体尺寸 + quint32 iconWidth; //图标图片宽度 + quint32 iconHeight; //图标图片高度 + + quint32 borderWidth; //边框宽度 + QString borderColor; //边框颜色 + + QString normalBgColor; //正常背景颜色 + QString normalTextColor; //正常文字颜色 + QString hoverBgColor; //悬停背景颜色 + QString hoverTextColor; //悬停文字颜色 + QString pressedBgColor; //按下背景颜色 + QString pressedTextColor; //按下文字颜色 + QString checkedBgColor; //选中背景颜色 + QString checkedTextColor; //选中文字颜色 + + StyleColor() { + position = "left"; + defaultBorder = false; + + btnWidth = 0; + btnHeight = 0; + + iconSize = 12; + iconWidth = 15; + iconHeight = 15; + + borderWidth = 3; + borderColor = "#029FEA"; + + normalBgColor = "#292F38"; + normalTextColor = "#54626F"; + hoverBgColor = "#40444D"; + hoverTextColor = "#FDFDFD"; + pressedBgColor = "#404244"; + pressedTextColor = "#FDFDFD"; + checkedBgColor = "#44494F"; + checkedTextColor = "#FDFDFD"; + } + + //设置常规颜色 普通状态+加深状态 + void setColor(const QString &normalBgColor, + const QString &normalTextColor, + const QString &darkBgColor, + const QString &darkTextColor) { + this->normalBgColor = normalBgColor; + this->normalTextColor = normalTextColor; + this->hoverBgColor = darkBgColor; + this->hoverTextColor = darkTextColor; + this->pressedBgColor = darkBgColor; + this->pressedTextColor = darkTextColor; + this->checkedBgColor = darkBgColor; + this->checkedTextColor = darkTextColor; + } + }; + + + //初始化图形字体 + static void initFont(); + //设置引用图形字体文件索引 + static void setIconFontIndex(int index); + + //获取图形字体 + static QFont getIconFontAliBaBa(); + static QFont getIconFontAwesome(); + static QFont getIconFontAwesome6(); + static QFont getIconFontWeather(); + + //根据值获取图形字体类 + static IconHelper *getIconHelper(int icon); + + //设置图形字体到标签 + static void setIcon(QLabel *lab, int icon, quint32 size = 12); + //设置图形字体到按钮 + static void setIcon(QAbstractButton *btn, int icon, quint32 size = 12); + + //设置图形字体到图标 + static void setPixmap(QAbstractButton *btn, const QColor &color, + int icon, quint32 size = 12, + quint32 width = 15, quint32 height = 15, + int flags = Qt::AlignCenter); + //获取指定图形字体,可以指定文字大小,图片宽高,文字对齐 + static QPixmap getPixmap(const QColor &color, int icon, quint32 size = 12, + quint32 width = 15, quint32 height = 15, + int flags = Qt::AlignCenter); + + //指定导航面板样式,带图标和效果切换+悬停颜色+按下颜色+选中颜色 + static void setStyle(QWidget *widget, QList btns, QList icons, const StyleColor &styleColor); + static void setStyle(QWidget *widget, QList btns, QList icons, const StyleColor &styleColor); + static void setStyle(QWidget *widget, QList btns, QList icons, const StyleColor &styleColor); + + //默认构造函数,传入字体文件+字体名称 + explicit IconHelper(const QString &fontFile, const QString &fontName, QObject *parent = 0); + +protected: + bool eventFilter(QObject *watched, QEvent *event); + +private: + QFont iconFont; //图形字体 + QList btns; //按钮队列 + QList pixNormal; //正常图片队列 + QList pixHover; //悬停图片队列 + QList pixPressed; //按下图片队列 + QList pixChecked; //选中图片队列 + +private slots: + //按钮选中状态切换处理 + void toggled(bool checked); + +public: + //获取图形字体 + QFont getIconFont(); + + //设置图形字体到标签 + void setIcon1(QLabel *lab, int icon, quint32 size = 12); + //设置图形字体到按钮 + void setIcon1(QAbstractButton *btn, int icon, quint32 size = 12); + + //设置图形字体到图标 + void setPixmap1(QAbstractButton *btn, const QColor &color, + int icon, quint32 size = 12, + quint32 width = 15, quint32 height = 15, + int flags = Qt::AlignCenter); + //获取指定图形字体,可以指定文字大小,图片宽高,文字对齐 + QPixmap getPixmap1(const QColor &color, int icon, quint32 size = 12, + quint32 width = 15, quint32 height = 15, + int flags = Qt::AlignCenter); + + //指定导航面板样式,带图标和效果切换+悬停颜色+按下颜色+选中颜色 + void setStyle1(QWidget *widget, QList btns, QList icons, const StyleColor &styleColor); + void setStyle1(QWidget *widget, QList btns, QList icons, const StyleColor &styleColor); + void setStyle1(QWidget *widget, QList btns, QList icons, const StyleColor &styleColor); +}; + +#endif // ICONHELPER_H diff --git a/core_base/qrc/font.qrc b/core_base/qrc/font.qrc new file mode 100644 index 0000000..9f303b2 --- /dev/null +++ b/core_base/qrc/font.qrc @@ -0,0 +1,7 @@ + + + font/fontawesome-webfont.ttf + font/iconfont.ttf + font/pe-icon-set-weather.ttf + + diff --git a/core_base/qrc/font/fontawesome-webfont.ttf b/core_base/qrc/font/fontawesome-webfont.ttf new file mode 100644 index 0000000..35acda2 Binary files /dev/null and b/core_base/qrc/font/fontawesome-webfont.ttf differ diff --git a/core_base/qrc/font/iconfont.ttf b/core_base/qrc/font/iconfont.ttf new file mode 100644 index 0000000..4757471 Binary files /dev/null and b/core_base/qrc/font/iconfont.ttf differ diff --git a/core_base/qrc/font/pe-icon-set-weather.ttf b/core_base/qrc/font/pe-icon-set-weather.ttf new file mode 100644 index 0000000..eb6f8e5 Binary files /dev/null and b/core_base/qrc/font/pe-icon-set-weather.ttf differ diff --git a/core_base/qrc/image.qrc b/core_base/qrc/image.qrc new file mode 100644 index 0000000..458c609 --- /dev/null +++ b/core_base/qrc/image.qrc @@ -0,0 +1,5 @@ + + + image/bg_novideo.png + + diff --git a/core_base/qrc/image/bg_novideo.png b/core_base/qrc/image/bg_novideo.png new file mode 100644 index 0000000..510dfb8 Binary files /dev/null and b/core_base/qrc/image/bg_novideo.png differ diff --git a/core_base/qrc/qm.qrc b/core_base/qrc/qm.qrc new file mode 100644 index 0000000..d14db1a --- /dev/null +++ b/core_base/qrc/qm.qrc @@ -0,0 +1,6 @@ + + + qm/qt_zh_CN.qm + qm/widgets.qm + + diff --git a/core_base/quihelper.cpp b/core_base/quihelper.cpp new file mode 100644 index 0000000..e3090aa --- /dev/null +++ b/core_base/quihelper.cpp @@ -0,0 +1,1006 @@ +#include "quihelper.h" +#include "qnetworkinterface.h" +#include "qnetworkproxy.h" + +#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz")) + +int QUIHelper::getScreenIndex() +{ + //需要对多个屏幕进行处理 + int screenIndex = 0; +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) + int screenCount = qApp->screens().size(); +#else + int screenCount = qApp->desktop()->screenCount(); +#endif + + if (screenCount > 1) { + //找到当前鼠标所在屏幕 + QPoint pos = QCursor::pos(); + for (int i = 0; i < screenCount; ++i) { +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) + if (qApp->screens().at(i)->geometry().contains(pos)) { +#else + if (qApp->desktop()->screenGeometry(i).contains(pos)) { +#endif + screenIndex = i; + break; + } + } + } + return screenIndex; +} + +QRect QUIHelper::getScreenRect(bool available) +{ + QRect rect; + int screenIndex = QUIHelper::getScreenIndex(); + if (available) { +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) + rect = qApp->screens().at(screenIndex)->availableGeometry(); +#else + rect = qApp->desktop()->availableGeometry(screenIndex); +#endif + } else { +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) + rect = qApp->screens().at(screenIndex)->geometry(); +#else + rect = qApp->desktop()->screenGeometry(screenIndex); +#endif + } + return rect; +} + +qreal QUIHelper::getScreenRatio(bool devicePixel) +{ + qreal ratio = 1.0; + int screenIndex = getScreenIndex(); +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) + QScreen *screen = qApp->screens().at(screenIndex); + if (devicePixel) { + //需要开启 AA_EnableHighDpiScaling 属性才能正常获取 + ratio = screen->devicePixelRatio() * 100; + } else { + ratio = screen->logicalDotsPerInch(); + } +#else + //Qt4不能动态识别缩放更改后的值 + ratio = qApp->desktop()->screen(screenIndex)->logicalDpiX(); +#endif + return ratio / 96; +} + +QRect QUIHelper::checkCenterRect(QRect &rect, bool available) +{ + QRect deskRect = QUIHelper::getScreenRect(available); + int formWidth = rect.width(); + int formHeight = rect.height(); + int deskWidth = deskRect.width(); + int deskHeight = deskRect.height(); + int formX = deskWidth / 2 - formWidth / 2 + deskRect.x(); + int formY = deskHeight / 2 - formHeight / 2; + rect = QRect(formX, formY, formWidth, formHeight); + return deskRect; +} + +int QUIHelper::deskWidth() +{ + return getScreenRect().width(); +} + +int QUIHelper::deskHeight() +{ + return getScreenRect().height(); +} + +QSize QUIHelper::deskSize() +{ + return getScreenRect().size(); +} + +QWidget *QUIHelper::centerBaseForm = 0; +void QUIHelper::setFormInCenter(QWidget *form) +{ + int formWidth = form->width(); + int formHeight = form->height(); + + //如果=0表示采用系统桌面屏幕为参照 + QRect rect; + if (centerBaseForm == 0) { + rect = getScreenRect(); + } else { + rect = centerBaseForm->geometry(); + } + + int deskWidth = rect.width(); + int deskHeight = rect.height(); + QPoint movePoint(deskWidth / 2 - formWidth / 2 + rect.x(), deskHeight / 2 - formHeight / 2 + rect.y()); + form->move(movePoint); +} + +void QUIHelper::showForm(QWidget *form) +{ + setFormInCenter(form); + form->show(); + + //判断宽高是否超过了屏幕分辨率,超过了则最大化显示 + //qDebug() << TIMEMS << form->size() << deskSize(); + if (form->width() + 20 > deskWidth() || form->height() + 50 > deskHeight()) { + QMetaObject::invokeMethod(form, "showMaximized", Qt::QueuedConnection); + } +} + +QString QUIHelper::appName() +{ + //没有必要每次都获取,只有当变量为空时才去获取一次 + static QString name; + if (name.isEmpty()) { + name = qApp->applicationFilePath(); + //下面的方法主要为了过滤安卓的路径 lib程序名_armeabi-v7a/lib程序名_arm64-v8a + QStringList list = name.split("/"); + name = list.at(list.size() - 1).split(".").at(0); + name.replace("_armeabi-v7a", ""); + name.replace("_arm64-v8a", ""); + } + + return name; +} + +QString QUIHelper::appPath() +{ + static QString path; + if (path.isEmpty()) { +#ifdef Q_OS_ANDROID + //默认安卓根目录 + path = "/storage/emulated/0"; + //带上程序名称作为目录 前面加个0方便排序 + path = path + "/0" + appName(); +#else + path = qApp->applicationDirPath(); +#endif + } + + return path; +} + +QStringList QUIHelper::getLocalIPs() +{ + static QStringList ips; + if (ips.size() == 0) { +#ifdef Q_OS_WASM + ips << "127.0.0.1"; +#else + QList netInterfaces = QNetworkInterface::allInterfaces(); + foreach (QNetworkInterface netInterface, netInterfaces) { + //移除虚拟机和抓包工具的虚拟网卡 + QString humanReadableName = netInterface.humanReadableName().toLower(); + if (humanReadableName.startsWith("vmware network adapter") || humanReadableName.startsWith("npcap loopback adapter")) { + continue; + } + + //过滤当前网络接口 + bool flag = (netInterface.flags() == (QNetworkInterface::IsUp | QNetworkInterface::IsRunning | QNetworkInterface::CanBroadcast | QNetworkInterface::CanMulticast)); + if (!flag) { + continue; + } + + QList addrs = netInterface.addressEntries(); + foreach (QNetworkAddressEntry addr, addrs) { + //只取出IPV4的地址 + if (addr.ip().protocol() != QAbstractSocket::IPv4Protocol) { + continue; + } + + QString ip4 = addr.ip().toString(); + if (ip4 != "127.0.0.1") { + ips << ip4; + } + } + } +#endif + } + + return ips; +} + +QList QUIHelper::colors = QList(); +QList QUIHelper::getColorList() +{ + //备用颜色集合 可以自行添加 + if (colors.size() == 0) { + colors << QColor(0, 176, 180) << QColor(0, 113, 193) << QColor(255, 192, 0); + colors << QColor(72, 103, 149) << QColor(185, 87, 86) << QColor(0, 177, 125); + colors << QColor(214, 77, 84) << QColor(71, 164, 233) << QColor(34, 163, 169); + colors << QColor(59, 123, 156) << QColor(162, 121, 197) << QColor(72, 202, 245); + colors << QColor(0, 150, 121) << QColor(111, 9, 176) << QColor(250, 170, 20); + } + + return colors; +} + +QStringList QUIHelper::getColorNames() +{ + QList colors = getColorList(); + QStringList colorNames; + foreach (QColor color, colors) { + colorNames << color.name(); + } + return colorNames; +} + +QColor QUIHelper::getRandColor() +{ + QList colors = getColorList(); + int index = getRandValue(0, colors.size(), true); + return colors.at(index); +} + +void QUIHelper::initRand() +{ + //初始化随机数种子 + QTime t = QTime::currentTime(); + srand(t.msec() + t.second() * 1000); +} + +float QUIHelper::getRandFloat(float min, float max) +{ + double diff = fabs(max - min); + double value = (double)(rand() % 100) / 100; + value = min + value * diff; + return value; +} + +double QUIHelper::getRandValue(int min, int max, bool contansMin, bool contansMax) +{ + int value; +#if (QT_VERSION <= QT_VERSION_CHECK(5,10,0)) + //通用公式 a是起始值,n是整数的范围 + //int value = a + rand() % n; + if (contansMin) { + if (contansMax) { + value = min + 0 + (rand() % (max - min + 1)); + } else { + value = min + 0 + (rand() % (max - min + 0)); + } + } else { + if (contansMax) { + value = min + 1 + (rand() % (max - min + 0)); + } else { + value = min + 1 + (rand() % (max - min - 1)); + } + } +#else + if (contansMin) { + if (contansMax) { + value = QRandomGenerator::global()->bounded(min + 0, max + 1); + } else { + value = QRandomGenerator::global()->bounded(min + 0, max + 0); + } + } else { + if (contansMax) { + value = QRandomGenerator::global()->bounded(min + 1, max + 1); + } else { + value = QRandomGenerator::global()->bounded(min + 1, max + 0); + } + } +#endif + return value; +} + +QStringList QUIHelper::getRandPoint(int count, float mainLng, float mainLat, float dotLng, float dotLat) +{ + //随机生成点坐标 + QStringList points; + for (int i = 0; i < count; ++i) { + //0.00881415 0.000442928 +#if (QT_VERSION >= QT_VERSION_CHECK(5,10,0)) + float lngx = QRandomGenerator::global()->bounded(dotLng); + float latx = QRandomGenerator::global()->bounded(dotLat); +#else + float lngx = getRandFloat(dotLng / 10, dotLng); + float latx = getRandFloat(dotLat / 10, dotLat); +#endif + //需要先用精度转换成字符串 + QString lng2 = QString::number(mainLng + lngx, 'f', 8); + QString lat2 = QString::number(mainLat + latx, 'f', 8); + QString point = QString("%1,%2").arg(lng2).arg(lat2); + points << point; + } + + return points; +} + +int QUIHelper::getRangeValue(int oldMin, int oldMax, int oldValue, int newMin, int newMax) +{ + return (((oldValue - oldMin) * (newMax - newMin)) / (oldMax - oldMin)) + newMin; +} + +QString QUIHelper::getUuid() +{ + QString uuid = QUuid::createUuid().toString(); + uuid.replace("{", ""); + uuid.replace("}", ""); + return uuid; +} + +void QUIHelper::checkPath(const QString &dirName) +{ + //相对路径需要补全完整路径 + QString path = dirName; + if (path.startsWith("./")) { + path.replace(".", ""); + path = QUIHelper::appPath() + path; + } else if (!path.startsWith("/") && !path.contains(":/")) { + path = QUIHelper::appPath() + "/" + path; + } + + //目录不存在则新建 + QDir dir(path); + if (!dir.exists()) { + dir.mkpath(path); + } +} + +void QUIHelper::sleep(int msec) +{ + if (msec <= 0) { + return; + } + +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) + QThread::msleep(msec); +#else + QTime endTime = QTime::currentTime().addMSecs(msec); + while (QTime::currentTime() < endTime) { + QCoreApplication::processEvents(QEventLoop::AllEvents, 100); + } +#endif +} + +void QUIHelper::setStyle() +{ + //打印下所有内置风格的名字 + qDebug() << TIMEMS << "QStyleFactory::keys" << QStyleFactory::keys(); + //设置内置风格 +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) + qApp->setStyle(QStyleFactory::create("Fusion")); +#else + qApp->setStyle(QStyleFactory::create("Cleanlooks")); +#endif + + //设置指定颜色 + QPalette palette; + palette.setBrush(QPalette::Window, QColor("#F0F0F0")); + qApp->setPalette(palette); +} + +QFont QUIHelper::addFont(const QString &fontFile, const QString &fontName) +{ + //判断图形字体是否存在,不存在则加入 + QFontDatabase fontDb; + if (!fontDb.families().contains(fontName)) { + int fontId = fontDb.addApplicationFont(fontFile); + QStringList listName = fontDb.applicationFontFamilies(fontId); + if (listName.size() == 0) { + qDebug() << QString("load %1 error").arg(fontName); + } + } + + //再次判断是否包含字体名称防止加载失败 + QFont font; + if (fontDb.families().contains(fontName)) { + font = QFont(fontName); +#if (QT_VERSION >= QT_VERSION_CHECK(4,8,0)) + font.setHintingPreference(QFont::PreferNoHinting); +#endif + } + + return font; +} + +void QUIHelper::setFont(int fontSize) +{ +#ifdef rk3399 + return; +#endif + //安卓套件在有些手机上默认字体不好看需要主动设置字体 + //网页套件需要主动加载中文字体才能正常显示中文 +#if (defined Q_OS_ANDROID) || (defined Q_OS_WASM) + QString fontFile = ":/font/DroidSansFallback.ttf"; + QString fontName = "Droid Sans Fallback"; + qApp->setFont(addFont(fontFile, fontName)); + return; +#endif + +#ifdef __arm__ + fontSize = 25; +#endif +#ifdef Q_OS_ANDROID + fontSize = 15; +#endif + + QFont font; + font.setFamily("MicroSoft Yahei"); + font.setPixelSize(fontSize); + qApp->setFont(font); +} + +void QUIHelper::setCode(bool utf8) +{ +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) + //如果想要控制台打印信息中文正常就注释掉这个设置 + if (utf8) { + QTextCodec *codec = QTextCodec::codecForName("utf-8"); + QTextCodec::setCodecForLocale(codec); + } +#else +#if _MSC_VER + QTextCodec *codec = QTextCodec::codecForName("gbk"); +#else + QTextCodec *codec = QTextCodec::codecForName("utf-8"); +#endif + QTextCodec::setCodecForLocale(codec); + QTextCodec::setCodecForCStrings(codec); + QTextCodec::setCodecForTr(codec); +#endif +} + +void QUIHelper::setTranslator(const QString &qmFile) +{ + //过滤下不存在的就不用设置了 + if (!QFile(qmFile).exists()) { + return; + } + + QTranslator *translator = new QTranslator(qApp); + if (translator->load(qmFile)) { + qApp->installTranslator(translator); + } +} + +#ifdef Q_OS_ANDROID +#if (QT_VERSION < QT_VERSION_CHECK(6,0,0)) +#include +#else +//Qt6中将相关类移到了core模块而且名字变了 +#include +#endif +#endif + +bool QUIHelper::checkPermission(const QString &permission) +{ +#ifdef Q_OS_ANDROID +#if (QT_VERSION >= QT_VERSION_CHECK(5,10,0) && QT_VERSION < QT_VERSION_CHECK(6,0,0)) + QtAndroid::PermissionResult result = QtAndroid::checkPermission(permission); + if (result == QtAndroid::PermissionResult::Denied) { + QtAndroid::requestPermissionsSync(QStringList() << permission); + result = QtAndroid::checkPermission(permission); + if (result == QtAndroid::PermissionResult::Denied) { + return false; + } + } +#else + QFuture result = QtAndroidPrivate::requestPermission(permission); + if (result.resultAt(0) == QtAndroidPrivate::PermissionResult::Denied) { + return false; + } +#endif +#endif + return true; +} + +void QUIHelper::initAndroidPermission() +{ + //可以把所有要动态申请的权限都写在这里 + checkPermission("android.permission.CALL_PHONE"); + checkPermission("android.permission.SEND_SMS"); + checkPermission("android.permission.CAMERA"); + checkPermission("android.permission.READ_EXTERNAL_STORAGE"); + checkPermission("android.permission.WRITE_EXTERNAL_STORAGE"); + + checkPermission("android.permission.ACCESS_COARSE_LOCATION"); + checkPermission("android.permission.BLUETOOTH"); + checkPermission("android.permission.BLUETOOTH_SCAN"); + checkPermission("android.permission.BLUETOOTH_CONNECT"); + checkPermission("android.permission.BLUETOOTH_ADVERTISE"); +} + +void QUIHelper::initAll(bool utf8, bool style, int fontSize) +{ + //初始化安卓权限 + QUIHelper::initAndroidPermission(); + //初始化随机数种子 + QUIHelper::initRand(); + //设置编码 + QUIHelper::setCode(utf8); + //设置字体 + QUIHelper::setFont(fontSize); + //设置样式风格 + if (style) { + QUIHelper::setStyle(); + } + + //设置翻译文件支持多个 + QUIHelper::setTranslator(":/qm/widgets.qm"); + QUIHelper::setTranslator(":/qm/qt_zh_CN.qm"); + QUIHelper::setTranslator(":/qm/designer_zh_CN.qm"); + + //设置不使用本地系统环境代理配置 + QNetworkProxyFactory::setUseSystemConfiguration(false); +} + +void QUIHelper::initMain(bool desktopSettingsAware, bool useOpenGLES) +{ + //设置是否应用操作系统设置比如字体 + QApplication::setDesktopSettingsAware(desktopSettingsAware); + +#ifdef Q_OS_ANDROID +#if (QT_VERSION >= QT_VERSION_CHECK(5,6,0)) + //开启高分屏缩放支持 + QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); +#endif +#else +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) + //不应用任何缩放 + QApplication::setAttribute(Qt::AA_Use96Dpi); +#endif +#endif + +#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0)) + //高分屏缩放策略 + QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); +#endif + +#if (QT_VERSION >= QT_VERSION_CHECK(5,4,0)) + //win上获取显卡是否被禁用(禁用则必须启用OpenGLES) +#ifdef Q_OS_WIN + QProcess p; + QStringList args; + args << "path" << "win32_VideoController" << "get" << "name,Status"; + p.start("wmic", args); + p.waitForFinished(1000); + QString result = QString::fromLocal8Bit(p.readAllStandardOutput()); + result.replace("\r", ""); + result.replace("\n", ""); + result = result.simplified(); + result = result.trimmed(); + //Name Status Intel(R) UHD Graphics 630 OK + //Name Status Intel(R) UHD Graphics 630 Error + //QStringList list = result.split(" "); + if (result.contains("Error")) { + useOpenGLES = true; + } +#endif + + //设置opengl模式 AA_UseDesktopOpenGL(默认) AA_UseOpenGLES AA_UseSoftwareOpenGL + //在一些很旧的设备上或者对opengl支持很低的设备上需要使用AA_UseOpenGLES表示禁用硬件加速 + //如果开启的是AA_UseOpenGLES则无法使用硬件加速比如ffmpeg的dxva2 + if (useOpenGLES) { + QApplication::setAttribute(Qt::AA_UseOpenGLES); + } + + //设置opengl共享上下文 + QApplication::setAttribute(Qt::AA_ShareOpenGLContexts); +#endif +} + +QVector QUIHelper::msgTypes = QVector() << 0 << 1 << 2 << 3 << 4; +QVector QUIHelper::msgKeys = QVector() << QString::fromUtf8("发送") << QString::fromUtf8("接收") << QString::fromUtf8("解析") << QString::fromUtf8("错误") << QString::fromUtf8("提示"); +QVector QUIHelper::msgColors = QVector() << QColor("#3BA372") << QColor("#EE6668") << QColor("#9861B4") << QColor("#FA8359") << QColor("#22A3A9"); +QString QUIHelper::appendMsg(QTextEdit *textEdit, int type, const QString &data, int maxCount, int ¤tCount, bool clear, bool pause) +{ + if (clear) { + textEdit->clear(); + currentCount = 0; + return QString(); + } + + if (pause) { + return QString(); + } + + if (currentCount >= maxCount) { + textEdit->clear(); + currentCount = 0; + } + + //不同类型不同颜色显示 + QString strType; + int index = msgTypes.indexOf(type); + if (index >= 0) { + strType = msgKeys.at(index); + textEdit->setTextColor(msgColors.at(index)); + } + + //过滤回车换行符 + QString strData = data; + strData.replace("\r", ""); + strData.replace("\n", ""); + strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData); + textEdit->append(strData); + currentCount++; + return strData; +} + +void QUIHelper::setFramelessForm(QWidget *widgetMain, bool tool, bool top, bool menu) +{ +// widgetMain->setProperty("form", true); + widgetMain->setProperty("canMove", true); + + //根据设定逐个追加属性 +#ifdef __arm__ + widgetMain->setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); +#else + widgetMain->setWindowFlags(Qt::FramelessWindowHint); +#endif + if (tool) { + widgetMain->setWindowFlags(widgetMain->windowFlags() | Qt::Tool); + } + if (top) { + widgetMain->setWindowFlags(widgetMain->windowFlags() | Qt::WindowStaysOnTopHint); + } + if (menu) { + //如果是其他系统比如neokylin会产生系统边框 +#ifdef Q_OS_WIN + widgetMain->setWindowFlags(widgetMain->windowFlags() | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); +#endif + } +} + +int QUIHelper::showMessageBox(const QString &text, int type, int closeSec, bool exec) +{ + int result = 0; + if (type == 0) { + showMessageBoxInfo(text, closeSec, exec); + } else if (type == 1) { + showMessageBoxError(text, closeSec, exec); + } else if (type == 2) { + result = showMessageBoxQuestion(text); + } + + return result; +} + +void QUIHelper::showMessageBoxInfo(const QString &text, int closeSec, bool exec) +{ + QMessageBox box(QMessageBox::Information, "提示", text); + box.setStandardButtons(QMessageBox::Yes); + box.setButtonText(QMessageBox::Yes, QString("确 定")); + box.exec(); + //QMessageBox::information(0, "提示", info, QMessageBox::Yes); +} + +void QUIHelper::showMessageBoxError(const QString &text, int closeSec, bool exec) +{ + QMessageBox box(QMessageBox::Critical, "错误", text); + box.setStandardButtons(QMessageBox::Yes); + box.setButtonText(QMessageBox::Yes, QString("确 定")); + box.exec(); + //QMessageBox::critical(0, "错误", info, QMessageBox::Yes); +} + +int QUIHelper::showMessageBoxQuestion(const QString &text) +{ + QMessageBox box(QMessageBox::Question, "询问", text); + box.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + box.setButtonText(QMessageBox::Yes, QString("确 定")); + box.setButtonText(QMessageBox::No, QString("取 消")); + return box.exec(); + //return QMessageBox::question(0, "询问", info, QMessageBox::Yes | QMessageBox::No); +} + +void QUIHelper::initDialog(QFileDialog *dialog, const QString &title, const QString &acceptName, + const QString &dirName, bool native, int width, int height) +{ + //设置标题 + dialog->setWindowTitle(title); + //设置标签文本 + dialog->setLabelText(QFileDialog::Accept, acceptName); + dialog->setLabelText(QFileDialog::Reject, "取消(&C)"); + dialog->setLabelText(QFileDialog::LookIn, "查看"); + dialog->setLabelText(QFileDialog::FileName, "名称"); + dialog->setLabelText(QFileDialog::FileType, "类型"); + + //设置默认显示目录 + if (!dirName.isEmpty()) { + dialog->setDirectory(dirName); + } + + //设置对话框宽高 + if (width > 0 && height > 0) { +#ifdef Q_OS_ANDROID + bool horizontal = (QUIHelper::deskWidth() > QUIHelper::deskHeight()); + if (horizontal) { + width = QUIHelper::deskWidth() / 2; + height = QUIHelper::deskHeight() - 50; + } else { + width = QUIHelper::deskWidth() - 10; + height = QUIHelper::deskHeight() / 2; + } +#endif + dialog->setFixedSize(width, height); + } + + //设置是否采用本地对话框 + dialog->setOption(QFileDialog::DontUseNativeDialog, !native); + //设置只读可以取消右上角的新建按钮 + //dialog->setReadOnly(true); +} + +QString QUIHelper::getDialogResult(QFileDialog *dialog) +{ + QString result; + if (dialog->exec() == QFileDialog::Accepted) { + result = dialog->selectedFiles().first(); + } + return result; +} + +QString QUIHelper::getOpenFileName(const QString &filter, const QString &dirName, const QString &fileName, + bool native, int width, int height) +{ + QFileDialog dialog; + initDialog(&dialog, "打开文件", "选择(&S)", dirName, native, width, height); + + //设置文件类型 + if (!filter.isEmpty()) { + dialog.setNameFilter(filter); + } + + //设置默认文件名称 + dialog.selectFile(fileName); + return getDialogResult(&dialog); +} + +QString QUIHelper::getSaveFileName(const QString &filter, const QString &dirName, const QString &fileName, + bool native, int width, int height) +{ + QFileDialog dialog; + initDialog(&dialog, "保存文件", "保存(&S)", dirName, native, width, height); + + //设置文件类型 + if (!filter.isEmpty()) { + dialog.setNameFilter(filter); + } + + //设置默认文件名称 + dialog.selectFile(fileName); + //设置模态类型允许输入 + dialog.setWindowModality(Qt::WindowModal); + //设置置顶显示 + dialog.setWindowFlags(dialog.windowFlags() | Qt::WindowStaysOnTopHint); + return getDialogResult(&dialog); +} + +QString QUIHelper::getExistingDirectory(const QString &dirName, bool native, int width, int height) +{ + QFileDialog dialog; + initDialog(&dialog, "选择目录", "选择(&S)", dirName, native, width, height); + dialog.setOption(QFileDialog::ReadOnly); + //设置只显示目录 +#if (QT_VERSION < QT_VERSION_CHECK(6,0,0)) + dialog.setFileMode(QFileDialog::DirectoryOnly); +#endif + dialog.setOption(QFileDialog::ShowDirsOnly); + return getDialogResult(&dialog); +} + +QString QUIHelper::getXorEncryptDecrypt(const QString &value, char key) +{ + //矫正范围外的数据 + if (key < 0 || key >= 127) { + key = 127; + } + + //大概从5.9版本输出的加密密码字符串前面会加上 @String 字符 + QString result = value; + if (result.startsWith("@String")) { + result = result.mid(8, result.length() - 9); + } + + int size = result.size(); + for (int i = 0; i < size; ++i) { + result[i] = QChar(result.at(i).toLatin1() ^ key); + } + return result; +} + +quint8 QUIHelper::getOrCode(const QByteArray &data) +{ + int len = data.length(); + quint8 result = 0; + for (int i = 0; i < len; ++i) { + result ^= data.at(i); + } + + return result; +} + +quint8 QUIHelper::getCheckCode(const QByteArray &data) +{ + int len = data.length(); + quint8 temp = 0; + for (int i = 0; i < len; ++i) { + temp += data.at(i); + } + + return temp % 256; +} + +void QUIHelper::initTableView(QTableView *tableView, int rowHeight, bool headVisible, bool edit, bool stretchLast) +{ + //设置弱属性用于应用qss特殊样式 + tableView->setProperty("model", true); + //取消自动换行 + tableView->setWordWrap(false); + //超出文本不显示省略号 + tableView->setTextElideMode(Qt::ElideNone); + //奇数偶数行颜色交替 + tableView->setAlternatingRowColors(false); + //垂直表头是否可见 + tableView->verticalHeader()->setVisible(headVisible); + //选中一行表头是否加粗 + tableView->horizontalHeader()->setHighlightSections(false); + //最后一行拉伸填充 + tableView->horizontalHeader()->setStretchLastSection(stretchLast); + //行标题最小宽度尺寸 + tableView->horizontalHeader()->setMinimumSectionSize(0); + //行标题最小高度,等同于和默认行高一致 + tableView->horizontalHeader()->setFixedHeight(rowHeight); + //默认行高 + tableView->verticalHeader()->setDefaultSectionSize(rowHeight); + //选中时一行整体选中 + tableView->setSelectionBehavior(QAbstractItemView::SelectRows); + //只允许选择单个 + tableView->setSelectionMode(QAbstractItemView::SingleSelection); + + //表头不可单击 +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) + tableView->horizontalHeader()->setSectionsClickable(false); +#else + tableView->horizontalHeader()->setClickable(false); +#endif + + //鼠标按下即进入编辑模式 + if (edit) { + tableView->setEditTriggers(QAbstractItemView::CurrentChanged | QAbstractItemView::DoubleClicked); + } else { + tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); + } +} + +void QUIHelper::openFile(const QString &fileName, const QString &msg) +{ +#ifdef __arm__ + return; +#endif + //文件不存在则不用处理 + if (!QFile(fileName).exists()) { + return; + } + if (QUIHelper::showMessageBoxQuestion(msg + "成功, 确定现在就打开吗?") == QMessageBox::Yes) { + QString url = QString("file:///%1").arg(fileName); + QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode)); + } +} + +bool QUIHelper::checkIniFile(const QString &iniFile) +{ + //如果配置文件大小为0,则以初始值继续运行,并生成配置文件 + QFile file(iniFile); + if (file.size() == 0) { + return false; + } + + //如果配置文件不完整,则以初始值继续运行,并生成配置文件 + if (file.open(QFile::ReadOnly)) { + bool ok = true; + while (!file.atEnd()) { + QString line = file.readLine(); + line.replace("\r", ""); + line.replace("\n", ""); + QStringList list = line.split("="); + + if (list.size() == 2) { + QString key = list.at(0); + QString value = list.at(1); + if (value.isEmpty()) { + qDebug() << TIMEMS << "ini node no value" << key; + ok = false; + break; + } + } + } + + if (!ok) { + return false; + } + } else { + return false; + } + + return true; +} + +QString QUIHelper::cutString(const QString &text, int len, int left, int right, bool file, const QString &mid) +{ + //如果指定了字符串分割则表示是文件名需要去掉拓展名 + QString result = text; + if (file && result.contains(".")) { + int index = result.lastIndexOf("."); + result = result.mid(0, index); + } + + //最终字符串格式为 前缀字符...后缀字符 + if (result.length() > len) { + result = QString("%1%2%3").arg(result.left(left)).arg(mid).arg(result.right(right)); + } + + return result; +} + +QRect QUIHelper::getCenterRect(const QSize &imageSize, const QRect &widgetRect, int borderWidth, int scaleMode) +{ + QSize newSize = imageSize; + QSize widgetSize = widgetRect.size() - QSize(borderWidth * 1, borderWidth * 1); + + if (scaleMode == 0) { + if (newSize.width() > widgetSize.width() || newSize.height() > widgetSize.height()) { + newSize.scale(widgetSize, Qt::KeepAspectRatio); + } + } else if (scaleMode == 1) { + newSize.scale(widgetSize, Qt::KeepAspectRatio); + } else { + newSize = widgetSize; + } + + int x = widgetRect.center().x() - newSize.width() / 2; + int y = widgetRect.center().y() - newSize.height() / 2; + //不是2的倍数需要偏移1像素 + x += (x % 2 == 0 ? 1 : 0); + y += (y % 2 == 0 ? 1 : 0); + return QRect(x, y, newSize.width(), newSize.height()); +} + +void QUIHelper::getScaledImage(QImage &image, const QSize &widgetSize, int scaleMode, bool fast) +{ + Qt::TransformationMode mode = fast ? Qt::FastTransformation : Qt::SmoothTransformation; + if (scaleMode == 0) { + if (image.width() > widgetSize.width() || image.height() > widgetSize.height()) { + image = image.scaled(widgetSize, Qt::KeepAspectRatio, mode); + } + } else if (scaleMode == 1) { + image = image.scaled(widgetSize, Qt::KeepAspectRatio, mode); + } else { + image = image.scaled(widgetSize, Qt::IgnoreAspectRatio, mode); + } +} + +QString QUIHelper::getTimeString(qint64 time) +{ + time = time / 1000; + QString min = QString("%1").arg(time / 60, 2, 10, QChar('0')); + QString sec = QString("%2").arg(time % 60, 2, 10, QChar('0')); + return QString("%1:%2").arg(min).arg(sec); +} + +QString QUIHelper::getTimeString(QElapsedTimer timer) +{ + return QString::number((float)timer.elapsed() / 1000, 'f', 3); +} + +QString QUIHelper::getSizeString(quint64 size) +{ + float num = size; + QStringList list; + list << "KB" << "MB" << "GB" << "TB"; + + QString unit("bytes"); + QStringListIterator i(list); + while (num >= 1024.0 && i.hasNext()) { + unit = i.next(); + num /= 1024.0; + } + + return QString("%1 %2").arg(QString::number(num, 'f', 2)).arg(unit); +} diff --git a/core_base/quihelper.h b/core_base/quihelper.h new file mode 100644 index 0000000..d0d79a9 --- /dev/null +++ b/core_base/quihelper.h @@ -0,0 +1,152 @@ +#ifndef QUIHELPER2_H +#define QUIHELPER2_H + +#include "head.h" + +class QUIHelper +{ +public: + //获取当前鼠标所在屏幕索引/区域尺寸/缩放系数 + static int getScreenIndex(); + static QRect getScreenRect(bool available = true); + static qreal getScreenRatio(bool devicePixel = false); + //矫正当前鼠标所在屏幕居中尺寸 + static QRect checkCenterRect(QRect &rect, bool available = true); + + //获取桌面宽度高度+居中显示 + static int deskWidth(); + static int deskHeight(); + static QSize deskSize(); + + //居中显示窗体 + //定义标志位指定是以桌面为参照还是主程序界面为参照 + static QWidget *centerBaseForm; + static void setFormInCenter(QWidget *form); + static void showForm(QWidget *form); + + //程序文件名称+当前所在路径 + static QString appName(); + static QString appPath(); + + //获取本地网卡IP集合 + static QStringList getLocalIPs(); + + //获取内置颜色集合 + static QList colors; + static QList getColorList(); + static QStringList getColorNames(); + //随机获取颜色集合中的颜色 + static QColor getRandColor(); + + //初始化随机数种子 + static void initRand(); + //获取随机小数 + 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); + //根据旧的范围值和值计算新的范围值对应的值 + static int getRangeValue(int oldMin, int oldMax, int oldValue, int newMin, int newMax); + + //获取uuid + static QString getUuid(); + //校验目录 + static void checkPath(const QString &dirName); + //延时 + static void sleep(int msec); + + //设置Qt自带样式 + static void setStyle(); + //设置字体 + static QFont addFont(const QString &fontFile, const QString &fontName); + static void setFont(int fontSize = 12); + //设置编码 + static void setCode(bool utf8 = true); + //设置翻译文件 + static void setTranslator(const QString &qmFile); + + //动态设置权限 + static bool checkPermission(const QString &permission); + //申请安卓权限 + static void initAndroidPermission(); + + //一次性设置所有包括编码样式字体等 + static void initAll(bool utf8 = true, bool style = true, int fontSize = 13); + //初始化main函数最前面执行的一段代码 + static void initMain(bool desktopSettingsAware = true, bool useOpenGLES = false); + + //插入消息 + static QVector msgTypes; + static QVector msgKeys; + static QVector msgColors; + static QString appendMsg(QTextEdit *textEdit, int type, const QString &data, + int maxCount, int ¤tCount, + bool clear = false, bool pause = false); + + //设置无边框 + static void setFramelessForm(QWidget *widgetMain, bool tool = false, bool top = false, bool menu = true); + + //弹出框 + static int showMessageBox(const QString &text, int type = 0, int closeSec = 0, bool exec = false); + //弹出消息框 + static void showMessageBoxInfo(const QString &text, int closeSec = 0, bool exec = false); + //弹出错误框 + static void showMessageBoxError(const QString &text, int closeSec = 0, bool exec = false); + //弹出询问框 + static int showMessageBoxQuestion(const QString &text); + + //为什么还要自定义对话框因为可控宽高和汉化对应文本等 + //初始化对话框文本 + 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); + + //异或加密-只支持字符,如果是中文需要将其转换base64编码 + static QString getXorEncryptDecrypt(const QString &value, char key); + //异或校验 + static quint8 getOrCode(const QByteArray &data); + //计算校验码 + static quint8 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); + + //首尾截断字符串显示 + static QString cutString(const QString &text, int len, int left, int right, bool file, const QString &mid = "..."); + + //传入图片尺寸和窗体区域及边框大小返回居中区域(scaleMode: 0-自动调整 1-等比缩放 2-拉伸填充) + static QRect getCenterRect(const QSize &imageSize, const QRect &widgetRect, int borderWidth = 2, int scaleMode = 0); + //传入图片尺寸和窗体尺寸及缩放策略返回合适尺寸(scaleMode: 0-自动调整 1-等比缩放 2-拉伸填充) + static void getScaledImage(QImage &image, const QSize &widgetSize, int scaleMode = 0, bool fast = true); + + //毫秒数转时间 00:00 + static QString getTimeString(qint64 time); + //用时时间转秒数 + static QString getTimeString(QElapsedTimer timer); + //文件大小转 KB MB GB TB + static QString getSizeString(quint64 size); +}; + +#endif // QUIHELPER2_H diff --git a/main.cpp b/main.cpp index 8b5c008..8e276fc 100644 --- a/main.cpp +++ b/main.cpp @@ -3,10 +3,15 @@ #include #include #include "widget/logindialog.h" +#include "quihelper.h" int main(int argc, char *argv[]) { + QUIHelper::initMain(); QApplication app(argc, argv); + QUIHelper::setFont(); + QUIHelper::setCode(); + QString appDir = QApplication::applicationDirPath(); QTranslator translator; @@ -22,6 +27,7 @@ int main(int argc, char *argv[]) MainWindow w; w.SetUserInfo(login.GetUserInfo()); w.LoadTrendsData(); + QUIHelper::setFormInCenter(&login); w.show(); return app.exec(); } diff --git a/qss.qrc b/qss.qrc new file mode 100644 index 0000000..c5219ef --- /dev/null +++ b/qss.qrc @@ -0,0 +1,28 @@ + + + qss/blacksoft.css + qss/blacksoft/add_bottom.png + qss/blacksoft/add_left.png + qss/blacksoft/add_right.png + qss/blacksoft/add_top.png + qss/blacksoft/arrow_bottom.png + qss/blacksoft/arrow_left.png + qss/blacksoft/arrow_right.png + qss/blacksoft/arrow_top.png + qss/blacksoft/branch_close.png + qss/blacksoft/branch_open.png + qss/blacksoft/calendar_nextmonth.png + qss/blacksoft/calendar_prevmonth.png + qss/blacksoft/checkbox_checked.png + qss/blacksoft/checkbox_checked_disable.png + qss/blacksoft/checkbox_parcial.png + qss/blacksoft/checkbox_parcial_disable.png + qss/blacksoft/checkbox_unchecked.png + qss/blacksoft/checkbox_unchecked_disable.png + qss/blacksoft/menu_checked.png + qss/blacksoft/radiobutton_checked.png + qss/blacksoft/radiobutton_checked_disable.png + qss/blacksoft/radiobutton_unchecked.png + qss/blacksoft/radiobutton_unchecked_disable.png + + diff --git a/qss/blacksoft.css b/qss/blacksoft.css new file mode 100644 index 0000000..6780634 --- /dev/null +++ b/qss/blacksoft.css @@ -0,0 +1,694 @@ +QPalette{background:#444444;}*{outline:0px;color:#DCDCDC;} + +QGraphicsView{ +border:1px solid #242424; +qproperty-backgroundBrush:#444444; +} + +QWidget[form="true"],QLabel[frameShape="1"]{ +border:1px solid #242424; +border-radius:0px; +} + +QWidget[form="bottom"]{ +background:#484848; +} + +QWidget[form="bottom"] .QFrame{ +border:1px solid #DCDCDC; +} + +QWidget[form="bottom"] QLabel,QWidget[form="title"] QLabel{ +border-radius:0px; +color:#DCDCDC; +background:none; +border-style:none; +} + +QWidget[form="title"],QWidget[nav="left"],QWidget[nav="top"] QAbstractButton{ +border-style:none; +border-radius:0px; +padding:5px; +color:#DCDCDC; +background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #484848,stop:1 #383838); +} + +QWidget[nav="top"] QAbstractButton:hover,QWidget[nav="top"] QAbstractButton:pressed,QWidget[nav="top"] QAbstractButton:checked{ +border-style:solid; +border-width:0px 0px 2px 0px; +padding:4px 4px 2px 4px; +border-color:#AAAAAA; +background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #646464,stop:1 #525252); +} + +QWidget[nav="left"] QAbstractButton{ +border-radius:0px; +color:#DCDCDC; +background:none; +border-style:none; +} + +QWidget[nav="left"] QAbstractButton:hover{ +color:#FFFFFF; +background-color:#AAAAAA; +} + +QWidget[nav="left"] QAbstractButton:checked,QWidget[nav="left"] QAbstractButton:pressed{ +color:#DCDCDC; +border-style:solid; +border-width:0px 0px 0px 2px; +padding:4px 4px 4px 2px; +border-color:#AAAAAA; +background-color:#444444; +} + +QWidget[video="true"] QLabel{ +color:#DCDCDC; +border:1px solid #242424; +background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #484848,stop:1 #383838); +} + +QWidget[video="true"] QLabel:focus{ +border:1px solid #AAAAAA; +background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #646464,stop:1 #525252); +} + +QLineEdit:read-only{ +background-color:#484848; +} + +QLineEdit,QTextEdit,QPlainTextEdit,QSpinBox,QDoubleSpinBox,QComboBox,QDateEdit,QTimeEdit,QDateTimeEdit{ +border:1px solid #242424; +border-radius:3px; +padding:2px; +background:none; +selection-background-color:#AAAAAA; +selection-color:#FFFFFF; +} + +QLineEdit:focus,QTextEdit:focus,QPlainTextEdit:focus,QSpinBox:focus,QDoubleSpinBox:focus,QComboBox:focus,QDateEdit:focus,QTimeEdit:focus,QDateTimeEdit:focus,QLineEdit:hover,QTextEdit:hover,QPlainTextEdit:hover,QSpinBox:hover,QDoubleSpinBox:hover,QComboBox:hover,QDateEdit:hover,QTimeEdit:hover,QDateTimeEdit:hover{ +border:1px solid #242424; +} + +QLineEdit[echoMode="2"]{ +lineedit-password-character:9679; +} + +.QFrame{ +border:1px solid #242424; +border-radius:3px; +} + +.QGroupBox{ +border:1px solid #242424; +border-radius:5px; +margin-top:9px; +} + +.QGroupBox::title{ +subcontrol-origin:margin; +position:relative; +left:10px; +} + +.QPushButton,.QToolButton{ +border-style:none; +border:1px solid #242424; +color:#DCDCDC; +padding:5px; +min-height:15px; +border-radius:5px; +background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #484848,stop:1 #383838); +} + +.QPushButton:hover,.QToolButton:hover{ +background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #646464,stop:1 #525252); +} + +.QPushButton:pressed,.QToolButton:pressed{ +background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #484848,stop:1 #383838); +} + +.QToolButton::menu-indicator{ +image:None; +} + +QToolButton#btnMenu,QPushButton#btnMenu_Min,QPushButton#btnMenu_Max,QPushButton#btnMenu_Close{ +border-radius:3px; +color:#DCDCDC; +padding:3px; +margin:0px; +background:none; +border-style:none; +} + +QToolButton#btnMenu:hover,QPushButton#btnMenu_Min:hover,QPushButton#btnMenu_Max:hover{ +color:#FFFFFF; +margin:1px 1px 2px 1px; +background-color:rgba(51,127,209,230); +} + +QPushButton#btnMenu_Close:hover{ +color:#FFFFFF; +margin:1px 1px 2px 1px; +background-color:rgba(238,0,0,128); +} + +QRadioButton::indicator{ +width:15px; +height:15px; +} + +QRadioButton::indicator::unchecked{ +image:url(:/qss/blacksoft/radiobutton_unchecked.png); +} + +QRadioButton::indicator::unchecked:disabled{ +image:url(:/qss/blacksoft/radiobutton_unchecked_disable.png); +} + +QRadioButton::indicator::checked{ +image:url(:/qss/blacksoft/radiobutton_checked.png); +} + +QRadioButton::indicator::checked:disabled{ +image:url(:/qss/blacksoft/radiobutton_checked_disable.png); +} + +QGroupBox::indicator,QTreeView::indicator,QListView::indicator,QTableView::indicator{ +padding:0px 0px 0px 0px; +} + +QCheckBox::indicator,QGroupBox::indicator,QTreeView::indicator,QListView::indicator,QTableView::indicator{ +width:13px; +height:13px; +} + +QCheckBox::indicator:unchecked,QGroupBox::indicator:unchecked,QTreeView::indicator:unchecked,QListView::indicator:unchecked,QTableView::indicator:unchecked{ +image:url(:/qss/blacksoft/checkbox_unchecked.png); +} + +QCheckBox::indicator:unchecked:disabled,QGroupBox::indicator:unchecked:disabled,QTreeView::indicator:unchecked:disabled,QListView::indicator:unchecked:disabled,QTableView::indicator:unchecked:disabled{ +image:url(:/qss/blacksoft/checkbox_unchecked_disable.png); +} + +QCheckBox::indicator:checked,QGroupBox::indicator:checked,QTreeView::indicator:checked,QListView::indicator:checked,QTableView::indicator:checked{ +image:url(:/qss/blacksoft/checkbox_checked.png); +} + +QCheckBox::indicator:checked:disabled,QGroupBox::indicator:checked:disabled,QTreeView::indicator:checked:disabled,QListView::indicator:checked:disabled,QTableView::indicator:checked:disabled{ +image:url(:/qss/blacksoft/checkbox_checked_disable.png); +} + +QCheckBox::indicator:indeterminate,QGroupBox::indicator:indeterminate,QTreeView::indicator:indeterminate,QListView::indicator:indeterminate,QTableView::indicator:indeterminate{ +image:url(:/qss/blacksoft/checkbox_parcial.png); +} + +QCheckBox::indicator:indeterminate:disabled,QGroupBox::indicator:indeterminate:disabled,QTreeView::indicator:indeterminate:disabled,QListView::indicator:indeterminate:disabled,QTableView::indicator:indeterminate:disabled{ +image:url(:/qss/blacksoft/checkbox_parcial_disable.png); +} + +QTimeEdit::up-button,QDateEdit::up-button,QDateTimeEdit::up-button,QDoubleSpinBox::up-button,QSpinBox::up-button{ +image:url(:/qss/blacksoft/add_top.png); +width:10px; +height:10px; +padding:2px 5px 0px 0px; +} + +QTimeEdit::down-button,QDateEdit::down-button,QDateTimeEdit::down-button,QDoubleSpinBox::down-button,QSpinBox::down-button{ +image:url(:/qss/blacksoft/add_bottom.png); +width:10px; +height:10px; +padding:0px 5px 2px 0px; +} + +QTimeEdit::up-button:pressed,QDateEdit::up-button:pressed,QDateTimeEdit::up-button:pressed,QDoubleSpinBox::up-button:pressed,QSpinBox::up-button:pressed{ +top:-2px; +} + +QTimeEdit::down-button:pressed,QDateEdit::down-button:pressed,QDateTimeEdit::down-button:pressed,QDoubleSpinBox::down-button:pressed,QSpinBox::down-button:pressed,QSpinBox::down-button:pressed{ +bottom:-2px; +} + +QComboBox::down-arrow,QDateEdit[calendarPopup="true"]::down-arrow,QTimeEdit[calendarPopup="true"]::down-arrow,QDateTimeEdit[calendarPopup="true"]::down-arrow{ +image:url(:/qss/blacksoft/add_bottom.png); +width:10px; +height:10px; +right:2px; +} + +QComboBox::drop-down,QDateEdit::drop-down,QTimeEdit::drop-down,QDateTimeEdit::drop-down{ +subcontrol-origin:padding; +subcontrol-position:top right; +width:15px; +border-left-width:0px; +border-left-style:solid; +border-top-right-radius:3px; +border-bottom-right-radius:3px; +border-left-color:#242424; +} + +QComboBox::drop-down:on{ +top:1px; +} + +QMenuBar::item{ +color:#DCDCDC; +background-color:#484848; +margin:0px; +padding:3px 10px; +} + +QMenu,QMenuBar,QMenu:disabled,QMenuBar:disabled{ +color:#DCDCDC; +background-color:#484848; +border:1px solid #242424; +margin:0px; +} + +QMenu::item{ +padding:3px 20px; +} + +QMenu::indicator{ +width:20px; +height:13px; +} + +QMenu::indicator::checked{ +image:url(:/qss/blacksoft/menu_checked.png); +} + +QMenu::right-arrow{ +image:url(:/qss/blacksoft/arrow_right.png); +width:13px; +height:13px; +padding:0px 3px 0px 0px; +} + +QMenu::item:selected,QMenuBar::item:selected{ +color:#DCDCDC; +border:0px solid #242424; +background:#646464; +} + +QMenu::separator{ +height:1px; +background:#242424; +} + +QProgressBar{ +min-height:10px; +background:#484848; +border-radius:5px; +text-align:center; +border:1px solid #484848; +} + +QProgressBar:chunk{ +border-radius:5px; +background-color:#242424; +} + +QSlider::groove:horizontal{ +height:8px; +border-radius:4px; +background:#484848; +} + +QSlider::add-page:horizontal{ +height:8px; +border-radius:4px; +background:#484848; +} + +QSlider::sub-page:horizontal{ +height:8px; +border-radius:4px; +background:#242424; +} + +QSlider::handle:horizontal{ +width:13px; +margin-top:-3px; +margin-bottom:-3px; +border-radius:6px; +background:qradialgradient(spread:pad,cx:0.5,cy:0.5,radius:0.5,fx:0.5,fy:0.5,stop:0.6 #444444,stop:0.8 #242424); +} + +QSlider::groove:vertical{ +width:8px; +border-radius:4px; +background:#484848; +} + +QSlider::add-page:vertical{ +width:8px; +border-radius:4px; +background:#242424; +} + +QSlider::sub-page:vertical{ +width:8px; +border-radius:4px; +background:#484848; +} + +QSlider::handle:vertical{ +height:14px; +margin-left:-3px; +margin-right:-3px; +border-radius:6px; +background:qradialgradient(spread:pad,cx:0.5,cy:0.5,radius:0.5,fx:0.5,fy:0.5,stop:0.6 #444444,stop:0.8 #242424); +} + +QScrollBar:horizontal{ +background:#484848; +padding:0px; +border-radius:6px; +max-height:12px; +} + +QScrollBar::handle:horizontal{ +background:#242424; +min-width:50px; +border-radius:6px; +} + +QScrollBar::handle:horizontal:hover{ +background:#AAAAAA; +} + +QScrollBar::handle:horizontal:pressed{ +background:#AAAAAA; +} + +QScrollBar::add-page:horizontal{ +background:none; +} + +QScrollBar::sub-page:horizontal{ +background:none; +} + +QScrollBar::add-line:horizontal{ +background:none; +} + +QScrollBar::sub-line:horizontal{ +background:none; +} + +QScrollBar:vertical{ +background:#484848; +padding:0px; +border-radius:6px; +max-width:12px; +} + +QScrollBar::handle:vertical{ +background:#242424; +min-height:50px; +border-radius:6px; +} + +QScrollBar::handle:vertical:hover{ +background:#AAAAAA; +} + +QScrollBar::handle:vertical:pressed{ +background:#AAAAAA; +} + +QScrollBar::add-page:vertical{ +background:none; +} + +QScrollBar::sub-page:vertical{ +background:none; +} + +QScrollBar::add-line:vertical{ +background:none; +} + +QScrollBar::sub-line:vertical{ +background:none; +} + +QScrollArea{ +border:0px; +} + +QTreeView,QListView,QTableView,QTabWidget::pane{ +border:1px solid #242424; +selection-background-color:#646464; +selection-color:#DCDCDC; +alternate-background-color:#525252; +gridline-color:#242424; +} + +QTreeView::branch:closed:has-children{ +margin:4px; +border-image:url(:/qss/blacksoft/branch_open.png); +} + +QTreeView::branch:open:has-children{ +margin:4px; +border-image:url(:/qss/blacksoft/branch_close.png); +} + +QTreeView,QListView,QTableView,QSplitter::handle,QTreeView::branch{ +background:#444444; +} + +QTableView::item:selected,QListView::item:selected,QTreeView::item:selected{ +color:#DCDCDC; +background:#383838; +} + +QTableView::item:hover,QListView::item:hover,QTreeView::item:hover,QHeaderView,QHeaderView::section,QTableCornerButton:section{ +color:#DCDCDC; +background:#525252; +} + +QTableView::item,QListView::item,QTreeView::item{ +padding:1px; +margin:0px; +border:0px; +} + +QHeaderView::section,QTableCornerButton:section{ +padding:3px; +margin:0px; +border:1px solid #242424; +border-left-width:0px; +border-right-width:1px; +border-top-width:0px; +border-bottom-width:1px; +} + +QTabBar::tab{ +border:1px solid #242424; +color:#DCDCDC; +margin:0px; +background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #646464,stop:1 #525252); +} + +QTabBar::tab:selected{ +border-style:solid; +border-color:#AAAAAA; +background:#444444; +} + +QTabBar::tab:top,QTabBar::tab:bottom{ +padding:3px 8px 3px 8px; +} + +QTabBar::tab:left,QTabBar::tab:right{ +padding:8px 3px 8px 3px; +} + +QTabBar::tab:top:selected{ +border-width:2px 0px 0px 0px; +} + +QTabBar::tab:right:selected{ +border-width:0px 0px 0px 2px; +} + +QTabBar::tab:bottom:selected{ +border-width:0px 0px 2px 0px; +} + +QTabBar::tab:left:selected{ +border-width:0px 2px 0px 0px; +} + +QTabBar::tab:first:top:selected,QTabBar::tab:first:bottom:selected{ +border-left-width:1px; +border-left-color:#242424; +} + +QTabBar::tab:first:left:selected,QTabBar::tab:first:right:selected{ +border-top-width:1px; +border-top-color:#242424; +} + +QTabBar::tab:last:top:selected,QTabBar::tab:last:bottom:selected{ +border-right-width:1px; +border-right-color:#242424; +} + +QTabBar::tab:last:left:selected,QTabBar::tab:last:right:selected{ +border-bottom-width:1px; +border-bottom-color:#242424; +} + +QStatusBar::item{ +border:0px solid #484848; +border-radius:3px; +} + +QToolBox::tab,QWidget[form="panel"]{ +padding:3px; +border-radius:5px; +color:#DCDCDC; +background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #484848,stop:1 #383838); +} + +QWidget[flag="paneltitle"]{ +border-bottom-left-radius:0px; +border-bottom-right-radius:0px; +} + +QWidget[flag="panelcontrol"]{ +border-top-width:0px; +border-top-left-radius:0px; +border-top-right-radius:0px; +} + +QToolTip{ +border:0px solid #DCDCDC; +padding:1px; +color:#DCDCDC; +background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #484848,stop:1 #383838); +} + +QToolBox::tab:selected{ +background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #646464,stop:1 #525252); +} + +QPrintPreviewDialog QToolButton{ +border:0px solid #DCDCDC; +border-radius:0px; +margin:0px; +padding:3px; +background:none; +} + +QColorDialog QPushButton,QFileDialog QPushButton{ +min-width:80px; +} + +QToolButton#qt_calendar_prevmonth{ +icon-size:0px; +min-width:20px; +image:url(:/qss/blacksoft/calendar_prevmonth.png); +} + +QToolButton#qt_calendar_nextmonth{ +icon-size:0px; +min-width:20px; +image:url(:/qss/blacksoft/calendar_nextmonth.png); +} + +QToolButton#qt_calendar_prevmonth,QToolButton#qt_calendar_nextmonth,QToolButton#qt_calendar_monthbutton,QToolButton#qt_calendar_yearbutton{ +border:0px solid #DCDCDC; +border-radius:3px; +margin:3px 3px 3px 3px; +padding:3px; +background:none; +} + +QToolButton#qt_calendar_prevmonth:hover,QToolButton#qt_calendar_nextmonth:hover,QToolButton#qt_calendar_monthbutton:hover,QToolButton#qt_calendar_yearbutton:hover,QToolButton#qt_calendar_prevmonth:pressed,QToolButton#qt_calendar_nextmonth:pressed,QToolButton#qt_calendar_monthbutton:pressed,QToolButton#qt_calendar_yearbutton:pressed{ +border:1px solid #242424; +} + +QCalendarWidget QSpinBox#qt_calendar_yearedit{ +margin:2px; +} + +QCalendarWidget QToolButton::menu-indicator{ +image:None; +} + +QCalendarWidget QTableView{ +border-width:0px; +} + +QCalendarWidget QWidget#qt_calendar_navigationbar{ +border:1px solid #242424; +border-width:1px 1px 0px 1px; +background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #484848,stop:1 #383838); +} + +QTableView[model="true"]::item{ +padding:0px; +margin:0px; +} + +QTableView QLineEdit,QTableView QComboBox,QTableView QSpinBox,QTableView QDoubleSpinBox,QTableView QDateEdit,QTableView QTimeEdit,QTableView QDateTimeEdit{ +border-width:0px; +border-radius:0px; +} + +QTableView QLineEdit:focus,QTableView QComboBox:focus,QTableView QSpinBox:focus,QTableView QDoubleSpinBox:focus,QTableView QDateEdit:focus,QTableView QTimeEdit:focus,QTableView QDateTimeEdit:focus{ +border-width:0px; +border-radius:0px; +} + +QLineEdit,QTextEdit,QPlainTextEdit,QSpinBox,QDoubleSpinBox,QComboBox,QDateEdit,QTimeEdit,QDateTimeEdit{ +background:#444444; +} + +QTabWidget::pane:top{top:-1px;} +QTabWidget::pane:bottom{bottom:-1px;} +QTabWidget::pane:left{right:-1px;} +QTabWidget::pane:right{left:-1px;} + +QDialog,QDial,#QUIWidgetMain{ +background-color:#444444; +color:#DCDCDC; +} + +QDialogButtonBox>QPushButton{ +min-width:50px; +} + +QListView[noborder="true"],QTreeView[noborder="true"],QTabWidget[noborder="true"]::pane{ +border-width:0px; +} + +QToolBar>*,QStatusBar>*{ +margin:2px; +} + +*:disabled,QMenu::item:disabled,QTabBar:tab:disabled,QHeaderView::section:disabled{ +background:#444444; +border-color:#484848; +color:#242424; +} + +QLabel:disabled{ +background:none; +} + +/*TextColor:#DCDCDC*/ +/*PanelColor:#444444*/ +/*BorderColor:#242424*/ +/*NormalColorStart:#484848*/ +/*NormalColorEnd:#383838*/ +/*DarkColorStart:#646464*/ +/*DarkColorEnd:#525252*/ +/*HighColor:#AAAAAA*/ \ No newline at end of file diff --git a/qss/blacksoft/add_bottom.png b/qss/blacksoft/add_bottom.png new file mode 100644 index 0000000..b4a5f14 Binary files /dev/null and b/qss/blacksoft/add_bottom.png differ diff --git a/qss/blacksoft/add_left.png b/qss/blacksoft/add_left.png new file mode 100644 index 0000000..165ebd0 Binary files /dev/null and b/qss/blacksoft/add_left.png differ diff --git a/qss/blacksoft/add_right.png b/qss/blacksoft/add_right.png new file mode 100644 index 0000000..4c79925 Binary files /dev/null and b/qss/blacksoft/add_right.png differ diff --git a/qss/blacksoft/add_top.png b/qss/blacksoft/add_top.png new file mode 100644 index 0000000..f76300f Binary files /dev/null and b/qss/blacksoft/add_top.png differ diff --git a/qss/blacksoft/arrow_bottom.png b/qss/blacksoft/arrow_bottom.png new file mode 100644 index 0000000..39d7cbc Binary files /dev/null and b/qss/blacksoft/arrow_bottom.png differ diff --git a/qss/blacksoft/arrow_left.png b/qss/blacksoft/arrow_left.png new file mode 100644 index 0000000..1353cb8 Binary files /dev/null and b/qss/blacksoft/arrow_left.png differ diff --git a/qss/blacksoft/arrow_right.png b/qss/blacksoft/arrow_right.png new file mode 100644 index 0000000..0e50d47 Binary files /dev/null and b/qss/blacksoft/arrow_right.png differ diff --git a/qss/blacksoft/arrow_top.png b/qss/blacksoft/arrow_top.png new file mode 100644 index 0000000..d2c71e8 Binary files /dev/null and b/qss/blacksoft/arrow_top.png differ diff --git a/qss/blacksoft/branch_close.png b/qss/blacksoft/branch_close.png new file mode 100644 index 0000000..58a7d13 Binary files /dev/null and b/qss/blacksoft/branch_close.png differ diff --git a/qss/blacksoft/branch_open.png b/qss/blacksoft/branch_open.png new file mode 100644 index 0000000..a072d68 Binary files /dev/null and b/qss/blacksoft/branch_open.png differ diff --git a/qss/blacksoft/calendar_nextmonth.png b/qss/blacksoft/calendar_nextmonth.png new file mode 100644 index 0000000..b06ae31 Binary files /dev/null and b/qss/blacksoft/calendar_nextmonth.png differ diff --git a/qss/blacksoft/calendar_prevmonth.png b/qss/blacksoft/calendar_prevmonth.png new file mode 100644 index 0000000..46d4d62 Binary files /dev/null and b/qss/blacksoft/calendar_prevmonth.png differ diff --git a/qss/blacksoft/checkbox_checked.png b/qss/blacksoft/checkbox_checked.png new file mode 100644 index 0000000..b5ba6ef Binary files /dev/null and b/qss/blacksoft/checkbox_checked.png differ diff --git a/qss/blacksoft/checkbox_checked_disable.png b/qss/blacksoft/checkbox_checked_disable.png new file mode 100644 index 0000000..f6aab40 Binary files /dev/null and b/qss/blacksoft/checkbox_checked_disable.png differ diff --git a/qss/blacksoft/checkbox_parcial.png b/qss/blacksoft/checkbox_parcial.png new file mode 100644 index 0000000..cd1645f Binary files /dev/null and b/qss/blacksoft/checkbox_parcial.png differ diff --git a/qss/blacksoft/checkbox_parcial_disable.png b/qss/blacksoft/checkbox_parcial_disable.png new file mode 100644 index 0000000..dd0918f Binary files /dev/null and b/qss/blacksoft/checkbox_parcial_disable.png differ diff --git a/qss/blacksoft/checkbox_unchecked.png b/qss/blacksoft/checkbox_unchecked.png new file mode 100644 index 0000000..8a23968 Binary files /dev/null and b/qss/blacksoft/checkbox_unchecked.png differ diff --git a/qss/blacksoft/checkbox_unchecked_disable.png b/qss/blacksoft/checkbox_unchecked_disable.png new file mode 100644 index 0000000..e2a2262 Binary files /dev/null and b/qss/blacksoft/checkbox_unchecked_disable.png differ diff --git a/qss/blacksoft/menu_checked.png b/qss/blacksoft/menu_checked.png new file mode 100644 index 0000000..4fca11f Binary files /dev/null and b/qss/blacksoft/menu_checked.png differ diff --git a/qss/blacksoft/radiobutton_checked.png b/qss/blacksoft/radiobutton_checked.png new file mode 100644 index 0000000..69e499f Binary files /dev/null and b/qss/blacksoft/radiobutton_checked.png differ diff --git a/qss/blacksoft/radiobutton_checked_disable.png b/qss/blacksoft/radiobutton_checked_disable.png new file mode 100644 index 0000000..f098cc5 Binary files /dev/null and b/qss/blacksoft/radiobutton_checked_disable.png differ diff --git a/qss/blacksoft/radiobutton_unchecked.png b/qss/blacksoft/radiobutton_unchecked.png new file mode 100644 index 0000000..3f36472 Binary files /dev/null and b/qss/blacksoft/radiobutton_unchecked.png differ diff --git a/qss/blacksoft/radiobutton_unchecked_disable.png b/qss/blacksoft/radiobutton_unchecked_disable.png new file mode 100644 index 0000000..f729f17 Binary files /dev/null and b/qss/blacksoft/radiobutton_unchecked_disable.png differ diff --git a/resource.qrc b/resource.qrc new file mode 100644 index 0000000..96950d1 --- /dev/null +++ b/resource.qrc @@ -0,0 +1,3 @@ + + + diff --git a/treasurefinder_zh_CN.ts b/treasurefinder_zh_CN.ts index 2ab6959..064c898 100644 --- a/treasurefinder_zh_CN.ts +++ b/treasurefinder_zh_CN.ts @@ -115,45 +115,70 @@ - + + Verification code - + 验证码 + 验证码 - + + Password + 密码 + 密码 + + + + 最小化 - - UserName + + 关闭 - + + + UserName + 用户名 + 用户名 + + + admin - + 1qazse42W3 - - + + Login - + 登录 + 登录 - + Cancel - + 取消 + 取消 + + + + mojin login + 摸金系统登录 + 摸金系统登录 - + Login Error. - + 登录错误 + 登录错误 @@ -245,82 +270,90 @@ - + date 日期 日期 - + week 星期 星期 - + name 证券名称 证券名称 - + operate 操作 操作 - + operateprice 操作价格 操作价格 - + volume 操作数量 操作数量 - + remainig 剩余数量 剩余数量 - + operatechange 操作涨跌幅 操作涨跌幅 - + close 收盘价 收盘价 - + operateprofit 操作盈亏 操作盈亏 - + totalprofit 收盘盈亏 收盘盈亏 - + finalprofit 总盈亏 总盈亏 - + remark 备注 备注 + + TrendsWidget + + + Form + + + diff --git a/widget/logindialog.cpp b/widget/logindialog.cpp index 114dcd6..2699aa3 100644 --- a/widget/logindialog.cpp +++ b/widget/logindialog.cpp @@ -8,12 +8,17 @@ #include #include #include +#include "iconhelper.h" +#include "quihelper.h" LoginDialog::LoginDialog(QWidget *parent) : QDialog(parent), ui(new Ui::LoginDialog) { ui->setupUi(this); + Init(); + InitStyle(); + this->installEventFilter(this); m_UserData.SetManagerType(ManagerType::Ruoyi); GetVerificationCode(); } @@ -23,11 +28,103 @@ LoginDialog::~LoginDialog() delete ui; } +bool LoginDialog::eventFilter(QObject *watched, QEvent *event) +{ + QWidget *w = (QWidget *)watched; + if(w->property("form") != "title") + { + return QObject::eventFilter(watched, event); + } + if (!w->property("canMove").toBool()) + { + return QObject::eventFilter(watched, event); + } + + static QPoint mousePoint; + static bool mousePressed = false; + + QMouseEvent *mouseEvent = static_cast(event); + if (mouseEvent->type() == QEvent::MouseButtonPress) { + if (mouseEvent->button() == Qt::LeftButton) { + mousePressed = true; + mousePoint = mouseEvent->globalPos() - this->pos(); + } + } else if (mouseEvent->type() == QEvent::MouseButtonRelease) { + mousePressed = false; + } else if (mouseEvent->type() == QEvent::MouseMove) { + if (mousePressed) { + this->move(mouseEvent->globalPos() - mousePoint); + return true; + } + } + + return QObject::eventFilter(watched, event); +} + + +void LoginDialog::Init() +{ + //设置无边框 + QUIHelper::setFramelessForm(this); + //设置图标 + IconHelper::setIcon(ui->btnMenu_Min, 0xf068); + IconHelper::setIcon(ui->btnMenu_Close, 0xf00d); + + //ui->widgetMenu->setVisible(false); + ui->widgetTitle->setProperty("form", "title"); + ui->widgetTitle->setProperty("canMove",true); + //关联事件过滤器用于双击放大 + ui->widgetTitle->installEventFilter(this); + ui->widgetTop->setProperty("nav", "top"); + + QFont font; + font.setPixelSize(25); + ui->labTitle->setFont(font); + ui->labTitle->setText(tr("mojin login")); + this->setWindowTitle(ui->labTitle->text()); +} + +void LoginDialog::InitStyle() +{ + //加载样式表 + QString qss; + QFile file(":/qss/blacksoft.css"); + if (file.open(QFile::ReadOnly)) { + qss = QLatin1String(file.readAll()); + QString paletteColor = qss.mid(20, 7); + qApp->setPalette(QPalette(paletteColor)); + qApp->setStyleSheet(qss); + file.close(); + } + + //先从样式表中取出对应的颜色 + QString textColor, panelColor, borderColor, normalColorStart, normalColorEnd, darkColorStart, darkColorEnd, highColor; + getQssColor(qss, textColor, panelColor, borderColor, normalColorStart, normalColorEnd, darkColorStart, darkColorEnd, highColor); + + //将对应颜色设置到控件 + this->borderColor = highColor; + this->normalBgColor = normalColorStart; + this->darkBgColor = panelColor; + this->normalTextColor = textColor; + this->darkTextColor = normalTextColor; +} + void LoginDialog::on_pushButton_cancle_clicked() { this->reject(); } +void LoginDialog::on_btnMenu_Min_clicked() +{ + showMinimized(); +} + +void LoginDialog::on_btnMenu_Close_clicked() +{ + close(); +} + + void LoginDialog::GetVerificationCode() { QPixmap pix = m_UserData.GetVerificationCode(); @@ -45,3 +142,25 @@ void LoginDialog::on_pushButton_login_clicked() this->accept(); } +void LoginDialog::getQssColor(const QString &qss, const QString &flag, QString &color) +{ + int index = qss.indexOf(flag); + if (index >= 0) { + color = qss.mid(index + flag.length(), 7); + } + //qDebug() << TIMEMS << flag << color; +} + +void LoginDialog::getQssColor(const QString &qss, QString &textColor, QString &panelColor, + QString &borderColor, QString &normalColorStart, QString &normalColorEnd, + QString &darkColorStart, QString &darkColorEnd, QString &highColor) +{ + getQssColor(qss, "TextColor:", textColor); + getQssColor(qss, "PanelColor:", panelColor); + getQssColor(qss, "BorderColor:", borderColor); + getQssColor(qss, "NormalColorStart:", normalColorStart); + getQssColor(qss, "NormalColorEnd:", normalColorEnd); + getQssColor(qss, "DarkColorStart:", darkColorStart); + getQssColor(qss, "DarkColorEnd:", darkColorEnd); + getQssColor(qss, "HighColor:", highColor); +} diff --git a/widget/logindialog.h b/widget/logindialog.h index 9429798..c45c07d 100644 --- a/widget/logindialog.h +++ b/widget/logindialog.h @@ -19,17 +19,39 @@ public: ~LoginDialog(); UserInfo GetUserInfo(){return m_UserInfo;} private: + void Init(); + void InitStyle(); //加载验证码 void GetVerificationCode(); +protected: + bool eventFilter(QObject *watched, QEvent *event); + private slots: void on_pushButton_cancle_clicked(); void on_pushButton_login_clicked(); + void on_btnMenu_Min_clicked(); +// void on_btnMenu_Max_clicked(); + void on_btnMenu_Close_clicked(); +private: + void getQssColor(const QString &qss, const QString &flag, QString &color); + void getQssColor(const QString &qss, QString &textColor, + QString &panelColor, QString &borderColor, + QString &normalColorStart, QString &normalColorEnd, + QString &darkColorStart, QString &darkColorEnd, + QString &highColor); private: Ui::LoginDialog *ui; UserData m_UserData; UserInfo m_UserInfo; + + //根据QSS样式获取对应颜色值 + QString borderColor; + QString normalBgColor; + QString darkBgColor; + QString normalTextColor; + QString darkTextColor; }; #endif // LOGINDIALOG_H diff --git a/widget/logindialog.ui b/widget/logindialog.ui index 0116a7b..1fd4ea0 100644 --- a/widget/logindialog.ui +++ b/widget/logindialog.ui @@ -6,8 +6,8 @@ 0 0 - 707 - 459 + 600 + 300 @@ -16,30 +16,232 @@ - 150 - 150 - 440 - 126 + 200 + 240 + 169 + 27 - - - + + + - Verification code + Login - - + + + + Cancel + + + + + + + + + 0 + 0 + 600 + 65 + + + + + 0 + 0 + + + + + 10 + + + 10 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Qt::AlignCenter + + + + + + + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + - 0 - 36 + 100 + 0 + + + + + 100 + 16777215 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + ArrowCursor + + + Qt::NoFocus + + + 最小化 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + ArrowCursor + + + Qt::NoFocus + + + 关闭 + + + + + + + + + + + + + 0 + 65 + 601 + 144 + + + @@ -59,14 +261,30 @@ - - + + + + + 0 + 36 + + + 1qazse42W3 + + Password - + + + + Verification code + + + + UserName @@ -77,54 +295,64 @@ - 128 + 168 36 admin + + UserName + - - + + 0 36 - - 1qazse42W3 + + Verification code - - - - - - 270 - 310 - 169 - 26 - - - - - - - Login + + + + Qt::Horizontal - + + + 40 + 20 + + + - - + + - Cancel + Password + + + + Qt::Horizontal + + + + 40 + 20 + + + + diff --git a/widget/trendswidget.cpp b/widget/trendswidget.cpp index 36c70b5..fd218df 100644 --- a/widget/trendswidget.cpp +++ b/widget/trendswidget.cpp @@ -36,6 +36,7 @@ void TrendsWidget::LoadTrendsData() if(rowCount > 2) { model->insertRow(0); + qDebug() << __FUNCTION__ << " trends[0]: " << trends[0]; QList columns = trends[0]; columnCount = columns.count(); for (int column = 0; column < columnCount; ++column) { @@ -43,7 +44,9 @@ void TrendsWidget::LoadTrendsData() model->setItem(0, column, item); } } - qDebug() << __FUNCTION__ << trends[1]; + qDebug() << __FUNCTION__ << " trends[1]: " < row1List = trends[1]; qDebug() << __FUNCTION__ << trends[1]; @@ -55,12 +58,12 @@ void TrendsWidget::LoadTrendsData() model->setItem(row, 0, item); } - for(int col = 1 ; col < columnCount; col++) + for(int row = 2 ; row < rowCount; row++) { - for(int row = 2 ; row < rowCount; row++) + for(int col = 0 ; col < columnCount; col++) { - QStandardItem *item = new QStandardItem(trends[col][row]); - model->setItem(row, col, item); + QStandardItem *item = new QStandardItem(trends[row][col]); + model->setItem(row, col+1, item); } }