File indexing completed on 2024-12-22 04:40:10
0001 /* 0002 SPDX-FileCopyrightText: 2022 Mladen Milinkovic <max@smoothware.net> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "subtitlepositionwidget.h" 0007 #include "ui_subtitlepositionwidget.h" 0008 0009 #include "application.h" 0010 #include "core/subtitleline.h" 0011 #include "gui/playerwidget.h" 0012 #include "videoplayer/videoplayer.h" 0013 0014 0015 using namespace SubtitleComposer; 0016 0017 SubtitlePositionWidget::SubtitlePositionWidget(QWidget *parent) 0018 : QWidget(parent), 0019 ui(new Ui::SubtitlePositionWidget), 0020 m_currentLine(nullptr) 0021 { 0022 ui->setupUi(this); 0023 setEnabled(false); 0024 0025 connect(ui->posTop, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &SubtitlePositionWidget::onPosTop); 0026 connect(ui->posRight, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &SubtitlePositionWidget::onPosRight); 0027 connect(ui->posBottom, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &SubtitlePositionWidget::onPosBottom); 0028 connect(ui->posLeft, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &SubtitlePositionWidget::onPosLeft); 0029 0030 connect(ui->haLeft, &QPushButton::toggled, this, &SubtitlePositionWidget::onHAlignLeft); 0031 connect(ui->haCenter, &QPushButton::toggled, this, &SubtitlePositionWidget::onHAlignCenter); 0032 connect(ui->haRight, &QPushButton::toggled, this, &SubtitlePositionWidget::onHAlignRight); 0033 connect(ui->vaTop, &QPushButton::toggled, this, &SubtitlePositionWidget::onVAlignTop); 0034 connect(ui->vaBottom, &QPushButton::toggled, this, &SubtitlePositionWidget::onVAlignBottom); 0035 } 0036 0037 SubtitlePositionWidget::~SubtitlePositionWidget() 0038 { 0039 delete ui; 0040 } 0041 0042 0043 void 0044 SubtitlePositionWidget::setCurrentLine(SubtitleLine *line) 0045 { 0046 if(m_currentLine == line) 0047 return; 0048 m_currentLine = line; 0049 0050 if(line) { 0051 setEnabled(true); 0052 updatePosition(line->pos()); 0053 } else { 0054 setEnabled(false); 0055 updatePosition(SubtitleRect()); 0056 } 0057 } 0058 0059 void 0060 SubtitlePositionWidget::updatePosition(const SubtitleRect &pos) 0061 { 0062 ui->haLeft->setChecked(pos.hAlign == SubtitleRect::START); 0063 ui->haCenter->setChecked(pos.hAlign == SubtitleRect::CENTER); 0064 ui->haRight->setChecked(pos.hAlign == SubtitleRect::END); 0065 ui->vaTop->setChecked(pos.vAlign == SubtitleRect::TOP); 0066 ui->vaBottom->setChecked(pos.vAlign == SubtitleRect::BOTTOM); 0067 ui->posTop->setValue(pos.top); 0068 ui->posLeft->setValue(pos.left); 0069 ui->posBottom->setValue(100. - pos.bottom); 0070 ui->posRight->setValue(100. - pos.right); 0071 } 0072 0073 void 0074 SubtitlePositionWidget::onPosTop(double value) 0075 { 0076 if(!m_currentLine || m_currentLine->pos().top == value) 0077 return; 0078 auto p = m_currentLine->pos(); 0079 p.top = value; 0080 m_currentLine->setPosition(p); 0081 } 0082 0083 void 0084 SubtitlePositionWidget::onPosBottom(double value) 0085 { 0086 if(!m_currentLine || m_currentLine->pos().bottom == 100. - value) 0087 return; 0088 auto p = m_currentLine->pos(); 0089 p.bottom = 100. - value; 0090 m_currentLine->setPosition(p); 0091 } 0092 0093 void 0094 SubtitlePositionWidget::onPosLeft(double value) 0095 { 0096 if(!m_currentLine || m_currentLine->pos().left == value) 0097 return; 0098 auto p = m_currentLine->pos(); 0099 p.left = value; 0100 m_currentLine->setPosition(p); 0101 } 0102 0103 void 0104 SubtitlePositionWidget::onPosRight(double value) 0105 { 0106 if(!m_currentLine || m_currentLine->pos().right == 100. - value) 0107 return; 0108 auto p = m_currentLine->pos(); 0109 p.right = 100. - value; 0110 m_currentLine->setPosition(p); 0111 } 0112 0113 void 0114 SubtitlePositionWidget::onHAlignLeft(bool checked) 0115 { 0116 if(!checked || !m_currentLine || m_currentLine->pos().hAlign == SubtitleRect::START) 0117 return; 0118 auto p = m_currentLine->pos(); 0119 p.hAlign = SubtitleRect::START; 0120 m_currentLine->setPosition(p); 0121 } 0122 0123 void 0124 SubtitlePositionWidget::onHAlignCenter(bool checked) 0125 { 0126 if(!checked || !m_currentLine || m_currentLine->pos().hAlign == SubtitleRect::CENTER) 0127 return; 0128 auto p = m_currentLine->pos(); 0129 p.hAlign = SubtitleRect::CENTER; 0130 m_currentLine->setPosition(p); 0131 } 0132 0133 void 0134 SubtitlePositionWidget::onHAlignRight(bool checked) 0135 { 0136 if(!checked || !m_currentLine || m_currentLine->pos().hAlign == SubtitleRect::END) 0137 return; 0138 auto p = m_currentLine->pos(); 0139 p.hAlign = SubtitleRect::END; 0140 m_currentLine->setPosition(p); 0141 } 0142 0143 void 0144 SubtitlePositionWidget::onVAlignTop(bool checked) 0145 { 0146 if(!checked || !m_currentLine || m_currentLine->pos().vAlign == SubtitleRect::TOP) 0147 return; 0148 auto p = m_currentLine->pos(); 0149 p.vAlign = SubtitleRect::TOP; 0150 m_currentLine->setPosition(p); 0151 } 0152 0153 void 0154 SubtitlePositionWidget::onVAlignBottom(bool checked) 0155 { 0156 if(!checked || !m_currentLine || m_currentLine->pos().vAlign == SubtitleRect::BOTTOM) 0157 return; 0158 auto p = m_currentLine->pos(); 0159 p.vAlign = SubtitleRect::BOTTOM; 0160 m_currentLine->setPosition(p); 0161 }