提交ledok

This commit is contained in:
gangphon 2022-08-25 18:40:38 +08:00
parent c5c6c23696
commit b41b4705e6
265 changed files with 427 additions and 93 deletions

18
LedOK/base/table.cpp Normal file
View File

@ -0,0 +1,18 @@
#include "table.h"
int Table::sizeHintForColumn(int column) const {
auto item = horizontalHeaderItem(column);
if(!item) return QTableWidget::sizeHintForColumn(column);
int width = item->data(0x99).toInt();
if(!width) return QTableWidget::sizeHintForColumn(column);
auto header = horizontalHeader();
if(header->sectionResizeMode(column)!=QHeaderView::ResizeToContents) return QTableWidget::sizeHintForColumn(column);
int colCnt = columnCount();
int remainWidth = header->width(), stretchWidth = width;
for(int cc=0; cc<colCnt; cc++) if(cc!=column && (item = horizontalHeaderItem(cc))) {
if(header->sectionResizeMode(cc)==QHeaderView::ResizeToContents) stretchWidth += item->data(0x99).toInt();
else remainWidth -= item->data(0x99).toInt();
}
if(remainWidth<=0) return QTableWidget::sizeHintForColumn(column);
return width * remainWidth / stretchWidth;
}

67
LedOK/base/table.h Normal file
View File

@ -0,0 +1,67 @@
#ifndef TABLE_H
#define TABLE_H
#include <QTableWidget>
#include <QHeaderView>
struct ColAttr {
QString field;
QString text;
int width{0};
};
class Table : public QTableWidget {
Q_OBJECT
public:
explicit Table(QWidget *parent = nullptr) : QTableWidget{parent} {}
Table(std::initializer_list<ColAttr> colAttrs, QWidget *parent = nullptr) : QTableWidget{0, (int)colAttrs.size(), parent} {
int i = 0;
for(typename std::initializer_list<ColAttr>::const_iterator it = colAttrs.begin(); it != colAttrs.end(); ++it) {
auto item = horizontalHeaderItem(i);
if(!item) {
item = new QTableWidgetItem();
item->setData(0x99, it->width);
setHorizontalHeaderItem(i, item);
}
item->setText(it->text);
if(it->width>0) horizontalHeader()->resizeSection(i, it->width);
mFieldMap.insert(it->field, i++);
}
}
Table *setDefs() {
setSelectionBehavior(QTableWidget::SelectRows);
setEditTriggers(QAbstractItemView::NoEditTriggers);
setAlternatingRowColors(true);
horizontalHeader()->setBackgroundRole(QPalette::Window);
return this;
}
auto item(int row, QString column) {
auto col = mFieldMap[column];
return QTableWidget::item(row, col);
}
void setItem(int row, QString column, QTableWidgetItem *item) {
auto col = mFieldMap[column];
QTableWidget::setItem(row, col, item);
}
void setValue(int row, QString column, const QString &text) {
auto col = mFieldMap[column];
QTableWidget::setItem(row, col, new QTableWidgetItem(text));
}
auto cellWidget(int row, QString column) {
auto col = mFieldMap[column];
return QTableWidget::cellWidget(row, col);
}
void setCellWidget(int row, QString column, QWidget *widget) {
auto col = mFieldMap[column];
QTableWidget::setCellWidget(row, col, widget);
}
QMap<QString,int> mFieldMap;
protected:
int sizeHintForColumn(int column) const override;
};
#endif // TABLE_H

55
LedOK/basedlg.cpp Normal file
View File

@ -0,0 +1,55 @@
#include "basedlg.h"
#include <QMouseEvent>
#include <QPainter>
#include <QPainterPath>
#include <QIcon>
#include <windows.h>
BaseDlg::BaseDlg(QWidget *parent) : QDialog(parent) {
setWindowFlag(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
}
void BaseDlg::paintEvent(QPaintEvent *e) {
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing);
QPainterPath path = QPainterPath();
path.addRoundedRect(0.5, 0.5, width()-1, height()-1, roundRadius, roundRadius);
painter.fillPath(path, palette().window());
painter.strokePath(path, isActive ? borderPenAct : borderPenUnact);
QString title = windowTitle();
if(! icon.isNull()) painter.drawPixmap(iconPos, icon);
if(! title.isEmpty()) {
static const QPen penTitleAct(Qt::black);
static const QPen penTitleUnact(Qt::darkGray);
painter.setPen(isActive ? penTitleAct : penTitleUnact);
painter.drawText(icon.isNull() ? iconPos.x() : iconPos.x()+icon.width()+6, iconPos.y()+12, title);
}
QDialog::paintEvent(e);
}
void BaseDlg::mousePressEvent(QMouseEvent *e) {
if(e->button() != Qt::LeftButton) return;
pressRel = pos() - e->globalPos();
}
void BaseDlg::mouseReleaseEvent(QMouseEvent *e) {
if(e->button() == Qt::LeftButton) pressRel *= 0;
}
void BaseDlg::mouseMoveEvent(QMouseEvent *e) {
if(e->buttons() & Qt::LeftButton) {
if(pressRel.isNull()) return;
if(isMaximized()) return;
move(pressRel + e->globalPos());
}
}
bool BaseDlg::nativeEvent(const QByteArray &eventType, void *message, long *){
if(eventType=="windows_generic_MSG"){
MSG *msg = (MSG*)message;
if(msg->message==WM_NCACTIVATE){
isActive = msg->wParam;
repaint();
}
}
return false;
}

26
LedOK/basedlg.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef BASEDLG_H
#define BASEDLG_H
#include <QDialog>
#include <QPen>
class BaseDlg : public QDialog {
Q_OBJECT
public:
explicit BaseDlg(QWidget *parent = nullptr);
QPen borderPenAct = QPen(Qt::gray);
QPen borderPenUnact = QPen(Qt::lightGray);
qreal roundRadius = 6.0;
QPixmap icon;
QPointF iconPos = QPointF(12, 12);
protected:
void paintEvent(QPaintEvent *) override;
void mousePressEvent(QMouseEvent *) override;
void mouseReleaseEvent(QMouseEvent *) override;
void mouseMoveEvent(QMouseEvent *) override;
bool nativeEvent(const QByteArray &, void *, long *) override;
QPoint pressRel;
bool isActive = false;
};
#endif // BASEDLG_H

129
LedOK/basewin.cpp Normal file
View File

