* Fix profile editing broken

* Don't allow creating profile with non even height Fixes #30
parent e4306c23
......@@ -70,7 +70,14 @@ ProfilesDialog::ProfilesDialog(const QString &profileDescription, QWidget *paren
fillList(profileDescription);
slotUpdateDisplay();
connect(m_view.profiles_list, static_cast<void (KComboBox::*)(const QString&)>(&KComboBox::currentIndexChanged), this, &ProfilesDialog::slotUpdateDisplay);
connectDialog();
}
void ProfilesDialog::connectDialog()
{
connect(m_view.profiles_list, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged), [&]() {
slotUpdateDisplay();
});
connect(m_view.button_create, &QAbstractButton::clicked, this, &ProfilesDialog::slotCreateProfile);
connect(m_view.button_save, &QAbstractButton::clicked, this, &ProfilesDialog::slotSaveProfile);
connect(m_view.button_delete, &QAbstractButton::clicked, this, &ProfilesDialog::slotDeleteProfile);
......@@ -85,6 +92,8 @@ ProfilesDialog::ProfilesDialog(const QString &profileDescription, QWidget *paren
connect(m_view.display_den, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ProfilesDialog::slotProfileEdited);
connect(m_view.progressive, &QCheckBox::stateChanged, this, &ProfilesDialog::slotProfileEdited);
connect(m_view.size_h, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ProfilesDialog::slotProfileEdited);
connect(m_view.size_h, &QAbstractSpinBox::editingFinished, this, &ProfilesDialog::slotAdjustHeight);
m_view.size_h->setSingleStep(2);
connect(m_view.size_w, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ProfilesDialog::slotProfileEdited);
connect(m_view.size_w, &QAbstractSpinBox::editingFinished, this, &ProfilesDialog::slotAdjustWidth);
m_view.size_w->setSingleStep(8);
......@@ -124,26 +133,13 @@ ProfilesDialog::ProfilesDialog(const QString &profilePath, bool, QWidget *parent
m_view.description->setEnabled(false);
slotUpdateDisplay(profilePath);
connect(m_view.button_save, &QAbstractButton::clicked, this, &ProfilesDialog::slotSaveProfile);
connect(m_view.description, &QLineEdit::textChanged, this, &ProfilesDialog::slotProfileEdited);
connect(m_view.frame_num, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ProfilesDialog::slotProfileEdited);
connect(m_view.frame_den, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ProfilesDialog::slotProfileEdited);
connect(m_view.aspect_num, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ProfilesDialog::slotProfileEdited);
connect(m_view.aspect_den, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ProfilesDialog::slotProfileEdited);
connect(m_view.display_num, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ProfilesDialog::slotProfileEdited);
connect(m_view.display_den, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ProfilesDialog::slotProfileEdited);
connect(m_view.progressive, &QCheckBox::stateChanged, this, &ProfilesDialog::slotProfileEdited);
connect(m_view.size_h, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ProfilesDialog::slotProfileEdited);
connect(m_view.size_w, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &ProfilesDialog::slotProfileEdited);
connect(m_view.size_w, &QAbstractSpinBox::editingFinished, this, &ProfilesDialog::slotAdjustWidth);
m_view.size_w->setSingleStep(8);
connectDialog();
}
void ProfilesDialog::slotAdjustWidth()
{
// A profile's width should always be a multiple of 8
m_view.size_w->blockSignals(true);
QSignalBlocker blk(m_view.size_w);
int val = m_view.size_w->value();
int correctedWidth = (val + 7) / 8 * 8;
if (val == correctedWidth) {
......@@ -156,7 +152,24 @@ void ProfilesDialog::slotAdjustWidth()
m_infoMessage->setMessageType(KMessageWidget::Warning);
m_infoMessage->animatedShow();
}
m_view.size_w->blockSignals(false);
}
void ProfilesDialog::slotAdjustHeight()
{
// A profile's height should always be a multiple of 2
QSignalBlocker blk(m_view.size_h);
int val = m_view.size_h->value();
int correctedHeight = val + (val % 2);
if (val == correctedHeight) {
// Ok, no action required, width is a multiple of 8
m_infoMessage->animatedHide();
} else {
m_view.size_h->setValue(correctedHeight);
m_infoMessage->setText(i18n("Profile height must be a multiple of 2. It was adjusted to %1", correctedHeight));
m_infoMessage->setWordWrap(m_infoMessage->text().length() > 35);
m_infoMessage->setMessageType(KMessageWidget::Warning);
m_infoMessage->animatedShow();
}
}
void ProfilesDialog::slotProfileEdited()
......@@ -314,8 +327,9 @@ void ProfilesDialog::slotDeleteProfile()
}
}
void ProfilesDialog::slotUpdateDisplay(QString currentProfile)
void ProfilesDialog::slotUpdateDisplay(QString currentProfilePath)
{
qDebug()<<"/ / / /UPDATING DISPLAY FOR PROFILE: "<<currentProfilePath;
if (!askForSave()) {
m_view.profiles_list->blockSignals(true);
m_view.profiles_list->setCurrentIndex(m_selectedProfileIndex);
......@@ -325,15 +339,15 @@ void ProfilesDialog::slotUpdateDisplay(QString currentProfile)
QLocale locale;
locale.setNumberOptions(QLocale::OmitGroupSeparator);
m_selectedProfileIndex = m_view.profiles_list->currentIndex();
if (currentProfile.isEmpty()) {
currentProfile = m_view.profiles_list->itemData(m_view.profiles_list->currentIndex()).toString();
if (currentProfilePath.isEmpty()) {
currentProfilePath = m_view.profiles_list->itemData(m_view.profiles_list->currentIndex()).toString();
}
m_isCustomProfile = currentProfile.contains(QLatin1Char('/'));
m_isCustomProfile = currentProfilePath.contains(QLatin1Char('/'));
m_view.button_create->setEnabled(true);
m_view.button_delete->setEnabled(m_isCustomProfile);
m_view.properties->setEnabled(m_isCustomProfile);
m_view.button_save->setEnabled(m_isCustomProfile);
std::unique_ptr<ProfileModel> &curProfile = ProfileRepository::get()->getProfile(currentProfile);
std::unique_ptr<ProfileModel> &curProfile = ProfileRepository::get()->getProfile(currentProfilePath);
m_view.description->setText(curProfile->description());
m_view.size_w->setValue(curProfile->width());
m_view.size_h->setValue(curProfile->height());
......
......@@ -41,7 +41,7 @@ protected:
void closeEvent(QCloseEvent *event) override;
private slots:
void slotUpdateDisplay(QString currentProfile = QString());
void slotUpdateDisplay(QString currentProfilePath = QString());
void slotCreateProfile();
bool slotSaveProfile();
void slotDeleteProfile();
......@@ -49,6 +49,8 @@ private slots:
void slotProfileEdited();
/** @brief Make sure the profile's width is always a multiple of 8 */
void slotAdjustWidth();
/** @brief Make sure the profile's height is always a multiple of 2 */
void slotAdjustHeight();
void accept() override;
void reject() override;
......@@ -64,6 +66,7 @@ private:
KMessageWidget *m_infoMessage;
void saveProfile(const QString &path);
bool askForSave();
void connectDialog();
};
#endif
......@@ -6,15 +6,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>430</width>
<height>502</height>
<width>594</width>
<height>639</height>
</rect>
</property>
<property name="windowTitle">
<string>Profiles</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="5">
<item row="0" column="6">
<widget class="QToolButton" name="button_delete">
<property name="enabled">
<bool>false</bool>
......@@ -24,10 +24,31 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KComboBox" name="profiles_list"/>
<item row="0" column="5">
<widget class="QToolButton" name="button_save">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>S</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Profile</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="7">
<item row="0" column="4">
<widget class="QToolButton" name="button_create">
<property name="text">
<string>C</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="8">
<widget class="QGroupBox" name="properties">
<property name="title">
<string>Properties</string>
......@@ -226,7 +247,7 @@
</layout>
</widget>
</item>
<item row="0" column="2">
<item row="0" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -239,24 +260,23 @@
</property>
</spacer>
</item>
<item row="0" column="4">
<widget class="QToolButton" name="button_save">
<property name="enabled">
<bool>false</bool>
<item row="2" column="0" colspan="7">
<widget class="QFrame" name="messageFrame">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>S</string>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QToolButton" name="button_create">
<property name="text">
<string>C</string>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
</widget>
</item>
<item row="3" column="4" colspan="3">
<item row="3" column="5" colspan="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -266,21 +286,7 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QPushButton" name="button_default">
<property name="text">
<string>Use as default</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Profile</string>
</property>
</widget>
</item>
<item row="3" column="2" colspan="2">
<item row="3" column="3" colspan="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -293,22 +299,16 @@
</property>
</spacer>
</item>
<item row="2" column="0" colspan="6">
<widget class="QFrame" name="messageFrame">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
<item row="3" column="0" colspan="3">
<widget class="QPushButton" name="button_default">
<property name="text">
<string>Use as default</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="profiles_list"/>
</item>
</layout>
</widget>
<customwidgets>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment