Skip to content

Commit

Permalink
Merge pull request #319 from tcuje/master
Browse files Browse the repository at this point in the history
Fix Issues #160 #239
  • Loading branch information
leozide authored Mar 10, 2019
2 parents 016fdc3 + 94d4e49 commit 03127de
Show file tree
Hide file tree
Showing 19 changed files with 730 additions and 603 deletions.
4 changes: 3 additions & 1 deletion common/lc_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void lcPreferences::LoadDefaults()
mViewSphereColor = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_COLOR);
mViewSphereTextColor = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_TEXT_COLOR);
mViewSphereHighlightColor = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_HIGHLIGHT_COLOR);
autoLoadMostRecent = lcGetProfileInt(LC_PROFILE_AUTOLOAD_MOSTRECENT);
}

void lcPreferences::SaveDefaults()
Expand All @@ -50,6 +51,7 @@ void lcPreferences::SaveDefaults()
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_COLOR, mViewSphereColor);
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_TEXT_COLOR, mViewSphereTextColor);
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_HIGHLIGHT_COLOR, mViewSphereHighlightColor);
lcSetProfileInt(LC_PROFILE_AUTOLOAD_MOSTRECENT, autoLoadMostRecent);
}

lcApplication::lcApplication(int& Argc, char** Argv)
Expand Down Expand Up @@ -196,7 +198,7 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
QString ModelName;
QString CameraName;
QString ViewpointName;
QString ProjectName;
QString ProjectName = lcGetProfileInt(LC_PROFILE_AUTOLOAD_MOSTRECENT) ? lcGetProfileString(LC_PROFILE_RECENT_FILE1) : QString();
QString SaveWavefrontName;
QString Save3DSName;
QString SaveCOLLADAName;
Expand Down
1 change: 1 addition & 0 deletions common/lc_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class lcPreferences
quint32 mViewSphereColor;
quint32 mViewSphereTextColor;
quint32 mViewSphereHighlightColor;
bool autoLoadMostRecent;
};

class lcApplication : public QApplication
Expand Down
2 changes: 1 addition & 1 deletion common/lc_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <array>

#ifndef Q_FALLTHROUGH
#define Q_FALLTHROUGH(); [[fallthrough]];
#define Q_FALLTHROUGH(); // fall through
#endif

#if !defined(EGL_VERSION_1_0) && !defined(GL_ES_VERSION_2_0) && !defined(GL_ES_VERSION_3_0) && !defined(QT_OPENGL_ES)
Expand Down
3 changes: 1 addition & 2 deletions common/lc_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,7 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
if (Token == QLatin1String("BEGIN"))
{
QString Name = LineStream.readAll().trimmed();
QByteArray NameUtf = Name.toUtf8(); // todo: replace with qstring
lcGroup* Group = GetGroup(NameUtf.constData(), true);
lcGroup* Group = GetGroup(Name, true);
if (!CurrentGroups.IsEmpty())
Group->mGroup = CurrentGroups[CurrentGroups.GetSize() - 1];
else
Expand Down
1 change: 1 addition & 0 deletions common/lc_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] =
lcProfileEntry("Settings", "RecentFile2", ""), // LC_PROFILE_RECENT_FILE2
lcProfileEntry("Settings", "RecentFile3", ""), // LC_PROFILE_RECENT_FILE3
lcProfileEntry("Settings", "RecentFile4", ""), // LC_PROFILE_RECENT_FILE4
lcProfileEntry("Settings", "AutoLoadMostRecent", false), // LC_PROFILE_AUTOLOAD_MOSTRECENT
lcProfileEntry("Settings", "AutosaveInterval", 10), // LC_PROFILE_AUTOSAVE_INTERVAL
lcProfileEntry("Settings", "MouseSensitivity", 11), // LC_PROFILE_MOUSE_SENSITIVITY
lcProfileEntry("Settings", "ImageWidth", 1280), // LC_PROFILE_IMAGE_WIDTH
Expand Down
1 change: 1 addition & 0 deletions common/lc_profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum LC_PROFILE_KEY
LC_PROFILE_RECENT_FILE2,
LC_PROFILE_RECENT_FILE3,
LC_PROFILE_RECENT_FILE4,
LC_PROFILE_AUTOLOAD_MOSTRECENT,
LC_PROFILE_AUTOSAVE_INTERVAL,
LC_PROFILE_MOUSE_SENSITIVITY,
LC_PROFILE_IMAGE_WIDTH,
Expand Down
1 change: 1 addition & 0 deletions leocad.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<file>resources/time_add_keys.png</file>
<file>resources/parts_search.png</file>
<file>resources/parts_cancel.png</file>
<file>resources/archive.png</file>
<file>resources/library.zip</file>
<file>resources/ldconfig.ldr</file>
<file>resources/minifig.ini</file>
Expand Down
14 changes: 12 additions & 2 deletions qt/lc_qpreferencesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget *parent, void *data) :
ui->lgeoPath->setText(options->LGEOPath);
ui->mouseSensitivity->setValue(options->Preferences.mMouseSensitivity);
ui->checkForUpdates->setCurrentIndex(options->CheckForUpdates);
ui->fixedDirectionKeys->setChecked((options->Preferences.mFixedAxes) != 0);
ui->fixedDirectionKeys->setChecked(options->Preferences.mFixedAxes);
ui->autoLoadMostRecent->setChecked(options->Preferences.autoLoadMostRecent);