@ -0,0 +1,129 @@
#include "basewin.h"
#include <QLayout>
#include <QMouseEvent>
#include <QPainter>
#include <QPainterPath>
#include <QIcon>
#include <windows.h>
BaseWin::BaseWin(QWidget *parent) : QWidget(parent){
setWindowFlag(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
setMouseTracking(true);
auto layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
layout->setContentsMargins(8,8,8,8);
layout->setSpacing(0);
layout->addWidget(center = new QWidget());
center->installEventFilter(this);
}
void BaseWin::paintEvent(QPaintEvent *e) {
QWidget::paintEvent(e);
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing);
if(isMaximized()) painter.fillRect(rect(), palette().window());
else {
QPainterPath path = QPainterPath();
path.addRoundedRect(0.5, 0.5, width()-1, height()-1, roundRadius, roundRadius);
painter.fillPath(path, palette().window());
painter.strokePath(path, isActive ? borderPenAct : borderPenUnact);
}
QString title = windowTitle();
if(! title.isNull()){
static const QPen penTitleAct(Qt::black);
static const QPen penTitleUnact(Qt::darkGray);
painter.setPen(isActive ? penTitleAct : penTitleUnact);
isMaximized() ? painter.drawText(titlePos.x()-8, titlePos.y()-8, title) : painter.drawText(titlePos, title);
}
if(! icon.isNull()) isMaximized() ? painter.drawPixmap(iconPos.x()-8, iconPos.y()-8, icon) : painter.drawPixmap(iconPos, icon);
}
void BaseWin::mousePressEvent(QMouseEvent *e) {
if(e->button() != Qt::LeftButton) return;
setFrmSec(e->pos());
if(mFrmSec==Qt::TitleBarArea || mFrmSec==Qt::TopSection || mFrmSec==Qt::LeftSection || mFrmSec==Qt::TopLeftSection) mPressRel = pos() - e->globalPos();
else if(mFrmSec==Qt::BottomRightSection) mPressRel = QPoint(width() - e->globalX(), height() - e->globalY());
else if(mFrmSec==Qt::RightSection ) mPressRel = QPoint(width() - e->globalX(), height() );
else if(mFrmSec==Qt::BottomSection ) mPressRel = QPoint(width() , height() - e->globalY());
else if(mFrmSec==Qt::TopRightSection ) mPressRel = geometry().topRight() - e->globalPos();
else if(mFrmSec==Qt::BottomLeftSection ) mPressRel = geometry().bottomLeft() - e->globalPos();
else if(mFrmSec==Qt::NoSection) mPressRel.setX(INT_MAX);
}
void BaseWin::mouseReleaseEvent(QMouseEvent *e) {
if(e->button() == Qt::LeftButton) mPressRel.setX(INT_MAX);
}
void BaseWin::mouseMoveEvent(QMouseEvent *e) {
if(e->buttons() & Qt::LeftButton) {
if(mFrmSec==Qt::NoSection || mPressRel.x()==INT_MAX) return;
if(isMaximized()) return;
if(mFrmSec==Qt::TitleBarArea) move(mPressRel + e->globalPos());
else if(mFrmSec==Qt::BottomRightSection) resize(mPressRel.rx() + e->globalX(), mPressRel.ry() + e->globalY());
else if(mFrmSec==Qt::RightSection ) resize(mPressRel.rx() + e->globalX(), mPressRel.ry() );
else if(mFrmSec==Qt::BottomSection ) resize(mPressRel.rx() , mPressRel.ry() + e->globalY());
else {
auto geo = geometry();
if(mFrmSec==Qt::LeftSection) geo.setLeft(mPressRel.rx() + e->globalX());
else if(mFrmSec==Qt::TopSection) geo.setTop(mPressRel.ry() + e->globalY());
else if(mFrmSec==Qt::TopLeftSection) geo.setTopLeft(mPressRel + e->globalPos());
else if(mFrmSec==Qt::TopRightSection) geo.setTopRight(mPressRel + e->globalPos());
else if(mFrmSec==Qt::BottomLeftSection) geo.setBottomLeft(mPressRel + e->globalPos());
setGeometry(geo);
}
} else setFrmSec(e->pos());
}
void BaseWin::setFrmSec(const QPoint &pos) {
if(isMaximized()) return;
if(pos.y()<8) {
if(pos.x()<16) setFrmSecIfNeed(Qt::TopLeftSection, Qt::SizeFDiagCursor);
else if(pos.x()<width()-16) setFrmSecIfNeed(Qt::TopSection, Qt::SizeVerCursor);
else setFrmSecIfNeed(Qt::TopRightSection, Qt::SizeBDiagCursor);
} else if(pos.y()>=height()-8) {
if(pos.x()<16) setFrmSecIfNeed(Qt::BottomLeftSection, Qt::SizeBDiagCursor);
else if(pos.x()<width()-16) setFrmSecIfNeed(Qt::BottomSection, Qt::SizeVerCursor);
else setFrmSecIfNeed(Qt::BottomRightSection, Qt::SizeFDiagCursor);
} else if(pos.x()<8) {
if(pos.y()<16) setFrmSecIfNeed(Qt::TopLeftSection, Qt::SizeFDiagCursor);
else if(pos.y()<height()-16) setFrmSecIfNeed(Qt::LeftSection, Qt::SizeHorCursor);
else setFrmSecIfNeed(Qt::BottomLeftSection, Qt::SizeBDiagCursor);
} else if(pos.x()>=width()-8) {
if(pos.y()<16) setFrmSecIfNeed(Qt::TopRightSection, Qt::SizeBDiagCursor);
else if(pos.y()<height()-16) setFrmSecIfNeed(Qt::RightSection, Qt::SizeHorCursor);
else setFrmSecIfNeed(Qt::BottomRightSection, Qt::SizeFDiagCursor);
} else setFrmSecIfNeed(Qt::TitleBarArea, Qt::ArrowCursor);
}
void BaseWin::setFrmSecIfNeed(Qt::WindowFrameSection frmSec, Qt::CursorShape cursor) {
if(mFrmSec==frmSec) return;
mFrmSec = frmSec;
if(cursor==Qt::ArrowCursor) unsetCursor();
else setCursor(cursor);
}
void BaseWin::leaveEvent(QEvent *) {
setFrmSecIfNeed(Qt::NoSection, Qt::ArrowCursor);
mPressRel.setX(INT_MAX);
}
bool BaseWin::eventFilter(QObject *watched, QEvent *e) {
if(e->type()==QEvent::Enter && watched==center) {
setFrmSecIfNeed(Qt::NoSection, Qt::ArrowCursor);
mPressRel.setX(INT_MAX);
}
return false;
}
void BaseWin::changeEvent(QEvent *e) {
if(e->type()==QEvent::WindowStateChange) isMaximized() ? layout()->setContentsMargins(0,0,0,0) : layout()->setContentsMargins(8,8,8,8);
}
void BaseWin::mouseDoubleClickEvent(QMouseEvent *e) {
if(e->y()>32) return;
if(isMaximized()) setWindowState(windowState() & ~(Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen));
else setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowFullScreen)) | Qt::WindowMaximized);
}
bool BaseWin::nativeEvent(const QByteArray &eventType, void *message, long *){
if(eventType=="windows_generic_MSG"){
MSG *msg = (MSG*)message;
if(msg->message==WM_NCACTIVATE){
isActive = msg->wParam;
repaint();
}
}
return false;
}

