diff --git a/3rd_qextserialport/3rd_qextserialport.pri b/3rd_qextserialport/3rd_qextserialport.pri index af5f020..12e8a78 100644 --- a/3rd_qextserialport/3rd_qextserialport.pri +++ b/3rd_qextserialport/3rd_qextserialport.pri @@ -1,11 +1,9 @@ -HEADERS += $$PWD/qextserialport.h -HEADERS += $$PWD/qextserialport_global.h -HEADERS += $$PWD/qextserialport_p.h +HEADERS += \ + $$PWD/qextserialport.h \ + $$PWD/qextserialport_global.h \ + $$PWD/qextserialport_p.h SOURCES += $$PWD/qextserialport.cpp -win32 { -SOURCES += $$PWD/qextserialport_win.cpp -} -unix { -SOURCES += $$PWD/qextserialport_unix.cpp -} + +win32:SOURCES += $$PWD/qextserialport_win.cpp +unix:SOURCES += $$PWD/qextserialport_unix.cpp diff --git a/3rd_qextserialport/qextserialport_win.cpp b/3rd_qextserialport/qextserialport_win.cpp index 50828af..e48ddde 100644 --- a/3rd_qextserialport/qextserialport_win.cpp +++ b/3rd_qextserialport/qextserialport_win.cpp @@ -35,26 +35,33 @@ #include #include #include -#include #include + #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) -# include +#include #else -# include +#include #endif + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#else +#include +#endif + void QextSerialPortPrivate::platformSpecificInit() { - handle = INVALID_HANDLE_VALUE; - ZeroMemory(&overlap, sizeof(OVERLAPPED)); - overlap.hEvent = CreateEvent(NULL, true, false, NULL); - winEventNotifier = 0; - bytesToWriteLock = new QReadWriteLock; + handle = INVALID_HANDLE_VALUE; + ZeroMemory(&overlap, sizeof(OVERLAPPED)); + overlap.hEvent = CreateEvent(NULL, true, false, NULL); + winEventNotifier = 0; + bytesToWriteLock = new QReadWriteLock; } void QextSerialPortPrivate::platformSpecificDestruct() { - CloseHandle(overlap.hEvent); - delete bytesToWriteLock; + CloseHandle(overlap.hEvent); + delete bytesToWriteLock; } @@ -66,108 +73,107 @@ void QextSerialPortPrivate::platformSpecificDestruct() */ static QString fullPortNameWin(const QString &name) { - QRegExp rx(QLatin1String("^COM(\\d+)")); - QString fullName(name); + QRegExp rx(QLatin1String("^COM(\\d+)")); + QString fullName(name); + if (rx.indexIn(fullName) >= 0) { + fullName.prepend(QLatin1String("\\\\.\\")); + } - if (fullName.contains(rx)) { - fullName.prepend(QLatin1String("\\\\.\\")); - } - - return fullName; + return fullName; } bool QextSerialPortPrivate::open_sys(QIODevice::OpenMode mode) { - Q_Q(QextSerialPort); - DWORD confSize = sizeof(COMMCONFIG); - commConfig.dwSize = confSize; - DWORD dwFlagsAndAttributes = 0; + Q_Q(QextSerialPort); + DWORD confSize = sizeof(COMMCONFIG); + commConfig.dwSize = confSize; + DWORD dwFlagsAndAttributes = 0; - if (queryMode == QextSerialPort::EventDriven) { - dwFlagsAndAttributes += FILE_FLAG_OVERLAPPED; - } + if (queryMode == QextSerialPort::EventDriven) { + dwFlagsAndAttributes += FILE_FLAG_OVERLAPPED; + } - /*open the port*/ - handle = CreateFileW((wchar_t *)fullPortNameWin(port).utf16(), GENERIC_READ | GENERIC_WRITE, - 0, NULL, OPEN_EXISTING, dwFlagsAndAttributes, NULL); + /*open the port*/ + handle = CreateFileW((wchar_t *)fullPortNameWin(port).utf16(), GENERIC_READ | GENERIC_WRITE, + 0, NULL, OPEN_EXISTING, dwFlagsAndAttributes, NULL); - if (handle != INVALID_HANDLE_VALUE) { - q->setOpenMode(mode); - /*configure port settings*/ - GetCommConfig(handle, &commConfig, &confSize); - GetCommState(handle, &(commConfig.dcb)); + if (handle != INVALID_HANDLE_VALUE) { + q->setOpenMode(mode); + /*configure port settings*/ + GetCommConfig(handle, &commConfig, &confSize); + GetCommState(handle, &(commConfig.dcb)); - /*set up parameters*/ - commConfig.dcb.fBinary = TRUE; - commConfig.dcb.fInX = FALSE; - commConfig.dcb.fOutX = FALSE; - commConfig.dcb.fAbortOnError = FALSE; - commConfig.dcb.fNull = FALSE; - /* Dtr default to true. See Issue 122*/ - commConfig.dcb.fDtrControl = TRUE; - /*flush all settings*/ - settingsDirtyFlags = DFE_ALL; - updatePortSettings(); + /*set up parameters*/ + commConfig.dcb.fBinary = TRUE; + commConfig.dcb.fInX = FALSE; + commConfig.dcb.fOutX = FALSE; + commConfig.dcb.fAbortOnError = FALSE; + commConfig.dcb.fNull = FALSE; + /* Dtr default to true. See Issue 122*/ + commConfig.dcb.fDtrControl = TRUE; + /*flush all settings*/ + settingsDirtyFlags = DFE_ALL; + updatePortSettings(); - //init event driven approach - if (queryMode == QextSerialPort::EventDriven) { - if (!SetCommMask(handle, EV_TXEMPTY | EV_RXCHAR | EV_DSR)) { - QESP_WARNING() << "failed to set Comm Mask. Error code:" << GetLastError(); - return false; - } + //init event driven approach + if (queryMode == QextSerialPort::EventDriven) { + if (!SetCommMask(handle, EV_TXEMPTY | EV_RXCHAR | EV_DSR)) { + QESP_WARNING() << "failed to set Comm Mask. Error code:" << GetLastError(); + return false; + } - winEventNotifier = new QWinEventNotifier(overlap.hEvent, q); - qRegisterMetaType("HANDLE"); - q->connect(winEventNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_onWinEvent(HANDLE)), Qt::DirectConnection); - WaitCommEvent(handle, &eventMask, &overlap); - } + winEventNotifier = new QWinEventNotifier(overlap.hEvent, q); + qRegisterMetaType("HANDLE"); + q->connect(winEventNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_onWinEvent(HANDLE)), Qt::DirectConnection); + WaitCommEvent(handle, &eventMask, &overlap); + } - return true; - } + return true; + } - return false; + return false; } bool QextSerialPortPrivate::close_sys() { - flush_sys(); - CancelIo(handle); + flush_sys(); + CancelIo(handle); - if (CloseHandle(handle)) { - handle = INVALID_HANDLE_VALUE; - } + if (CloseHandle(handle)) { + handle = INVALID_HANDLE_VALUE; + } - if (winEventNotifier) { - winEventNotifier->setEnabled(false); - winEventNotifier->deleteLater(); - winEventNotifier = 0; - } + if (winEventNotifier) { + winEventNotifier->setEnabled(false); + winEventNotifier->deleteLater(); + winEventNotifier = 0; + } - foreach (OVERLAPPED *o, pendingWrites) { - CloseHandle(o->hEvent); - delete o; - } + foreach (OVERLAPPED *o, pendingWrites) { + CloseHandle(o->hEvent); + delete o; + } - pendingWrites.clear(); - return true; + pendingWrites.clear(); + return true; } bool QextSerialPortPrivate::flush_sys() { - FlushFileBuffers(handle); - return true; + FlushFileBuffers(handle); + return true; } qint64 QextSerialPortPrivate::bytesAvailable_sys() const { - DWORD Errors; - COMSTAT Status; + DWORD Errors; + COMSTAT Status; - if (ClearCommError(handle, &Errors, &Status)) { - return Status.cbInQue; - } + if (ClearCommError(handle, &Errors, &Status)) { + return Status.cbInQue; + } - return (qint64) - 1; + return (qint64) - 1; } /* @@ -175,23 +181,23 @@ qint64 QextSerialPortPrivate::bytesAvailable_sys() const */ void QextSerialPortPrivate::translateError(ulong error) { - if (error & CE_BREAK) { - lastErr = E_BREAK_CONDITION; - } else if (error & CE_FRAME) { - lastErr = E_FRAMING_ERROR; - } else if (error & CE_IOE) { - lastErr = E_IO_ERROR; - } else if (error & CE_MODE) { - lastErr = E_INVALID_FD; - } else if (error & CE_OVERRUN) { - lastErr = E_BUFFER_OVERRUN; - } else if (error & CE_RXPARITY) { - lastErr = E_RECEIVE_PARITY_ERROR; - } else if (error & CE_RXOVER) { - lastErr = E_RECEIVE_OVERFLOW; - } else if (error & CE_TXFULL) { - lastErr = E_TRANSMIT_OVERFLOW; - } + if (error & CE_BREAK) { + lastErr = E_BREAK_CONDITION; + } else if (error & CE_FRAME) { + lastErr = E_FRAMING_ERROR; + } else if (error & CE_IOE) { + lastErr = E_IO_ERROR; + } else if (error & CE_MODE) { + lastErr = E_INVALID_FD; + } else if (error & CE_OVERRUN) { + lastErr = E_BUFFER_OVERRUN; + } else if (error & CE_RXPARITY) { + lastErr = E_RECEIVE_PARITY_ERROR; + } else if (error & CE_RXOVER) { + lastErr = E_RECEIVE_OVERFLOW; + } else if (error & CE_TXFULL) { + lastErr = E_TRANSMIT_OVERFLOW; + } } /* @@ -204,30 +210,30 @@ void QextSerialPortPrivate::translateError(ulong error) */ qint64 QextSerialPortPrivate::readData_sys(char *data, qint64 maxSize) { - DWORD bytesRead = 0; - bool failed = false; + DWORD bytesRead = 0; + bool failed = false; - if (queryMode == QextSerialPort::EventDriven) { - OVERLAPPED overlapRead; - ZeroMemory(&overlapRead, sizeof(OVERLAPPED)); + if (queryMode == QextSerialPort::EventDriven) { + OVERLAPPED overlapRead; + ZeroMemory(&overlapRead, sizeof(OVERLAPPED)); - if (!ReadFile(handle, (void *)data, (DWORD)maxSize, &bytesRead, &overlapRead)) { - if (GetLastError() == ERROR_IO_PENDING) { - GetOverlappedResult(handle, &overlapRead, &bytesRead, true); - } else { - failed = true; - } - } - } else if (!ReadFile(handle, (void *)data, (DWORD)maxSize, &bytesRead, NULL)) { - failed = true; - } + if (!ReadFile(handle, (void *)data, (DWORD)maxSize, &bytesRead, &overlapRead)) { + if (GetLastError() == ERROR_IO_PENDING) { + GetOverlappedResult(handle, &overlapRead, &bytesRead, true); + } else { + failed = true; + } + } + } else if (!ReadFile(handle, (void *)data, (DWORD)maxSize, &bytesRead, NULL)) { + failed = true; + } - if (!failed) { - return (qint64)bytesRead; - } + if (!failed) { + return (qint64)bytesRead; + } - lastErr = E_READ_FAILED; - return -1; + lastErr = E_READ_FAILED; + return -1; } /* @@ -240,79 +246,79 @@ qint64 QextSerialPortPrivate::readData_sys(char *data, qint64 maxSize) */ qint64 QextSerialPortPrivate::writeData_sys(const char *data, qint64 maxSize) { - DWORD bytesWritten = 0; - bool failed = false; + DWORD bytesWritten = 0; + bool failed = false; - if (queryMode == QextSerialPort::EventDriven) { - OVERLAPPED *newOverlapWrite = new OVERLAPPED; - ZeroMemory(newOverlapWrite, sizeof(OVERLAPPED)); - newOverlapWrite->hEvent = CreateEvent(NULL, true, false, NULL); + if (queryMode == QextSerialPort::EventDriven) { + OVERLAPPED *newOverlapWrite = new OVERLAPPED; + ZeroMemory(newOverlapWrite, sizeof(OVERLAPPED)); + newOverlapWrite->hEvent = CreateEvent(NULL, true, false, NULL); - if (WriteFile(handle, (void *)data, (DWORD)maxSize, &bytesWritten, newOverlapWrite)) { - CloseHandle(newOverlapWrite->hEvent); - delete newOverlapWrite; - } else if (GetLastError() == ERROR_IO_PENDING) { - // writing asynchronously...not an error - QWriteLocker writelocker(bytesToWriteLock); - pendingWrites.append(newOverlapWrite); - } else { - QESP_WARNING() << "QextSerialPort write error:" << GetLastError(); - failed = true; + if (WriteFile(handle, (void *)data, (DWORD)maxSize, &bytesWritten, newOverlapWrite)) { + CloseHandle(newOverlapWrite->hEvent); + delete newOverlapWrite; + } else if (GetLastError() == ERROR_IO_PENDING) { + // writing asynchronously...not an error + QWriteLocker writelocker(bytesToWriteLock); + pendingWrites.append(newOverlapWrite); + } else { + QESP_WARNING() << "QextSerialPort write error:" << GetLastError(); + failed = true; - if (!CancelIo(newOverlapWrite->hEvent)) { - QESP_WARNING("QextSerialPort: couldn't cancel IO"); - } + if (!CancelIo(newOverlapWrite->hEvent)) { + QESP_WARNING("QextSerialPort: couldn't cancel IO"); + } - if (!CloseHandle(newOverlapWrite->hEvent)) { - QESP_WARNING("QextSerialPort: couldn't close OVERLAPPED handle"); - } + if (!CloseHandle(newOverlapWrite->hEvent)) { + QESP_WARNING("QextSerialPort: couldn't close OVERLAPPED handle"); + } - delete newOverlapWrite; - } - } else if (!WriteFile(handle, (void *)data, (DWORD)maxSize, &bytesWritten, NULL)) { - failed = true; - } + delete newOverlapWrite; + } + } else if (!WriteFile(handle, (void *)data, (DWORD)maxSize, &bytesWritten, NULL)) { + failed = true; + } - if (!failed) { - return (qint64)bytesWritten; - } + if (!failed) { + return (qint64)bytesWritten; + } - lastErr = E_WRITE_FAILED; - return -1; + lastErr = E_WRITE_FAILED; + return -1; } void QextSerialPortPrivate::setDtr_sys(bool set) { - EscapeCommFunction(handle, set ? SETDTR : CLRDTR); + EscapeCommFunction(handle, set ? SETDTR : CLRDTR); } void QextSerialPortPrivate::setRts_sys(bool set) { - EscapeCommFunction(handle, set ? SETRTS : CLRRTS); + EscapeCommFunction(handle, set ? SETRTS : CLRRTS); } ulong QextSerialPortPrivate::lineStatus_sys(void) { - unsigned long Status = 0, Temp = 0; - GetCommModemStatus(handle, &Temp); + unsigned long Status = 0, Temp = 0; + GetCommModemStatus(handle, &Temp); - if (Temp & MS_CTS_ON) { - Status |= LS_CTS; - } + if (Temp & MS_CTS_ON) { + Status |= LS_CTS; + } - if (Temp & MS_DSR_ON) { - Status |= LS_DSR; - } + if (Temp & MS_DSR_ON) { + Status |= LS_DSR; + } - if (Temp & MS_RING_ON) { - Status |= LS_RI; - } + if (Temp & MS_RING_ON) { + Status |= LS_RI; + } - if (Temp & MS_RLSD_ON) { - Status |= LS_DCD; - } + if (Temp & MS_RLSD_ON) { + Status |= LS_DCD; + } - return Status; + return Status; } /* @@ -320,157 +326,157 @@ ulong QextSerialPortPrivate::lineStatus_sys(void) */ void QextSerialPortPrivate::_q_onWinEvent(HANDLE h) { - Q_Q(QextSerialPort); + Q_Q(QextSerialPort); - if (h == overlap.hEvent) { - if (eventMask & EV_RXCHAR) { - if (q->sender() != q && bytesAvailable_sys() > 0) { - _q_canRead(); - } - } + if (h == overlap.hEvent) { + if (eventMask & EV_RXCHAR) { + if (q->sender() != q && bytesAvailable_sys() > 0) { + _q_canRead(); + } + } - if (eventMask & EV_TXEMPTY) { - /* - A write completed. Run through the list of OVERLAPPED writes, and if - they completed successfully, take them off the list and delete them. - Otherwise, leave them on there so they can finish. - */ - qint64 totalBytesWritten = 0; - QList overlapsToDelete; + if (eventMask & EV_TXEMPTY) { + /* + A write completed. Run through the list of OVERLAPPED writes, and if + they completed successfully, take them off the list and delete them. + Otherwise, leave them on there so they can finish. + */ + qint64 totalBytesWritten = 0; + QList overlapsToDelete; - foreach (OVERLAPPED *o, pendingWrites) { - DWORD numBytes = 0; + foreach (OVERLAPPED *o, pendingWrites) { + DWORD numBytes = 0; - if (GetOverlappedResult(handle, o, &numBytes, false)) { - overlapsToDelete.append(o); - totalBytesWritten += numBytes; - } else if (GetLastError() != ERROR_IO_INCOMPLETE) { - overlapsToDelete.append(o); - QESP_WARNING() << "CommEvent overlapped write error:" << GetLastError(); - } - } + if (GetOverlappedResult(handle, o, &numBytes, false)) { + overlapsToDelete.append(o); + totalBytesWritten += numBytes; + } else if (GetLastError() != ERROR_IO_INCOMPLETE) { + overlapsToDelete.append(o); + QESP_WARNING() << "CommEvent overlapped write error:" << GetLastError(); + } + } - if (q->sender() != q && totalBytesWritten > 0) { - QWriteLocker writelocker(bytesToWriteLock); - Q_EMIT q->bytesWritten(totalBytesWritten); - } + if (q->sender() != q && totalBytesWritten > 0) { + QWriteLocker writelocker(bytesToWriteLock); + Q_EMIT q->bytesWritten(totalBytesWritten); + } - foreach (OVERLAPPED *o, overlapsToDelete) { - OVERLAPPED *toDelete = pendingWrites.takeAt(pendingWrites.indexOf(o)); - CloseHandle(toDelete->hEvent); - delete toDelete; - } - } + foreach (OVERLAPPED *o, overlapsToDelete) { + OVERLAPPED *toDelete = pendingWrites.takeAt(pendingWrites.indexOf(o)); + CloseHandle(toDelete->hEvent); + delete toDelete; + } + } - if (eventMask & EV_DSR) { - if (lineStatus_sys() & LS_DSR) { - Q_EMIT q->dsrChanged(true); - } else { - Q_EMIT q->dsrChanged(false); - } - } - } + if (eventMask & EV_DSR) { + if (lineStatus_sys() & LS_DSR) { + Q_EMIT q->dsrChanged(true); + } else { + Q_EMIT q->dsrChanged(false); + } + } + } - WaitCommEvent(handle, &eventMask, &overlap); + WaitCommEvent(handle, &eventMask, &overlap); } void QextSerialPortPrivate::updatePortSettings() { - if (!q_ptr->isOpen() || !settingsDirtyFlags) { - return; - } + if (!q_ptr->isOpen() || !settingsDirtyFlags) { + return; + } - //fill struct : COMMCONFIG - if (settingsDirtyFlags & DFE_BaudRate) { - commConfig.dcb.BaudRate = settings.BaudRate; - } + //fill struct : COMMCONFIG + if (settingsDirtyFlags & DFE_BaudRate) { + commConfig.dcb.BaudRate = settings.BaudRate; + } - if (settingsDirtyFlags & DFE_Parity) { - commConfig.dcb.Parity = (BYTE)settings.Parity; - commConfig.dcb.fParity = (settings.Parity == PAR_NONE) ? FALSE : TRUE; - } + if (settingsDirtyFlags & DFE_Parity) { + commConfig.dcb.Parity = (BYTE)settings.Parity; + commConfig.dcb.fParity = (settings.Parity == PAR_NONE) ? FALSE : TRUE; + } - if (settingsDirtyFlags & DFE_DataBits) { - commConfig.dcb.ByteSize = (BYTE)settings.DataBits; - } + if (settingsDirtyFlags & DFE_DataBits) { + commConfig.dcb.ByteSize = (BYTE)settings.DataBits; + } - if (settingsDirtyFlags & DFE_StopBits) { - switch (settings.StopBits) { - case STOP_1: - commConfig.dcb.StopBits = ONESTOPBIT; - break; + if (settingsDirtyFlags & DFE_StopBits) { + switch (settings.StopBits) { + case STOP_1: + commConfig.dcb.StopBits = ONESTOPBIT; + break; - case STOP_1_5: - commConfig.dcb.StopBits = ONE5STOPBITS; - break; + case STOP_1_5: + commConfig.dcb.StopBits = ONE5STOPBITS; + break; - case STOP_2: - commConfig.dcb.StopBits = TWOSTOPBITS; - break; - } - } + case STOP_2: + commConfig.dcb.StopBits = TWOSTOPBITS; + break; + } + } - if (settingsDirtyFlags & DFE_Flow) { - switch (settings.FlowControl) { - /*no flow control*/ - case FLOW_OFF: - commConfig.dcb.fOutxCtsFlow = FALSE; - commConfig.dcb.fRtsControl = RTS_CONTROL_DISABLE; - commConfig.dcb.fInX = FALSE; - commConfig.dcb.fOutX = FALSE; - break; + if (settingsDirtyFlags & DFE_Flow) { + switch (settings.FlowControl) { + /*no flow control*/ + case FLOW_OFF: + commConfig.dcb.fOutxCtsFlow = FALSE; + commConfig.dcb.fRtsControl = RTS_CONTROL_DISABLE; + commConfig.dcb.fInX = FALSE; + commConfig.dcb.fOutX = FALSE; + break; - /*software (XON/XOFF) flow control*/ - case FLOW_XONXOFF: - commConfig.dcb.fOutxCtsFlow = FALSE; - commConfig.dcb.fRtsControl = RTS_CONTROL_DISABLE; - commConfig.dcb.fInX = TRUE; - commConfig.dcb.fOutX = TRUE; - break; + /*software (XON/XOFF) flow control*/ + case FLOW_XONXOFF: + commConfig.dcb.fOutxCtsFlow = FALSE; + commConfig.dcb.fRtsControl = RTS_CONTROL_DISABLE; + commConfig.dcb.fInX = TRUE; + commConfig.dcb.fOutX = TRUE; + break; - /*hardware flow control*/ - case FLOW_HARDWARE: - commConfig.dcb.fOutxCtsFlow = TRUE; - commConfig.dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; - commConfig.dcb.fInX = FALSE; - commConfig.dcb.fOutX = FALSE; - break; - } - } + /*hardware flow control*/ + case FLOW_HARDWARE: + commConfig.dcb.fOutxCtsFlow = TRUE; + commConfig.dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; + commConfig.dcb.fInX = FALSE; + commConfig.dcb.fOutX = FALSE; + break; + } + } - //fill struct : COMMTIMEOUTS - if (settingsDirtyFlags & DFE_TimeOut) { - if (queryMode != QextSerialPort::EventDriven) { - int millisec = settings.Timeout_Millisec; + //fill struct : COMMTIMEOUTS + if (settingsDirtyFlags & DFE_TimeOut) { + if (queryMode != QextSerialPort::EventDriven) { + int millisec = settings.Timeout_Millisec; - if (millisec == -1) { - commTimeouts.ReadIntervalTimeout = MAXDWORD; - commTimeouts.ReadTotalTimeoutConstant = 0; - } else { - commTimeouts.ReadIntervalTimeout = millisec; - commTimeouts.ReadTotalTimeoutConstant = millisec; - } + if (millisec == -1) { + commTimeouts.ReadIntervalTimeout = MAXDWORD; + commTimeouts.ReadTotalTimeoutConstant = 0; + } else { + commTimeouts.ReadIntervalTimeout = millisec; + commTimeouts.ReadTotalTimeoutConstant = millisec; + } - commTimeouts.ReadTotalTimeoutMultiplier = 0; - commTimeouts.WriteTotalTimeoutMultiplier = millisec; - commTimeouts.WriteTotalTimeoutConstant = 0; - } else { - commTimeouts.ReadIntervalTimeout = MAXDWORD; - commTimeouts.ReadTotalTimeoutMultiplier = 0; - commTimeouts.ReadTotalTimeoutConstant = 0; - commTimeouts.WriteTotalTimeoutMultiplier = 0; - commTimeouts.WriteTotalTimeoutConstant = 0; - } - } + commTimeouts.ReadTotalTimeoutMultiplier = 0; + commTimeouts.WriteTotalTimeoutMultiplier = millisec; + commTimeouts.WriteTotalTimeoutConstant = 0; + } else { + commTimeouts.ReadIntervalTimeout = MAXDWORD; + commTimeouts.ReadTotalTimeoutMultiplier = 0; + commTimeouts.ReadTotalTimeoutConstant = 0; + commTimeouts.WriteTotalTimeoutMultiplier = 0; + commTimeouts.WriteTotalTimeoutConstant = 0; + } + } - if (settingsDirtyFlags & DFE_Settings_Mask) { - SetCommConfig(handle, &commConfig, sizeof(COMMCONFIG)); - } + if (settingsDirtyFlags & DFE_Settings_Mask) { + SetCommConfig(handle, &commConfig, sizeof(COMMCONFIG)); + } - if ((settingsDirtyFlags & DFE_TimeOut)) { - SetCommTimeouts(handle, &commTimeouts); - } + if ((settingsDirtyFlags & DFE_TimeOut)) { + SetCommTimeouts(handle, &commTimeouts); + } - settingsDirtyFlags = 0; + settingsDirtyFlags = 0; } diff --git a/emailtool/sendemail/sendemail.pri b/3rd_smtpclient/3rd_smtpclient.pri similarity index 86% rename from emailtool/sendemail/sendemail.pri rename to 3rd_smtpclient/3rd_smtpclient.pri index bb9bb07..90a51fd 100644 --- a/emailtool/sendemail/sendemail.pri +++ b/3rd_smtpclient/3rd_smtpclient.pri @@ -11,8 +11,7 @@ HEADERS += \ $$PWD/mimetext.h \ $$PWD/quotedprintable.h \ $$PWD/smtpclient.h \ - $$PWD/smtpmime.h \ - $$PWD/sendemailthread.h + $$PWD/smtpmime.h SOURCES += \ $$PWD/emailaddress.cpp \ @@ -26,5 +25,4 @@ SOURCES += \ $$PWD/mimepart.cpp \ $$PWD/mimetext.cpp \ $$PWD/quotedprintable.cpp \ - $$PWD/smtpclient.cpp \ - $$PWD/sendemailthread.cpp + $$PWD/smtpclient.cpp diff --git a/emailtool/sendemail/emailaddress.cpp b/3rd_smtpclient/emailaddress.cpp similarity index 100% rename from emailtool/sendemail/emailaddress.cpp rename to 3rd_smtpclient/emailaddress.cpp diff --git a/emailtool/sendemail/emailaddress.h b/3rd_smtpclient/emailaddress.h similarity index 100% rename from emailtool/sendemail/emailaddress.h rename to 3rd_smtpclient/emailaddress.h diff --git a/emailtool/sendemail/mimeattachment.cpp b/3rd_smtpclient/mimeattachment.cpp similarity index 100% rename from emailtool/sendemail/mimeattachment.cpp rename to 3rd_smtpclient/mimeattachment.cpp diff --git a/emailtool/sendemail/mimeattachment.h b/3rd_smtpclient/mimeattachment.h similarity index 100% rename from emailtool/sendemail/mimeattachment.h rename to 3rd_smtpclient/mimeattachment.h diff --git a/emailtool/sendemail/mimecontentformatter.cpp b/3rd_smtpclient/mimecontentformatter.cpp similarity index 100% rename from emailtool/sendemail/mimecontentformatter.cpp rename to 3rd_smtpclient/mimecontentformatter.cpp diff --git a/emailtool/sendemail/mimecontentformatter.h b/3rd_smtpclient/mimecontentformatter.h similarity index 100% rename from emailtool/sendemail/mimecontentformatter.h rename to 3rd_smtpclient/mimecontentformatter.h diff --git a/emailtool/sendemail/mimefile.cpp b/3rd_smtpclient/mimefile.cpp similarity index 100% rename from emailtool/sendemail/mimefile.cpp rename to 3rd_smtpclient/mimefile.cpp diff --git a/emailtool/sendemail/mimefile.h b/3rd_smtpclient/mimefile.h similarity index 100% rename from emailtool/sendemail/mimefile.h rename to 3rd_smtpclient/mimefile.h diff --git a/emailtool/sendemail/mimehtml.cpp b/3rd_smtpclient/mimehtml.cpp similarity index 100% rename from emailtool/sendemail/mimehtml.cpp rename to 3rd_smtpclient/mimehtml.cpp diff --git a/emailtool/sendemail/mimehtml.h b/3rd_smtpclient/mimehtml.h similarity index 100% rename from emailtool/sendemail/mimehtml.h rename to 3rd_smtpclient/mimehtml.h diff --git a/emailtool/sendemail/mimeinlinefile.cpp b/3rd_smtpclient/mimeinlinefile.cpp similarity index 100% rename from emailtool/sendemail/mimeinlinefile.cpp rename to 3rd_smtpclient/mimeinlinefile.cpp diff --git a/emailtool/sendemail/mimeinlinefile.h b/3rd_smtpclient/mimeinlinefile.h similarity index 100% rename from emailtool/sendemail/mimeinlinefile.h rename to 3rd_smtpclient/mimeinlinefile.h diff --git a/3rd_smtpclient/mimemessage.cpp b/3rd_smtpclient/mimemessage.cpp new file mode 100644 index 0000000..f419936 --- /dev/null +++ b/3rd_smtpclient/mimemessage.cpp @@ -0,0 +1,223 @@ +#include "mimemessage.h" + +#include +#include "quotedprintable.h" +#include + +MimeMessage::MimeMessage(bool createAutoMimeContent) : + hEncoding(MimePart::_8Bit) +{ + if (createAutoMimeContent) { + this->content = new MimeMultiPart(); + } +} + +MimeMessage::~MimeMessage() +{ +} + +MimePart &MimeMessage::getContent() +{ + return *content; +} + +void MimeMessage::setContent(MimePart *content) +{ + this->content = content; +} + +void MimeMessage::setSender(EmailAddress *e) +{ + this->sender = e; +} + +void MimeMessage::addRecipient(EmailAddress *rcpt, RecipientType type) +{ + switch (type) { + case To: + recipientsTo << rcpt; + break; + + case Cc: + recipientsCc << rcpt; + break; + + case Bcc: + recipientsBcc << rcpt; + break; + } +} + +void MimeMessage::addTo(EmailAddress *rcpt) +{ + this->recipientsTo << rcpt; +} + +void MimeMessage::addCc(EmailAddress *rcpt) +{ + this->recipientsCc << rcpt; +} + +void MimeMessage::addBcc(EmailAddress *rcpt) +{ + this->recipientsBcc << rcpt; +} + +void MimeMessage::setSubject(const QString &subject) +{ + this->subject = subject; +} + +void MimeMessage::addPart(MimePart *part) +{ + if (typeid(*content) == typeid(MimeMultiPart)) { + ((MimeMultiPart *) content)->addPart(part); + }; +} + +void MimeMessage::setHeaderEncoding(MimePart::Encoding hEnc) +{ + this->hEncoding = hEnc; +} + +const EmailAddress &MimeMessage::getSender() const +{ + return *sender; +} + +const QList &MimeMessage::getRecipients(RecipientType type) const +{ + switch (type) { + default: + case To: + return recipientsTo; + + case Cc: + return recipientsCc; + + case Bcc: + return recipientsBcc; + } +} + +const QString &MimeMessage::getSubject() const +{ + return subject; +} + +const QList &MimeMessage::getParts() const +{ + if (typeid(*content) == typeid(MimeMultiPart)) { + return ((MimeMultiPart *) content)->getParts(); + } else { + QList *res = new QList(); + res->append(content); + return *res; + } +} + +QString MimeMessage::toString() +{ + QString mime; + mime = "From:"; + + QByteArray name = sender->getName().toUtf8(); + if (name != "") { + switch (hEncoding) { + case MimePart::Base64: + mime += " =?utf-8?B?" + QByteArray().append(name).toBase64() + "?="; + break; + + case MimePart::QuotedPrintable: + mime += " =?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append(name)).replace(' ', "_").replace(':', "=3A") + "?="; + break; + + default: + mime += " " + name; + } + } + + mime += " <" + sender->getAddress() + ">\r\n"; + + mime += "To:"; + QList::iterator it; + int i; + + for (i = 0, it = recipientsTo.begin(); it != recipientsTo.end(); ++it, ++i) { + if (i != 0) { + mime += ","; + } + + QByteArray name = (*it)->getName().toUtf8(); + if (name != "") { + switch (hEncoding) { + case MimePart::Base64: + mime += " =?utf-8?B?" + QByteArray().append(name).toBase64() + "?="; + break; + + case MimePart::QuotedPrintable: + mime += " =?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append(name)).replace(' ', "_").replace(':', "=3A") + "?="; + break; + + default: + mime += " " + name; + } + } + + mime += " <" + (*it)->getAddress() + ">"; + } + + mime += "\r\n"; + if (recipientsCc.size() != 0) { + mime += "Cc:"; + } + + for (i = 0, it = recipientsCc.begin(); it != recipientsCc.end(); ++it, ++i) { + if (i != 0) { + mime += ","; + } + + QByteArray name = (*it)->getName().toUtf8(); + if (name != "") { + switch (hEncoding) { + case MimePart::Base64: + mime += " =?utf-8?B?" + QByteArray().append(name).toBase64() + "?="; + break; + + case MimePart::QuotedPrintable: + mime += " =?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append(name)).replace(' ', "_").replace(':', "=3A") + "?="; + break; + + default: + mime += " " + name; + } + } + + mime += " <" + (*it)->getAddress() + ">"; + } + + if (recipientsCc.size() != 0) { + mime += "\r\n"; + } + + mime += "Subject: "; + + switch (hEncoding) { + case MimePart::Base64: + mime += "=?utf-8?B?" + QByteArray().append(subject.toUtf8()).toBase64() + "?="; + break; + + case MimePart::QuotedPrintable: + mime += "=?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append(subject.toUtf8())).replace(' ', "_").replace(':', "=3A") + "?="; + break; + + default: + mime += subject; + } + + mime += "\r\n"; + mime += "MIME-Version: 1.0\r\n"; + + mime += content->toString(); + return mime; +} diff --git a/emailtool/sendemail/mimemessage.h b/3rd_smtpclient/mimemessage.h similarity index 100% rename from emailtool/sendemail/mimemessage.h rename to 3rd_smtpclient/mimemessage.h diff --git a/3rd_smtpclient/mimemultipart.cpp b/3rd_smtpclient/mimemultipart.cpp new file mode 100644 index 0000000..dfde103 --- /dev/null +++ b/3rd_smtpclient/mimemultipart.cpp @@ -0,0 +1,66 @@ +#include "mimemultipart.h" +#include "stdlib.h" +#include +#include + +const QString MULTI_PART_NAMES[] = { + "multipart/mixed", // Mixed + "multipart/digest", // Digest + "multipart/alternative", // Alternative + "multipart/related", // Related + "multipart/report", // Report + "multipart/signed", // Signed + "multipart/encrypted" // Encrypted +}; + +MimeMultiPart::MimeMultiPart(MultiPartType type) +{ + this->type = type; + this->cType = MULTI_PART_NAMES[this->type]; + this->cEncoding = _8Bit; + + QCryptographicHash md5(QCryptographicHash::Md5); + md5.addData(QByteArray().append(rand())); + cBoundary = md5.result().toHex(); +} + +MimeMultiPart::~MimeMultiPart() +{ + +} + +void MimeMultiPart::addPart(MimePart *part) +{ + parts.append(part); +} + +const QList &MimeMultiPart::getParts() const +{ + return parts; +} + +void MimeMultiPart::prepare() +{ + QList::iterator it; + content = ""; + + for (it = parts.begin(); it != parts.end(); it++) { + content += "--" + cBoundary.toUtf8() + "\r\n"; + (*it)->prepare(); + content += (*it)->toString().toUtf8(); + }; + + content += "--" + cBoundary.toUtf8() + "--\r\n"; + MimePart::prepare(); +} + +void MimeMultiPart::setMimeType(const MultiPartType type) +{ + this->type = type; + this->cType = MULTI_PART_NAMES[type]; +} + +MimeMultiPart::MultiPartType MimeMultiPart::getMimeType() const +{ + return type; +} diff --git a/emailtool/sendemail/mimemultipart.h b/3rd_smtpclient/mimemultipart.h similarity index 100% rename from emailtool/sendemail/mimemultipart.h rename to 3rd_smtpclient/mimemultipart.h diff --git a/emailtool/sendemail/mimepart.cpp b/3rd_smtpclient/mimepart.cpp similarity index 98% rename from emailtool/sendemail/mimepart.cpp rename to 3rd_smtpclient/mimepart.cpp index e9d0f65..5bcc457 100644 --- a/emailtool/sendemail/mimepart.cpp +++ b/3rd_smtpclient/mimepart.cpp @@ -142,7 +142,7 @@ void MimePart::prepare() break; } - if (cId != 0) { + if (cId.toInt() != 0) { mimeString.append("Content-ID: <").append(cId).append(">\r\n"); } diff --git a/emailtool/sendemail/mimepart.h b/3rd_smtpclient/mimepart.h similarity index 100% rename from emailtool/sendemail/mimepart.h rename to 3rd_smtpclient/mimepart.h diff --git a/emailtool/sendemail/mimetext.cpp b/3rd_smtpclient/mimetext.cpp similarity index 90% rename from emailtool/sendemail/mimetext.cpp rename to 3rd_smtpclient/mimetext.cpp index 5269051..f1161e9 100644 --- a/emailtool/sendemail/mimetext.cpp +++ b/3rd_smtpclient/mimetext.cpp @@ -23,6 +23,6 @@ const QString &MimeText::getText() const void MimeText::prepare() { this->content.clear(); - this->content.append(text); + this->content.append(text.toUtf8()); MimePart::prepare(); } diff --git a/emailtool/sendemail/mimetext.h b/3rd_smtpclient/mimetext.h similarity index 100% rename from emailtool/sendemail/mimetext.h rename to 3rd_smtpclient/mimetext.h diff --git a/emailtool/sendemail/quotedprintable.cpp b/3rd_smtpclient/quotedprintable.cpp similarity index 100% rename from emailtool/sendemail/quotedprintable.cpp rename to 3rd_smtpclient/quotedprintable.cpp diff --git a/emailtool/sendemail/quotedprintable.h b/3rd_smtpclient/quotedprintable.h similarity index 100% rename from emailtool/sendemail/quotedprintable.h rename to 3rd_smtpclient/quotedprintable.h diff --git a/emailtool/sendemail/smtpclient.cpp b/3rd_smtpclient/smtpclient.cpp similarity index 95% rename from emailtool/sendemail/smtpclient.cpp rename to 3rd_smtpclient/smtpclient.cpp index 17247d8..886c1b9 100644 --- a/emailtool/sendemail/smtpclient.cpp +++ b/3rd_smtpclient/smtpclient.cpp @@ -222,7 +222,7 @@ bool SmtpClient::login(const QString &user, const QString &password, AuthMethod try { if (method == AuthPlain) { // Sending command: AUTH PLAIN base64('\0' + username + '\0' + password) - sendMessage("AUTH PLAIN " + QByteArray().append((char) 0).append(user).append((char) 0).append(password).toBase64()); + sendMessage("AUTH PLAIN " + QByteArray().append((char) 0).append(user.toUtf8()).append((char) 0).append(password.toUtf8()).toBase64()); // Wait for the server's response waitForResponse(); @@ -245,7 +245,7 @@ bool SmtpClient::login(const QString &user, const QString &password, AuthMethod } // Send the username in base64 - sendMessage(QByteArray().append(user).toBase64()); + sendMessage(QByteArray().append(user.toUtf8()).toBase64()); // Wait for 334 waitForResponse(); @@ -256,7 +256,7 @@ bool SmtpClient::login(const QString &user, const QString &password, AuthMethod } // Send the password in base64 - sendMessage(QByteArray().append(password).toBase64()); + sendMessage(QByteArray().append(password.toUtf8()).toBase64()); // Wait for the server's responce waitForResponse(); @@ -354,7 +354,7 @@ void SmtpClient::quit() sendMessage("QUIT"); } -void SmtpClient::waitForResponse() throw (ResponseTimeoutException) +void SmtpClient::waitForResponse() { do { if (!socket->waitForReadyRead(responseTimeout)) { diff --git a/emailtool/sendemail/smtpclient.h b/3rd_smtpclient/smtpclient.h similarity index 97% rename from emailtool/sendemail/smtpclient.h rename to 3rd_smtpclient/smtpclient.h index 1fa072e..0cf2815 100644 --- a/emailtool/sendemail/smtpclient.h +++ b/3rd_smtpclient/smtpclient.h @@ -92,7 +92,7 @@ protected: int responseCode; class ResponseTimeoutException {}; - void waitForResponse() throw (ResponseTimeoutException); + void waitForResponse(); void sendMessage(const QString &text); signals: diff --git a/emailtool/sendemail/smtpmime.h b/3rd_smtpclient/smtpmime.h similarity index 100% rename from emailtool/sendemail/smtpmime.h rename to 3rd_smtpclient/smtpmime.h diff --git a/QWidgetDemo.pro b/QWidgetDemo.pro index 66ac2d6..4dadbac 100644 --- a/QWidgetDemo.pro +++ b/QWidgetDemo.pro @@ -24,7 +24,6 @@ SUBDIRS += maskwidget #遮罩层窗体 SUBDIRS += battery #电池电量控件 SUBDIRS += lineeditnext #文本框回车焦点下移 SUBDIRS += zhtopy #汉字转拼音 -SUBDIRS += qwtdemo #qwt的源码版本,无需插件,直接源码集成到你的项目即可 SUBDIRS += devicebutton #设备按钮地图效果 SUBDIRS += mouseline #鼠标定位十字线 SUBDIRS += emailtool #邮件发送工具 @@ -46,5 +45,12 @@ SUBDIRS += miniblink #miniblink示例 #如果你电脑对应的Qt版本有webkit或者webengine组件可以自行打开 #SUBDIRS += echartgauge #echart仪表盘含交互支持webkit及webengine -#designer项目只支持Qt4,如果是Qt4可以自行打开 + +lessThan(QT_MAJOR_VERSION, 4) { #SUBDIRS += designer #QtDesigner4源码 +} + +#qwt项目需要等官方适配了qwt组件才能适配 +lessThan(QT_MAJOR_VERSION, 6) { +SUBDIRS += qwtdemo #qwt的源码版本,无需插件,直接源码集成到你的项目即可 +} diff --git a/README.md b/README.md index d44fc54..dfb6d2c 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ 1. **可以选择打开QWidgetDemo.pro一次性编译所有的,也可以进入到目录下打开pro进行编译** 2. **如果发现有些子项目没有加载请打开QWidgetDemo.pro仔细看里面的注释** 3. **编译好的可执行文件在源码同级目录下的bin目录** +4. 亲测Qt4.6到Qt6.1所有版本,亲测win、linux、mac、uos等系统。 | 编号 | 文件夹 | 描述 | | ------ | ------ | ------ | diff --git a/base64/base64.pro b/base64/base64.pro index 850513e..6b1000a 100644 --- a/base64/base64.pro +++ b/base64/base64.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = base64 TEMPLATE = app diff --git a/battery/battery.cpp b/battery/battery.cpp index 9ef0ab1..0c9d816 100644 --- a/battery/battery.cpp +++ b/battery/battery.cpp @@ -128,11 +128,13 @@ void Battery::updateValue() if (isForward) { currentValue -= step; if (currentValue <= value) { + currentValue = value; timer->stop(); } } else { currentValue += step; if (currentValue >= value) { + currentValue = value; timer->stop(); } } diff --git a/battery/battery.h b/battery/battery.h index 7df5486..8dc5f1f 100644 --- a/battery/battery.h +++ b/battery/battery.h @@ -20,7 +20,8 @@ class Battery : public QWidget #endif { - Q_OBJECT + Q_OBJECT + Q_PROPERTY(double minValue READ getMinValue WRITE setMinValue) Q_PROPERTY(double maxValue READ getMaxValue WRITE setMaxValue) Q_PROPERTY(double value READ getValue WRITE setValue) @@ -54,7 +55,7 @@ protected: private slots: void updateValue(); -private: +private: double minValue; //最小值 double maxValue; //最大值 double value; //目标电量 @@ -80,7 +81,7 @@ private: QRectF batteryRect; //电池主体区域 QTimer *timer; //绘制定时器 -public: +public: double getMinValue() const; double getMaxValue() const; double getValue() const; diff --git a/battery/battery.pro b/battery/battery.pro index 236fb5f..477070a 100644 --- a/battery/battery.pro +++ b/battery/battery.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = battery TEMPLATE = app diff --git a/bgdemo/bgdemo.pro b/bgdemo/bgdemo.pro index e0cc918..b5ec7df 100644 --- a/bgdemo/bgdemo.pro +++ b/bgdemo/bgdemo.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = bgdemo TEMPLATE = app diff --git a/colorwidget/colorwidget.cpp b/colorwidget/colorwidget.cpp index 3409f21..53e6fe7 100644 --- a/colorwidget/colorwidget.cpp +++ b/colorwidget/colorwidget.cpp @@ -6,13 +6,18 @@ #include "qlabel.h" #include "qlineedit.h" #include "qapplication.h" -#include "qdesktopwidget.h" #include "qtimer.h" #include "qevent.h" #include "qdebug.h" -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) #include "qscreen.h" +#define deskGeometry qApp->primaryScreen()->geometry() +#define deskGeometry2 qApp->primaryScreen()->availableGeometry() +#else +#include "qdesktopwidget.h" +#define deskGeometry qApp->desktop()->geometry() +#define deskGeometry2 qApp->desktop()->availableGeometry() #endif ColorWidget *ColorWidget::instance = 0; @@ -130,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(QApplication::desktop()->winId(), x, y, 2, 2); +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) + QPixmap pixmap = QPixmap::grabWindow(qApp->desktop()->winId(), x, y, 2, 2); #else - QScreen *screen = QApplication::primaryScreen(); - QPixmap pixmap = screen->grabWindow(QApplication::desktop()->winId(), x, y, 2, 2); + QScreen *screen = qApp->primaryScreen(); + QPixmap pixmap = screen->grabWindow(0, x, y, 2, 2); #endif int red, green, blue; diff --git a/colorwidget/colorwidget.pro b/colorwidget/colorwidget.pro index 460cf1b..173071e 100644 --- a/colorwidget/colorwidget.pro +++ b/colorwidget/colorwidget.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = colorwidget TEMPLATE = app diff --git a/colorwidget/main.cpp b/colorwidget/main.cpp index e872570..6155c67 100644 --- a/colorwidget/main.cpp +++ b/colorwidget/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); a.setFont(QFont("Microsoft Yahei", 9)); -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if _MSC_VER QTextCodec *codec = QTextCodec::codecForName("gbk"); #else diff --git a/comtool/comtool.pro b/comtool/comtool.pro index d7d6259..3121037 100644 --- a/comtool/comtool.pro +++ b/comtool/comtool.pro @@ -7,6 +7,7 @@ QT += core gui network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = comtool TEMPLATE = app diff --git a/comtool/head.h b/comtool/head.h index e7bb6b6..63c0ee1 100644 --- a/comtool/head.h +++ b/comtool/head.h @@ -6,6 +6,9 @@ #include #endif -#include "appconfig.h" +#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) +#include +#endif #pragma execution_character_set("utf-8") +#include "appconfig.h" diff --git a/core_qui/iconfont.cpp b/core_qui/iconfont.cpp index 944e412..cba136f 100644 --- a/core_qui/iconfont.cpp +++ b/core_qui/iconfont.cpp @@ -15,7 +15,7 @@ IconFont *IconFont::Instance() } IconFont::IconFont(QObject *parent) : QObject(parent) -{ +{ //判断图形字体是否存在,不存在则加入 QFontDatabase fontDb; if (!fontDb.families().contains("iconfont")) { @@ -34,21 +34,21 @@ IconFont::IconFont(QObject *parent) : QObject(parent) } } -void IconFont::setIcon(QLabel *lab, const QChar &icon, quint32 size) +void IconFont::setIcon(QLabel *lab, int icon, quint32 size) { iconFont.setPixelSize(size); lab->setFont(iconFont); - lab->setText(icon); + lab->setText((QChar)icon); } -void IconFont::setIcon(QAbstractButton *btn, const QChar &icon, quint32 size) +void IconFont::setIcon(QAbstractButton *btn, int icon, quint32 size) { iconFont.setPixelSize(size); btn->setFont(iconFont); - btn->setText(icon); + btn->setText((QChar)icon); } -QPixmap IconFont::getPixmap(const QColor &color, const QChar &icon, quint32 size, +QPixmap IconFont::getPixmap(const QColor &color, int icon, quint32 size, quint32 pixWidth, quint32 pixHeight, int flags) { QPixmap pix(pixWidth, pixHeight); @@ -61,7 +61,7 @@ QPixmap IconFont::getPixmap(const QColor &color, const QChar &icon, quint32 size iconFont.setPixelSize(size); painter.setFont(iconFont); - painter.drawText(pix.rect(), flags, icon); + painter.drawText(pix.rect(), flags, (QChar)icon); painter.end(); return pix; @@ -90,16 +90,16 @@ void IconFont::setStyle(QWidget *widget, const QString &type, int borderWidth, c QString strBorder; if (type == "top") { strBorder = QString("border-width:%1px 0px 0px 0px;padding:%1px %2px %2px %2px;") - .arg(borderWidth).arg(borderWidth * 2); + .arg(borderWidth).arg(borderWidth * 2); } else if (type == "right") { strBorder = QString("border-width:0px %1px 0px 0px;padding:%2px %1px %2px %2px;") - .arg(borderWidth).arg(borderWidth * 2); + .arg(borderWidth).arg(borderWidth * 2); } else if (type == "bottom") { strBorder = QString("border-width:0px 0px %1px 0px;padding:%2px %2px %1px %2px;") - .arg(borderWidth).arg(borderWidth * 2); + .arg(borderWidth).arg(borderWidth * 2); } else if (type == "left") { strBorder = QString("border-width:0px 0px 0px %1px;padding:%2px %2px %2px %1px;") - .arg(borderWidth).arg(borderWidth * 2); + .arg(borderWidth).arg(borderWidth * 2); } QStringList qss; @@ -115,7 +115,7 @@ void IconFont::setStyle(QWidget *widget, const QString &type, int borderWidth, c widget->setStyleSheet(qss.join("")); } -void IconFont::setStyle(QWidget *widget, QList btns, QList icons, +void IconFont::setStyle(QWidget *widget, QList btns, QList icons, quint32 iconSize, quint32 iconWidth, quint32 iconHeight, const QString &type, int borderWidth, const QString &borderColor, const QString &normalBgColor, const QString &darkBgColor, @@ -130,16 +130,16 @@ void IconFont::setStyle(QWidget *widget, QList btns, QList QString strBorder; if (type == "top") { strBorder = QString("border-width:%1px 0px 0px 0px;padding:%1px %2px %2px %2px;") - .arg(borderWidth).arg(borderWidth * 2); + .arg(borderWidth).arg(borderWidth * 2); } else if (type == "right") { strBorder = QString("border-width:0px %1px 0px 0px;padding:%2px %1px %2px %2px;") - .arg(borderWidth).arg(borderWidth * 2); + .arg(borderWidth).arg(borderWidth * 2); } else if (type == "bottom") { strBorder = QString("border-width:0px 0px %1px 0px;padding:%2px %2px %1px %2px;") - .arg(borderWidth).arg(borderWidth * 2); + .arg(borderWidth).arg(borderWidth * 2); } else if (type == "left") { strBorder = QString("border-width:0px 0px 0px %1px;padding:%2px %2px %2px %1px;") - .arg(borderWidth).arg(borderWidth * 2); + .arg(borderWidth).arg(borderWidth * 2); } //如果图标是左侧显示则需要让没有选中的按钮左侧也有加深的边框,颜色为背景颜色 @@ -168,10 +168,11 @@ void IconFont::setStyle(QWidget *widget, QList btns, QList widget->setStyleSheet(qss.join("")); + //存储对应按钮对象,方便鼠标移上去的时候切换图片 for (int i = 0; i < btnCount; i++) { - //存储对应按钮对象,方便鼠标移上去的时候切换图片 - QPixmap pixNormal = getPixmap(normalTextColor, icons.at(i), iconSize, iconWidth, iconHeight); - QPixmap pixDark = getPixmap(darkTextColor, icons.at(i), iconSize, iconWidth, iconHeight); + int icon = icons.at(i); + QPixmap pixNormal = getPixmap(normalTextColor, icon, iconSize, iconWidth, iconHeight); + QPixmap pixDark = getPixmap(darkTextColor, icon, iconSize, iconWidth, iconHeight); btns.at(i)->setIcon(QIcon(pixNormal)); btns.at(i)->setIconSize(QSize(iconWidth, iconHeight)); @@ -183,7 +184,7 @@ void IconFont::setStyle(QWidget *widget, QList btns, QList } } -void IconFont::setStyle(QFrame *frame, QList btns, QList icons, +void IconFont::setStyle(QFrame *frame, QList btns, QList icons, quint32 iconSize, quint32 iconWidth, quint32 iconHeight, const QString &normalBgColor, const QString &darkBgColor, const QString &normalTextColor, const QString &darkTextColor) @@ -203,10 +204,11 @@ void IconFont::setStyle(QFrame *frame, QList btns, QList i frame->setStyleSheet(qss.join("")); - for (int i = 0; i < btnCount; i++) { - //存储对应按钮对象,方便鼠标移上去的时候切换图片 - QPixmap pixNormal = getPixmap(normalTextColor, icons.at(i), iconSize, iconWidth, iconHeight); - QPixmap pixDark = getPixmap(darkTextColor, icons.at(i), iconSize, iconWidth, iconHeight); + //存储对应按钮对象,方便鼠标移上去的时候切换图片 + for (int i = 0; i < btnCount; i++) { + int icon = icons.at(i); + QPixmap pixNormal = getPixmap(normalTextColor, icon, iconSize, iconWidth, iconHeight); + QPixmap pixDark = getPixmap(darkTextColor, icon, iconSize, iconWidth, iconHeight); btns.at(i)->setIcon(QIcon(pixNormal)); btns.at(i)->setIconSize(QSize(iconWidth, iconHeight)); diff --git a/core_qui/iconfont.h b/core_qui/iconfont.h index f8b5625..667ac8d 100644 --- a/core_qui/iconfont.h +++ b/core_qui/iconfont.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 @@ -20,9 +20,9 @@ public: static IconFont *Instance(); explicit IconFont(QObject *parent = 0); - void setIcon(QLabel *lab, const QChar &icon, quint32 size = 12); - void setIcon(QAbstractButton *btn, const QChar &icon, quint32 size = 12); - QPixmap getPixmap(const QColor &color, const QChar &icon, quint32 size = 12, + void setIcon(QLabel *lab, int icon, quint32 size = 12); + void setIcon(QAbstractButton *btn, int icon, quint32 size = 12); + QPixmap getPixmap(const QColor &color, int icon, quint32 size = 12, quint32 pixWidth = 15, quint32 pixHeight = 15, int flags = Qt::AlignCenter); @@ -38,7 +38,7 @@ public: const QString &darkTextColor = "#FDFDFD"); //指定导航面板样式,带图标和效果切换 - void setStyle(QWidget *widget, QList btns, QList icons, + void setStyle(QWidget *widget, QList btns, QList icons, quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15, const QString &type = "left", int borderWidth = 3, const QString &borderColor = "#029FEA", @@ -48,7 +48,7 @@ public: const QString &darkTextColor = "#FDFDFD"); //指定导航按钮样式,带图标和效果切换 - void setStyle(QFrame *frame, QList btns, QList icons, + void setStyle(QFrame *frame, QList btns, QList icons, quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15, const QString &normalBgColor = "#2FC5A2", const QString &darkBgColor = "#3EA7E9", diff --git a/core_qui/iconhelper.cpp b/core_qui/iconhelper.cpp index ab22f33..6e53df2 100644 --- a/core_qui/iconhelper.cpp +++ b/core_qui/iconhelper.cpp @@ -39,21 +39,21 @@ QFont IconHelper::getIconFont() return this->iconFont; } -void IconHelper::setIcon(QLabel *lab, const QChar &icon, quint32 size) +void IconHelper::setIcon(QLabel *lab, int icon, quint32 size) { iconFont.setPixelSize(size); lab->setFont(iconFont); - lab->setText(icon); + lab->setText((QChar)icon); } -void IconHelper::setIcon(QAbstractButton *btn, const QChar &icon, quint32 size) +void IconHelper::setIcon(QAbstractButton *btn, int icon, quint32 size) { iconFont.setPixelSize(size); btn->setFont(iconFont); - btn->setText(icon); + btn->setText((QChar)icon); } -QPixmap IconHelper::getPixmap(const QColor &color, const QChar &icon, quint32 size, +QPixmap IconHelper::getPixmap(const QColor &color, int icon, quint32 size, quint32 pixWidth, quint32 pixHeight, int flags) { QPixmap pix(pixWidth, pixHeight); @@ -66,7 +66,7 @@ QPixmap IconHelper::getPixmap(const QColor &color, const QChar &icon, quint32 si iconFont.setPixelSize(size); painter.setFont(iconFont); - painter.drawText(pix.rect(), flags, icon); + painter.drawText(pix.rect(), flags, (QChar)icon); painter.end(); return pix; @@ -106,7 +106,7 @@ QPixmap IconHelper::getPixmap(QToolButton *btn, int type) return pix; } -void IconHelper::setStyle(QFrame *frame, QList btns, QList icons, +void IconHelper::setStyle(QFrame *frame, QList btns, QList icons, quint32 iconSize, quint32 iconWidth, quint32 iconHeight, const QString &normalBgColor, const QString &darkBgColor, const QString &normalTextColor, const QString &darkTextColor) @@ -127,8 +127,9 @@ void IconHelper::setStyle(QFrame *frame, QList btns, QList //存储对应按钮对象,方便鼠标移上去的时候切换图片 for (int i = 0; i < btnCount; i++) { - QPixmap pixNormal = getPixmap(normalTextColor, icons.at(i), iconSize, iconWidth, iconHeight); - QPixmap pixDark = getPixmap(darkTextColor, icons.at(i), iconSize, iconWidth, iconHeight); + int icon = icons.at(i); + QPixmap pixNormal = getPixmap(normalTextColor, icon, iconSize, iconWidth, iconHeight); + QPixmap pixDark = getPixmap(darkTextColor, icon, iconSize, iconWidth, iconHeight); QToolButton *btn = btns.at(i); btn->setIcon(QIcon(pixNormal)); @@ -194,7 +195,7 @@ void IconHelper::removeStyle(QList btns) } } -void IconHelper::setStyle(QWidget *widget, QList btns, QList icons, +void IconHelper::setStyle(QWidget *widget, QList btns, QList icons, quint32 iconSize, quint32 iconWidth, quint32 iconHeight, const QString &type, int borderWidth, const QString &borderColor, const QString &normalBgColor, const QString &darkBgColor, @@ -247,8 +248,9 @@ void IconHelper::setStyle(QWidget *widget, QList btns, QListsetIcon(QIcon(pixNormal)); @@ -264,7 +266,7 @@ void IconHelper::setStyle(QWidget *widget, QList btns, QList btns, QList icons, const IconHelper::StyleColor &styleColor) +void IconHelper::setStyle(QWidget *widget, QList btns, QList icons, const IconHelper::StyleColor &styleColor) { int btnCount = btns.count(); int charCount = icons.count(); @@ -320,10 +322,11 @@ void IconHelper::setStyle(QWidget *widget, QList btns, QListsetIcon(QIcon(pixNormal)); diff --git a/core_qui/iconhelper.h b/core_qui/iconhelper.h index 728c2bc..28931ba 100644 --- a/core_qui/iconhelper.h +++ b/core_qui/iconhelper.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 @@ -24,12 +24,12 @@ public: QFont getIconFont(); //设置图形字体到标签 - void setIcon(QLabel *lab, const QChar &icon, quint32 size = 12); + void setIcon(QLabel *lab, int icon, quint32 size = 12); //设置图形字体到按钮 - void setIcon(QAbstractButton *btn, const QChar &icon, quint32 size = 12); + void setIcon(QAbstractButton *btn, int icon, quint32 size = 12); //获取指定图形字体,可以指定文字大小,图片宽高,文字对齐 - QPixmap getPixmap(const QColor &color, const QChar &icon, quint32 size = 12, + QPixmap getPixmap(const QColor &color, int icon, quint32 size = 12, quint32 pixWidth = 15, quint32 pixHeight = 15, int flags = Qt::AlignCenter); @@ -38,7 +38,7 @@ public: QPixmap getPixmap(QToolButton *btn, int type); //指定QFrame导航按钮样式,带图标 - void setStyle(QFrame *frame, QList btns, QList icons, + void setStyle(QFrame *frame, QList btns, QList icons, quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15, const QString &normalBgColor = "#2FC5A2", const QString &darkBgColor = "#3EA7E9", @@ -57,7 +57,7 @@ public: void removeStyle(QList btns); //指定QWidget导航面板样式,带图标和效果切换 - void setStyle(QWidget *widget, QList btns, QList icons, + void setStyle(QWidget *widget, QList btns, QList icons, quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15, const QString &type = "left", int borderWidth = 3, const QString &borderColor = "#029FEA", @@ -101,7 +101,7 @@ public: }; //指定QWidget导航面板样式,带图标和效果切换+悬停颜色+按下颜色+选中颜色 - void setStyle(QWidget *widget, QList btns, QList icons, const StyleColor &styleColor); + void setStyle(QWidget *widget, QList btns, QList icons, const StyleColor &styleColor); protected: bool eventFilter(QObject *watched, QEvent *event); diff --git a/core_qui/quiconfig.cpp b/core_qui/quiconfig.cpp index 1ed4f1f..9fe51fd 100644 --- a/core_qui/quiconfig.cpp +++ b/core_qui/quiconfig.cpp @@ -1,11 +1,11 @@ #include "quiconfig.h" -QChar QUIConfig::IconMain = 0xf072; -QChar QUIConfig::IconMenu = 0xf0d7; -QChar QUIConfig::IconMin = 0xf068; -QChar QUIConfig::IconMax = 0xf2d2; -QChar QUIConfig::IconNormal = 0xf2d0; -QChar QUIConfig::IconClose = 0xf00d; +int QUIConfig::IconMain = 0xf072; +int QUIConfig::IconMenu = 0xf0d7; +int QUIConfig::IconMin = 0xf068; +int QUIConfig::IconMax = 0xf2d2; +int QUIConfig::IconNormal = 0xf2d0; +int QUIConfig::IconClose = 0xf00d; #ifdef __arm__ QString QUIConfig::FontName = "WenQuanYi Micro Hei"; diff --git a/core_qui/quiconfig.h b/core_qui/quiconfig.h index b581e7f..b3a5d27 100644 --- a/core_qui/quiconfig.h +++ b/core_qui/quiconfig.h @@ -7,12 +7,12 @@ class QUIConfig { public: //全局图标 - static QChar IconMain; //标题栏左上角图标 - static QChar IconMenu; //下拉菜单图标 - static QChar IconMin; //最小化图标 - static QChar IconMax; //最大化图标 - static QChar IconNormal; //还原图标 - static QChar IconClose; //关闭图标 + static int IconMain; //标题栏左上角图标 + static int IconMenu; //下拉菜单图标 + static int IconMin; //最小化图标 + static int IconMax; //最大化图标 + static int IconNormal; //还原图标 + static int IconClose; //关闭图标 //全局字体 static QString FontName; //全局字体名称 diff --git a/core_qui/quidateselect.cpp b/core_qui/quidateselect.cpp index 515eb47..68f04ea 100644 --- a/core_qui/quidateselect.cpp +++ b/core_qui/quidateselect.cpp @@ -256,7 +256,7 @@ QString QUIDateSelect::getEndDateTime() const return this->endDateTime; } -void QUIDateSelect::setIconMain(const QChar &icon, quint32 size) +void QUIDateSelect::setIconMain(int icon, quint32 size) { IconHelper::Instance()->setIcon(this->labIco, icon, size); } diff --git a/core_qui/quidateselect.h b/core_qui/quidateselect.h index 759c3fc..ca402b4 100644 --- a/core_qui/quidateselect.h +++ b/core_qui/quidateselect.h @@ -57,7 +57,7 @@ public: QString getEndDateTime() const; public Q_SLOTS: - void setIconMain(const QChar &icon, quint32 size = 12); + void setIconMain(int icon, quint32 size = 12); void setFormat(const QString &format); }; diff --git a/core_qui/quihelper.cpp b/core_qui/quihelper.cpp index f0c346f..3ee8e4a 100644 --- a/core_qui/quihelper.cpp +++ b/core_qui/quihelper.cpp @@ -1,23 +1,24 @@ #include "quihelper.h" -QString QUIHelper::getUuid() -{ - QString uuid = QUuid::createUuid().toString(); - uuid = uuid.replace("{", ""); - uuid = uuid.replace("}", ""); - return uuid; -} - int QUIHelper::getScreenIndex() { //需要对多个屏幕进行处理 - int screenIndex = -1; + 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; } @@ -26,18 +27,50 @@ int QUIHelper::getScreenIndex() 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() { - int screenIndex = QUIHelper::getScreenIndex(); - int width = qApp->desktop()->availableGeometry(screenIndex).width(); - return width; + return getScreenRect().width(); } int QUIHelper::deskHeight() { - int screenIndex = QUIHelper::getScreenIndex(); - int height = qApp->desktop()->availableGeometry(screenIndex).height(); - return height; + return getScreenRect().height(); +} + +void QUIHelper::setFormInCenter(QWidget *form) +{ + int formWidth = form->width(); + int formHeight = form->height(); + QRect rect = getScreenRect(); + int deskWidth = rect.width(); + int deskHeight = rect.height(); + QPoint movePoint(deskWidth / 2 - formWidth / 2 + rect.x(), deskHeight / 2 - formHeight / 2); + form->move(movePoint); + + //其他系统自动最大化 +#ifndef Q_OS_WIN + QTimer::singleShot(100, form, SLOT(showMaximized())); +#endif } QString QUIHelper::appName() @@ -64,11 +97,98 @@ QString QUIHelper::appPath() #endif } +QString QUIHelper::getUuid() +{ + QString uuid = QUuid::createUuid().toString(); + uuid = uuid.replace("{", ""); + uuid = uuid.replace("}", ""); + return uuid; +} + void QUIHelper::initRand() { //初始化随机数种子 QTime t = QTime::currentTime(); - qsrand(t.msec() + t.second() * 1000); + 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::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::setFont(const QString &ttfFile, const QString &fontName, int fontSize) +{ + QFont font; + font.setFamily(fontName); + font.setPixelSize(fontSize); + + //如果存在字体文件则设备字体文件中的字体 + //安卓版本和网页版本需要字体文件一起打包单独设置字体 + if (!ttfFile.isEmpty()) { + QFontDatabase fontDb; + int fontId = fontDb.addApplicationFont(ttfFile); + if (fontId != -1) { + QStringList androidFont = fontDb.applicationFontFamilies(fontId); + if (androidFont.size() != 0) { + font.setFamily(androidFont.at(0)); + font.setPixelSize(fontSize); + } + } + } + qApp->setFont(font); +} + +void QUIHelper::setTranslator(const QString &qmFile) +{ + QTranslator *translator = new QTranslator(qApp); + translator->load(qmFile); + qApp->installTranslator(translator); } void QUIHelper::initDb(const QString &dbName) @@ -122,14 +242,14 @@ bool QUIHelper::checkIniFile(const QString &iniFile) return true; } -void QUIHelper::setIconBtn(QAbstractButton *btn, const QString &png, const QChar &str) +void QUIHelper::setIconBtn(QAbstractButton *btn, const QString &png, int icon) { int size = 16; int width = 18; int height = 18; QPixmap pix; if (QPixmap(png).isNull()) { - pix = IconHelper::Instance()->getPixmap(QUIConfig::TextColor, str, size, width, height); + pix = IconHelper::Instance()->getPixmap(QUIConfig::TextColor, icon, size, width, height); } else { pix = QPixmap(png); } @@ -138,22 +258,6 @@ void QUIHelper::setIconBtn(QAbstractButton *btn, const QString &png, const QChar btn->setIcon(QIcon(pix)); } -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::writeInfo(const QString &info, bool needWrite, const QString &filePath) { if (!needWrite) { @@ -231,80 +335,6 @@ void QUIHelper::setFramelessForm(QWidget *widgetMain, QWidget *widgetTitle, IconHelper::Instance()->setIcon(btnClose, QUIConfig::IconClose, QUIConfig::FontSize); } -void QUIHelper::setFormInCenter(QWidget *frm) -{ - //增加了多屏幕的判断在哪个屏幕就显示在哪个屏幕 - int screenIndex = QUIHelper::getScreenIndex(); - int frmX = frm->width(); - int frmY = frm->height(); - QDesktopWidget w; - QRect rect = w.availableGeometry(screenIndex); - int deskWidth = rect.width(); - int deskHeight = rect.height(); - QPoint movePoint(deskWidth / 2 - frmX / 2 + rect.x(), deskHeight / 2 - frmY / 2); - frm->move(movePoint); -} - -void QUIHelper::setTranslator(const QString &qmFile) -{ - QTranslator *translator = new QTranslator(qApp); - translator->load(qmFile); - qApp->installTranslator(translator); -} - -void QUIHelper::setCode() -{ -#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 - QTextCodec *codec = QTextCodec::codecForName("utf-8"); - QTextCodec::setCodecForLocale(codec); -#endif -} - -void QUIHelper::setFont(const QString &ttfFile, const QString &fontName, int fontSize) -{ - QFont font; - font.setFamily(fontName); - font.setPixelSize(fontSize); - - //如果存在字体文件则设备字体文件中的字体 - //安卓版本和网页版本需要字体文件一起打包单独设置字体 - if (!ttfFile.isEmpty()) { - QFontDatabase fontDb; - int fontId = fontDb.addApplicationFont(ttfFile); - if (fontId != -1) { - QStringList androidFont = fontDb.applicationFontFamilies(fontId); - if (androidFont.size() != 0) { - font.setFamily(androidFont.at(0)); - font.setPixelSize(fontSize); - } - } - } - qApp->setFont(font); -} - -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::setSystemDateTime(const QString &year, const QString &month, const QString &day, const QString &hour, const QString &min, const QString &sec) { #ifdef Q_OS_WIN @@ -340,8 +370,10 @@ QString QUIHelper::getIP(const QString &url) { //取出IP地址 QRegExp regExp("((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))"); - regExp.indexIn(url); - return url.mid(url.indexOf(regExp), regExp.matchedLength()); + int start = regExp.indexIn(url); + int length = regExp.matchedLength(); + QString ip = url.mid(start, length); + return ip; } bool QUIHelper::isIP(const QString &ip) @@ -1180,7 +1212,7 @@ void QUIHelper::initTableView(QTableView *tableView, int rowHeight, bool headVis tableView->setSelectionMode(QAbstractItemView::SingleSelection); //表头不可单击 -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) tableView->horizontalHeader()->setSectionsClickable(false); #else tableView->horizontalHeader()->setClickable(false); diff --git a/core_qui/quihelper.h b/core_qui/quihelper.h index 658af95..9d4d8b3 100644 --- a/core_qui/quihelper.h +++ b/core_qui/quihelper.h @@ -6,21 +6,32 @@ class QUIHelper { public: - //获取uuid - static QString getUuid(); - //获取当前鼠标所在屏幕 + //获取当前鼠标所在屏幕索引+尺寸 static int getScreenIndex(); + static QRect getScreenRect(bool available = true); - //桌面宽度高度 + //获取桌面宽度高度+居中显示 static int deskWidth(); static int deskHeight(); + 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 setCode(bool utf8 = true); + //设置字体 + static void setFont(const QString &ttfFile = ":/image/DroidSansFallback.ttf", + const QString &fontName = "Microsoft Yahei", int fontSize = 12); + //设置翻译文件 + static void setTranslator(const QString &qmFile = ":/image/qt_zh_CN.qm"); //初始化数据库 static void initDb(const QString &dbName); @@ -31,10 +42,7 @@ public: static bool checkIniFile(const QString &iniFile); //设置图标到按钮 - static void setIconBtn(QAbstractButton *btn, const QString &png, const QChar &str); - - //新建目录 - static void newDir(const QString &dirName); + static void setIconBtn(QAbstractButton *btn, const QString &png, int icon); //写入消息到额外的的消息日志文件 static void writeInfo(const QString &info, bool needWrite = false, const QString &filePath = "log"); @@ -47,18 +55,6 @@ public: QLabel *labIco, QPushButton *btnClose, bool tool = true, bool top = true, bool menu = false); - //设置窗体居中显示 - static void setFormInCenter(QWidget *frm); - //设置翻译文件 - static void setTranslator(const QString &qmFile = ":/image/qt_zh_CN.qm"); - //设置编码 - static void setCode(); - //设置字体 - static void setFont(const QString &ttfFile = ":/image/DroidSansFallback.ttf", - const QString &fontName = "Microsoft Yahei", int fontSize = 12); - - //设置延时 - static void sleep(int msec); //设置系统时间 static void setSystemDateTime(const QString &year, const QString &month, const QString &day, const QString &hour, const QString &min, const QString &sec); diff --git a/core_qui/quiinputbox.cpp b/core_qui/quiinputbox.cpp index 8a9ccd5..1f2e2db 100644 --- a/core_qui/quiinputbox.cpp +++ b/core_qui/quiinputbox.cpp @@ -285,7 +285,7 @@ void QUIInputBox::on_btnMenu_Close_clicked() close(); } -void QUIInputBox::setIconMain(const QChar &icon, quint32 size) +void QUIInputBox::setIconMain(int icon, quint32 size) { IconHelper::Instance()->setIcon(this->labIco, icon, size); } diff --git a/core_qui/quiinputbox.h b/core_qui/quiinputbox.h index 3b827b5..7ac4b1e 100644 --- a/core_qui/quiinputbox.h +++ b/core_qui/quiinputbox.h @@ -59,7 +59,7 @@ public: QString getValue()const; public Q_SLOTS: - void setIconMain(const QChar &icon, quint32 size = 12); + void setIconMain(int icon, quint32 size = 12); void setParameter(const QString &title, int type = 0, int closeSec = 0, QString placeholderText = QString(), bool pwd = false, const QString &defaultValue = QString()); diff --git a/core_qui/quimessagebox.cpp b/core_qui/quimessagebox.cpp index cb6e971..e428055 100644 --- a/core_qui/quimessagebox.cpp +++ b/core_qui/quimessagebox.cpp @@ -262,17 +262,17 @@ void QUIMessageBox::on_btnMenu_Close_clicked() close(); } -void QUIMessageBox::setIconMain(const QChar &icon, quint32 size) +void QUIMessageBox::setIconMain(int icon, quint32 size) { IconHelper::Instance()->setIcon(this->labIco, icon, size); } -void QUIMessageBox::setIconMsg(const QString &png, const QChar &str) +void QUIMessageBox::setIconMsg(const QString &png, int icon) { //图片存在则取图片,不存在则取图形字体 int size = this->labIcoMain->size().height(); if (QImage(png).isNull()) { - IconHelper::Instance()->setIcon(this->labIcoMain, str, size); + IconHelper::Instance()->setIcon(this->labIcoMain, icon, size); } else { this->labIcoMain->setStyleSheet(QString("border-image:url(%1);").arg(png)); } diff --git a/core_qui/quimessagebox.h b/core_qui/quimessagebox.h index b51f799..ffa769d 100644 --- a/core_qui/quimessagebox.h +++ b/core_qui/quimessagebox.h @@ -56,8 +56,8 @@ private slots: void on_btnMenu_Close_clicked(); public Q_SLOTS: - void setIconMain(const QChar &icon, quint32 size = 12); - void setIconMsg(const QString &png, const QChar &str); + void setIconMain(int icon, quint32 size = 12); + void setIconMsg(const QString &png, int icon); void setMessage(const QString &msg, int type, int closeSec = 0); }; diff --git a/core_qui/quitipbox.cpp b/core_qui/quitipbox.cpp index 2823112..9242ebd 100644 --- a/core_qui/quitipbox.cpp +++ b/core_qui/quitipbox.cpp @@ -198,7 +198,7 @@ void QUITipBox::on_btnMenu_Close_clicked() close(); } -void QUITipBox::setIconMain(const QChar &icon, quint32 size) +void QUITipBox::setIconMain(int icon, quint32 size) { IconHelper::Instance()->setIcon(this->labIco, icon, size); } @@ -216,8 +216,7 @@ void QUITipBox::setTip(const QString &title, const QString &tip, bool fullScreen this->labInfo->setAlignment(center ? Qt::AlignCenter : Qt::AlignLeft); this->setWindowTitle(this->labTitle->text()); - int screenIndex = QUIHelper::getScreenIndex(); - QRect rect = fullScreen ? qApp->desktop()->screenGeometry(screenIndex) : qApp->desktop()->availableGeometry(screenIndex); + QRect rect = QUIHelper::getScreenRect(!fullScreen); int width = rect.width(); int height = rect.height(); int x = width - this->width() + rect.x(); @@ -235,8 +234,7 @@ void QUITipBox::setTip(const QString &title, const QString &tip, bool fullScreen void QUITipBox::hide() { - int screenIndex = QUIHelper::getScreenIndex(); - QRect rect = fullScreen ? qApp->desktop()->screenGeometry(screenIndex) : qApp->desktop()->availableGeometry(screenIndex); + QRect rect = QUIHelper::getScreenRect(!fullScreen); int width = rect.width(); int height = rect.height(); int x = width - this->width() + rect.x(); @@ -245,7 +243,7 @@ void QUITipBox::hide() //启动动画 animation->stop(); animation->setStartValue(QPoint(x, y)); - animation->setEndValue(QPoint(x, qApp->desktop()->geometry().height())); + animation->setEndValue(QPoint(x, QUIHelper::getScreenRect(false).height())); animation->start(); } diff --git a/core_qui/quitipbox.h b/core_qui/quitipbox.h index 24d50c2..0b797f7 100644 --- a/core_qui/quitipbox.h +++ b/core_qui/quitipbox.h @@ -49,7 +49,7 @@ private slots: void on_btnMenu_Close_clicked(); public Q_SLOTS: - void setIconMain(const QChar &icon, quint32 size = 12); + void setIconMain(int icon, quint32 size = 12); void setTip(const QString &title, const QString &tip, bool fullScreen = false, bool center = true, int closeSec = 0); void hide(); }; diff --git a/core_qui/quiwidget.cpp b/core_qui/quiwidget.cpp index ba9f76e..c599c97 100644 --- a/core_qui/quiwidget.cpp +++ b/core_qui/quiwidget.cpp @@ -271,7 +271,7 @@ void QUIWidget::changeStyle() emit changeStyle(qssFile); } -void QUIWidget::setIcon(QUIWidget::Widget widget, const QChar &icon, quint32 size) +void QUIWidget::setIcon(QUIWidget::Widget widget, int icon, quint32 size) { if (widget == QUIWidget::Lab_Ico) { setIconMain(icon, size); @@ -293,7 +293,7 @@ void QUIWidget::setIcon(QUIWidget::Widget widget, const QChar &icon, quint32 siz } } -void QUIWidget::setIconMain(const QChar &icon, quint32 size) +void QUIWidget::setIconMain(int icon, quint32 size) { QUIConfig::IconMain = icon; IconHelper::Instance()->setIcon(this->labIco, icon, size); @@ -418,8 +418,7 @@ void QUIWidget::on_btnMenu_Max_clicked() setIcon(QUIWidget::BtnMenu_Normal, QUIConfig::IconNormal); } else { location = this->geometry(); - int screenIndex = QUIHelper::getScreenIndex(); - this->setGeometry(qApp->desktop()->availableGeometry(screenIndex)); + this->setGeometry(QUIHelper::getScreenRect()); setIcon(QUIWidget::BtnMenu_Max, QUIConfig::IconMax); } diff --git a/core_qui/quiwidget.h b/core_qui/quiwidget.h index a25b64f..98f9581 100644 --- a/core_qui/quiwidget.h +++ b/core_qui/quiwidget.h @@ -77,8 +77,8 @@ private slots: public Q_SLOTS: //设置部件图标 - void setIcon(QUIWidget::Widget widget, const QChar &icon, quint32 size = 12); - void setIconMain(const QChar &icon, quint32 size = 12); + void setIcon(QUIWidget::Widget widget, int icon, quint32 size = 12); + void setIconMain(int icon, quint32 size = 12); //设置部件图片 void setPixmap(QUIWidget::Widget widget, const QString &file, const QSize &size = QSize(16, 16)); //设置部件是否可见 diff --git a/countcode/countcode.pro b/countcode/countcode.pro index 0bba8e4..889765a 100644 --- a/countcode/countcode.pro +++ b/countcode/countcode.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = countcode TEMPLATE = app diff --git a/dbpage/dbpage.cpp b/dbpage/dbpage.cpp index 36d18b3..f2228e6 100644 --- a/dbpage/dbpage.cpp +++ b/dbpage/dbpage.cpp @@ -39,7 +39,7 @@ QVariant SqlQueryModel::data(const QModelIndex &index, int role) const if (row == index.row()) { if (role == Qt::BackgroundRole) { value = QColor(property("hoverBgColor").toString()); - } else if (role == Qt::TextColorRole) { + } else if (role == Qt::ForegroundRole) { value = QColor(property("hoverTextColor").toString()); } } diff --git a/dbpage/dbpage.pro b/dbpage/dbpage.pro index 273c568..bb55919 100644 --- a/dbpage/dbpage.pro +++ b/dbpage/dbpage.pro @@ -7,6 +7,7 @@ QT += core gui sql greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = dbpage TEMPLATE = app diff --git a/devicebutton/devicebutton.pro b/devicebutton/devicebutton.pro index cbd4038..ebbe199 100644 --- a/devicebutton/devicebutton.pro +++ b/devicebutton/devicebutton.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = devicebutton TEMPLATE = app diff --git a/devicesizetable/devicesizetable.h b/devicesizetable/devicesizetable.h index 4fb6057..a1fbc82 100644 --- a/devicesizetable/devicesizetable.h +++ b/devicesizetable/devicesizetable.h @@ -21,6 +21,7 @@ class DeviceSizeTable : public QTableWidget { Q_OBJECT + Q_PROPERTY(QColor bgColor READ getBgColor WRITE setBgColor) Q_PROPERTY(QColor chunkColor1 READ getChunkColor1 WRITE setChunkColor1) Q_PROPERTY(QColor chunkColor2 READ getChunkColor2 WRITE setChunkColor2) diff --git a/devicesizetable/devicesizetable.pro b/devicesizetable/devicesizetable.pro index 11fb450..943cb45 100644 --- a/devicesizetable/devicesizetable.pro +++ b/devicesizetable/devicesizetable.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = devicesizetable TEMPLATE = app diff --git a/emailtool/emailtool.pro b/emailtool/emailtool.pro index 614ff60..d1a8e42 100644 --- a/emailtool/emailtool.pro +++ b/emailtool/emailtool.pro @@ -4,9 +4,10 @@ # #------------------------------------------------- -QT += core gui network sql xml +QT += core gui network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = emailtool TEMPLATE = app @@ -14,10 +15,10 @@ DESTDIR = $$PWD/../bin CONFIG += warn_off SOURCES += main.cpp -SOURCES += frmemailtool.cpp -HEADERS += frmemailtool.h +SOURCES += frmemailtool.cpp sendemailthread.cpp +HEADERS += frmemailtool.h sendemailthread.h FORMS += frmemailtool.ui -include ($$PWD/sendemail/sendemail.pri) INCLUDEPATH += $$PWD -INCLUDEPATH += $$PWD/sendemail +INCLUDEPATH += $$PWD/../3rd_smtpclient +include ($$PWD/../3rd_smtpclient/3rd_smtpclient.pri) diff --git a/emailtool/frmemailtool.ui b/emailtool/frmemailtool.ui index 05e5549..6c5083d 100644 --- a/emailtool/frmemailtool.ui +++ b/emailtool/frmemailtool.ui @@ -13,174 +13,180 @@ Form - - - 6 - - - 6 - - - 6 - - - 6 - - - - - 用户名: - - - - - - - feiyangqingyun@126.com - - - - - - - 密码: - - - - - - - - - - QLineEdit::Password - - - - - - - 服务器: - - - - - - - - smtp.163.com - + + + + + + + PointingHandCursor + + + 发送 + + - - - smtp.126.com - + + + + + 25 + + + + + 465 + + + + + 587 + + + - - - smtp.qq.com - + + + + SSL + + - - - smt.sina.com - + + + + 服务端口 + + - - - smtp.sohu.com - + + + + PointingHandCursor + + + 浏览 + + - - - smtp.139.com - + + + + feiyangqingyun@163.com;517216493@qq.com + + - - - smtp.189.com - + + - - - - - - 端口: - - - - - - - - 25 - + + + + 邮件标题 + + - - - 465 - + + + + 测试邮件 + + - - - 587 - + + + + + smtp.163.com + + + + + smtp.126.com + + + + + smtp.qq.com + + + + + smt.sina.com + + + + + smtp.sohu.com + + + + + smtp.139.com + + + + + smtp.189.com + + + - + + + + 收件地址 + + + + + + + 选择附件 + + + + + + + 服务地址 + + + + + + + 用户名称 + + + + + + + feiyangqingyun@126.com + + + + + + + 用户密码 + + + + + + + + + + QLineEdit::Password + + + + - - - - SSL - - - - - - - PointingHandCursor - - - 发送 - - - - - - - 标 题: - - - - - - - 附 件: - - - - - - - 正 文: - - - - - - - PointingHandCursor - - - 浏览 - - - - - - - + false @@ -189,35 +195,27 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'宋体'; font-size:9pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">1</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、最短的爱情哲理小说:“</span><span style=" font-size:11pt;">你应该嫁给我啦?</span><span style=" font-family:'Times New Roman'; font-size:11pt;">” “ </span><span style=" font-size:11pt;">不</span><span style=" font-family:'Times New Roman'; font-size:11pt;">” </span><span style=" font-size:11pt;">于是他俩又继续幸福地生活在一起</span><span style=" font-family:'Times New Roman'; font-size:11pt;">!<br /></span><span style=" font-size:11pt;">2</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、近年来中国最精彩的写实小说,全文八个字:</span><span style=" font-family:'Times New Roman'; font-size:16pt; font-weight:600; font-style:italic; color:#ff007f;">此地钱多人傻速来</span><span style=" font-family:'Times New Roman'; font-size:11pt;">  据说是发自杭州市宝石山下一出租房的汇款单上的简短附言,是该按摩女给家乡妹妹汇 款时随手涂鸦的,令无数专业作家汗颜!<br /></span><span style=" font-size:11pt;">3</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、最短的幽默小说 《夜》 男:疼么?女:恩!男:算了?女:别!</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">4</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、最短的荒诞小说:有一个面包走在街上,它觉得自己很饿,就把自己吃了。<br /></span><span style=" font-size:11pt;">5</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、世界最短言情小说:他死的那天,孩子出生了。<br /></span><span style=" font-size:11pt;">6</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、世界最短武侠小说:</span><span style=" font-family:'Times New Roman'; font-size:11pt; font-weight:600; color:#00aa00;">高手被豆腐砸死了</span><span style=" font-family:'Times New Roman'; font-size:11pt;">。<br /></span><span style=" font-size:11pt;">7</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、世界最短科幻小说:最后一个地球人坐在家里,突然响起了敲门声。<br /></span><span style=" font-size:11pt;">8</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、世界最短悬疑小说:生,死,生。<br /></span><span style=" font-size:11pt;">9</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、世界最短推理小说:他死了,一定曾经活过。 <br />1</span><span style=" font-size:11pt;">0</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、世界最短恐怖小说:惊醒,身边躺着自己的尸体。</span></p></body></html> - - - - - - - 测试邮件 - - - - - - - 收件人: - - - - - - - feiyangqingyun@163.com;517216493@qq.com +</style></head><body style=" font-family:'SimSun'; font-size:9.07563pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'宋体'; font-size:11pt;">1</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、最短的爱情哲理小说:“</span><span style=" font-family:'宋体'; font-size:11pt;">你应该嫁给我啦?</span><span style=" font-family:'Times New Roman'; font-size:11pt;">” “ </span><span style=" font-family:'宋体'; font-size:11pt;">不</span><span style=" font-family:'Times New Roman'; font-size:11pt;">” </span><span style=" font-family:'宋体'; font-size:11pt;">于是他俩又继续幸福地生活在一起</span><span style=" font-family:'Times New Roman'; font-size:11pt;">!<br /></span><span style=" font-family:'宋体'; font-size:11pt;">2</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、近年来中国最精彩的写实小说,全文八个字:</span><span style=" font-family:'Times New Roman'; font-size:16pt; font-weight:600; font-style:italic; color:#ff007f;">此地钱多人傻速来</span><span style=" font-family:'Times New Roman'; font-size:11pt;">  据说是发自杭州市宝石山下一出租房的汇款单上的简短附言,是该按摩女给家乡妹妹汇 款时随手涂鸦的,令无数专业作家汗颜!<br /></span><span style=" font-family:'宋体'; font-size:11pt;">3</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、最短的幽默小说 《夜》 男:疼么?女:恩!男:算了?女:别!</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'宋体'; font-size:11pt;">4</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、最短的荒诞小说:有一个面包走在街上,它觉得自己很饿,就把自己吃了。<br /></span><span style=" font-family:'宋体'; font-size:11pt;">5</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、世界最短言情小说:他死的那天,孩子出生了。<br /></span><span style=" font-family:'宋体'; font-size:11pt;">6</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、世界最短武侠小说:</span><span style=" font-family:'Times New Roman'; font-size:11pt; font-weight:600; color:#00aa00;">高手被豆腐砸死了</span><span style=" font-family:'Times New Roman'; font-size:11pt;">。<br /></span><span style=" font-family:'宋体'; font-size:11pt;">7</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、世界最短科幻小说:最后一个地球人坐在家里,突然响起了敲门声。<br /></span><span style=" font-family:'宋体'; font-size:11pt;">8</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、世界最短悬疑小说:生,死,生。<br /></span><span style=" font-family:'宋体'; font-size:11pt;">9</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、世界最短推理小说:他死了,一定曾经活过。 <br />1</span><span style=" font-family:'宋体'; font-size:11pt;">0</span><span style=" font-family:'Times New Roman'; font-size:11pt;">、世界最短恐怖小说:惊醒,身边躺着自己的尸体。</span></p></body></html> + + txtSenderAddr + txtSenderPwd + cboxServer + cboxPort + ckSSL + txtTitle + txtReceiverAddr + btnSend + txtFileName + btnSelect + txtContent + diff --git a/emailtool/main.cpp b/emailtool/main.cpp index 3741ddc..6dbfb60 100644 --- a/emailtool/main.cpp +++ b/emailtool/main.cpp @@ -24,7 +24,7 @@ int main(int argc, char *argv[]) #endif frmEmailTool w; - w.setWindowTitle("邮件发送工具"); + w.setWindowTitle("串口调试助手 V2021 (QQ: 517216493 WX: feiyangqingyun)"); w.show(); return a.exec(); diff --git a/emailtool/sendemail/mimemessage.cpp b/emailtool/sendemail/mimemessage.cpp deleted file mode 100644 index 691bf74..0000000 --- a/emailtool/sendemail/mimemessage.cpp +++ /dev/null @@ -1,222 +0,0 @@ -#include "mimemessage.h" - -#include -#include "quotedprintable.h" -#include - -MimeMessage::MimeMessage(bool createAutoMimeContent) : - hEncoding(MimePart::_8Bit) -{ - if (createAutoMimeContent) { - this->content = new MimeMultiPart(); - } -} - -MimeMessage::~MimeMessage() -{ -} - -MimePart &MimeMessage::getContent() -{ - return *content; -} - -void MimeMessage::setContent(MimePart *content) -{ - this->content = content; -} - -void MimeMessage::setSender(EmailAddress *e) -{ - this->sender = e; -} - -void MimeMessage::addRecipient(EmailAddress *rcpt, RecipientType type) -{ - switch (type) { - case To: - recipientsTo << rcpt; - break; - - case Cc: - recipientsCc << rcpt; - break; - - case Bcc: - recipientsBcc << rcpt; - break; - } -} - -void MimeMessage::addTo(EmailAddress *rcpt) -{ - this->recipientsTo << rcpt; -} - -void MimeMessage::addCc(EmailAddress *rcpt) -{ - this->recipientsCc << rcpt; -} - -void MimeMessage::addBcc(EmailAddress *rcpt) -{ - this->recipientsBcc << rcpt; -} - -void MimeMessage::setSubject(const QString &subject) -{ - this->subject = subject; -} - -void MimeMessage::addPart(MimePart *part) -{ - if (typeid(*content) == typeid(MimeMultiPart)) { - ((MimeMultiPart *) content)->addPart(part); - }; -} - -void MimeMessage::setHeaderEncoding(MimePart::Encoding hEnc) -{ - this->hEncoding = hEnc; -} - -const EmailAddress &MimeMessage::getSender() const -{ - return *sender; -} - -const QList &MimeMessage::getRecipients(RecipientType type) const -{ - switch (type) { - default: - case To: - return recipientsTo; - - case Cc: - return recipientsCc; - - case Bcc: - return recipientsBcc; - } -} - -const QString &MimeMessage::getSubject() const -{ - return subject; -} - -const QList &MimeMessage::getParts() const -{ - if (typeid(*content) == typeid(MimeMultiPart)) { - return ((MimeMultiPart *) content)->getParts(); - } else { - QList *res = new QList(); - res->append(content); - return *res; - } -} - -QString MimeMessage::toString() -{ - QString mime; - - mime = "From:"; - - if (sender->getName() != "") { - switch (hEncoding) { - case MimePart::Base64: - mime += " =?utf-8?B?" + QByteArray().append(sender->getName()).toBase64() + "?="; - break; - - case MimePart::QuotedPrintable: - mime += " =?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append(sender->getName())).replace(' ', "_").replace(':', "=3A") + "?="; - break; - - default: - mime += " " + sender->getName(); - } - } - - mime += " <" + sender->getAddress() + ">\r\n"; - - mime += "To:"; - QList::iterator it; - int i; - - for (i = 0, it = recipientsTo.begin(); it != recipientsTo.end(); ++it, ++i) { - if (i != 0) { - mime += ","; - } - - if ((*it)->getName() != "") { - switch (hEncoding) { - case MimePart::Base64: - mime += " =?utf-8?B?" + QByteArray().append((*it)->getName()).toBase64() + "?="; - break; - - case MimePart::QuotedPrintable: - mime += " =?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append((*it)->getName())).replace(' ', "_").replace(':', "=3A") + "?="; - break; - - default: - mime += " " + (*it)->getName(); - } - } - - mime += " <" + (*it)->getAddress() + ">"; - } - - mime += "\r\n"; - - if (recipientsCc.size() != 0) { - mime += "Cc:"; - } - - for (i = 0, it = recipientsCc.begin(); it != recipientsCc.end(); ++it, ++i) { - if (i != 0) { - mime += ","; - } - - if ((*it)->getName() != "") { - switch (hEncoding) { - case MimePart::Base64: - mime += " =?utf-8?B?" + QByteArray().append((*it)->getName()).toBase64() + "?="; - break; - - case MimePart::QuotedPrintable: - mime += " =?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append((*it)->getName())).replace(' ', "_").replace(':', "=3A") + "?="; - break; - - default: - mime += " " + (*it)->getName(); - } - } - - mime += " <" + (*it)->getAddress() + ">"; - } - - if (recipientsCc.size() != 0) { - mime += "\r\n"; - } - - mime += "Subject: "; - - switch (hEncoding) { - case MimePart::Base64: - mime += "=?utf-8?B?" + QByteArray().append(subject).toBase64() + "?="; - break; - - case MimePart::QuotedPrintable: - mime += "=?utf-8?Q?" + QuotedPrintable::encode(QByteArray().append(subject)).replace(' ', "_").replace(':', "=3A") + "?="; - break; - - default: - mime += subject; - } - - mime += "\r\n"; - mime += "MIME-Version: 1.0\r\n"; - - mime += content->toString(); - return mime; -} diff --git a/emailtool/sendemail/mimemultipart.cpp b/emailtool/sendemail/mimemultipart.cpp deleted file mode 100644 index 27196f7..0000000 --- a/emailtool/sendemail/mimemultipart.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "mimemultipart.h" -#include -#include - -const QString MULTI_PART_NAMES[] = { - "multipart/mixed", // Mixed - "multipart/digest", // Digest - "multipart/alternative", // Alternative - "multipart/related", // Related - "multipart/report", // Report - "multipart/signed", // Signed - "multipart/encrypted" // Encrypted -}; - -MimeMultiPart::MimeMultiPart(MultiPartType type) -{ - this->type = type; - this->cType = MULTI_PART_NAMES[this->type]; - this->cEncoding = _8Bit; - - QCryptographicHash md5(QCryptographicHash::Md5); - md5.addData(QByteArray().append(qrand())); - cBoundary = md5.result().toHex(); -} - -MimeMultiPart::~MimeMultiPart() -{ - -} - -void MimeMultiPart::addPart(MimePart *part) -{ - parts.append(part); -} - -const QList &MimeMultiPart::getParts() const -{ - return parts; -} - -void MimeMultiPart::prepare() -{ - QList::iterator it; - - content = ""; - - for (it = parts.begin(); it != parts.end(); it++) { - content += "--" + cBoundary + "\r\n"; - (*it)->prepare(); - content += (*it)->toString(); - }; - - content += "--" + cBoundary + "--\r\n"; - - MimePart::prepare(); -} - -void MimeMultiPart::setMimeType(const MultiPartType type) -{ - this->type = type; - this->cType = MULTI_PART_NAMES[type]; -} - -MimeMultiPart::MultiPartType MimeMultiPart::getMimeType() const -{ - return type; -} diff --git a/emailtool/sendemail/sendemailthread.cpp b/emailtool/sendemailthread.cpp similarity index 99% rename from emailtool/sendemail/sendemailthread.cpp rename to emailtool/sendemailthread.cpp index d9cb259..e8a1993 100644 --- a/emailtool/sendemail/sendemailthread.cpp +++ b/emailtool/sendemailthread.cpp @@ -1,5 +1,5 @@ #include "sendemailthread.h" -#include "sendemail/smtpmime.h" +#include "smtpmime.h" #pragma execution_character_set("utf-8") #define TIMEMS qPrintable(QTime::currentTime().toString("hh:mm:ss zzz")) diff --git a/emailtool/sendemail/sendemailthread.h b/emailtool/sendemailthread.h similarity index 100% rename from emailtool/sendemail/sendemailthread.h rename to emailtool/sendemailthread.h diff --git a/ffmpegdemo/ffmpegdemo.pro b/ffmpegdemo/ffmpegdemo.pro index 47256a4..49bab23 100644 --- a/ffmpegdemo/ffmpegdemo.pro +++ b/ffmpegdemo/ffmpegdemo.pro @@ -1,6 +1,13 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2019-02-16T15:08:47 +# +#------------------------------------------------- + QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat android {QT += androidextras} TARGET = ffmpegdemo diff --git a/ffmpegdemo/main.cpp b/ffmpegdemo/main.cpp index 00d6b1c..b149321 100644 --- a/ffmpegdemo/main.cpp +++ b/ffmpegdemo/main.cpp @@ -1,9 +1,7 @@ #pragma execution_character_set("utf-8") #include "widget.h" - #include #include -#include int main(int argc, char *argv[]) { @@ -35,12 +33,5 @@ int main(int argc, char *argv[]) w.setWindowTitle("视频流播放ffmpeg内核 (QQ: 517216493)"); w.show(); - //居中显示窗体 - QDesktopWidget deskWidget; - int deskWidth = deskWidget.availableGeometry().width(); - int deskHeight = deskWidget.availableGeometry().height(); - QPoint movePoint(deskWidth / 2 - w.width() / 2, deskHeight / 2 - w.height() / 2); - w.move(movePoint); - return a.exec(); } diff --git a/flatui/flatui.h b/flatui/flatui.h index 0088b4d..da96658 100644 --- a/flatui/flatui.h +++ b/flatui/flatui.h @@ -29,7 +29,7 @@ class Q_DECL_EXPORT FlatUI class FlatUI #endif -{ +{ public: //设置按钮样式 static QString setPushButtonQss(QPushButton *btn, //按钮对象 diff --git a/flatui/flatui.pro b/flatui/flatui.pro index aa06d05..8f683bb 100644 --- a/flatui/flatui.pro +++ b/flatui/flatui.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = flatui TEMPLATE = app diff --git a/flatui/frmflatui.cpp b/flatui/frmflatui.cpp index 08248e3..804ce06 100644 --- a/flatui/frmflatui.cpp +++ b/flatui/frmflatui.cpp @@ -4,7 +4,6 @@ #include "ui_frmflatui.h" #include "flatui.h" #include "qdebug.h" -#include "qdesktopwidget.h" #include "qdatetime.h" frmFlatUI::frmFlatUI(QWidget *parent) : QWidget(parent), ui(new Ui::frmFlatUI) @@ -58,7 +57,7 @@ void frmFlatUI::initForm() FlatUI::setScrollBarQss(ui->verticalScrollBar, 8, 120, 20, "#606060", "#34495E", "#1ABC9C", "#E74C3C"); //设置列数和列宽 - int width = qApp->desktop()->availableGeometry().width() - 120; + int width = 1920; ui->tableWidget->setColumnCount(5); ui->tableWidget->setColumnWidth(0, width * 0.06); ui->tableWidget->setColumnWidth(1, width * 0.10); @@ -82,7 +81,6 @@ void frmFlatUI::initForm() for (int i = 0; i < 300; i++) { ui->tableWidget->setRowHeight(i, 24); - QTableWidgetItem *itemDeviceID = new QTableWidgetItem(QString::number(i + 1)); QTableWidgetItem *itemDeviceName = new QTableWidgetItem(QString("测试设备%1").arg(i + 1)); QTableWidgetItem *itemDeviceAddr = new QTableWidgetItem(QString::number(i + 1)); @@ -95,5 +93,4 @@ void frmFlatUI::initForm() ui->tableWidget->setItem(i, 3, itemContent); ui->tableWidget->setItem(i, 4, itemTime); } - } diff --git a/flatui/main.cpp b/flatui/main.cpp index 0ddb826..765c0e1 100644 --- a/flatui/main.cpp +++ b/flatui/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); a.setFont(QFont("Microsoft Yahei", 9)); -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if _MSC_VER QTextCodec *codec = QTextCodec::codecForName("gbk"); #else diff --git a/framelesswidget/framelesswidget.pro b/framelesswidget/framelesswidget.pro index ffc2845..b26e72b 100644 --- a/framelesswidget/framelesswidget.pro +++ b/framelesswidget/framelesswidget.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = framelesswidget TEMPLATE = app diff --git a/framelesswidget/frmframelesswidget.cpp b/framelesswidget/frmframelesswidget.cpp index 933f49f..e8b2f57 100644 --- a/framelesswidget/frmframelesswidget.cpp +++ b/framelesswidget/frmframelesswidget.cpp @@ -36,7 +36,7 @@ void frmFramelessWidget::initWidget(QWidget *w) //设置下背景颜色区别看 QPalette palette = w->palette(); - palette.setBrush(QPalette::Background, QColor(162, 121, 197)); + palette.setBrush(QPalette::Window, QColor(162, 121, 197)); w->setPalette(palette); QPushButton *btn = new QPushButton(w); diff --git a/framelesswidget/main.cpp b/framelesswidget/main.cpp index 39b7479..a51e854 100644 --- a/framelesswidget/main.cpp +++ b/framelesswidget/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); a.setFont(QFont("Microsoft Yahei", 9)); -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if _MSC_VER QTextCodec *codec = QTextCodec::codecForName("gbk"); #else diff --git a/gifwidget/gifwidget.cpp b/gifwidget/gifwidget.cpp index 53638fa..d438e5d 100644 --- a/gifwidget/gifwidget.cpp +++ b/gifwidget/gifwidget.cpp @@ -13,13 +13,19 @@ #include "qtimer.h" #include "qdatetime.h" #include "qapplication.h" -#include "qdesktopwidget.h" #include "qdesktopservices.h" #include "qfiledialog.h" #include "qurl.h" #include "qdebug.h" -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) + +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) #include "qscreen.h" +#define deskGeometry qApp->primaryScreen()->geometry() +#define deskGeometry2 qApp->primaryScreen()->availableGeometry() +#else +#include "qdesktopwidget.h" +#define deskGeometry qApp->desktop()->geometry() +#define deskGeometry2 qApp->desktop()->availableGeometry() #endif QScopedPointer GifWidget::self; @@ -267,7 +273,7 @@ void GifWidget::saveImage() return; } -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#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); diff --git a/gifwidget/gifwidget.pro b/gifwidget/gifwidget.pro index b9ed176..5b27cd6 100644 --- a/gifwidget/gifwidget.pro +++ b/gifwidget/gifwidget.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = gifwidget TEMPLATE = app diff --git a/gifwidget/main.cpp b/gifwidget/main.cpp index 8c6b27f..ff0d396 100644 --- a/gifwidget/main.cpp +++ b/gifwidget/main.cpp @@ -11,7 +11,7 @@ int main(int argc, char *argv[]) a.setFont(QFont("Microsoft Yahei", 9)); a.setWindowIcon(QIcon(":/image/gifwidget.ico")); -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if _MSC_VER QTextCodec *codec = QTextCodec::codecForName("gbk"); #else diff --git a/imageswitch/imageswitch.pro b/imageswitch/imageswitch.pro index 548a8f3..7986074 100644 --- a/imageswitch/imageswitch.pro +++ b/imageswitch/imageswitch.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = imageswitch TEMPLATE = app diff --git a/ipaddress/ipaddress.h b/ipaddress/ipaddress.h index cc95f4e..cdbb5c3 100644 --- a/ipaddress/ipaddress.h +++ b/ipaddress/ipaddress.h @@ -24,6 +24,7 @@ class IPAddress : public QWidget { Q_OBJECT + Q_PROPERTY(QString ip READ getIP WRITE setIP) public: diff --git a/ipaddress/ipaddress.pro b/ipaddress/ipaddress.pro index 4d28b9e..cd5976f 100644 --- a/ipaddress/ipaddress.pro +++ b/ipaddress/ipaddress.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = ipaddress TEMPLATE = app diff --git a/lightbutton/lightbutton.cpp b/lightbutton/lightbutton.cpp index 148e45a..a0fe916 100644 --- a/lightbutton/lightbutton.cpp +++ b/lightbutton/lightbutton.cpp @@ -442,7 +442,7 @@ void LightButton::alarm() bgColor = normalColor; } else { textColor = QColor(255, 255, 255); - bgColor = alarmColor; + bgColor = alarmColor; } this->update(); diff --git a/lightbutton/lightbutton.h b/lightbutton/lightbutton.h index 7fa9fa6..dcc09d0 100644 --- a/lightbutton/lightbutton.h +++ b/lightbutton/lightbutton.h @@ -25,6 +25,7 @@ class LightButton : public QWidget { Q_OBJECT + Q_PROPERTY(QString text READ getText WRITE setText) Q_PROPERTY(QColor textColor READ getTextColor WRITE setTextColor) Q_PROPERTY(QColor alarmColor READ getAlarmColor WRITE setAlarmColor) diff --git a/lightbutton/lightbutton.pro b/lightbutton/lightbutton.pro index 16bf06e..8418c56 100644 --- a/lightbutton/lightbutton.pro +++ b/lightbutton/lightbutton.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = lightbutton TEMPLATE = app diff --git a/lineeditnext/lineeditnext.pro b/lineeditnext/lineeditnext.pro index 9226c90..73f4309 100644 --- a/lineeditnext/lineeditnext.pro +++ b/lineeditnext/lineeditnext.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = lineeditnext TEMPLATE = app diff --git a/live/livetool/trayicon.cpp b/live/livetool/trayicon.cpp index 133f973..98b5f49 100644 --- a/live/livetool/trayicon.cpp +++ b/live/livetool/trayicon.cpp @@ -4,14 +4,13 @@ #include "qmutex.h" #include "qmenu.h" #include "qapplication.h" -#include "qdesktopwidget.h" #include "qdebug.h" QScopedPointer TrayIcon::self; TrayIcon *TrayIcon::Instance() { if (self.isNull()) { - QMutex mutex; + static QMutex mutex; QMutexLocker locker(&mutex); if (self.isNull()) { self.reset(new TrayIcon); @@ -27,21 +26,21 @@ TrayIcon::TrayIcon(QObject *parent) : QObject(parent) trayIcon = new QSystemTrayIcon(this); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconIsActived(QSystemTrayIcon::ActivationReason))); - menu = new QMenu(QApplication::desktop()); + menu = new QMenu; exitDirect = true; } void TrayIcon::iconIsActived(QSystemTrayIcon::ActivationReason reason) { switch (reason) { - case QSystemTrayIcon::Trigger: - case QSystemTrayIcon::DoubleClick: { - mainWidget->showNormal(); - break; - } + case QSystemTrayIcon::Trigger: + case QSystemTrayIcon::DoubleClick: { + mainWidget->showNormal(); + break; + } - default: - break; + default: + break; } } diff --git a/live/livetool/trayicon.h b/live/livetool/trayicon.h index 8487d81..3eda414 100644 --- a/live/livetool/trayicon.h +++ b/live/livetool/trayicon.h @@ -3,10 +3,10 @@ /** * 托盘图标控件 作者:feiyangqingyun(QQ:517216493) 2017-1-8 - * 1:可设置托盘图标对应所属主窗体 - * 2:可设置托盘图标 - * 3:可设置提示信息 - * 4:自带右键菜单 + * 1. 可设置托盘图标对应所属主窗体 + * 2. 可设置托盘图标 + * 3. 可设置提示信息 + * 4. 自带右键菜单 */ #include @@ -15,13 +15,7 @@ class QMenu; #ifdef quc -#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) -#include -#else -#include -#endif - -class QDESIGNER_WIDGET_EXPORT TrayIcon : public QObject +class Q_DECL_EXPORT TrayIcon : public QObject #else class TrayIcon : public QObject #endif diff --git a/lunarcalendarwidget/lunarcalendarinfo.cpp b/lunarcalendarwidget/lunarcalendarinfo.cpp index 1d29861..e985081 100644 --- a/lunarcalendarwidget/lunarcalendarinfo.cpp +++ b/lunarcalendarwidget/lunarcalendarinfo.cpp @@ -235,45 +235,45 @@ int LunarCalendarInfo::getMonthDays(int year, int month) int loopDay = isLoopYear(year) ? 1 : 0; switch (month) { - case 1: - countDay = 31; - break; - case 2: - countDay = 28 + loopDay; - break; - case 3: - countDay = 31; - break; - case 4: - countDay = 30; - break; - case 5: - countDay = 31; - break; - case 6: - countDay = 30; - break; - case 7: - countDay = 31; - break; - case 8: - countDay = 31; - break; - case 9: - countDay = 30; - break; - case 10: - countDay = 31; - break; - case 11: - countDay = 30; - break; - case 12: - countDay = 31; - break; - default: - countDay = 30; - break; + case 1: + countDay = 31; + break; + case 2: + countDay = 28 + loopDay; + break; + case 3: + countDay = 31; + break; + case 4: + countDay = 30; + break; + case 5: + countDay = 31; + break; + case 6: + countDay = 30; + break; + case 7: + countDay = 31; + break; + case 8: + countDay = 31; + break; + case 9: + countDay = 30; + break; + case 10: + countDay = 31; + break; + case 11: + countDay = 30; + break; + case 12: + countDay = 31; + break; + default: + countDay = 30; + break; } return countDay; @@ -286,45 +286,45 @@ int LunarCalendarInfo::getTotalMonthDays(int year, int month) int loopDay = isLoopYear(year) ? 1 : 0; switch (month) { - case 1: - countDay = 0; - break; - case 2: - countDay = 31; - break; - case 3: - countDay = 59 + loopDay; - break; - case 4: - countDay = 90 + loopDay; - break; - case 5: - countDay = 120 + loopDay; - break; - case 6: - countDay = 151 + loopDay; - break; - case 7: - countDay = 181 + loopDay; - break; - case 8: - countDay = 212 + loopDay; - break; - case 9: - countDay = 243 + loopDay; - break; - case 10: - countDay = 273 + loopDay; - break; - case 11: - countDay = 304 + loopDay; - break; - case 12: - countDay = 334 + loopDay; - break; - default: - countDay = 0; - break; + case 1: + countDay = 0; + break; + case 2: + countDay = 31; + break; + case 3: + countDay = 59 + loopDay; + break; + case 4: + countDay = 90 + loopDay; + break; + case 5: + countDay = 120 + loopDay; + break; + case 6: + countDay = 151 + loopDay; + break; + case 7: + countDay = 181 + loopDay; + break; + case 8: + countDay = 212 + loopDay; + break; + case 9: + countDay = 243 + loopDay; + break; + case 10: + countDay = 273 + loopDay; + break; + case 11: + countDay = 304 + loopDay; + break; + case 12: + countDay = 334 + loopDay; + break; + default: + countDay = 0; + break; } return countDay; @@ -347,89 +347,89 @@ QString LunarCalendarInfo::getHoliday(int month, int day) QString strHoliday; switch (temp) { - case 0x0101: - strHoliday = "元旦"; - break; - case 0x020E: - strHoliday = "情人节"; - break; - case 0x0303: - strHoliday = "爱耳日"; - break; - case 0x0305: - strHoliday = "志愿者服务日"; - break; - case 0x0308: - strHoliday = "妇女节"; - break; - case 0x0309: - strHoliday = "保护母亲河"; - break; - case 0x030C: - strHoliday = "植树节"; - break; - case 0x030F: - strHoliday = "消费者权益日"; - break; - case 0x0401: - strHoliday = "愚人节"; - break; - case 0x0501: - strHoliday = "劳动节"; - break; - case 0x0504: - strHoliday = "青年节"; - break; - case 0x0601: - strHoliday = "儿童节"; - break; - case 0x0606: - strHoliday = "全国爱眼日"; - break; - case 0x0701: - strHoliday = "建党节"; - break; - case 0x0707: - strHoliday = "抗战纪念日"; - break; - case 0x0801: - strHoliday = "建军节"; - break; - case 0x090A: - strHoliday = "教师节"; - break; - case 0x0910: - strHoliday = "脑健康日"; - break; - case 0x0914: - strHoliday = "爱牙日"; - break; - case 0x0A01: - strHoliday = "国庆节"; - break; - case 0x0A0A: - strHoliday = "高血压日"; - break; - case 0x0A1C: - strHoliday = "男性健康日"; - break; - case 0x0B08: - strHoliday = "记者节"; - break; - case 0x0B09: - strHoliday = "消防宣传日"; - break; - case 0x0C04: - strHoliday = "法制宣传日"; - break; - case 0x0C18: - strHoliday = "平安夜"; - break; - case 0x0C19: - strHoliday = "圣诞节"; - break; - default: - break; + case 0x0101: + strHoliday = "元旦"; + break; + case 0x020E: + strHoliday = "情人节"; + break; + case 0x0303: + strHoliday = "爱耳日"; + break; + case 0x0305: + strHoliday = "志愿者服务日"; + break; + case 0x0308: + strHoliday = "妇女节"; + break; + case 0x0309: + strHoliday = "保护母亲河"; + break; + case 0x030C: + strHoliday = "植树节"; + break; + case 0x030F: + strHoliday = "消费者权益日"; + break; + case 0x0401: + strHoliday = "愚人节"; + break; + case 0x0501: + strHoliday = "劳动节"; + break; + case 0x0504: + strHoliday = "青年节"; + break; + case 0x0601: + strHoliday = "儿童节"; + break; + case 0x0606: + strHoliday = "全国爱眼日"; + break; + case 0x0701: + strHoliday = "建党节"; + break; + case 0x0707: + strHoliday = "抗战纪念日"; + break; + case 0x0801: + strHoliday = "建军节"; + break; + case 0x090A: + strHoliday = "教师节"; + break; + case 0x0910: + strHoliday = "脑健康日"; + break; + case 0x0914: + strHoliday = "爱牙日"; + break; + case 0x0A01: + strHoliday = "国庆节"; + break; + case 0x0A0A: + strHoliday = "高血压日"; + break; + case 0x0A1C: + strHoliday = "男性健康日"; + break; + case 0x0B08: + strHoliday = "记者节"; + break; + case 0x0B09: + strHoliday = "消防宣传日"; + break; + case 0x0C04: + strHoliday = "法制宣传日"; + break; + case 0x0C18: + strHoliday = "平安夜"; + break; + case 0x0C19: + strHoliday = "圣诞节"; + break; + default: + break; } return strHoliday; @@ -466,35 +466,35 @@ QString LunarCalendarInfo::getLunarFestival(int month, int day) QString strFestival; switch (temp) { - case 0x0101: - strFestival = "春节"; - break; - case 0x010F: - strFestival = "元宵节"; - break; - case 0x0202: - strFestival = "龙抬头"; - break; - case 0x0505: - strFestival = "端午节"; - break; - case 0x0707: - strFestival = "七夕节"; - break; - case 0x080F: - strFestival = "中秋节"; - break; - case 0x0909: - strFestival = "重阳节"; - break; - case 0x0C08: - strFestival = "腊八节"; - break; - case 0x0C1E: - strFestival = "除夕"; - break; - default: - break; + case 0x0101: + strFestival = "春节"; + break; + case 0x010F: + strFestival = "元宵节"; + break; + case 0x0202: + strFestival = "龙抬头"; + break; + case 0x0505: + strFestival = "端午节"; + break; + case 0x0707: + strFestival = "七夕节"; + break; + case 0x080F: + strFestival = "中秋节"; + break; + case 0x0909: + strFestival = "重阳节"; + break; + case 0x0C08: + strFestival = "腊八节"; + break; + case 0x0C1E: + strFestival = "除夕"; + break; + default: + break; } return strFestival; @@ -641,7 +641,7 @@ void LunarCalendarInfo::getLunarCalendarInfo(int year, int month, int day, //记录大小月的天数 29或30 int monthCount = 0; - if(((lunarCalendarTable.at(year - 1901) & 0x0060) >> 5) == 1) { + if (((lunarCalendarTable.at(year - 1901) & 0x0060) >> 5) == 1) { springOffset = (lunarCalendarTable.at(year - 1901) & 0x001F) - 1; } else { springOffset = (lunarCalendarTable.at(year - 1901) & 0x001F) - 1 + 31; @@ -649,7 +649,7 @@ void LunarCalendarInfo::getLunarCalendarInfo(int year, int month, int day, //如果是不闰年且不是2月份 +1 newYearOffset = monthAdd.at(month - 1) + day - 1; - if((!(year % 4)) && (month > 2)) { + if ((!(year % 4)) && (month > 2)) { newYearOffset++; } @@ -665,7 +665,7 @@ void LunarCalendarInfo::getLunarCalendarInfo(int year, int month, int day, index = 1; flag = 0; - if((lunarCalendarTable.at(year - 1901) & (0x80000 >> (index - 1))) == 0) { + if ((lunarCalendarTable.at(year - 1901) & (0x80000 >> (index - 1))) == 0) { monthCount = 29; } else { monthCount = 30; @@ -674,7 +674,7 @@ void LunarCalendarInfo::getLunarCalendarInfo(int year, int month, int day, while (newYearOffset >= monthCount) { newYearOffset -= monthCount; index++; - if (month == ((lunarCalendarTable.at(year - 1901) & 0xF00000) >> 20) ) { + if (month == ((lunarCalendarTable.at(year - 1901) & 0xF00000) >> 20)) { flag = ~flag; if (flag == 0) { month++; @@ -713,11 +713,11 @@ void LunarCalendarInfo::getLunarCalendarInfo(int year, int month, int day, springOffset -= monthCount; index--; - if(flag == 0) { + if (flag == 0) { month--; } - if(month == ((lunarCalendarTable.at(year - 1901) & 0xF00000) >> 20)) { + if (month == ((lunarCalendarTable.at(year - 1901) & 0xF00000) >> 20)) { flag = ~flag; } diff --git a/lunarcalendarwidget/lunarcalendaritem.cpp b/lunarcalendarwidget/lunarcalendaritem.cpp index 52a0828..a003656 100644 --- a/lunarcalendarwidget/lunarcalendaritem.cpp +++ b/lunarcalendarwidget/lunarcalendaritem.cpp @@ -224,7 +224,7 @@ void LunarCalendarItem::drawLunar(QPainter *painter) QFont font; font.setPixelSize(side / 5); - painter->setFont(font); + painter->setFont(font); QRect lunarRect(0, height / 2, width, height / 2); painter->drawText(lunarRect, Qt::AlignCenter, lunar); diff --git a/lunarcalendarwidget/lunarcalendarwidget.pro b/lunarcalendarwidget/lunarcalendarwidget.pro index d519cad..afd86c3 100644 --- a/lunarcalendarwidget/lunarcalendarwidget.pro +++ b/lunarcalendarwidget/lunarcalendarwidget.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = lunarcalendarwidget TEMPLATE = app diff --git a/maskwidget/main.cpp b/maskwidget/main.cpp index b7b9fdd..dcb3645 100644 --- a/maskwidget/main.cpp +++ b/maskwidget/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); a.setFont(QFont("Microsoft Yahei", 9)); -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if _MSC_VER QTextCodec *codec = QTextCodec::codecForName("gbk"); #else diff --git a/maskwidget/maskwidget.cpp b/maskwidget/maskwidget.cpp index 0cf5ede..0f1c047 100644 --- a/maskwidget/maskwidget.cpp +++ b/maskwidget/maskwidget.cpp @@ -2,10 +2,19 @@ #include "maskwidget.h" #include "qmutex.h" -#include "qdesktopwidget.h" #include "qapplication.h" #include "qdebug.h" +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) +#include "qscreen.h" +#define deskGeometry qApp->primaryScreen()->geometry() +#define deskGeometry2 qApp->primaryScreen()->availableGeometry() +#else +#include "qdesktopwidget.h" +#define deskGeometry qApp->desktop()->geometry() +#define deskGeometry2 qApp->desktop()->availableGeometry() +#endif + QScopedPointer MaskWidget::self; MaskWidget *MaskWidget::Instance() { @@ -27,7 +36,7 @@ MaskWidget::MaskWidget(QWidget *parent) : QWidget(parent) setBgColor(QColor(0, 0, 0)); //不设置主窗体则遮罩层大小为默认桌面大小 - this->setGeometry(qApp->desktop()->geometry()); + this->setGeometry(deskGeometry); this->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool); //绑定全局事件,过滤弹窗窗体进行处理 diff --git a/maskwidget/maskwidget.pro b/maskwidget/maskwidget.pro index 60f1992..92fe1cb 100644 --- a/maskwidget/maskwidget.pro +++ b/maskwidget/maskwidget.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = maskwidget TEMPLATE = app diff --git a/miniblink/miniblink.pro b/miniblink/miniblink.pro index 8f6af00..6be1fe9 100644 --- a/miniblink/miniblink.pro +++ b/miniblink/miniblink.pro @@ -1,5 +1,13 @@ -QT += core gui +#------------------------------------------------- +# +# Project created by QtCreator 2019-02-16T15:08:47 +# +#------------------------------------------------- + +QT += core gui + greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = miniblink TEMPLATE = app diff --git a/mouseline/mouseline.pro b/mouseline/mouseline.pro index e887ff4..c70bd02 100644 --- a/mouseline/mouseline.pro +++ b/mouseline/mouseline.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = mouseline TEMPLATE = app diff --git a/movewidget/main.cpp b/movewidget/main.cpp index f094e03..66fc9cd 100644 --- a/movewidget/main.cpp +++ b/movewidget/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); a.setFont(QFont("Microsoft Yahei", 9)); -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if _MSC_VER QTextCodec *codec = QTextCodec::codecForName("gbk"); #else diff --git a/movewidget/movewidget.pro b/movewidget/movewidget.pro index 10bae42..865856e 100644 --- a/movewidget/movewidget.pro +++ b/movewidget/movewidget.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = movewidget TEMPLATE = app diff --git a/mpvdemo/main.cpp b/mpvdemo/main.cpp index 82336ab..a6be2e6 100644 --- a/mpvdemo/main.cpp +++ b/mpvdemo/main.cpp @@ -1,9 +1,7 @@ #pragma execution_character_set("utf-8") #include "widget.h" - #include #include -#include int main(int argc, char *argv[]) { @@ -30,14 +28,7 @@ int main(int argc, char *argv[]) Widget w; w.setWindowTitle("视频流播放mpv内核 (QQ: 517216493)"); - w.show(); - - //居中显示窗体 - QDesktopWidget deskWidget; - int deskWidth = deskWidget.availableGeometry().width(); - int deskHeight = deskWidget.availableGeometry().height(); - QPoint movePoint(deskWidth / 2 - w.width() / 2, deskHeight / 2 - w.height() / 2); - w.move(movePoint); + w.show(); return a.exec(); } diff --git a/mpvdemo/mpvdemo.pro b/mpvdemo/mpvdemo.pro index d9843c3..98cd6a4 100644 --- a/mpvdemo/mpvdemo.pro +++ b/mpvdemo/mpvdemo.pro @@ -1,6 +1,13 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2019-02-16T15:08:47 +# +#------------------------------------------------- + QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = mpvdemo TEMPLATE = app diff --git a/navbutton/frmnavbutton.cpp b/navbutton/frmnavbutton.cpp index 2d9e2e1..57a0a1d 100644 --- a/navbutton/frmnavbutton.cpp +++ b/navbutton/frmnavbutton.cpp @@ -24,7 +24,7 @@ void frmNavButton::initForm() quint32 pixHeight = 15; //从图形字体获得图片,也可以从资源文件或者路径文件获取 - QChar icon = 0xf061; + int icon = 0xf061; QPixmap iconNormal = IconHelper::Instance()->getPixmap(QColor(100, 100, 100).name(), icon, size, pixWidth, pixHeight); QPixmap iconHover = IconHelper::Instance()->getPixmap(QColor(255, 255, 255).name(), icon, size, pixWidth, pixHeight); QPixmap iconCheck = IconHelper::Instance()->getPixmap(QColor(255, 255, 255).name(), icon, size, pixWidth, pixHeight); @@ -49,8 +49,8 @@ void frmNavButton::initForm() pixWidth = 20; pixHeight = 20; - QList pixChar; - pixChar << 0xf17b << 0xf002 << 0xf013 << 0xf021 << 0xf0e0 << 0xf135; + QList icons; + icons << 0xf17b << 0xf002 << 0xf013 << 0xf021 << 0xf0e0 << 0xf135; QColor normalBgColor = QColor("#2D9191"); QColor hoverBgColor = QColor("#187294"); QColor checkBgColor = QColor("#145C75"); @@ -72,7 +72,7 @@ void frmNavButton::initForm() btn->setIconSize(QSize(22, 22)); //分开设置图标 - QChar icon = pixChar.at(i); + int icon = icons.at(i); QPixmap iconNormal = IconHelper::Instance()->getPixmap(normalTextColor.name(), icon, size, pixWidth, pixHeight); QPixmap iconHover = IconHelper::Instance()->getPixmap(hoverTextColor.name(), icon, size, pixWidth, pixHeight); QPixmap iconCheck = IconHelper::Instance()->getPixmap(checkTextColor.name(), icon, size, pixWidth, pixHeight); @@ -114,7 +114,7 @@ void frmNavButton::initForm() btn->setIconSize(QSize(22, 22)); //分开设置图标 - QChar icon = pixChar.at(i); + int icon = icons.at(i); QPixmap iconNormal = IconHelper::Instance()->getPixmap(normalTextColor.name(), icon, size, pixWidth, pixHeight); QPixmap iconHover = IconHelper::Instance()->getPixmap(hoverTextColor.name(), icon, size, pixWidth, pixHeight); QPixmap iconCheck = IconHelper::Instance()->getPixmap(checkTextColor.name(), icon, size, pixWidth, pixHeight); @@ -192,7 +192,7 @@ void frmNavButton::initForm() btn->setIconSize(QSize(22, 22)); //分开设置图标 - QChar icon = pixChar.at(i); + int icon = icons.at(i); QPixmap iconNormal = IconHelper::Instance()->getPixmap(normalTextColor.name(), icon, size, pixWidth, pixHeight); QPixmap iconHover = IconHelper::Instance()->getPixmap(hoverTextColor.name(), icon, size, pixWidth, pixHeight); QPixmap iconCheck = IconHelper::Instance()->getPixmap(checkTextColor.name(), icon, size, pixWidth, pixHeight); @@ -232,7 +232,7 @@ void frmNavButton::initForm() btn->setIconSize(QSize(22, 22)); //分开设置图标 - QChar icon = pixChar.at(i); + int icon = icons.at(i); QPixmap iconNormal = IconHelper::Instance()->getPixmap(normalTextColor.name(), icon, size, pixWidth, pixHeight); QPixmap iconHover = IconHelper::Instance()->getPixmap(hoverTextColor.name(), icon, size, pixWidth, pixHeight); QPixmap iconCheck = IconHelper::Instance()->getPixmap(checkTextColor.name(), icon, size, pixWidth, pixHeight); diff --git a/navbutton/frmnavbutton.h b/navbutton/frmnavbutton.h index 08775dc..427aa8f 100644 --- a/navbutton/frmnavbutton.h +++ b/navbutton/frmnavbutton.h @@ -5,8 +5,7 @@ class NavButton; -namespace Ui -{ +namespace Ui { class frmNavButton; } diff --git a/navbutton/iconhelper.cpp b/navbutton/iconhelper.cpp index 356e065..6e53df2 100644 --- a/navbutton/iconhelper.cpp +++ b/navbutton/iconhelper.cpp @@ -34,21 +34,26 @@ IconHelper::IconHelper(QObject *parent) : QObject(parent) } } -void IconHelper::setIcon(QLabel *lab, const QChar &str, quint32 size) +QFont IconHelper::getIconFont() +{ + return this->iconFont; +} + +void IconHelper::setIcon(QLabel *lab, int icon, quint32 size) { iconFont.setPixelSize(size); lab->setFont(iconFont); - lab->setText(str); + lab->setText((QChar)icon); } -void IconHelper::setIcon(QAbstractButton *btn, const QChar &str, quint32 size) +void IconHelper::setIcon(QAbstractButton *btn, int icon, quint32 size) { iconFont.setPixelSize(size); btn->setFont(iconFont); - btn->setText(str); + btn->setText((QChar)icon); } -QPixmap IconHelper::getPixmap(const QColor &color, const QChar &str, quint32 size, +QPixmap IconHelper::getPixmap(const QColor &color, int icon, quint32 size, quint32 pixWidth, quint32 pixHeight, int flags) { QPixmap pix(pixWidth, pixHeight); @@ -61,7 +66,7 @@ QPixmap IconHelper::getPixmap(const QColor &color, const QChar &str, quint32 siz iconFont.setPixelSize(size); painter.setFont(iconFont); - painter.drawText(pix.rect(), flags, str); + painter.drawText(pix.rect(), flags, (QChar)icon); painter.end(); return pix; @@ -71,7 +76,6 @@ QPixmap IconHelper::getPixmap(QToolButton *btn, bool normal) { QPixmap pix; int index = btns.indexOf(btn); - if (index >= 0) { if (normal) { pix = pixNormal.at(index); @@ -83,28 +87,86 @@ QPixmap IconHelper::getPixmap(QToolButton *btn, bool normal) return pix; } +QPixmap IconHelper::getPixmap(QToolButton *btn, int type) +{ + QPixmap pix; + int index = btns.indexOf(btn); + if (index >= 0) { + if (type == 0) { + pix = pixNormal.at(index); + } else if (type == 1) { + pix = pixHover.at(index); + } else if (type == 2) { + pix = pixPressed.at(index); + } else if (type == 3) { + pix = pixChecked.at(index); + } + } + + return pix; +} + +void IconHelper::setStyle(QFrame *frame, QList btns, QList icons, + quint32 iconSize, quint32 iconWidth, quint32 iconHeight, + const QString &normalBgColor, const QString &darkBgColor, + const QString &normalTextColor, const QString &darkTextColor) +{ + int btnCount = btns.count(); + int charCount = icons.count(); + if (btnCount <= 0 || charCount <= 0 || btnCount != charCount) { + return; + } + + QStringList qss; + qss.append(QString("QFrame>QToolButton{border-style:none;border-width:0px;" + "background-color:%1;color:%2;}").arg(normalBgColor).arg(normalTextColor)); + qss.append(QString("QFrame>QToolButton:hover,QFrame>QToolButton:pressed,QFrame>QToolButton:checked" + "{background-color:%1;color:%2;}").arg(darkBgColor).arg(darkTextColor)); + + frame->setStyleSheet(qss.join("")); + + //存储对应按钮对象,方便鼠标移上去的时候切换图片 + for (int i = 0; i < btnCount; i++) { + int icon = icons.at(i); + QPixmap pixNormal = getPixmap(normalTextColor, icon, iconSize, iconWidth, iconHeight); + QPixmap pixDark = getPixmap(darkTextColor, icon, iconSize, iconWidth, iconHeight); + + QToolButton *btn = btns.at(i); + btn->setIcon(QIcon(pixNormal)); + btn->setIconSize(QSize(iconWidth, iconHeight)); + btn->installEventFilter(this); + + this->btns.append(btn); + this->pixNormal.append(pixNormal); + this->pixDark.append(pixDark); + this->pixHover.append(pixDark); + this->pixPressed.append(pixDark); + this->pixChecked.append(pixDark); + } +} + void IconHelper::setStyle(QWidget *widget, const QString &type, int borderWidth, const QString &borderColor, const QString &normalBgColor, const QString &darkBgColor, const QString &normalTextColor, const QString &darkTextColor) { QString strBorder; if (type == "top") { - strBorder = QString("border-width:%1px 0px 0px 0px;padding:%1px %2px %2px %2px;") - .arg(borderWidth).arg(borderWidth * 2); + strBorder = QString("border-width:%1px 0px 0px 0px;padding-top:%1px;padding-bottom:%2px;") + .arg(borderWidth).arg(borderWidth * 2); } else if (type == "right") { - strBorder = QString("border-width:0px %1px 0px 0px;padding:%2px %1px %2px %2px;") - .arg(borderWidth).arg(borderWidth * 2); + strBorder = QString("border-width:0px %1px 0px 0px;padding-right:%1px;padding-left:%2px;") + .arg(borderWidth).arg(borderWidth * 2); } else if (type == "bottom") { - strBorder = QString("border-width:0px 0px %1px 0px;padding:%2px %2px %1px %2px;") - .arg(borderWidth).arg(borderWidth * 2); + strBorder = QString("border-width:0px 0px %1px 0px;padding-bottom:%1px;padding-top:%2px;") + .arg(borderWidth).arg(borderWidth * 2); } else if (type == "left") { - strBorder = QString("border-width:0px 0px 0px %1px;padding:%2px %2px %2px %1px;") - .arg(borderWidth).arg(borderWidth * 2); + strBorder = QString("border-width:0px 0px 0px %1px;padding-left:%1px;padding-right:%2px;") + .arg(borderWidth).arg(borderWidth * 2); } QStringList qss; - qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:none;border-radius:0px;padding:5px;color:%2;background:%3;}") - .arg(type).arg(normalTextColor).arg(normalBgColor)); + qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:none;border-radius:0px;padding:5px;" + "color:%2;background:%3;}").arg(type).arg(normalTextColor).arg(normalBgColor)); qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton:hover," "QWidget[flag=\"%1\"] QAbstractButton:pressed," @@ -115,31 +177,49 @@ void IconHelper::setStyle(QWidget *widget, const QString &type, int borderWidth, widget->setStyleSheet(qss.join("")); } -void IconHelper::setStyle(QWidget *widget, QList btns, QList pixChar, +void IconHelper::removeStyle(QList btns) +{ + for (int i = 0; i < btns.count(); i++) { + for (int j = 0; j < this->btns.count(); j++) { + if (this->btns.at(j) == btns.at(i)) { + this->btns.at(j)->removeEventFilter(this); + this->btns.removeAt(j); + this->pixNormal.removeAt(j); + this->pixDark.removeAt(j); + this->pixHover.removeAt(j); + this->pixPressed.removeAt(j); + this->pixChecked.removeAt(j); + break; + } + } + } +} + +void IconHelper::setStyle(QWidget *widget, QList btns, QList icons, quint32 iconSize, quint32 iconWidth, quint32 iconHeight, const QString &type, int borderWidth, const QString &borderColor, const QString &normalBgColor, const QString &darkBgColor, const QString &normalTextColor, const QString &darkTextColor) { int btnCount = btns.count(); - int charCount = pixChar.count(); + int charCount = icons.count(); if (btnCount <= 0 || charCount <= 0 || btnCount != charCount) { return; } QString strBorder; if (type == "top") { - strBorder = QString("border-width:%1px 0px 0px 0px;padding:%1px %2px %2px %2px;") - .arg(borderWidth).arg(borderWidth * 2); + strBorder = QString("border-width:%1px 0px 0px 0px;padding-top:%1px;padding-bottom:%2px;") + .arg(borderWidth).arg(borderWidth * 2); } else if (type == "right") { - strBorder = QString("border-width:0px %1px 0px 0px;padding:%2px %1px %2px %2px;") - .arg(borderWidth).arg(borderWidth * 2); + strBorder = QString("border-width:0px %1px 0px 0px;padding-right:%1px;padding-left:%2px;") + .arg(borderWidth).arg(borderWidth * 2); } else if (type == "bottom") { - strBorder = QString("border-width:0px 0px %1px 0px;padding:%2px %2px %1px %2px;") - .arg(borderWidth).arg(borderWidth * 2); + strBorder = QString("border-width:0px 0px %1px 0px;padding-bottom:%1px;padding-top:%2px;") + .arg(borderWidth).arg(borderWidth * 2); } else if (type == "left") { - strBorder = QString("border-width:0px 0px 0px %1px;padding:%2px %2px %2px %1px;") - .arg(borderWidth).arg(borderWidth * 2); + strBorder = QString("border-width:0px 0px 0px %1px;padding-left:%1px;padding-right:%2px;") + .arg(borderWidth).arg(borderWidth * 2); } //如果图标是左侧显示则需要让没有选中的按钮左侧也有加深的边框,颜色为背景颜色 @@ -159,62 +239,106 @@ void IconHelper::setStyle(QWidget *widget, QList btns, QList .arg(type).arg(strBorder).arg(borderColor).arg(darkTextColor).arg(darkBgColor)); qss.append(QString("QWidget#%1{background:%2;}").arg(widget->objectName()).arg(normalBgColor)); - - qss.append(QString("QWidget>QToolButton{border-width:0px;}")); - qss.append(QString("QWidget>QToolButton{background-color:%1;color:%2;}") - .arg(normalBgColor).arg(normalTextColor)); - qss.append(QString("QWidget>QToolButton:hover,QWidget>QToolButton:pressed,QWidget>QToolButton:checked{background-color:%1;color:%2;}") - .arg(darkBgColor).arg(darkTextColor)); + qss.append(QString("QWidget>QToolButton{border-width:0px;" + "background-color:%1;color:%2;}").arg(normalBgColor).arg(normalTextColor)); + qss.append(QString("QWidget>QToolButton:hover,QWidget>QToolButton:pressed,QWidget>QToolButton:checked{" + "background-color:%1;color:%2;}").arg(darkBgColor).arg(darkTextColor)); widget->setStyleSheet(qss.join("")); + //存储对应按钮对象,方便鼠标移上去的时候切换图片 for (int i = 0; i < btnCount; i++) { - //存储对应按钮对象,方便鼠标移上去的时候切换图片 - QPixmap pixNormal = getPixmap(normalTextColor, QChar(pixChar.at(i)), iconSize, iconWidth, iconHeight); - QPixmap pixDark = getPixmap(darkTextColor, QChar(pixChar.at(i)), iconSize, iconWidth, iconHeight); + int icon = icons.at(i); + QPixmap pixNormal = getPixmap(normalTextColor, icon, iconSize, iconWidth, iconHeight); + QPixmap pixDark = getPixmap(darkTextColor, icon, iconSize, iconWidth, iconHeight); - btns.at(i)->setIcon(QIcon(pixNormal)); - btns.at(i)->setIconSize(QSize(iconWidth, iconHeight)); - btns.at(i)->installEventFilter(this); + QToolButton *btn = btns.at(i); + btn->setIcon(QIcon(pixNormal)); + btn->setIconSize(QSize(iconWidth, iconHeight)); + btn->installEventFilter(this); - this->btns.append(btns.at(i)); + this->btns.append(btn); this->pixNormal.append(pixNormal); this->pixDark.append(pixDark); + this->pixHover.append(pixDark); + this->pixPressed.append(pixDark); + this->pixChecked.append(pixDark); } } -void IconHelper::setStyle(QFrame *frame, QList btns, QList pixChar, - quint32 iconSize, quint32 iconWidth, quint32 iconHeight, - const QString &normalBgColor, const QString &darkBgColor, - const QString &normalTextColor, const QString &darkTextColor) +void IconHelper::setStyle(QWidget *widget, QList btns, QList icons, const IconHelper::StyleColor &styleColor) { int btnCount = btns.count(); - int charCount = pixChar.count(); + int charCount = icons.count(); if (btnCount <= 0 || charCount <= 0 || btnCount != charCount) { return; } + quint32 iconSize = styleColor.iconSize; + quint32 iconWidth = styleColor.iconWidth; + quint32 iconHeight = styleColor.iconHeight; + quint32 borderWidth = styleColor.borderWidth; + QString type = styleColor.type; + + QString strBorder; + if (type == "top") { + strBorder = QString("border-width:%1px 0px 0px 0px;padding-top:%1px;padding-bottom:%2px;") + .arg(borderWidth).arg(borderWidth * 2); + } else if (type == "right") { + strBorder = QString("border-width:0px %1px 0px 0px;padding-right:%1px;padding-left:%2px;") + .arg(borderWidth).arg(borderWidth * 2); + } else if (type == "bottom") { + strBorder = QString("border-width:0px 0px %1px 0px;padding-bottom:%1px;padding-top:%2px;") + .arg(borderWidth).arg(borderWidth * 2); + } else if (type == "left") { + strBorder = QString("border-width:0px 0px 0px %1px;padding-left:%1px;padding-right:%2px;") + .arg(borderWidth).arg(borderWidth * 2); + } + + //如果图标是左侧显示则需要让没有选中的按钮左侧也有加深的边框,颜色为背景颜色 QStringList qss; - qss.append(QString("QFrame>QToolButton{border-style:none;border-width:0px;}")); - qss.append(QString("QFrame>QToolButton{background-color:%1;color:%2;}") - .arg(normalBgColor).arg(normalTextColor)); - qss.append(QString("QFrame>QToolButton:hover,QFrame>QToolButton:pressed,QFrame>QToolButton:checked{background-color:%1;color:%2;}") - .arg(darkBgColor).arg(darkTextColor)); + if (btns.at(0)->toolButtonStyle() == Qt::ToolButtonTextBesideIcon) { + qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:solid;border-radius:0px;%2border-color:%3;color:%4;background:%5;}") + .arg(type).arg(strBorder).arg(styleColor.normalBgColor).arg(styleColor.normalTextColor).arg(styleColor.normalBgColor)); + } else { + qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton{border-style:none;border-radius:0px;padding:5px;color:%2;background:%3;}") + .arg(type).arg(styleColor.normalTextColor).arg(styleColor.normalBgColor)); + } - frame->setStyleSheet(qss.join("")); + qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton:hover{border-style:solid;%2border-color:%3;color:%4;background:%5;}") + .arg(type).arg(strBorder).arg(styleColor.borderColor).arg(styleColor.hoverTextColor).arg(styleColor.hoverBgColor)); + qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton:pressed{border-style:solid;%2border-color:%3;color:%4;background:%5;}") + .arg(type).arg(strBorder).arg(styleColor.borderColor).arg(styleColor.pressedTextColor).arg(styleColor.pressedBgColor)); + qss.append(QString("QWidget[flag=\"%1\"] QAbstractButton:checked{border-style:solid;%2border-color:%3;color:%4;background:%5;}") + .arg(type).arg(strBorder).arg(styleColor.borderColor).arg(styleColor.checkedTextColor).arg(styleColor.checkedBgColor)); + qss.append(QString("QWidget#%1{background:%2;}").arg(widget->objectName()).arg(styleColor.normalBgColor)); + qss.append(QString("QWidget>QToolButton{border-width:0px;background-color:%1;color:%2;}").arg(styleColor.normalBgColor).arg(styleColor.normalTextColor)); + qss.append(QString("QWidget>QToolButton:hover{background-color:%1;color:%2;}").arg(styleColor.hoverBgColor).arg(styleColor.hoverTextColor)); + qss.append(QString("QWidget>QToolButton:pressed{background-color:%1;color:%2;}").arg(styleColor.pressedBgColor).arg(styleColor.pressedTextColor)); + qss.append(QString("QWidget>QToolButton:checked{background-color:%1;color:%2;}").arg(styleColor.checkedBgColor).arg(styleColor.checkedTextColor)); + + widget->setStyleSheet(qss.join("")); + + //存储对应按钮对象,方便鼠标移上去的时候切换图片 for (int i = 0; i < btnCount; i++) { - //存储对应按钮对象,方便鼠标移上去的时候切换图片 - QPixmap pixNormal = getPixmap(normalTextColor, QChar(pixChar.at(i)), iconSize, iconWidth, iconHeight); - QPixmap pixDark = getPixmap(darkTextColor, QChar(pixChar.at(i)), iconSize, iconWidth, iconHeight); + int icon = icons.at(i); + QPixmap pixNormal = getPixmap(styleColor.normalTextColor, icon, iconSize, iconWidth, iconHeight); + QPixmap pixHover = getPixmap(styleColor.hoverTextColor, icon, iconSize, iconWidth, iconHeight); + QPixmap pixPressed = getPixmap(styleColor.pressedTextColor, icon, iconSize, iconWidth, iconHeight); + QPixmap pixChecked = getPixmap(styleColor.checkedTextColor, icon, iconSize, iconWidth, iconHeight); - btns.at(i)->setIcon(QIcon(pixNormal)); - btns.at(i)->setIconSize(QSize(iconWidth, iconHeight)); - btns.at(i)->installEventFilter(this); + QToolButton *btn = btns.at(i); + btn->setIcon(QIcon(pixNormal)); + btn->setIconSize(QSize(iconWidth, iconHeight)); + btn->installEventFilter(this); - this->btns.append(btns.at(i)); + this->btns.append(btn); this->pixNormal.append(pixNormal); - this->pixDark.append(pixDark); + this->pixDark.append(pixHover); + this->pixHover.append(pixHover); + this->pixPressed.append(pixPressed); + this->pixChecked.append(pixChecked); } } @@ -225,10 +349,12 @@ bool IconHelper::eventFilter(QObject *watched, QEvent *event) int index = btns.indexOf(btn); if (index >= 0) { if (event->type() == QEvent::Enter) { - btn->setIcon(QIcon(pixDark.at(index))); + btn->setIcon(QIcon(pixHover.at(index))); + } else if (event->type() == QEvent::MouseButtonPress) { + btn->setIcon(QIcon(pixPressed.at(index))); } else if (event->type() == QEvent::Leave) { if (btn->isChecked()) { - btn->setIcon(QIcon(pixDark.at(index))); + btn->setIcon(QIcon(pixChecked.at(index))); } else { btn->setIcon(QIcon(pixNormal.at(index))); } diff --git a/navbutton/iconhelper.h b/navbutton/iconhelper.h index 992bc8d..28931ba 100644 --- a/navbutton/iconhelper.h +++ b/navbutton/iconhelper.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 @@ -20,14 +20,30 @@ public: static IconHelper *Instance(); explicit IconHelper(QObject *parent = 0); - void setIcon(QLabel *lab, const QChar &str, quint32 size = 12); - void setIcon(QAbstractButton *btn, const QChar &str, quint32 size = 12); - QPixmap getPixmap(const QColor &color, const QChar &str, quint32 size = 12, + //获取图形字体 + QFont getIconFont(); + + //设置图形字体到标签 + void setIcon(QLabel *lab, int icon, quint32 size = 12); + //设置图形字体到按钮 + void setIcon(QAbstractButton *btn, int icon, quint32 size = 12); + + //获取指定图形字体,可以指定文字大小,图片宽高,文字对齐 + QPixmap getPixmap(const QColor &color, int icon, quint32 size = 12, quint32 pixWidth = 15, quint32 pixHeight = 15, int flags = Qt::AlignCenter); //根据按钮获取该按钮对应的图标 QPixmap getPixmap(QToolButton *btn, bool normal); + QPixmap getPixmap(QToolButton *btn, int type); + + //指定QFrame导航按钮样式,带图标 + void setStyle(QFrame *frame, QList btns, QList icons, + quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15, + const QString &normalBgColor = "#2FC5A2", + const QString &darkBgColor = "#3EA7E9", + const QString &normalTextColor = "#EEEEEE", + const QString &darkTextColor = "#FFFFFF"); //指定导航面板样式,不带图标 static void setStyle(QWidget *widget, const QString &type = "left", int borderWidth = 3, @@ -37,8 +53,11 @@ public: const QString &normalTextColor = "#54626F", const QString &darkTextColor = "#FDFDFD"); - //指定导航面板样式,带图标和效果切换 - void setStyle(QWidget *widget, QList btns, QList pixChar, + //移除导航面板样式,防止重复 + void removeStyle(QList btns); + + //指定QWidget导航面板样式,带图标和效果切换 + void setStyle(QWidget *widget, QList btns, QList icons, quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15, const QString &type = "left", int borderWidth = 3, const QString &borderColor = "#029FEA", @@ -47,22 +66,56 @@ public: const QString &normalTextColor = "#54626F", const QString &darkTextColor = "#FDFDFD"); - //指定导航按钮样式,带图标和效果切换 - void setStyle(QFrame *frame, QList btns, QList pixChar, - quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15, - const QString &normalBgColor = "#2FC5A2", - const QString &darkBgColor = "#3EA7E9", - const QString &normalTextColor = "#EEEEEE", - const QString &darkTextColor = "#FFFFFF"); + struct StyleColor { + quint32 iconSize; + quint32 iconWidth; + quint32 iconHeight; + quint32 borderWidth; + QString type; + QString borderColor; + QString normalBgColor; + QString normalTextColor; + QString hoverBgColor; + QString hoverTextColor; + QString pressedBgColor; + QString pressedTextColor; + QString checkedBgColor; + QString checkedTextColor; + + StyleColor() { + iconSize = 12; + iconWidth = 15; + iconHeight = 15; + borderWidth = 3; + type = "left"; + borderColor = "#029FEA"; + normalBgColor = "#292F38"; + normalTextColor = "#54626F"; + hoverBgColor = "#40444D"; + hoverTextColor = "#FDFDFD"; + pressedBgColor = "#404244"; + pressedTextColor = "#FDFDFD"; + checkedBgColor = "#44494F"; + checkedTextColor = "#FDFDFD"; + } + }; + + //指定QWidget导航面板样式,带图标和效果切换+悬停颜色+按下颜色+选中颜色 + void setStyle(QWidget *widget, QList btns, QList icons, const StyleColor &styleColor); protected: bool eventFilter(QObject *watched, QEvent *event); private: static QScopedPointer self; + QFont iconFont; //图形字体 QList btns; //按钮队列 QList pixNormal; //正常图片队列 QList pixDark; //加深图片队列 + QList pixHover; //悬停图片队列 + QList pixPressed; //按下图片队列 + QList pixChecked; //选中图片队列 }; + #endif // ICONHELPER_H diff --git a/navbutton/main.cpp b/navbutton/main.cpp index a2d67c4..d1a7a66 100644 --- a/navbutton/main.cpp +++ b/navbutton/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); a.setFont(QFont("Microsoft Yahei", 9)); -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if _MSC_VER QTextCodec *codec = QTextCodec::codecForName("gbk"); #else diff --git a/navbutton/navbutton.pro b/navbutton/navbutton.pro index 31bb886..1ddf940 100644 --- a/navbutton/navbutton.pro +++ b/navbutton/navbutton.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = navbutton TEMPLATE = app diff --git a/netserver/head.h b/netserver/head.h index 8fa8768..63c0ee1 100644 --- a/netserver/head.h +++ b/netserver/head.h @@ -6,5 +6,9 @@ #include #endif +#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) +#include +#endif + #pragma execution_character_set("utf-8") #include "appconfig.h" diff --git a/netserver/netserver.pro b/netserver/netserver.pro index bc70821..600cec3 100644 --- a/netserver/netserver.pro +++ b/netserver/netserver.pro @@ -7,6 +7,7 @@ QT += core gui network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = netserver TEMPLATE = app diff --git a/nettool/head.h b/nettool/head.h index 4808e74..7adfea8 100644 --- a/nettool/head.h +++ b/nettool/head.h @@ -9,6 +9,9 @@ #endif #endif -#include "appconfig.h" +#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0)) +#include +#endif #pragma execution_character_set("utf-8") +#include "appconfig.h" diff --git a/nettool/nettool.pro b/nettool/nettool.pro index f9caf08..e284d27 100644 --- a/nettool/nettool.pro +++ b/nettool/nettool.pro @@ -14,6 +14,8 @@ QT += websockets DEFINES += websocket }} +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat + TARGET = nettool TEMPLATE = app RC_FILE = other/main.rc diff --git a/ntpclient/ntpclient.cpp b/ntpclient/ntpclient.cpp index 409123f..c87dda5 100644 --- a/ntpclient/ntpclient.cpp +++ b/ntpclient/ntpclient.cpp @@ -34,7 +34,7 @@ void NtpClient::sendData() qint8 STRATUM = 0; qint8 POLL = 4; qint8 PREC = -6; - QDateTime epoch(QDate(1900, 1, 1)); + QDateTime epoch(QDate(1900, 1, 1), QTime(0, 0, 0)); qint32 second = quint32(epoch.secsTo(QDateTime::currentDateTime())); qint32 temp = 0; @@ -59,8 +59,8 @@ void NtpClient::sendData() void NtpClient::readData() { QByteArray newTime; - QDateTime epoch(QDate(1900, 1, 1)); - QDateTime unixStart(QDate(1970, 1, 1)); + QDateTime epoch(QDate(1900, 1, 1), QTime(0, 0, 0)); + QDateTime unixStart(QDate(1970, 1, 1), QTime(0, 0, 0)); while (udpSocket->hasPendingDatagrams()) { newTime.resize(udpSocket->pendingDatagramSize()); @@ -79,7 +79,9 @@ void NtpClient::readData() } QDateTime dateTime; +#if (QT_VERSION < QT_VERSION_CHECK(6,0,0)) dateTime.setTime_t(seconds - epoch.secsTo(unixStart)); +#endif #ifdef __arm__ #ifdef arma9 diff --git a/ntpclient/ntpclient.pro b/ntpclient/ntpclient.pro index 7140f06..977d902 100644 --- a/ntpclient/ntpclient.pro +++ b/ntpclient/ntpclient.pro @@ -7,6 +7,7 @@ QT += core gui network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = ntpclient TEMPLATE = app diff --git a/pngtool/pngtool.pro b/pngtool/pngtool.pro index e3e86a8..cbee728 100644 --- a/pngtool/pngtool.pro +++ b/pngtool/pngtool.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = pngtool TEMPLATE = app diff --git a/savelog/main.cpp b/savelog/main.cpp index ada65d9..07c9a92 100644 --- a/savelog/main.cpp +++ b/savelog/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); a.setFont(QFont("Microsoft Yahei", 9)); -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if _MSC_VER QTextCodec *codec = QTextCodec::codecForName("gbk"); #else diff --git a/savelog/savelog.cpp b/savelog/savelog.cpp index 901b399..9bcf8c4 100644 --- a/savelog/savelog.cpp +++ b/savelog/savelog.cpp @@ -11,7 +11,7 @@ #define QDATE qPrintable(QDate::currentDate().toString("yyyy-MM-dd")) //日志重定向 -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) void Log(QtMsgType type, const char *msg) #else void Log(QtMsgType type, const QMessageLogContext &, const QString &msg) @@ -24,21 +24,21 @@ void Log(QtMsgType type, const QMessageLogContext &, const QString &msg) //这里可以根据不同的类型加上不同的头部用于区分 switch (type) { - case QtDebugMsg: - content = QString("%1").arg(msg); - break; + case QtDebugMsg: + content = QString("%1").arg(msg); + break; - case QtWarningMsg: - content = QString("%1").arg(msg); - break; + case QtWarningMsg: + content = QString("%1").arg(msg); + break; - case QtCriticalMsg: - content = QString("%1").arg(msg); - break; + case QtCriticalMsg: + content = QString("%1").arg(msg); + break; - case QtFatalMsg: - content = QString("%1").arg(msg); - break; + case QtFatalMsg: + content = QString("%1").arg(msg); + break; } SaveLog::Instance()->save(content); @@ -77,13 +77,13 @@ SaveLog::SaveLog(QObject *parent) : QObject(parent) SaveLog::~SaveLog() { - file->close(); + file->close(); } //安装日志钩子,输出调试信息到文件,便于调试 void SaveLog::start() { -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) qInstallMsgHandler(Log); #else qInstallMessageHandler(Log); @@ -93,7 +93,7 @@ void SaveLog::start() //卸载日志钩子 void SaveLog::stop() { -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) qInstallMsgHandler(0); #else qInstallMessageHandler(0); @@ -161,7 +161,7 @@ SendLog::SendLog(QObject *parent) connect(server, SIGNAL(newConnection()), this, SLOT(newConnection())); int listenPort = 6000; -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) server->listen(QHostAddress::AnyIPv4, listenPort); #else server->listen(QHostAddress::Any, listenPort); diff --git a/savelog/savelog.pro b/savelog/savelog.pro index 9b3db26..86ec593 100644 --- a/savelog/savelog.pro +++ b/savelog/savelog.pro @@ -7,6 +7,7 @@ QT += core gui network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = savelog TEMPLATE = app diff --git a/saveruntime/main.cpp b/saveruntime/main.cpp index 48dd92a..b8cee62 100644 --- a/saveruntime/main.cpp +++ b/saveruntime/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); a.setFont(QFont("Microsoft Yahei", 9)); -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if _MSC_VER QTextCodec *codec = QTextCodec::codecForName("gbk"); #else diff --git a/saveruntime/saveruntime.pro b/saveruntime/saveruntime.pro index 430ea87..998eedc 100644 --- a/saveruntime/saveruntime.pro +++ b/saveruntime/saveruntime.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = saveruntime TEMPLATE = app diff --git a/screenwidget/main.cpp b/screenwidget/main.cpp index a297357..3caa5e3 100644 --- a/screenwidget/main.cpp +++ b/screenwidget/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); a.setFont(QFont("Microsoft Yahei", 9)); -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if _MSC_VER QTextCodec *codec = QTextCodec::codecForName("gbk"); #else diff --git a/screenwidget/screenwidget.cpp b/screenwidget/screenwidget.cpp index 994662f..7913587 100644 --- a/screenwidget/screenwidget.cpp +++ b/screenwidget/screenwidget.cpp @@ -4,14 +4,19 @@ #include "qmutex.h" #include "qapplication.h" #include "qpainter.h" -#include "qdesktopwidget.h" #include "qfiledialog.h" #include "qevent.h" #include "qdatetime.h" #include "qstringlist.h" -#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION >= QT_VERSION_CHECK(5,0,0)) #include "qscreen.h" +#define deskGeometry qApp->primaryScreen()->geometry() +#define deskGeometry2 qApp->primaryScreen()->availableGeometry() +#else +#include "qdesktopwidget.h" +#define deskGeometry qApp->desktop()->geometry() +#define deskGeometry2 qApp->desktop()->availableGeometry() #endif #define STRDATETIME qPrintable (QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss")) @@ -174,7 +179,7 @@ ScreenWidget::ScreenWidget(QWidget *parent) : QWidget(parent) menu->addAction("退出截图", this, SLOT(hide())); //取得屏幕大小 - screen = new Screen(QApplication::desktop()->size()); + screen = new Screen(deskGeometry.size()); //保存全屏图像 fullScreen = new QPixmap(); } @@ -213,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(QApplication::desktop()->winId(), 0, 0, screen->width(), screen->height()); +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) + *fullScreen = fullScreen->grabWindow(0, 0, 0, screen->width(), screen->height()); #else QScreen *pscreen = QApplication::primaryScreen(); - *fullScreen = pscreen->grabWindow(QApplication::desktop()->winId(), 0, 0, screen->width(), screen->height()); + *fullScreen = pscreen->grabWindow(0, 0, 0, screen->width(), screen->height()); #endif //设置透明度实现模糊背景 diff --git a/screenwidget/screenwidget.pro b/screenwidget/screenwidget.pro index f2f07cd..682ed7e 100644 --- a/screenwidget/screenwidget.pro +++ b/screenwidget/screenwidget.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = screenwidget TEMPLATE = app diff --git a/smoothcurve/frmsmoothcurve.cpp b/smoothcurve/frmsmoothcurve.cpp index 749f3ce..bf36bdf 100644 --- a/smoothcurve/frmsmoothcurve.cpp +++ b/smoothcurve/frmsmoothcurve.cpp @@ -12,13 +12,13 @@ frmSmoothCurve::frmSmoothCurve(QWidget *parent) : QWidget(parent), ui(new Ui::fr ui->setupUi(this); //初始化随机数种子 - qsrand(QDateTime::currentDateTime().toMSecsSinceEpoch()); + srand(QDateTime::currentDateTime().toMSecsSinceEpoch()); //随机生成曲线上的点 int x = -300; while (x < 300) { - datas << QPointF(x, qrand() % 300 - 100); - x += qMin(qrand() % 30 + 5, 300); + datas << QPointF(x, rand() % 300 - 100); + x += qMin(rand() % 30 + 5, 300); } //正常曲线 @@ -28,14 +28,14 @@ frmSmoothCurve::frmSmoothCurve(QWidget *parent) : QWidget(parent), ui(new Ui::fr } //平滑曲线1 - qDebug() << TIMEMS << "createSmoothCurve start"; + //qDebug() << TIMEMS << "createSmoothCurve start"; pathSmooth1 = SmoothCurve::createSmoothCurve(datas); - qDebug() << TIMEMS << "createSmoothCurve stop"; + //qDebug() << TIMEMS << "createSmoothCurve stop"; //平滑曲线2 - qDebug() << TIMEMS << "createSmoothCurve2 start"; + //qDebug() << TIMEMS << "createSmoothCurve2 start"; pathSmooth2 = SmoothCurve::createSmoothCurve2(datas); - qDebug() << TIMEMS << "createSmoothCurve2 stop"; + //qDebug() << TIMEMS << "createSmoothCurve2 stop"; ui->ckShowPoint->setChecked(true); connect(ui->ckShowPoint, SIGNAL(clicked(bool)), this, SLOT(update())); diff --git a/smoothcurve/main.cpp b/smoothcurve/main.cpp index f3c23d9..2812bfa 100644 --- a/smoothcurve/main.cpp +++ b/smoothcurve/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); a.setFont(QFont("Microsoft Yahei", 9)); -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if _MSC_VER QTextCodec *codec = QTextCodec::codecForName("gbk"); #else diff --git a/smoothcurve/smoothcurve.pro b/smoothcurve/smoothcurve.pro index 3a70bfe..8b24791 100644 --- a/smoothcurve/smoothcurve.pro +++ b/smoothcurve/smoothcurve.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = smoothcurve TEMPLATE = app diff --git a/styledemo/frmmain.cpp b/styledemo/frmmain.cpp index 453a128..413be95 100644 --- a/styledemo/frmmain.cpp +++ b/styledemo/frmmain.cpp @@ -4,7 +4,6 @@ #include "qfile.h" #include "qtextstream.h" #include "qtranslator.h" -#include "qdesktopwidget.h" #include "qdebug.h" frmMain::frmMain(QWidget *parent) : QMainWindow(parent), ui(new Ui::frmMain) @@ -38,7 +37,7 @@ void frmMain::initForm() void frmMain::initTableWidget() { //设置列数和列宽 - int width = qApp->desktop()->availableGeometry().width() - 120; + int width = 1920; ui->tableWidget->setColumnCount(5); ui->tableWidget->setColumnWidth(0, width * 0.06); ui->tableWidget->setColumnWidth(1, width * 0.10); diff --git a/styledemo/head.h b/styledemo/head.h index 83996ba..3d68241 100644 --- a/styledemo/head.h +++ b/styledemo/head.h @@ -1,7 +1,7 @@ #include #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/styledemo/main.cpp b/styledemo/main.cpp index a7b00a3..b143b1d 100644 --- a/styledemo/main.cpp +++ b/styledemo/main.cpp @@ -2,10 +2,12 @@ #include "frmmain.h" #include #include -#include 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); a.setFont(QFont("Microsoft Yahei", 9)); @@ -25,14 +27,7 @@ int main(int argc, char *argv[]) frmMain w; w.setWindowTitle("样式表示例 (QQ: 517216493 WX: feiyangqingyun)"); - w.show(); - - //居中显示窗体 - QDesktopWidget deskWidget; - int deskWidth = deskWidget.availableGeometry().width(); - int deskHeight = deskWidget.availableGeometry().height(); - QPoint movePoint(deskWidth / 2 - w.width() / 2, deskHeight / 2 - w.height() / 2); - w.move(movePoint); + w.show(); return a.exec(); } diff --git a/styledemo/styledemo.pro b/styledemo/styledemo.pro index 7a56ace..19c587a 100644 --- a/styledemo/styledemo.pro +++ b/styledemo/styledemo.pro @@ -4,9 +4,9 @@ # #------------------------------------------------- -QT += core gui network - +QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = styledemo TEMPLATE = app diff --git a/videopanel/videopanel.pro b/videopanel/videopanel.pro index 4d59fff..2e93891 100644 --- a/videopanel/videopanel.pro +++ b/videopanel/videopanel.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = videopanel TEMPLATE = app diff --git a/videowidget/videowidget.pro b/videowidget/videowidget.pro index 832e77b..5c6933e 100644 --- a/videowidget/videowidget.pro +++ b/videowidget/videowidget.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = videowidget TEMPLATE = app diff --git a/vlcdemo/main.cpp b/vlcdemo/main.cpp index 62bc384..b63f79f 100644 --- a/vlcdemo/main.cpp +++ b/vlcdemo/main.cpp @@ -1,9 +1,7 @@ #pragma execution_character_set("utf-8") #include "widget.h" - #include #include -#include int main(int argc, char *argv[]) { @@ -32,12 +30,5 @@ int main(int argc, char *argv[]) w.setWindowTitle("视频流播放vlc内核 (QQ: 517216493)"); w.show(); - //居中显示窗体 - QDesktopWidget deskWidget; - int deskWidth = deskWidget.availableGeometry().width(); - int deskHeight = deskWidget.availableGeometry().height(); - QPoint movePoint(deskWidth / 2 - w.width() / 2, deskHeight / 2 - w.height() / 2); - w.move(movePoint); - return a.exec(); } diff --git a/vlcdemo/vlcdemo.pro b/vlcdemo/vlcdemo.pro index c66bc3d..b51d677 100644 --- a/vlcdemo/vlcdemo.pro +++ b/vlcdemo/vlcdemo.pro @@ -1,6 +1,13 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2019-02-16T15:08:47 +# +#------------------------------------------------- + QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = vlcdemo TEMPLATE = app diff --git a/zhtopy/frmzhtopy.ui b/zhtopy/frmzhtopy.ui index 63d9b33..6febd1c 100644 --- a/zhtopy/frmzhtopy.ui +++ b/zhtopy/frmzhtopy.ui @@ -13,56 +13,90 @@ Form - - - - 10 - 10 - 381 - 61 - - - - - - - 汉字 + + + + + + 0 - - - - - - 飞扬青云 QQ:517216493 + + 0 - - - - - - 转全拼 + + 0 - - - - - - 结果 + + 0 - - - - - - - - - 转简拼 - - - - - + + + + 转全拼 + + + + + + + 飞扬青云 QQ:517216493 + + + + + + + 汉字 + + + + + + + + + + 结果 + + + + + + + 转简拼 + + + + + + + + + + Qt::Horizontal + + + + 59 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 203 + + + + + diff --git a/zhtopy/main.cpp b/zhtopy/main.cpp index d224a5a..7ade848 100644 --- a/zhtopy/main.cpp +++ b/zhtopy/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); a.setFont(QFont("Microsoft Yahei", 9)); -#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#if (QT_VERSION < QT_VERSION_CHECK(5,0,0)) #if _MSC_VER QTextCodec *codec = QTextCodec::codecForName("gbk"); #else diff --git a/zhtopy/zhtopy.cpp b/zhtopy/zhtopy.cpp index 06b27ee..f5631b6 100644 --- a/zhtopy/zhtopy.cpp +++ b/zhtopy/zhtopy.cpp @@ -271,24 +271,24 @@ QString ZhToPY::zhToPY(const QString &chinese) QString ZhToPY::zhToJP(const QString &chinese) { QString strChineseFirstPY = listJP.join(""); - if(chinese.length() == 0) { + if (chinese.length() == 0) { return chinese; } QString str; int index = 0; - for(int i = 0; i < chinese.length(); i++) { + for (int i = 0; i < chinese.length(); i++) { //若是字母或数字则直接输出 ushort vChar = chinese.at(i).unicode() ; - if((vChar >= 'a' && vChar <= 'z' ) || (vChar >= 'A' && vChar <= 'Z')) { + if ((vChar >= 'a' && vChar <= 'z') || (vChar >= 'A' && vChar <= 'Z')) { str.append(chinese.at(i).toUpper()); } - if((vChar >= '0' && vChar <= '9')) { + if ((vChar >= '0' && vChar <= '9')) { str.append(chinese.at(i)); } else { index = (int)vChar - 19968; - if(index >= 0 && index < strChineseFirstPY.length()) { + if (index >= 0 && index < strChineseFirstPY.length()) { str.append(strChineseFirstPY.at(index)); } } diff --git a/zhtopy/zhtopy.pro b/zhtopy/zhtopy.pro index 225b0ce..4c3fa9f 100644 --- a/zhtopy/zhtopy.pro +++ b/zhtopy/zhtopy.pro @@ -7,6 +7,7 @@ QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat TARGET = zhtopy TEMPLATE = app