qt/LedOK/program/eweb.cpp

146 lines
4.0 KiB
C++
Raw Normal View History

2022-08-25 18:37:24 +08:00
#include "eweb.h"
2024-05-23 17:13:51 +08:00
#include "gutil/qgui.h"
2022-08-25 18:37:24 +08:00
#include <QSpinBox>
#include <QLineEdit>
2023-05-08 09:59:15 +08:00
#include <QPainter>
2022-08-25 18:37:24 +08:00
EWeb::EWeb(EBase *multiWin) : EBase(multiWin) {
mType = EBase::Web;
}
2023-10-23 14:58:29 +08:00
EWeb::EWeb(const JObj &json, EBase *multiWin) : EBase(multiWin) {
2022-08-25 18:37:24 +08:00
mType = EBase::Web;
setBaseAttr(json);
url = json["url"].toString();
2024-05-23 17:13:51 +08:00
zoom = json["zoom"].toInt(100);
_x = json["offX"].toInt(0);
_y = json["offY"].toInt(0);
2024-06-19 18:54:32 +08:00
scaleX = json["scaleX"].toInt(100);
scaleY = json["scaleY"].toInt(100);
2022-08-25 18:37:24 +08:00
}
void EWeb::paint(QPainter *painter, const QStyleOptionGraphicsItem *a, QWidget *b) {
auto inner = innerRect();
painter->setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
double maskW = holder().width(), maskH = holder().height();
if(maskW>inner.width() || maskH>inner.height()) {
double rate = qMin(inner.width() / maskW, inner.height() / maskH);
maskW *= rate;
maskH *= rate;
}
painter->drawImage(QRectF((inner.width() - maskW)/2, (inner.height() - maskH)/2, maskW, maskH), holder());
EBase::paint(painter, a, b);
}
QWidget* EWeb::attrWgt() {
2024-05-23 17:13:51 +08:00
auto wgtAttr = new QWidget;
auto vBox = new VBox(wgtAttr);
2022-08-25 18:37:24 +08:00
vBox->setContentsMargins(6, 0, 6, 0);
2024-05-23 17:13:51 +08:00
if(mMultiWin) vBox->setSpacing(3);
2022-08-25 18:37:24 +08:00
addBaseAttrWgt(vBox);
2024-05-23 17:13:51 +08:00
auto hBox = new HBox(vBox);
hBox->addLabel(tr("Basic Properties"));
2022-08-25 18:37:24 +08:00
2024-05-23 17:13:51 +08:00
auto line = new QFrame;
2022-08-25 18:37:24 +08:00
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
hBox->addWidget(line, 1);
2024-05-23 17:13:51 +08:00
hBox = new HBox(vBox);
2022-08-25 18:37:24 +08:00
hBox->addSpacing(6);
2024-05-23 17:13:51 +08:00
hBox->addLabel("URL:");
2022-08-25 18:37:24 +08:00
auto url_fd = new QLineEdit(url);
hBox->addWidget(url_fd);
connect(url_fd, &QLineEdit::textChanged, this, [this](const QString &text) {
url = text;
});
2024-05-23 17:13:51 +08:00
hBox = new HBox(vBox);
auto lb = hBox->addLabel(tr("Zoom")+":");
lb->setMinimumWidth(70);
lb->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
auto fdZoom = new QSpinBox;
fdZoom->setRange(1, 99999);
fdZoom->setValue(zoom);
connect(fdZoom, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
zoom = value;
});
hBox->addWidget(fdZoom);
hBox->addSpacing(-3);
hBox->addLabel("%");
hBox->addStretch();
hBox = new HBox(vBox);
lb = hBox->addLabel(tr("Offset")+" X:");
lb->setMinimumWidth(70);
lb->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
auto fdX = new QSpinBox;
fdX->setRange(0, 99999);
fdX->setValue(_x);
connect(fdX, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
_x = value;
});
hBox->addWidget(fdX);
2024-06-19 18:54:32 +08:00
hBox->addSpacing(-3);
hBox->addLabel()->setMinimumWidth(30);
2024-05-23 17:13:51 +08:00
hBox->addLabel("Y:");
auto fdY = new QSpinBox;
fdY->setRange(0, 99999);
fdY->setValue(_y);
connect(fdY, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
_y = value;
});
hBox->addWidget(fdY);
hBox->addStretch();
2024-06-19 18:54:32 +08:00
hBox = new HBox(vBox);
lb = hBox->addLabel(tr("Scale")+" X:");
lb->setMinimumWidth(70);
lb->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
auto fdScaleX = new QSpinBox;
fdScaleX->setRange(-9999, 99999);
fdScaleX->setValue(scaleX);
connect(fdScaleX, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
scaleX = value;
});
hBox->addWidget(fdScaleX);
hBox->addSpacing(-3);
hBox->addLabel("%")->setMinimumWidth(30);
hBox->addLabel("Y:");
auto fdScaleY = new QSpinBox;
fdScaleY->setRange(-9999, 99999);
fdScaleY->setValue(scaleY);
connect(fdScaleY, (void(QSpinBox::*)(int))&QSpinBox::valueChanged, this, [=](int value) {
scaleY = value;
});
hBox->addWidget(fdScaleY);
hBox->addSpacing(-3);
hBox->addLabel("%");
hBox->addStretch();
2022-08-25 18:37:24 +08:00
vBox->addStretch();
return wgtAttr;
}
2023-10-23 14:58:29 +08:00
JObj EWeb::attrJson() const {
2024-05-23 17:13:51 +08:00
JObj obj;
addBaseAttr(obj);
obj["elementType"] = "Web";
obj["url"] = url;
obj["zoom"] = zoom;
obj["offX"] = _x;
obj["offY"] = _y;
2024-06-19 18:54:32 +08:00
obj["scaleX"] = scaleX;
obj["scaleY"] = scaleY;
2024-05-23 17:13:51 +08:00
return obj;
2022-08-25 18:37:24 +08:00
}