37
LedOK/basewin.h Normal file
View File

@ -0,0 +1,37 @@
#ifndef BASEWIN_H
#define BASEWIN_H
#include <QWidget>
#include <QPen>
class BaseWin : public QWidget {
Q_OBJECT
public:
explicit BaseWin(QWidget *parent = nullptr);
QWidget *center{nullptr};
QPen borderPenAct{Qt::gray};
QPen borderPenUnact{Qt::lightGray};
qreal roundRadius{6.0};
QPointF titlePos{36, 26};
QPixmap icon;
QPointF iconPos{13, 13};
protected:
void paintEvent(QPaintEvent *) override;
void mousePressEvent(QMouseEvent *) override;
void mouseReleaseEvent(QMouseEvent *) override;
void mouseMoveEvent(QMouseEvent *) override;
void leaveEvent(QEvent *) override;
bool eventFilter(QObject *, QEvent *) override;
void changeEvent(QEvent *) override;
void mouseDoubleClickEvent(QMouseEvent *) override;
bool nativeEvent(const QByteArray &, void *, long *) override;
void setFrmSec(const QPoint &pos);
void setFrmSecIfNeed(Qt::WindowFrameSection frmSec, Qt::CursorShape cursor);
QPoint mPressRel{INT_MAX, INT_MAX};
Qt::WindowFrameSection mFrmSec{Qt::NoSection};
bool isActive{false};
};
#endif // BASEWIN_H

View File

@ -0,0 +1,76 @@
#include "eleborder.h"
#include <QJsonObject>
#include <QPainter>
#include <QPainterPath>
#include <QTimerEvent>
EleBorder::EleBorder(QString path, QString eff, int speed, QWidget *parent) : QWidget{parent}, speed(speed) {
img.load(path);
if(eff.startsWith("ro")) this->eff = 'r';
else if(eff.startsWith("bl")) this->eff = 'b';
}
void EleBorder::paintEvent(QPaintEvent *) {
if(eff=='b' && off > 0) return;
if(timerId==0) {
if(eff=='r') timerId = startTimer(speed==1 ? 66 : (speed==2 ? 33 : 16), Qt::PreciseTimer);
else if(eff=='b') timerId = startTimer(speed==1 ? 500 : (speed==2 ? 250 : 66));
}
int bdWidth = img.height();
int halfBdWidth = (bdWidth+1)/2;
QBrush brush(img);
QTransform transTop = QTransform::fromTranslate(halfBdWidth+off, 0);
QTransform transRight = QTransform::fromTranslate(width() - bdWidth, halfBdWidth*3-width()+off);
transRight.rotate(90);
QTransform transBottom = QTransform::fromTranslate(halfBdWidth*3-height()-off, height() - bdWidth);
transBottom.rotate(180);
QTransform transLeft = QTransform::fromTranslate(0, halfBdWidth-off);
transLeft.rotate(270);
QPainter painter(this);
brush.setTransform(transTop);
QPainterPath path(QPointF(0, 0));
path.lineTo(width(), 0);
path.lineTo(width() - bdWidth, bdWidth);
path.lineTo(bdWidth, bdWidth);
path.closeSubpath();
painter.fillPath(path, brush);
brush.setTransform(transRight);
path = QPainterPath(QPointF(width(), 0));
path.lineTo(width(), height());
path.lineTo(width() - bdWidth, height() - bdWidth);
path.lineTo(width() - bdWidth, bdWidth);
path.closeSubpath();
painter.fillPath(path, brush);
brush.setTransform(transBottom);
path = QPainterPath(QPointF(width(), height()));
path.lineTo(0, height());
path.lineTo(bdWidth, height() - bdWidth);
path.lineTo(width() - bdWidth, height() - bdWidth);
path.closeSubpath();
painter.fillPath(path, brush);
brush.setTransform(transLeft);
path = QPainterPath(QPointF(0, height()));
path.lineTo(0, 0);
path.lineTo(bdWidth, bdWidth);
path.lineTo(bdWidth, height() - bdWidth);
path.closeSubpath();
painter.fillPath(path, brush);
}
void EleBorder::timerEvent(QTimerEvent *) {
if(isVisible()) {
if(eff=='r') {
if(off >= img.width() - 1) off = 0;
else off++;
} else off = off==0 ? 1 : 0;
update();
} else if(timerId!=0) {
killTimer(timerId);
timerId = 0;
}
}

