全部支持Qt4-Qt6

master
feiyangqingyun 2021-05-30 15:59:42 +08:00
parent 392697b3b9
commit 30ee14dbcf
140 changed files with 1787 additions and 1475 deletions

View File

@ -1,11 +1,9 @@
HEADERS += $$PWD/qextserialport.h HEADERS += \
HEADERS += $$PWD/qextserialport_global.h $$PWD/qextserialport.h \
HEADERS += $$PWD/qextserialport_p.h $$PWD/qextserialport_global.h \
$$PWD/qextserialport_p.h
SOURCES += $$PWD/qextserialport.cpp SOURCES += $$PWD/qextserialport.cpp
win32 {
SOURCES += $$PWD/qextserialport_win.cpp win32:SOURCES += $$PWD/qextserialport_win.cpp
} unix:SOURCES += $$PWD/qextserialport_unix.cpp
unix {
SOURCES += $$PWD/qextserialport_unix.cpp
}

View File

@ -35,26 +35,33 @@
#include <QtCore/QReadWriteLock> #include <QtCore/QReadWriteLock>
#include <QtCore/QMutexLocker> #include <QtCore/QMutexLocker>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QRegExp>
#include <QtCore/QMetaType> #include <QtCore/QMetaType>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
# include <QtCore/QWinEventNotifier> #include <QtCore/QWinEventNotifier>
#else #else
# include <QtCore/private/qwineventnotifier_p.h> #include <QtCore/private/qwineventnotifier_p.h>
#endif #endif
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QtCore5Compat/QRegExp>
#else
#include <QtCore/QRegExp>
#endif
void QextSerialPortPrivate::platformSpecificInit() void QextSerialPortPrivate::platformSpecificInit()
{ {
handle = INVALID_HANDLE_VALUE; handle = INVALID_HANDLE_VALUE;
ZeroMemory(&overlap, sizeof(OVERLAPPED)); ZeroMemory(&overlap, sizeof(OVERLAPPED));
overlap.hEvent = CreateEvent(NULL, true, false, NULL); overlap.hEvent = CreateEvent(NULL, true, false, NULL);
winEventNotifier = 0; winEventNotifier = 0;
bytesToWriteLock = new QReadWriteLock; bytesToWriteLock = new QReadWriteLock;
} }
void QextSerialPortPrivate::platformSpecificDestruct() void QextSerialPortPrivate::platformSpecificDestruct()
{ {
CloseHandle(overlap.hEvent); CloseHandle(overlap.hEvent);
delete bytesToWriteLock; delete bytesToWriteLock;
} }
@ -66,108 +73,107 @@ void QextSerialPortPrivate::platformSpecificDestruct()
*/ */
static QString fullPortNameWin(const QString &name) static QString fullPortNameWin(const QString &name)
{ {
QRegExp rx(QLatin1String("^COM(\\d+)")); QRegExp rx(QLatin1String("^COM(\\d+)"));
QString fullName(name); QString fullName(name);
if (rx.indexIn(fullName) >= 0) {
fullName.prepend(QLatin1String("\\\\.\\"));
}
if (fullName.contains(rx)) { return fullName;
fullName.prepend(QLatin1String("\\\\.\\"));
}
return fullName;
} }
bool QextSerialPortPrivate::open_sys(QIODevice::OpenMode mode) bool QextSerialPortPrivate::open_sys(QIODevice::OpenMode mode)
{ {
Q_Q(QextSerialPort); Q_Q(QextSerialPort);
DWORD confSize = sizeof(COMMCONFIG); DWORD confSize = sizeof(COMMCONFIG);
commConfig.dwSize = confSize; commConfig.dwSize = confSize;
DWORD dwFlagsAndAttributes = 0; DWORD dwFlagsAndAttributes = 0;
if (queryMode == QextSerialPort::EventDriven) { if (queryMode == QextSerialPort::EventDriven) {
dwFlagsAndAttributes += FILE_FLAG_OVERLAPPED; dwFlagsAndAttributes += FILE_FLAG_OVERLAPPED;
} }
/*open the port*/ /*open the port*/
handle = CreateFileW((wchar_t *)fullPortNameWin(port).utf16(), GENERIC_READ | GENERIC_WRITE, handle = CreateFileW((wchar_t *)fullPortNameWin(port).utf16(), GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, dwFlagsAndAttributes, NULL); 0, NULL, OPEN_EXISTING, dwFlagsAndAttributes, NULL);
if (handle != INVALID_HANDLE_VALUE) { if (handle != INVALID_HANDLE_VALUE) {
q->setOpenMode(mode); q->setOpenMode(mode);
/*configure port settings*/ /*configure port settings*/
GetCommConfig(handle, &commConfig, &confSize); GetCommConfig(handle, &commConfig, &confSize);
GetCommState(handle, &(commConfig.dcb)); GetCommState(handle, &(commConfig.dcb));
/*set up parameters*/ /*set up parameters*/
commConfig.dcb.fBinary = TRUE; commConfig.dcb.fBinary = TRUE;
commConfig.dcb.fInX = FALSE; commConfig.dcb.fInX = FALSE;
commConfig.dcb.fOutX = FALSE; commConfig.dcb.fOutX = FALSE;
commConfig.dcb.fAbortOnError = FALSE; commConfig.dcb.fAbortOnError = FALSE;
commConfig.dcb.fNull = FALSE; commConfig.dcb.fNull = FALSE;
/* Dtr default to true. See Issue 122*/ /* Dtr default to true. See Issue 122*/
commConfig.dcb.fDtrControl = TRUE; commConfig.dcb.fDtrControl = TRUE;
/*flush all settings*/ /*flush all settings*/
settingsDirtyFlags = DFE_ALL; settingsDirtyFlags = DFE_ALL;
updatePortSettings(); updatePortSettings();
//init event driven approach //init event driven approach
if (queryMode == QextSerialPort::EventDriven) { if (queryMode == QextSerialPort::EventDriven) {
if (!SetCommMask(handle, EV_TXEMPTY | EV_RXCHAR | EV_DSR)) { if (!SetCommMask(handle, EV_TXEMPTY | EV_RXCHAR | EV_DSR)) {
QESP_WARNING() << "failed to set Comm Mask. Error code:" << GetLastError(); QESP_WARNING() << "failed to set Comm Mask. Error code:" << GetLastError();
return false; return false;
} }
winEventNotifier = new QWinEventNotifier(overlap.hEvent, q); winEventNotifier = new QWinEventNotifier(overlap.hEvent, q);
qRegisterMetaType<HANDLE>("HANDLE"); qRegisterMetaType<HANDLE>("HANDLE");
q->connect(winEventNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_onWinEvent(HANDLE)), Qt::DirectConnection); q->connect(winEventNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_onWinEvent(HANDLE)), Qt::DirectConnection);
WaitCommEvent(handle, &eventMask, &overlap); WaitCommEvent(handle, &eventMask, &overlap);
} }
return true; return true;
} }
return false; return false;
} }
bool QextSerialPortPrivate::close_sys() bool QextSerialPortPrivate::close_sys()
{ {
flush_sys(); flush_sys();
CancelIo(handle); CancelIo(handle);
if (CloseHandle(handle)) { if (CloseHandle(handle)) {
handle = INVALID_HANDLE_VALUE; handle = INVALID_HANDLE_VALUE;
} }
if (winEventNotifier) { if (winEventNotifier) {
winEventNotifier->setEnabled(false); winEventNotifier->setEnabled(false);
winEventNotifier->deleteLater(); winEventNotifier->deleteLater();
winEventNotifier = 0; winEventNotifier = 0;
} }
foreach (OVERLAPPED *o, pendingWrites) { foreach (OVERLAPPED *o, pendingWrites) {
CloseHandle(o->hEvent); CloseHandle(o->hEvent);
delete o; delete o;
} }
pendingWrites.clear(); pendingWrites.clear();
return true; return true;
} }
bool QextSerialPortPrivate::flush_sys() bool QextSerialPortPrivate::flush_sys()
{ {
FlushFileBuffers(handle); FlushFileBuffers(handle);
return true; return true;
} }
qint64 QextSerialPortPrivate::bytesAvailable_sys() const qint64 QextSerialPortPrivate::bytesAvailable_sys() const
{ {
DWORD Errors; DWORD Errors;
COMSTAT Status; COMSTAT Status;
if (ClearCommError(handle, &Errors, &Status)) { if (ClearCommError(handle, &Errors, &Status)) {
return Status.cbInQue; return Status.cbInQue;
} }
return (qint64) - 1; return (qint64) - 1;
} }
/* /*
@ -175,23 +181,23 @@ qint64 QextSerialPortPrivate::bytesAvailable_sys() const
*/ */
void QextSerialPortPrivate::translateError(ulong error) void QextSerialPortPrivate::translateError(ulong error)
{ {
if (error & CE_BREAK) { if (error & CE_BREAK) {
lastErr = E_BREAK_CONDITION; lastErr = E_BREAK_CONDITION;
} else if (error & CE_FRAME) { } else if (error & CE_FRAME) {
lastErr = E_FRAMING_ERROR; lastErr = E_FRAMING_ERROR;
} else if (error & CE_IOE) { } else if (error & CE_IOE) {
lastErr = E_IO_ERROR; lastErr = E_IO_ERROR;
} else if (error & CE_MODE) { } else if (error & CE_MODE) {
lastErr = E_INVALID_FD; lastErr = E_INVALID_FD;
} else if (error & CE_OVERRUN) { } else if (error & CE_OVERRUN) {
lastErr = E_BUFFER_OVERRUN; lastErr = E_BUFFER_OVERRUN;
} else if (error & CE_RXPARITY) { } else if (error & CE_RXPARITY) {
lastErr = E_RECEIVE_PARITY_ERROR; lastErr = E_RECEIVE_PARITY_ERROR;
} else if (error & CE_RXOVER) { } else if (error & CE_RXOVER) {
lastErr = E_RECEIVE_OVERFLOW; lastErr = E_RECEIVE_OVERFLOW;
} else if (error & CE_TXFULL) { } else if (error & CE_TXFULL) {
lastErr = E_TRANSMIT_OVERFLOW; lastErr = E_TRANSMIT_OVERFLOW;
} }
} }
/* /*
@ -204,30 +210,30 @@ void QextSerialPortPrivate::translateError(ulong error)
*/ */
qint64 QextSerialPortPrivate::readData_sys(char *data, qint64 maxSize) qint64 QextSerialPortPrivate::readData_sys(char *data, qint64 maxSize)
{ {
DWORD bytesRead = 0; DWORD bytesRead = 0;
bool failed = false; bool failed = false;
if (queryMode == QextSerialPort::EventDriven) { if (queryMode == QextSerialPort::EventDriven) {
OVERLAPPED overlapRead; OVERLAPPED overlapRead;
ZeroMemory(&overlapRead, sizeof(OVERLAPPED)); ZeroMemory(&overlapRead, sizeof(OVERLAPPED));
if (!ReadFile(handle, (void *)data, (DWORD)maxSize, &bytesRead, &overlapRead)) { if (!ReadFile(handle, (void *)data, (DWORD)maxSize, &bytesRead, &overlapRead)) {
if (GetLastError() == ERROR_IO_PENDING) { if (GetLastError() == ERROR_IO_PENDING) {
GetOverlappedResult(handle, &overlapRead, &bytesRead, true); GetOverlappedResult(handle, &overlapRead, &bytesRead, true);
} else { } else {
failed = true; failed = true;
} }
} }
} else if (!ReadFile(handle, (void *)data, (DWORD)maxSize, &bytesRead, NULL)) { } else if (!ReadFile(handle, (void *)data, (DWORD)maxSize, &bytesRead, NULL)) {
failed = true; failed = true;
} }
if (!failed) { if (!failed) {
return (qint64)bytesRead; return (qint64)bytesRead;
} }
lastErr = E_READ_FAILED; lastErr = E_READ_FAILED;
return -1; return -1;
} }
/* /*
@ -240,79 +246,79 @@ qint64 QextSerialPortPrivate::readData_sys(char *data, qint64 maxSize)
*/ */
qint64 QextSerialPortPrivate::writeData_sys(const char *data, qint64 maxSize) qint64 QextSerialPortPrivate::writeData_sys(const char *data, qint64 maxSize)
{ {
DWORD bytesWritten = 0; DWORD bytesWritten = 0;
bool failed = false; bool failed = false;
if (queryMode == QextSerialPort::EventDriven) { if (queryMode == QextSerialPort::EventDriven) {
OVERLAPPED *newOverlapWrite = new OVERLAPPED; OVERLAPPED *newOverlapWrite = new OVERLAPPED;
ZeroMemory(newOverlapWrite, sizeof(OVERLAPPED)); ZeroMemory(newOverlapWrite, sizeof(OVERLAPPED));
newOverlapWrite->hEvent = CreateEvent(NULL, true, false, NULL); newOverlapWrite->hEvent = CreateEvent(NULL, true, false, NULL);
if (WriteFile(handle, (void *)data, (DWORD)maxSize, &bytesWritten, newOverlapWrite)) { if (WriteFile(handle, (void *)data, (DWORD)maxSize, &bytesWritten, newOverlapWrite)) {
CloseHandle(newOverlapWrite->hEvent); CloseHandle(newOverlapWrite->hEvent);
delete newOverlapWrite; delete newOverlapWrite;
} else if (GetLastError() == ERROR_IO_PENDING) { } else if (GetLastError() == ERROR_IO_PENDING) {
// writing asynchronously...not an error // writing asynchronously...not an error
QWriteLocker writelocker(bytesToWriteLock); QWriteLocker writelocker(bytesToWriteLock);
pendingWrites.append(newOverlapWrite); pendingWrites.append(newOverlapWrite);
} else { } else {
QESP_WARNING() << "QextSerialPort write error:" << GetLastError(); QESP_WARNING() << "QextSerialPort write error:" << GetLastError();
failed = true; failed = true;
if (!CancelIo(newOverlapWrite->hEvent)) { if (!CancelIo(newOverlapWrite->hEvent)) {
QESP_WARNING("QextSerialPort: couldn't cancel IO"); QESP_WARNING("QextSerialPort: couldn't cancel IO");
} }
if (!CloseHandle(newOverlapWrite->hEvent)) { if (!CloseHandle(newOverlapWrite->hEvent)) {
QESP_WARNING("QextSerialPort: couldn't close OVERLAPPED handle"); QESP_WARNING("QextSerialPort: couldn't close OVERLAPPED handle");
} }
delete newOverlapWrite; delete newOverlapWrite;
} }
} else if (!WriteFile(handle, (void *)data, (DWORD)maxSize, &bytesWritten, NULL)) { } else if (!WriteFile(handle, (void *)data, (DWORD)maxSize, &bytesWritten, NULL)) {
failed = true; failed = true;
} }
if (!failed) { if (!failed) {
return (qint64)bytesWritten; return (qint64)bytesWritten;
} }
lastErr = E_WRITE_FAILED; lastErr = E_WRITE_FAILED;
return -1; return -1;
} }
void QextSerialPortPrivate::setDtr_sys(bool set) void QextSerialPortPrivate::setDtr_sys(bool set)
{ {
EscapeCommFunction(handle, set ? SETDTR : CLRDTR); EscapeCommFunction(handle, set ? SETDTR : CLRDTR);
} }
void QextSerialPortPrivate::setRts_sys(bool set) void QextSerialPortPrivate::setRts_sys(bool set)
{ {
EscapeCommFunction(handle, set ? SETRTS : CLRRTS); EscapeCommFunction(handle, set ? SETRTS : CLRRTS);
} }
ulong QextSerialPortPrivate::lineStatus_sys(void) ulong QextSerialPortPrivate::lineStatus_sys(void)
{ {
unsigned long Status = 0, Temp = 0; unsigned long Status = 0, Temp = 0;
GetCommModemStatus(handle, &Temp); GetCommModemStatus(handle, &Temp);
if (Temp & MS_CTS_ON) { if (Temp & MS_CTS_ON) {
Status |= LS_CTS; Status |= LS_CTS;
} }
if (Temp & MS_DSR_ON) { if (Temp & MS_DSR_ON) {
Status |= LS_DSR; Status |= LS_DSR;
} }
if (Temp & MS_RING_ON) { if (Temp & MS_RING_ON) {
Status |= LS_RI; Status |= LS_RI;
} }
if (Temp & MS_RLSD_ON) { if (Temp & MS_RLSD_ON) {
Status |= LS_DCD; Status |= LS_DCD;
} }
return Status; return Status;
} }
/* /*
@ -320,157 +326,157 @@ ulong QextSerialPortPrivate::lineStatus_sys(void)
*/ */
void QextSerialPortPrivate::_q_onWinEvent(HANDLE h) void QextSerialPortPrivate::_q_onWinEvent(HANDLE h)
{ {
Q_Q(QextSerialPort); Q_Q(QextSerialPort);
if (h == overlap.hEvent) { if (h == overlap.hEvent) {
if (eventMask & EV_RXCHAR) { if (eventMask & EV_RXCHAR) {
if (q->sender() != q && bytesAvailable_sys() > 0) { if (q->sender() != q && bytesAvailable_sys() > 0) {
_q_canRead(); _q_canRead();
} }
} }
if (eventMask & EV_TXEMPTY) { if (eventMask & EV_TXEMPTY) {
/* /*
A write completed. Run through the list of OVERLAPPED writes, and if A write completed. Run through the list of OVERLAPPED writes, and if
they completed successfully, take them off the list and delete them. they completed successfully, take them off the list and delete them.
Otherwise, leave them on there so they can finish. Otherwise, leave them on there so they can finish.
*/ */
qint64 totalBytesWritten = 0; qint64 totalBytesWritten = 0;
QList<OVERLAPPED *> overlapsToDelete; QList<OVERLAPPED *> overlapsToDelete;
foreach (OVERLAPPED *o, pendingWrites) { foreach (OVERLAPPED *o, pendingWrites) {
DWORD numBytes = 0; DWORD numBytes = 0;
if (GetOverlappedResult(handle, o, &numBytes, false)) { if (GetOverlappedResult(handle, o, &numBytes, false)) {
overlapsToDelete.append(o); overlapsToDelete.append(o);
totalBytesWritten += numBytes; totalBytesWritten += numBytes;
} else if (GetLastError() != ERROR_IO_INCOMPLETE) { } else if (GetLastError() != ERROR_IO_INCOMPLETE) {
overlapsToDelete.append(o); overlapsToDelete.append(o);
QESP_WARNING() << "CommEvent overlapped write error:" << GetLastError(); QESP_WARNING() << "CommEvent overlapped write error:" << GetLastError();
} }
} }
if (q->sender() != q && totalBytesWritten > 0) { if (q->sender() != q && totalBytesWritten > 0) {
QWriteLocker writelocker(bytesToWriteLock); QWriteLocker writelocker(bytesToWriteLock);
Q_EMIT q->bytesWritten(totalBytesWritten); Q_EMIT q->bytesWritten(totalBytesWritten);
} }
foreach (OVERLAPPED *o, overlapsToDelete) { foreach (OVERLAPPED *o, overlapsToDelete) {
OVERLAPPED *toDelete = pendingWrites.takeAt(pendingWrites.indexOf(o)); OVERLAPPED *toDelete = pendingWrites.takeAt(pendingWrites.indexOf(o));
CloseHandle(toDelete->hEvent); CloseHandle(toDelete->hEvent);
delete toDelete; delete toDelete;
} }
} }
if (eventMask & EV_DSR) { if (eventMask & EV_DSR) {
if (lineStatus_sys() & LS_DSR) { if (lineStatus_sys() & LS_DSR) {
Q_EMIT q->dsrChanged(true); Q_EMIT q->dsrChanged(true);
} else { } else {
Q_EMIT q->dsrChanged(false); Q_EMIT q->dsrChanged(false);
} }
} }
} }
WaitCommEvent(handle, &eventMask, &overlap); WaitCommEvent(handle, &eventMask, &overlap);
} }
void QextSerialPortPrivate::updatePortSettings() void QextSerialPortPrivate::updatePortSettings()
{ {
if (!q_ptr->isOpen() || !settingsDirtyFlags) { if (!q_ptr->isOpen() || !settingsDirtyFlags) {
return; return;
} }
//fill struct : COMMCONFIG //fill struct : COMMCONFIG
if (settingsDirtyFlags & DFE_BaudRate) { if (settingsDirtyFlags & DFE_BaudRate) {
commConfig.dcb.BaudRate = settings.BaudRate; commConfig.dcb.BaudRate = settings.BaudRate;
} }
if (settingsDirtyFlags & DFE_Parity) { if (settingsDirtyFlags & DFE_Parity) {
commConfig.dcb.Parity = (BYTE)settings.Parity; commConfig.dcb.Parity = (BYTE)settings.Parity;
commConfig.dcb.fParity = (settings.Parity == PAR_NONE) ? FALSE : TRUE; commConfig.dcb.fParity = (settings.Parity == PAR_NONE) ? FALSE : TRUE;
} }
if (settingsDirtyFlags & DFE_DataBits) { if (settingsDirtyFlags & DFE_DataBits) {
commConfig.dcb.ByteSize = (BYTE)settings.DataBits; commConfig.dcb.ByteSize = (BYTE)settings.DataBits;
} }
if (settingsDirtyFlags & DFE_StopBits) { if (settingsDirtyFlags & DFE_StopBits) {
switch (settings.StopBits) { switch (settings.StopBits) {
case STOP_1: case STOP_1:
commConfig.dcb.StopBits = ONESTOPBIT; commConfig.dcb.StopBits = ONESTOPBIT;
break; break;
case STOP_1_5: case STOP_1_5:
commConfig.dcb.StopBits = ONE5STOPBITS; commConfig.dcb.StopBits = ONE5STOPBITS;
break; break;
case STOP_2: case STOP_2:
commConfig.dcb.StopBits = TWOSTOPBITS; commConfig.dcb.StopBits = TWOSTOPBITS;
break; break;
} }
} }
if (settingsDirtyFlags & DFE_Flow) { if (settingsDirtyFlags & DFE_Flow) {
switch (settings.FlowControl) { switch (settings.FlowControl) {
/*no flow control*/ /*no flow control*/
case FLOW_OFF: case FLOW_OFF:
commConfig.dcb.fOutxCtsFlow = FALSE; commConfig.dcb.fOutxCtsFlow = FALSE;
commConfig.dcb.fRtsControl = RTS_CONTROL_DISABLE; commConfig.dcb.fRtsControl = RTS_CONTROL_DISABLE;
commConfig.dcb.fInX = FALSE; commConfig.dcb.fInX = FALSE;
commConfig.dcb.fOutX = FALSE; commConfig.dcb.fOutX = FALSE;
break; break;
/*software (XON/XOFF) flow control*/ /*software (XON/XOFF) flow control*/
case FLOW_XONXOFF: case FLOW_XONXOFF:
commConfig.dcb.fOutxCtsFlow = FALSE; commConfig.dcb.fOutxCtsFlow = FALSE;
commConfig.dcb.fRtsControl = RTS_CONTROL_DISABLE; commConfig.dcb.fRtsControl = RTS_CONTROL_DISABLE;
commConfig.dcb.fInX = TRUE; commConfig.dcb.fInX = TRUE;
commConfig.dcb.fOutX = TRUE; commConfig.dcb.fOutX = TRUE;
break; break;
/*hardware flow control*/ /*hardware flow control*/
case FLOW_HARDWARE: case FLOW_HARDWARE:
commConfig.dcb.fOutxCtsFlow = TRUE; commConfig.dcb.fOutxCtsFlow = TRUE;
commConfig.dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; commConfig.dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
commConfig.dcb.fInX = FALSE; commConfig.dcb.fInX = FALSE;
commConfig.dcb.fOutX = FALSE; commConfig.dcb.fOutX = FALSE;
break; break;
} }
} }
//fill struct : COMMTIMEOUTS //fill struct : COMMTIMEOUTS
if (settingsDirtyFlags & DFE_TimeOut) { if (settingsDirtyFlags & DFE_TimeOut) {
if (queryMode != QextSerialPort::EventDriven) { if (queryMode != QextSerialPort::EventDriven) {
int millisec = settings.Timeout_Millisec; int millisec = settings.Timeout_Millisec;
if (millisec == -1) { if (millisec == -1) {
commTimeouts.ReadIntervalTimeout = MAXDWORD; commTimeouts.ReadIntervalTimeout = MAXDWORD;
commTimeouts.ReadTotalTimeoutConstant = 0; commTimeouts.ReadTotalTimeoutConstant = 0;
} else { } else {
commTimeouts.ReadIntervalTimeout = millisec; commTimeouts.ReadIntervalTimeout = millisec;
commTimeouts.ReadTotalTimeoutConstant = millisec; commTimeouts.ReadTotalTimeoutConstant = millisec;
} }
commTimeouts.ReadTotalTimeoutMultiplier = 0; commTimeouts.ReadTotalTimeoutMultiplier = 0;
commTimeouts.WriteTotalTimeoutMultiplier = millisec; commTimeouts.WriteTotalTimeoutMultiplier = millisec;
commTimeouts.WriteTotalTimeoutConstant = 0; commTimeouts.WriteTotalTimeoutConstant = 0;
} else { } else {
commTimeouts.ReadIntervalTimeout = MAXDWORD; commTimeouts.ReadIntervalTimeout = MAXDWORD;
commTimeouts.ReadTotalTimeoutMultiplier = 0; commTimeouts.ReadTotalTimeoutMultiplier = 0;
commTimeouts.ReadTotalTimeoutConstant = 0; commTimeouts.ReadTotalTimeoutConstant = 0;
commTimeouts.WriteTotalTimeoutMultiplier = 0; commTimeouts.WriteTotalTimeoutMultiplier = 0;
commTimeouts.WriteTotalTimeoutConstant = 0; commTimeouts.WriteTotalTimeoutConstant = 0;
} }
} }
if (settingsDirtyFlags & DFE_Settings_Mask) { if (settingsDirtyFlags & DFE_Settings_Mask) {
SetCommConfig(handle, &commConfig, sizeof(COMMCONFIG)); SetCommConfig(handle, &commConfig, sizeof(COMMCONFIG));
} }
if ((settingsDirtyFlags & DFE_TimeOut)) { if ((settingsDirtyFlags & DFE_TimeOut)) {
SetCommTimeouts(handle, &commTimeouts); SetCommTimeouts(handle, &commTimeouts);
} }
settingsDirtyFlags = 0; settingsDirtyFlags = 0;
} }

View File

@ -11,8 +11,7 @@ HEADERS += \
$$PWD/mimetext.h \ $$PWD/mimetext.h \
$$PWD/quotedprintable.h \ $$PWD/quotedprintable.h \
$$PWD/smtpclient.h \ $$PWD/smtpclient.h \
$$PWD/smtpmime.h \ $$PWD/smtpmime.h
$$PWD/sendemailthread.h
SOURCES += \ SOURCES += \
$$PWD/emailaddress.cpp \ $$PWD/emailaddress.cpp \
@ -26,5 +25,4 @@ SOURCES += \
$$PWD/mimepart.cpp \ $$PWD/mimepart.cpp \
$$PWD/mimetext.cpp \ $$PWD/mimetext.cpp \
$$PWD/quotedprintable.cpp \ $$PWD/quotedprintable.cpp \
$$PWD/smtpclient.cpp \ $$PWD/smtpclient.cpp
$$PWD/sendemailthread.cpp

View File

@ -0,0 +1,223 @@
#include "mimemessage.h"
#include <QDateTime>
#include "quotedprintable.h"
#include <typeinfo>
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<EmailAddress *> &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<MimePart *> &MimeMessage::getParts() const
{
if (typeid(*content) == typeid(MimeMultiPart)) {
return ((MimeMultiPart *) content)->getParts();
} else {
QList<MimePart *> *res = new QList<MimePart *>();
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<EmailAddress *>::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;
}

View File

@ -0,0 +1,66 @@
#include "mimemultipart.h"
#include "stdlib.h"
#include <QTime>
#include <QCryptographicHash>
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<MimePart *> &MimeMultiPart::getParts() const
{
return parts;
}
void MimeMultiPart::prepare()
{
QList<MimePart *>::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;
}

View File

@ -142,7 +142,7 @@ void MimePart::prepare()
break; break;
} }
if (cId != 0) { if (cId.toInt() != 0) {
mimeString.append("Content-ID: <").append(cId).append(">\r\n"); mimeString.append("Content-ID: <").append(cId).append(">\r\n");
} }

