File indexing completed on 2023-11-26 04:48:46
0001 /* 0002 SPDX-FileCopyrightText: 2016 Jean-Baptiste Mardelle <jb@kdenlive.org> 0003 This file is part of Kdenlive. See www.kdenlive.org. 0004 0005 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #include "effectsettings.h" 0009 #include "kdenlivesettings.h" 0010 0011 #include "klocalizedstring.h" 0012 #include <QApplication> 0013 #include <QResizeEvent> 0014 #include <QScrollArea> 0015 #include <QToolButton> 0016 #include <QVBoxLayout> 0017 0018 ElidedCheckBox::ElidedCheckBox(QWidget *parent) 0019 : QCheckBox(parent) 0020 { 0021 } 0022 0023 void ElidedCheckBox::setBoxText(const QString &text) 0024 { 0025 m_text = text; 0026 int width = currentWidth(); 0027 updateText(width); 0028 } 0029 0030 void ElidedCheckBox::updateText(int width) 0031 { 0032 setText(fontMetrics().elidedText(m_text, Qt::ElideRight, width)); 0033 } 0034 0035 int ElidedCheckBox::currentWidth() const 0036 { 0037 int width = 0; 0038 if (isVisible()) { 0039 width = contentsRect().width() - (2 * iconSize().width()); 0040 } else { 0041 QMargins mrg = contentsMargins(); 0042 width = sizeHint().width() - mrg.left() - mrg.right() - (2 * iconSize().width()); 0043 } 0044 return width; 0045 } 0046 0047 void ElidedCheckBox::resizeEvent(QResizeEvent *event) 0048 { 0049 int diff = event->size().width() - event->oldSize().width(); 0050 updateText(currentWidth() + diff); 0051 QCheckBox::resizeEvent(event); 0052 } 0053 0054 EffectSettings::EffectSettings(QWidget *parent) 0055 : QWidget(parent) 0056 { 0057 auto *vbox1 = new QVBoxLayout(this); 0058 vbox1->setContentsMargins(0, 0, 0, 0); 0059 vbox1->setSpacing(0); 0060 checkAll = new ElidedCheckBox(this); 0061 checkAll->setToolTip(i18n("Enable/Disable all effects")); 0062 auto *hbox = new QHBoxLayout; 0063 hbox->addWidget(checkAll); 0064 effectCompare = new QToolButton(this); 0065 effectCompare->setIcon(QIcon::fromTheme(QStringLiteral("view-split-effect"))); 0066 effectCompare->setToolTip(i18n("Split compare")); 0067 effectCompare->setCheckable(true); 0068 effectCompare->setChecked(false); 0069 hbox->addWidget(effectCompare); 0070 vbox1->addLayout(hbox); 0071 container = new QScrollArea; 0072 container->setFrameShape(QFrame::NoFrame); 0073 container->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred)); 0074 container->setWidgetResizable(true); 0075 QPalette p = qApp->palette(); 0076 p.setBrush(QPalette::Window, QBrush(Qt::transparent)); 0077 container->setPalette(p); 0078 container->setAlignment(Qt::AlignLeft | Qt::AlignTop); 0079 vbox1->addWidget(container); 0080 setLayout(vbox1); 0081 0082 // m_ui.buttonShowComments->setIcon(QIcon::fromTheme(QStringLiteral("help-about"))); 0083 // m_ui.buttonShowComments->setToolTip(i18n("Show additional information for the parameters")); 0084 // connect(m_ui.buttonShowComments, SIGNAL(clicked()), this, SLOT(slotShowComments())); 0085 // m_ui.labelComment->setHidden(true); 0086 setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum)); 0087 } 0088 0089 void EffectSettings::setLabel(const QString &label, const QString &tooltip) 0090 { 0091 checkAll->setBoxText(label); 0092 checkAll->setToolTip(tooltip); 0093 checkAll->setEnabled(!label.isEmpty()); 0094 } 0095 0096 void EffectSettings::updateCheckState(int state) 0097 { 0098 checkAll->blockSignals(true); 0099 checkAll->setCheckState(Qt::CheckState(state)); 0100 checkAll->blockSignals(false); 0101 } 0102 0103 void EffectSettings::updatePalette() 0104 { 0105 // We need to reset current stylesheet if we want to change the palette! 0106 // m_effectEdit->updatePalette(); 0107 } 0108 0109 void EffectSettings::resizeEvent(QResizeEvent *event) 0110 { 0111 int diff = event->size().width() - event->oldSize().width(); 0112 checkAll->updateText(checkAll->currentWidth() + diff); 0113 QWidget::resizeEvent(event); 0114 }