Skip to content

Commit

Permalink
Version 1.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
4lex4 committed Feb 18, 2018
2 parents 3d7449e + a5ee350 commit 76aa95e
Show file tree
Hide file tree
Showing 119 changed files with 2,915 additions and 1,158 deletions.
10 changes: 3 additions & 7 deletions AbstractFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <vector>

class FilterUiInterface;
class PageId;
class PageInfo;
class ProjectReader;
class ProjectWriter;
class AbstractRelinker;
Expand Down Expand Up @@ -60,17 +60,13 @@ class AbstractFilter : public ref_countable {

virtual void performRelinking(const AbstractRelinker& relinker) = 0;

virtual void preUpdateUI(FilterUiInterface* ui, const PageId& page_id) = 0;

virtual void updateStatistics() {
}
virtual void preUpdateUI(FilterUiInterface* ui, const PageInfo& page_info) = 0;

virtual QDomElement saveSettings(const ProjectWriter& writer, QDomDocument& doc) const = 0;

virtual void loadSettings(const ProjectReader& reader, const QDomElement& filters_el) = 0;

virtual void loadDefaultSettings(const PageId& page_id) {
};
virtual void loadDefaultSettings(const PageInfo& page_info) = 0;
};


Expand Down
4 changes: 2 additions & 2 deletions Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ void Application::initTranslations() {

const QStringList language_file_filter("scantailor_*.qm");
for (const QString& path : translation_dirs) {
QDir dir(path);
QDir dir(QDir::cleanPath(applicationDirPath() + '/' + path));
if (dir.exists()) {
QStringList translationFileNames = QDir(path).entryList(language_file_filter);
QStringList translationFileNames = QDir(dir.path()).entryList(language_file_filter);
for (const QString& fileName : translationFileNames) {
QString locale(fileName);
locale.truncate(locale.lastIndexOf('.'));
Expand Down
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -548,14 +548,16 @@ SET(
filter_dc/ContentBoxCollector.h
filter_dc/PageOrientationCollector.h
ImageViewInfoProvider.cpp ImageViewInfoProvider.h
ImageViewInfoObserver.cpp ImageViewInfoObserver.h
ImageViewInfoObserver.h
UnitsProvider.cpp UnitsProvider.h
UnitsObserver.h UnitsObserver.cpp
UnitsConverter.cpp UnitsConverter.h
Units.cpp Units.h
DefaultParams.cpp DefaultParams.h
DefaultParamsProfileManager.cpp DefaultParamsProfileManager.h
DefaultParamsProvider.cpp DefaultParamsProvider.h
DeviationProvider.h
OrderByDeviationProvider.cpp OrderByDeviationProvider.h
version.h
config.h.in
${common_ui_files})
Expand All @@ -582,7 +584,8 @@ SET(
MainWindow.cpp MainWindow.h
main.cpp
StatusBarPanel.cpp StatusBarPanel.h
DefaultParamsDialog.cpp DefaultParamsDialog.h)
DefaultParamsDialog.cpp DefaultParamsDialog.h
CollapsibleGroupBox.cpp CollapsibleGroupBox.h)

SET(
cli_only_sources
Expand Down
217 changes: 217 additions & 0 deletions CollapsibleGroupBox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@

#include "CollapsibleGroupBox.h"
#include <QSettings>
#include <QtCore/QEvent>
#include <QtGui/QShowEvent>
#include <foundation/ScopedIncDec.h>

CollapsibleGroupBox::CollapsibleGroupBox(QWidget* parent)
: QGroupBox(parent) {
initialize();
}

CollapsibleGroupBox::CollapsibleGroupBox(const QString& title, QWidget* parent)
: QGroupBox(title, parent) {
initialize();
}

void CollapsibleGroupBox::initialize() {
collapseIcon.addPixmap(
QPixmap(QString::fromLatin1(":/icons/minus-16.png"))
);
expandIcon.addPixmap(
QPixmap(QString::fromLatin1(":/icons/plus-16.png"))
);
collapseButton = new QToolButton(this);
collapseButton->setObjectName("collapseButton");
collapseButton->setAutoRaise(true);
collapseButton->setFixedSize(14, 14);
collapseButton->setIconSize(QSize(12, 12));
collapseButton->setIcon(collapseIcon);
setFocusProxy(collapseButton);
setFocusPolicy(Qt::StrongFocus);

connect(collapseButton, &QAbstractButton::clicked, this, &CollapsibleGroupBox::toggleCollapsed);
connect(this, &QGroupBox::toggled, this, &CollapsibleGroupBox::checkToggled);
connect(this, &QGroupBox::clicked, this, &CollapsibleGroupBox::checkClicked);
}

void CollapsibleGroupBox::setCollapsed(const bool collapse) {
const bool changed = (collapse != collapsed);

if (changed) {
collapsed = collapse;
collapseButton->setIcon(collapse ? expandIcon : collapseIcon);

updateWidgets();

emit collapsedStateChanged(isCollapsed());
}
}

bool CollapsibleGroupBox::isCollapsed() const {
return collapsed;
}

void CollapsibleGroupBox::checkToggled(bool) {
collapseButton->setEnabled(true);
}

void CollapsibleGroupBox::checkClicked(bool checked) {
if (checked && isCollapsed()) {
setCollapsed(false);
} else if (!checked && !isCollapsed()) {
setCollapsed(true);
}
}

void CollapsibleGroupBox::toggleCollapsed() {
// verify if sender is this group box's collapse button
auto* sender = dynamic_cast<QToolButton*>(QObject::sender());
const bool isSenderCollapseButton = (sender && (sender == collapseButton));

if (isSenderCollapseButton) {
setCollapsed(!isCollapsed());
}
}

void CollapsibleGroupBox::updateWidgets() {
const ScopedIncDec<int> guard(ignoreVisibilityEvents);

if (collapsed) {
for (QObject* child : children()) {
auto* widget = dynamic_cast<QWidget*>(child);
if (widget && (widget != collapseButton) && widget->isVisible()) {
collapsedWidgets.insert(widget);
widget->hide();
}
}
} else {
for (QObject* child : children()) {
auto* widget = dynamic_cast<QWidget*>(child);
if (widget && (widget != collapseButton) && (collapsedWidgets.find(widget) != collapsedWidgets.end())) {
collapsedWidgets.erase(widget);
widget->show();
}
}
}
}

void CollapsibleGroupBox::showEvent(QShowEvent* event) {
// initialize widget on first show event only
if (shown) {
event->accept();
return;
}
shown = true;

loadState();

QWidget::showEvent(event);
}

void CollapsibleGroupBox::changeEvent(QEvent* event) {
QGroupBox::changeEvent(event);

if ((event->type() == QEvent::EnabledChange) && isEnabled()) {
collapseButton->setEnabled(true);
}
}

void CollapsibleGroupBox::childEvent(QChildEvent* event) {
auto* childWidget = dynamic_cast<QWidget*>(event->child());
if (childWidget && (event)->type() == QEvent::ChildAdded) {
if (collapsed) {
if (childWidget->isVisible()) {
collapsedWidgets.insert(childWidget);
childWidget->hide();
}
}

childWidget->installEventFilter(this);
}

QGroupBox::childEvent(event);
}

bool CollapsibleGroupBox::eventFilter(QObject* watched, QEvent* event) {
if (collapsed && !ignoreVisibilityEvents) {
auto* childWidget = dynamic_cast<QWidget*>(watched);
if (childWidget) {
if (event->type() == QEvent::ShowToParent) {
const ScopedIncDec<int> guard(ignoreVisibilityEvents);

collapsedWidgets.insert(childWidget);
childWidget->hide();
} else if (event->type() == QEvent::HideToParent) {
collapsedWidgets.erase(childWidget);
}
}
}

return QObject::eventFilter(watched, event);
}

CollapsibleGroupBox::~CollapsibleGroupBox() {
saveState();
}

void CollapsibleGroupBox::loadState() {
if (!isEnabled()) {
return;
}

const QString key = getSettingsKey();
if (key.isEmpty()) {
return;
}

setUpdatesEnabled(false);

QSettings settings;

if (isCheckable()) {
QVariant val = settings.value(key + "/checked");
if (!val.isNull()) {
setChecked(val.toBool());
}
}

{
QVariant val = settings.value(key + "/collapsed");
if (!val.isNull()) {
setCollapsed(val.toBool());
}
}

setUpdatesEnabled(true);
}

void CollapsibleGroupBox::saveState() {
if (!shown || !isEnabled()) {
return;
}

const QString key = getSettingsKey();
if (key.isEmpty()) {
return;
}

QSettings settings;

if (isCheckable()) {
settings.setValue(key + "/checked", isChecked());
}
settings.setValue(key + "/collapsed", isCollapsed());
}

QString CollapsibleGroupBox::getSettingsKey() const {
if (objectName().isEmpty()) {
return QString();
}

QString saveKey = '/' + objectName();
saveKey = "CollapsibleGroupBox" + saveKey;
return saveKey;
}

83 changes: 83 additions & 0 deletions CollapsibleGroupBox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

#ifndef SCANTAILOR_COLLAPSIBLEGROUPBOX_H
#define SCANTAILOR_COLLAPSIBLEGROUPBOX_H


#include <QtWidgets/QToolButton>
#include <QtWidgets/QGroupBox>
#include <unordered_set>

class CollapsibleGroupBox : public QGroupBox {
Q_OBJECT

/**
* The collapsed state of this group box. If it is set to true, all content is hidden
* if it is set to false all content is shown.
*/
Q_PROPERTY(bool collapsed READ isCollapsed WRITE setCollapsed USER true)

public:
explicit CollapsibleGroupBox(QWidget* parent = nullptr);

explicit CollapsibleGroupBox(const QString& title, QWidget* parent = nullptr);

~CollapsibleGroupBox() override;

/**
* Returns the current collapsed state of this group box.
*/
bool isCollapsed() const;

/**
* Collapse or expand this group box.
*
* \param collapse Will collapse on true and expand on false
*/
void setCollapsed(bool collapse);

signals:

/** Signal emitted when the group box collapsed/expanded state is changed, and when first shown */
void collapsedStateChanged(bool collapsed);

public slots:

void checkToggled(bool);

void checkClicked(bool checked);

void toggleCollapsed();

protected:
void updateWidgets();

void showEvent(QShowEvent* event) override;

void changeEvent(QEvent* event) override;

void childEvent(QChildEvent *event) override;

bool eventFilter(QObject* watched, QEvent* event) override;

void initialize();

void loadState();

void saveState();

QString getSettingsKey() const;

private:
bool collapsed = false;
bool shown = false;
QToolButton* collapseButton = nullptr;

QIcon collapseIcon;
QIcon expandIcon;

int ignoreVisibilityEvents = 0;
std::unordered_set<QWidget*> collapsedWidgets;
};


#endif //SCANTAILOR_COLLAPSIBLEGROUPBOX_H
Loading

0 comments on commit 76aa95e

Please sign in to comment.