File indexing completed on 2024-12-22 04:14:46
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Emmet O 'Neill <emmetoneill.pdx@gmail.com> 0003 * SPDX-FileCopyrightText: 2018 Eoin O 'Neill <eoinoneill1991@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "timeline_insert_keyframe_dialog.h" 0009 #include "KisAnimTimelineFramesView.h" 0010 0011 #include <QLabel> 0012 #include <QGroupBox> 0013 #include <QSpinBox> 0014 #include <QRadioButton> 0015 #include <QDialogButtonBox> 0016 #include <QVBoxLayout> 0017 #include <QFormLayout> 0018 #include <klocalizedstring.h> 0019 #include <kstandardguiitem.h> 0020 0021 #include "KSharedConfig" 0022 #include "KConfigGroup" 0023 0024 0025 TimelineInsertKeyframeDialog::TimelineInsertKeyframeDialog(QWidget *parent) : 0026 QDialog(parent) 0027 { 0028 setWindowTitle(i18nc("@title:window","Insert Keyframes")); 0029 setModal(true); 0030 0031 QVBoxLayout *layout = new QVBoxLayout(this); 0032 0033 { // Count and Spacing Forms. 0034 QWidget *forms = new QWidget(this); 0035 layout->addWidget(forms); 0036 0037 frameCountSpinbox.setMinimum(1); 0038 frameCountSpinbox.setValue(1); 0039 0040 frameTimingSpinbox.setMinimum(1); 0041 frameTimingSpinbox.setValue(1); 0042 0043 QFormLayout *LO = new QFormLayout(forms); 0044 0045 LO->addRow(QString(i18nc("@label:spinbox", "Number of frames:")), &frameCountSpinbox); 0046 LO->addRow(QString(i18nc("@label:spinbox", "Frame timing:")), &frameTimingSpinbox); 0047 } 0048 { // Side Buttons. 0049 QGroupBox *sideRadioButtons = new QGroupBox(i18nc("@label:group","Side:"), this); 0050 layout->addWidget(sideRadioButtons); 0051 0052 leftBefore = new QRadioButton(i18nc("@label:radio", "Left / Before"), sideRadioButtons); 0053 rightAfter = new QRadioButton(i18nc("@label:radio", "Right / After"), sideRadioButtons); 0054 leftBefore->setChecked(true); 0055 0056 QVBoxLayout *LO = new QVBoxLayout(sideRadioButtons); 0057 0058 LO->addWidget(leftBefore); 0059 LO->addWidget(rightAfter); 0060 } 0061 { // Cancel / OK Buttons. 0062 QDialogButtonBox *buttonbox = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); 0063 layout->addWidget(buttonbox); 0064 0065 KGuiItem::assign(buttonbox->button(QDialogButtonBox::Ok), KStandardGuiItem::ok()); 0066 KGuiItem::assign(buttonbox->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel()); 0067 0068 connect(buttonbox, SIGNAL(accepted()), this, SLOT(accept())); 0069 connect(buttonbox, SIGNAL(rejected()), this, SLOT(reject())); 0070 } 0071 } 0072 0073 bool TimelineInsertKeyframeDialog::promptUserSettings(int &out_count, int &out_timing, TimelineDirection &out_direction) 0074 { 0075 KConfigGroup cfg = KSharedConfig::openConfig()->group("FrameActionsDefaultValues"); 0076 frameCountSpinbox.setValue(cfg.readEntry("defaultNumberOfFramesToAdd", 1)); 0077 frameTimingSpinbox.setValue(defaultTimingOfAddedFrames()); 0078 rightAfter->setChecked(cfg.readEntry("addNewFramesToTheRight", true)); 0079 0080 if (exec() == QDialog::Accepted) { 0081 out_count = frameCountSpinbox.value(); 0082 out_timing = frameTimingSpinbox.value(); 0083 0084 out_direction = TimelineDirection::LEFT; // Default 0085 if (rightAfter && rightAfter->isChecked()) { 0086 out_direction = TimelineDirection::RIGHT; 0087 } 0088 0089 cfg.writeEntry("defaultNumberOfFramesToAdd", out_count); 0090 setDefaultTimingOfAddedFrames(out_timing); 0091 cfg.writeEntry("addNewFramesToTheRight", rightAfter->isChecked()); 0092 0093 return true; 0094 } 0095 return false; 0096 } 0097 0098 int TimelineInsertKeyframeDialog::defaultTimingOfAddedFrames() const 0099 { 0100 KConfigGroup cfg = KSharedConfig::openConfig()->group("FrameActionsDefaultValues"); 0101 return cfg.readEntry("defaultTimingOfAddedFrames", 1); 0102 } 0103 0104 void TimelineInsertKeyframeDialog::setDefaultTimingOfAddedFrames(int value) 0105 { 0106 KConfigGroup cfg = KSharedConfig::openConfig()->group("FrameActionsDefaultValues"); 0107 cfg.writeEntry("defaultTimingOfAddedFrames", value); 0108 } 0109 0110 int TimelineInsertKeyframeDialog::defaultNumberOfHoldFramesToRemove() const 0111 { 0112 KConfigGroup cfg = KSharedConfig::openConfig()->group("FrameActionsDefaultValues"); 0113 return cfg.readEntry("defaultNumberOfHoldFramesToRemove", 1); 0114 } 0115 0116 void TimelineInsertKeyframeDialog::setDefaultNumberOfHoldFramesToRemove(int value) 0117 { 0118 KConfigGroup cfg = KSharedConfig::openConfig()->group("FrameActionsDefaultValues"); 0119 cfg.writeEntry("defaultNumberOfHoldFramesToRemove", value); 0120 }