View File

@ -23,6 +23,6 @@ const QString &MimeText::getText() const
void MimeText::prepare() void MimeText::prepare()
{ {
this->content.clear(); this->content.clear();
this->content.append(text); this->content.append(text.toUtf8());
MimePart::prepare(); MimePart::prepare();
} }

View File

@ -222,7 +222,7 @@ bool SmtpClient::login(const QString &user, const QString &password, AuthMethod
try { try {
if (method == AuthPlain) { if (method == AuthPlain) {
// Sending command: AUTH PLAIN base64('\0' + username + '\0' + password) // 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 // Wait for the server's response
waitForResponse(); waitForResponse();
@ -245,7 +245,7 @@ bool SmtpClient::login(const QString &user, const QString &password, AuthMethod
} }
// Send the username in base64 // Send the username in base64
sendMessage(QByteArray().append(user).toBase64()); sendMessage(QByteArray().append(user.toUtf8()).toBase64());
// Wait for 334 // Wait for 334
waitForResponse(); waitForResponse();
@ -256,7 +256,7 @@ bool SmtpClient::login(const QString &user, const QString &password, AuthMethod
} }
// Send the password in base64 // Send the password in base64
sendMessage(QByteArray().append(password).toBase64()); sendMessage(QByteArray().append(password.toUtf8()).toBase64());
// Wait for the server's responce // Wait for the server's responce
waitForResponse(); waitForResponse();
@ -354,7 +354,7 @@ void SmtpClient::quit()
sendMessage("QUIT"); sendMessage("QUIT");
} }
void SmtpClient::waitForResponse() throw (ResponseTimeoutException) void SmtpClient::waitForResponse()
{ {
do { do {
if (!socket->waitForReadyRead(responseTimeout)) { if (!socket->waitForReadyRead(responseTimeout)) {

View File

@ -92,7 +92,7 @@ protected:
int responseCode; int responseCode;
class ResponseTimeoutException {}; class ResponseTimeoutException {};
void waitForResponse() throw (ResponseTimeoutException); void waitForResponse();
void sendMessage(const QString &text); void sendMessage(const QString &text);
signals: signals:

View File

@ -24,7 +24,6 @@ SUBDIRS += maskwidget #遮罩层窗体
SUBDIRS += battery #电池电量控件 SUBDIRS += battery #电池电量控件
SUBDIRS += lineeditnext #文本框回车焦点下移 SUBDIRS += lineeditnext #文本框回车焦点下移
SUBDIRS += zhtopy #汉字转拼音 SUBDIRS += zhtopy #汉字转拼音
SUBDIRS += qwtdemo #qwt的源码版本无需插件直接源码集成到你的项目即可
SUBDIRS += devicebutton #设备按钮地图效果 SUBDIRS += devicebutton #设备按钮地图效果
SUBDIRS += mouseline #鼠标定位十字线 SUBDIRS += mouseline #鼠标定位十字线
SUBDIRS += emailtool #邮件发送工具 SUBDIRS += emailtool #邮件发送工具
@ -46,5 +45,12 @@ SUBDIRS += miniblink #miniblink示例
#如果你电脑对应的Qt版本有webkit或者webengine组件可以自行打开 #如果你电脑对应的Qt版本有webkit或者webengine组件可以自行打开
#SUBDIRS += echartgauge #echart仪表盘含交互支持webkit及webengine #SUBDIRS += echartgauge #echart仪表盘含交互支持webkit及webengine
#designer项目只支持Qt4,如果是Qt4可以自行打开
lessThan(QT_MAJOR_VERSION, 4) {
#SUBDIRS += designer #QtDesigner4源码 #SUBDIRS += designer #QtDesigner4源码
}
#qwt项目需要等官方适配了qwt组件才能适配
lessThan(QT_MAJOR_VERSION, 6) {
SUBDIRS += qwtdemo #qwt的源码版本无需插件直接源码集成到你的项目即可
}

View File

@ -2,6 +2,7 @@
1. **可以选择打开QWidgetDemo.pro一次性编译所有的也可以进入到目录下打开pro进行编译** 1. **可以选择打开QWidgetDemo.pro一次性编译所有的也可以进入到目录下打开pro进行编译**
2. **如果发现有些子项目没有加载请打开QWidgetDemo.pro仔细看里面的注释** 2. **如果发现有些子项目没有加载请打开QWidgetDemo.pro仔细看里面的注释**
3. **编译好的可执行文件在源码同级目录下的bin目录** 3. **编译好的可执行文件在源码同级目录下的bin目录**
4. 亲测Qt4.6到Qt6.1所有版本亲测win、linux、mac、uos等系统。
| 编号 | 文件夹 | 描述 | | 编号 | 文件夹 | 描述 |
| ------ | ------ | ------ | | ------ | ------ | ------ |

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = base64 TARGET = base64
TEMPLATE = app TEMPLATE = app

View File

@ -128,11 +128,13 @@ void Battery::updateValue()
if (isForward) { if (isForward) {
currentValue -= step; currentValue -= step;
if (currentValue <= value) { if (currentValue <= value) {
currentValue = value;
timer->stop(); timer->stop();
} }
} else { } else {
currentValue += step; currentValue += step;
if (currentValue >= value) { if (currentValue >= value) {
currentValue = value;
timer->stop(); timer->stop();
} }
} }

View File

@ -20,7 +20,8 @@ class Battery : public QWidget
#endif #endif
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(double minValue READ getMinValue WRITE setMinValue) Q_PROPERTY(double minValue READ getMinValue WRITE setMinValue)
Q_PROPERTY(double maxValue READ getMaxValue WRITE setMaxValue) Q_PROPERTY(double maxValue READ getMaxValue WRITE setMaxValue)
Q_PROPERTY(double value READ getValue WRITE setValue) Q_PROPERTY(double value READ getValue WRITE setValue)
@ -54,7 +55,7 @@ protected:
private slots: private slots:
void updateValue(); void updateValue();
private: private:
double minValue; //最小值 double minValue; //最小值
double maxValue; //最大值 double maxValue; //最大值
double value; //目标电量 double value; //目标电量
@ -80,7 +81,7 @@ private:
QRectF batteryRect; //电池主体区域 QRectF batteryRect; //电池主体区域
QTimer *timer; //绘制定时器 QTimer *timer; //绘制定时器
public: public:
double getMinValue() const; double getMinValue() const;
double getMaxValue() const; double getMaxValue() const;
double getValue() const; double getValue() const;

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = battery TARGET = battery
TEMPLATE = app TEMPLATE = app

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = bgdemo TARGET = bgdemo
TEMPLATE = app TEMPLATE = app

View File

@ -6,13 +6,18 @@
#include "qlabel.h" #include "qlabel.h"
#include "qlineedit.h" #include "qlineedit.h"
#include "qapplication.h" #include "qapplication.h"
#include "qdesktopwidget.h"
#include "qtimer.h" #include "qtimer.h"
#include "qevent.h" #include "qevent.h"
#include "qdebug.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" #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 #endif
ColorWidget *ColorWidget::instance = 0; ColorWidget *ColorWidget::instance = 0;
@ -130,11 +135,11 @@ void ColorWidget::showColorValue()
int y = QCursor::pos().y(); int y = QCursor::pos().y();
txtPoint->setText(tr("x:%1 y:%2").arg(x).arg(y)); txtPoint->setText(tr("x:%1 y:%2").arg(x).arg(y));
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
QPixmap pixmap = QPixmap::grabWindow(QApplication::desktop()->winId(), x, y, 2, 2); QPixmap pixmap = QPixmap::grabWindow(qApp->desktop()->winId(), x, y, 2, 2);
#else #else
QScreen *screen = QApplication::primaryScreen(); QScreen *screen = qApp->primaryScreen();
QPixmap pixmap = screen->grabWindow(QApplication::desktop()->winId(), x, y, 2, 2); QPixmap pixmap = screen->grabWindow(0, x, y, 2, 2);
#endif #endif
int red, green, blue; int red, green, blue;

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = colorwidget TARGET = colorwidget
TEMPLATE = app TEMPLATE = app

View File

@ -9,7 +9,7 @@ int main(int argc, char *argv[])
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); 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 #if _MSC_VER
QTextCodec *codec = QTextCodec::codecForName("gbk"); QTextCodec *codec = QTextCodec::codecForName("gbk");
#else #else

View File

@ -7,6 +7,7 @@
QT += core gui network QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = comtool TARGET = comtool
TEMPLATE = app TEMPLATE = app

View File

@ -6,6 +6,9 @@
#include <QtWidgets> #include <QtWidgets>
#endif #endif
#include "appconfig.h" #if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
#include <QtCore5Compat>
#endif
#pragma execution_character_set("utf-8") #pragma execution_character_set("utf-8")
#include "appconfig.h"

View File

@ -15,7 +15,7 @@ IconFont *IconFont::Instance()
} }
IconFont::IconFont(QObject *parent) : QObject(parent) IconFont::IconFont(QObject *parent) : QObject(parent)
{ {
//判断图形字体是否存在,不存在则加入 //判断图形字体是否存在,不存在则加入
QFontDatabase fontDb; QFontDatabase fontDb;
if (!fontDb.families().contains("iconfont")) { 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); iconFont.setPixelSize(size);
lab->setFont(iconFont); 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); iconFont.setPixelSize(size);
btn->setFont(iconFont); 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) quint32 pixWidth, quint32 pixHeight, int flags)
{ {
QPixmap pix(pixWidth, pixHeight); QPixmap pix(pixWidth, pixHeight);
@ -61,7 +61,7 @@ QPixmap IconFont::getPixmap(const QColor &color, const QChar &icon, quint32 size
iconFont.setPixelSize(size); iconFont.setPixelSize(size);
painter.setFont(iconFont); painter.setFont(iconFont);
painter.drawText(pix.rect(), flags, icon); painter.drawText(pix.rect(), flags, (QChar)icon);
painter.end(); painter.end();
return pix; return pix;
@ -90,16 +90,16 @@ void IconFont::setStyle(QWidget *widget, const QString &type, int borderWidth, c
QString strBorder; QString strBorder;
if (type == "top") { if (type == "top") {
strBorder = QString("border-width:%1px 0px 0px 0px;padding:%1px %2px %2px %2px;") 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") { } else if (type == "right") {
strBorder = QString("border-width:0px %1px 0px 0px;padding:%2px %1px %2px %2px;") 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") { } else if (type == "bottom") {
strBorder = QString("border-width:0px 0px %1px 0px;padding:%2px %2px %1px %2px;") 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") { } else if (type == "left") {
strBorder = QString("border-width:0px 0px 0px %1px;padding:%2px %2px %2px %1px;") 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; QStringList qss;
@ -115,7 +115,7 @@ void IconFont::setStyle(QWidget *widget, const QString &type, int borderWidth, c
widget->setStyleSheet(qss.join("")); widget->setStyleSheet(qss.join(""));
} }
void IconFont::setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QChar> icons, void IconFont::setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> icons,
quint32 iconSize, quint32 iconWidth, quint32 iconHeight, quint32 iconSize, quint32 iconWidth, quint32 iconHeight,
const QString &type, int borderWidth, const QString &borderColor, const QString &type, int borderWidth, const QString &borderColor,
const QString &normalBgColor, const QString &darkBgColor, const QString &normalBgColor, const QString &darkBgColor,
@ -130,16 +130,16 @@ void IconFont::setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QChar>
QString strBorder; QString strBorder;
if (type == "top") { if (type == "top") {
strBorder = QString("border-width:%1px 0px 0px 0px;padding:%1px %2px %2px %2px;") 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") { } else if (type == "right") {
strBorder = QString("border-width:0px %1px 0px 0px;padding:%2px %1px %2px %2px;") 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") { } else if (type == "bottom") {
strBorder = QString("border-width:0px 0px %1px 0px;padding:%2px %2px %1px %2px;") 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") { } else if (type == "left") {
strBorder = QString("border-width:0px 0px 0px %1px;padding:%2px %2px %2px %1px;") 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<QToolButton *> btns, QList<QChar>
widget->setStyleSheet(qss.join("")); widget->setStyleSheet(qss.join(""));
//存储对应按钮对象,方便鼠标移上去的时候切换图片
for (int i = 0; i < btnCount; i++) { for (int i = 0; i < btnCount; i++) {
//存储对应按钮对象,方便鼠标移上去的时候切换图片 int icon = icons.at(i);
QPixmap pixNormal = getPixmap(normalTextColor, icons.at(i), iconSize, iconWidth, iconHeight); QPixmap pixNormal = getPixmap(normalTextColor, icon, iconSize, iconWidth, iconHeight);
QPixmap pixDark = getPixmap(darkTextColor, icons.at(i), iconSize, iconWidth, iconHeight); QPixmap pixDark = getPixmap(darkTextColor, icon, iconSize, iconWidth, iconHeight);
btns.at(i)->setIcon(QIcon(pixNormal)); btns.at(i)->setIcon(QIcon(pixNormal));
btns.at(i)->setIconSize(QSize(iconWidth, iconHeight)); btns.at(i)->setIconSize(QSize(iconWidth, iconHeight));
@ -183,7 +184,7 @@ void IconFont::setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QChar>
} }
} }
void IconFont::setStyle(QFrame *frame, QList<QToolButton *> btns, QList<QChar> icons, void IconFont::setStyle(QFrame *frame, QList<QToolButton *> btns, QList<int> icons,
quint32 iconSize, quint32 iconWidth, quint32 iconHeight, quint32 iconSize, quint32 iconWidth, quint32 iconHeight,
const QString &normalBgColor, const QString &darkBgColor, const QString &normalBgColor, const QString &darkBgColor,
const QString &normalTextColor, const QString &darkTextColor) const QString &normalTextColor, const QString &darkTextColor)
@ -203,10 +204,11 @@ void IconFont::setStyle(QFrame *frame, QList<QToolButton *> btns, QList<QChar> i
frame->setStyleSheet(qss.join("")); frame->setStyleSheet(qss.join(""));
for (int i = 0; i < btnCount; i++) { //存储对应按钮对象,方便鼠标移上去的时候切换图片
//存储对应按钮对象,方便鼠标移上去的时候切换图片 for (int i = 0; i < btnCount; i++) {
QPixmap pixNormal = getPixmap(normalTextColor, icons.at(i), iconSize, iconWidth, iconHeight); int icon = icons.at(i);
QPixmap pixDark = getPixmap(darkTextColor, icons.at(i), iconSize, iconWidth, iconHeight); 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)->setIcon(QIcon(pixNormal));
btns.at(i)->setIconSize(QSize(iconWidth, iconHeight)); btns.at(i)->setIconSize(QSize(iconWidth, iconHeight));

View File

@ -3,7 +3,7 @@
#include <QtCore> #include <QtCore>
#include <QtGui> #include <QtGui>
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
#include <QtWidgets> #include <QtWidgets>
#endif #endif
@ -20,9 +20,9 @@ public:
static IconFont *Instance(); static IconFont *Instance();
explicit IconFont(QObject *parent = 0); explicit IconFont(QObject *parent = 0);
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, quint32 pixWidth = 15, quint32 pixHeight = 15,
int flags = Qt::AlignCenter); int flags = Qt::AlignCenter);
@ -38,7 +38,7 @@ public:
const QString &darkTextColor = "#FDFDFD"); const QString &darkTextColor = "#FDFDFD");
//指定导航面板样式,带图标和效果切换 //指定导航面板样式,带图标和效果切换
void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QChar> icons, void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> icons,
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15, quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
const QString &type = "left", int borderWidth = 3, const QString &type = "left", int borderWidth = 3,
const QString &borderColor = "#029FEA", const QString &borderColor = "#029FEA",
@ -48,7 +48,7 @@ public:
const QString &darkTextColor = "#FDFDFD"); const QString &darkTextColor = "#FDFDFD");
//指定导航按钮样式,带图标和效果切换 //指定导航按钮样式,带图标和效果切换
void setStyle(QFrame *frame, QList<QToolButton *> btns, QList<QChar> icons, void setStyle(QFrame *frame, QList<QToolButton *> btns, QList<int> icons,
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15, quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
const QString &normalBgColor = "#2FC5A2", const QString &normalBgColor = "#2FC5A2",
const QString &darkBgColor = "#3EA7E9", const QString &darkBgColor = "#3EA7E9",

View File

@ -39,21 +39,21 @@ QFont IconHelper::getIconFont()
return this->iconFont; 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); iconFont.setPixelSize(size);
lab->setFont(iconFont); 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); iconFont.setPixelSize(size);
btn->setFont(iconFont); 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) quint32 pixWidth, quint32 pixHeight, int flags)
{ {
QPixmap pix(pixWidth, pixHeight); QPixmap pix(pixWidth, pixHeight);
@ -66,7 +66,7 @@ QPixmap IconHelper::getPixmap(const QColor &color, const QChar &icon, quint32 si
iconFont.setPixelSize(size); iconFont.setPixelSize(size);
painter.setFont(iconFont); painter.setFont(iconFont);
painter.drawText(pix.rect(), flags, icon); painter.drawText(pix.rect(), flags, (QChar)icon);
painter.end(); painter.end();
return pix; return pix;
@ -106,7 +106,7 @@ QPixmap IconHelper::getPixmap(QToolButton *btn, int type)
return pix; return pix;
} }
void IconHelper::setStyle(QFrame *frame, QList<QToolButton *> btns, QList<QChar> icons, void IconHelper::setStyle(QFrame *frame, QList<QToolButton *> btns, QList<int> icons,
quint32 iconSize, quint32 iconWidth, quint32 iconHeight, quint32 iconSize, quint32 iconWidth, quint32 iconHeight,
const QString &normalBgColor, const QString &darkBgColor, const QString &normalBgColor, const QString &darkBgColor,
const QString &normalTextColor, const QString &darkTextColor) const QString &normalTextColor, const QString &darkTextColor)
@ -127,8 +127,9 @@ void IconHelper::setStyle(QFrame *frame, QList<QToolButton *> btns, QList<QChar>
//存储对应按钮对象,方便鼠标移上去的时候切换图片 //存储对应按钮对象,方便鼠标移上去的时候切换图片
for (int i = 0; i < btnCount; i++) { for (int i = 0; i < btnCount; i++) {
QPixmap pixNormal = getPixmap(normalTextColor, icons.at(i), iconSize, iconWidth, iconHeight); int icon = icons.at(i);
QPixmap pixDark = getPixmap(darkTextColor, icons.at(i), iconSize, iconWidth, iconHeight); QPixmap pixNormal = getPixmap(normalTextColor, icon, iconSize, iconWidth, iconHeight);
QPixmap pixDark = getPixmap(darkTextColor, icon, iconSize, iconWidth, iconHeight);
QToolButton *btn = btns.at(i); QToolButton *btn = btns.at(i);
btn->setIcon(QIcon(pixNormal)); btn->setIcon(QIcon(pixNormal));
@ -194,7 +195,7 @@ void IconHelper::removeStyle(QList<QToolButton *> btns)
} }
} }
void IconHelper::setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QChar> icons, void IconHelper::setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> icons,
quint32 iconSize, quint32 iconWidth, quint32 iconHeight, quint32 iconSize, quint32 iconWidth, quint32 iconHeight,
const QString &type, int borderWidth, const QString &borderColor, const QString &type, int borderWidth, const QString &borderColor,
const QString &normalBgColor, const QString &darkBgColor, const QString &normalBgColor, const QString &darkBgColor,
@ -247,8 +248,9 @@ void IconHelper::setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QCha
//存储对应按钮对象,方便鼠标移上去的时候切换图片 //存储对应按钮对象,方便鼠标移上去的时候切换图片
for (int i = 0; i < btnCount; i++) { for (int i = 0; i < btnCount; i++) {
QPixmap pixNormal = getPixmap(normalTextColor, icons.at(i), iconSize, iconWidth, iconHeight); int icon = icons.at(i);
QPixmap pixDark = getPixmap(darkTextColor, icons.at(i), iconSize, iconWidth, iconHeight); QPixmap pixNormal = getPixmap(normalTextColor, icon, iconSize, iconWidth, iconHeight);
QPixmap pixDark = getPixmap(darkTextColor, icon, iconSize, iconWidth, iconHeight);
QToolButton *btn = btns.at(i); QToolButton *btn = btns.at(i);
btn->setIcon(QIcon(pixNormal)); btn->setIcon(QIcon(pixNormal));
@ -264,7 +266,7 @@ void IconHelper::setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QCha
} }
} }
void IconHelper::setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QChar> icons, const IconHelper::StyleColor &styleColor) void IconHelper::setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> icons, const IconHelper::StyleColor &styleColor)
{ {
int btnCount = btns.count(); int btnCount = btns.count();
int charCount = icons.count(); int charCount = icons.count();
@ -320,10 +322,11 @@ void IconHelper::setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QCha
//存储对应按钮对象,方便鼠标移上去的时候切换图片 //存储对应按钮对象,方便鼠标移上去的时候切换图片
for (int i = 0; i < btnCount; i++) { for (int i = 0; i < btnCount; i++) {
QPixmap pixNormal = getPixmap(styleColor.normalTextColor, icons.at(i), iconSize, iconWidth, iconHeight); int icon = icons.at(i);
QPixmap pixHover = getPixmap(styleColor.hoverTextColor, icons.at(i), iconSize, iconWidth, iconHeight); QPixmap pixNormal = getPixmap(styleColor.normalTextColor, icon, iconSize, iconWidth, iconHeight);
QPixmap pixPressed = getPixmap(styleColor.pressedTextColor, icons.at(i), iconSize, iconWidth, iconHeight); QPixmap pixHover = getPixmap(styleColor.hoverTextColor, icon, iconSize, iconWidth, iconHeight);
QPixmap pixChecked = getPixmap(styleColor.checkedTextColor, icons.at(i), iconSize, iconWidth, iconHeight); QPixmap pixPressed = getPixmap(styleColor.pressedTextColor, icon, iconSize, iconWidth, iconHeight);
QPixmap pixChecked = getPixmap(styleColor.checkedTextColor, icon, iconSize, iconWidth, iconHeight);
QToolButton *btn = btns.at(i); QToolButton *btn = btns.at(i);
btn->setIcon(QIcon(pixNormal)); btn->setIcon(QIcon(pixNormal));

View File

@ -3,7 +3,7 @@
#include <QtCore> #include <QtCore>
#include <QtGui> #include <QtGui>
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
#include <QtWidgets> #include <QtWidgets>
#endif #endif
@ -24,12 +24,12 @@ public:
QFont getIconFont(); 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, quint32 pixWidth = 15, quint32 pixHeight = 15,
int flags = Qt::AlignCenter); int flags = Qt::AlignCenter);
@ -38,7 +38,7 @@ public:
QPixmap getPixmap(QToolButton *btn, int type); QPixmap getPixmap(QToolButton *btn, int type);
//指定QFrame导航按钮样式,带图标 //指定QFrame导航按钮样式,带图标
void setStyle(QFrame *frame, QList<QToolButton *> btns, QList<QChar> icons, void setStyle(QFrame *frame, QList<QToolButton *> btns, QList<int> icons,
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15, quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
const QString &normalBgColor = "#2FC5A2", const QString &normalBgColor = "#2FC5A2",
const QString &darkBgColor = "#3EA7E9", const QString &darkBgColor = "#3EA7E9",
@ -57,7 +57,7 @@ public:
void removeStyle(QList<QToolButton *> btns); void removeStyle(QList<QToolButton *> btns);
//指定QWidget导航面板样式,带图标和效果切换 //指定QWidget导航面板样式,带图标和效果切换
void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QChar> icons, void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> icons,
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15, quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
const QString &type = "left", int borderWidth = 3, const QString &type = "left", int borderWidth = 3,
const QString &borderColor = "#029FEA", const QString &borderColor = "#029FEA",
@ -101,7 +101,7 @@ public:
}; };
//指定QWidget导航面板样式,带图标和效果切换+悬停颜色+按下颜色+选中颜色 //指定QWidget导航面板样式,带图标和效果切换+悬停颜色+按下颜色+选中颜色
void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<QChar> icons, const StyleColor &styleColor); void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> icons, const StyleColor &styleColor);
protected: protected:
bool eventFilter(QObject *watched, QEvent *event); bool eventFilter(QObject *watched, QEvent *event);

