Change the method that normalized weight text displayed from spinner box suffix to a Qlabel to prevent annoying interruption when typing weight.

This commit is contained in:
luyuju151 2018-07-09 01:25:08 +08:00
parent 8b2d5c9697
commit e58deb1194
3 changed files with 63 additions and 8 deletions

View File

@ -484,7 +484,7 @@ private:
//Xforms.
DoubleSpinBox* m_XformWeightSpin;
SpinnerButtonWidget* m_XformWeightSpinnerButtonWidget;
SpinnerLabelButtonWidget* m_XformWeightSpinnerButtonWidget;
QFormLayout* m_XformsSelectionLayout;
vector<QCheckBox*> m_XformSelections;

View File

@ -1,4 +1,4 @@
#include "FractoriumPch.h"
#include "FractoriumPch.h"
#include "Fractorium.h"
/// <summary>
@ -15,14 +15,20 @@ void Fractorium::InitXformsUI()
connect(ui.AddFinalXformButton, SIGNAL(clicked(bool)), this, SLOT(OnAddFinalXformButtonClicked(bool)), Qt::QueuedConnection);
connect(ui.CurrentXformCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(OnCurrentXformComboChanged(int)), Qt::QueuedConnection);
connect(ui.AnimateXformCheckBox, SIGNAL(stateChanged(int)), this, SLOT(OnXformAnimateCheckBoxStateChanged(int)), Qt::QueuedConnection);
SetFixedTableHeader(ui.XformWeightNameTable->horizontalHeader());
SetFixedTableHeader(ui.XformWeightNameTable->horizontalHeader(),QHeaderView::ResizeToContents);
//Use SetupSpinner() just to create the spinner, but use col of -1 to prevent it from being added to the table.
SetupSpinner<DoubleSpinBox, double>(ui.XformWeightNameTable, this, row, -1, m_XformWeightSpin, spinHeight, 0, 1000, 0.05, SIGNAL(valueChanged(double)), SLOT(OnXformWeightChanged(double)), false, 0, 1, 0);
m_XformWeightSpin->setDecimals(3);
m_XformWeightSpin->SmallStep(0.001);
m_XformWeightSpinnerButtonWidget = new SpinnerButtonWidget(m_XformWeightSpin, "=", 20, 19, ui.XformWeightNameTable);
m_XformWeightSpin->setMinimumWidth(40);
m_XformWeightSpinnerButtonWidget = new SpinnerLabelButtonWidget(m_XformWeightSpin, "=", 20, 19, ui.XformWeightNameTable);
m_XformWeightSpinnerButtonWidget->m_SpinBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
m_XformWeightSpinnerButtonWidget->m_Label->setStyleSheet("border: 0px;");
m_XformWeightSpinnerButtonWidget->m_Label->setAlignment(Qt::AlignRight| Qt::AlignVCenter);
m_XformWeightSpinnerButtonWidget->m_Label->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed);
m_XformWeightSpinnerButtonWidget->m_Button->setToolTip("Equalize weights");
m_XformWeightSpinnerButtonWidget->m_Button->setStyleSheet("text-align: center center");
m_XformWeightSpinnerButtonWidget->setMaximumWidth(130);
connect(m_XformWeightSpinnerButtonWidget->m_Button, SIGNAL(clicked(bool)), this, SLOT(OnEqualWeightButtonClicked(bool)), Qt::QueuedConnection);
ui.XformWeightNameTable->setCellWidget(0, 0, m_XformWeightSpinnerButtonWidget);
ui.XformWeightNameTable->setItem(0, 1, new QTableWidgetItem());
@ -471,7 +477,8 @@ void FractoriumEmberController<T>::SetNormalizedWeightText(Xform<T>* xform)
m_Ember.CalcNormalizedWeights(m_NormalizedWeights);
if (index != -1 && index < m_NormalizedWeights.size())
m_Fractorium->m_XformWeightSpin->setSuffix(QString(" (") + QLocale::system().toString(double(m_NormalizedWeights[index]), 'g', 3) + ")");
//m_Fractorium->m_XformWeightSpin->setSuffix(QString(" (") + QLocale::system().toString(double(m_NormalizedWeights[index]), 'g', 3) + ")");
m_Fractorium->m_XformWeightSpinnerButtonWidget->m_Label->setText(QString(" (") + QLocale::system().toString(double(m_NormalizedWeights[index]), 'g', 3) + ")");
}
}
/// <summary>

View File

@ -1,4 +1,4 @@
#pragma once
#pragma once
#include "FractoriumPch.h"
#include "DoubleSpinBox.h"
@ -118,3 +118,51 @@ public:
DoubleSpinBox* m_SpinBox;
QPushButton* m_Button;
};
class SpinnerLabelButtonWidget : public QWidget
{
Q_OBJECT
public:
/// <summary>
/// Constructor that passes the parent to the base, then creates a QLabel,
/// then creates a QPushButton and sets up its caption and dimensions, then
/// assigns the DoubleSpinBox.
/// </summary>
/// <param name="spinBox">The pre-created DoubleSpinBox</param>
/// <param name="buttonCaption">The caption of the button</param>
/// <param name="w">The width of the button</param>
/// <param name="h">The height of the button</param>
/// <param name="p">The parent widget</param>
SpinnerLabelButtonWidget(DoubleSpinBox* spinBox, QString buttonCaption, int w, int h, QWidget* p)
: QWidget(p)
{
QHBoxLayout* l = new QHBoxLayout(this);
m_Button = new QPushButton(buttonCaption, p);
m_SpinBox = spinBox;
m_Label = new QLabel(p);
m_Label->setMinimumHeight(h);
m_Label->setMaximumHeight(h);
if (w != -1)
{
m_Button->setMinimumWidth(w);
m_Button->setMaximumWidth(w);
}
m_Button->setMinimumHeight(h);
m_Button->setMaximumHeight(h);
l->addWidget(spinBox);
l->addWidget(m_Label);
l->addWidget(m_Button);
l->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
l->setMargin(0);
l->setSpacing(0);
setLayout(l);
}
DoubleSpinBox* m_SpinBox;
QPushButton* m_Button;
QLabel* m_Label;
};