diff --git a/3rd_smtpclient/emailaddress.cpp b/3rd_smtpclient/emailaddress.cpp index 19cf418..808ce43 100644 --- a/3rd_smtpclient/emailaddress.cpp +++ b/3rd_smtpclient/emailaddress.cpp @@ -20,12 +20,12 @@ void EmailAddress::setAddress(const QString &address) this->address = address; } -const QString EmailAddress::getName() const +const QString &EmailAddress::getName() const { return name; } -const QString EmailAddress::getAddress() const +const QString &EmailAddress::getAddress() const { - return address; + return address; } diff --git a/3rd_smtpclient/emailaddress.h b/3rd_smtpclient/emailaddress.h index 06a09c0..0ea0e05 100644 --- a/3rd_smtpclient/emailaddress.h +++ b/3rd_smtpclient/emailaddress.h @@ -8,7 +8,7 @@ class EmailAddress : public QObject Q_OBJECT public: - explicit EmailAddress(); + EmailAddress(); EmailAddress(const QString &address, const QString &name = ""); ~EmailAddress(); @@ -16,8 +16,8 @@ public: void setName(const QString &name); void setAddress(const QString &address); - const QString getName() const; - const QString getAddress() const; + const QString &getName() const; + const QString &getAddress() const; private: QString name; diff --git a/3rd_smtpclient/smtpclient.h b/3rd_smtpclient/smtpclient.h index 0cf2815..1c3b097 100644 --- a/3rd_smtpclient/smtpclient.h +++ b/3rd_smtpclient/smtpclient.h @@ -3,7 +3,7 @@ #include #include -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) #include #endif #include "mimemessage.h" diff --git a/QWidgetDemo.pro b/QWidgetDemo.pro index 82271a7..ab8012d 100644 --- a/QWidgetDemo.pro +++ b/QWidgetDemo.pro @@ -14,7 +14,7 @@ SUBDIRS += devicesizetable #硬盘容量控件 SUBDIRS += styledemo #高仿PS黑色+扁平白色+淡蓝色风格主题 SUBDIRS += navbutton #导航按钮控件 SUBDIRS += videopanel #视频监控画面分割demo -SUBDIRS += framelesswidget #通用无边框拖动拉伸类 +SUBDIRS += framelesswidget #跨平台无边框窗体 SUBDIRS += ipaddress #IP地址输入控件 SUBDIRS += bgdemo #无边框背景透明窗体 SUBDIRS += dbpage #通用数据库翻页查询 @@ -35,9 +35,8 @@ SUBDIRS += videowidget #通用视频控件 SUBDIRS += screenwidget #屏幕截图控件 SUBDIRS += imageswitch #图片开关控件 SUBDIRS += netserver #网络中转服务器 -SUBDIRS += base64 #图片文字base64互换 +SUBDIRS += base64helper #图片文字base64互换 SUBDIRS += smoothcurve #平滑曲线 -SUBDIRS += frameless #跨平台无边框窗体 #限定windows系统加载下面的项目 win32 { diff --git a/README.md b/README.md index 0b47245..3a481f3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#### 一、目录说明 +#### 一、目录说明 1. **可以选择打开QWidgetDemo.pro一次性编译所有的,也可以进入到目录下打开pro进行编译。** 2. **如果发现有些子项目没有加载请打开QWidgetDemo.pro仔细看里面的注释。** 3. **编译好的可执行文件在源码同级目录下的bin目录。** @@ -17,7 +17,7 @@ | 9 | styledemo | 高仿PS黑色+扁平白色+淡蓝色风格主题 | | 10 | navbutton | 导航按钮控件 | | 11 | videopanel | 视频监控画面分割demo | -| 12 | framelesswidget | 通用无边框拖动拉伸类 | +| 12 | framelesswidget | 跨平台无边框窗体 | | 13 | ipaddress | IP地址输入控件 | | 14 | bgdemo | 无边框背景透明窗体 | | 15 | dbpage | 通用数据库翻页查询 | @@ -49,7 +49,6 @@ | 41 | miniblink | miniblink示例 | | 42 | base64 | 图片文字base64互换 | | 43 | smoothcurve | 平滑曲线 | -| 44 | frameless | 跨平台无边框窗体 | ### 二、学习群 1. **Qt交流大会群 853086607(雨田哥)** diff --git a/base64/base64.cpp b/base64helper/base64helper.cpp similarity index 61% rename from base64/base64.cpp rename to base64helper/base64helper.cpp index 1e0b100..6093970 100644 --- a/base64/base64.cpp +++ b/base64helper/base64helper.cpp @@ -1,13 +1,13 @@ -#include "base64.h" +#include "base64helper.h" #include "qbuffer.h" #include "qdebug.h" -QString Base64::imageToBase64(const QImage &image) +QString Base64Helper::imageToBase64(const QImage &image) { return QString(imageToBase64x(image)); } -QByteArray Base64::imageToBase64x(const QImage &image) +QByteArray Base64Helper::imageToBase64x(const QImage &image) { //这个转换可能比较耗时建议在线程中执行 QByteArray data; @@ -17,12 +17,12 @@ QByteArray Base64::imageToBase64x(const QImage &image) return data; } -QImage Base64::base64ToImage(const QString &data) +QImage Base64Helper::base64ToImage(const QString &data) { return base64ToImagex(data.toUtf8()); } -QImage Base64::base64ToImagex(const QByteArray &data) +QImage Base64Helper::base64ToImagex(const QByteArray &data) { //这个转换可能比较耗时建议在线程中执行 QImage image; @@ -30,12 +30,12 @@ QImage Base64::base64ToImagex(const QByteArray &data) return image; } -QString Base64::textToBase64(const QString &text) +QString Base64Helper::textToBase64(const QString &text) { return QString(text.toLocal8Bit().toBase64()); } -QString Base64::base64ToText(const QString &text) +QString Base64Helper::base64ToText(const QString &text) { return QString(QByteArray::fromBase64(text.toLocal8Bit())); } diff --git a/core_common/base64.h b/base64helper/base64helper.h similarity index 86% rename from core_common/base64.h rename to base64helper/base64helper.h index 71b6954..e17cae6 100644 --- a/core_common/base64.h +++ b/base64helper/base64helper.h @@ -1,5 +1,5 @@ -#ifndef BASE64_H -#define BASE64_H +#ifndef BASE64HELPER_H +#define BASE64HELPER_H /** * base64编码转换类 作者:feiyangqingyun(QQ:517216493) 2016-12-16 @@ -14,9 +14,9 @@ #include #ifdef quc -class Q_DECL_EXPORT Base64 +class Q_DECL_EXPORT Base64Helper #else -class Base64 +class Base64Helper #endif { @@ -34,4 +34,4 @@ public: static QString base64ToText(const QString &text); }; -#endif // BASE64_H +#endif // BASE64HELPER_H diff --git a/base64/base64.pro b/base64helper/base64helper.pro similarity index 52% rename from base64/base64.pro rename to base64helper/base64helper.pro index 3b0f7fa..4a0a580 100644 --- a/base64/base64.pro +++ b/base64helper/base64helper.pro @@ -2,18 +2,18 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat -TARGET = base64 +TARGET = base64helper TEMPLATE = app DESTDIR = $$PWD/../bin CONFIG += warn_off SOURCES += main.cpp -SOURCES += frmbase64.cpp -SOURCES += base64.cpp +SOURCES += frmbase64helper.cpp +SOURCES += base64helper.cpp -HEADERS += frmbase64.h -HEADERS += base64.h +HEADERS += frmbase64helper.h +HEADERS += base64helper.h -FORMS += frmbase64.ui +FORMS += frmbase64helper.ui diff --git a/base64/frmbase64.cpp b/base64helper/frmbase64helper.cpp similarity index 69% rename from base64/frmbase64.cpp rename to base64helper/frmbase64helper.cpp index 164f522..9d021fd 100644 --- a/base64/frmbase64.cpp +++ b/base64helper/frmbase64helper.cpp @@ -1,23 +1,23 @@ #pragma execution_character_set("utf-8") -#include "frmbase64.h" -#include "ui_frmbase64.h" -#include "base64.h" +#include "frmbase64helper.h" +#include "ui_frmbase64helper.h" +#include "base64helper.h" #include "qfiledialog.h" #include "qelapsedtimer.h" #include "qdebug.h" -frmBase64::frmBase64(QWidget *parent) : QWidget(parent), ui(new Ui::frmBase64) +frmBase64Helper::frmBase64Helper(QWidget *parent) : QWidget(parent), ui(new Ui::frmBase64Helper) { ui->setupUi(this); } -frmBase64::~frmBase64() +frmBase64Helper::~frmBase64Helper() { delete ui; } -void frmBase64::on_btnOpen_clicked() +void frmBase64Helper::on_btnOpen_clicked() { QString fileName = QFileDialog::getOpenFileName(this, "选择文件", "", "图片(*.png *.bmp *.jpg)"); if (!fileName.isEmpty()) { @@ -28,7 +28,7 @@ void frmBase64::on_btnOpen_clicked() } } -void frmBase64::on_btnClear_clicked() +void frmBase64Helper::on_btnClear_clicked() { ui->txtFile->clear(); ui->txtText->clear(); @@ -36,7 +36,7 @@ void frmBase64::on_btnClear_clicked() ui->labImage->clear(); } -void frmBase64::on_btnImageToBase64_clicked() +void frmBase64Helper::on_btnImageToBase64_clicked() { //计时 QElapsedTimer time; @@ -44,7 +44,7 @@ void frmBase64::on_btnImageToBase64_clicked() QString fileName = ui->txtFile->text().trimmed(); if (!fileName.isEmpty()) { - ui->txtBase64->setText(Base64::imageToBase64(QImage(fileName))); + ui->txtBase64->setText(Base64Helper::imageToBase64(QImage(fileName))); } //统计用时 @@ -57,7 +57,7 @@ void frmBase64::on_btnImageToBase64_clicked() qDebug() << QString("用时 %1 毫秒").arg(strTime); } -void frmBase64::on_btnBase64ToImage_clicked() +void frmBase64Helper::on_btnBase64ToImage_clicked() { //计时 QElapsedTimer time; @@ -65,7 +65,7 @@ void frmBase64::on_btnBase64ToImage_clicked() QString text = ui->txtBase64->toPlainText().trimmed(); if (!text.isEmpty()) { - QPixmap pix = QPixmap::fromImage(Base64::base64ToImage(text)); + QPixmap pix = QPixmap::fromImage(Base64Helper::base64ToImage(text)); pix = pix.scaled(ui->labImage->size() - QSize(4, 4), Qt::KeepAspectRatio); ui->labImage->setPixmap(pix); } @@ -80,18 +80,18 @@ void frmBase64::on_btnBase64ToImage_clicked() qDebug() << QString("用时 %1 毫秒").arg(strTime); } -void frmBase64::on_btnTextToBase64_clicked() +void frmBase64Helper::on_btnTextToBase64_clicked() { QString text = ui->txtText->text().trimmed(); if (!text.isEmpty()) { - ui->txtBase64->setText(Base64::textToBase64(text)); + ui->txtBase64->setText(Base64Helper::textToBase64(text)); } } -void frmBase64::on_btnBase64ToText_clicked() +void frmBase64Helper::on_btnBase64ToText_clicked() { QString text = ui->txtBase64->toPlainText().trimmed(); if (!text.isEmpty()) { - ui->txtText->setText(Base64::base64ToText(text)); + ui->txtText->setText(Base64Helper::base64ToText(text)); } } diff --git a/base64/frmbase64.h b/base64helper/frmbase64helper.h similarity index 55% rename from base64/frmbase64.h rename to base64helper/frmbase64helper.h index cc76748..8e13ae4 100644 --- a/base64/frmbase64.h +++ b/base64helper/frmbase64helper.h @@ -1,22 +1,22 @@ -#ifndef FRMBASE64_H -#define FRMBASE64_H +#ifndef FRMBASE64HELPER_H +#define FRMBASE64HELPER_H #include namespace Ui { -class frmBase64; +class frmBase64Helper; } -class frmBase64 : public QWidget +class frmBase64Helper : public QWidget { Q_OBJECT public: - explicit frmBase64(QWidget *parent = 0); - ~frmBase64(); + explicit frmBase64Helper(QWidget *parent = 0); + ~frmBase64Helper(); private: - Ui::frmBase64 *ui; + Ui::frmBase64Helper *ui; private slots: void on_btnOpen_clicked(); @@ -27,4 +27,4 @@ private slots: void on_btnBase64ToText_clicked(); }; -#endif // FRMBASE64_H +#endif // FRMBASE64HELPER_H diff --git a/base64/frmbase64.ui b/base64helper/frmbase64helper.ui similarity index 93% rename from base64/frmbase64.ui rename to base64helper/frmbase64helper.ui index a19e3f6..a552879 100644 --- a/base64/frmbase64.ui +++ b/base64helper/frmbase64helper.ui @@ -1,7 +1,7 @@ - frmBase64 - + frmBase64Helper + 0 @@ -25,7 +25,7 @@ - 110 + 120 0 @@ -38,7 +38,7 @@ - 110 + 120 0 @@ -51,7 +51,7 @@ - 110 + 120 0 @@ -71,7 +71,7 @@ - 110 + 120 0 @@ -84,7 +84,7 @@ - 110 + 120 0 @@ -97,7 +97,7 @@ - 110 + 120 0 diff --git a/base64/main.cpp b/base64helper/main.cpp similarity index 93% rename from base64/main.cpp rename to base64helper/main.cpp index 5260c98..8a6fccb 100644 --- a/base64/main.cpp +++ b/base64helper/main.cpp @@ -1,6 +1,6 @@ #pragma execution_character_set("utf-8") -#include "frmbase64.h" +#include "frmbase64helper.h" #include #include @@ -23,7 +23,7 @@ int main(int argc, char *argv[]) QTextCodec::setCodecForLocale(codec); #endif - frmBase64 w; + frmBase64Helper w; w.setWindowTitle("图片文字base64编码互换"); w.show(); diff --git a/colorwidget/colorwidget.cpp b/colorwidget/colorwidget.cpp index 53e6fe7..0de3fc4 100644 --- a/colorwidget/colorwidget.cpp +++ b/colorwidget/colorwidget.cpp @@ -135,11 +135,11 @@ void ColorWidget::showColorValue() int y = QCursor::pos().y(); txtPoint->setText(tr("x:%1 y:%2").arg(x).arg(y)); -#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) - QPixmap pixmap = QPixmap::grabWindow(qApp->desktop()->winId(), x, y, 2, 2); -#else +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) QScreen *screen = qApp->primaryScreen(); QPixmap pixmap = screen->grabWindow(0, x, y, 2, 2); +#else + QPixmap pixmap = QPixmap::grabWindow(qApp->desktop()->winId(), x, y, 2, 2); #endif int red, green, blue; diff --git a/comtool/head.h b/comtool/head.h index 8b707e9..01a297f 100644 --- a/comtool/head.h +++ b/comtool/head.h @@ -2,7 +2,7 @@ #include #include -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) #include #endif diff --git a/core_common/appinit.cpp b/core_common/appinit.cpp deleted file mode 100644 index ab7f9df..0000000 --- a/core_common/appinit.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "appinit.h" -#include "qmutex.h" -#include "qapplication.h" -#include "qevent.h" -#include "qwidget.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_common/appinit.h b/core_common/appinit.h deleted file mode 100644 index 467ad84..0000000 --- a/core_common/appinit.h +++ /dev/null @@ -1,23 +0,0 @@ -#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_common/base64.cpp b/core_common/base64.cpp deleted file mode 100644 index 1e0b100..0000000 --- a/core_common/base64.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "base64.h" -#include "qbuffer.h" -#include "qdebug.h" - -QString Base64::imageToBase64(const QImage &image) -{ - return QString(imageToBase64x(image)); -} - -QByteArray Base64::imageToBase64x(const QImage &image) -{ - //这个转换可能比较耗时建议在线程中执行 - QByteArray data; - QBuffer buffer(&data); - image.save(&buffer, "JPG"); - data = data.toBase64(); - return data; -} - -QImage Base64::base64ToImage(const QString &data) -{ - return base64ToImagex(data.toUtf8()); -} - -QImage Base64::base64ToImagex(const QByteArray &data) -{ - //这个转换可能比较耗时建议在线程中执行 - QImage image; - image.loadFromData(QByteArray::fromBase64(data)); - return image; -} - -QString Base64::textToBase64(const QString &text) -{ - return QString(text.toLocal8Bit().toBase64()); -} - -QString Base64::base64ToText(const QString &text) -{ - return QString(QByteArray::fromBase64(text.toLocal8Bit())); -} diff --git a/core_common/common.qrc b/core_common/common.qrc deleted file mode 100644 index 827aaf3..0000000 --- a/core_common/common.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - image/fontawesome-webfont.ttf - - diff --git a/core_common/core_common.pri b/core_common/core_common.pri deleted file mode 100644 index b6f95a9..0000000 --- a/core_common/core_common.pri +++ /dev/null @@ -1,36 +0,0 @@ -#指定编译产生的文件分门别类放到对应目录 -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 - -#引入全志H3芯片依赖 -include ($$PWD/h3.pri) - -HEADERS += \ - $$PWD/appinit.h \ - $$PWD/base64.h \ - $$PWD/iconhelper.h \ - $$PWD/quihelper.h - -SOURCES += \ - $$PWD/appinit.cpp \ - $$PWD/base64.cpp \ - $$PWD/iconhelper.cpp \ - $$PWD/quihelper.cpp - -RESOURCES += \ - $$PWD/common.qrc diff --git a/core_common/h3.pri b/core_common/h3.pri deleted file mode 100644 index d976a3e..0000000 --- a/core_common/h3.pri +++ /dev/null @@ -1,6 +0,0 @@ -unix:!macx { -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_common/iconhelper.cpp b/core_common/iconhelper.cpp deleted file mode 100644 index e9df4ff..0000000 --- a/core_common/iconhelper.cpp +++ /dev/null @@ -1,351 +0,0 @@ -#include "iconhelper.h" - -IconHelper *IconHelper::iconFontAliBaBa = 0; -IconHelper *IconHelper::iconFontAwesome = 0; -void IconHelper::initFont() -{ - static bool isInit = false; - if (!isInit) { - isInit = true; - if (iconFontAliBaBa == 0) { - iconFontAliBaBa = new IconHelper(":/image/iconfont.ttf", "iconfont"); - } - if (iconFontAwesome == 0) { - iconFontAwesome = new IconHelper(":/image/fontawesome-webfont.ttf", "FontAwesome"); - } - } -} - -void IconHelper::setIcon(QLabel *lab, int icon, quint32 size) -{ - initFont(); - - //自动根据不同的字体的值选择对应的类,fontawesome 0xf开头 iconfont 0xe开头 - if (icon > 0xe000 && icon < 0xf000) { - iconFontAliBaBa->setIcon1(lab, icon, size); - } else if (icon > 0xf000) { - iconFontAwesome->setIcon1(lab, icon, size); - } -} - -void IconHelper::setIcon(QAbstractButton *btn, int icon, quint32 size) -{ - initFont(); - - //自动根据不同的字体的值选择对应的类,fontawesome 0xf开头 iconfont 0xe开头 - if (icon > 0xe000 && icon < 0xf000) { - iconFontAliBaBa->setIcon1(btn, icon, size); - } else if (icon > 0xf000) { - iconFontAwesome->setIcon1(btn, icon, size); - } -} - -void IconHelper::setPixmap(QAbstractButton *btn, const QColor &color, int icon, quint32 size, - quint32 width, quint32 height, int flags) -{ - initFont(); - - //自动根据不同的字体的值选择对应的类,fontawesome 0xf开头 iconfont 0xe开头 - if (icon > 0xe000 && icon < 0xf000) { - iconFontAliBaBa->setPixmap1(btn, color, icon, size, width, height, flags); - } else if (icon > 0xf000) { - iconFontAwesome->setPixmap1(btn, color, icon, size, width, height, flags); - } -} - -QPixmap IconHelper::getPixmap(const QColor &color, int icon, quint32 size, - quint32 width, quint32 height, int flags) -{ - initFont(); - - //自动根据不同的字体的值选择对应的类,fontawesome 0xf开头 iconfont 0xe开头 - QPixmap pix; - if (icon > 0xe000 && icon < 0xf000) { - pix = iconFontAliBaBa->getPixmap1(color, icon, size, width, height, flags); - } else if (icon > 0xf000) { - pix = iconFontAwesome->getPixmap1(color, icon, size, width, height, flags); - } - return pix; -} - -void IconHelper::setStyle(QWidget *widget, QList btns, - QList icons, const IconHelper::StyleColor &styleColor) -{ - initFont(); - - //自动根据不同的字体的值选择对应的类,fontawesome 0xf开头 iconfont 0xe开头 - int icon = icons.first(); - if (icon > 0xe000 && icon < 0xf000) { - iconFontAliBaBa->setStyle1(widget, btns, icons, styleColor); - } else if (icon > 0xf000) { - iconFontAwesome->setStyle1(widget, btns, icons, styleColor); - } -} - -void IconHelper::setStyle(QWidget *widget, QList btns, - QList icons, const IconHelper::StyleColor &styleColor) -{ - initFont(); - - //自动根据不同的字体的值选择对应的类,fontawesome 0xf开头 iconfont 0xe开头 - int icon = icons.first(); - if (icon > 0xe000 && icon < 0xf000) { - iconFontAliBaBa->setStyle1(widget, btns, icons, styleColor); - } else if (icon > 0xf000) { - iconFontAwesome->setStyle1(widget, btns, icons, styleColor); - } -} - -void IconHelper::setStyle(QWidget *widget, QList btns, - QList icons, const IconHelper::StyleColor &styleColor) -{ - initFont(); - - //自动根据不同的字体的值选择对应的类,fontawesome 0xf开头 iconfont 0xe开头 - int icon = icons.first(); - if (icon > 0xe000 && icon < 0xf000) { - iconFontAliBaBa->setStyle1(widget, btns, icons, styleColor); - } else if (icon > 0xf000) { - iconFontAwesome->setStyle1(widget, btns, icons, styleColor); - } -} - -IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject *parent) : QObject(parent) -{ - //判断图形字体是否存在,不存在则加入 - QFontDatabase fontDb; - if (!fontDb.families().contains(fontName)) { - 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))); - } -} - -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 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); - } - - //如果图标是左侧显示则需要让没有选中的按钮左侧也有加深的边框,颜色为背景颜色 - QStringList qss; - if (styleColor.textBesideIcon) { - 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); - - //设置样式表 - 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_common/iconhelper.h b/core_common/iconhelper.h deleted file mode 100644 index ad5ea9a..0000000 --- a/core_common/iconhelper.h +++ /dev/null @@ -1,148 +0,0 @@ -#ifndef ICONHELPER_H -#define ICONHELPER_H - -#include -#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) -#include -#endif - -/** - * 超级图形字体类 作者:feiyangqingyun(QQ:517216493) 2016-11-23 - * 1. 可传入多种图形字体文件。 - * 2. 可设置 QLabel+QAbstractButton 图形字体。 - * 3. 可设置按钮图标。 - * 4. 可获取指定尺寸的图形字体图片。 - * 5. 超级导航栏样式设置,带图标和效果切换、悬停颜色、按下颜色、选中颜色。 - */ - -#ifdef quc -class Q_DECL_EXPORT IconHelper : public QObject -#else -class IconHelper : public QObject -#endif - -{ - Q_OBJECT - -public: - //样式颜色结构体 - struct StyleColor { - QString position; //位置 left right top bottom - bool textBesideIcon; //文字在图标左侧 - - 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"; - textBesideIcon = false; - - 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 IconHelper *iconFontAliBaBa; - //FontAwesome图形字体类 - static IconHelper *iconFontAwesome; - //初始化图形字体 - static void initFont(); - - 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: - //设置图形字体到标签 - 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_common/image/fontawesome-webfont.ttf b/core_common/image/fontawesome-webfont.ttf deleted file mode 100644 index 35acda2..0000000 Binary files a/core_common/image/fontawesome-webfont.ttf and /dev/null differ diff --git a/core_common/quihelper.cpp b/core_common/quihelper.cpp deleted file mode 100644 index f0f5156..0000000 --- a/core_common/quihelper.cpp +++ /dev/null @@ -1,372 +0,0 @@ -#include "quihelper.h" - -int QUIHelper::getScreenIndex() -{ - //需要对多个屏幕进行处理 - int screenIndex = 0; -#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) - int screenCount = qApp->screens().count(); -#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; -} - -int QUIHelper::deskWidth() -{ - return getScreenRect().width(); -} - -int QUIHelper::deskHeight() -{ - return getScreenRect().height(); -} - -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); -} - -QString QUIHelper::appName() -{ - //没有必要每次都获取,只有当变量为空时才去获取一次 - static QString name; - if (name.isEmpty()) { - name = qApp->applicationFilePath(); - //下面的方法主要为了过滤安卓的路径 lib程序名_armeabi-v7a - QStringList list = name.split("/"); - name = list.at(list.count() - 1).split(".").at(0); - } - - return name; -} - -QString QUIHelper::appPath() -{ -#ifdef Q_OS_ANDROID - //return QString("/sdcard/Android/%1").arg(appName()); - return QString("/storage/emulated/0/%1").arg(appName()); -#else - return qApp->applicationDirPath(); -#endif -} - -QString QUIHelper::getUuid() -{ - QString uuid = QUuid::createUuid().toString(); - uuid.replace("{", ""); - uuid.replace("}", ""); - return uuid; -} - -void QUIHelper::initRand() -{ - //初始化随机数种子 - QTime t = QTime::currentTime(); - srand(t.msec() + t.second() * 1000); -} - -void QUIHelper::newDir(const QString &dirName) -{ - QString strDir = dirName; - - //如果路径中包含斜杠字符则说明是绝对路径 - //linux系统路径字符带有 / windows系统 路径字符带有 :/ - if (!strDir.startsWith("/") && !strDir.contains(":/")) { - strDir = QString("%1/%2").arg(QUIHelper::appPath()).arg(strDir); - } - - QDir dir(strDir); - if (!dir.exists()) { - dir.mkpath(strDir); - } -} - -void QUIHelper::sleep(int msec) -{ - if (msec > 0) { -#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) - QTime endTime = QTime::currentTime().addMSecs(msec); - while (QTime::currentTime() < endTime) { - QCoreApplication::processEvents(QEventLoop::AllEvents, 100); - } -#else - QThread::msleep(msec); -#endif - } -} - -void QUIHelper::setStyle() -{ - //打印下所有内置风格的名字 - qDebug() << "Qt内置的样式" << QStyleFactory::keys(); -#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) - qApp->setStyle(QStyleFactory::create("Fusion")); -#else - qApp->setStyle(QStyleFactory::create("Cleanlooks")); -#endif - //qApp->setPalette(QPalette("#FFFFFF")); -} - -void QUIHelper::setFont(int fontSize) -{ - QFont font; - font.setFamily("MicroSoft Yahei"); -#ifdef Q_OS_ANDROID - font.setPixelSize(15); -#elif __arm__ - font.setPixelSize(25); -#else - font.setPixelSize(fontSize); -#endif - -#ifndef rk3399 - qApp->setFont(font); -#endif -} - -void QUIHelper::setCode(bool utf8) -{ -#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) -#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); -#else - //如果想要控制台打印信息中文正常就注释掉这个设置 - if (utf8) { - QTextCodec *codec = QTextCodec::codecForName("utf-8"); - QTextCodec::setCodecForLocale(codec); - } -#endif -} - -void QUIHelper::setTranslator(const QString &qmFile) -{ - QTranslator *translator = new QTranslator(qApp); - translator->load(qmFile); - qApp->installTranslator(translator); -} - -int QUIHelper::showMessageBox(const QString &info, int type, int closeSec, bool exec) -{ - int result = 0; - if (type == 0) { - showMessageBoxInfo(info, closeSec, exec); - } else if (type == 1) { - showMessageBoxError(info, closeSec, exec); - } else if (type == 2) { - result = showMessageBoxQuestion(info); - } - - return result; -} - -void QUIHelper::showMessageBoxInfo(const QString &info, int closeSec, bool exec) -{ - QMessageBox box(QMessageBox::Information, "提示", info); - box.setStandardButtons(QMessageBox::Yes); - box.setButtonText(QMessageBox::Yes, QString("确 定")); - box.exec(); - //QMessageBox::information(0, "提示", info, QMessageBox::Yes); -} - -void QUIHelper::showMessageBoxError(const QString &info, int closeSec, bool exec) -{ - QMessageBox box(QMessageBox::Critical, "错误", info); - box.setStandardButtons(QMessageBox::Yes); - box.setButtonText(QMessageBox::Yes, QString("确 定")); - box.exec(); - //QMessageBox::critical(0, "错误", info, QMessageBox::Yes); -} - -int QUIHelper::showMessageBoxQuestion(const QString &info) -{ - QMessageBox box(QMessageBox::Question, "询问", info); - 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); -} - -QString QUIHelper::getXorEncryptDecrypt(const QString &value, char key) -{ - //矫正范围外的数据 - if (key < 0 || key >= 127) { - key = 127; - } - - QString result = value; - int count = result.count(); - for (int i = 0; i < count; i++) { - result[i] = QChar(result.at(i).toLatin1() ^ key); - } - return result; -} - -uchar QUIHelper::getOrCode(const QByteArray &data) -{ - int len = data.length(); - uchar result = 0; - for (int i = 0; i < len; i++) { - result ^= data.at(i); - } - - return result; -} - -uchar QUIHelper::getCheckCode(const QByteArray &data) -{ - int len = data.length(); - uchar temp = 0; - for (uchar 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) -{ - //取消自动换行 - 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 (fileName.isEmpty()) { - 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.count() == 2) { - if (list.at(1) == "") { - qDebug() << "ini node no value" << list.at(0); - ok = false; - break; - } - } - } - - if (!ok) { - return false; - } - } else { - return false; - } - - return true; -} diff --git a/core_common/quihelper.h b/core_common/quihelper.h deleted file mode 100644 index 1ce6711..0000000 --- a/core_common/quihelper.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef QUIHELPER2_H -#define QUIHELPER2_H - -#include "head.h" - -class QUIHelper -{ -public: - //获取当前鼠标所在屏幕索引+尺寸 - static int getScreenIndex(); - static QRect getScreenRect(bool available = true); - - //获取桌面宽度高度+居中显示 - static int deskWidth(); - static int deskHeight(); - - //居中显示窗体 - //定义标志位指定是以桌面为参照还是主程序界面为参照 - static QWidget *centerBaseForm; - static void setFormInCenter(QWidget *form); - - //程序文件名称+当前所在路径 - static QString appName(); - static QString appPath(); - - //获取uuid+初始化随机数种子+新建目录+延时 - static QString getUuid(); - static void initRand(); - static void newDir(const QString &dirName); - static void sleep(int msec); - - //设置样式+字体+编码+居中+翻译 - static void setStyle(); - static void setFont(int fontSize = 12); - static void setCode(bool utf8 = true); - static void setTranslator(const QString &qmFile = ":/image/qt_zh_CN.qm"); - - //弹出框 - static int showMessageBox(const QString &info, int type = 0, int closeSec = 0, bool exec = false); - //弹出消息框 - static void showMessageBoxInfo(const QString &info, int closeSec = 0, bool exec = false); - //弹出错误框 - static void showMessageBoxError(const QString &info, int closeSec = 0, bool exec = false); - //弹出询问框 - static int showMessageBoxQuestion(const QString &info); - - //异或加密-只支持字符,如果是中文需要将其转换base64编码 - static QString getXorEncryptDecrypt(const QString &value, char key); - //异或校验 - static uchar getOrCode(const QByteArray &data); - //计算校验码 - static uchar getCheckCode(const QByteArray &data); - - //初始化表格 - static void initTableView(QTableView *tableView, int rowHeight = 25, - bool headVisible = false, bool edit = false, - bool stretchLast = true); - //打开文件带提示框 - static void openFile(const QString &fileName, const QString &msg); - - //检查ini配置文件 - static bool checkIniFile(const QString &iniFile); -}; - -#endif // QUIHELPER2_H diff --git a/core_qui/base64.h b/core_qui/base64.h deleted file mode 100644 index 71b6954..0000000 --- a/core_qui/base64.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef BASE64_H -#define BASE64_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 Base64 -#else -class Base64 -#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 // BASE64_H diff --git a/core_qui/base64.cpp b/core_qui/base64helper.cpp similarity index 61% rename from core_qui/base64.cpp rename to core_qui/base64helper.cpp index 1e0b100..6093970 100644 --- a/core_qui/base64.cpp +++ b/core_qui/base64helper.cpp @@ -1,13 +1,13 @@ -#include "base64.h" +#include "base64helper.h" #include "qbuffer.h" #include "qdebug.h" -QString Base64::imageToBase64(const QImage &image) +QString Base64Helper::imageToBase64(const QImage &image) { return QString(imageToBase64x(image)); } -QByteArray Base64::imageToBase64x(const QImage &image) +QByteArray Base64Helper::imageToBase64x(const QImage &image) { //这个转换可能比较耗时建议在线程中执行 QByteArray data; @@ -17,12 +17,12 @@ QByteArray Base64::imageToBase64x(const QImage &image) return data; } -QImage Base64::base64ToImage(const QString &data) +QImage Base64Helper::base64ToImage(const QString &data) { return base64ToImagex(data.toUtf8()); } -QImage Base64::base64ToImagex(const QByteArray &data) +QImage Base64Helper::base64ToImagex(const QByteArray &data) { //这个转换可能比较耗时建议在线程中执行 QImage image; @@ -30,12 +30,12 @@ QImage Base64::base64ToImagex(const QByteArray &data) return image; } -QString Base64::textToBase64(const QString &text) +QString Base64Helper::textToBase64(const QString &text) { return QString(text.toLocal8Bit().toBase64()); } -QString Base64::base64ToText(const QString &text) +QString Base64Helper::base64ToText(const QString &text) { return QString(QByteArray::fromBase64(text.toLocal8Bit())); } diff --git a/base64/base64.h b/core_qui/base64helper.h similarity index 86% rename from base64/base64.h rename to core_qui/base64helper.h index 71b6954..e17cae6 100644 --- a/base64/base64.h +++ b/core_qui/base64helper.h @@ -1,5 +1,5 @@ -#ifndef BASE64_H -#define BASE64_H +#ifndef BASE64HELPER_H +#define BASE64HELPER_H /** * base64编码转换类 作者:feiyangqingyun(QQ:517216493) 2016-12-16 @@ -14,9 +14,9 @@ #include #ifdef quc -class Q_DECL_EXPORT Base64 +class Q_DECL_EXPORT Base64Helper #else -class Base64 +class Base64Helper #endif { @@ -34,4 +34,4 @@ public: static QString base64ToText(const QString &text); }; -#endif // BASE64_H +#endif // BASE64HELPER_H diff --git a/core_qui/core_qui.pri b/core_qui/core_qui.pri index d554096..bcae2ad 100644 --- a/core_qui/core_qui.pri +++ b/core_qui/core_qui.pri @@ -21,7 +21,7 @@ CONFIG += resources_big include ($$PWD/h3.pri) HEADERS += \ - $$PWD/base64.h \ + $$PWD/base64helper.h \ $$PWD/iconhelper.h \ $$PWD/quiconfig.h \ $$PWD/quidateselect.h \ @@ -34,7 +34,7 @@ HEADERS += \ $$PWD/quiwidget.h SOURCES += \ - $$PWD/base64.cpp \ + $$PWD/base64helper.cpp \ $$PWD/iconhelper.cpp \ $$PWD/quiconfig.cpp \ $$PWD/quidateselect.cpp \ diff --git a/core_qui/quihead.h b/core_qui/quihead.h index e63a1a6..3252eee 100644 --- a/core_qui/quihead.h +++ b/core_qui/quihead.h @@ -55,7 +55,6 @@ #include "quihelper.h" #include "quiconfig.h" #include "quistyle.h" -#include "quihead.h" #include "quimessagebox.h" #include "quitipbox.h" #include "quidateselect.h" diff --git a/core_qui/quihelper.cpp b/core_qui/quihelper.cpp index 0c8cc7b..aad78be 100644 --- a/core_qui/quihelper.cpp +++ b/core_qui/quihelper.cpp @@ -134,21 +134,29 @@ void QUIHelper::newDir(const QString &dirName) void QUIHelper::sleep(int msec) { - if (msec > 0) { -#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) - QTime endTime = QTime::currentTime().addMSecs(msec); - while (QTime::currentTime() < endTime) { - QCoreApplication::processEvents(QEventLoop::AllEvents, 100); - } -#else - QThread::msleep(msec); -#endif + 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::setCode(bool utf8) { -#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) +#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 @@ -157,12 +165,6 @@ void QUIHelper::setCode(bool utf8) QTextCodec::setCodecForLocale(codec); QTextCodec::setCodecForCStrings(codec); QTextCodec::setCodecForTr(codec); -#else - //如果想要控制台打印信息中文正常就注释掉这个设置 - if (utf8) { - QTextCodec *codec = QTextCodec::codecForName("utf-8"); - QTextCodec::setCodecForLocale(codec); - } #endif } @@ -378,6 +380,75 @@ void QUIHelper::runWithSystem(const QString &strName, const QString &strPath, bo #endif } +QList QUIHelper::colors = QList(); +QList QUIHelper::getColorList() +{ + //备用颜色集合 可以自行添加 + if (colors.count() == 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.count(), true); + return colors.at(index); +} + +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; +} + QString QUIHelper::getIP(const QString &url) { //取出IP地址 diff --git a/core_qui/quihelper.h b/core_qui/quihelper.h index d8b46c1..5e24f88 100644 --- a/core_qui/quihelper.h +++ b/core_qui/quihelper.h @@ -65,6 +65,16 @@ public: //设置开机自启动 static void runWithSystem(const QString &strName, const QString &strPath, bool autoRun = true); + //获取内置颜色集合 + static QList colors; + static QList getColorList(); + static QStringList getColorNames(); + //随机获取颜色集合中的颜色 + static QColor getRandColor(); + + //获取随机数,指定最小值和最大值 + static double getRandValue(int min, int max, bool contansMin = false, bool contansMax = false); + //从字符串获取IP地址 static QString getIP(const QString &url); //判断是否是IP地址 diff --git a/dbpage/dbpage.h b/dbpage/dbpage.h index d9c4130..25b9da3 100644 --- a/dbpage/dbpage.h +++ b/dbpage/dbpage.h @@ -16,7 +16,7 @@ #include #include -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) #include #endif diff --git a/ffmpegdemo/ffmpeg/ffmpeg.h b/ffmpegdemo/ffmpeg/ffmpeg.h index c0b192b..e79c028 100644 --- a/ffmpegdemo/ffmpeg/ffmpeg.h +++ b/ffmpegdemo/ffmpeg/ffmpeg.h @@ -2,7 +2,7 @@ #define FFMPEG_H #include -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) #include #endif diff --git a/ffmpegdemo/ffmpeg/ffmpeg3/include/libavutil/base64.h b/ffmpegdemo/ffmpeg/ffmpeg3/include/libavutil/base64.h index 71b6954..2954c12 100644 --- a/ffmpegdemo/ffmpeg/ffmpeg3/include/libavutil/base64.h +++ b/ffmpegdemo/ffmpeg/ffmpeg3/include/libavutil/base64.h @@ -1,37 +1,72 @@ -#ifndef BASE64_H -#define BASE64_H - -/** - * base64编码转换类 作者:feiyangqingyun(QQ:517216493) 2016-12-16 - * 1. 图片转base64字符串。 - * 2. base64字符串转图片。 - * 3. 字符转base64字符串。 - * 4. base64字符串转字符。 - * 5. 后期增加数据压缩。 - * 6. Qt6对base64编码转换进行了重写效率提升至少200%。 +/* + * Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include +#ifndef AVUTIL_BASE64_H +#define AVUTIL_BASE64_H -#ifdef quc -class Q_DECL_EXPORT Base64 -#else -class Base64 -#endif +#include -{ -public: - //图片转base64字符串 - static QString imageToBase64(const QImage &image); - static QByteArray imageToBase64x(const QImage &image); +/** + * @defgroup lavu_base64 Base64 + * @ingroup lavu_crypto + * @{ + */ - //base64字符串转图片 - static QImage base64ToImage(const QString &data); - static QImage base64ToImagex(const QByteArray &data); +/** + * Decode a base64-encoded string. + * + * @param out buffer for decoded data + * @param in null-terminated input string + * @param out_size size in bytes of the out buffer, must be at + * least 3/4 of the length of in, that is AV_BASE64_DECODE_SIZE(strlen(in)) + * @return number of bytes written, or a negative value in case of + * invalid input + */ +int av_base64_decode(uint8_t *out, const char *in, int out_size); - //字符串与base64互转 - static QString textToBase64(const QString &text); - static QString base64ToText(const QString &text); -}; +/** + * Calculate the output size in bytes needed to decode a base64 string + * with length x to a data buffer. + */ +#define AV_BASE64_DECODE_SIZE(x) ((x) * 3LL / 4) -#endif // BASE64_H +/** + * Encode data to base64 and null-terminate. + * + * @param out buffer for encoded data + * @param out_size size in bytes of the out buffer (including the + * null terminator), must be at least AV_BASE64_SIZE(in_size) + * @param in input buffer containing the data to encode + * @param in_size size in bytes of the in buffer + * @return out or NULL in case of error + */ +char *av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size); + +/** + * Calculate the output size needed to base64-encode x bytes to a + * null-terminated string. + */ +#define AV_BASE64_SIZE(x) (((x)+2) / 3 * 4 + 1) + + /** + * @} + */ + +#endif /* AVUTIL_BASE64_H */ diff --git a/ffmpegdemo/ffmpeg/ffmpeg3/include64/libavutil/base64.h b/ffmpegdemo/ffmpeg/ffmpeg3/include64/libavutil/base64.h index 71b6954..2954c12 100644 --- a/ffmpegdemo/ffmpeg/ffmpeg3/include64/libavutil/base64.h +++ b/ffmpegdemo/ffmpeg/ffmpeg3/include64/libavutil/base64.h @@ -1,37 +1,72 @@ -#ifndef BASE64_H -#define BASE64_H - -/** - * base64编码转换类 作者:feiyangqingyun(QQ:517216493) 2016-12-16 - * 1. 图片转base64字符串。 - * 2. base64字符串转图片。 - * 3. 字符转base64字符串。 - * 4. base64字符串转字符。 - * 5. 后期增加数据压缩。 - * 6. Qt6对base64编码转换进行了重写效率提升至少200%。 +/* + * Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include +#ifndef AVUTIL_BASE64_H +#define AVUTIL_BASE64_H -#ifdef quc -class Q_DECL_EXPORT Base64 -#else -class Base64 -#endif +#include -{ -public: - //图片转base64字符串 - static QString imageToBase64(const QImage &image); - static QByteArray imageToBase64x(const QImage &image); +/** + * @defgroup lavu_base64 Base64 + * @ingroup lavu_crypto + * @{ + */ - //base64字符串转图片 - static QImage base64ToImage(const QString &data); - static QImage base64ToImagex(const QByteArray &data); +/** + * Decode a base64-encoded string. + * + * @param out buffer for decoded data + * @param in null-terminated input string + * @param out_size size in bytes of the out buffer, must be at + * least 3/4 of the length of in, that is AV_BASE64_DECODE_SIZE(strlen(in)) + * @return number of bytes written, or a negative value in case of + * invalid input + */ +int av_base64_decode(uint8_t *out, const char *in, int out_size); - //字符串与base64互转 - static QString textToBase64(const QString &text); - static QString base64ToText(const QString &text); -}; +/** + * Calculate the output size in bytes needed to decode a base64 string + * with length x to a data buffer. + */ +#define AV_BASE64_DECODE_SIZE(x) ((x) * 3LL / 4) -#endif // BASE64_H +/** + * Encode data to base64 and null-terminate. + * + * @param out buffer for encoded data + * @param out_size size in bytes of the out buffer (including the + * null terminator), must be at least AV_BASE64_SIZE(in_size) + * @param in input buffer containing the data to encode + * @param in_size size in bytes of the in buffer + * @return out or NULL in case of error + */ +char *av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size); + +/** + * Calculate the output size needed to base64-encode x bytes to a + * null-terminated string. + */ +#define AV_BASE64_SIZE(x) (((x)+2) / 3 * 4 + 1) + + /** + * @} + */ + +#endif /* AVUTIL_BASE64_H */ diff --git a/ffmpegdemo/ffmpeg/ffmpeg4/include/libavutil/base64.h b/ffmpegdemo/ffmpeg/ffmpeg4/include/libavutil/base64.h index 71b6954..2954c12 100644 --- a/ffmpegdemo/ffmpeg/ffmpeg4/include/libavutil/base64.h +++ b/ffmpegdemo/ffmpeg/ffmpeg4/include/libavutil/base64.h @@ -1,37 +1,72 @@ -#ifndef BASE64_H -#define BASE64_H - -/** - * base64编码转换类 作者:feiyangqingyun(QQ:517216493) 2016-12-16 - * 1. 图片转base64字符串。 - * 2. base64字符串转图片。 - * 3. 字符转base64字符串。 - * 4. base64字符串转字符。 - * 5. 后期增加数据压缩。 - * 6. Qt6对base64编码转换进行了重写效率提升至少200%。 +/* + * Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include +#ifndef AVUTIL_BASE64_H +#define AVUTIL_BASE64_H -#ifdef quc -class Q_DECL_EXPORT Base64 -#else -class Base64 -#endif +#include -{ -public: - //图片转base64字符串 - static QString imageToBase64(const QImage &image); - static QByteArray imageToBase64x(const QImage &image); +/** + * @defgroup lavu_base64 Base64 + * @ingroup lavu_crypto + * @{ + */ - //base64字符串转图片 - static QImage base64ToImage(const QString &data); - static QImage base64ToImagex(const QByteArray &data); +/** + * Decode a base64-encoded string. + * + * @param out buffer for decoded data + * @param in null-terminated input string + * @param out_size size in bytes of the out buffer, must be at + * least 3/4 of the length of in, that is AV_BASE64_DECODE_SIZE(strlen(in)) + * @return number of bytes written, or a negative value in case of + * invalid input + */ +int av_base64_decode(uint8_t *out, const char *in, int out_size); - //字符串与base64互转 - static QString textToBase64(const QString &text); - static QString base64ToText(const QString &text); -}; +/** + * Calculate the output size in bytes needed to decode a base64 string + * with length x to a data buffer. + */ +#define AV_BASE64_DECODE_SIZE(x) ((x) * 3LL / 4) -#endif // BASE64_H +/** + * Encode data to base64 and null-terminate. + * + * @param out buffer for encoded data + * @param out_size size in bytes of the out buffer (including the + * null terminator), must be at least AV_BASE64_SIZE(in_size) + * @param in input buffer containing the data to encode + * @param in_size size in bytes of the in buffer + * @return out or NULL in case of error + */ +char *av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size); + +/** + * Calculate the output size needed to base64-encode x bytes to a + * null-terminated string. + */ +#define AV_BASE64_SIZE(x) (((x)+2) / 3 * 4 + 1) + + /** + * @} + */ + +#endif /* AVUTIL_BASE64_H */ diff --git a/ffmpegdemo/ffmpeg/ffmpeg4/include64/libavutil/base64.h b/ffmpegdemo/ffmpeg/ffmpeg4/include64/libavutil/base64.h index 71b6954..2954c12 100644 --- a/ffmpegdemo/ffmpeg/ffmpeg4/include64/libavutil/base64.h +++ b/ffmpegdemo/ffmpeg/ffmpeg4/include64/libavutil/base64.h @@ -1,37 +1,72 @@ -#ifndef BASE64_H -#define BASE64_H - -/** - * base64编码转换类 作者:feiyangqingyun(QQ:517216493) 2016-12-16 - * 1. 图片转base64字符串。 - * 2. base64字符串转图片。 - * 3. 字符转base64字符串。 - * 4. base64字符串转字符。 - * 5. 后期增加数据压缩。 - * 6. Qt6对base64编码转换进行了重写效率提升至少200%。 +/* + * Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com) + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include +#ifndef AVUTIL_BASE64_H +#define AVUTIL_BASE64_H -#ifdef quc -class Q_DECL_EXPORT Base64 -#else -class Base64 -#endif +#include -{ -public: - //图片转base64字符串 - static QString imageToBase64(const QImage &image); - static QByteArray imageToBase64x(const QImage &image); +/** + * @defgroup lavu_base64 Base64 + * @ingroup lavu_crypto + * @{ + */ - //base64字符串转图片 - static QImage base64ToImage(const QString &data); - static QImage base64ToImagex(const QByteArray &data); +/** + * Decode a base64-encoded string. + * + * @param out buffer for decoded data + * @param in null-terminated input string + * @param out_size size in bytes of the out buffer, must be at + * least 3/4 of the length of in, that is AV_BASE64_DECODE_SIZE(strlen(in)) + * @return number of bytes written, or a negative value in case of + * invalid input + */ +int av_base64_decode(uint8_t *out, const char *in, int out_size); - //字符串与base64互转 - static QString textToBase64(const QString &text); - static QString base64ToText(const QString &text); -}; +/** + * Calculate the output size in bytes needed to decode a base64 string + * with length x to a data buffer. + */ +#define AV_BASE64_DECODE_SIZE(x) ((x) * 3LL / 4) -#endif // BASE64_H +/** + * Encode data to base64 and null-terminate. + * + * @param out buffer for encoded data + * @param out_size size in bytes of the out buffer (including the + * null terminator), must be at least AV_BASE64_SIZE(in_size) + * @param in input buffer containing the data to encode + * @param in_size size in bytes of the in buffer + * @return out or NULL in case of error + */ +char *av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size); + +/** + * Calculate the output size needed to base64-encode x bytes to a + * null-terminated string. + */ +#define AV_BASE64_SIZE(x) (((x)+2) / 3 * 4 + 1) + + /** + * @} + */ + +#endif /* AVUTIL_BASE64_H */ diff --git a/frameless/frameless.pro b/frameless/frameless.pro deleted file mode 100644 index 8679857..0000000 --- a/frameless/frameless.pro +++ /dev/null @@ -1,21 +0,0 @@ -QT += core gui -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat - -TARGET = frameless -TEMPLATE = app -DESTDIR = $$PWD/../bin - -CONFIG += warn_off -HEADERS += head.h -SOURCES += main.cpp - -INCLUDEPATH += $$PWD -INCLUDEPATH += $$PWD/form -include ($$PWD/form/form.pri) - -INCLUDEPATH += $$PWD/../core_frameless -include ($$PWD/../core_frameless/core_frameless.pri) - -INCLUDEPATH += $$PWD/../core_common -include ($$PWD/../core_common/core_common.pri) diff --git a/frameless/frameless.pro.user b/frameless/frameless.pro.user deleted file mode 100644 index b82f2a5..0000000 --- a/frameless/frameless.pro.user +++ /dev/null @@ -1,746 +0,0 @@ - - - - - - EnvironmentId - {849db446-6f90-46aa-afcf-9e726de1fb02} - - - ProjectExplorer.Project.ActiveTarget - 1 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 0 - true - true - true - *.md, *.MD, Makefile - false - true - - - - ProjectExplorer.Project.PluginSettings - - - true - true - true - true - true - - - 0 - true - - - - ProjectExplorer.Project.Target.0 - - Desktop - desk5.7.0 - desk5.7.0 - {30975ac4-3883-489b-ac7a-132064e40ec0} - 0 - 0 - 0 - - 0 - I:\gitee\QWidgetDemo\build-frameless-desk5_7_0-Debug - I:/gitee/QWidgetDemo/build-frameless-desk5_7_0-Debug - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - 0 - - - I:\gitee\QWidgetDemo\build-frameless-desk5_7_0-Release - I:/gitee/QWidgetDemo/build-frameless-desk5_7_0-Release - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - I:\gitee\QWidgetDemo\build-frameless-desk5_7_0-Profile - I:/gitee/QWidgetDemo/build-frameless-desk5_7_0-Profile - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - - 2 - - Qt4ProjectManager.Qt4RunConfiguration:I:/gitee/QWidgetDemo/frameless/frameless.pro - I:/gitee/QWidgetDemo/frameless/frameless.pro - false - true - true - false - true - I:/gitee/QWidgetDemo/core_common/../bin - - 1 - - - - ProjectExplorer.Project.Target.1 - - Desktop - desk5.7.1 - desk5.7.1 - {dde7e584-9f35-480c-9d61-83b32a324d7c} - 0 - 0 - 0 - - 0 - I:\gitee\QWidgetDemo\build-frameless-desk5_7_1-Debug - I:/gitee/QWidgetDemo/build-frameless-desk5_7_1-Debug - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - 0 - - - I:\gitee\QWidgetDemo\build-frameless-desk5_7_1-Release - I:/gitee/QWidgetDemo/build-frameless-desk5_7_1-Release - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - I:\gitee\QWidgetDemo\build-frameless-desk5_7_1-Profile - I:/gitee/QWidgetDemo/build-frameless-desk5_7_1-Profile - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - - 2 - - Qt4ProjectManager.Qt4RunConfiguration:I:/gitee/QWidgetDemo/frameless/frameless.pro - I:/gitee/QWidgetDemo/frameless/frameless.pro - false - true - true - false - true - I:/gitee/QWidgetDemo/core_common/../bin - - 1 - - - - ProjectExplorer.Project.Target.2 - - Desktop - desk6.2.0 - desk6.2.0 - {5a1d4711-9200-4ff6-be1e-e1f5a4d5b8d2} - 0 - 0 - 0 - - 0 - I:\gitee\QWidgetDemo\build-frameless-desk6_2_0-Debug - I:/gitee/QWidgetDemo/build-frameless-desk6_2_0-Debug - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - 0 - - - I:\gitee\QWidgetDemo\build-frameless-desk6_2_0-Release - I:/gitee/QWidgetDemo/build-frameless-desk6_2_0-Release - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - - 0 - I:\gitee\QWidgetDemo\build-frameless-desk6_2_0-Profile - I:/gitee/QWidgetDemo/build-frameless-desk6_2_0-Profile - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - - 2 - - Qt4ProjectManager.Qt4RunConfiguration:I:/gitee/QWidgetDemo/frameless/frameless.pro - I:/gitee/QWidgetDemo/frameless/frameless.pro - false - true - true - false - true - I:/gitee/QWidgetDemo/core_common/../bin - - 1 - - - - ProjectExplorer.Project.TargetCount - 3 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/frameless/head.h b/frameless/head.h deleted file mode 100644 index 304849c..0000000 --- a/frameless/head.h +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) -#include -#endif - -#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) -#include -#endif - -#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz")) -#define DATETIME qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")) -#pragma execution_character_set("utf-8") - diff --git a/frameless/main.cpp b/frameless/main.cpp deleted file mode 100644 index 993784f..0000000 --- a/frameless/main.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "quihelper.h" -#include "mainwindow.h" -#include "widget.h" -#include "dialog.h" - -int main(int argc, char *argv[]) -{ -#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) - QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); -#endif - QApplication a(argc, argv); - - QUIHelper::setStyle(); - QUIHelper::setFont(15); - QUIHelper::setCode(); - - MainWindow w; - //Widget w; - //Dialog w; - -#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) - w.resize(800, 600); -#else - w.resize(800, 550); -#endif - QUIHelper::setFormInCenter(&w); - w.show(); - return a.exec(); -} diff --git a/frameless/readme.md b/frameless/readme.md deleted file mode 100644 index fdec90e..0000000 --- a/frameless/readme.md +++ /dev/null @@ -1,50 +0,0 @@ -### 一 前言 -不知道各位程序员有没有遇到过这样一种困惑,好不容易在开源网站找到了类似的想要的项目代码,结果down下来一编译,我勒个去,几百个错误,根本没法用,熟悉的人还好可以直接阅读代码进行修改(有些只要做小改动就能正常编译,有些可能需要大刀阔斧),可是对于绝大部分的初学者来说绝对是噩梦,连把代码看下去的勇气都没有,我们没有任何权利和理由去责怪开原作者,只是期望各位能够在项目开源的同时,将开源项目完善好、测试好,最起码要把项目中依赖的遗漏的文件一起打包好,或者作出必要的说明,比如对应的开发编译版本要求,以来的文件去哪里下载。很多优秀的项目就毁在这个地方,没人完善和维护(可能因为没有耐心,也没有持续的收入来源,所以干的没劲,作者甚至转行送外卖了)。只有解决了这个痛点才能使得对应的开源项目持续发光发热。 - -本人自从学习Qt开发以来,开源过至少上百个项目(大部分早期开源的目前不在开源主页,有空会全部整理好重新发布),我要是说在国内Qt界开源的项目数量和质量排第十的话,没人敢说排第一、第二、第三...到第九。关于无边框界面方案,网上也有不少的优秀的开源的例子,99%都存在以下几个问题,针对以上问题,解决这些痛点,借助自己刚好有多个操作系统、几十个Qt版本的开发测试环境,特意完善了这个无边框类。 - -- 无法正常编译,缺少文件,作者真粗心,自己都没测试过。 -- 只限定了部分特定的版本才能编译。 -- 只解决了单个问题,比如无边框拖动,没有系统特性拉到左侧右侧半屏、顶部最大化。 -- 代码赶鸭子上架,复制粘贴的一坨坨,毫无章法。 -- 代码就是给作者自己用的,放上去就是给个参考,管他那么多。 -- 往左侧拉动抖动的厉害。 -- mac系统上不能最小化。 -- 不能同时支持win、linux、mac三种主流操作系统。 - -### 二 功能特点 -1. 同时支持Qt4-Qt6,亲测Qt4.7到Qt6.2以及后续版本。 -2. 同时支持mingw、msvc、gcc等。 -3. 同时支持windows、linux、mac。 -4. 同时支持QMainWindow、QWidget、QDialog。 -5. 使用方法极其简单,只需要将继承类修改即可。 -6. 自动识别双击标题栏响应。 -7. 无边框拉伸在windows下不抖动。 -8. 在windows下具有移动到边缘半屏、移动到顶部全屏特性。 -9. 解决mac系统上无边框最小化最大化失效的BUG。 -10. 解决系统休眠后再次启动程序懵逼的BUG。 -11. 解决有时候窗体重新显示的时候假死不刷新的BUG。 -12. 轻量级,1个代码文件,核心代码行数不到300行。 -13. 注释详细,示例完美,非常适合阅读和学习。 -14. 开源开箱即用,保证任意Qt版本可正常编译运行,无需任何调整。 - -### 三 效果图 -#### 1 windows -![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/frameless/snap/win.gif) - -#### 2 ubuntu -![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/frameless/snap/ubuntu.gif) - -#### 3 uos -![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/frameless/snap/uos.gif) - -#### 4 kylin -![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/frameless/snap/kylin.gif) - -#### 5 mac -![avatar](https://gitee.com/feiyangqingyun/QWidgetDemo/raw/master/frameless/snap/mac.gif) - -### 四 特别说明 -1. 点赞、评论、留言、转发、发代码。 -2. 国内站点:[https://gitee.com/feiyangqingyun/QWidgetDemo](https://gitee.com/feiyangqingyun/QWidgetDemo) -3. 国际站点:[https://github.com/feiyangqingyun/QWidgetDemo](https://github.com/feiyangqingyun/QWidgetDemo) \ No newline at end of file diff --git a/frameless/snap/kylin.gif b/frameless/snap/kylin.gif deleted file mode 100644 index 459dd53..0000000 Binary files a/frameless/snap/kylin.gif and /dev/null differ diff --git a/frameless/snap/mac.gif b/frameless/snap/mac.gif deleted file mode 100644 index fdfd54b..0000000 Binary files a/frameless/snap/mac.gif and /dev/null differ diff --git a/frameless/snap/ubuntu.gif b/frameless/snap/ubuntu.gif deleted file mode 100644 index 38a2c7b..0000000 Binary files a/frameless/snap/ubuntu.gif and /dev/null differ diff --git a/frameless/snap/uos.gif b/frameless/snap/uos.gif deleted file mode 100644 index 991f76c..0000000 Binary files a/frameless/snap/uos.gif and /dev/null differ diff --git a/frameless/snap/win.gif b/frameless/snap/win.gif deleted file mode 100644 index fe07065..0000000 Binary files a/frameless/snap/win.gif and /dev/null differ diff --git a/core_frameless/core_frameless.pri b/framelesswidget/framelesscore/framelesscore.pri similarity index 100% rename from core_frameless/core_frameless.pri rename to framelesswidget/framelesscore/framelesscore.pri diff --git a/core_frameless/framelessdialog.cpp b/framelesswidget/framelesscore/framelessdialog.cpp similarity index 100% rename from core_frameless/framelessdialog.cpp rename to framelesswidget/framelesscore/framelessdialog.cpp diff --git a/core_frameless/framelessdialog.h b/framelesswidget/framelesscore/framelessdialog.h similarity index 100% rename from core_frameless/framelessdialog.h rename to framelesswidget/framelesscore/framelessdialog.h diff --git a/core_frameless/framelessmainwindow.cpp b/framelesswidget/framelesscore/framelessmainwindow.cpp similarity index 100% rename from core_frameless/framelessmainwindow.cpp rename to framelesswidget/framelesscore/framelessmainwindow.cpp diff --git a/core_frameless/framelessmainwindow.h b/framelesswidget/framelesscore/framelessmainwindow.h similarity index 100% rename from core_frameless/framelessmainwindow.h rename to framelesswidget/framelesscore/framelessmainwindow.h diff --git a/core_frameless/framelesswidget.cpp b/framelesswidget/framelesscore/framelesswidget.cpp similarity index 100% rename from core_frameless/framelesswidget.cpp rename to framelesswidget/framelesscore/framelesswidget.cpp diff --git a/core_frameless/framelesswidget.h b/framelesswidget/framelesscore/framelesswidget.h similarity index 100% rename from core_frameless/framelesswidget.h rename to framelesswidget/framelesscore/framelesswidget.h diff --git a/frameless/form/dialog.cpp b/framelesswidget/framelessform/dialog.cpp similarity index 97% rename from frameless/form/dialog.cpp rename to framelesswidget/framelessform/dialog.cpp index 3cd7272..037cb9f 100644 --- a/frameless/form/dialog.cpp +++ b/framelesswidget/framelessform/dialog.cpp @@ -1,7 +1,7 @@ #include "dialog.h" #include "ui_dialog.h" -#include "head.h" +#pragma execution_character_set("utf-8") Dialog::Dialog(QWidget *parent) : FramelessDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); diff --git a/frameless/form/dialog.h b/framelesswidget/framelessform/dialog.h similarity index 100% rename from frameless/form/dialog.h rename to framelesswidget/framelessform/dialog.h diff --git a/frameless/form/dialog.ui b/framelesswidget/framelessform/dialog.ui similarity index 100% rename from frameless/form/dialog.ui rename to framelesswidget/framelessform/dialog.ui diff --git a/frameless/form/form.pri b/framelesswidget/framelessform/framelessform.pri similarity index 100% rename from frameless/form/form.pri rename to framelesswidget/framelessform/framelessform.pri diff --git a/frameless/form/mainwindow.cpp b/framelesswidget/framelessform/mainwindow.cpp similarity index 97% rename from frameless/form/mainwindow.cpp rename to framelesswidget/framelessform/mainwindow.cpp index 2f09f60..2c52138 100644 --- a/frameless/form/mainwindow.cpp +++ b/framelesswidget/framelessform/mainwindow.cpp @@ -1,7 +1,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include "head.h" +#pragma execution_character_set("utf-8") MainWindow::MainWindow(QWidget *parent) : FramelessMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); diff --git a/frameless/form/mainwindow.h b/framelesswidget/framelessform/mainwindow.h similarity index 100% rename from frameless/form/mainwindow.h rename to framelesswidget/framelessform/mainwindow.h diff --git a/frameless/form/mainwindow.ui b/framelesswidget/framelessform/mainwindow.ui similarity index 100% rename from frameless/form/mainwindow.ui rename to framelesswidget/framelessform/mainwindow.ui diff --git a/frameless/form/widget.cpp b/framelesswidget/framelessform/widget.cpp similarity index 97% rename from frameless/form/widget.cpp rename to framelesswidget/framelessform/widget.cpp index 57c2342..724aab3 100644 --- a/frameless/form/widget.cpp +++ b/framelesswidget/framelessform/widget.cpp @@ -1,7 +1,7 @@ #include "widget.h" #include "ui_widget.h" -#include "head.h" +#pragma execution_character_set("utf-8") Widget::Widget(QWidget *parent) : FramelessWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); diff --git a/frameless/form/widget.h b/framelesswidget/framelessform/widget.h similarity index 100% rename from frameless/form/widget.h rename to framelesswidget/framelessform/widget.h diff --git a/frameless/form/widget.ui b/framelesswidget/framelessform/widget.ui similarity index 100% rename from frameless/form/widget.ui rename to framelesswidget/framelessform/widget.ui diff --git a/framelesswidget/framelesswidget.cpp b/framelesswidget/framelesswidget.cpp deleted file mode 100644 index f5934fa..0000000 --- a/framelesswidget/framelesswidget.cpp +++ /dev/null @@ -1,221 +0,0 @@ -#include "framelesswidget.h" -#include "qevent.h" -#include "qdebug.h" - -FramelessWidget::FramelessWidget(QObject *parent) : QObject(parent) -{ - padding = 8; - moveEnable = true; - resizeEnable = true; - widget = 0; - - mousePressed = false; - mousePoint = QPoint(0, 0); - mouseRect = QRect(0, 0, 0, 0); - - for (int i = 0; i < 8; ++i) { - pressedArea << false; - pressedRect << QRect(0, 0, 0, 0); - } - - //如果父类是窗体则直接设置 - if (parent->isWidgetType()) { - setWidget((QWidget *)parent); - } -} - -bool FramelessWidget::eventFilter(QObject *watched, QEvent *event) -{ - if (widget != 0 && watched == widget) { - if (event->type() == QEvent::WindowStateChange) { - //解决mac系统上无边框最小化失效的BUG -#ifdef Q_OS_MACOS - if (widget->windowState() & Qt::WindowMinimized) { - isMin = true; - } else { - if (isMin) { - //设置无边框属性 - widget->setWindowFlags(flags | Qt::FramelessWindowHint); - widget->setVisible(true); - isMin = false; - } - } -#endif - } else if (event->type() == QEvent::Resize) { - //重新计算八个描点的区域,描点区域的作用还有就是计算鼠标坐标是否在某一个区域内 - int width = widget->width(); - int height = widget->height(); - - //左侧描点区域 - pressedRect[0] = QRect(0, padding, padding, height - padding * 2); - //右侧描点区域 - pressedRect[1] = QRect(width - padding, padding, padding, height - padding * 2); - //上侧描点区域 - pressedRect[2] = QRect(padding, 0, width - padding * 2, padding); - //下侧描点区域 - pressedRect[3] = QRect(padding, height - padding, width - padding * 2, padding); - - //左上角描点区域 - pressedRect[4] = QRect(0, 0, padding, padding); - //右上角描点区域 - pressedRect[5] = QRect(width - padding, 0, padding, padding); - //左下角描点区域 - pressedRect[6] = QRect(0, height - padding, padding, padding); - //右下角描点区域 - pressedRect[7] = QRect(width - padding, height - padding, padding, padding); - } else if (event->type() == QEvent::HoverMove) { - //设置对应鼠标形状,这个必须放在这里而不是下面,因为可以在鼠标没有按下的时候识别 - QHoverEvent *hoverEvent = (QHoverEvent *)event; - QPoint point = hoverEvent->pos(); - if (resizeEnable) { - if (pressedRect.at(0).contains(point)) { - widget->setCursor(Qt::SizeHorCursor); - } else if (pressedRect.at(1).contains(point)) { - widget->setCursor(Qt::SizeHorCursor); - } else if (pressedRect.at(2).contains(point)) { - widget->setCursor(Qt::SizeVerCursor); - } else if (pressedRect.at(3).contains(point)) { - widget->setCursor(Qt::SizeVerCursor); - } else if (pressedRect.at(4).contains(point)) { - widget->setCursor(Qt::SizeFDiagCursor); - } else if (pressedRect.at(5).contains(point)) { - widget->setCursor(Qt::SizeBDiagCursor); - } else if (pressedRect.at(6).contains(point)) { - widget->setCursor(Qt::SizeBDiagCursor); - } else if (pressedRect.at(7).contains(point)) { - widget->setCursor(Qt::SizeFDiagCursor); - } else { - widget->setCursor(Qt::ArrowCursor); - } - } - - //根据当前鼠标位置,计算XY轴移动了多少 - int offsetX = point.x() - mousePoint.x(); - int offsetY = point.y() - mousePoint.y(); - - //根据按下处的位置判断是否是移动控件还是拉伸控件 - if (moveEnable && mousePressed) { - widget->move(widget->x() + offsetX, widget->y() + offsetY); - } - - if (resizeEnable) { - int rectX = mouseRect.x(); - int rectY = mouseRect.y(); - int rectW = mouseRect.width(); - int rectH = mouseRect.height(); - - if (pressedArea.at(0)) { - int resizeW = widget->width() - offsetX; - if (widget->minimumWidth() <= resizeW) { - widget->setGeometry(widget->x() + offsetX, rectY, resizeW, rectH); - } - } else if (pressedArea.at(1)) { - widget->setGeometry(rectX, rectY, rectW + offsetX, rectH); - } else if (pressedArea.at(2)) { - int resizeH = widget->height() - offsetY; - if (widget->minimumHeight() <= resizeH) { - widget->setGeometry(rectX, widget->y() + offsetY, rectW, resizeH); - } - } else if (pressedArea.at(3)) { - widget->setGeometry(rectX, rectY, rectW, rectH + offsetY); - } else if (pressedArea.at(4)) { - int resizeW = widget->width() - offsetX; - int resizeH = widget->height() - offsetY; - if (widget->minimumWidth() <= resizeW) { - widget->setGeometry(widget->x() + offsetX, widget->y(), resizeW, resizeH); - } - if (widget->minimumHeight() <= resizeH) { - widget->setGeometry(widget->x(), widget->y() + offsetY, resizeW, resizeH); - } - } else if (pressedArea.at(5)) { - int resizeW = rectW + offsetX; - int resizeH = widget->height() - offsetY; - if (widget->minimumHeight() <= resizeH) { - widget->setGeometry(widget->x(), widget->y() + offsetY, resizeW, resizeH); - } - } else if (pressedArea.at(6)) { - int resizeW = widget->width() - offsetX; - int resizeH = rectH + offsetY; - if (widget->minimumWidth() <= resizeW) { - widget->setGeometry(widget->x() + offsetX, widget->y(), resizeW, resizeH); - } - if (widget->minimumHeight() <= resizeH) { - widget->setGeometry(widget->x(), widget->y(), resizeW, resizeH); - } - } else if (pressedArea.at(7)) { - int resizeW = rectW + offsetX; - int resizeH = rectH + offsetY; - widget->setGeometry(widget->x(), widget->y(), resizeW, resizeH); - } - } - } else if (event->type() == QEvent::MouseButtonPress) { - //记住鼠标按下的坐标+窗体区域 - QMouseEvent *mouseEvent = (QMouseEvent *)event; - mousePoint = mouseEvent->pos(); - mouseRect = widget->geometry(); - - //判断按下的手柄的区域位置 - if (pressedRect.at(0).contains(mousePoint)) { - pressedArea[0] = true; - } else if (pressedRect.at(1).contains(mousePoint)) { - pressedArea[1] = true; - } else if (pressedRect.at(2).contains(mousePoint)) { - pressedArea[2] = true; - } else if (pressedRect.at(3).contains(mousePoint)) { - pressedArea[3] = true; - } else if (pressedRect.at(4).contains(mousePoint)) { - pressedArea[4] = true; - } else if (pressedRect.at(5).contains(mousePoint)) { - pressedArea[5] = true; - } else if (pressedRect.at(6).contains(mousePoint)) { - pressedArea[6] = true; - } else if (pressedRect.at(7).contains(mousePoint)) { - pressedArea[7] = true; - } else { - mousePressed = true; - } - } else if (event->type() == QEvent::MouseMove) { - //改成用HoverMove识别 - } else if (event->type() == QEvent::MouseButtonRelease) { - //恢复所有 - widget->setCursor(Qt::ArrowCursor); - mousePressed = false; - for (int i = 0; i < 8; ++i) { - pressedArea[i] = false; - } - } - } - - return QObject::eventFilter(watched, event); -} - -void FramelessWidget::setPadding(int padding) -{ - this->padding = padding; -} - -void FramelessWidget::setMoveEnable(bool moveEnable) -{ - this->moveEnable = moveEnable; -} - -void FramelessWidget::setResizeEnable(bool resizeEnable) -{ - this->resizeEnable = resizeEnable; -} - -void FramelessWidget::setWidget(QWidget *widget) -{ - if (this->widget == 0) { - this->widget = widget; - //设置鼠标追踪为真 - this->widget->setMouseTracking(true); - //绑定事件过滤器 - this->widget->installEventFilter(this); - //设置悬停为真,必须设置这个,不然当父窗体里边还有子窗体全部遮挡了识别不到MouseMove,需要识别HoverMove - this->widget->setAttribute(Qt::WA_Hover, true); - - isMin = false; - flags = widget->windowFlags(); - } -} diff --git a/framelesswidget/framelesswidget.h b/framelesswidget/framelesswidget.h deleted file mode 100644 index 99a83e7..0000000 --- a/framelesswidget/framelesswidget.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef FRAMELESSWIDGET_H -#define FRAMELESSWIDGET_H - -/** - * 无边框窗体类 作者:feiyangqingyun(QQ:517216493) 2019-10-03 - * 1. 可以指定需要无边框的widget。 - * 2. 边框四周八个方位都可以自由拉伸。 - * 3. 可设置对应位置的边距,以便识别更大区域。 - * 4. 可设置是否允许拖动。 - * 5. 可设置是否允许拉伸。 - */ - -#include - -#ifdef quc -class Q_DECL_EXPORT FramelessWidget : public QObject -#else -class FramelessWidget : public QObject -#endif - -{ - Q_OBJECT -public: - explicit FramelessWidget(QObject *parent = 0); - -protected: - bool eventFilter(QObject *watched, QEvent *event); - -private: - //边距+可移动+可拉伸 - int padding; - bool moveEnable; - bool resizeEnable; - - //无边框窗体 - QWidget *widget; - - //鼠标是否按下+按下坐标+按下时窗体区域 - bool mousePressed; - QPoint mousePoint; - QRect mouseRect; - - //鼠标是否按下某个区域+按下区域的大小 - //依次为 左侧+右侧+上侧+下侧+左上侧+右上侧+左下侧+右下侧 - QList pressedArea; - QList pressedRect; - - //记录是否最小化 - bool isMin; - //存储窗体默认的属性 - Qt::WindowFlags flags; - -public Q_SLOTS: - //设置边距 - void setPadding(int padding); - //设置是否可拖动+拉伸 - void setMoveEnable(bool moveEnable); - void setResizeEnable(bool resizeEnable); - - //设置要无边框的窗体 - void setWidget(QWidget *widget); -}; - -#endif // FRAMELESSWIDGET_H diff --git a/framelesswidget/framelesswidget.pro b/framelesswidget/framelesswidget.pro index 6f35268..afce1dc 100644 --- a/framelesswidget/framelesswidget.pro +++ b/framelesswidget/framelesswidget.pro @@ -9,11 +9,15 @@ CONFIG += warn_off SOURCES += main.cpp SOURCES += frmframelesswidget.cpp -SOURCES += framelesswidget.cpp SOURCES += framelesswidget2.cpp HEADERS += frmframelesswidget.h -HEADERS += framelesswidget.h HEADERS += framelesswidget2.h FORMS += frmframelesswidget.ui + +INCLUDEPATH += $$PWD/framelesscore +INCLUDEPATH += $$PWD/framelessform + +include ($$PWD/framelesscore/framelesscore.pri) +include ($$PWD/framelessform/framelessform.pri) diff --git a/framelesswidget/framelesswidget2.cpp b/framelesswidget/framelesswidget2.cpp index 9586618..8e19985 100644 --- a/framelesswidget/framelesswidget2.cpp +++ b/framelesswidget/framelesswidget2.cpp @@ -1,123 +1,193 @@ #include "framelesswidget2.h" -#include "qdatetime.h" #include "qevent.h" #include "qdebug.h" -#ifdef Q_OS_WIN -#include "windows.h" -#pragma comment (lib,"user32.lib") -#endif - -#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz")) - -FramelessWidget2::FramelessWidget2(QWidget *parent) : QWidget(parent) +FramelessWidget2::FramelessWidget2(QObject *parent) : QObject(parent) { padding = 8; moveEnable = true; resizeEnable = true; + widget = 0; - //安装事件过滤器识别拖动 - this->installEventFilter(this); + mousePressed = false; + mousePoint = QPoint(0, 0); + mouseRect = QRect(0, 0, 0, 0); + + for (int i = 0; i < 8; ++i) { + pressedArea << false; + pressedRect << QRect(0, 0, 0, 0); + } + + //如果父类是窗体则直接设置 + if (parent->isWidgetType()) { + setWidget((QWidget *)parent); + } } bool FramelessWidget2::eventFilter(QObject *watched, QEvent *event) { - if (watched == this && moveEnable) { - 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(); + if (widget != 0 && watched == widget) { + if (event->type() == QEvent::WindowStateChange) { + //解决mac系统上无边框最小化失效的BUG +#ifdef Q_OS_MACOS + if (widget->windowState() & Qt::WindowMinimized) { + isMin = true; + } else { + if (isMin) { + //设置无边框属性 + widget->setWindowFlags(flags | Qt::FramelessWindowHint); + widget->setVisible(true); + isMin = false; + } } - } else if (mouseEvent->type() == QEvent::MouseButtonRelease) { - mousePressed = false; - } else if (mouseEvent->type() == QEvent::MouseMove) { - if (mousePressed) { - this->move(mouseEvent->globalPos() - mousePoint); - return true; - } - } - } - - return QWidget::eventFilter(watched, event); -} - -#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) -bool FramelessWidget2::nativeEvent(const QByteArray &eventType, void *message, qintptr *result) -#else -bool FramelessWidget2::nativeEvent(const QByteArray &eventType, void *message, long *result) #endif -{ - if (eventType == "windows_generic_MSG") { -#ifdef Q_OS_WIN - MSG *msg = static_cast(message); - //qDebug() << TIMEMS << "nativeEvent" << msg->wParam << msg->message; + } else if (event->type() == QEvent::Resize) { + //重新计算八个描点的区域,描点区域的作用还有就是计算鼠标坐标是否在某一个区域内 + int width = widget->width(); + int height = widget->height(); - //不同的消息类型和参数进行不同的处理 - if (msg->message == WM_NCCALCSIZE) { - *result = 0; - return true; - } else if (msg->message == WM_NCHITTEST) { - //计算鼠标对应的屏幕坐标 - long x = LOWORD(msg->lParam); - long y = HIWORD(msg->lParam); - QPoint pos = mapFromGlobal(QPoint(x, y)); + //左侧描点区域 + pressedRect[0] = QRect(0, padding, padding, height - padding * 2); + //右侧描点区域 + pressedRect[1] = QRect(width - padding, padding, padding, height - padding * 2); + //上侧描点区域 + pressedRect[2] = QRect(padding, 0, width - padding * 2, padding); + //下侧描点区域 + pressedRect[3] = QRect(padding, height - padding, width - padding * 2, padding); - //判断当前鼠标位置在哪个区域 - bool left = pos.x() < padding; - bool right = pos.x() > width() - padding; - bool top = pos.y() < padding; - bool bottom = pos.y() > height() - padding; - - //鼠标移动到四个角,这个消息是当鼠标移动或者有鼠标键按下时候发出的 - *result = 0; + //左上角描点区域 + pressedRect[4] = QRect(0, 0, padding, padding); + //右上角描点区域 + pressedRect[5] = QRect(width - padding, 0, padding, padding); + //左下角描点区域 + pressedRect[6] = QRect(0, height - padding, padding, padding); + //右下角描点区域 + pressedRect[7] = QRect(width - padding, height - padding, padding, padding); + } else if (event->type() == QEvent::HoverMove) { + //设置对应鼠标形状,这个必须放在这里而不是下面,因为可以在鼠标没有按下的时候识别 + QHoverEvent *hoverEvent = (QHoverEvent *)event; + QPoint point = hoverEvent->pos(); if (resizeEnable) { - if (left && top) { - *result = HTTOPLEFT; - } else if (left && bottom) { - *result = HTBOTTOMLEFT; - } else if (right && top) { - *result = HTTOPRIGHT; - } else if (right && bottom) { - *result = HTBOTTOMRIGHT; - } else if (left) { - *result = HTLEFT; - } else if (right) { - *result = HTRIGHT; - } else if (top) { - *result = HTTOP; - } else if (bottom) { - *result = HTBOTTOM; + if (pressedRect.at(0).contains(point)) { + widget->setCursor(Qt::SizeHorCursor); + } else if (pressedRect.at(1).contains(point)) { + widget->setCursor(Qt::SizeHorCursor); + } else if (pressedRect.at(2).contains(point)) { + widget->setCursor(Qt::SizeVerCursor); + } else if (pressedRect.at(3).contains(point)) { + widget->setCursor(Qt::SizeVerCursor); + } else if (pressedRect.at(4).contains(point)) { + widget->setCursor(Qt::SizeFDiagCursor); + } else if (pressedRect.at(5).contains(point)) { + widget->setCursor(Qt::SizeBDiagCursor); + } else if (pressedRect.at(6).contains(point)) { + widget->setCursor(Qt::SizeBDiagCursor); + } else if (pressedRect.at(7).contains(point)) { + widget->setCursor(Qt::SizeFDiagCursor); + } else { + widget->setCursor(Qt::ArrowCursor); } } - //先处理掉拉伸 - if (0 != *result) { - return true; + //根据当前鼠标位置,计算XY轴移动了多少 + int offsetX = point.x() - mousePoint.x(); + int offsetY = point.y() - mousePoint.y(); + + //根据按下处的位置判断是否是移动控件还是拉伸控件 + if (moveEnable && mousePressed) { + widget->move(widget->x() + offsetX, widget->y() + offsetY); + } + + if (resizeEnable) { + int rectX = mouseRect.x(); + int rectY = mouseRect.y(); + int rectW = mouseRect.width(); + int rectH = mouseRect.height(); + + if (pressedArea.at(0)) { + int resizeW = widget->width() - offsetX; + if (widget->minimumWidth() <= resizeW) { + widget->setGeometry(widget->x() + offsetX, rectY, resizeW, rectH); + } + } else if (pressedArea.at(1)) { + widget->setGeometry(rectX, rectY, rectW + offsetX, rectH); + } else if (pressedArea.at(2)) { + int resizeH = widget->height() - offsetY; + if (widget->minimumHeight() <= resizeH) { + widget->setGeometry(rectX, widget->y() + offsetY, rectW, resizeH); + } + } else if (pressedArea.at(3)) { + widget->setGeometry(rectX, rectY, rectW, rectH + offsetY); + } else if (pressedArea.at(4)) { + int resizeW = widget->width() - offsetX; + int resizeH = widget->height() - offsetY; + if (widget->minimumWidth() <= resizeW) { + widget->setGeometry(widget->x() + offsetX, widget->y(), resizeW, resizeH); + } + if (widget->minimumHeight() <= resizeH) { + widget->setGeometry(widget->x(), widget->y() + offsetY, resizeW, resizeH); + } + } else if (pressedArea.at(5)) { + int resizeW = rectW + offsetX; + int resizeH = widget->height() - offsetY; + if (widget->minimumHeight() <= resizeH) { + widget->setGeometry(widget->x(), widget->y() + offsetY, resizeW, resizeH); + } + } else if (pressedArea.at(6)) { + int resizeW = widget->width() - offsetX; + int resizeH = rectH + offsetY; + if (widget->minimumWidth() <= resizeW) { + widget->setGeometry(widget->x() + offsetX, widget->y(), resizeW, resizeH); + } + if (widget->minimumHeight() <= resizeH) { + widget->setGeometry(widget->x(), widget->y(), resizeW, resizeH); + } + } else if (pressedArea.at(7)) { + int resizeW = rectW + offsetX; + int resizeH = rectH + offsetY; + widget->setGeometry(widget->x(), widget->y(), resizeW, resizeH); + } + } + } else if (event->type() == QEvent::MouseButtonPress) { + //记住鼠标按下的坐标+窗体区域 + QMouseEvent *mouseEvent = (QMouseEvent *)event; + mousePoint = mouseEvent->pos(); + mouseRect = widget->geometry(); + + //判断按下的手柄的区域位置 + if (pressedRect.at(0).contains(mousePoint)) { + pressedArea[0] = true; + } else if (pressedRect.at(1).contains(mousePoint)) { + pressedArea[1] = true; + } else if (pressedRect.at(2).contains(mousePoint)) { + pressedArea[2] = true; + } else if (pressedRect.at(3).contains(mousePoint)) { + pressedArea[3] = true; + } else if (pressedRect.at(4).contains(mousePoint)) { + pressedArea[4] = true; + } else if (pressedRect.at(5).contains(mousePoint)) { + pressedArea[5] = true; + } else if (pressedRect.at(6).contains(mousePoint)) { + pressedArea[6] = true; + } else if (pressedRect.at(7).contains(mousePoint)) { + pressedArea[7] = true; + } else { + mousePressed = true; + } + } else if (event->type() == QEvent::MouseMove) { + //改成用HoverMove识别 + } else if (event->type() == QEvent::MouseButtonRelease) { + //恢复所有 + widget->setCursor(Qt::ArrowCursor); + mousePressed = false; + for (int i = 0; i < 8; ++i) { + pressedArea[i] = false; } } -#endif - } else if (eventType == "NSEvent") { -#ifdef Q_OS_MACOS -#endif - } else if (eventType == "xcb_generic_event_t") { -#ifdef Q_OS_LINUX -#endif } - return false; -} -#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) -#ifdef Q_OS_WIN -bool FramelessWidget2::winEvent(MSG *message, long *result) -{ - return nativeEvent("windows_generic_MSG", message, result); + return QObject::eventFilter(watched, event); } -#endif -#endif void FramelessWidget2::setPadding(int padding) { @@ -133,3 +203,19 @@ void FramelessWidget2::setResizeEnable(bool resizeEnable) { this->resizeEnable = resizeEnable; } + +void FramelessWidget2::setWidget(QWidget *widget) +{ + if (this->widget == 0) { + this->widget = widget; + //设置鼠标追踪为真 + this->widget->setMouseTracking(true); + //绑定事件过滤器 + this->widget->installEventFilter(this); + //设置悬停为真,必须设置这个,不然当父窗体里边还有子窗体全部遮挡了识别不到MouseMove,需要识别HoverMove + this->widget->setAttribute(Qt::WA_Hover, true); + + isMin = false; + flags = widget->windowFlags(); + } +} diff --git a/framelesswidget/framelesswidget2.h b/framelesswidget/framelesswidget2.h index 0bca12c..a332161 100644 --- a/framelesswidget/framelesswidget2.h +++ b/framelesswidget/framelesswidget2.h @@ -1,47 +1,64 @@ #ifndef FRAMELESSWIDGET2_H #define FRAMELESSWIDGET2_H +/** + * 无边框窗体类 作者:feiyangqingyun(QQ:517216493) 2019-10-03 + * 1. 可以指定需要无边框的widget。 + * 2. 边框四周八个方位都可以自由拉伸。 + * 3. 可设置对应位置的边距,以便识别更大区域。 + * 4. 可设置是否允许拖动。 + * 5. 可设置是否允许拉伸。 + */ + #include #ifdef quc -class Q_DECL_EXPORT FramelessWidget2 : public QWidget +class Q_DECL_EXPORT FramelessWidget2 : public QObject #else -class FramelessWidget2 : public QWidget +class FramelessWidget2 : public QObject #endif { Q_OBJECT public: - explicit FramelessWidget2(QWidget *parent = 0); + explicit FramelessWidget2(QObject *parent = 0); protected: bool eventFilter(QObject *watched, QEvent *event); - //拦截系统事件用于修复系统休眠后唤醒程序的BUG -#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) - bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result); -#else - bool nativeEvent(const QByteArray &eventType, void *message, long *result); -#endif - - //Qt4的写法 -#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) -#ifdef Q_OS_WIN - bool winEvent(MSG *message, long *result); -#endif -#endif - private: //边距+可移动+可拉伸 int padding; bool moveEnable; bool resizeEnable; -public: - //设置边距+可拖动+可拉伸 + //无边框窗体 + QWidget *widget; + + //鼠标是否按下+按下坐标+按下时窗体区域 + bool mousePressed; + QPoint mousePoint; + QRect mouseRect; + + //鼠标是否按下某个区域+按下区域的大小 + //依次为 左侧+右侧+上侧+下侧+左上侧+右上侧+左下侧+右下侧 + QList pressedArea; + QList pressedRect; + + //记录是否最小化 + bool isMin; + //存储窗体默认的属性 + Qt::WindowFlags flags; + +public Q_SLOTS: + //设置边距 void setPadding(int padding); + //设置是否可拖动+拉伸 void setMoveEnable(bool moveEnable); void setResizeEnable(bool resizeEnable); + + //设置要无边框的窗体 + void setWidget(QWidget *widget); }; #endif // FRAMELESSWIDGET2_H diff --git a/framelesswidget/frmframelesswidget.cpp b/framelesswidget/frmframelesswidget.cpp index 279121f..e84a000 100644 --- a/framelesswidget/frmframelesswidget.cpp +++ b/framelesswidget/frmframelesswidget.cpp @@ -4,15 +4,13 @@ #include "ui_frmframelesswidget.h" #include "qpushbutton.h" #include "qcheckbox.h" -#include "framelesswidget.h" #include "framelesswidget2.h" frmFramelessWidget::frmFramelessWidget(QWidget *parent) : QWidget(parent), ui(new Ui::frmFramelessWidget) { ui->setupUi(this); - widget1 = 0; + widget = 0; frameless = 0; - frameless2 = 0; } frmFramelessWidget::~frmFramelessWidget() @@ -59,14 +57,14 @@ void frmFramelessWidget::initWidget(QWidget *w) void frmFramelessWidget::on_pushButton_clicked() { - if (widget1 == 0) { - widget1 = new QWidget; - this->initWidget(widget1); - frameless = new FramelessWidget(widget1); - frameless->setWidget(widget1); + if (widget == 0) { + widget = new QWidget; + this->initWidget(widget); + frameless = new FramelessWidget2(widget); + frameless->setWidget(widget); } - widget1->show(); + widget->show(); } void frmFramelessWidget::stateChanged1(int arg1) @@ -74,9 +72,6 @@ void frmFramelessWidget::stateChanged1(int arg1) if (frameless != 0) { frameless->setMoveEnable(arg1 != 0); } - if (frameless2 != 0) { - frameless2->setMoveEnable(arg1 != 0); - } } void frmFramelessWidget::stateChanged2(int arg1) @@ -84,17 +79,4 @@ void frmFramelessWidget::stateChanged2(int arg1) if (frameless != 0) { frameless->setResizeEnable(arg1 != 0); } - if (frameless2 != 0) { - frameless2->setResizeEnable(arg1 != 0); - } -} - -void frmFramelessWidget::on_pushButton_2_clicked() -{ - if (frameless2 == 0) { - frameless2 = new FramelessWidget2; - this->initWidget(frameless2); - } - - frameless2->show(); } diff --git a/framelesswidget/frmframelesswidget.h b/framelesswidget/frmframelesswidget.h index 52dc15c..f36faea 100644 --- a/framelesswidget/frmframelesswidget.h +++ b/framelesswidget/frmframelesswidget.h @@ -2,7 +2,6 @@ #define FRMFRAMELESSWIDGET_H #include -class FramelessWidget; class FramelessWidget2; namespace Ui { @@ -22,16 +21,14 @@ protected: private: Ui::frmFramelessWidget *ui; - QWidget *widget1; - FramelessWidget *frameless; - FramelessWidget2 *frameless2; + QWidget *widget; + FramelessWidget2 *frameless; private slots: void initWidget(QWidget *w); void on_pushButton_clicked(); void stateChanged1(int arg1); void stateChanged2(int arg1); - void on_pushButton_2_clicked(); }; #endif // FRMFRAMELESSWIDGET_H diff --git a/framelesswidget/frmframelesswidget.ui b/framelesswidget/frmframelesswidget.ui index ff695b8..772d41c 100644 --- a/framelesswidget/frmframelesswidget.ui +++ b/framelesswidget/frmframelesswidget.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 800 + 600 @@ -26,19 +26,6 @@ 弹出 - - - - 110 - 10 - 92 - 28 - - - - 无边框2 - - diff --git a/framelesswidget/main.cpp b/framelesswidget/main.cpp index 4c839b4..e10c6f2 100644 --- a/framelesswidget/main.cpp +++ b/framelesswidget/main.cpp @@ -1,6 +1,9 @@ #pragma execution_character_set("utf-8") #include "frmframelesswidget.h" +#include "dialog.h" +#include "widget.h" +#include "mainwindow.h" #include #include @@ -27,7 +30,11 @@ int main(int argc, char *argv[]) #endif frmFramelessWidget w; + //Dialog w; + //Widget w; + //MainWindow w; w.setWindowTitle("无边框窗体类"); + w.resize(800, 600); w.show(); return a.exec(); diff --git a/gifwidget/gifwidget.cpp b/gifwidget/gifwidget.cpp index 79da488..9217551 100644 --- a/gifwidget/gifwidget.cpp +++ b/gifwidget/gifwidget.cpp @@ -274,14 +274,14 @@ void GifWidget::saveImage() return; } -#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) - //由于qt4没有RGBA8888,采用最接近RGBA8888的是ARGB32,颜色会有点偏差 - QPixmap pix = QPixmap::grabWindow(0, x() + rectGif.x(), y() + rectGif.y(), rectGif.width(), rectGif.height()); - QImage image = pix.toImage().convertToFormat(QImage::Format_ARGB32); -#else +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) QScreen *screen = QApplication::primaryScreen(); QPixmap pix = screen->grabWindow(0, x() + rectGif.x(), y() + rectGif.y(), rectGif.width(), rectGif.height()); QImage image = pix.toImage().convertToFormat(QImage::Format_RGBA8888); +#else + //由于qt4没有RGBA8888,采用最接近RGBA8888的是ARGB32,颜色会有点偏差 + QPixmap pix = QPixmap::grabWindow(0, x() + rectGif.x(), y() + rectGif.y(), rectGif.width(), rectGif.height()); + QImage image = pix.toImage().convertToFormat(QImage::Format_ARGB32); #endif gif.GifWriteFrame(gifWriter, image.bits(), rectGif.width(), rectGif.height(), fps); diff --git a/mpvdemo/mpv/mpv.h b/mpvdemo/mpv/mpv.h index 2880858..075bc30 100644 --- a/mpvdemo/mpv/mpv.h +++ b/mpvdemo/mpv/mpv.h @@ -2,7 +2,7 @@ #define VLC_H #include -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) #include #endif diff --git a/netserver/api/tcpserver1.cpp b/netserver/api/tcpserver1.cpp index 9835e00..04144a0 100644 --- a/netserver/api/tcpserver1.cpp +++ b/netserver/api/tcpserver1.cpp @@ -80,7 +80,7 @@ TcpServer1::TcpServer1(QObject *parent) : QTcpServer(parent) { } -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) void TcpServer1::incomingConnection(qintptr handle) #else void TcpServer1::incomingConnection(int handle) @@ -120,7 +120,7 @@ void TcpServer1::disconnected() bool TcpServer1::start() { -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) bool ok = listen(QHostAddress::AnyIPv4, AppConfig::ListenPort1); #else bool ok = listen(QHostAddress::Any, AppConfig::ListenPort1); diff --git a/netserver/api/tcpserver1.h b/netserver/api/tcpserver1.h index 0d002cc..71266cf 100644 --- a/netserver/api/tcpserver1.h +++ b/netserver/api/tcpserver1.h @@ -45,7 +45,7 @@ private: QList clients; protected: -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) void incomingConnection(qintptr handle); #else void incomingConnection(int handle); diff --git a/netserver/api/tcpserver2.cpp b/netserver/api/tcpserver2.cpp index 9cd8a24..f967cdd 100644 --- a/netserver/api/tcpserver2.cpp +++ b/netserver/api/tcpserver2.cpp @@ -80,7 +80,7 @@ TcpServer2::TcpServer2(QObject *parent) : QTcpServer(parent) { } -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) void TcpServer2::incomingConnection(qintptr handle) #else void TcpServer2::incomingConnection(int handle) @@ -120,7 +120,7 @@ void TcpServer2::disconnected() bool TcpServer2::start() { -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) bool ok = listen(QHostAddress::AnyIPv4, AppConfig::ListenPort2); #else bool ok = listen(QHostAddress::Any, AppConfig::ListenPort2); diff --git a/netserver/api/tcpserver2.h b/netserver/api/tcpserver2.h index 9f73427..e0ccb1d 100644 --- a/netserver/api/tcpserver2.h +++ b/netserver/api/tcpserver2.h @@ -45,7 +45,7 @@ private: QList clients; protected: -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) void incomingConnection(qintptr handle); #else void incomingConnection(int handle); diff --git a/netserver/head.h b/netserver/head.h index 63c0ee1..c494cae 100644 --- a/netserver/head.h +++ b/netserver/head.h @@ -2,7 +2,7 @@ #include #include -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) #include #endif diff --git a/nettool/head.h b/nettool/head.h index 612e37c..4c827d2 100644 --- a/nettool/head.h +++ b/nettool/head.h @@ -2,7 +2,7 @@ #include #include -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) #include #ifdef websocket #include diff --git a/ntpclient/ntpclient.cpp b/ntpclient/ntpclient.cpp index d7fb2fe..f9b5288 100644 --- a/ntpclient/ntpclient.cpp +++ b/ntpclient/ntpclient.cpp @@ -86,10 +86,10 @@ void NtpClient::readData() QDateTime dateTime; uint secs = seconds - epoch.secsTo(unixStart); -#if (QT_VERSION < QT_VERSION_CHECK(6,0,0)) - dateTime.setTime_t(secs); -#else +#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) dateTime.setSecsSinceEpoch(secs); +#else + dateTime.setTime_t(secs); #endif #ifdef __arm__ diff --git a/screenwidget/screenwidget.cpp b/screenwidget/screenwidget.cpp index 7913587..61654a1 100644 --- a/screenwidget/screenwidget.cpp +++ b/screenwidget/screenwidget.cpp @@ -218,11 +218,11 @@ void ScreenWidget::showEvent(QShowEvent *) screen->setStart(point); screen->setEnd(point); -#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) - *fullScreen = fullScreen->grabWindow(0, 0, 0, screen->width(), screen->height()); -#else +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) QScreen *pscreen = QApplication::primaryScreen(); *fullScreen = pscreen->grabWindow(0, 0, 0, screen->width(), screen->height()); +#else + *fullScreen = fullScreen->grabWindow(0, 0, 0, screen->width(), screen->height()); #endif //设置透明度实现模糊背景 diff --git a/vlcdemo/vlc/vlc.h b/vlcdemo/vlc/vlc.h index b72daeb..0c38d2b 100644 --- a/vlcdemo/vlc/vlc.h +++ b/vlcdemo/vlc/vlc.h @@ -2,7 +2,7 @@ #define VLC_H #include -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) #include #endif