View File

@ -1,11 +1,11 @@
#include "quiconfig.h" #include "quiconfig.h"
QChar QUIConfig::IconMain = 0xf072; int QUIConfig::IconMain = 0xf072;
QChar QUIConfig::IconMenu = 0xf0d7; int QUIConfig::IconMenu = 0xf0d7;
QChar QUIConfig::IconMin = 0xf068; int QUIConfig::IconMin = 0xf068;
QChar QUIConfig::IconMax = 0xf2d2; int QUIConfig::IconMax = 0xf2d2;
QChar QUIConfig::IconNormal = 0xf2d0; int QUIConfig::IconNormal = 0xf2d0;
QChar QUIConfig::IconClose = 0xf00d; int QUIConfig::IconClose = 0xf00d;
#ifdef __arm__ #ifdef __arm__
QString QUIConfig::FontName = "WenQuanYi Micro Hei"; QString QUIConfig::FontName = "WenQuanYi Micro Hei";

View File

@ -7,12 +7,12 @@ class QUIConfig
{ {
public: public:
//全局图标 //全局图标
static QChar IconMain; //标题栏左上角图标 static int IconMain; //标题栏左上角图标
static QChar IconMenu; //下拉菜单图标 static int IconMenu; //下拉菜单图标
static QChar IconMin; //最小化图标 static int IconMin; //最小化图标
static QChar IconMax; //最大化图标 static int IconMax; //最大化图标
static QChar IconNormal; //还原图标 static int IconNormal; //还原图标
static QChar IconClose; //关闭图标 static int IconClose; //关闭图标
//全局字体 //全局字体
static QString FontName; //全局字体名称 static QString FontName; //全局字体名称

View File

@ -256,7 +256,7 @@ QString QUIDateSelect::getEndDateTime() const
return this->endDateTime; 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); IconHelper::Instance()->setIcon(this->labIco, icon, size);
} }