ui->antiAliasing->setChecked(options->AASamples != 1);
if (options->AASamples == 8)
Expand Down Expand Up @@ -145,6 +146,7 @@ void lcQPreferencesDialog::accept()
options->Preferences.mMouseSensitivity = ui->mouseSensitivity->value();
options->CheckForUpdates = ui->checkForUpdates->currentIndex();
options->Preferences.mFixedAxes = ui->fixedDirectionKeys->isChecked();
options->Preferences.autoLoadMostRecent = ui->autoLoadMostRecent->isChecked();

if (!ui->antiAliasing->isChecked())
options->AASamples = 1;
Expand Down Expand Up @@ -188,7 +190,15 @@ void lcQPreferencesDialog::accept()

void lcQPreferencesDialog::on_partsLibraryBrowse_clicked()
{
QString result = QFileDialog::getExistingDirectory(this, tr("Open Parts Library Folder"), ui->partsLibrary->text());
QString result = QFileDialog::getExistingDirectory(this, tr("Select Parts Library Folder..."), ui->partsLibrary->text());

if (!result.isEmpty())
ui->partsLibrary->setText(QDir::toNativeSeparators(result));
}

void lcQPreferencesDialog::on_partsArchiveBrowse_clicked()
{
QString result = QFileDialog::getOpenFileName(this, tr("Select Parts Library Archive..."), ui->partsLibrary->text(), tr("Supported Archives (*.zip *.bin);;All Files (*.*)"));

if (!result.isEmpty())
ui->partsLibrary->setText(QDir::toNativeSeparators(result));
Expand Down
1 change: 1 addition & 0 deletions qt/lc_qpreferencesdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class lcQPreferencesDialog : public QDialog
public slots:
void accept();
void on_partsLibraryBrowse_clicked();
void on_partsArchiveBrowse_clicked();
void on_povrayExecutableBrowse_clicked();
void on_lgeoPathBrowse_clicked();
void ColorButtonClicked();
Expand Down
21 changes: 19 additions & 2 deletions qt/lc_qpreferencesdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,17 @@
</item>
<item>
<widget class="QToolButton" name="partsLibraryBrowse">
<property name="text">
<string>...</string>
<property name="icon">
<iconset>
<normaloff>:/resources/file_open.png</normaloff>:/resources/file_open.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="partsArchiveBrowse">
<property name="icon">
<iconset>
<normaloff>:/resources/archive.png</normaloff>:/resources/archive.png</iconset>
</property>
</widget>
</item>
Expand Down Expand Up @@ -158,6 +167,13 @@
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="autoLoadMostRecent">
<property name="text">
<string>Open most recent file on startup</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabRendering">
Expand Down Expand Up @@ -982,6 +998,7 @@
<tabstop>authorName</tabstop>
<tabstop>partsLibrary</tabstop>
<tabstop>partsLibraryBrowse</tabstop>
<tabstop>partsArchiveBrowse</tabstop>
<tabstop>povrayExecutable</tabstop>
<tabstop>povrayExecutableBrowse</tabstop>
<tabstop>lgeoPath</tabstop>
Expand Down
4 changes: 2 additions & 2 deletions qt/lc_qpropertiestree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void lcQPropertiesTreeDelegate::paint(QPainter *painter, const QStyleOptionViewI
if (m_treeWidget)
hasValue = m_treeWidget->indexToItem(index)->data(0, lcQPropertiesTree::PropertyTypeRole).toInt() != lcQPropertiesTree::PropertyGroup;

QStyleOptionViewItemV3 opt = option;
QStyleOptionViewItem opt = option;

opt.state &= ~QStyle::State_HasFocus;

Expand Down Expand Up @@ -241,7 +241,7 @@ QSize lcQPropertiesTree::sizeHint() const

void lcQPropertiesTree::drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItemV3 opt = option;
QStyleOptionViewItem opt = option;

QTreeWidgetItem *item = itemFromIndex(index);

Expand Down
67 changes: 49 additions & 18 deletions qt/lc_renderdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ lcRenderDialog::lcRenderDialog(QWidget* Parent)

QImage Image(LC_POVRAY_PREVIEW_WIDTH, LC_POVRAY_PREVIEW_HEIGHT, QImage::Format_RGB32);
Image.fill(QColor(255, 255, 255));
ui->label->setPixmap(QPixmap::fromImage(Image));
ui->preview->setPixmap(QPixmap::fromImage(Image));

connect(&mUpdateTimer, SIGNAL(timeout()), this, SLOT(Update()));
mUpdateTimer.start(500);
Expand Down Expand Up @@ -168,10 +168,15 @@ void lcRenderDialog::on_RenderButton_clicked()
#endif

mProcess = new QProcess(this);
connect(mProcess, SIGNAL(readyReadStandardError()), this, SLOT(ReadStdErr()));
mProcess->start(POVRayPath, Arguments);

if (mProcess->waitForStarted())
{
ui->RenderButton->setText(tr("Cancel"));
ui->RenderProgress->setValue(ui->RenderProgress->minimum());
stdErrList.clear();
}
else
{
QMessageBox::warning(this, tr("Error"), tr("Error starting POV-Ray."));
Expand All @@ -180,6 +185,19 @@ void lcRenderDialog::on_RenderButton_clicked()
#endif
}

void lcRenderDialog::ReadStdErr()
{
QString stdErr = QString(mProcess->readAllStandardError());
stdErrList.append(stdErr);
QRegExp regexPovRayProgress("Rendered (\\d+) of (\\d+) pixels.*");
regexPovRayProgress.setCaseSensitivity(Qt::CaseInsensitive);
if (regexPovRayProgress.indexIn(stdErr) == 0)
{
ui->RenderProgress->setMaximum(regexPovRayProgress.cap(2).toInt());
ui->RenderProgress->setValue(regexPovRayProgress.cap(1).toInt());
}
}

void lcRenderDialog::Update()
{
#ifndef QT_NO_PROCESS
Expand All @@ -188,14 +206,12 @@ void lcRenderDialog::Update()

if (mProcess->state() == QProcess::NotRunning)
{
// QString Output = mProcess->readAllStandardError();
// QMessageBox::information(this, "LeoCAD", Output);

#ifdef Q_OS_LINUX
QByteArray Output = mProcess->readAllStandardOutput();
QImage Image = QImage::fromData(Output);
ui->label->setPixmap(QPixmap::fromImage(Image.scaled(LC_POVRAY_PREVIEW_WIDTH, LC_POVRAY_PREVIEW_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
mImage = QImage::fromData(Output);
ShowResult();
#endif

CloseProcess();
}
#endif
Expand Down Expand Up @@ -251,23 +267,38 @@ void lcRenderDialog::Update()

Header->PixelsRead = PixelsWritten;

ui->label->setPixmap(QPixmap::fromImage(mImage.scaled(LC_POVRAY_PREVIEW_WIDTH, LC_POVRAY_PREVIEW_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation)));

if (PixelsWritten == Width * Height)
{
QString FileName = ui->OutputEdit->text();
ShowResult();
#endif
}

if (!FileName.isEmpty())
{
QImageWriter Writer(FileName);
void lcRenderDialog::ShowResult() {
ReadStdErr();
ui->RenderProgress->setValue(ui->RenderProgress->maximum());

if (mProcess->exitStatus() != QProcess::NormalExit || mProcess->exitCode() != 0) {
QMessageBox error;
error.setWindowTitle(tr("Error"));
error.setIcon(QMessageBox::Critical);
error.setText(tr("An error occurred while rendering. Check details or try again."));
error.setDetailedText(stdErrList.join(""));
error.exec();
return;
}

bool Result = Writer.write(mImage);
ui->preview->setPixmap(QPixmap::fromImage(mImage.scaled(LC_POVRAY_PREVIEW_WIDTH, LC_POVRAY_PREVIEW_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation)));

if (!Result)
QMessageBox::information(this, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, Writer.errorString()));
}
QString FileName = ui->OutputEdit->text();

if (!FileName.isEmpty())
{
QImageWriter Writer(FileName);

bool Result = Writer.write(mImage);

if (!Result)
QMessageBox::information(this, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, Writer.errorString()));
}
#endif
}

void lcRenderDialog::on_OutputBrowseButton_clicked()
Expand Down
5 changes: 5 additions & 0 deletions qt/lc_renderdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ public slots:
void on_OutputBrowseButton_clicked();
void Update();

protected slots:
void ReadStdErr();

protected:
QString GetOutputFileName() const;
QString GetPOVFileName() const;
void CloseProcess();
bool PromptCancel();
void ShowResult();

#ifndef QT_NO_PROCESS
QProcess* mProcess;
Expand All @@ -33,6 +37,7 @@ public slots:
QFile mOutputFile;
void* mOutputBuffer;
QImage mImage;
QStringList stdErrList;

Ui::lcRenderDialog* ui;
};
Loading

0 comments on commit 03127de

Please sign in to comment.