2022-08-25 18:37:24 +08:00
|
|
|
|
#include "pageeditor.h"
|
|
|
|
|
#include "cfg.h"
|
|
|
|
|
#include "globaldefine.h"
|
|
|
|
|
#include "tools.h"
|
|
|
|
|
#include "wProgramManager/eaclock.h"
|
|
|
|
|
#include "wProgramManager/eaudio.h"
|
|
|
|
|
#include "wProgramManager/ebase.h"
|
|
|
|
|
#include "wProgramManager/edclock.h"
|
|
|
|
|
#include "wProgramManager/eenviron.h"
|
|
|
|
|
#include "wProgramManager/egif.h"
|
|
|
|
|
#include "wProgramManager/emultiwin.h"
|
|
|
|
|
#include "wProgramManager/ephoto.h"
|
|
|
|
|
#include "wProgramManager/etext.h"
|
|
|
|
|
#include "wProgramManager/etimer.h"
|
|
|
|
|
#include "wProgramManager/evideo.h"
|
|
|
|
|
#include "wProgramManager/eweb.h"
|
|
|
|
|
#include "wProgramManager/pagelistitem.h"
|
|
|
|
|
#include <QKeyEvent>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QToolBar>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
PageEditor::PageEditor(QWidget *parent) : QWidget(parent) {
|
|
|
|
|
auto vBox = new QVBoxLayout(this);
|
|
|
|
|
vBox->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
vBox->setSpacing(0);
|
|
|
|
|
|
|
|
|
|
//主区域编辑工具栏
|
|
|
|
|
auto toolBar = new QToolBar();
|
|
|
|
|
toolBar->setStyleSheet("QToolBar{spacing: 2px;}");
|
|
|
|
|
toolBar->setIconSize(QSize(18, 18));
|
|
|
|
|
toolBar->addSeparator();
|
|
|
|
|
auto actScaleUp = new QAction(QIcon(":/res/ProgramManager/EditProgram/ScaleUp.png"), tr("Zoom In"));
|
|
|
|
|
toolBar->addAction(actScaleUp); //放大
|
|
|
|
|
connect(actScaleUp, &QAction::triggered, this, &PageEditor::onScaleUp);
|
|
|
|
|
|
|
|
|
|
fdScale = new QLabel("100");
|
|
|
|
|
QPalette pal;
|
|
|
|
|
pal.setBrush(QPalette::Window, Qt::white);
|
|
|
|
|
fdScale->setPalette(pal);
|
|
|
|
|
fdScale->setAutoFillBackground(true);
|
|
|
|
|
fdScale->setFixedWidth(32);
|
|
|
|
|
fdScale->setAlignment(Qt::AlignCenter);
|
|
|
|
|
toolBar->addWidget(fdScale);//当前视图比例
|
|
|
|
|
|
|
|
|
|
auto actScaleDown = new QAction(QIcon(":/res/ProgramManager/EditProgram/ScaleDown.png"), tr("Zoom Out"));
|
|
|
|
|
toolBar->addAction(actScaleDown);//缩小
|
|
|
|
|
connect(actScaleDown, &QAction::triggered, this, &PageEditor::onScaleDown);
|
|
|
|
|
|
|
|
|
|
QAction *actScaleOrg = new QAction(QIcon(":/res/ProgramManager/EditProgram/ScaleOrg.png"), tr("Original size"));
|
|
|
|
|
connect(actScaleOrg, &QAction::triggered, this, [this] {
|
|
|
|
|
curScale = 100;
|
|
|
|
|
fdScale->setText("100");
|
|
|
|
|
graphicsView->resetTransform();
|
|
|
|
|
});
|
|
|
|
|
toolBar->addAction(actScaleOrg);//1:1恢复视图
|
|
|
|
|
toolBar->addSeparator();
|
|
|
|
|
|
|
|
|
|
QAction *actDelete = new QAction(QIcon(":/res/ProgramManager/EditProgram/Delete.png"), tr("Delete the secect media"));
|
|
|
|
|
QAction *actClean = new QAction(QIcon(":/res/ProgramManager/EditProgram/Clean.png"), tr("Clear all media"));
|
|
|
|
|
//QAction *actCut = new QAction(QIcon(":/res/ProgramManager/EditProgram/Cut.png"), tr("Cut media"));
|
|
|
|
|
QAction *actLayerUp = new QAction(QIcon(":/res/ProgramManager/EditProgram/LayerUp.png"), tr("Move layer up"));
|
|
|
|
|
QAction *actLayerDown = new QAction(QIcon(":/res/ProgramManager/EditProgram/LayerDown.png"), tr("Send backward"));
|
|
|
|
|
QAction *actLayerTop = new QAction(QIcon(":/res/ProgramManager/EditProgram/LayerTop.png"), tr("Bring to front"));
|
|
|
|
|
QAction *actLayerBottom = new QAction(QIcon(":/res/ProgramManager/EditProgram/LayerBottom.png"), tr("Move to the bottom layer"));
|
|
|
|
|
QAction *actTileFull = new QAction(QIcon(":/res/ProgramManager/EditProgram/TileFull.png"), tr("Fill the entire screen"));
|
|
|
|
|
QAction *actTileH = new QAction(QIcon(":/res/ProgramManager/EditProgram/TileH.png"), tr("Fill the screen horizontally"));
|
|
|
|
|
QAction *actTileV = new QAction(QIcon(":/res/ProgramManager/EditProgram/TileV.png"), tr("Fill the screen vertically"));
|
|
|
|
|
QAction *actArrayTop = new QAction(QIcon(":/res/ProgramManager/EditProgram/ArrayTop.png"), tr("Align top"));
|
|
|
|
|
QAction *actArrayHCenter = new QAction(QIcon(":/res/ProgramManager/EditProgram/ArrayHCenter.png"), tr("Center vertically"));
|
|
|
|
|
QAction *actArrayBottom = new QAction(QIcon(":/res/ProgramManager/EditProgram/ArrayBottom.png"), tr("Bottom align"));
|
|
|
|
|
QAction *actArrayLeft = new QAction(QIcon(":/res/ProgramManager/EditProgram/ArrayLeft.png"), tr("Align left"));
|
|
|
|
|
QAction *actArrayVCenter = new QAction(QIcon(":/res/ProgramManager/EditProgram/ArrayVCenter.png"), tr("Center horizontally"));
|
|
|
|
|
QAction *actArrayRight = new QAction(QIcon(":/res/ProgramManager/EditProgram/ArrayRight.png"), tr("Align right"));
|
|
|
|
|
toolBar->addAction(actDelete);
|
|
|
|
|
toolBar->addAction(actClean);
|
|
|
|
|
toolBar->addSeparator();
|
|
|
|
|
toolBar->addAction(actLayerUp);
|
|
|
|
|
toolBar->addAction(actLayerDown);
|
|
|
|
|
toolBar->addAction(actLayerTop);
|
|
|
|
|
toolBar->addAction(actLayerBottom);
|
|
|
|
|
toolBar->addSeparator();
|
|
|
|
|
toolBar->addAction(actTileFull);
|
|
|
|
|
toolBar->addAction(actTileH);
|
|
|
|
|
toolBar->addAction(actTileV);
|
|
|
|
|
toolBar->addSeparator();
|
|
|
|
|
toolBar->addAction(actArrayTop);
|
|
|
|
|
toolBar->addAction(actArrayHCenter);
|
|
|
|
|
toolBar->addAction(actArrayBottom);
|
|
|
|
|
toolBar->addAction(actArrayLeft);
|
|
|
|
|
toolBar->addAction(actArrayVCenter);
|
|
|
|
|
toolBar->addAction(actArrayRight);
|
|
|
|
|
connect(actDelete, SIGNAL(triggered(bool)), this, SLOT(onDelete()));
|
|
|
|
|
connect(actClean, SIGNAL(triggered(bool)), this, SLOT(onClean()));
|
|
|
|
|
connect(actLayerUp, SIGNAL(triggered(bool)), this, SLOT(onLayerUp()));
|
|
|
|
|
connect(actLayerDown, SIGNAL(triggered(bool)), this, SLOT(onLayerDown()));
|
|
|
|
|
connect(actLayerTop, SIGNAL(triggered(bool)), this, SLOT(onLayerTop()));
|
|
|
|
|
connect(actLayerBottom, SIGNAL(triggered(bool)), this, SLOT(onLayerBottom()));
|
|
|
|
|
connect(actTileFull, SIGNAL(triggered(bool)), this, SLOT(onTileFull()));
|
|
|
|
|
connect(actTileH, SIGNAL(triggered(bool)), this, SLOT(onTileH()));
|
|
|
|
|
connect(actTileV, SIGNAL(triggered(bool)), this, SLOT(onTileV()));
|
|
|
|
|
connect(actArrayTop, SIGNAL(triggered(bool)), this, SLOT(onArrayTop()));
|
|
|
|
|
connect(actArrayHCenter, SIGNAL(triggered(bool)), this, SLOT(onArrayHCenter()));
|
|
|
|
|
connect(actArrayBottom, SIGNAL(triggered(bool)), this, SLOT(onArrayBottom()));
|
|
|
|
|
connect(actArrayLeft, SIGNAL(triggered(bool)), this, SLOT(onArrayLeft()));
|
|
|
|
|
connect(actArrayVCenter, SIGNAL(triggered(bool)), this, SLOT(onArrayVCenter()));
|
|
|
|
|
connect(actArrayRight, SIGNAL(triggered(bool)), this, SLOT(onArrayRight()));
|
|
|
|
|
vBox->addWidget(toolBar);
|
|
|
|
|
|
|
|
|
|
graphicsView = new QGraphicsView(this);
|
|
|
|
|
graphicsView->setStyleSheet("QGraphicsView{background-color:transparent;}");
|
|
|
|
|
vBox->addWidget(graphicsView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageEditor::keyReleaseEvent(QKeyEvent *event) {
|
|
|
|
|
switch (event->key()) {
|
|
|
|
|
case Qt::Key_Delete: onDelete(); break;
|
|
|
|
|
case Qt::Key_Home: onLayerTop(); break;
|
|
|
|
|
case Qt::Key_End: onLayerBottom(); break;
|
|
|
|
|
case Qt::Key_PageUp: onLayerUp(); break;
|
|
|
|
|
case Qt::Key_PageDown: onLayerDown(); break;
|
|
|
|
|
case Qt::Key_Left: onSelectionLeft(); break;
|
|
|
|
|
case Qt::Key_Right: onSelectionRight(); break;
|
|
|
|
|
case Qt::Key_Up: onSelectionTop(); break;
|
|
|
|
|
case Qt::Key_Down: onSelectionBottom(); break;
|
|
|
|
|
default:break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void PageEditor::wheelEvent(QWheelEvent *e) {
|
|
|
|
|
if(e->angleDelta().y()>0) onScaleUp();
|
|
|
|
|
else onScaleDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<EBase*> PageEditor::sortedEles() {
|
|
|
|
|
QList<EBase*> eles;
|
|
|
|
|
auto scene = graphicsView->scene();
|
|
|
|
|
if(nullptr == scene) return eles;
|
|
|
|
|
auto items = scene->items(Qt::AscendingOrder);
|
|
|
|
|
foreach(auto item, items) {
|
|
|
|
|
auto ele = static_cast<EBase*>(item);
|
|
|
|
|
if(ele->mMultiWin == nullptr) eles.append(ele);
|
|
|
|
|
}
|
|
|
|
|
return eles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EBase* PageEditor::getElementSelected(){
|
|
|
|
|
auto scene = graphicsView->scene();
|
|
|
|
|
if(nullptr == scene) return nullptr;
|
|
|
|
|
auto selectedItems = scene->selectedItems();
|
|
|
|
|
if(selectedItems.count() != 1) return nullptr;
|
|
|
|
|
return static_cast<EBase*>(selectedItems.at(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageEditor::onScaleUp() {
|
|
|
|
|
if(curScale > 790) return;
|
|
|
|
|
curScale += 10;
|
|
|
|
|
fdScale->setText(QString::number(curScale));
|
|
|
|
|
graphicsView->resetTransform();
|
|
|
|
|
qreal scale = curScale / 100.0;
|
|
|
|
|
graphicsView->scale(scale, scale);
|
|
|
|
|
}
|
|
|
|
|
void PageEditor::onScaleDown() {
|
|
|
|
|
if(curScale < 20) return;
|
|
|
|
|
curScale -= 10;
|
|
|
|
|
fdScale->setText(QString::number(curScale));
|
|
|
|
|
graphicsView->resetTransform();
|
|
|
|
|
qreal scale = curScale / 100.0;
|
|
|
|
|
graphicsView->scale(scale, scale);
|
|
|
|
|
}
|
|
|
|
|
void PageEditor::onDelete() {
|
|
|
|
|
auto scene = graphicsView->scene();
|
|
|
|
|
if(nullptr == scene) return;
|
|
|
|
|
auto selectedItems = scene->selectedItems();
|
|
|
|
|
if(selectedItems.count() == 0) return;
|
|
|
|
|
foreach(QGraphicsItem *selectedItem, selectedItems) if(selectedItem->type() >= QGraphicsItem::UserType) {
|
|
|
|
|
scene->removeItem(selectedItem);
|
|
|
|
|
static_cast<EBase*>(selectedItem)->freeFiles();
|
|
|
|
|
delete selectedItem;
|
|
|
|
|
}
|
|
|
|
|
auto eles = sortedEles();
|
|
|
|
|
for(int i=0; i<eles.size(); i++) eles[i]->setZValue(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageEditor::onClean() {
|
|
|
|
|
auto res = QMessageBox::information(this, tr("Tip Info"),tr("Clear all medias?"), QMessageBox::Ok, QMessageBox::Cancel);
|
|
|
|
|
if(res == QMessageBox::Ok) {
|
|
|
|
|
auto eles = sortedEles();
|
|
|
|
|
foreach(auto ele, eles) {
|
|
|
|
|
graphicsView->scene()->removeItem(ele);
|
|
|
|
|
delete ele;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void PageEditor::onLayerUp(){
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
|
|
|
|
QList<EBase*> list = sortedEles();
|
|
|
|
|
int n = list.count();
|
|
|
|
|
int o = static_cast<int>(element->zValue());
|
|
|
|
|
if(o < n-1) {
|
|
|
|
|
element->setZValue(o+1);
|
|
|
|
|
list.at(o+1)->setZValue(o);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageEditor::onSelectionLeft()
|
|
|
|
|
{
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
|
|
|
|
element->setX(x()-1);
|
|
|
|
|
}
|
|
|
|
|
void PageEditor::onSelectionRight()
|
|
|
|
|
{
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
|
|
|
|
element->setX(x()+1);
|
|
|
|
|
}
|
|
|
|
|
void PageEditor::onSelectionTop()
|
|
|
|
|
{
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
|
|
|
|
element->setY(y()-1);
|
|
|
|
|
}
|
|
|
|
|
void PageEditor::onSelectionBottom()
|
|
|
|
|
{
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
|
|
|
|
element->setY(y()+1);
|
|
|
|
|
}
|
|
|
|
|
void PageEditor::onLayerDown()
|
|
|
|
|
{
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
|
|
|
|
QList<EBase*> list = sortedEles();
|
|
|
|
|
int o = static_cast<int>(element->zValue());
|
|
|
|
|
if(o > 0) {
|
|
|
|
|
element->setZValue(o-1);
|
|
|
|
|
list.at(o-1)->setZValue(o);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void PageEditor::onLayerTop()
|
|
|
|
|
{
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
|
|
|
|
QList<EBase*> list = sortedEles();
|
|
|
|
|
int n = list.count();
|
|
|
|
|
int o = static_cast<int>(element->zValue());
|
|
|
|
|
if(o < n-1) {
|
|
|
|
|
for(int i=o+1; i<n; i++)
|
|
|
|
|
list.at(i)->setZValue(i-1);
|
|
|
|
|
element->setZValue(n-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageEditor::onLayerBottom()
|
|
|
|
|
{
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
|
|
|
|
QList<EBase*> list = sortedEles();
|
|
|
|
|
int o = static_cast<int>(element->zValue());
|
|
|
|
|
if(o > 0) {
|
|
|
|
|
for(int i=0; i<o; i++)
|
|
|
|
|
list.at(i)->setZValue(i+1);
|
|
|
|
|
element->setZValue(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageEditor::onTileFull() {
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
|
|
|
|
element->setPos(0,0);
|
2022-10-27 15:07:45 +08:00
|
|
|
|
element->setSize(gProgItem->mWidth, gProgItem->mHeight);
|
2022-08-25 18:37:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageEditor::onTileH(){
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
|
|
|
|
element->setX(0);
|
2022-10-27 15:07:45 +08:00
|
|
|
|
element->setSize(gProgItem->mWidth, element->mHeight);
|
2022-08-25 18:37:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageEditor::onTileV() {
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
|
|
|
|
element->setY(0);
|
2022-10-27 15:07:45 +08:00
|
|
|
|
element->setSize(element->mWidth, gProgItem->mHeight);
|
2022-08-25 18:37:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageEditor::onArrayTop() {
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
|
|
|
|
element->setY(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageEditor::onArrayHCenter() {
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
2022-10-27 15:07:45 +08:00
|
|
|
|
element->setY(floor((gProgItem->mHeight - element->mHeight) / 2));
|
2022-08-25 18:37:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageEditor::onArrayBottom(){
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
2022-10-27 15:07:45 +08:00
|
|
|
|
element->setY(gProgItem->mHeight - element->mHeight);
|
2022-08-25 18:37:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageEditor::onArrayLeft(){
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
|
|
|
|
element->setX(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageEditor::onArrayVCenter() {
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
2022-10-27 15:07:45 +08:00
|
|
|
|
element->setX(floor((gProgItem->mWidth - element->mWidth) / 2));
|
2022-08-25 18:37:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageEditor::onArrayRight() {
|
|
|
|
|
EBase *element = getElementSelected();
|
|
|
|
|
if(nullptr == element) return;
|
2022-10-27 15:07:45 +08:00
|
|
|
|
element->setX(gProgItem->mWidth - element->mWidth);
|
2022-08-25 18:37:24 +08:00
|
|
|
|
}
|