File indexing completed on 2024-12-22 04:40:07
0001 /* 0002 SPDX-FileCopyrightText: 2007-2012 Sergio Pistone <sergio_pistone@yahoo.com.ar> 0003 SPDX-FileCopyrightText: 2013-2022 Mladen Milinkovic <max@smoothware.net> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "subtitlecolordialog.h" 0009 0010 #include <QDebug> 0011 #include <QDialogButtonBox> 0012 #include <QPushButton> 0013 0014 #include <KLocalizedString> 0015 0016 using namespace SubtitleComposer; 0017 0018 SubtitleColorDialog::SubtitleColorDialog(QWidget *parent) 0019 : QColorDialog(parent), 0020 m_defaultColorSelected(false) 0021 { 0022 QDialogButtonBox *buttons = findChild<QDialogButtonBox *>(); 0023 0024 QPushButton *defaultColor = buttons->addButton(i18n("Default Color"), QDialogButtonBox::AcceptRole); 0025 connect(defaultColor, &QAbstractButton::clicked, this, [&](){ 0026 m_defaultColorSelected = true; 0027 accept(); 0028 }); 0029 0030 setOption(DontUseNativeDialog, true); 0031 } 0032 0033 SubtitleColorDialog::SubtitleColorDialog(const QColor &initial, QWidget *parent) 0034 : SubtitleColorDialog(parent) 0035 { 0036 QSignalBlocker sb(this); 0037 setCurrentColor(initial); 0038 } 0039 0040 QColor 0041 SubtitleColorDialog::selectedColor() const 0042 { 0043 return m_defaultColorSelected ? QColor(0, 0, 0, 0) : QColorDialog::selectedColor(); 0044 } 0045 0046 QColor 0047 SubtitleColorDialog::getColor(const QColor &initial, QWidget *parent, const QString &title, ColorDialogOptions options) 0048 { 0049 SubtitleColorDialog dlg(initial, parent); 0050 if(!title.isEmpty()) 0051 dlg.setWindowTitle(title); 0052 dlg.setOptions(options | DontUseNativeDialog); 0053 return dlg.exec() == QDialog::Accepted ? dlg.selectedColor() : QColor(); 0054 } 0055