19
LedOK/player/eleborder.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef ELEBORDER_H
#define ELEBORDER_H
#include <QWidget>
class EleBorder : public QWidget {
Q_OBJECT
public:
explicit EleBorder(QString, QString, int, QWidget *parent = nullptr);
QPixmap img;
char eff = 0;
int speed = 2, off = 0;
int timerId = 0;
protected:
void paintEvent(QPaintEvent *) override;
void timerEvent(QTimerEvent *) override;
};
#endif

View File

@ -1,22 +0,0 @@
QMAKE_CXX.QT_COMPILER_STDCXX = 199711L
QMAKE_CXX.QMAKE_MSC_VER = 1929
QMAKE_CXX.QMAKE_MSC_FULL_VER = 192930133
QMAKE_CXX.COMPILER_MACROS = \
QT_COMPILER_STDCXX \
QMAKE_MSC_VER \
QMAKE_MSC_FULL_VER
QMAKE_CXX.INCDIRS = \
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\ATLMFC\\include" \
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\include" \
"C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.6.1\\include\\um" \
"C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\ucrt" \
"C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\shared" \
"C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\um" \
"C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\winrt" \
"C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\cppwinrt"
QMAKE_CXX.LIBDIRS = \
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\ATLMFC\\lib\\x86" \
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\lib\\x86" \
"C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.6.1\\lib\\um\\x86" \
"C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.19041.0\\ucrt\\x86" \
"C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.19041.0\\um\\x86"

View File

@ -1,37 +0,0 @@
#include <windows.h>
IDI_ICON1 ICON DISCARDABLE "D:\\_workspace\\comp\\qt\\LedOK\\res\\Logo.ico"
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,2,8,0
PRODUCTVERSION 1,2,8,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "\0"
VALUE "FileDescription", "\0"
VALUE "FileVersion", "1.2.8.0\0"
VALUE "LegalCopyright", "\0"
VALUE "OriginalFilename", "LedOK Express.exe\0"
VALUE "ProductName", "LedOK Express\0"
VALUE "ProductVersion", "1.2.8.0\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 1200
END
END
/* End of Version info */

View File

@ -1,12 +0,0 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="i18n">
<file alias="app_zh_CN.qm">D:/_workspace/comp/qt/build-LedOK-Desktop_Qt_5_15_2_MSVC2019_32bit-Release/debug/app_zh_CN.qm</file>
<file alias="app_zh_TW.qm">D:/_workspace/comp/qt/build-LedOK-Desktop_Qt_5_15_2_MSVC2019_32bit-Release/debug/app_zh_TW.qm</file>
<file alias="app_ja.qm">D:/_workspace/comp/qt/build-LedOK-Desktop_Qt_5_15_2_MSVC2019_32bit-Release/debug/app_ja.qm</file>
<file alias="app_en.qm">D:/_workspace/comp/qt/build-LedOK-Desktop_Qt_5_15_2_MSVC2019_32bit-Release/debug/app_en.qm</file>
<file alias="qt_zh_CN.qm">D:/_workspace/comp/qt/build-LedOK-Desktop_Qt_5_15_2_MSVC2019_32bit-Release/debug/qt_zh_CN.qm</file>
<file alias="qt_zh_TW.qm">D:/_workspace/comp/qt/build-LedOK-Desktop_Qt_5_15_2_MSVC2019_32bit-Release/debug/qt_zh_TW.qm</file>
<file alias="qt_ja.qm">D:/_workspace/comp/qt/build-LedOK-Desktop_Qt_5_15_2_MSVC2019_32bit-Release/debug/qt_ja.qm</file>
<file alias="qt_en.qm">D:/_workspace/comp/qt/build-LedOK-Desktop_Qt_5_15_2_MSVC2019_32bit-Release/debug/qt_en.qm</file>
</qresource>
</RCC>

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