Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create constant padding page layout option #5270

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/core/control/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ void Control::initWindow(MainWindow* win) {
setViewColumns(settings->getViewColumns());
}

setViewLayoutType(settings->getViewLayoutType());
setViewLayoutVert(settings->getViewLayoutVert());
setViewLayoutR2L(settings->getViewLayoutR2L());
setViewLayoutB2T(settings->getViewLayoutB2T());
Expand Down Expand Up @@ -907,6 +908,7 @@ void Control::setViewPresentationMode(bool enabled) {
setViewColumns(settings->getViewColumns());
}

setViewLayoutType(settings->getViewLayoutType());
setViewLayoutVert(settings->getViewLayoutVert());
setViewLayoutR2L(settings->getViewLayoutR2L());
setViewLayoutB2T(settings->getViewLayoutB2T());
Expand Down Expand Up @@ -956,6 +958,12 @@ void Control::setViewRows(int numRows) {
scrollHandler->scrollToPage(getCurrentPageNo());
}

void Control::setViewLayoutType(LayoutType type) {
settings->setViewLayoutType(type);
win->getXournal()->layoutPages();
scrollHandler->scrollToPage(getCurrentPageNo());
}

void Control::setViewLayoutVert(bool vert) {
settings->setViewLayoutVert(vert);
win->getXournal()->layoutPages();
Expand Down
22 changes: 12 additions & 10 deletions src/core/control/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
#include <glib.h> // for guint
#include <gtk/gtk.h> // for GtkLabel

#include "control/ToolEnums.h" // for ToolSize, ToolType
#include "control/jobs/ProgressListener.h" // for ProgressListener
#include "control/settings/ViewModes.h" // for ViewModeId
#include "control/tools/EditSelection.h" // for OrderChange
#include "enums/Action.enum.h" // for Action
#include "model/DocumentHandler.h" // for DocumentHandler
#include "model/DocumentListener.h" // for DocumentListener
#include "model/GeometryTool.h" // for GeometryTool
#include "model/PageRef.h" // for PageRef
#include "undo/UndoRedoHandler.h" // for UndoRedoHandler (ptr only)
#include "control/ToolEnums.h" // for ToolSize, ToolType
#include "control/jobs/ProgressListener.h" // for ProgressListener
#include "control/settings/SettingsEnums.h" // for LayoutType
#include "control/settings/ViewModes.h" // for ViewModeId
#include "control/tools/EditSelection.h" // for OrderChange
#include "enums/Action.enum.h" // for Action
#include "model/DocumentHandler.h" // for DocumentHandler
#include "model/DocumentListener.h" // for DocumentListener
#include "model/GeometryTool.h" // for GeometryTool
#include "model/PageRef.h" // for PageRef
#include "undo/UndoRedoHandler.h" // for UndoRedoHandler (ptr only)

#include "ClipboardHandler.h" // for ClipboardListener
#include "ToolHandler.h" // for ToolListener
Expand Down Expand Up @@ -166,6 +167,7 @@ class Control:
void setPairsOffset(int numOffset);
void setViewColumns(int numColumns);
void setViewRows(int numRows);
void setViewLayoutType(LayoutType type);
void setViewLayoutVert(bool vert);
void setViewLayoutR2L(bool r2l);
void setViewLayoutB2T(bool b2t);
Expand Down
12 changes: 12 additions & 0 deletions src/core/control/actions/ActionProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,18 @@ struct ActionProperties<Action::SHOW_TOOLBAR> {
static void callback(GSimpleAction*, GVariant* p, Control* ctrl) { ctrl->setShowToolbar(g_variant_get_boolean(p)); }
};

template <>
struct ActionProperties<Action::SET_LAYOUT_TYPE> {
using state_type = LayoutType;
using parameter_type = state_type;
static state_type initialState(Control* ctrl) { return ctrl->getSettings()->getViewLayoutType(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
LayoutType type = getGVariantValue<LayoutType>(p);
ctrl->setViewLayoutType(type);
}
};

template <>
struct ActionProperties<Action::SET_LAYOUT_VERTICAL> {
using state_type = bool;
Expand Down
16 changes: 16 additions & 0 deletions src/core/control/settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void Settings::loadDefault() {
this->numRows = 1;
this->viewFixedRows = false;

this->layoutType = LAYOUT_TYPE_GRID;
this->layoutVertical = false;
this->layoutRightToLeft = false;
this->layoutBottomToTop = false;
Expand Down Expand Up @@ -441,6 +442,8 @@ void Settings::parseItem(xmlDocPtr doc, xmlNodePtr cur) {
this->numRows = g_ascii_strtoll(reinterpret_cast<const char*>(value), nullptr, 10);
} else if (xmlStrcmp(name, reinterpret_cast<const xmlChar*>("viewFixedRows")) == 0) {
this->viewFixedRows = xmlStrcmp(value, reinterpret_cast<const xmlChar*>("true")) == 0;
} else if (xmlStrcmp(name, reinterpret_cast<const xmlChar*>("layoutType")) == 0) {
this->layoutType = layoutTypeFromString(reinterpret_cast<const char*>(value));
} else if (xmlStrcmp(name, reinterpret_cast<const xmlChar*>("layoutVertical")) == 0) {
this->layoutVertical = xmlStrcmp(value, reinterpret_cast<const xmlChar*>("true")) == 0;
} else if (xmlStrcmp(name, reinterpret_cast<const xmlChar*>("layoutRightToLeft")) == 0) {
Expand Down Expand Up @@ -1000,6 +1003,8 @@ void Settings::save() {
SAVE_INT_PROP(numRows);
SAVE_BOOL_PROP(viewFixedRows);
SAVE_BOOL_PROP(showPairedPages);
xmlNode = saveProperty("layoutType", LayoutTypeToString(this->layoutType), root);
ATTACH_COMMENT("The page layout type, allowed values are \"grid\", \"constantPadding\"");
SAVE_BOOL_PROP(layoutVertical);
SAVE_BOOL_PROP(layoutRightToLeft);
SAVE_BOOL_PROP(layoutBottomToTop);
Expand Down Expand Up @@ -1829,6 +1834,17 @@ void Settings::setViewFixedRows(bool viewFixedRows) {

auto Settings::isViewFixedRows() const -> bool { return this->viewFixedRows; }

void Settings::setViewLayoutType(LayoutType type) {
if (this->layoutType == type) {
return;
}

this->layoutType = type;
save();
}

auto Settings::getViewLayoutType() const -> LayoutType { return this->layoutType; }

void Settings::setViewLayoutVert(bool vert) {
if (this->layoutVertical == vert) {
return;
Expand Down
10 changes: 9 additions & 1 deletion src/core/control/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "util/Color.h" // for Color

#include "LatexSettings.h" // for LatexSettings
#include "SettingsEnums.h" // for InputDeviceTypeOption
#include "SettingsEnums.h" // for InputDeviceTypeOption, LayoutType
#include "ViewModes.h" // for ViewModes
#include "filesystem.h" // for path

Expand Down Expand Up @@ -259,6 +259,9 @@ class Settings {
void setViewFixedRows(bool viewFixedRows);
bool isViewFixedRows() const;

void setViewLayoutType(LayoutType type);
LayoutType getViewLayoutType() const;

void setViewLayoutVert(bool vert);
bool getViewLayoutVert() const;

Expand Down Expand Up @@ -845,6 +848,11 @@ class Settings {
*/
bool viewFixedRows{};

/**
* Layout as grid or with constant padding
*/
LayoutType layoutType;

/**
* Layout Vertical then Horizontal
*/
Expand Down
11 changes: 11 additions & 0 deletions src/core/control/settings/SettingsEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ auto iconThemeFromString(const std::string& iconThemeStr) -> IconTheme {
return ICON_THEME_COLOR;
}

auto layoutTypeFromString(const std::string& layoutTypeStr) -> LayoutType {
if (layoutTypeStr == "grid") {
return LAYOUT_TYPE_GRID;
}
if (layoutTypeStr == "constantPadding") {
return LAYOUT_TYPE_CONST_PADDING;
}
g_warning("Settings::Unknown layout type: %s\n", layoutTypeStr.c_str());
return LAYOUT_TYPE_GRID;
}

auto emptyLastPageAppendFromString(const std::string& str) -> EmptyLastPageAppendType {
if (str == "disabled") {
return EmptyLastPageAppendType::Disabled;
Expand Down
17 changes: 17 additions & 0 deletions src/core/control/settings/SettingsEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ enum IconTheme {
ICON_THEME_LUCIDE = 1,
};

enum LayoutType {
LAYOUT_TYPE_GRID = 0,
LAYOUT_TYPE_CONST_PADDING = 1,
};

Comment on lines +87 to +91
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hesitated between creating a custom enumeration and defining the setting as a simple bool layoutConstPadding or something. I'm also not really sure the enum declaration is in the right place here

/**
* The user-selectable Page Preview Decoration style
*/
Expand Down Expand Up @@ -165,6 +170,17 @@ constexpr auto iconThemeToString(IconTheme iconTheme) -> const char* {
}
}

constexpr auto LayoutTypeToString(LayoutType layoutType) -> const char* {
switch (layoutType) {
case LAYOUT_TYPE_GRID:
return "grid";
case LAYOUT_TYPE_CONST_PADDING:
return "constantPadding";
default:
return "unknown";
}
}

constexpr auto emptyLastPageAppendToString(EmptyLastPageAppendType appendType) -> const char* {
switch (appendType) {
case EmptyLastPageAppendType::Disabled:
Expand All @@ -181,4 +197,5 @@ constexpr auto emptyLastPageAppendToString(EmptyLastPageAppendType appendType) -
StylusCursorType stylusCursorTypeFromString(const std::string& stylusCursorTypeStr);
EraserVisibility eraserVisibilityFromString(const std::string& eraserVisibilityStr);
IconTheme iconThemeFromString(const std::string& iconThemeStr);
LayoutType layoutTypeFromString(const std::string& layoutTypeStr);
EmptyLastPageAppendType emptyLastPageAppendFromString(const std::string& str);
1 change: 1 addition & 0 deletions src/core/enums/Action.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ enum class Action : size_t {
FULLSCREEN,
SHOW_SIDEBAR,
SHOW_TOOLBAR,
SET_LAYOUT_TYPE,
SET_LAYOUT_VERTICAL,
SET_LAYOUT_RIGHT_TO_LEFT,
SET_LAYOUT_BOTTOM_TO_TOP,
Expand Down
3 changes: 2 additions & 1 deletion src/core/enums/generated/Action.NameMap.generated.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ** THIS FILE IS GENERATED **
// ** use generateConvertNEW.php to update this file **
// ** use generateConvert.php to update this file **


#pragma once
Expand Down Expand Up @@ -34,6 +34,7 @@ constexpr const char* ACTION_NAMES[] = { // Action to string conversion map
"fullscreen",
"show-sidebar",
"show-toolbar",
"set-layout-type",
"set-layout-vertical",
"set-layout-right-to-left",
"set-layout-bottom-to-top",
Expand Down
Loading