Avoid using floating point notation in the properties pane.

This commit is contained in:
leo
2015-01-19 23:48:46 +00:00
parent 9b5d6a18df
commit 817ffce7ef
6 changed files with 42 additions and 139 deletions
-103
View File
@@ -107,109 +107,6 @@ void lcMesh::CreateBox()
UpdateBuffers();
}
void lcMesh::Render(int DefaultColorIdx, bool Selected, bool Focused)
{
char* ElementsOffset;
char* BufferOffset;
if (GL_HasVertexBufferObject())
{
glBindBuffer(GL_ARRAY_BUFFER_ARB, mVertexBuffer.mBuffer);
BufferOffset = NULL;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, mIndexBuffer.mBuffer);
ElementsOffset = NULL;
}
else
{
BufferOffset = (char*)mVertexBuffer.mData;
ElementsOffset = (char*)mIndexBuffer.mData;
}
glVertexPointer(3, GL_FLOAT, 0, BufferOffset);
for (int SectionIdx = 0; SectionIdx < mNumSections; SectionIdx++)
{
lcMeshSection* Section = &mSections[SectionIdx];
int ColorIdx = Section->ColorIndex;
if (Section->PrimitiveType == GL_TRIANGLES)
{
if (ColorIdx == gDefaultColor)
ColorIdx = DefaultColorIdx;
if (lcIsColorTranslucent(ColorIdx))
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // TODO: cache states
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
}
else
{
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
}
lcSetColor(ColorIdx);
}
else
{
glDepthMask(GL_TRUE); // TODO: cache states
glDisable(GL_BLEND);
if (Focused)
lcSetColorFocused();
else if (Selected)
lcSetColorSelected();
else if (ColorIdx == gEdgeColor)
lcSetEdgeColor(DefaultColorIdx);
else
lcSetColor(ColorIdx);
}
if (mNumTexturedVertices)
{
if (Section->Texture) // TODO: cache states
{
glVertexPointer(3, GL_FLOAT, sizeof(lcVertexTextured), BufferOffset + (mNumVertices * sizeof(lcVertex)));
glTexCoordPointer(2, GL_FLOAT, sizeof(lcVertexTextured), BufferOffset + ((mNumVertices + 1) * sizeof(lcVertex)));
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glBindTexture(GL_TEXTURE_2D, Section->Texture->mTexture);
glEnable(GL_TEXTURE_2D);
}
else
{
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, BufferOffset);
glTexCoordPointer(2, GL_FLOAT, 0, NULL);
glDisable(GL_TEXTURE_2D);
}
}
glDrawElements(Section->PrimitiveType, Section->NumIndices, mIndexType, ElementsOffset + Section->IndexOffset);
}
glDepthMask(GL_TRUE); // TODO: cache states
glDisable(GL_BLEND);
if (GL_HasVertexBufferObject())
{
glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
}
else
glVertexPointer(3, GL_FLOAT, 0, NULL);
if (mNumTexturedVertices)
{
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, NULL);
glDisable(GL_TEXTURE_2D);
}
}
template<typename IndexType>
bool lcMesh::MinIntersectDist(const lcVector3& Start, const lcVector3& End, float& MinDist, lcVector3& Intersection)
{
-1
View File
@@ -129,7 +129,6 @@ public:
void Create(int NumSections, int NumVertices, int NumTexturedVertices, int NumIndices);
void CreateBox();
void Render(int ColorIdx, bool Selected, bool Focused);
bool FileLoad(lcFile& File);
void FileSave(lcFile& File);
+3 -15
View File
@@ -15,6 +15,7 @@
#include "lc_application.h"
#include "lc_library.h"
#include "lc_context.h"
#include "lc_qutils.h"
#define LC_PIECE_SAVE_VERSION 12 // LeoCAD 0.80
@@ -65,22 +66,9 @@ void lcPiece::SaveLDraw(QTextStream& Stream) const
const float* Matrix = mModelWorld;
float Numbers[12] = { Matrix[12], -Matrix[14], Matrix[13], Matrix[0], -Matrix[8], Matrix[4], -Matrix[2], Matrix[10], -Matrix[6], Matrix[1], -Matrix[9], Matrix[5] };
for (int NumberIdx = 0; NumberIdx < 12; NumberIdx++)
{
QString Number = QString::number(Numbers[NumberIdx], 'f', 6);
int Dot = Number.indexOf('.');
if (Dot != -1)
{
while (Number.endsWith('0'))
Number.chop(1);
if (Number.endsWith('.'))
Number.chop(1);
}
Stream << Number << ' ';
}
Stream << lcFormatValue(Numbers[NumberIdx]) << ' ';
Stream << mPieceInfo->GetSaveID() << LineEnding;
}
+20 -20
View File
@@ -10,6 +10,7 @@
#include "light.h"
#include "pieceinf.h"
#include "lc_library.h"
#include "lc_qutils.h"
// Draw an icon indicating opened/closing branches
static QIcon drawIndicatorIcon(const QPalette &palette, QStyle *style)
@@ -17,7 +18,6 @@ static QIcon drawIndicatorIcon(const QPalette &palette, QStyle *style)
QPixmap pix(14, 14);
pix.fill(Qt::transparent);
QStyleOption branchOption;
QRect r(QPoint(0, 0), pix.size());
branchOption.rect = QRect(2, 2, 9, 9); // ### hardcoded in qcommonstyle.cpp
branchOption.palette = palette;
branchOption.state = QStyle::State_Children;
@@ -405,7 +405,7 @@ QWidget *lcQPropertiesTree::createEditor(QWidget *parent, QTreeWidgetItem *item)
float value = item->data(0, PropertyValueRole).toFloat();
editor->setValidator(new QDoubleValidator());
editor->setText(QString::number(value));
editor->setText(lcFormatValue(value));
connect(editor, SIGNAL(returnPressed()), this, SLOT(slotReturnPressed()));
@@ -781,19 +781,19 @@ void lcQPropertiesTree::setPart(lcObject *newFocusObject)
lcPiece *part = (lcPiece*)focusObject;
lcVector3 position = part->mModelWorld.GetTranslation();
partPositionX->setText(1, QString::number(position[0]));
partPositionX->setText(1, lcFormatValue(position[0]));
partPositionX->setData(0, PropertyValueRole, position[0]);
partPositionY->setText(1, QString::number(position[1]));
partPositionY->setText(1, lcFormatValue(position[1]));
partPositionY->setData(0, PropertyValueRole, position[1]);
partPositionZ->setText(1, QString::number(position[2]));
partPositionZ->setText(1, lcFormatValue(position[2]));
partPositionZ->setData(0, PropertyValueRole, position[2]);
lcVector3 rotation = lcMatrix44ToEulerAngles(part->mModelWorld) * LC_RTOD;
partRotationX->setText(1, QString::number(rotation[0]));
partRotationX->setText(1, lcFormatValue(rotation[0]));
partRotationX->setData(0, PropertyValueRole, rotation[0]);
partRotationY->setText(1, QString::number(rotation[1]));
partRotationY->setText(1, lcFormatValue(rotation[1]));
partRotationY->setData(0, PropertyValueRole, rotation[1]);
partRotationZ->setText(1, QString::number(rotation[2]));
partRotationZ->setText(1, lcFormatValue(rotation[2]));
partRotationZ->setData(0, PropertyValueRole, rotation[2]);
lcStep show = part->GetStepShow();
@@ -856,36 +856,36 @@ void lcQPropertiesTree::setCamera(lcObject *newFocusObject)
lcCamera *camera = (lcCamera*)focusObject;
lcVector3 position = camera->mPosition;
cameraPositionX->setText(1, QString::number(position[0]));
cameraPositionX->setText(1, lcFormatValue(position[0]));
cameraPositionX->setData(0, PropertyValueRole, position[0]);
cameraPositionY->setText(1, QString::number(position[1]));
cameraPositionY->setText(1, lcFormatValue(position[1]));
cameraPositionY->setData(0, PropertyValueRole, position[1]);
cameraPositionZ->setText(1, QString::number(position[2]));
cameraPositionZ->setText(1, lcFormatValue(position[2]));
cameraPositionZ->setData(0, PropertyValueRole, position[2]);
lcVector3 target = camera->mTargetPosition;
cameraTargetX->setText(1, QString::number(target[0]));
cameraTargetX->setText(1, lcFormatValue(target[0]));
cameraTargetX->setData(0, PropertyValueRole, target[0]);
cameraTargetY->setText(1, QString::number(target[1]));
cameraTargetY->setText(1, lcFormatValue(target[1]));
cameraTargetY->setData(0, PropertyValueRole, target[1]);
cameraTargetZ->setText(1, QString::number(target[2]));
cameraTargetZ->setText(1, lcFormatValue(target[2]));
cameraTargetZ->setData(0, PropertyValueRole, target[2]);
lcVector3 up = camera->mUpVector;
cameraUpX->setText(1, QString::number(up[0]));
cameraUpX->setText(1, lcFormatValue(up[0]));
cameraUpX->setData(0, PropertyValueRole, up[0]);
cameraUpY->setText(1, QString::number(up[1]));
cameraUpY->setText(1, lcFormatValue(up[1]));
cameraUpY->setData(0, PropertyValueRole, up[1]);
cameraUpZ->setText(1, QString::number(up[2]));
cameraUpZ->setText(1, lcFormatValue(up[2]));
cameraUpZ->setData(0, PropertyValueRole, up[2]);
cameraOrtho->setText(1, camera->IsOrtho() ? "True" : "False");
cameraOrtho->setData(0, PropertyValueRole, camera->IsOrtho());
cameraFOV->setText(1, QString::number(camera->m_fovy));
cameraFOV->setText(1, lcFormatValue(camera->m_fovy));
cameraFOV->setData(0, PropertyValueRole, camera->m_fovy);
cameraNear->setText(1, QString::number(camera->m_zNear));
cameraNear->setText(1, lcFormatValue(camera->m_zNear));
cameraNear->setData(0, PropertyValueRole, camera->m_zNear);
cameraFar->setText(1, QString::number(camera->m_zFar));
cameraFar->setText(1, lcFormatValue(camera->m_zFar));
cameraFar->setData(0, PropertyValueRole, camera->m_zFar);
cameraName->setText(1, camera->GetName());
+17
View File
@@ -4,6 +4,23 @@
#include "lc_library.h"
#include "pieceinf.h"
QString lcFormatValue(float Value)
{
QString String = QString::number(Value, 'f', 6);
int Dot = String.indexOf('.');
if (Dot != -1)
{
while (String.endsWith('0'))
String.chop(1);
if (String.endsWith('.'))
String.chop(1);
}
return String;
}
// Resize all columns to content except for one stretching column. (taken from QT creator)
lcQTreeWidgetColumnStretcher::lcQTreeWidgetColumnStretcher(QTreeWidget *treeWidget, int columnToStretch)
: QObject(treeWidget->header()), m_columnToStretch(columnToStretch)
+2
View File
@@ -3,6 +3,8 @@
#include <QObject>
QString lcFormatValue(float Value);
class lcQTreeWidgetColumnStretcher : public QObject
{
public: