diff --git a/Source/Fractorium/Fractorium.h b/Source/Fractorium/Fractorium.h index ad92d21..4e70e26 100644 --- a/Source/Fractorium/Fractorium.h +++ b/Source/Fractorium/Fractorium.h @@ -484,7 +484,7 @@ private: //Xforms. DoubleSpinBox* m_XformWeightSpin; - SpinnerButtonWidget* m_XformWeightSpinnerButtonWidget; + SpinnerLabelButtonWidget* m_XformWeightSpinnerButtonWidget; QFormLayout* m_XformsSelectionLayout; vector m_XformSelections; diff --git a/Source/Fractorium/FractoriumXforms.cpp b/Source/Fractorium/FractoriumXforms.cpp index 02b362b..f2c93d6 100644 --- a/Source/Fractorium/FractoriumXforms.cpp +++ b/Source/Fractorium/FractoriumXforms.cpp @@ -1,4 +1,4 @@ -#include "FractoriumPch.h" +#include "FractoriumPch.h" #include "Fractorium.h" /// @@ -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(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_XformWeightSpinnerButtonWidget->m_Button->setToolTip("Equalize weights"); + 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,8 +477,9 @@ void FractoriumEmberController::SetNormalizedWeightText(Xform* 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) + ")"); + } } /// /// Determine whether the specified xform is the final xform in the ember. diff --git a/Source/Fractorium/TwoButtonComboWidget.h b/Source/Fractorium/TwoButtonComboWidget.h index 7537740..86ec269 100644 --- a/Source/Fractorium/TwoButtonComboWidget.h +++ b/Source/Fractorium/TwoButtonComboWidget.h @@ -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: + /// + /// 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. + /// + /// The pre-created DoubleSpinBox + /// The caption of the button + /// The width of the button + /// The height of the button + /// The parent widget + 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; +};