View File

@ -57,7 +57,7 @@ public:
QString getEndDateTime() const; QString getEndDateTime() const;
public Q_SLOTS: public Q_SLOTS:
void setIconMain(const QChar &icon, quint32 size = 12); void setIconMain(int icon, quint32 size = 12);
void setFormat(const QString &format); void setFormat(const QString &format);
}; };

View File

@ -1,23 +1,24 @@
#include "quihelper.h" #include "quihelper.h"
QString QUIHelper::getUuid()
{
QString uuid = QUuid::createUuid().toString();
uuid = uuid.replace("{", "");
uuid = uuid.replace("}", "");
return uuid;
}
int QUIHelper::getScreenIndex() 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(); int screenCount = qApp->desktop()->screenCount();
#endif
if (screenCount > 1) { if (screenCount > 1) {
//找到当前鼠标所在屏幕 //找到当前鼠标所在屏幕
QPoint pos = QCursor::pos(); QPoint pos = QCursor::pos();
for (int i = 0; i < screenCount; ++i) { 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)) { if (qApp->desktop()->screenGeometry(i).contains(pos)) {
#endif
screenIndex = i; screenIndex = i;
break; break;
} }
@ -26,18 +27,50 @@ int QUIHelper::getScreenIndex()
return screenIndex; 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 QUIHelper::deskWidth()
{ {
int screenIndex = QUIHelper::getScreenIndex(); return getScreenRect().width();
int width = qApp->desktop()->availableGeometry(screenIndex).width();
return width;
} }
int QUIHelper::deskHeight() int QUIHelper::deskHeight()
{ {
int screenIndex = QUIHelper::getScreenIndex(); return getScreenRect().height();
int height = qApp->desktop()->availableGeometry(screenIndex).height(); }
return 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() QString QUIHelper::appName()
@ -64,11 +97,98 @@ QString QUIHelper::appPath()
#endif #endif
} }
QString QUIHelper::getUuid()
{
QString uuid = QUuid::createUuid().toString();
uuid = uuid.replace("{", "");
uuid = uuid.replace("}", "");
return uuid;
}
void QUIHelper::initRand() void QUIHelper::initRand()
{ {
//初始化随机数种子 //初始化随机数种子
QTime t = QTime::currentTime(); 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) void QUIHelper::initDb(const QString &dbName)
@ -122,14 +242,14 @@ bool QUIHelper::checkIniFile(const QString &iniFile)
return true; 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 size = 16;
int width = 18; int width = 18;
int height = 18; int height = 18;
QPixmap pix; QPixmap pix;
if (QPixmap(png).isNull()) { 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 { } else {
pix = QPixmap(png); pix = QPixmap(png);
} }
@ -138,22 +258,6 @@ void QUIHelper::setIconBtn(QAbstractButton *btn, const QString &png, const QChar
btn->setIcon(QIcon(pix)); 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) void QUIHelper::writeInfo(const QString &info, bool needWrite, const QString &filePath)
{ {
if (!needWrite) { if (!needWrite) {
@ -231,80 +335,6 @@ void QUIHelper::setFramelessForm(QWidget *widgetMain, QWidget *widgetTitle,
IconHelper::Instance()->setIcon(btnClose, QUIConfig::IconClose, QUIConfig::FontSize); 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) 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 #ifdef Q_OS_WIN
@ -340,8 +370,10 @@ QString QUIHelper::getIP(const QString &url)
{ {
//取出IP地址 //取出IP地址
QRegExp regExp("((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))"); 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); int start = regExp.indexIn(url);
return url.mid(url.indexOf(regExp), regExp.matchedLength()); int length = regExp.matchedLength();
QString ip = url.mid(start, length);
return ip;
} }
bool QUIHelper::isIP(const QString &ip) bool QUIHelper::isIP(const QString &ip)
@ -1180,7 +1212,7 @@ void QUIHelper::initTableView(QTableView *tableView, int rowHeight, bool headVis
tableView->setSelectionMode(QAbstractItemView::SingleSelection); 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); tableView->horizontalHeader()->setSectionsClickable(false);
#else #else
tableView->horizontalHeader()->setClickable(false); tableView->horizontalHeader()->setClickable(false);

View File

@ -6,21 +6,32 @@
class QUIHelper class QUIHelper
{ {
public: public:
//获取uuid //获取当前鼠标所在屏幕索引+尺寸
static QString getUuid();
//获取当前鼠标所在屏幕
static int getScreenIndex(); static int getScreenIndex();
static QRect getScreenRect(bool available = true);
//桌面宽度高度 //获取桌面宽度高度+居中显示
static int deskWidth(); static int deskWidth();
static int deskHeight(); static int deskHeight();
static void setFormInCenter(QWidget *form);
//程序文件名称+当前所在路径 //程序文件名称+当前所在路径
static QString appName(); static QString appName();
static QString appPath(); static QString appPath();
//初始化随机数种子 //获取uuid+初始化随机数种子+新建目录+延时
static QString getUuid();
static void initRand(); 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); static void initDb(const QString &dbName);
@ -31,10 +42,7 @@ public:
static bool checkIniFile(const QString &iniFile); static bool checkIniFile(const QString &iniFile);
//设置图标到按钮 //设置图标到按钮
static void setIconBtn(QAbstractButton *btn, const QString &png, const QChar &str); static void setIconBtn(QAbstractButton *btn, const QString &png, int icon);
//新建目录
static void newDir(const QString &dirName);
//写入消息到额外的的消息日志文件 //写入消息到额外的的消息日志文件
static void writeInfo(const QString &info, bool needWrite = false, const QString &filePath = "log"); static void writeInfo(const QString &info, bool needWrite = false, const QString &filePath = "log");
@ -47,18 +55,6 @@ public:
QLabel *labIco, QPushButton *btnClose, QLabel *labIco, QPushButton *btnClose,
bool tool = true, bool top = true, bool menu = false); 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, static void setSystemDateTime(const QString &year, const QString &month, const QString &day,
const QString &hour, const QString &min, const QString &sec); const QString &hour, const QString &min, const QString &sec);

View File

@ -285,7 +285,7 @@ void QUIInputBox::on_btnMenu_Close_clicked()
close(); close();
} }
void QUIInputBox::setIconMain(const QChar &icon, quint32 size) void QUIInputBox::setIconMain(int icon, quint32 size)
{ {
IconHelper::Instance()->setIcon(this->labIco, icon, size); IconHelper::Instance()->setIcon(this->labIco, icon, size);
} }

View File

@ -59,7 +59,7 @@ public:
QString getValue()const; QString getValue()const;
public Q_SLOTS: 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, void setParameter(const QString &title, int type = 0, int closeSec = 0,
QString placeholderText = QString(), bool pwd = false, QString placeholderText = QString(), bool pwd = false,
const QString &defaultValue = QString()); const QString &defaultValue = QString());

View File

@ -262,17 +262,17 @@ void QUIMessageBox::on_btnMenu_Close_clicked()
close(); close();
} }
void QUIMessageBox::setIconMain(const QChar &icon, quint32 size) void QUIMessageBox::setIconMain(int icon, quint32 size)
{ {
IconHelper::Instance()->setIcon(this->labIco, icon, 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(); int size = this->labIcoMain->size().height();
if (QImage(png).isNull()) { if (QImage(png).isNull()) {
IconHelper::Instance()->setIcon(this->labIcoMain, str, size); IconHelper::Instance()->setIcon(this->labIcoMain, icon, size);
} else { } else {
this->labIcoMain->setStyleSheet(QString("border-image:url(%1);").arg(png)); this->labIcoMain->setStyleSheet(QString("border-image:url(%1);").arg(png));
} }

View File

@ -56,8 +56,8 @@ private slots:
void on_btnMenu_Close_clicked(); void on_btnMenu_Close_clicked();
public Q_SLOTS: public Q_SLOTS:
void setIconMain(const QChar &icon, quint32 size = 12); void setIconMain(int icon, quint32 size = 12);
void setIconMsg(const QString &png, const QChar &str); void setIconMsg(const QString &png, int icon);
void setMessage(const QString &msg, int type, int closeSec = 0); void setMessage(const QString &msg, int type, int closeSec = 0);
}; };

View File

@ -198,7 +198,7 @@ void QUITipBox::on_btnMenu_Close_clicked()
close(); close();
} }
void QUITipBox::setIconMain(const QChar &icon, quint32 size) void QUITipBox::setIconMain(int icon, quint32 size)
{ {
IconHelper::Instance()->setIcon(this->labIco, icon, 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->labInfo->setAlignment(center ? Qt::AlignCenter : Qt::AlignLeft);
this->setWindowTitle(this->labTitle->text()); this->setWindowTitle(this->labTitle->text());
int screenIndex = QUIHelper::getScreenIndex(); QRect rect = QUIHelper::getScreenRect(!fullScreen);
QRect rect = fullScreen ? qApp->desktop()->screenGeometry(screenIndex) : qApp->desktop()->availableGeometry(screenIndex);
int width = rect.width(); int width = rect.width();
int height = rect.height(); int height = rect.height();
int x = width - this->width() + rect.x(); 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() void QUITipBox::hide()
{ {
int screenIndex = QUIHelper::getScreenIndex(); QRect rect = QUIHelper::getScreenRect(!fullScreen);
QRect rect = fullScreen ? qApp->desktop()->screenGeometry(screenIndex) : qApp->desktop()->availableGeometry(screenIndex);
int width = rect.width(); int width = rect.width();
int height = rect.height(); int height = rect.height();
int x = width - this->width() + rect.x(); int x = width - this->width() + rect.x();
@ -245,7 +243,7 @@ void QUITipBox::hide()
//启动动画 //启动动画
animation->stop(); animation->stop();
animation->setStartValue(QPoint(x, y)); animation->setStartValue(QPoint(x, y));
animation->setEndValue(QPoint(x, qApp->desktop()->geometry().height())); animation->setEndValue(QPoint(x, QUIHelper::getScreenRect(false).height()));
animation->start(); animation->start();
} }

View File

@ -49,7 +49,7 @@ private slots:
void on_btnMenu_Close_clicked(); void on_btnMenu_Close_clicked();
public Q_SLOTS: 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 setTip(const QString &title, const QString &tip, bool fullScreen = false, bool center = true, int closeSec = 0);
void hide(); void hide();
}; };

View File

@ -271,7 +271,7 @@ void QUIWidget::changeStyle()
emit changeStyle(qssFile); 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) { if (widget == QUIWidget::Lab_Ico) {
setIconMain(icon, size); 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; QUIConfig::IconMain = icon;
IconHelper::Instance()->setIcon(this->labIco, icon, size); IconHelper::Instance()->setIcon(this->labIco, icon, size);
@ -418,8 +418,7 @@ void QUIWidget::on_btnMenu_Max_clicked()
setIcon(QUIWidget::BtnMenu_Normal, QUIConfig::IconNormal); setIcon(QUIWidget::BtnMenu_Normal, QUIConfig::IconNormal);
} else { } else {
location = this->geometry(); location = this->geometry();
int screenIndex = QUIHelper::getScreenIndex(); this->setGeometry(QUIHelper::getScreenRect());
this->setGeometry(qApp->desktop()->availableGeometry(screenIndex));
setIcon(QUIWidget::BtnMenu_Max, QUIConfig::IconMax); setIcon(QUIWidget::BtnMenu_Max, QUIConfig::IconMax);
} }

View File

@ -77,8 +77,8 @@ private slots:
public Q_SLOTS: public Q_SLOTS:
//设置部件图标 //设置部件图标
void setIcon(QUIWidget::Widget widget, const QChar &icon, quint32 size = 12); void setIcon(QUIWidget::Widget widget, int icon, quint32 size = 12);
void setIconMain(const QChar &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)); void setPixmap(QUIWidget::Widget widget, const QString &file, const QSize &size = QSize(16, 16));
//设置部件是否可见 //设置部件是否可见

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = countcode TARGET = countcode
TEMPLATE = app TEMPLATE = app

View File

@ -39,7 +39,7 @@ QVariant SqlQueryModel::data(const QModelIndex &index, int role) const
if (row == index.row()) { if (row == index.row()) {
if (role == Qt::BackgroundRole) { if (role == Qt::BackgroundRole) {
value = QColor(property("hoverBgColor").toString()); value = QColor(property("hoverBgColor").toString());
} else if (role == Qt::TextColorRole) { } else if (role == Qt::ForegroundRole) {
value = QColor(property("hoverTextColor").toString()); value = QColor(property("hoverTextColor").toString());
} }
} }

View File

@ -7,6 +7,7 @@
QT += core gui sql QT += core gui sql
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = dbpage TARGET = dbpage
TEMPLATE = app TEMPLATE = app

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = devicebutton TARGET = devicebutton
TEMPLATE = app TEMPLATE = app

View File

@ -21,6 +21,7 @@ class DeviceSizeTable : public QTableWidget
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QColor bgColor READ getBgColor WRITE setBgColor) Q_PROPERTY(QColor bgColor READ getBgColor WRITE setBgColor)
Q_PROPERTY(QColor chunkColor1 READ getChunkColor1 WRITE setChunkColor1) Q_PROPERTY(QColor chunkColor1 READ getChunkColor1 WRITE setChunkColor1)
Q_PROPERTY(QColor chunkColor2 READ getChunkColor2 WRITE setChunkColor2) Q_PROPERTY(QColor chunkColor2 READ getChunkColor2 WRITE setChunkColor2)

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = devicesizetable TARGET = devicesizetable
TEMPLATE = app TEMPLATE = app

View File

@ -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, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = emailtool TARGET = emailtool
TEMPLATE = app TEMPLATE = app
@ -14,10 +15,10 @@ DESTDIR = $$PWD/../bin
CONFIG += warn_off CONFIG += warn_off
SOURCES += main.cpp SOURCES += main.cpp
SOURCES += frmemailtool.cpp SOURCES += frmemailtool.cpp sendemailthread.cpp
HEADERS += frmemailtool.h HEADERS += frmemailtool.h sendemailthread.h
FORMS += frmemailtool.ui FORMS += frmemailtool.ui
include ($$PWD/sendemail/sendemail.pri)
INCLUDEPATH += $$PWD INCLUDEPATH += $$PWD
INCLUDEPATH += $$PWD/sendemail INCLUDEPATH += $$PWD/../3rd_smtpclient
include ($$PWD/../3rd_smtpclient/3rd_smtpclient.pri)

View File

@ -13,174 +13,180 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin"> <item>
<number>6</number> <layout class="QGridLayout" name="gridLayout">
</property> <item row="2" column="4">
<property name="topMargin"> <widget class="QPushButton" name="btnSend">
<number>6</number> <property name="cursor">
</property> <cursorShape>PointingHandCursor</cursorShape>
<property name="rightMargin"> </property>
<number>6</number> <property name="text">
</property> <string>发送</string>
<property name="bottomMargin"> </property>
<number>6</number> </widget>
</property>
<item row="0" column="0">
<widget class="QLabel" name="labSenderAddr">
<property name="text">
<string>用户名:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtSenderAddr">
<property name="text">
<string>feiyangqingyun@126.com</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="labSenderPwd">
<property name="text">
<string>密码:</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLineEdit" name="txtSenderPwd">
<property name="text">
<string/>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QLabel" name="labServer">
<property name="text">
<string>服务器:</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QComboBox" name="cboxServer">
<item>
<property name="text">
<string>smtp.163.com</string>
</property>
</item> </item>
<item> <item row="1" column="3">
<property name="text"> <widget class="QComboBox" name="cboxPort">
<string>smtp.126.com</string> <item>
</property> <property name="text">
<string>25</string>
</property>
</item>
<item>
<property name="text">
<string>465</string>
</property>
</item>
<item>
<property name="text">
<string>587</string>
</property>
</item>
</widget>
</item> </item>
<item> <item row="1" column="4">
<property name="text"> <widget class="QCheckBox" name="ckSSL">
<string>smtp.qq.com</string> <property name="text">
</property> <string>SSL</string>
</property>
</widget>
</item> </item>
<item> <item row="1" column="2">
<property name="text"> <widget class="QLabel" name="labPort">
<string>smt.sina.com</string> <property name="text">
</property> <string>服务端口</string>
</property>
</widget>
</item> </item>
<item> <item row="3" column="4">
<property name="text"> <widget class="QPushButton" name="btnSelect">
<string>smtp.sohu.com</string> <property name="cursor">
</property> <cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>浏览</string>
</property>
</widget>
</item> </item>
<item> <item row="2" column="3">
<property name="text"> <widget class="QLineEdit" name="txtReceiverAddr">
<string>smtp.139.com</string> <property name="text">
</property> <string>feiyangqingyun@163.com;517216493@qq.com</string>
</property>
</widget>
</item> </item>
<item> <item row="3" column="1" colspan="3">
<property name="text"> <widget class="QLineEdit" name="txtFileName"/>
<string>smtp.189.com</string>
</property>
</item> </item>
</widget> <item row="2" column="0">
</item> <widget class="QLabel" name="labTitle">
<item row="0" column="6"> <property name="text">
<widget class="QLabel" name="labPort"> <string>邮件标题</string>
<property name="text"> </property>
<string>端口:</string> </widget>
</property>
</widget>
</item>
<item row="0" column="7">
<widget class="QComboBox" name="cboxPort">
<item>
<property name="text">
<string>25</string>
</property>
</item> </item>
<item> <item row="2" column="1">
<property name="text"> <widget class="QLineEdit" name="txtTitle">
<string>465</string> <property name="text">
</property> <string>测试邮件</string>
</property>
</widget>
</item> </item>
<item> <item row="1" column="1">
<property name="text"> <widget class="QComboBox" name="cboxServer">
<string>587</string> <item>
</property> <property name="text">
<string>smtp.163.com</string>
</property>
</item>
<item>
<property name="text">
<string>smtp.126.com</string>
</property>
</item>
<item>
<property name="text">
<string>smtp.qq.com</string>
</property>
</item>
<item>
<property name="text">
<string>smt.sina.com</string>
</property>
</item>
<item>
<property name="text">
<string>smtp.sohu.com</string>
</property>
</item>
<item>
<property name="text">
<string>smtp.139.com</string>
</property>
</item>
<item>
<property name="text">
<string>smtp.189.com</string>
</property>
</item>
</widget>
</item> </item>
</widget> <item row="2" column="2">
<widget class="QLabel" name="labReceiverAddr">
<property name="text">
<string>收件地址</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labFileName">
<property name="text">
<string>选择附件</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labServer">
<property name="text">
<string>服务地址</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labSenderAddr">
<property name="text">
<string>用户名称</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtSenderAddr">
<property name="text">
<string>feiyangqingyun@126.com</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="labSenderPwd">
<property name="text">
<string>用户密码</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLineEdit" name="txtSenderPwd">
<property name="text">
<string/>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</item> </item>
<item row="0" column="8"> <item>
<widget class="QCheckBox" name="ckSSL">
<property name="text">
<string>SSL</string>
</property>
</widget>
</item>
<item row="0" column="9">
<widget class="QPushButton" name="btnSend">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>发送</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labTitle">
<property name="text">
<string>标 题:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labFileName">
<property name="text">
<string>附 件:</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="labContent">
<property name="text">
<string>正 文:</string>
</property>
</widget>
</item>
<item row="4" column="9">
<widget class="QPushButton" name="btnSelect">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>浏览</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="8">
<widget class="QLineEdit" name="txtFileName"/>
</item>
<item row="5" column="1" colspan="9">
<widget class="QTextBrowser" name="txtContent"> <widget class="QTextBrowser" name="txtContent">
<property name="readOnly"> <property name="readOnly">
<bool>false</bool> <bool>false</bool>
@ -189,35 +195,27 @@
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt; <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt; &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; } p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'宋体'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt; &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'SimSun'; font-size:9.07563pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:11pt;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、最短的爱情哲理小说:“&lt;/span&gt;&lt;span style=&quot; font-size:11pt;&quot;&gt;你应该嫁给我啦?&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;” “ &lt;/span&gt;&lt;span style=&quot; font-size:11pt;&quot;&gt;不&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;” &lt;/span&gt;&lt;span style=&quot; font-size:11pt;&quot;&gt;于是他俩又继续幸福地生活在一起&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot; font-size:11pt;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、近年来中国最精彩的写实小说,全文八个字:&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:16pt; font-weight:600; font-style:italic; color:#ff007f;&quot;&gt;此地钱多人傻速来&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;  据说是发自杭州市宝石山下一出租房的汇款单上的简短附言,是该按摩女给家乡妹妹汇 款时随手涂鸦的,令无数专业作家汗颜!&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot; font-size:11pt;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、最短的幽默小说 《夜》 男:疼么?女:恩!男:算了?女:别!&lt;/span&gt;&lt;/p&gt; &lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'宋体'; font-size:11pt;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、最短的爱情哲理小说:“&lt;/span&gt;&lt;span style=&quot; font-family:'宋体'; font-size:11pt;&quot;&gt;你应该嫁给我啦?&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;” “ &lt;/span&gt;&lt;span style=&quot; font-family:'宋体'; font-size:11pt;&quot;&gt;不&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;” &lt;/span&gt;&lt;span style=&quot; font-family:'宋体'; font-size:11pt;&quot;&gt;于是他俩又继续幸福地生活在一起&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot; font-family:'宋体'; font-size:11pt;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、近年来中国最精彩的写实小说,全文八个字:&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:16pt; font-weight:600; font-style:italic; color:#ff007f;&quot;&gt;此地钱多人傻速来&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;  据说是发自杭州市宝石山下一出租房的汇款单上的简短附言,是该按摩女给家乡妹妹汇 款时随手涂鸦的,令无数专业作家汗颜!&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot; font-family:'宋体'; font-size:11pt;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、最短的幽默小说 《夜》 男:疼么?女:恩!男:算了?女:别!&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:11pt;&quot;&gt;4&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、最短的荒诞小说:有一个面包走在街上,它觉得自己很饿,就把自己吃了。&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot; font-size:11pt;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、世界最短言情小说:他死的那天,孩子出生了。&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot; font-size:11pt;&quot;&gt;6&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、世界最短武侠小说:&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt; font-weight:600; color:#00aa00;&quot;&gt;高手被豆腐砸死了&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;。&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot; font-size:11pt;&quot;&gt;7&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、世界最短科幻小说:最后一个地球人坐在家里,突然响起了敲门声。&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot; font-size:11pt;&quot;&gt;8&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、世界最短悬疑小说:生,死,生。&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot; font-size:11pt;&quot;&gt;9&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、世界最短推理小说:他死了,一定曾经活过。 &lt;br /&gt;1&lt;/span&gt;&lt;span style=&quot; font-size:11pt;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、世界最短恐怖小说:惊醒,身边躺着自己的尸体。&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> &lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'宋体'; font-size:11pt;&quot;&gt;4&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、最短的荒诞小说:有一个面包走在街上,它觉得自己很饿,就把自己吃了。&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot; font-family:'宋体'; font-size:11pt;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、世界最短言情小说:他死的那天,孩子出生了。&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot; font-family:'宋体'; font-size:11pt;&quot;&gt;6&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、世界最短武侠小说:&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt; font-weight:600; color:#00aa00;&quot;&gt;高手被豆腐砸死了&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;。&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot; font-family:'宋体'; font-size:11pt;&quot;&gt;7&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、世界最短科幻小说:最后一个地球人坐在家里,突然响起了敲门声。&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot; font-family:'宋体'; font-size:11pt;&quot;&gt;8&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、世界最短悬疑小说:生,死,生。&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot; font-family:'宋体'; font-size:11pt;&quot;&gt;9&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、世界最短推理小说:他死了,一定曾经活过。 &lt;br /&gt;1&lt;/span&gt;&lt;span style=&quot; font-family:'宋体'; font-size:11pt;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot; font-family:'Times New Roman'; font-size:11pt;&quot;&gt;、世界最短恐怖小说:惊醒,身边躺着自己的尸体。&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="3">
<widget class="QLineEdit" name="txtTitle">
<property name="text">
<string>测试邮件</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QLabel" name="labReceiverAddr">
<property name="text">
<string>收件人:</string>
</property>
</widget>
</item>
<item row="1" column="5" colspan="5">
<widget class="QLineEdit" name="txtReceiverAddr">
<property name="text">
<string>feiyangqingyun@163.com;517216493@qq.com</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<tabstops>
<tabstop>txtSenderAddr</tabstop>
<tabstop>txtSenderPwd</tabstop>
<tabstop>cboxServer</tabstop>
<tabstop>cboxPort</tabstop>
<tabstop>ckSSL</tabstop>
<tabstop>txtTitle</tabstop>
<tabstop>txtReceiverAddr</tabstop>
<tabstop>btnSend</tabstop>
<tabstop>txtFileName</tabstop>
<tabstop>btnSelect</tabstop>
<tabstop>txtContent</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -24,7 +24,7 @@ int main(int argc, char *argv[])
#endif #endif
frmEmailTool w; frmEmailTool w;
w.setWindowTitle("邮件发送工具"); w.setWindowTitle("串口调试助手 V2021 (QQ: 517216493 WX: feiyangqingyun)");
w.show(); w.show();
return a.exec(); return a.exec();

