Skip to content

Commit

Permalink
Version 1.0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
4lex4 committed Jul 17, 2018
2 parents 275ae37 + 57e5d44 commit 5e0068f
Show file tree
Hide file tree
Showing 51 changed files with 737 additions and 516 deletions.
3 changes: 3 additions & 0 deletions Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Application.h"
#include <config.h>
#include <QDir>
#include <QFontDatabase>
#include <QTemporaryDir>
#include "DebugImages.h"
#include "ErrorWidget.h"
Expand All @@ -37,6 +38,8 @@
Application::Application(int& argc, char** argv) : QApplication(argc, argv), m_currentLocale("en") {
initTranslations();
initPortableVersion();

QFontDatabase::addApplicationFont(":/fonts/symbols.ttf");
}

bool Application::notify(QObject* receiver, QEvent* e) {
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ set(common_sources
BlackOnWhiteEstimator.cpp BlackOnWhiteEstimator.h
ImageSettings.cpp ImageSettings.h
EmptyTaskStatus.h
OrderByCompleteness.cpp OrderByCompleteness.h
OrderByCompletenessProvider.cpp OrderByCompletenessProvider.h
version.h
config.h.in
${common_ui_files})
Expand Down
1 change: 1 addition & 0 deletions ColorScheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <QStyle>
#include <QtGui/QPalette>
#include <memory>
#include <unordered_map>

class ColorScheme {
Expand Down
39 changes: 30 additions & 9 deletions DefaultParamsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,6 @@ void DefaultParamsDialog::updatePageLayoutDisplay(const DefaultParams::PageLayou
alignmentMode->setCurrentIndex(1);
autoAlignSettingsGroup->setVisible(false);
}
updateAlignmentButtonsEnabled();
updateAutoModeButtons();

alignWithOthersCB->setChecked(!alignment.isNull());

for (const auto& kv : m_alignmentByButton) {
Expand All @@ -247,6 +244,10 @@ void DefaultParamsDialog::updatePageLayoutDisplay(const DefaultParams::PageLayou
break;
}
}

updateAlignmentModeEnabled();
updateAlignmentButtonsEnabled();
updateAutoModeButtons();
}

void DefaultParamsDialog::updateOutputDisplay(const DefaultParams::OutputParams& params) {
Expand Down Expand Up @@ -479,7 +480,8 @@ void DefaultParamsDialog::alignmentModeChanged(const int idx) {
updateAutoModeButtons();
}

void DefaultParamsDialog::alignWithOthersToggled(const bool) {
void DefaultParamsDialog::alignWithOthersToggled(const bool state) {
updateAlignmentModeEnabled();
updateAlignmentButtonsEnabled();
}

Expand All @@ -500,6 +502,7 @@ void DefaultParamsDialog::colorModeChanged(const int idx) {
break;
}
thresholdOptions->setEnabled(threshold_options_visible);
despecklePanel->setEnabled(threshold_options_visible);
pictureShapeOptions->setEnabled(picture_shape_visible);
splittingOptions->setEnabled(splitting_options_visible);

Expand All @@ -517,8 +520,7 @@ void DefaultParamsDialog::colorModeChanged(const int idx) {
morphologicalSmoothingCB->setEnabled(colorMode != COLOR_GRAYSCALE);

colorSegmentationCB->setEnabled(threshold_options_visible);
segmenterOptionsWidget->setEnabled(threshold_options_visible);
segmenterOptionsWidget->setEnabled(colorSegmentationCB->isChecked());
segmenterOptionsWidget->setEnabled(threshold_options_visible && colorSegmentationCB->isChecked());
if (threshold_options_visible) {
posterizeCB->setEnabled(colorSegmentationCB->isChecked());
posterizeOptionsWidget->setEnabled(colorSegmentationCB->isChecked() && posterizeCB->isChecked());
Expand Down Expand Up @@ -910,15 +912,27 @@ void DefaultParamsDialog::profileChanged(const int index) {
std::unique_ptr<DefaultParams> sourceProfile = m_profileManager.createSourceProfile();
loadParams(*sourceProfile);
} else {
std::unique_ptr<DefaultParams> profile = m_profileManager.readProfile(profileCB->itemData(index).toString());
if (profile != nullptr) {
const QString profileName = profileCB->currentData().toString();
DefaultParamsProfileManager::LoadStatus loadStatus;

std::unique_ptr<DefaultParams> profile = m_profileManager.readProfile(profileName, &loadStatus);
if (loadStatus == DefaultParamsProfileManager::SUCCESS) {
profileSaveButton->setEnabled(true);
profileDeleteButton->setEnabled(true);
setTabWidgetsEnabled(true);

loadParams(*profile);
} else {
QMessageBox::critical(this, tr("Error"), tr("Error loading the profile."));
if (loadStatus == DefaultParamsProfileManager::INCOMPATIBLE_VERSION_ERROR) {
const int result = QMessageBox::warning(
this, tr("Error"), tr("The profile file is not compatible with the current application version. Remove?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (result == QMessageBox::Yes) {
m_profileManager.deleteProfile(profileName);
}
} else {
QMessageBox::critical(this, tr("Error"), tr("Error loading the profile."));
}
profileCB->setCurrentIndex(0);
profileCB->removeItem(index);
m_customProfileItemIdx--;
Expand Down Expand Up @@ -1107,3 +1121,10 @@ void DefaultParamsDialog::despeckleSliderValueChanged(int value) {
tooltip_pos = despeckleSlider->mapToGlobal(tooltip_pos);
QToolTip::showText(tooltip_pos, tooltip_text, despeckleSlider);
}

void DefaultParamsDialog::updateAlignmentModeEnabled() {
const bool is_alignment_null = !alignWithOthersCB->isChecked();

alignmentMode->setEnabled(!is_alignment_null);
autoAlignSettingsGroup->setEnabled(!is_alignment_null);
}
4 changes: 3 additions & 1 deletion DefaultParamsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DefaultParamsDialog : public QDialog, private Ui::DefaultParamsDialog {

void alignmentModeChanged(int idx);

void alignWithOthersToggled(bool);
void alignWithOthersToggled(bool state);

void autoHorizontalAligningToggled(bool);

Expand Down Expand Up @@ -126,6 +126,8 @@ class DefaultParamsDialog : public QDialog, private Ui::DefaultParamsDialog {

void updateAutoModeButtons();

void updateAlignmentModeEnabled();

QToolButton* getCheckedAlignmentButton() const;

void setLinkButtonLinked(QToolButton* button, bool linked);
Expand Down
19 changes: 17 additions & 2 deletions DefaultParamsProfileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,40 @@ std::list<QString> DefaultParamsProfileManager::getProfileList() const {
QList<QFileInfo> fileInfoList = dir.entryInfoList();
for (const QFileInfo& fileInfo : fileInfoList) {
if (fileInfo.isFile() && ((fileInfo.suffix() == "stp") || (fileInfo.suffix() == "xml"))) {
profileList.push_back(fileInfo.baseName());
profileList.push_back(fileInfo.completeBaseName());
}
}
}

return profileList;
}

std::unique_ptr<DefaultParams> DefaultParamsProfileManager::readProfile(const QString& name) const {
std::unique_ptr<DefaultParams> DefaultParamsProfileManager::readProfile(const QString& name, LoadStatus* status) const {
QDir dir(m_path);
QFileInfo profile(dir.absoluteFilePath(name + ".stp"));
if (!profile.exists()) {
profile = dir.absoluteFilePath(name + ".xml");
if (!profile.exists()) {
if (status) {
*status = IO_ERROR;
}
return nullptr;
}
}

QFile profileFile(profile.filePath());
if (!profileFile.open(QIODevice::ReadOnly)) {
if (status) {
*status = IO_ERROR;
}
return nullptr;
}

QDomDocument doc;
if (!doc.setContent(&profileFile)) {
if (status) {
*status = IO_ERROR;
}
return nullptr;
}

Expand All @@ -63,10 +72,16 @@ std::unique_ptr<DefaultParams> DefaultParamsProfileManager::readProfile(const QS
const QDomElement profileElement(doc.documentElement());
const QString version = profileElement.attribute("version");
if (version.isNull() || (version.toInt() != PROJECT_VERSION)) {
if (status) {
*status = INCOMPATIBLE_VERSION_ERROR;
}
return nullptr;
}
const QDomElement defaultParamsElement(profileElement.namedItem("default-params").toElement());

if (status) {
*status = SUCCESS;
}
return std::make_unique<DefaultParams>(defaultParamsElement);
}

Expand Down
8 changes: 7 additions & 1 deletion DefaultParamsProfileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ class DefaultParamsProfileManager {

explicit DefaultParamsProfileManager(const QString& path);

enum LoadStatus {
SUCCESS,
IO_ERROR,
INCOMPATIBLE_VERSION_ERROR
};

std::list<QString> getProfileList() const;

std::unique_ptr<DefaultParams> readProfile(const QString& name) const;
std::unique_ptr<DefaultParams> readProfile(const QString& name, LoadStatus* status = nullptr) const;

bool writeProfile(const DefaultParams& params, const QString& name) const;

Expand Down
62 changes: 50 additions & 12 deletions MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,20 @@ MainWindow::MainWindow()
connect(actionNextSelectedPageW, SIGNAL(triggered(bool)), this, SLOT(goNextSelectedPage()));
connect(actionAbout, SIGNAL(triggered(bool)), this, SLOT(showAboutDialog()));
connect(&OutOfMemoryHandler::instance(), SIGNAL(outOfMemory()), SLOT(handleOutOfMemorySituation()));
connect(prevPageBtn, &QToolButton::clicked, this, [this]() {
if (filterSelectedBtn->isChecked()) {
goPrevSelectedPage();
} else {
goPrevPage();
}
});
connect(nextPageBtn, &QToolButton::clicked, this, [this]() {
if (filterSelectedBtn->isChecked()) {
goNextSelectedPage();
} else {
goNextPage();
}
});

connect(actionSwitchFilter1, SIGNAL(triggered(bool)), SLOT(switchFilter1()));
connect(actionSwitchFilter2, SIGNAL(triggered(bool)), SLOT(switchFilter2()));
Expand Down Expand Up @@ -283,6 +297,12 @@ MainWindow::MainWindow()
}
}
m_autoSaveProject = settings.value("settings/auto_save_project").toBool();

m_maxLogicalThumbSizeUpdater.setSingleShot(true);
connect(&m_maxLogicalThumbSizeUpdater, &QTimer::timeout, this, &MainWindow::updateMaxLogicalThumbSize);

m_sceneItemsPosUpdater.setSingleShot(true);
connect(&m_sceneItemsPosUpdater, &QTimer::timeout, m_thumbSequence.get(), &ThumbnailSequence::updateSceneItemsPos);
}

MainWindow::~MainWindow() {
Expand Down Expand Up @@ -438,23 +458,27 @@ void MainWindow::createBatchProcessingWidget() {
connect(stop_btn, SIGNAL(clicked()), SLOT(stopBatchProcessing()));
} // MainWindow::createBatchProcessingWidget

void MainWindow::setupThumbView() {
void MainWindow::updateThumbViewMinWidth() {
const int sb = thumbView->style()->pixelMetric(QStyle::PM_ScrollBarExtent);
int inner_width = thumbView->maximumViewportSize().width() - sb;
if (thumbView->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, 0, thumbView)) {
inner_width -= thumbView->frameWidth() * 2;
}
const int delta_x = thumbView->size().width() - inner_width;
thumbView->setMinimumWidth((int) std::ceil(m_maxLogicalThumbSize.width() + delta_x));
}

void MainWindow::setupThumbView() {
updateThumbViewMinWidth();
m_thumbSequence->attachView(thumbView);

thumbView->installEventFilter(this);
}

bool MainWindow::eventFilter(QObject* obj, QEvent* ev) {
if ((obj == thumbView) && (ev->type() == QEvent::Resize)) {
emit invalidateAllThumbnails();
if (!m_sceneItemsPosUpdater.isActive()) {
m_sceneItemsPosUpdater.start(150);
}
}

if ((obj == thumbView || obj == thumbView->verticalScrollBar()) && (ev->type() == QEvent::Wheel)) {
Expand Down Expand Up @@ -1385,19 +1409,32 @@ void MainWindow::openDefaultParamsDialog() {

void MainWindow::onSettingsChanged() {
QSettings settings;
bool need_invalidate = true;

m_autoSaveProject = settings.value("settings/auto_save_project").toBool();

if (auto* app = dynamic_cast<Application*>(qApp)) {
app->installLanguage(settings.value("settings/language").toString());
}

if (m_thumbnailCache) {
const QSize max_thumb_size = settings.value("settings/thumbnail_quality").toSize();
if (m_thumbnailCache->getMaxThumbSize() != max_thumb_size) {
m_thumbnailCache->setMaxThumbSize(max_thumb_size);
need_invalidate = true;
}
}

const QSizeF max_logical_thumb_size = settings.value("settings/max_logical_thumb_size").toSizeF();
if (m_maxLogicalThumbSize != max_logical_thumb_size) {
updateMaxLogicalThumbSize(max_logical_thumb_size);
m_maxLogicalThumbSize = max_logical_thumb_size;
updateMaxLogicalThumbSize();
need_invalidate = false;
}

m_thumbSequence->invalidateAllThumbnails();
if (need_invalidate) {
m_thumbSequence->invalidateAllThumbnails();
}
}

void MainWindow::showAboutDialog() {
Expand Down Expand Up @@ -1567,7 +1604,7 @@ void MainWindow::updateWindowTitle() {
} else if (cli.hasWindowTitle()) {
project_name = cli.getWindowTitle();
} else {
project_name = QFileInfo(m_projectFile).baseName();
project_name = QFileInfo(m_projectFile).completeBaseName();
}
const QString version(QString::fromUtf8(VERSION));
setWindowTitle(tr("%2 - ScanTailor Advanced [%1bit]").arg(sizeof(void*) * 8).arg(project_name));
Expand Down Expand Up @@ -2015,16 +2052,17 @@ void MainWindow::scaleThumbnails(const QWheelEvent* wheel_event) {
const double dy = std::copysign(16.0, wheel_dist);
const double width = qBound(100.0, m_maxLogicalThumbSize.width() + dx, 1000.0);
const double height = qBound(64.0, m_maxLogicalThumbSize.height() + dy, 640.0);
updateMaxLogicalThumbSize(QSizeF(width, height));
m_maxLogicalThumbSize = QSizeF(width, height);
if (!m_maxLogicalThumbSizeUpdater.isActive()) {
m_maxLogicalThumbSizeUpdater.start(350);
}

QSettings().setValue("settings/max_logical_thumb_size", m_maxLogicalThumbSize);
}
}

void MainWindow::updateMaxLogicalThumbSize(const QSizeF& size) {
m_maxLogicalThumbSize = size;

void MainWindow::updateMaxLogicalThumbSize() {
m_thumbSequence->setMaxLogicalThumbSize(m_maxLogicalThumbSize);
setupThumbView();
updateThumbViewMinWidth();
resetThumbSequence(currentPageOrderProvider(), ThumbnailSequence::KEEP_SELECTION);
}
}
6 changes: 5 additions & 1 deletion MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ class MainWindow : public QMainWindow, private FilterUiInterface, private Ui::Ma
const QString& project_file_path = QString(),
const ProjectReader* project_reader = nullptr);

void updateThumbViewMinWidth();

void setupThumbView();

void showNewOpenProjectPanel();
Expand Down Expand Up @@ -297,7 +299,7 @@ class MainWindow : public QMainWindow, private FilterUiInterface, private Ui::Ma

void scaleThumbnails(const QWheelEvent* wheel_event);

void updateMaxLogicalThumbSize(const QSizeF& size);
void updateMaxLogicalThumbSize();

QSizeF m_maxLogicalThumbSize;
intrusive_ptr<ProjectPages> m_pages;
Expand Down Expand Up @@ -332,6 +334,8 @@ class MainWindow : public QMainWindow, private FilterUiInterface, private Ui::Ma
bool m_autoSaveProject;
std::unique_ptr<StatusBarPanel> m_statusBarPanel;
std::unique_ptr<QActionGroup> m_unitsMenuActionGroup;
QTimer m_maxLogicalThumbSizeUpdater;
QTimer m_sceneItemsPosUpdater;
};


Expand Down
2 changes: 1 addition & 1 deletion NewOpenProjectPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ NewOpenProjectPanel::NewOpenProjectPanel(QWidget* parent) : QWidget(parent) {

void NewOpenProjectPanel::addRecentProject(const QString& file_path) {
const QFileInfo file_info(file_path);
QString base_name(file_info.baseName());
QString base_name(file_info.completeBaseName());
if (base_name.isEmpty()) {
base_name = QChar('_');
}
Expand Down
9 changes: 0 additions & 9 deletions OrderByCompleteness.cpp

This file was deleted.

Loading

0 comments on commit 5e0068f

Please sign in to comment.