View File

@ -1,222 +0,0 @@
#include "mimemessage.h"
#include <QDateTime>
#include "quotedprintable.h"
#include <typeinfo>
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<EmailAddress *> &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<MimePart *> &MimeMessage::getParts() const
{
if (typeid(*content) == typeid(MimeMultiPart)) {
return ((MimeMultiPart *) content)->getParts();
} else {
QList<MimePart *> *res = new QList<MimePart *>();
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<EmailAddress *>::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;
}

View File

@ -1,67 +0,0 @@
#include "mimemultipart.h"
#include <QTime>
#include <QCryptographicHash>
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<MimePart *> &MimeMultiPart::getParts() const
{
return parts;
}
void MimeMultiPart::prepare()
{
QList<MimePart *>::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;
}

View File

@ -1,5 +1,5 @@
#include "sendemailthread.h" #include "sendemailthread.h"
#include "sendemail/smtpmime.h" #include "smtpmime.h"
#pragma execution_character_set("utf-8") #pragma execution_character_set("utf-8")
#define TIMEMS qPrintable(QTime::currentTime().toString("hh:mm:ss zzz")) #define TIMEMS qPrintable(QTime::currentTime().toString("hh:mm:ss zzz"))

View File

@ -1,6 +1,13 @@
#-------------------------------------------------
#
# Project created by QtCreator 2019-02-16T15:08:47
#
#-------------------------------------------------
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
android {QT += androidextras} android {QT += androidextras}
TARGET = ffmpegdemo TARGET = ffmpegdemo

View File

@ -1,9 +1,7 @@
#pragma execution_character_set("utf-8") #pragma execution_character_set("utf-8")
#include "widget.h" #include "widget.h"
#include <QApplication> #include <QApplication>
#include <QTextCodec> #include <QTextCodec>
#include <QDesktopWidget>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -35,12 +33,5 @@ int main(int argc, char *argv[])
w.setWindowTitle("视频流播放ffmpeg内核 (QQ: 517216493)"); w.setWindowTitle("视频流播放ffmpeg内核 (QQ: 517216493)");
w.show(); 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(); return a.exec();
} }

View File

@ -29,7 +29,7 @@ class Q_DECL_EXPORT FlatUI
class FlatUI class FlatUI
#endif #endif
{ {
public: public:
//设置按钮样式 //设置按钮样式
static QString setPushButtonQss(QPushButton *btn, //按钮对象 static QString setPushButtonQss(QPushButton *btn, //按钮对象

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = flatui TARGET = flatui
TEMPLATE = app TEMPLATE = app

View File

@ -4,7 +4,6 @@
#include "ui_frmflatui.h" #include "ui_frmflatui.h"
#include "flatui.h" #include "flatui.h"
#include "qdebug.h" #include "qdebug.h"
#include "qdesktopwidget.h"
#include "qdatetime.h" #include "qdatetime.h"
frmFlatUI::frmFlatUI(QWidget *parent) : QWidget(parent), ui(new Ui::frmFlatUI) 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"); 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->setColumnCount(5);
ui->tableWidget->setColumnWidth(0, width * 0.06); ui->tableWidget->setColumnWidth(0, width * 0.06);
ui->tableWidget->setColumnWidth(1, width * 0.10); ui->tableWidget->setColumnWidth(1, width * 0.10);
@ -82,7 +81,6 @@ void frmFlatUI::initForm()
for (int i = 0; i < 300; i++) { for (int i = 0; i < 300; i++) {
ui->tableWidget->setRowHeight(i, 24); ui->tableWidget->setRowHeight(i, 24);
QTableWidgetItem *itemDeviceID = new QTableWidgetItem(QString::number(i + 1)); QTableWidgetItem *itemDeviceID = new QTableWidgetItem(QString::number(i + 1));
QTableWidgetItem *itemDeviceName = new QTableWidgetItem(QString("测试设备%1").arg(i + 1)); QTableWidgetItem *itemDeviceName = new QTableWidgetItem(QString("测试设备%1").arg(i + 1));
QTableWidgetItem *itemDeviceAddr = new QTableWidgetItem(QString::number(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, 3, itemContent);
ui->tableWidget->setItem(i, 4, itemTime); ui->tableWidget->setItem(i, 4, itemTime);
} }
} }

View File

@ -9,7 +9,7 @@ int main(int argc, char *argv[])
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); 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 #if _MSC_VER
QTextCodec *codec = QTextCodec::codecForName("gbk"); QTextCodec *codec = QTextCodec::codecForName("gbk");
#else #else

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = framelesswidget TARGET = framelesswidget
TEMPLATE = app TEMPLATE = app

View File

@ -36,7 +36,7 @@ void frmFramelessWidget::initWidget(QWidget *w)
//设置下背景颜色区别看 //设置下背景颜色区别看
QPalette palette = w->palette(); QPalette palette = w->palette();
palette.setBrush(QPalette::Background, QColor(162, 121, 197)); palette.setBrush(QPalette::Window, QColor(162, 121, 197));
w->setPalette(palette); w->setPalette(palette);
QPushButton *btn = new QPushButton(w); QPushButton *btn = new QPushButton(w);

View File

@ -9,7 +9,7 @@ int main(int argc, char *argv[])
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); 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 #if _MSC_VER
QTextCodec *codec = QTextCodec::codecForName("gbk"); QTextCodec *codec = QTextCodec::codecForName("gbk");
#else #else

View File

@ -13,13 +13,19 @@
#include "qtimer.h" #include "qtimer.h"
#include "qdatetime.h" #include "qdatetime.h"
#include "qapplication.h" #include "qapplication.h"
#include "qdesktopwidget.h"
#include "qdesktopservices.h" #include "qdesktopservices.h"
#include "qfiledialog.h" #include "qfiledialog.h"
#include "qurl.h" #include "qurl.h"
#include "qdebug.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" #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 #endif
QScopedPointer<GifWidget> GifWidget::self; QScopedPointer<GifWidget> GifWidget::self;
@ -267,7 +273,7 @@ void GifWidget::saveImage()
return; return;
} }
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
//由于qt4没有RGBA8888,采用最接近RGBA8888的是ARGB32,颜色会有点偏差 //由于qt4没有RGBA8888,采用最接近RGBA8888的是ARGB32,颜色会有点偏差
QPixmap pix = QPixmap::grabWindow(0, x() + rectGif.x(), y() + rectGif.y(), rectGif.width(), rectGif.height()); QPixmap pix = QPixmap::grabWindow(0, x() + rectGif.x(), y() + rectGif.y(), rectGif.width(), rectGif.height());
QImage image = pix.toImage().convertToFormat(QImage::Format_ARGB32); QImage image = pix.toImage().convertToFormat(QImage::Format_ARGB32);

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = gifwidget TARGET = gifwidget
TEMPLATE = app TEMPLATE = app

View File

@ -11,7 +11,7 @@ int main(int argc, char *argv[])
a.setFont(QFont("Microsoft Yahei", 9)); a.setFont(QFont("Microsoft Yahei", 9));
a.setWindowIcon(QIcon(":/image/gifwidget.ico")); 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 #if _MSC_VER
QTextCodec *codec = QTextCodec::codecForName("gbk"); QTextCodec *codec = QTextCodec::codecForName("gbk");
#else #else

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = imageswitch TARGET = imageswitch
TEMPLATE = app TEMPLATE = app

View File

@ -24,6 +24,7 @@ class IPAddress : public QWidget
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString ip READ getIP WRITE setIP) Q_PROPERTY(QString ip READ getIP WRITE setIP)
public: public:

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = ipaddress TARGET = ipaddress
TEMPLATE = app TEMPLATE = app

View File

@ -442,7 +442,7 @@ void LightButton::alarm()
bgColor = normalColor; bgColor = normalColor;
} else { } else {
textColor = QColor(255, 255, 255); textColor = QColor(255, 255, 255);
bgColor = alarmColor; bgColor = alarmColor;
} }
this->update(); this->update();

View File

@ -25,6 +25,7 @@ class LightButton : public QWidget
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString text READ getText WRITE setText) Q_PROPERTY(QString text READ getText WRITE setText)
Q_PROPERTY(QColor textColor READ getTextColor WRITE setTextColor) Q_PROPERTY(QColor textColor READ getTextColor WRITE setTextColor)
Q_PROPERTY(QColor alarmColor READ getAlarmColor WRITE setAlarmColor) Q_PROPERTY(QColor alarmColor READ getAlarmColor WRITE setAlarmColor)

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = lightbutton TARGET = lightbutton
TEMPLATE = app TEMPLATE = app

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = lineeditnext TARGET = lineeditnext
TEMPLATE = app TEMPLATE = app

View File

@ -4,14 +4,13 @@
#include "qmutex.h" #include "qmutex.h"
#include "qmenu.h" #include "qmenu.h"
#include "qapplication.h" #include "qapplication.h"
#include "qdesktopwidget.h"
#include "qdebug.h" #include "qdebug.h"
QScopedPointer<TrayIcon> TrayIcon::self; QScopedPointer<TrayIcon> TrayIcon::self;
TrayIcon *TrayIcon::Instance() TrayIcon *TrayIcon::Instance()
{ {
if (self.isNull()) { if (self.isNull()) {
QMutex mutex; static QMutex mutex;
QMutexLocker locker(&mutex); QMutexLocker locker(&mutex);
if (self.isNull()) { if (self.isNull()) {
self.reset(new TrayIcon); self.reset(new TrayIcon);
@ -27,21 +26,21 @@ TrayIcon::TrayIcon(QObject *parent) : QObject(parent)
trayIcon = new QSystemTrayIcon(this); trayIcon = new QSystemTrayIcon(this);
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(iconIsActived(QSystemTrayIcon::ActivationReason))); this, SLOT(iconIsActived(QSystemTrayIcon::ActivationReason)));
menu = new QMenu(QApplication::desktop()); menu = new QMenu;
exitDirect = true; exitDirect = true;
} }
void TrayIcon::iconIsActived(QSystemTrayIcon::ActivationReason reason) void TrayIcon::iconIsActived(QSystemTrayIcon::ActivationReason reason)
{ {
switch (reason) { switch (reason) {
case QSystemTrayIcon::Trigger: case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::DoubleClick: { case QSystemTrayIcon::DoubleClick: {
mainWidget->showNormal(); mainWidget->showNormal();
break; break;
} }
default: default:
break; break;
} }
} }

View File

@ -3,10 +3,10 @@
/** /**
* :feiyangqingyun(QQ:517216493) 2017-1-8 * :feiyangqingyun(QQ:517216493) 2017-1-8
* 1: * 1.
* 2: * 2.
* 3: * 3.
* 4: * 4.
*/ */
#include <QObject> #include <QObject>
@ -15,13 +15,7 @@
class QMenu; class QMenu;
#ifdef quc #ifdef quc
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) class Q_DECL_EXPORT TrayIcon : public QObject
#include <QtDesigner/QDesignerExportWidget>
#else
#include <QtUiPlugin/QDesignerExportWidget>
#endif
class QDESIGNER_WIDGET_EXPORT TrayIcon : public QObject
#else #else
class TrayIcon : public QObject class TrayIcon : public QObject
#endif #endif

View File

@ -235,45 +235,45 @@ int LunarCalendarInfo::getMonthDays(int year, int month)
int loopDay = isLoopYear(year) ? 1 : 0; int loopDay = isLoopYear(year) ? 1 : 0;
switch (month) { switch (month) {
case 1: case 1:
countDay = 31; countDay = 31;
break; break;
case 2: case 2:
countDay = 28 + loopDay; countDay = 28 + loopDay;
break; break;
case 3: case 3:
countDay = 31; countDay = 31;
break; break;
case 4: case 4:
countDay = 30; countDay = 30;
break; break;
case 5: case 5:
countDay = 31; countDay = 31;
break; break;
case 6: case 6:
countDay = 30; countDay = 30;
break; break;
case 7: case 7:
countDay = 31; countDay = 31;
break; break;
case 8: case 8:
countDay = 31; countDay = 31;
break; break;
case 9: case 9:
countDay = 30; countDay = 30;
break; break;
case 10: case 10:
countDay = 31; countDay = 31;
break; break;
case 11: case 11:
countDay = 30; countDay = 30;
break; break;
case 12: case 12:
countDay = 31; countDay = 31;
break; break;
default: default:
countDay = 30; countDay = 30;
break; break;
} }
return countDay; return countDay;
@ -286,45 +286,45 @@ int LunarCalendarInfo::getTotalMonthDays(int year, int month)
int loopDay = isLoopYear(year) ? 1 : 0; int loopDay = isLoopYear(year) ? 1 : 0;
switch (month) { switch (month) {
case 1: case 1:
countDay = 0; countDay = 0;
break; break;
case 2: case 2:
countDay = 31; countDay = 31;
break; break;
case 3: case 3:
countDay = 59 + loopDay; countDay = 59 + loopDay;
break; break;
case 4: case 4:
countDay = 90 + loopDay; countDay = 90 + loopDay;
break; break;
case 5: case 5:
countDay = 120 + loopDay; countDay = 120 + loopDay;
break; break;
case 6: case 6:
countDay = 151 + loopDay; countDay = 151 + loopDay;
break; break;
case 7: case 7:
countDay = 181 + loopDay; countDay = 181 + loopDay;
break; break;
case 8: case 8:
countDay = 212 + loopDay; countDay = 212 + loopDay;
break; break;
case 9: case 9:
countDay = 243 + loopDay; countDay = 243 + loopDay;
break; break;
case 10: case 10:
countDay = 273 + loopDay; countDay = 273 + loopDay;
break; break;
case 11: case 11:
countDay = 304 + loopDay; countDay = 304 + loopDay;
break; break;
case 12: case 12:
countDay = 334 + loopDay; countDay = 334 + loopDay;
break; break;
default: default:
countDay = 0; countDay = 0;
break; break;
} }
return countDay; return countDay;
@ -347,89 +347,89 @@ QString LunarCalendarInfo::getHoliday(int month, int day)
QString strHoliday; QString strHoliday;
switch (temp) { switch (temp) {
case 0x0101: case 0x0101:
strHoliday = "元旦"; strHoliday = "元旦";
break; break;
case 0x020E: case 0x020E:
strHoliday = "情人节"; strHoliday = "情人节";
break; break;
case 0x0303: case 0x0303:
strHoliday = "爱耳日"; strHoliday = "爱耳日";
break; break;
case 0x0305: case 0x0305:
strHoliday = "志愿者服务日"; strHoliday = "志愿者服务日";
break; break;
case 0x0308: case 0x0308:
strHoliday = "妇女节"; strHoliday = "妇女节";
break; break;
case 0x0309: case 0x0309:
strHoliday = "保护母亲河"; strHoliday = "保护母亲河";
break; break;
case 0x030C: case 0x030C:
strHoliday = "植树节"; strHoliday = "植树节";
break; break;
case 0x030F: case 0x030F:
strHoliday = "消费者权益日"; strHoliday = "消费者权益日";
break; break;
case 0x0401: case 0x0401:
strHoliday = "愚人节"; strHoliday = "愚人节";
break; break;
case 0x0501: case 0x0501:
strHoliday = "劳动节"; strHoliday = "劳动节";
break; break;
case 0x0504: case 0x0504:
strHoliday = "青年节"; strHoliday = "青年节";
break; break;
case 0x0601: case 0x0601:
strHoliday = "儿童节"; strHoliday = "儿童节";
break; break;
case 0x0606: case 0x0606:
strHoliday = "全国爱眼日"; strHoliday = "全国爱眼日";
break; break;
case 0x0701: case 0x0701:
strHoliday = "建党节"; strHoliday = "建党节";
break; break;
case 0x0707: case 0x0707:
strHoliday = "抗战纪念日"; strHoliday = "抗战纪念日";
break; break;
case 0x0801: case 0x0801:
strHoliday = "建军节"; strHoliday = "建军节";
break; break;
case 0x090A: case 0x090A:
strHoliday = "教师节"; strHoliday = "教师节";
break; break;
case 0x0910: case 0x0910:
strHoliday = "脑健康日"; strHoliday = "脑健康日";
break; break;
case 0x0914: case 0x0914:
strHoliday = "爱牙日"; strHoliday = "爱牙日";
break; break;
case 0x0A01: case 0x0A01:
strHoliday = "国庆节"; strHoliday = "国庆节";
break; break;
case 0x0A0A: case 0x0A0A:
strHoliday = "高血压日"; strHoliday = "高血压日";
break; break;
case 0x0A1C: case 0x0A1C:
strHoliday = "男性健康日"; strHoliday = "男性健康日";
break; break;
case 0x0B08: case 0x0B08:
strHoliday = "记者节"; strHoliday = "记者节";
break; break;
case 0x0B09: case 0x0B09:
strHoliday = "消防宣传日"; strHoliday = "消防宣传日";
break; break;
case 0x0C04: case 0x0C04:
strHoliday = "法制宣传日"; strHoliday = "法制宣传日";
break; break;
case 0x0C18: case 0x0C18:
strHoliday = "平安夜"; strHoliday = "平安夜";
break; break;
case 0x0C19: case 0x0C19:
strHoliday = "圣诞节"; strHoliday = "圣诞节";
break; break;
default: default:
break; break;
} }
return strHoliday; return strHoliday;
@ -466,35 +466,35 @@ QString LunarCalendarInfo::getLunarFestival(int month, int day)
QString strFestival; QString strFestival;
switch (temp) { switch (temp) {
case 0x0101: case 0x0101:
strFestival = "春节"; strFestival = "春节";
break; break;
case 0x010F: case 0x010F:
strFestival = "元宵节"; strFestival = "元宵节";
break; break;
case 0x0202: case 0x0202:
strFestival = "龙抬头"; strFestival = "龙抬头";
break; break;
case 0x0505: case 0x0505:
strFestival = "端午节"; strFestival = "端午节";
break; break;
case 0x0707: case 0x0707:
strFestival = "七夕节"; strFestival = "七夕节";
break; break;
case 0x080F: case 0x080F:
strFestival = "中秋节"; strFestival = "中秋节";
break; break;
case 0x0909: case 0x0909:
strFestival = "重阳节"; strFestival = "重阳节";
break; break;
case 0x0C08: case 0x0C08:
strFestival = "腊八节"; strFestival = "腊八节";
break; break;
case 0x0C1E: case 0x0C1E:
strFestival = "除夕"; strFestival = "除夕";
break; break;
default: default:
break; break;
} }
return strFestival; return strFestival;
@ -641,7 +641,7 @@ void LunarCalendarInfo::getLunarCalendarInfo(int year, int month, int day,
//记录大小月的天数 29或30 //记录大小月的天数 29或30
int monthCount = 0; 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; springOffset = (lunarCalendarTable.at(year - 1901) & 0x001F) - 1;
} else { } else {
springOffset = (lunarCalendarTable.at(year - 1901) & 0x001F) - 1 + 31; springOffset = (lunarCalendarTable.at(year - 1901) & 0x001F) - 1 + 31;
@ -649,7 +649,7 @@ void LunarCalendarInfo::getLunarCalendarInfo(int year, int month, int day,
//如果是不闰年且不是2月份 +1 //如果是不闰年且不是2月份 +1
newYearOffset = monthAdd.at(month - 1) + day - 1; newYearOffset = monthAdd.at(month - 1) + day - 1;
if((!(year % 4)) && (month > 2)) { if ((!(year % 4)) && (month > 2)) {
newYearOffset++; newYearOffset++;
} }
@ -665,7 +665,7 @@ void LunarCalendarInfo::getLunarCalendarInfo(int year, int month, int day,
index = 1; index = 1;
flag = 0; flag = 0;
if((lunarCalendarTable.at(year - 1901) & (0x80000 >> (index - 1))) == 0) { if ((lunarCalendarTable.at(year - 1901) & (0x80000 >> (index - 1))) == 0) {
monthCount = 29; monthCount = 29;
} else { } else {
monthCount = 30; monthCount = 30;
@ -674,7 +674,7 @@ void LunarCalendarInfo::getLunarCalendarInfo(int year, int month, int day,
while (newYearOffset >= monthCount) { while (newYearOffset >= monthCount) {
newYearOffset -= monthCount; newYearOffset -= monthCount;
index++; index++;
if (month == ((lunarCalendarTable.at(year - 1901) & 0xF00000) >> 20) ) { if (month == ((lunarCalendarTable.at(year - 1901) & 0xF00000) >> 20)) {
flag = ~flag; flag = ~flag;
if (flag == 0) { if (flag == 0) {
month++; month++;
@ -713,11 +713,11 @@ void LunarCalendarInfo::getLunarCalendarInfo(int year, int month, int day,
springOffset -= monthCount; springOffset -= monthCount;
index--; index--;
if(flag == 0) { if (flag == 0) {
month--; month--;
} }
if(month == ((lunarCalendarTable.at(year - 1901) & 0xF00000) >> 20)) { if (month == ((lunarCalendarTable.at(year - 1901) & 0xF00000) >> 20)) {
flag = ~flag; flag = ~flag;
} }

View File

@ -224,7 +224,7 @@ void LunarCalendarItem::drawLunar(QPainter *painter)
QFont font; QFont font;
font.setPixelSize(side / 5); font.setPixelSize(side / 5);
painter->setFont(font); painter->setFont(font);
QRect lunarRect(0, height / 2, width, height / 2); QRect lunarRect(0, height / 2, width, height / 2);
painter->drawText(lunarRect, Qt::AlignCenter, lunar); painter->drawText(lunarRect, Qt::AlignCenter, lunar);

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = lunarcalendarwidget TARGET = lunarcalendarwidget
TEMPLATE = app TEMPLATE = app

View File

@ -9,7 +9,7 @@ int main(int argc, char *argv[])
QApplication a(argc, argv); QApplication a(argc, argv);
a.setFont(QFont("Microsoft Yahei", 9)); 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 #if _MSC_VER
QTextCodec *codec = QTextCodec::codecForName("gbk"); QTextCodec *codec = QTextCodec::codecForName("gbk");
#else #else

View File

@ -2,10 +2,19 @@
#include "maskwidget.h" #include "maskwidget.h"
#include "qmutex.h" #include "qmutex.h"
#include "qdesktopwidget.h"
#include "qapplication.h" #include "qapplication.h"
#include "qdebug.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> MaskWidget::self; QScopedPointer<MaskWidget> MaskWidget::self;
MaskWidget *MaskWidget::Instance() MaskWidget *MaskWidget::Instance()
{ {
@ -27,7 +36,7 @@ MaskWidget::MaskWidget(QWidget *parent) : QWidget(parent)
setBgColor(QColor(0, 0, 0)); setBgColor(QColor(0, 0, 0));
//不设置主窗体则遮罩层大小为默认桌面大小 //不设置主窗体则遮罩层大小为默认桌面大小
this->setGeometry(qApp->desktop()->geometry()); this->setGeometry(deskGeometry);
this->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool); this->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
//绑定全局事件,过滤弹窗窗体进行处理 //绑定全局事件,过滤弹窗窗体进行处理

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = maskwidget TARGET = maskwidget
TEMPLATE = app TEMPLATE = app

View File

@ -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, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = miniblink TARGET = miniblink
TEMPLATE = app TEMPLATE = app

View File

@ -7,6 +7,7 @@
QT += core gui QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 5): QT += core5compat
TARGET = mouseline TARGET = mouseline
TEMPLATE = app TEMPLATE = app

Some files were not shown because too many files have changed in this diff Show More