id
int64 0
755k
| file_name
stringlengths 3
109
| file_path
stringlengths 13
185
| content
stringlengths 31
9.38M
| size
int64 31
9.38M
| language
stringclasses 1
value | extension
stringclasses 11
values | total_lines
int64 1
340k
| avg_line_length
float64 2.18
149k
| max_line_length
int64 7
2.22M
| alphanum_fraction
float64 0
1
| repo_name
stringlengths 6
65
| repo_stars
int64 100
47.3k
| repo_forks
int64 0
12k
| repo_open_issues
int64 0
3.4k
| repo_license
stringclasses 9
values | repo_extraction_date
stringclasses 92
values | exact_duplicates_redpajama
bool 2
classes | near_duplicates_redpajama
bool 2
classes | exact_duplicates_githubcode
bool 2
classes | exact_duplicates_stackv2
bool 1
class | exact_duplicates_stackv1
bool 2
classes | near_duplicates_githubcode
bool 2
classes | near_duplicates_stackv1
bool 2
classes | near_duplicates_stackv2
bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
12,835
|
CompassController.h
|
xournalpp_xournalpp/src/core/control/CompassController.h
|
/*
* Xournal++
*
* A compass controller
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <gtk/gtk.h>
#include "gui/PageView.h"
#include "model/GeometryTool.h"
#include "util/Point.h"
#include "GeometryToolController.h"
class Compass;
class Stroke;
/**
* @brief A class that controls a compass
* The compass can be moved, rotated and scaled
* There are methods for translating coordinates
* and methods to deal with the temporary stroke
* that is displayed near the the outline of the
* compass or the marked radius.
*/
class CompassController: public GeometryToolController {
public:
CompassController(XojPageView* view, Compass* compass);
~CompassController() override;
public:
GeometryToolType getType() const override;
/**
* @brief returns the position of a point relative to a coordinate system, in which the
* positive x-axis coincides with the distinguished compass axis and the origin lies
* in the center of the compass
* @param x the x-coordinate of the point (in document coordinates)
* @param y the y-coordinate of the point (in document coordinates)
*/
xoj::util::Point<double> posRelToSide(double x, double y) const;
/**
* @brief checks whether a point with given coordinates lies in the geometry tool with an additional
* border enlarging (or shrinked) it
* @param x the x-coordinate of the given point (in document coordinates)
* @param y the y-coordinate of the given point (in document coordinates)
* @param border the size of the border (if negative, the geometry tool is shrinked via the border)
*/
bool isInsideGeometryTool(double x, double y, double border = 0.0) const override;
/**
* @brief the point (in document coordinates) for a given angle on the outline of the compass
* @param a the angle with respect to the distinguished compass axis of the point
*/
xoj::util::Point<double> getPointForAngle(double a) const;
/**
* @brief the point (in document coordinates) for a given radius on the marked radius of the compass
* @param r the x-coordinate with respect to a coordinate system, in which the positive x-axis
* coincides with the marked radius and the origin lies in the center of the compass
*/
xoj::util::Point<double> getPointForRadius(double r) const;
/**
* @brief creates a stroke starting at the given angle of the outline of the compass
* @param a the angle of the point on the outline of the compass (when unrotated and untranslated)
*/
void createOutlineStroke(double a);
/**
* @brief updates the stroke near the outline of the compass
* @param a the angle of the point on the outline of the compass (when unrotated and untranslated)
* updating the stroke
*/
void updateOutlineStroke(double a);
/**
* @brief finishes the stroke near the outline of the compass
*/
void finalizeOutlineStroke();
/**
* @brief finishes the stroke aligned to the marked radius of the compass
*/
void finalizeRadialStroke();
/**
* @brief creates a stroke starting at the given point of the marked radius of the compass
* @param x the x-coordinate with respect to the marked radius
*/
void createRadialStroke(double x);
/**
* @brief updates the stroke near the marked radius of the compass
* @param x the x-coordinate with respect to the marked radius
*/
void updateRadialStroke(double x);
/**
* checks whether a stroke near the outline already exists
*/
bool existsOutlineStroke();
/**
* checks whether a radius already exists
*/
bool existsRadialStroke();
private:
/**
* @brief when a stroke near the radius with the measuring marks
* is drawn, the minimal and maximal radii are saved in
* the variables radiusMax and radiusMin
*
*/
double radiusMax = std::numeric_limits<double>::lowest();
double radiusMin = std::numeric_limits<double>::max();
/**
* @brief when a stroke near the outline of the compass is drawn, the minimal and maximal
* angles of the point to be drawn (with respect to an unrotated, and untranslated coordinate system)
* are saved in the variables angleMin and angleMax
*/
double angleMax = std::numeric_limits<double>::lowest();
double angleMin = std::numeric_limits<double>::max();
};
| 4,517
|
C++
|
.h
| 113
| 35.292035
| 105
| 0.710568
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,836
|
XournalMain.h
|
xournalpp_xournalpp/src/core/control/XournalMain.h
|
/*
* Xournal++
*
* Xournal main entry, commandline parser
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
namespace XournalMain {
auto run(int argc, char** argv) -> int;
}
| 254
|
C++
|
.h
| 14
| 16.142857
| 41
| 0.706383
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,837
|
ToolBase.h
|
xournalpp_xournalpp/src/core/control/ToolBase.h
|
/*
* Xournal++
*
* Base class for a tool, which contains the tool configuration,
* this is also used for other classes, e.g. to store current tool configuration
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include "model/LineStyle.h" // for LineStyle
#include "util/Color.h" // for Color
#include "ToolEnums.h" // for DrawingType, EraserType, ToolSize, DRAW...
class ToolBase {
public:
ToolBase();
virtual ~ToolBase();
private:
void operator=(const ToolBase& t);
ToolBase(const ToolBase& t);
public:
/**
* @return Color of the tool for all drawing tools
*/
Color getColor() const;
/**
* @param color Color of the tool for all drawing tools
*/
virtual void setColor(Color color);
/**
* @return Size of a drawing tool
*/
ToolSize getSize() const;
/**
* @param size Size of a drawing tool
*/
void setSize(ToolSize size);
/**
* @return Draw special shape
*/
DrawingType getDrawingType() const;
/**
* @param drawingType Draw special shape
*/
void setDrawingType(DrawingType drawingType);
/**
* @brief Get the Eraser Type object
*
* @return EraserType
*/
EraserType getEraserType() const;
/**
* @brief Set the Eraser Type object
*
* @param eraserType
*/
void setEraserType(EraserType eraserType);
/**
* @return Fill of the shape is enabled
*/
bool getFill() const;
/**
* @param fill Fill of the shape is enabled
*/
void setFill(bool fill);
/**
* @return Alpha for fill
*/
int getFillAlpha() const;
/**
* @param fillAlpha Alpha for fill
*/
void setFillAlpha(int fillAlpha);
/**
* @return Style of the line drawing
*/
const LineStyle& getLineStyle() const;
/**
* @param style Style of the line drawing
*/
void setLineStyle(const LineStyle& style);
private:
/**
* Color of the tool for all drawing tools
*/
Color color = Colors::black;
/**
* Size of a drawing tool
*/
ToolSize size = TOOL_SIZE_MEDIUM;
/**
* Draw special shape
*/
DrawingType drawingType = DRAWING_TYPE_DEFAULT;
/**
* Eraser type
*/
EraserType eraserType = ERASER_TYPE_DEFAULT;
/**
* Fill of the shape is enabled
*/
bool fill = false;
/**
* Alpha for fill
*/
int fillAlpha = 128;
/**
* Style of the line drawing
*/
LineStyle lineStyle;
};
| 2,627
|
C++
|
.h
| 113
| 18.256637
| 80
| 0.615601
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,838
|
AudioController.h
|
xournalpp_xournalpp/src/core/control/AudioController.h
|
/*
* Xournal++
*
* Audio Recording / Playing controller
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cstddef> // for size_t
#include <memory> // for make_unique, unique_ptr
#include <vector> // for vector
#include <portaudiocpp/PortAudioCpp.hxx> // for AutoSystem
#include "filesystem.h" // for path
class AudioPlayer;
class AudioRecorder;
class Control;
class DeviceInfo;
class Settings;
class AudioController final {
public:
// Todo convert Pointers to reference (changes to control.cpp are necessary)
AudioController(Settings* settings, Control* control);
~AudioController();
bool startRecording();
bool stopRecording();
bool isRecording();
bool isPlaying();
bool startPlayback(fs::path const& file, unsigned int timestamp);
void pausePlayback();
void continuePlayback();
void stopPlayback();
void seekForwards();
void seekBackwards();
fs::path const& getAudioFilename() const;
fs::path getAudioFolder() const;
size_t getStartTime() const;
std::vector<DeviceInfo> getOutputDevices() const;
std::vector<DeviceInfo> getInputDevices() const;
private:
Settings& settings;
Control& control;
/**
* RAII initializer don't move below the portaudio::System::instance() calls in
* AudioRecorder and AudioPlayer
* */
portaudio::AutoSystem autoSys;
std::unique_ptr<AudioRecorder> audioRecorder;
std::unique_ptr<AudioPlayer> audioPlayer;
fs::path audioFilename;
size_t timestamp = 0;
};
| 1,605
|
C++
|
.h
| 54
| 26.12963
| 83
| 0.722547
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,839
|
ToolHandler.h
|
xournalpp_xournalpp/src/core/control/ToolHandler.h
|
/*
* Xournal++
*
* Handles Tools
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <array> // for array
#include <functional> // for function
#include <memory> // for unique_ptr
#include <vector> // for vector
#include "control/ToolEnums.h" // for ToolSize, ToolType, Draw...
#include "control/settings/SettingsEnums.h" // for Button
#include "util/Color.h" // for Color
#include "Tool.h" // for Tool
class LineStyle;
class Settings;
class ActionDatabase;
// enum for ptrs that are dynamically pointing to different tools
/**
* @brief Enum for ptrs that are dynamically pointing to different tools
* - active: describes the currently active tool used for drawing
* - toolbar: describes the tool currently selected in the toolbar
*
* These tools are to be distinguished from ButtonTools which are mostly static
* apart from changes to the Config
*
*/
enum SelectedTool { active, toolbar };
class ToolListener {
public:
/**
* @brief Update the Cursor and the Toolbar based on the active color
*
*/
virtual void toolColorChanged() = 0;
/**
* @brief Change the color of the current selection based on the active Tool
*
*/
virtual void changeColorOfSelection() = 0;
virtual void toolSizeChanged() = 0;
virtual void toolFillChanged() = 0;
virtual void toolLineStyleChanged() = 0;
virtual void toolChanged() = 0;
virtual ~ToolListener();
};
class ToolHandler {
public:
using ToolChangedCallback = std::function<void(ToolType)>;
ToolHandler(ToolListener* stateChangedListener, ActionDatabase* actionDB, Settings* settings);
virtual ~ToolHandler();
/**
* @brief Reset the Button tool with a new tooltype
*
* @param type Tooltype to be set for the button
* @param button button which should be set
*/
void resetButtonTool(ToolType type, Button button);
/**
* Select the color for the active tool and under certain circumstances toolbar selected tool
*
* If the current tool does not have the color capability but the toolbar selected tool has
* the color can be set for the toolbar selected tool.
* This is indicated by a little pen shown on top of the color in the UI.
*
* @param color Color
* @param userSelection
* true if the user selected the color
* false if the color is selected by a tool change
* and therefore should not be applied to a selection
*/
void setColor(Color color, bool userSelection);
/**
* @brief Set the color for a Button
* This is a separate function from `setColor` to prevent mixup of different usecases.
*
* @param color color to be set
* @param button button to set color for
*/
void setButtonColor(Color color, Button button);
/**
* @brief Get the Color of the active tool
*
* @return Color of active tool
*/
Color getColor() const;
/**
* @brief Get the Color of the active tool except the alpha value is replaced by 0xFF
*/
Color getColorMaskAlpha() const;
/**
* @brief Enable/disable fill for the tool selected in the toolbar
*
* @param fill whether fill should be enabled
* @param fireEvent whether a toolFillChanged event should be fired
*/
void setFillEnabled(bool fill);
/**
* @brief Get the Fill of the active tool
*
* @return -1 if fill is disabled
* @return int > 0 otherwise
*/
int getFill() const;
/**
* @brief Get the Drawing Type one of selected tools
*
* @param selectedTool by the default the active one
* @return DrawingType
*/
DrawingType getDrawingType(SelectedTool selectedTool = SelectedTool::active) const;
/**
* @brief Set the Drawing Type of the toolbar selected tool
* @note It is safer to always set the toolbar tool as the active tool could be pointing to a button tool which
* could lead to hard to debug behaviour
*
* @param drawingType
*/
void setDrawingType(DrawingType drawingType);
/**
* @brief Set the Button Drawing Type of the button tool
*
* @param drawingType
* @param button button tool to be selected
*/
void setButtonDrawingType(DrawingType drawingType, Button button);
/**
* @brief Set the Stroke Type of a button tool
*
* @param strokeType The stroke type to apply
* @param button The button tool to change
*/
void setButtonStrokeType(StrokeType strokeType, Button button);
void setButtonStrokeType(const LineStyle& lineStyle, Button button);
/**
* @brief Get the Line Style of active tool
*
* @return const LineStyle&
*/
const LineStyle& getLineStyle() const;
/**
* @brief Get the Size of one of the selected tools
*
* @param selectedTool
* @return ToolSize
*/
ToolSize getSize(SelectedTool selectedTool = SelectedTool::active) const;
/**
* @brief Set the Size of toolbar selected tool
* @note It is safer to always set the toolbar tool as the active tool could be pointing to a button tool which
* could lead to hard to debug behaviour
*
* @param size is clamped to be within the defined range [0,5)
*/
void setSize(ToolSize size);
/**
* @brief Set the Button Size
*
* @param size is clamped to be within the defined range [0,5)
* @param button size will be applied to
*/
void setButtonSize(ToolSize size, Button button);
/**
* @brief Get the Thickness of the active tool
*
* @return double
*/
double getThickness() const;
void setLineStyle(const LineStyle& style);
ToolSize getPenSize() const;
ToolSize getEraserSize() const;
ToolSize getHighlighterSize() const;
void setPenSize(ToolSize size);
void setEraserSize(ToolSize size);
void setHighlighterSize(ToolSize size);
void setPenFillEnabled(bool fill);
bool getPenFillEnabled() const;
void setPenFill(int alpha);
int getPenFill() const;
void setHighlighterFillEnabled(bool fill);
bool getHighlighterFillEnabled() const;
void setHighlighterFill(int alpha);
int getHighlighterFill() const;
void setSelectPDFTextMarkerOpacity(int alpha);
int getSelectPDFTextMarkerOpacity() const;
/**
* @brief Set the toolbar selected tool to the type
* This will also point the active tool to the same tool as the toolbar selected tool.
* This ensure that the toolbar and the cursor are correctly updated right after selecting the tool in the toolbar.
*
* @param type
*/
void selectTool(ToolType type);
/**
* @brief Get the Tool Type of active tool
*
* @return ToolType
*/
ToolType getToolType() const;
/**
* @brief Update the Toolbar and the cursor based on the active Tool
*
*/
void fireToolChanged() const;
/**
* @brief Listen for tool changes.
*
* Different from the listener given to the constructor -- [listener]
* here only listens for when the current tool is changed to another.
*
* @param listener A callback, called when the user/client
* changes tools.
*/
void addToolChangedListener(ToolChangedCallback listener);
/**
* @brief Get the Tool of a certain type
*
* @param type
* @return Tool&
*/
Tool& getTool(ToolType type) const;
/**
* @brief Get the active Tool, returns nullptr if no tool is active
*
* @return Tool*
*/
Tool* getActiveTool() const;
/**
* @brief Set the Eraser Type of the Eraser in the toolbar
* @note Here the Eraser Tool in the toolbar is changed regardless of the the tool currently selected.
* This is necessary to allow users to change the Eraser type for their Button Tools while having another tool
* active. This is relevant in case of Eraser Type being set to "Don't Change" for the button.
*
* @param eraserType
*/
void setEraserType(EraserType eraserType);
/**
* @brief Set the Button Eraser Type
*
* @param eraserType
* @param button
*/
void setButtonEraserType(EraserType eraserType, Button button);
/**
* @brief Get the Eraser Type
* If the currently active Tool is an eraser it's type is returned (relevant for Buttontools).
* If the currently active Tool is not a eraser the erasertype of the eraser in the toolbar is obtained.
*
* @param selectedTool
* @return EraserType
*/
EraserType getEraserType() const;
/**
* @brief Update the toolbar based on the Eraser type of the active tool
*
*/
void eraserTypeChanged();
/**
* @brief Check whether the selectedTool has a certain capability
*
* @param cap
* @param selectedTool
* @return true if tool has the capability
* @return false if tool does not have the capability
*/
bool hasCapability(ToolCapabilities cap, SelectedTool selectedTool = SelectedTool::active) const;
/**
* @brief Check whether the active tool is a Drawing tool.
* Drawing tools are considered all tools that directly change the canvas.
* Right now these are:
* - Highlighter
* - Pen
* - Eraser
*
* @return true if active tool is a drawing tool
* @return false if active tool is no drawing tool
*/
bool isDrawingTool() const;
void saveSettings() const;
void loadSettings();
/**
* @brief Point the active tool to the corresponding button tool if it is not already pointing to it
*
* @param button Button tool which should be pointed to
* @return true if the active toolpointer was changed
* @return false if the active toolpointer was not changed (it was already pointing to the right button)
*/
bool pointActiveToolToButtonTool(Button button);
/**
* @brief Point the active tool to tool selected in the toolbar
*
* @return true if the active toolpointer was changed
* @return false if the active toolpointer was not changed (it was already pointing to the toolbar-tool)
*/
bool pointActiveToolToToolbarTool();
[[maybe_unused]] std::array<std::unique_ptr<Tool>, TOOL_COUNT> const& getTools() const;
/**
* Change the selection tools capabilities, depending on the selected elements
*/
void setSelectionEditTools(bool setColor, bool setSize, bool setFill, bool setLineStyle);
const double* getToolThickness(ToolType type) const;
/**
* Returns whether the current tool will create an element that may only reside on a single page even when the
* pointer moves to another
* @return
*/
bool isSinglePageTool() const;
/**
* Returns whether the current tool accepts events from outside the page input started in (i.e. events
* should not be clamped to the page)
*/
bool acceptsOutOfPageEvents() const;
/**
* @brief Whether the tool supports short taps filtering (for floating toolbox or selection)
* see Preferences->Drawing Area->Action on Tool tap
*/
bool supportsTapFilter() const;
protected:
void initTools();
private:
std::array<std::unique_ptr<Tool>, TOOL_COUNT> tools;
/**
* @brief Get the Button Tool pointer based on enum
*
* @param button
* @return Tool*
*/
Tool* getButtonTool(Button button) const;
/**
* @brief Get the Selected Tool pointer based on enum
*
* @param selectedTool
* @return Tool*
*/
Tool* getSelectedTool(SelectedTool selectedTool) const;
// active Tool which is used for drawing
Tool* activeTool = nullptr;
// tool which is selected in the toolbar
Tool* toolbarSelectedTool = nullptr;
// tools set for the different Buttons
std::unique_ptr<Tool> stylusButton1Tool;
std::unique_ptr<Tool> stylusButton2Tool;
std::unique_ptr<Tool> eraserButtonTool;
std::unique_ptr<Tool> mouseMiddleButtonTool;
std::unique_ptr<Tool> mouseRightButtonTool;
std::unique_ptr<Tool> touchDrawingButtonTool;
std::vector<ToolChangedCallback> toolChangeListeners;
ToolListener* stateChangeListener = nullptr;
ActionDatabase* actionDB = nullptr;
Settings* settings = nullptr;
};
| 12,509
|
C++
|
.h
| 356
| 29.842697
| 119
| 0.68304
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,840
|
SetsquareController.h
|
xournalpp_xournalpp/src/core/control/SetsquareController.h
|
/*
* Xournal++
*
* A setsquare controller
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <gtk/gtk.h>
#include "gui/PageView.h"
#include "model/GeometryTool.h"
#include "util/Point.h"
#include "GeometryToolController.h"
class Setsquare;
class Stroke;
enum Leg { HYPOTENUSE, LEFT_LEG, RIGHT_LEG };
/**
* @brief A class that controls a setsquare
* The setsquare can be moved, rotated and scaled
* There are methods for translating coordinates
* and methods to deal with the temporary stroke
* that is displayed near the longest side or
* the midpoint to the longest side of the setsquare.
*/
class SetsquareController: public GeometryToolController {
public:
SetsquareController(XojPageView* view, Setsquare* setsquare);
~SetsquareController() override;
public:
GeometryToolType getType() const override;
/**
* @brief returns the position of a point relative to a coordinate system, in which the given setsquare leg lies on
* the x-axis with the origin in its center (where the unit is 1 cm)
* @param leg the leg of the setsquare
* @param x the x-coordinate of the point (in document coordinates)
* @param y the y-coordinate of the point (in document coordinates)
*/
xoj::util::Point<double> posRelToSide(Leg leg, double x, double y) const;
/**
* @brief checks whether a point with given coordinates lies in the setsquare with an additional border enlarging
* (or shrinked) it
* @param x the x-coordinate of the given point (in document coordinates)
* @param y the y-coordinate of the given point (in document coordinates)
* @param border the size of the border (if negative, the setsquare is shrinked via the border)
*/
bool isInsideGeometryTool(double x, double y, double border = 0.0) const override;
/**
* @brief the point (in document coordinates) for a given position on the longest side of the setsquare
* @param x the x-coordinate of the point on the longest side of the setsquare (when unrotated and untranslated)
*/
xoj::util::Point<double> getPointForPos(double x) const;
/**
* @brief creates a stroke starting at the given position of the longest side of the setsquare
* @param x the x-coordinate of the point on the longest side of the setsquare (when unrotated and untranslated)
*/
void createEdgeStroke(double x);
/**
* @brief updates the stroke aligned to the longest side of the setsquare
* @param x the x-coordinate of the point on the longest side of the setsquare (when unrotated and untranslated)
* updating the stroke
*/
void updateEdgeStroke(double x);
/**
* @brief finishes the stroke aligned to the longest side of the setsquare
*/
void finalizeEdgeStroke();
/**
* @brief creates a radius starting at the given position to the origin of the setsquare
* @param x the x-coordinate of the current point
* @param y the y-coordinate of the current point
*/
void createRadialStroke(double x, double y);
/**
* @brief updates the radius to the origin of the setsquare
* @param x the x-coordinate of the current point
* @param y the y-coordinate of the current point
* updating the stroke
*/
void updateRadialStroke(double x, double y);
/**
* @brief finishes the radius to the origin of the setsquare
*/
void finalizeRadialStroke();
/**
* checks whether a stroke already exists
*/
bool existsEdgeStroke();
/**
* checks whether a radius already exists
*/
bool existsRadialStroke();
private:
/**
* @brief when a stroke aligned to the longest side (hypotenuse) of the setsquare is drawn, the minimal and maximal
* x-coordinates of the point to be drawn (with respect to an unrotated, and untranslated coordinate system) are
* saved in the variables hypotenuseMin and hypotenuseMax
*/
double hypotenuseMax = std::numeric_limits<double>::lowest();
double hypotenuseMin = std::numeric_limits<double>::max();
/**
* @brief the current angle at which the temporary radius is drawn
*/
double strokeAngle = NAN;
};
| 4,279
|
C++
|
.h
| 107
| 35.401869
| 119
| 0.712702
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,841
|
ScrollHandler.h
|
xournalpp_xournalpp/src/core/control/ScrollHandler.h
|
/*
* Xournal++
*
* Scroll handler
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cstddef> // for size_t
#include "gui/widgets/SpinPageAdapter.h" // for SpinPageListener
#include "model/PageRef.h" // for PageRef
#include "pdf/base/XojPdfPage.h" // for XojPdfRectangle
class Control;
class LinkDestination;
class ScrollHandler: public SpinPageListener {
public:
ScrollHandler(Control* control);
~ScrollHandler() override;
public:
void goToPreviousPage();
void goToNextPage();
void goToLastPage();
void goToFirstPage();
void scrollToPage(const PageRef& page, XojPdfRectangle rect = {0, 0, -1, -1});
void scrollToPage(size_t page, XojPdfRectangle rect = {0, 0, -1, -1});
void scrollToAnnotatedPage(bool next);
/**
* Scroll to a given link's destination, provided the
* destination is a local destination and not a URI.
*
* If the destination is a non-existent PDF page,
* we ask the user whether to add the missing page or not.
*
* @param dest is to shown
*/
void scrollToLinkDest(const LinkDestination& dest);
bool isPageVisible(size_t page, int* visibleHeight = nullptr);
public:
void pageChanged(size_t page) override;
private:
Control* control = nullptr;
};
| 1,382
|
C++
|
.h
| 45
| 27.088889
| 82
| 0.69713
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,842
|
ExportHelper.h
|
xournalpp_xournalpp/src/core/control/ExportHelper.h
|
/*
* Xournal++
*
* Helper functions to iterate over devices
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include "control/jobs/BaseExportJob.h" // for ExportBackgroundType
class Document;
namespace ExportHelper {
/**
* @brief Export the input file as a bunch of image files (one per page)
* @param doc Document to export
* @param output Path to the output file(s)
* @param range Page range to be parsed. If range=nullptr, exports the whole file
* @param layerRange Layer range to be parsed. Will only export those layers, for every exported page.
* If a number is too high for the number of layers on a given page, it is just ignored.
* If range=nullptr, exports all layers.
* @param pngDpi Set dpi for Png files. Non positive values are ignored
* @param pngWidth Set the width for Png files. Non positive values are ignored
* @param pngHeight Set the height for Png files. Non positive values are ignored
* @param exportBackground If EXPORT_BACKGROUND_NONE, the exported image file has transparent background
*
* The priority is: pngDpi overwrites pngWidth overwrites pngHeight
*
* @return 0 on success, -2 on failure opening the input file, -3 on export failure
*/
int exportImg(Document* doc, const char* output, const char* range, const char* layerRange, int pngDpi, int pngWidth,
int pngHeight, ExportBackgroundType exportBackground);
/**
* @brief Export the input file as pdf
* @param doc Document to export
* @param output Path to the output file
* @param range Page range to be parsed. If range=nullptr, exports the whole file
* @param layerRange Layer range to be parsed. Will only export those layers, for every exported page.
* If a number is too high for the number of layers on a given page, it is just ignored.
* If range=nullptr, exports all layers.
* @param exportBackground If EXPORT_BACKGROUND_NONE, the exported pdf file has white background
* @param progressiveMode If true, then for each xournalpp page, instead of rendering one PDF page, the page layers are
* rendered one by one to produce as many pages as there are layers.
*
* @return 0 on success, -2 on failure opening the input file, -3 on export failure
*/
int exportPdf(Document* doc, const char* output, const char* range, const char* layerRange,
ExportBackgroundType exportBackground, bool progressiveMode);
} // namespace ExportHelper
| 2,536
|
C++
|
.h
| 50
| 48.22
| 119
| 0.740008
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,843
|
GeometryToolController.h
|
xournalpp_xournalpp/src/core/control/GeometryToolController.h
|
/*
* Xournal++
*
* A geometry tool controller
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <gtk/gtk.h>
#include "gui/PageView.h"
#include "model/GeometryTool.h"
#include "util/Point.h"
class Stroke;
/**
* @brief A class that controls a geometry tool
* The geometry tool can be moved, rotated and scaled
* There are methods for translating coordinates
* and methods to deal with the temporary stroke
*/
class GeometryToolController {
public:
GeometryToolController(XojPageView* view, GeometryTool* geometryTool);
virtual ~GeometryToolController();
public:
/**
* @brief translates the geometry tool in x- and y-direction
* @param x the translation in x-direction (in document coordinates)
* @param y the translation in y-direction (in document coordinates)
*/
void translate(double x, double y);
/**
* @brief rotates the geometry tool around its rotation center
* @param da the rotation angle
* @param cx the x-coordinate of the rotation center (in document coordinates)
* @param cy the y-coordinate of the rotation center (in document coordinates)
*/
void rotate(double da, double cx, double cy);
/**
* @brief resizes the geometry tool by the factor f with respect to a given scaling center
* @param f the scaling factor
* @param cx the x-coordinate of the scaling center (in document coordinates)
* @param cy the y-coordinate of the scaling center (in document coordiantes)
*/
void scale(double f, double cx, double cy);
/**
* @brief marks a point with a "x" and puts the mark onto the current layer
* @param x the x-coordinate of the point (in document coordinates)
* @param y the y-coordinate of the point (in document coordinates)
*/
void markPoint(double x, double y);
/**
* @brief adds the stroke to the layer and rerenders the stroke area
*/
void addStrokeToLayer();
/**
* @brief initializes the stroke by using the properties from the tool handler
*/
void initializeStroke();
/**
* @brief the page view of the page with respect to which the geometry tool is initialized
*/
XojPageView* getView() const;
/**
* @brief the page with respect to which the setsquare is initialized
*/
const PageRef getPage() const;
virtual bool isInsideGeometryTool(double x, double y, double border = 0.0) const = 0;
virtual GeometryToolType getType() const = 0;
public:
XojPageView* view;
/**
* @brief the underlying geometry tool
*/
GeometryTool* geometryTool;
/**
* @brief The stroke drawn
*/
std::unique_ptr<Stroke> stroke;
};
| 2,781
|
C++
|
.h
| 82
| 29.45122
| 94
| 0.696529
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,844
|
ClipboardHandler.h
|
xournalpp_xournalpp/src/core/control/ClipboardHandler.h
|
/*
* Xournal++
*
* The main Control
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <limits> // for numeric_limits
#include <string> // for string
#include <gdk-pixbuf/gdk-pixbuf.h> // for GdkPixbuf
#include <gdk/gdk.h> // for GdkAtom, GdkEvent
#include <glib.h> // for gchar, gulong
#include <gtk/gtk.h> // for GtkClipboard, GtkSelectionData
class ObjectInputStream;
class EditSelection;
class ClipboardListener {
public:
virtual void clipboardCutCopyEnabled(bool enabled) = 0;
virtual void clipboardPasteEnabled(bool enabled) = 0;
virtual void clipboardPasteText(std::string text) = 0;
virtual void clipboardPasteImage(GdkPixbuf* img) = 0;
virtual void clipboardPasteXournal(ObjectInputStream& in) = 0;
virtual void deleteSelection() = 0;
virtual ~ClipboardListener();
};
class ClipboardHandler {
public:
ClipboardHandler(ClipboardListener* listener, GtkWidget* widget);
virtual ~ClipboardHandler();
public:
bool paste();
bool cut();
bool copy();
void setSelection(EditSelection* selection);
void setCopyCutEnabled(bool enabled);
private:
static void ownerChangedCallback(GtkClipboard* clip, GdkEvent* event, ClipboardHandler* handler);
void clipboardUpdated(GdkAtom atom);
static void receivedClipboardContents(GtkClipboard* clipboard, GtkSelectionData* selectionData,
ClipboardHandler* handler);
static void pasteClipboardContents(GtkClipboard* clipboard, GtkSelectionData* selectionData,
ClipboardHandler* handler);
static void pasteClipboardImage(GtkClipboard* clipboard, GdkPixbuf* pixbuf, ClipboardHandler* handler);
static void pasteClipboardText(GtkClipboard* clipboard, const gchar* text, ClipboardHandler* handler);
private:
ClipboardListener* listener = nullptr;
GtkClipboard* clipboard = nullptr;
gulong handlerId = std::numeric_limits<gulong>::max();
EditSelection* selection = nullptr;
bool containsText = false;
bool containsXournal = false;
bool containsImage = false;
};
| 2,232
|
C++
|
.h
| 57
| 34.403509
| 107
| 0.721167
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,845
|
CrashHandler.h
|
xournalpp_xournalpp/src/core/control/CrashHandler.h
|
/*
* Xournal++
*
* Error handler, prints a stacktrace if Xournal++ crashes
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
class Document;
void setEmergencyDocument(Document* doc);
void installCrashHandlers();
void emergencySave();
| 311
|
C++
|
.h
| 15
| 19
| 58
| 0.755102
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,846
|
ToolEnums.h
|
xournalpp_xournalpp/src/core/control/ToolEnums.h
|
/*
* Xournal++
*
* Enum definition used for tools
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string> // for string
#include "model/LineStyle.h"
enum ToolSize {
TOOL_SIZE_VERY_FINE = 0,
TOOL_SIZE_FINE,
TOOL_SIZE_MEDIUM,
TOOL_SIZE_THICK,
TOOL_SIZE_VERY_THICK,
// None has to be at the end, because this enum is used as memory offset
TOOL_SIZE_NONE
};
std::string toolSizeToString(ToolSize size);
ToolSize toolSizeFromString(const std::string& size);
enum DrawingType {
/**
* For config entry, don't change value
*/
DRAWING_TYPE_DONT_CHANGE = 0,
/**
* Default drawing, nothing special
*/
DRAWING_TYPE_DEFAULT,
DRAWING_TYPE_LINE,
DRAWING_TYPE_RECTANGLE,
DRAWING_TYPE_ELLIPSE,
DRAWING_TYPE_ARROW,
DRAWING_TYPE_DOUBLE_ARROW,
DRAWING_TYPE_COORDINATE_SYSTEM,
DRAWING_TYPE_SHAPE_RECOGNIZER,
DRAWING_TYPE_SPLINE
};
std::string drawingTypeToString(DrawingType type);
DrawingType drawingTypeFromString(const std::string& type);
// Has to be in the same order as in Action.h: ActionType!
// The numbers must agree with the action's targets in ui/mainmenubar.xml
enum ToolType {
TOOL_NONE = 0,
// First valid tool, often used starting Index 0
TOOL_PEN = 1,
TOOL_ERASER = 2,
TOOL_HIGHLIGHTER = 3,
TOOL_TEXT = 4,
TOOL_IMAGE = 5,
TOOL_SELECT_RECT = 6,
TOOL_SELECT_REGION = 7,
TOOL_SELECT_MULTILAYER_RECT = 8,
TOOL_SELECT_MULTILAYER_REGION = 9,
TOOL_SELECT_OBJECT = 10,
TOOL_PLAY_OBJECT = 11,
TOOL_VERTICAL_SPACE = 12,
TOOL_HAND = 13,
TOOL_DRAW_RECT = 14,
TOOL_DRAW_ELLIPSE = 15,
TOOL_DRAW_ARROW = 16,
TOOL_DRAW_DOUBLE_ARROW = 17,
TOOL_DRAW_COORDINATE_SYSTEM = 18,
TOOL_FLOATING_TOOLBOX = 19,
TOOL_DRAW_SPLINE = 20,
TOOL_SELECT_PDF_TEXT_LINEAR = 21,
TOOL_SELECT_PDF_TEXT_RECT = 22,
TOOL_END_ENTRY
};
auto isSelectToolType(ToolType type) -> bool;
auto isSelectToolTypeSingleLayer(ToolType type) -> bool;
/**
* @brief Whether or not the tool needs the selection to be cleared when selected
*/
auto requiresClearedSelection(ToolType type) -> bool;
// The count of tools
#define TOOL_COUNT (TOOL_END_ENTRY - 1)
std::string toolTypeToString(ToolType type);
ToolType toolTypeFromString(const std::string& type);
enum OpacityFeature {
OPACITY_NONE,
OPACITY_FILL_PEN,
OPACITY_FILL_HIGHLIGHTER,
OPACITY_SELECT_PDF_TEXT_MARKER,
};
std::string opacityFeatureToString(OpacityFeature feature);
OpacityFeature opacityFeatureFromString(const std::string& feature);
enum EraserType { ERASER_TYPE_NONE = 0, ERASER_TYPE_DEFAULT, ERASER_TYPE_WHITEOUT, ERASER_TYPE_DELETE_STROKE };
std::string eraserTypeToString(EraserType type);
EraserType eraserTypeFromString(const std::string& type);
enum ToolCapabilities : unsigned int {
TOOL_CAP_NONE = 0,
TOOL_CAP_COLOR = 1 << 0,
TOOL_CAP_SIZE = 1 << 1,
TOOL_CAP_RULER = 1 << 2,
TOOL_CAP_RECTANGLE = 1 << 3,
TOOL_CAP_ELLIPSE = 1 << 4,
TOOL_CAP_ARROW = 1 << 5,
TOOL_CAP_DOUBLE_ARROW = 1 << 6,
TOOL_CAP_RECOGNIZER = 1 << 7,
TOOL_CAP_FILL = 1 << 8,
TOOL_CAP_COORDINATE_SYSTEM = 1 << 9,
TOOL_CAP_DASH_LINE = 1 << 10,
TOOL_CAP_SPLINE = 1 << 11,
TOOL_CAP_LINE_STYLE = 1 << 12
};
enum StrokeType {
STROKE_TYPE_NONE = 0,
STROKE_TYPE_STANDARD = 1,
STROKE_TYPE_DASHED = 2,
STROKE_TYPE_DASHDOTTED = 3,
STROKE_TYPE_DOTTED = 4
};
auto strokeTypeFromString(const std::string& type) -> StrokeType;
auto strokeTypeToLineStyle(StrokeType type) -> LineStyle;
auto strokeTypeToString(StrokeType type) -> std::string;
namespace xoj::tool {
/// \return Whether the provided tool is used for selecting objects on a PDF.
bool isPdfSelectionTool(ToolType toolType);
} // namespace xoj::tool
| 3,875
|
C++
|
.h
| 124
| 27.677419
| 111
| 0.706513
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,847
|
PdfCache.h
|
xournalpp_xournalpp/src/core/control/PdfCache.h
|
/*
* Xournal++
*
* Caches PDF backgrounds for faster repaint
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cstddef> // for size_t
#include <deque> // for deque
#include <mutex> // for mutex
#include <cairo.h> // for cairo_t, cairo_surface_t
#include "pdf/base/XojPdfDocument.h" // for XojPdfDocument
#include "pdf/base/XojPdfPage.h" // for XojPdfPageSPtr
namespace xoj::view {
class Mask;
};
class PdfCacheEntry;
class Settings;
class PdfCache {
public:
PdfCache(const XojPdfDocument& doc, Settings* settings);
virtual ~PdfCache();
private:
PdfCache(const PdfCache& cache);
void operator=(const PdfCache& cache);
public:
/**
* @brief Render the page with number pdfPageNo of the pdf document to the cairo context
* @param cr the cairo context
* @param pdfPageNo The page number (in the pdf document)
* @param zoom The current zoom level
* @param pageWidth/pageHeight Xournal++ page dimensions
*/
void render(cairo_t* cr, size_t pdfPageNo, double zoom, double pageWidth, double pageHeight);
public:
/**
* @brief Set the maximum tolerable zoom difference, as a percentage.
*
* @param threshold is the minimum percent-difference between the zoom value at
* which the cached version of the page was rendered and the current zoom,
* for which the page will be re-cached while zooming.
*/
void setRefreshThreshold(double percentDifference);
void setMaxSize(size_t newSize);
void updateSettings(Settings* settings);
/**
* @brief Renders an error background, for when the pdf page cannot be rendered
*/
static void renderMissingPdfPage(cairo_t* cr, double pageWidth, double pageHeight);
private:
/**
* @brief Look up for a cache entry for the page with number pdfPgeNo in the PDF.
*/
const PdfCacheEntry* lookup(size_t pdfPageNo) const;
/**
* @brief Push a cache entry
*/
const PdfCacheEntry* cache(XojPdfPageSPtr popplerPage, xoj::view::Mask&& buffer);
private:
XojPdfDocument pdfDocument;
std::mutex renderMutex;
std::deque<std::unique_ptr<PdfCacheEntry>> data;
decltype(data)::size_type maxSize = 0;
double zoomRefreshThreshold;
};
| 2,324
|
C++
|
.h
| 69
| 29.768116
| 97
| 0.712114
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,848
|
SearchControl.h
|
xournalpp_xournalpp/src/core/control/SearchControl.h
|
/*
* Xournal++
*
* Handles text search on a PDF page and in Xournal Texts
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string> // for string
#include <vector> // for vector
#include "model/OverlayBase.h"
#include "model/PageRef.h" // for PageRef
#include "model/Point.h" // for Point
#include "pdf/base/XojPdfPage.h" // for XojPdfPageSPtr, XojPdfRectangle
#include "util/DispatchPool.h"
namespace xoj::view {
class OverlayView;
class Repaintable;
class SearchResultView;
}; // namespace xoj::view
class SearchControl: public OverlayBase {
public:
SearchControl(const PageRef& page, XojPdfPageSPtr pdf);
virtual ~SearchControl();
bool search(const std::string& text, size_t index, size_t* occurrences, XojPdfRectangle* UpperMostMatch);
const std::vector<XojPdfRectangle>& getResults() const { return results; }
const XojPdfRectangle* getHighlightRect() const { return highlightRect; }
const std::shared_ptr<xoj::util::DispatchPool<xoj::view::SearchResultView>>& getViewPool() const {
return viewPool;
}
private:
PageRef page;
XojPdfPageSPtr pdf;
std::string currentText;
XojPdfRectangle* highlightRect = nullptr;
std::vector<XojPdfRectangle> results;
std::shared_ptr<xoj::util::DispatchPool<xoj::view::SearchResultView>> viewPool;
};
| 1,414
|
C++
|
.h
| 41
| 31.536585
| 109
| 0.734949
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,849
|
CrashHandlerWindows.h
|
xournalpp_xournalpp/src/core/control/CrashHandlerWindows.h
|
/*
* Xournal++
*
* This is the Windows Crash Handler implementation
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
void installCrashHandlers() {
// Todo: Implement SE-Exception Handler for Windows
}
| 282
|
C++
|
.h
| 14
| 18.142857
| 55
| 0.730337
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,850
|
DeviceListHelper.h
|
xournalpp_xournalpp/src/core/control/DeviceListHelper.h
|
/*
* Xournal++
*
* Helper functions to iterate over devices
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string> // for string, basic_string
#include <vector> // for vector
#include <gdk/gdk.h> // for GdkInputSource, GdkDevice
#include "gui/inputdevices/InputEvents.h" // for InputDeviceClass
class Settings;
class InputDevice {
public:
explicit InputDevice(GdkDevice* device);
explicit InputDevice(std::string name, GdkInputSource source);
~InputDevice() = default;
public:
std::string getType() const;
std::string getName() const;
GdkInputSource getSource() const;
void updateType(GdkInputSource newSource);
bool operator==(const InputDevice& inputDevice) const;
private:
std::string name;
GdkInputSource source;
};
namespace DeviceListHelper {
std::vector<InputDevice> getDeviceList(Settings* settings, bool ignoreTouchDevices = false);
InputDeviceClass getSourceMapping(GdkInputSource source, Settings* settings);
} // namespace DeviceListHelper
| 1,095
|
C++
|
.h
| 35
| 28.6
| 92
| 0.762857
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,851
|
CrashHandlerUnix.h
|
xournalpp_xournalpp/src/core/control/CrashHandlerUnix.h
|
/*
* Xournal++
*
* This is the Linux / Unix Crash Handler implementation
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <bitset>
#include <fstream> // std::ofstream
#include <iomanip> // for operator<<, setw
#include <execinfo.h>
#include <gtk/gtk.h>
#include "util/PathUtil.h"
#include "util/Stacktrace.h"
#include "config-dev.h"
#include "config-git.h"
#include "config.h"
static bool alreadyCrashed = false;
static void crashHandler(int sig);
constexpr GLogLevelFlags RECORDED_LOG_LEVELS = GLogLevelFlags(0xff); //< Record all messages
static void log_handler(const gchar* log_domain, GLogLevelFlags log_level, const gchar* message,
std::stringstream* logBuffer) {
if ((log_level & RECORDED_LOG_LEVELS) != 0) {
if (log_level & G_LOG_FLAG_FATAL) {
*logBuffer << "FATAL ";
}
*logBuffer << std::setw(8) << std::left;
switch (log_level & G_LOG_LEVEL_MASK) {
case G_LOG_LEVEL_ERROR:
*logBuffer << "ERROR";
break;
case G_LOG_LEVEL_CRITICAL:
*logBuffer << "CRITICAL";
break;
case G_LOG_LEVEL_WARNING:
*logBuffer << "WARNING";
break;
case G_LOG_LEVEL_MESSAGE:
*logBuffer << "MESSAGE";
break;
case G_LOG_LEVEL_INFO:
*logBuffer << "INFO";
break;
case G_LOG_LEVEL_DEBUG:
*logBuffer << "DEBUG";
break;
default:
*logBuffer << std::bitset<8>(static_cast<unsigned int>(log_level));
}
*logBuffer << ": " << (log_domain ? log_domain : "--") << " :: " << (message ? message : "No message")
<< std::endl;
}
// Forward to stderr/stdout
g_log_default_handler(log_domain, log_level, message, nullptr);
}
void installCrashHandlers() {
sigset_t mask;
sigemptyset(&mask);
#ifdef SIGSEGV
signal(SIGSEGV, crashHandler);
sigaddset(&mask, SIGSEGV);
#endif
#ifdef SIGFPE
signal(SIGFPE, crashHandler);
sigaddset(&mask, SIGFPE);
#endif
#ifdef SIGILL
signal(SIGILL, crashHandler);
sigaddset(&mask, SIGILL);
#endif
#ifdef SIGABRT
signal(SIGABRT, crashHandler);
sigaddset(&mask, SIGABRT);
#endif
sigprocmask(SIG_UNBLOCK, &mask, 0);
g_log_set_default_handler(GLogFunc(log_handler), getCrashHandlerLogBuffer());
}
/**
* Print crash log to config directory
*/
static void crashHandler(int sig) {
if (alreadyCrashed) // crasehd again on emergency save
{
exit(2);
}
alreadyCrashed = true;
g_warning("[Crash Handler] Crashed with signal %i", sig);
time_t lt;
void* array[100];
char** messages;
// get void*'s for all entries on the stack
int size = backtrace(array, 100);
time_t curtime = time(0);
char stime[128];
strftime(stime, sizeof(stime), "%Y%m%d-%H%M%S", localtime(&curtime));
auto const& errorlogPath = Util::getCacheSubfolder(ERRORLOG_DIR) / (std::string("errorlog.") + stime + ".log");
std::ofstream fp(errorlogPath);
if (fp) {
g_warning("[Crash Handler] Wrote crash log to: %s", errorlogPath.c_str());
}
lt = time(nullptr);
fp << FORMAT_STR("Date: {1}") % ctime(<);
fp << FORMAT_STR("Error: signal {1}") % sig;
fp << "\n";
fp << "Xournal++ version " << PROJECT_VERSION << std::endl;
if (auto const gitCommitId = std::string{GIT_COMMIT_ID}; !gitCommitId.empty()) {
fp << "Git commit " << gitCommitId << " from " << GIT_ORIGIN_OWNER << "/" << GIT_BRANCH << std::endl;
}
fp << "Gtk version " << gtk_get_major_version() << "." << gtk_get_minor_version() << "." << gtk_get_micro_version()
<< std::endl
<< std::endl;
messages = backtrace_symbols(array, size);
for (int i = 0; i < size; i++) {
fp << FORMAT_STR("[bt]: ({1}) {2}") % i % messages[i];
fp << "\n";
}
free(messages);
fp << "\n\nTry to get a better stacktrace...\n";
Stacktrace::printStacktrace(fp);
fp << "\n\nExecution log:\n\n";
fp << getCrashHandlerLogBuffer()->str();
if (fp) {
fp.close();
}
emergencySave();
exit(1);
}
| 4,352
|
C++
|
.h
| 131
| 26.763359
| 119
| 0.589345
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,852
|
UndoRedoController.h
|
xournalpp_xournalpp/src/core/control/UndoRedoController.h
|
/*
* Xournal++
*
* Wrapper for undo / redo stuff, to move out the logic of the main Control class
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <vector> // for vector
class Control;
class Layer;
class Element;
class UndoRedoController {
private:
UndoRedoController(Control* control);
virtual ~UndoRedoController();
private:
void before();
void after();
public:
static void undo(Control* control);
static void redo(Control* control);
private:
/**
* Controller
*/
Control* control = nullptr;
/**
* Layer of the selection before change
*/
Layer* layer = nullptr;
/**
* Selected elements
*/
std::vector<Element*> elements;
};
| 798
|
C++
|
.h
| 39
| 17
| 81
| 0.674667
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,853
|
DoubleAttribute.h
|
xournalpp_xournalpp/src/core/control/xml/DoubleAttribute.h
|
/*
* Xournal++
*
* XML Writer helper class
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include "Attribute.h" // for XMLAttribute
class OutputStream;
class DoubleAttribute: public XMLAttribute {
public:
DoubleAttribute(const char* name, double value);
~DoubleAttribute() override;
public:
void writeOut(OutputStream* out) override;
private:
double value;
};
| 463
|
C++
|
.h
| 22
| 18.590909
| 52
| 0.741935
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,854
|
XmlNode.h
|
xournalpp_xournalpp/src/core/control/xml/XmlNode.h
|
/*
* Xournal++
*
* XML Writer helper class
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cstddef> // for size_t
#include <memory> // for unique_ptr
#include <string> // for string
#include <vector> // for vector
#include "Attribute.h" // for XMLAttribute
class ProgressListener;
class OutputStream;
class XmlNode {
public:
XmlNode(const char* tag);
virtual ~XmlNode() = default;
public:
void setAttrib(const char* attrib, std::string value);
void setAttrib(const char* attrib, const char* value);
void setAttrib(const char* attrib, double value);
void setAttrib(const char* attrib, int value);
void setAttrib(const char* attrib, size_t value);
void setAttrib(const char* attrib, std::vector<double> values);
void writeOut(OutputStream* out, ProgressListener* _listener);
virtual void writeOut(OutputStream* out) { writeOut(out, nullptr); }
void addChild(XmlNode* node);
protected:
void putAttrib(XMLAttribute* a);
void writeAttributes(OutputStream* out);
protected:
std::vector<std::unique_ptr<XmlNode>> children{};
std::vector<std::unique_ptr<XMLAttribute>> attributes{};
std::string tag;
};
| 1,266
|
C++
|
.h
| 40
| 28.525
| 72
| 0.719934
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,855
|
SizeTAttribute.h
|
xournalpp_xournalpp/src/core/control/xml/SizeTAttribute.h
|
/*
* Xournal++
*
* XML Writer helper class
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cstddef> // for size_t
#include "Attribute.h" // for XMLAttribute
class OutputStream;
class SizeTAttribute: public XMLAttribute {
public:
SizeTAttribute(const char* name, size_t value);
~SizeTAttribute() override;
public:
void writeOut(OutputStream* out) override;
private:
size_t value;
};
| 494
|
C++
|
.h
| 23
| 19.086957
| 51
| 0.730603
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,856
|
XmlTextNode.h
|
xournalpp_xournalpp/src/core/control/xml/XmlTextNode.h
|
/*
* Xournal++
*
* XML Writer helper class
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string> // for string
#include "XmlAudioNode.h" // for XmlAudioNode
class OutputStream;
class XmlTextNode: public XmlAudioNode {
public:
XmlTextNode(const char* tag, std::string text);
explicit XmlTextNode(const char* tag);
~XmlTextNode() override = default;
public:
void setText(std::string text);
void writeOut(OutputStream* out) override;
private:
std::string text;
};
| 584
|
C++
|
.h
| 25
| 20.72
| 51
| 0.725953
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,857
|
IntAttribute.h
|
xournalpp_xournalpp/src/core/control/xml/IntAttribute.h
|
/*
* Xournal++
*
* XML Writer helper class
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include "Attribute.h" // for XMLAttribute
class OutputStream;
class IntAttribute: public XMLAttribute {
public:
IntAttribute(const char* name, int value);
~IntAttribute() override;
public:
void writeOut(OutputStream* out) override;
private:
int value;
};
| 447
|
C++
|
.h
| 22
| 17.909091
| 46
| 0.732697
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,858
|
XmlImageNode.h
|
xournalpp_xournalpp/src/core/control/xml/XmlImageNode.h
|
/*
* Xournal++
*
* XML Writer helper class
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cairo.h> // for cairo_surface_t, cairo_status_t
#include "XmlNode.h" // for XmlNode
class OutputStream;
class XmlImageNode: public XmlNode {
public:
XmlImageNode(const char* tag);
virtual ~XmlImageNode();
public:
void setImage(cairo_surface_t* img);
static cairo_status_t pngWriteFunction(XmlImageNode* image, const unsigned char* data, unsigned int length);
void writeOut(OutputStream* out) override;
private:
cairo_surface_t* img;
OutputStream* out;
unsigned int pos;
unsigned char buffer[30] = {0};
};
| 731
|
C++
|
.h
| 28
| 23.142857
| 112
| 0.722944
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,859
|
DoubleArrayAttribute.h
|
xournalpp_xournalpp/src/core/control/xml/DoubleArrayAttribute.h
|
/*
* Xournal++
*
* XML Writer helper class
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <vector> // for vector
#include "Attribute.h" // for XMLAttribute
class OutputStream;
class DoubleArrayAttribute: public XMLAttribute {
public:
DoubleArrayAttribute(const char* name, std::vector<double>&& values);
~DoubleArrayAttribute() override;
public:
void writeOut(OutputStream* out) override;
private:
std::vector<double> values;
};
| 542
|
C++
|
.h
| 23
| 21.130435
| 73
| 0.741683
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,860
|
XmlTexNode.h
|
xournalpp_xournalpp/src/core/control/xml/XmlTexNode.h
|
/*
* Xournal++
*
* XML Writer helper class
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string> // for string
#include "XmlNode.h" // for XmlNode
class OutputStream;
class XmlTexNode: public XmlNode {
public:
XmlTexNode(const char* tag, std::string&& binaryData);
virtual ~XmlTexNode();
public:
void writeOut(OutputStream* out) override;
private:
/**
* Binary .PNG or .PDF
*/
std::string binaryData;
};
| 532
|
C++
|
.h
| 26
| 17.692308
| 58
| 0.691383
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,861
|
TextAttribute.h
|
xournalpp_xournalpp/src/core/control/xml/TextAttribute.h
|
/*
* Xournal++
*
* XML Writer helper class
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string> // for string
#include "Attribute.h" // for XMLAttribute
class OutputStream;
class TextAttribute: public XMLAttribute {
public:
TextAttribute(std::string name, std::string value);
~TextAttribute() override;
public:
void writeOut(OutputStream* out) override;
private:
std::string value;
};
| 500
|
C++
|
.h
| 23
| 19.347826
| 55
| 0.731915
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,862
|
Attribute.h
|
xournalpp_xournalpp/src/core/control/xml/Attribute.h
|
/*
* Xournal++
*
* XML Writer helper class
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string> // for string
class OutputStream;
class XMLAttribute {
public:
XMLAttribute(std::string name);
virtual ~XMLAttribute();
public:
virtual void writeOut(OutputStream* out) = 0;
std::string getName();
private:
std::string name;
};
| 441
|
C++
|
.h
| 23
| 16.608696
| 49
| 0.708029
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,863
|
XmlAudioNode.h
|
xournalpp_xournalpp/src/core/control/xml/XmlAudioNode.h
|
/*
* Xournal++
*
* [Header description]
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include "XmlNode.h"
#include "filesystem.h"
class XmlAudioNode: public XmlNode {
public:
XmlAudioNode(const char* tag);
virtual ~XmlAudioNode();
private:
XmlAudioNode(const XmlAudioNode& node);
void operator=(const XmlAudioNode& node);
public:
[[maybe_unused]] fs::path getAudioFilepath();
[[maybe_unused]] void setAudioFilepath(fs::path filepath);
private:
fs::path audioFilepath;
};
| 585
|
C++
|
.h
| 26
| 19.846154
| 62
| 0.723327
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,864
|
XmlPointNode.h
|
xournalpp_xournalpp/src/core/control/xml/XmlPointNode.h
|
/*
* Xournal++
*
* XML Writer helper class
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <vector> // for vector
#include "model/Point.h" // for Point
#include "XmlAudioNode.h" // for XmlAudioNode
class OutputStream;
class XmlPointNode: public XmlAudioNode {
public:
XmlPointNode(const char* tag);
public:
void setPoints(std::vector<Point> points);
void writeOut(OutputStream* out) override;
private:
std::vector<Point> points{};
};
| 547
|
C++
|
.h
| 24
| 20.416667
| 46
| 0.726214
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,865
|
LatexGenerator.h
|
xournalpp_xournalpp/src/core/control/latex/LatexGenerator.h
|
/*
* Xournal++
*
* Latex file generator
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string> // for string
#include <variant> // for variant
#include <gio/gio.h> // for GSubprocess
#include "util/Color.h" // for Color
#include "filesystem.h" // for path
class LatexSettings;
class LatexGenerator {
public:
LatexGenerator(const LatexSettings& settings);
LatexGenerator(const LatexGenerator&) = delete;
LatexGenerator& operator=(const LatexGenerator&) = delete;
LatexGenerator(const LatexGenerator&&) = delete;
LatexGenerator&& operator=(const LatexGenerator&&) = delete;
virtual ~LatexGenerator() = default;
struct GenError {
std::string message;
};
using Result = std::variant<GSubprocess*, GenError>;
/**
* Run the LaTeX command asynchronously to generate a preview for the given
* LaTeX file. The contents of the LaTeX file will be written to "tex.tex"
* in the given directory.
* The resultant process will have its standard error and (original) standard output
* combined into a single standard out stream.
*/
Result asyncRun(const fs::path& texDir, const std::string& texFileContents);
/**
* Instantiate the LaTeX template.
*/
static std::string templateSub(const std::string& input, const std::string& templ, Color textColor);
private:
const LatexSettings& settings;
};
| 1,487
|
C++
|
.h
| 44
| 29.977273
| 104
| 0.712291
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,866
|
EllipseHandler.h
|
xournalpp_xournalpp/src/core/control/tools/EllipseHandler.h
|
/*
* Xournal++
*
* Handles input to draw ellipses
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <vector> // for vector
#include "model/PageRef.h" // for PageRef
#include "BaseShapeHandler.h" // for BaseShapeHandler
class Point;
class Control;
class EllipseHandler: public BaseShapeHandler {
public:
EllipseHandler(Control* control, const PageRef& page, bool flipShift = false, bool flipControl = false);
~EllipseHandler() override;
private:
auto createShape(bool isAltDown, bool isShiftDown, bool isControlDown)
-> std::pair<std::vector<Point>, Range> override;
};
| 687
|
C++
|
.h
| 24
| 25.958333
| 108
| 0.73628
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,867
|
EditSelection.h
|
xournalpp_xournalpp/src/core/control/tools/EditSelection.h
|
/*
* Xournal++
*
* A selection for editing, every selection (Rect, Lasso...) is
* converted to this one if the selection is finished
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <memory> // for unique_ptr
#include <utility> // for pair
#include <vector> // for vector
#include <cairo.h> // for cairo_t, cairo_matrix_t
#include <glib.h> // for GSource
#include "control/ToolEnums.h" // for ToolSize
#include "model/Element.h" // for Element, Element::Index
#include "model/ElementContainer.h" // for ElementContainer
#include "model/ElementInsertionPosition.h" // for InsertionOrder
#include "model/PageRef.h" // for PageRef
#include "undo/UndoAction.h" // for UndoAction (ptr only)
#include "util/Color.h" // for Color
#include "util/Rectangle.h" // for Rectangle
#include "util/serializing/Serializable.h" // for Serializable
#include "CursorSelectionType.h" // for CursorSelectionType, CURS...
#include "SnapToGridInputHandler.h" // for SnapToGridInputHandler
class UndoRedoHandler;
class Layer;
class XojPageView;
class Selection;
class EditSelectionContents;
class DeleteUndoAction;
class LineStyle;
class ObjectInputStream;
class ObjectOutputStream;
class XojFont;
class Document;
class EditSelection;
namespace SelectionFactory {
auto createFromFloatingElement(Control* ctrl, const PageRef& page, Layer* layer, XojPageView* view, ElementPtr e)
-> std::unique_ptr<EditSelection>;
auto createFromFloatingElements(Control* ctrl, const PageRef& page, Layer* layer, XojPageView* view,
InsertionOrder elts) //
-> std::pair<std::unique_ptr<EditSelection>, Range>;
auto createFromElementOnActiveLayer(Control* ctrl, const PageRef& page, XojPageView* view, Element* e,
Element::Index pos = Element::InvalidIndex) //
-> std::unique_ptr<EditSelection>;
auto createFromElementsOnActiveLayer(Control* ctrl, const PageRef& page, XojPageView* view, InsertionOrderRef elts)
-> std::unique_ptr<EditSelection>;
/**
* @brief Creates a new instance containing base->getElements() and *e. The content of *base is cleared but *base is not
* destroyed.
*/
auto addElementFromActiveLayer(Control* ctrl, EditSelection* base, Element* e, Element::Index pos)
-> std::unique_ptr<EditSelection>;
/**
* @brief Creates a new instance containing base->getElements() and the content of elts. The content of *base is cleared
* but *base is not destroyed.
*/
auto addElementsFromActiveLayer(Control* ctrl, EditSelection* base, const InsertionOrderRef& elts)
-> std::unique_ptr<EditSelection>;
}; // namespace SelectionFactory
class EditSelection: public ElementContainer, public Serializable {
public:
EditSelection(Control* ctrl, InsertionOrder elts, const PageRef& page, Layer* layer, XojPageView* view,
const Range& bounds, const Range& snappingBounds);
/// Construct an empty selection
EditSelection(Control* ctrl, const PageRef& page, Layer* layer, XojPageView* view);
~EditSelection() override;
public:
/**
* get the X coordinate relative to the provided view (getView())
* in document coordinates
*/
double getXOnView() const;
/**
* Get the Y coordinate relative to the provided view (getView())
* in document coordinates
*/
double getYOnView() const;
/**
* @return The original X coordinates of the provided view in document
* coordinates.
*/
double getOriginalXOnView();
/**
* @return The original Y coordinates of the provided view in document
* coordinates.
*/
double getOriginalYOnView();
/**
* Get the width in document coordinates (multiple with zoom)
*/
double getWidth() const;
/**
* Get the height in document coordinates (multiple with zoom)
*/
double getHeight() const;
/**
* Get the bounding rectangle in document coordinates (multiple with zoom)
*/
xoj::util::Rectangle<double> getRect() const;
/**
* gets the minimal bounding box containing all elements of the selection used for e.g. grid snapping
*/
xoj::util::Rectangle<double> getSnappedBounds() const;
/**
* get the original bounding rectangle in document coordinates
*/
xoj::util::Rectangle<double> getOriginalBounds() const;
/**
* Get the rotation angle of the selection
*/
double getRotation() const;
/**
* Get if the selection supports being rotated
*/
bool isRotationSupported() const;
/**
* Get the source page (where the selection was done)
*/
PageRef getSourcePage() const;
/**
* Get the source layer (form where the Elements come)
*/
Layer* getSourceLayer() const;
/**
* Get the X coordinate in View coordinates (absolute)
*/
int getXOnViewAbsolute() const;
/**
* Get the Y coordinate in View coordinates (absolute)
*/
int getYOnViewAbsolute() const;
inline XojPageView* getView() const { return view; }
public:
/**
* Sets the tool size for pen or eraser, returns an undo action
* (or nullptr if nothing is done)
*/
UndoActionPtr setSize(ToolSize size, const double* thicknessPen, const double* thicknessHighlighter,
const double* thicknessEraser);
/**
* Set the line style of all strokes, return an undo action
* (Or nullptr if nothing done)
*/
UndoActionPtr setLineStyle(LineStyle style);
/**
* Set the color of all elements, return an undo action
* (Or nullptr if nothing done, e.g. because there is only an image)
*/
UndoActionPtr setColor(Color color);
/**
* Sets the font of all containing text elements, return an undo action
* (or nullptr if there are no Text elements)
*/
UndoActionPtr setFont(const XojFont& font);
/**
* Fills the undo item if the selection is deleted
* the selection is cleared after
*/
void fillUndoItem(DeleteUndoAction* undo);
/**
* Fills the stroke, return an undo action
* (Or nullptr if nothing done, e.g. because there is only an image)
*/
UndoActionPtr setFill(int alphaPen, int alphaHighligther);
public:
/**
* Add an element to the this selection
* @param pos: specifies the index of the element from the source layer,
* in case we want to replace it back where it came from.
*/
void addElement(ElementPtr e, Element::Index pos);
/**
* Returns all containing elements of this selection
*/
auto getElements() const -> std::vector<Element*> const&;
void forEachElement(std::function<void(Element*)> f) const override;
/**
* Returns the insert order of this selection
*/
auto getInsertionOrder() const -> InsertionOrder const&;
enum class OrderChange {
BringToFront,
BringForward,
SendBackward,
SendToBack,
};
/**
* Change the insert order of this selection.
*/
auto rearrangeInsertionOrder(const OrderChange change) -> UndoActionPtr;
/**
* Finish the current movement
* (should be called in the mouse-button-released event handler)
*/
void mouseUp();
/**
* Move the selection
*/
void moveSelection(double dx, double dy, bool addMoveUndo = false);
/**
* Get the cursor type for the current position (if 0 then the default cursor should be used)
*/
CursorSelectionType getSelectionTypeForPos(double x, double y, double zoom);
/**
* Paints the selection to cr, with the given zoom factor. The coordinates of cr
* should be relative to the provided view by getView() (use translateEvent())
*/
void paint(cairo_t* cr, double zoom);
/**
* Gets the selection's bounding box in view coordinates. This takes document zoom
* and selection rotation into account.
*/
auto getBoundingBoxInView() const -> xoj::util::Rectangle<double>;
/**
* If the selection is outside the visible area correct the coordinates
*/
void ensureWithinVisibleArea();
public:
/**
* Handles mouse input for moving and resizing, coordinates are relative to "view"
*/
void mouseDown(CursorSelectionType type, double x, double y);
/**
* Handles mouse input for moving and resizing, coordinates are relative to "view"
*/
void mouseMove(double x, double y, bool alt);
/**
* If the user is currently moving the selection.
*/
bool isMoving();
void copySelection();
public:
XojPageView* getView();
public:
// Serialize interface
void serialize(ObjectOutputStream& out) const override;
void readSerialized(ObjectInputStream& in) override;
/// Applies the transformation to the selected elements, empties the selection and return the modified elements
InsertionOrder makeMoveEffective();
private:
/**
* Draws an indicator where you can scale the selection
*/
void drawAnchorRect(cairo_t* cr, double x, double y, double zoom);
/**
* Draws an indicator where you can rotate the selection
*/
void drawAnchorRotation(cairo_t* cr, double x, double y, double zoom);
/**
* Draws an indicator where you can delete the selection
*/
void drawDeleteRect(cairo_t* cr, double x, double y, double zoom) const;
/**
* Finishes all pending changes, move the elements, scale the elements and add
* them to new layer if any or to the old if no new layer
*/
void finalizeSelection();
/**
* Gets the PageView under the cursor
*/
XojPageView* getPageViewUnderCursor();
/**
* Translate all coordinates which are relative to the current view to the new view,
* and set the attribute view to the new view
*/
void translateToView(XojPageView* v);
/**
* Updates rotation matrix
*/
void updateMatrix();
/**
* scales and shifts to update bounding boxes
*/
void scaleShift(double fx, double fy, bool changeLeft, bool changeTop);
/**
* Set edge panning signal.
*/
void setEdgePan(bool edgePan);
/**
* Whether the edge pan signal is set.
*/
bool isEdgePanning() const;
static bool handleEdgePan(EditSelection* self);
private: // DATA
/**
* The position (and rotation) relative to the current view
*/
double x{};
double y{};
double rotation = 0;
/**
* Use to translate to rotated selection
*/
cairo_matrix_t cmatrix{};
/**
* The size, including the padding and frame
*/
double width{};
double height{};
/**
* The size and dimensions for snapping
*/
xoj::util::Rectangle<double> snappedBounds{};
/**
* Mouse coordinates for moving / resizing
*/
CursorSelectionType mouseDownType = CURSOR_SELECTION_NONE;
double relMousePosX{};
double relMousePosY{};
double relMousePosRotX{};
double relMousePosRotY{};
/**
* If both scale axes should have the same scale factor, e.g. for Text
* (we can only set the font size for text)
*/
bool preserveAspectRatio = false;
/**
* If mirrors are allowed e.g. for strokes
*/
bool supportMirroring = true;
/**
* Support rotation
*/
bool supportRotation = true;
/**
* Size of the editing handles
*/
int btnWidth{8};
/**
* The source page (form where the Elements come)
*/
PageRef sourcePage;
/**
* The source layer (form where the Elements come)
*/
Layer* sourceLayer{};
/**
* The contents of the selection
*/
std::unique_ptr<EditSelectionContents> contents;
private: // HANDLER
/**
* The page view for the anchor
*/
XojPageView* view{};
/**
* Undo redo handler
*/
UndoRedoHandler* undo{};
/**
* The handler for snapping points
*/
SnapToGridInputHandler snappingHandler;
/**
* Edge pan timer
*/
GSource* edgePanHandler = nullptr;
/**
* Inhibit the next move event after edge panning finishes. This prevents
* the selection from teleporting if the page has changed during panning.
* Additionally, this reduces the amount of "jitter" resulting from moving
* the selection in mouseDown while edge panning.
*/
bool edgePanInhibitNext = false;
};
| 12,681
|
C++
|
.h
| 370
| 28.986486
| 120
| 0.671982
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,868
|
StrokeStabilizerEnum.h
|
xournalpp_xournalpp/src/core/control/tools/StrokeStabilizerEnum.h
|
/*
* Xournal++
*
* Enum available stabilizer
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
namespace StrokeStabilizer {
enum class AveragingMethod { NONE, ARITHMETIC, VELOCITY_GAUSSIAN };
constexpr bool isValid(AveragingMethod am) {
return am == AveragingMethod::NONE || am == AveragingMethod::ARITHMETIC || am == AveragingMethod::VELOCITY_GAUSSIAN;
}
enum class Preprocessor { NONE, DEADZONE, INERTIA };
constexpr bool isValid(Preprocessor pp) {
return pp == Preprocessor::NONE || pp == Preprocessor::DEADZONE || pp == Preprocessor::INERTIA;
}
} // namespace StrokeStabilizer
| 671
|
C++
|
.h
| 21
| 29.857143
| 120
| 0.745342
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,869
|
EraseHandler.h
|
xournalpp_xournalpp/src/core/control/tools/EraseHandler.h
|
/*
* Xournal++
*
* Handles the erase of stroke, in special split into different parts etc.
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include "model/PageRef.h" // for PageRef
class DeleteUndoAction;
class Document;
class EraseUndoAction;
class Layer;
class Range;
class LegacyRedrawable;
class Stroke;
class ToolHandler;
class UndoRedoHandler;
class EraseHandler {
public:
EraseHandler(UndoRedoHandler* undo, Document* doc, const PageRef& page, ToolHandler* handler,
LegacyRedrawable* view);
virtual ~EraseHandler();
public:
void erase(double x, double y);
void finalize();
private:
void eraseStroke(Layer* l, Stroke* s, double x, double y, Range& range);
private:
PageRef page;
ToolHandler* handler;
LegacyRedrawable* view;
Document* doc;
UndoRedoHandler* undo;
DeleteUndoAction* eraseDeleteUndoAction;
EraseUndoAction* eraseUndoAction;
double halfEraserSize;
private:
/**
* Coefficient for adding padding to the erased sections of strokes.
* It depends on the stroke cap style ROUND, BUTT or SQUARE.
* The order must match the enum StrokeCapStyle in Stroke.h
*/
static constexpr double PADDING_COEFFICIENT_CAP[] = {0.4, 0.01, 0.5};
};
| 1,328
|
C++
|
.h
| 48
| 24.25
| 97
| 0.733858
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,870
|
ImageHandler.h
|
xournalpp_xournalpp/src/core/control/tools/ImageHandler.h
|
/*
* Xournal++
*
* Image Tool handler
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <functional>
#include <memory>
#include "model/PageRef.h"
#include "util/Rectangle.h"
#include "filesystem.h"
class Control;
class Image;
class ImageHandler final {
public:
ImageHandler(Control* control);
~ImageHandler();
public:
/**
* inserts an image scaled to the given size
*/
void insertImageWithSize(PageRef page, const xoj::util::Rectangle<double>& space);
/// Creates the image from the given file
[[nodiscard]] static auto createImageFromFile(const fs::path& path) -> std::unique_ptr<Image>;
static bool addImageToDocument(std::unique_ptr<Image> img, PageRef page, Control* ctrl, bool addUndoAction);
/**
* scale down (only if necessary) the image so that it then fits on the page
* applies (potentially adjusted) width/height to the image
*/
static void automaticScaling(Image& img, PageRef page);
/// lets the user choose an image file, creates the image and calls the callback
void chooseAndCreateImage(std::function<void(std::unique_ptr<Image>)> callback);
private:
Control* control;
};
| 1,257
|
C++
|
.h
| 40
| 28.075
| 112
| 0.722822
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,871
|
SnapToGridInputHandler.h
|
xournalpp_xournalpp/src/core/control/tools/SnapToGridInputHandler.h
|
/*
* Xournal++
*
* Snapping methods which take account of the settings
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include "model/Point.h"
class Settings;
class SnapToGridInputHandler final {
public:
SnapToGridInputHandler(Settings* settings);
protected:
const Settings* settings;
public:
/**
* @brief If a value is near enough to the y-coordinate of a grid point, it returns the nearest y-coordinate of the
* grid point. Otherwise the original value itself.
* @param y the value
* @param alt indicates whether snapping mode is altered (via the Alt key)
*/
[[nodiscard]] double snapVertically(double y, bool alt);
/**
* @brief If a value is near enough to the x-coordinate of a grid point, it returns the nearest x-coordinate of the
* grid point. Otherwise the original value itself.
* @param x the value
* @param alt indicates whether snapping mode is altered (via the Alt key)
*/
[[nodiscard]] double snapHorizontally(double x, bool alt);
/**
* @brief If a points distance to the nearest grid point is under a certain tolerance, it returns the nearest
* grid point. Otherwise the original Point itself.
* @param pos the position
* @param alt indicates whether snapping mode is altered (via the Alt key)
*/
[[nodiscard]] Point snapToGrid(Point const& pos, bool alt);
/**
* @brief if the angles distance to a multiple quarter of PI is under a certain tolerance, it returns the latter.
* Otherwise the original angle.
* @param radian the angle (in radian)
* @param alt indicates whether snapping mode is altered (via the Alt key)
*/
[[nodiscard]] double snapAngle(double radian, bool alt);
/**
* @brief Snaps the angle between the horizontal axis and the line between the given point and center
* and returns the point rotated accordingly
* @param pos the coordinate of the point
* @param center the center of rotation
* @param alt indicates whether snapping mode is altered (via the Alt key)
*/
[[nodiscard]] Point snapRotation(Point const& pos, Point const& center, bool alt);
/**
* @brief Does rotation snapping followed by snapping to grid
* @param pos the coordinate of the point
* @param center the center of rotation
* @param alt indicates whether snapping mode is altered (via the Alt key)
*/
[[nodiscard]] Point snap(Point const& pos, Point const& center, bool alt);
};
| 2,582
|
C++
|
.h
| 63
| 36.31746
| 119
| 0.703748
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,872
|
PdfElemSelection.h
|
xournalpp_xournalpp/src/core/control/tools/PdfElemSelection.h
|
/*
* Xournal++
*
* Tool for selecting PDF content
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cstddef> // for size_t
#include <string> // for string
#include <vector> // for vector
#include <cairo.h> // for cairo_region_t, cairo_t
#include "control/ToolEnums.h" // for ToolType
#include "model/OverlayBase.h"
#include "pdf/base/XojPdfPage.h" // for XojPdfPageSelectionStyle, XojPdfRec...
#include "util/DispatchPool.h"
#include "util/Util.h" // for npos
#include "util/raii/CairoWrappers.h" // for CairoRegionSPtr
class Range;
class Control;
namespace xoj::view {
class PdfElementSelectionView;
};
/// Represents elements selected from a PDF page, such as text.
class PdfElemSelection: public OverlayBase {
public:
PdfElemSelection(double x, double y, Control* control);
PdfElemSelection& operator=(const PdfElemSelection&) = delete;
PdfElemSelection(const PdfElemSelection&) = delete;
PdfElemSelection& operator=(PdfElemSelection&&) = default;
PdfElemSelection(PdfElemSelection&&) = default;
virtual ~PdfElemSelection();
public:
/// Calls finalizeSelection() and then repaints the page.
bool finalizeSelectionAndRepaint(XojPdfPageSelectionStyle style);
/// Sets the final selection bounds using the provided selection style.
/// Returns true iff there is text contained within the selection bounds.
bool finalizeSelection(XojPdfPageSelectionStyle style);
/// Update the (unfinalized) selection bounds with the given
/// style.
void currentPos(double x, double y, XojPdfPageSelectionStyle style);
/// If the selection is a rectangle, returns true iff the given point is
/// contained in the selection. Returns false on text selection.
bool contains(double x, double y);
const std::vector<XojPdfRectangle>& getSelectedTextRects() const;
/// Returns the text contained in the selection region.
const std::string& getSelectedText() const;
/// Returns true iff the final selections bounds are known.
bool isFinalized() const;
size_t getSelectionPageNr() const;
void setToolType(ToolType toolType);
const cairo_region_t* getSelectedRegion() const { return selectedTextRegion.get(); }
/// Returns the selection style corresponding to the given tool type.
static XojPdfPageSelectionStyle selectionStyleForToolType(ToolType type);
inline const std::shared_ptr<xoj::util::DispatchPool<xoj::view::PdfElementSelectionView>>& getViewPool() const {
return viewPool;
}
private:
/// Assigns the selected text region to the current selection bounds.
void selectTextRegion(XojPdfPageSelectionStyle style);
Range getRegionBbox() const;
XojPdfPageSPtr pdf;
/// The rectangles corresponding to the lines of selected text.
std::vector<XojPdfRectangle> selectedTextRects;
/// The text content of the selection.
std::string selectedText;
/// The area containing the selected text. Used for rendering.
xoj::util::CairoRegionSPtr selectedTextRegion;
/// The PDF selection tool used for the selection.
ToolType toolType;
size_t selectionPageNr = npos;
/// The selection bounds. Note that this does not necessarily correspond to
/// a rectangle--it may also indicate start and end positions of a linear
/// text selection.
XojPdfRectangle bounds;
bool finalized;
std::shared_ptr<xoj::util::DispatchPool<xoj::view::PdfElementSelectionView>> viewPool;
};
| 3,569
|
C++
|
.h
| 81
| 40.135802
| 116
| 0.746532
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,873
|
SplineHandler.h
|
xournalpp_xournalpp/src/core/control/tools/SplineHandler.h
|
/*
* Xournal++
*
* Handles input to draw a spline consisting of linear and cubic spline segments
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <memory> // for unique_ptr
#include <optional> // for optional
#include <vector> // for vector
#include <gdk/gdk.h> // for GdkEventKey
#include "control/zoom/ZoomListener.h"
#include "model/PageRef.h" // for PageRef
#include "model/Point.h" // for Point
#include "util/Range.h" // for Range
#include "InputHandler.h" // for InputHandler
#include "SnapToGridInputHandler.h" // for SnapToGridInputHandler
class PositionInputData;
class Control;
namespace xoj::util {
template <class T>
class DispatchPool;
};
namespace xoj::view {
class OverlayView;
class Repaintable;
class SplineToolView;
}; // namespace xoj::view
/**
* @brief Helper structure for communication with the views
*/
struct SplineHandlerData {
const std::vector<Point>& knots;
const std::vector<Point>& tangents;
const Point& currPoint;
double knotsAttractionRadius;
bool closedSpline;
};
/**
* @brief A class to handle splines
*
* Drawing of a spline is started by a ButtonPressEvent. Every ButtonPressEvent gives a new knot.
* Click-dragging will set the tangents. After a ButtonReleaseEvent the spline segment is dynamically
* drawn and finished after the next ButtonPressEvent.
* The spline is completed through a ButtonDoublePressEvent, the escape key or a
* ButtonPressEvent near the first knot. The latter event closes the spline.
*
* Splines segments can be linear or cubic (as in Inkscape). Where there is a nontrivial tangent,
* the join is smooth.
* The last knot and tangent can be modified using the keyboard.
*/
class SplineHandler: public InputHandler, public ZoomListener {
public:
SplineHandler(Control* control, const PageRef& page);
~SplineHandler() override;
std::unique_ptr<xoj::view::OverlayView> createView(xoj::view::Repaintable* parent) const override;
void onSequenceCancelEvent() override;
bool onMotionNotifyEvent(const PositionInputData& pos, double zoom) override;
void onButtonReleaseEvent(const PositionInputData& pos, double zoom) override;
void onButtonPressEvent(const PositionInputData& pos, double zoom) override;
void onButtonDoublePressEvent(const PositionInputData& pos, double zoom) override;
bool onKeyPressEvent(const KeyEvent& event) override;
bool onKeyReleaseEvent(const KeyEvent& event) override;
void finalizeSpline();
// ZoomListener interface
void zoomChanged() override;
public:
const std::shared_ptr<xoj::util::DispatchPool<xoj::view::SplineToolView>>& getViewPool() const;
using Data = SplineHandlerData;
std::optional<Data> getData() const;
static auto linearizeSpline(const Data& data) -> std::vector<Point>;
Range computeTotalRepaintRange(const Data& data, double strokeWidth) const;
Range computeLastSegmentRepaintRange() const;
private:
void addKnot(const Point& p);
void addKnotWithTangent(const Point& p, const Point& t);
void modifyLastTangent(const Point& t);
void deleteLastKnotWithTangent();
void movePoint(double dx, double dy);
/**
* @brief Clears out the spline and remove the views. Assumes the spline has at most 1 definitive knot
*/
void clearTinySpline();
private:
std::vector<Point> knots{};
std::vector<Point> tangents{};
Point currPoint;
Point buttonDownPoint; // never snapped to grid
/**
* @brief Radius of the knots attractive radius for closing the spline.
* Depends on the zoom level during input events
*/
double knotsAttractionRadius;
bool isButtonPressed = false;
bool inFirstKnotAttractionZone = false;
SnapToGridInputHandler snappingHandler;
std::shared_ptr<xoj::util::DispatchPool<xoj::view::SplineToolView>> viewPool;
static constexpr double KNOTS_ATTRACTION_RADIUS_IN_PIXELS = 10.0; // for circling the spline's knots
};
| 4,075
|
C++
|
.h
| 103
| 36.213592
| 106
| 0.75114
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,874
|
RulerHandler.h
|
xournalpp_xournalpp/src/core/control/tools/RulerHandler.h
|
/*
* Xournal++
*
* Handles input of the ruler
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <vector>
#include "model/PageRef.h" // for PageRef
#include "BaseShapeHandler.h" // for BaseShapeHandler
class Point;
class Control;
class RulerHandler: public BaseShapeHandler {
public:
RulerHandler(Control* control, const PageRef& page);
~RulerHandler() override;
private:
auto createShape(bool isAltDown, bool isShiftDown, bool isControlDown)
-> std::pair<std::vector<Point>, Range> override;
};
| 612
|
C++
|
.h
| 24
| 22.833333
| 74
| 0.733219
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,875
|
RectangleHandler.h
|
xournalpp_xournalpp/src/core/control/tools/RectangleHandler.h
|
/*
* Xournal++
*
* Handles input to draw a rectangle
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <vector> // for vector
#include "model/PageRef.h" // for PageRef
#include "BaseShapeHandler.h" // for BaseShapeHandler
class Point;
class Control;
class RectangleHandler: public BaseShapeHandler {
public:
RectangleHandler(Control* control, const PageRef& page, bool flipShift = false, bool flipControl = false);
~RectangleHandler() override;
private:
auto createShape(bool isAltDown, bool isShiftDown, bool isControlDown)
-> std::pair<std::vector<Point>, Range> override;
};
| 696
|
C++
|
.h
| 24
| 26.333333
| 110
| 0.738346
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,876
|
Selection.h
|
xournalpp_xournalpp/src/core/control/tools/Selection.h
|
/*
* Xournal++
*
* A selection while you are selection, not for editing, only for selection
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <vector> // for vector
#include "model/Element.h" // for Element (ptr only), ShapeContainer
#include "model/ElementInsertionPosition.h"
#include "model/OverlayBase.h"
#include "model/PageRef.h" // for PageRef
#include "util/DispatchPool.h"
#include "util/Point.h"
#include "util/Range.h"
#include "view/overlays/SelectionView.h"
class Document;
class Selection: public ShapeContainer, public OverlayBase {
public:
Selection(bool multiLayer);
~Selection() override;
using BoundaryPoint = xoj::util::Point<double>;
public:
/**
* @return layerId of selected objects, 0 if there is nothing in RectSelection
*/
size_t finalize(PageRef page, bool disableMultilayer, Document* doc);
virtual void currentPos(double x, double y) = 0;
virtual bool userTapped(double zoom) const = 0;
virtual const std::vector<BoundaryPoint>& getBoundary() const = 0;
inline auto getViewPool() const -> const std::shared_ptr<xoj::util::DispatchPool<xoj::view::SelectionView>>& {
return viewPool;
}
auto isMultiLayerSelection() -> bool;
/**
* Get the selected elements and clears them (std::move)
*/
auto releaseElements() -> InsertionOrderRef;
private:
protected:
std::vector<BoundaryPoint> boundaryPoints;
bool multiLayer;
InsertionOrderRef selectedElements;
PageRef page;
Range bbox;
std::shared_ptr<xoj::util::DispatchPool<xoj::view::SelectionView>> viewPool;
friend class EditSelection;
};
class RectSelection: public Selection {
public:
RectSelection(double x, double y, bool multiLayer = false);
~RectSelection() override;
public:
void currentPos(double x, double y) override;
bool contains(double x, double y) const override;
bool userTapped(double zoom) const override;
const std::vector<BoundaryPoint>& getBoundary() const override;
private:
double sx;
double sy;
double ex;
double ey;
double maxDist = 0;
};
class RegionSelect: public Selection {
public:
RegionSelect(double x, double y, bool multiLayer = false);
public:
void currentPos(double x, double y) override;
bool contains(double x, double y) const override;
bool userTapped(double zoom) const override;
const std::vector<BoundaryPoint>& getBoundary() const override;
};
| 2,533
|
C++
|
.h
| 77
| 29.285714
| 114
| 0.731417
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,877
|
TextEditorKeyBindings.h
|
xournalpp_xournalpp/src/core/control/tools/TextEditorKeyBindings.h
|
/*
* Xournal++
*
* Key bindings for text editor event handling
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cstdint>
#include <unordered_map>
#include <gdk/gdkevents.h>
#include <gdk/gdkkeysyms.h>
#include "gui/inputdevices/InputEvents.h"
#include "util/gdk4_helper.h"
#include "TextEditor.h"
struct PressedModifier {
constexpr explicit PressedModifier(GdkModifierType mod): mod(mod) {}
constexpr PressedModifier operator&(PressedModifier o) const {
return PressedModifier((GdkModifierType)(mod | o.mod));
}
GdkModifierType mod;
};
constexpr PressedModifier NONE{(GdkModifierType)0};
constexpr PressedModifier CTRL(GDK_CONTROL_MASK);
constexpr PressedModifier SHIFT(GDK_SHIFT_MASK);
struct TextEditor::KeyBindings {
using hash_type = uint64_t;
using keyval_type = std::invoke_result_t<decltype(gdk_key_event_get_keyval), GdkEvent*>;
static_assert(std::is_same<keyval_type, guint>::value);
using mapped_type = void (*)(TextEditor*);
using value_type = std::pair<const hash_type, mapped_type>;
static_assert(sizeof(PressedModifier) + sizeof(keyval_type) == sizeof(hash_type));
KeyBindings(std::initializer_list<value_type> list): table(list) {}
static constexpr hash_type hash(PressedModifier mod, keyval_type keyval) {
return (static_cast<hash_type>(keyval) | (static_cast<hash_type>(mod.mod) << 32));
}
static hash_type hash(const KeyEvent& e) { return hash(PressedModifier(e.state), e.keyval); }
std::unordered_map<hash_type, mapped_type> table;
bool processEvent(TextEditor* te, const KeyEvent& e) const {
auto it = table.find(hash(e));
if (it == table.end()) {
return false;
}
it->second(te);
return true;
}
};
template <auto fun, auto... a>
void wrap(TextEditor* te) {
(te->*fun)(a...);
}
#define move_binding(mod, key, mvt, dir) \
{KeyBindings::hash(mod, GDK_KEY_##key), wrap<&TextEditor::moveCursor, mvt, dir, false>}, \
{KeyBindings::hash(mod & SHIFT, GDK_KEY_##key), wrap<&TextEditor::moveCursor, mvt, dir, true>}, \
{KeyBindings::hash(mod, GDK_KEY_KP_##key), wrap<&TextEditor::moveCursor, mvt, dir, false>}, { \
KeyBindings::hash(mod& SHIFT, GDK_KEY_KP_##key), wrap<&TextEditor::moveCursor, mvt, dir, true> \
}
const TextEditor::KeyBindings TextEditor::keyBindings(
{move_binding(NONE, Right, GTK_MOVEMENT_VISUAL_POSITIONS, 1),
move_binding(NONE, Left, GTK_MOVEMENT_VISUAL_POSITIONS, -1),
move_binding(CTRL, Right, GTK_MOVEMENT_WORDS, 1),
move_binding(CTRL, Left, GTK_MOVEMENT_WORDS, -1),
move_binding(NONE, Up, GTK_MOVEMENT_DISPLAY_LINES, -1),
move_binding(NONE, Down, GTK_MOVEMENT_DISPLAY_LINES, 1),
move_binding(CTRL, Up, GTK_MOVEMENT_PARAGRAPHS, -1),
move_binding(CTRL, Down, GTK_MOVEMENT_PARAGRAPHS, 1),
move_binding(NONE, Home, GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1),
move_binding(NONE, End, GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1),
move_binding(CTRL, Home, GTK_MOVEMENT_BUFFER_ENDS, -1),
move_binding(CTRL, End, GTK_MOVEMENT_BUFFER_ENDS, 1),
move_binding(NONE, Page_Up, GTK_MOVEMENT_PAGES, -1),
move_binding(NONE, Page_Down, GTK_MOVEMENT_PAGES, 1),
move_binding(CTRL, Page_Up, GTK_MOVEMENT_HORIZONTAL_PAGES, -1),
move_binding(CTRL, Page_Down, GTK_MOVEMENT_HORIZONTAL_PAGES, 1),
{KeyBindings::hash(CTRL, GDK_KEY_a), wrap<&TextEditor::selectAtCursor, TextEditor::SelectType::ALL>},
{KeyBindings::hash(CTRL, GDK_KEY_slash), wrap<&TextEditor::selectAtCursor, TextEditor::SelectType::ALL>},
{KeyBindings::hash(NONE, GDK_KEY_Delete), wrap<&TextEditor::deleteFromCursor, GTK_DELETE_CHARS, 1>},
{KeyBindings::hash(NONE, GDK_KEY_KP_Delete), wrap<&TextEditor::deleteFromCursor, GTK_DELETE_CHARS, 1>},
{KeyBindings::hash(NONE, GDK_KEY_BackSpace), wrap<&TextEditor::backspace>},
{KeyBindings::hash(SHIFT, GDK_KEY_BackSpace), wrap<&TextEditor::backspace>},
{KeyBindings::hash(CTRL, GDK_KEY_Delete), wrap<&TextEditor::deleteFromCursor, GTK_DELETE_WORD_ENDS, 1>},
{KeyBindings::hash(CTRL, GDK_KEY_KP_Delete), wrap<&TextEditor::deleteFromCursor, GTK_DELETE_WORD_ENDS, 1>},
{KeyBindings::hash(CTRL, GDK_KEY_BackSpace), wrap<&TextEditor::deleteFromCursor, GTK_DELETE_WORD_ENDS, -1>},
{KeyBindings::hash(CTRL & SHIFT, GDK_KEY_Delete),
wrap<&TextEditor::deleteFromCursor, GTK_DELETE_PARAGRAPH_ENDS, 1>},
{KeyBindings::hash(CTRL & SHIFT, GDK_KEY_KP_Delete),
wrap<&TextEditor::deleteFromCursor, GTK_DELETE_PARAGRAPH_ENDS, 1>},
{KeyBindings::hash(CTRL & SHIFT, GDK_KEY_BackSpace),
wrap<&TextEditor::deleteFromCursor, GTK_DELETE_PARAGRAPH_ENDS, -1>},
{KeyBindings::hash(CTRL, GDK_KEY_x), wrap<&TextEditor::cutToClipboard>},
{KeyBindings::hash(SHIFT, GDK_KEY_Delete), wrap<&TextEditor::cutToClipboard>},
{KeyBindings::hash(CTRL, GDK_KEY_c), wrap<&TextEditor::copyToClipboard>},
{KeyBindings::hash(CTRL, GDK_KEY_Insert), wrap<&TextEditor::copyToClipboard>},
{KeyBindings::hash(CTRL, GDK_KEY_v), wrap<&TextEditor::pasteFromClipboard>},
{KeyBindings::hash(SHIFT, GDK_KEY_Insert), wrap<&TextEditor::pasteFromClipboard>},
{KeyBindings::hash(NONE, GDK_KEY_Insert), wrap<&TextEditor::toggleOverwrite>},
{KeyBindings::hash(NONE, GDK_KEY_KP_Insert), wrap<&TextEditor::toggleOverwrite>},
{KeyBindings::hash(CTRL, GDK_KEY_b), wrap<&TextEditor::toggleBoldFace>},
{KeyBindings::hash(CTRL, GDK_KEY_B), wrap<&TextEditor::toggleBoldFace>},
{KeyBindings::hash(CTRL, GDK_KEY_plus), wrap<&TextEditor::increaseFontSize>},
{KeyBindings::hash(CTRL, GDK_KEY_KP_Add), wrap<&TextEditor::increaseFontSize>},
{KeyBindings::hash(CTRL, GDK_KEY_minus), wrap<&TextEditor::decreaseFontSize>},
{KeyBindings::hash(CTRL, GDK_KEY_KP_Subtract), wrap<&TextEditor::decreaseFontSize>},
{KeyBindings::hash(NONE, GDK_KEY_Return), wrap<&TextEditor::linebreak>},
{KeyBindings::hash(NONE, GDK_KEY_ISO_Enter), wrap<&TextEditor::linebreak>},
{KeyBindings::hash(NONE, GDK_KEY_KP_Enter), wrap<&TextEditor::linebreak>},
{KeyBindings::hash(NONE, GDK_KEY_Tab), wrap<&TextEditor::tabulation>},
{KeyBindings::hash(NONE, GDK_KEY_KP_Tab), wrap<&TextEditor::tabulation>},
{KeyBindings::hash(NONE, GDK_KEY_ISO_Left_Tab), wrap<&TextEditor::tabulation>},
// Backwards tabulation (deindentation) is not implemented. Do as forward tabulation
{KeyBindings::hash(SHIFT, GDK_KEY_Tab), wrap<&TextEditor::tabulation>},
{KeyBindings::hash(SHIFT, GDK_KEY_KP_Tab), wrap<&TextEditor::tabulation>},
{KeyBindings::hash(SHIFT, GDK_KEY_ISO_Left_Tab), wrap<&TextEditor::tabulation>}});
| 7,080
|
C++
|
.h
| 116
| 53.853448
| 117
| 0.672292
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,878
|
StrokeHandler.h
|
xournalpp_xournalpp/src/core/control/tools/StrokeHandler.h
|
/*
* Xournal++
*
* Handles input of strokes
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <memory> // for unique_ptr
#include <gdk/gdk.h> // for GdkEventKey
#include "model/PageRef.h" // for PageRef
#include "model/Point.h" // for Point
#include "InputHandler.h" // for InputHandler
#include "SnapToGridInputHandler.h" // for SnapToGridInputHandler
class Control;
class Layer;
class PositionInputData;
class Stroke;
namespace xoj::util {
template <class T>
class DispatchPool;
};
namespace xoj::view {
class OverlayView;
class Repaintable;
class StrokeToolView;
}; // namespace xoj::view
namespace StrokeStabilizer {
class Base;
class Active;
} // namespace StrokeStabilizer
/**
* @brief The stroke handler draws a stroke on a XojPageView
*
* The stroke is drawn using a cairo_surface_t* as a mask:
* As the pointer moves on the canvas single segments are
* drawn opaquely on the initially transparent masking
* surface. The surface is used to mask the stroke
* when drawing it to the XojPageView
*/
class StrokeHandler: public InputHandler {
public:
StrokeHandler(Control* control, const PageRef& page);
~StrokeHandler() override;
void onSequenceCancelEvent() override;
bool onMotionNotifyEvent(const PositionInputData& pos, double zoom) override;
void onButtonReleaseEvent(const PositionInputData& pos, double zoom) override;
void onButtonPressEvent(const PositionInputData& pos, double zoom) override;
void onButtonDoublePressEvent(const PositionInputData& pos, double zoom) override;
bool onKeyPressEvent(const KeyEvent& event) override;
bool onKeyReleaseEvent(const KeyEvent& event) override;
/**
* @brief Add a straight line to the stroke (if the movement is valid).
* The line may be subdivided into smaller segments if the pressure variation is too big.
* @param point The endpoint of the added line
*/
void paintTo(Point point);
auto createView(xoj::view::Repaintable* parent) const -> std::unique_ptr<xoj::view::OverlayView> override;
const std::shared_ptr<xoj::util::DispatchPool<xoj::view::StrokeToolView>>& getViewPool() const;
protected:
/**
* @brief Unconditionally add a segment to the stroke.
* Warning: it does not set the width properly nor test if the motion is valid. Use paintTo instead.
* @param point The endpoint of the added segment
*/
void drawSegmentTo(const Point& point);
void strokeRecognizerDetected(std::unique_ptr<Stroke> recognized, Layer* layer);
protected:
Point buttonDownPoint; // used for tapSelect and filtering - never snapped to grid.
SnapToGridInputHandler snappingHandler;
private:
/**
* @brief Pointer to the Stabilizer instance
*/
std::unique_ptr<StrokeStabilizer::Base> stabilizer;
std::shared_ptr<xoj::util::DispatchPool<xoj::view::StrokeToolView>> viewPool;
bool hasPressure;
friend class StrokeStabilizer::Active;
static constexpr double MAX_WIDTH_VARIATION = 0.3;
};
| 3,104
|
C++
|
.h
| 83
| 34.168675
| 110
| 0.75025
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,879
|
CursorSelectionType.h
|
xournalpp_xournalpp/src/core/control/tools/CursorSelectionType.h
|
/*
* Xournal++
*
* The cursor types for selections
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
enum CursorSelectionType {
CURSOR_SELECTION_NONE = 0,
// Inside the selection
CURSOR_SELECTION_MOVE = 1,
// Edges
CURSOR_SELECTION_TOP_LEFT,
CURSOR_SELECTION_TOP_RIGHT,
CURSOR_SELECTION_BOTTOM_LEFT,
CURSOR_SELECTION_BOTTOM_RIGHT,
// Sides
CURSOR_SELECTION_LEFT,
CURSOR_SELECTION_RIGHT,
CURSOR_SELECTION_TOP,
CURSOR_SELECTION_BOTTOM,
CURSOR_SELECTION_ROTATE,
CURSOR_SELECTION_DELETE
};
| 625
|
C++
|
.h
| 28
| 18.714286
| 41
| 0.711636
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,880
|
TextEditor.h
|
xournalpp_xournalpp/src/core/control/tools/TextEditor.h
|
/*
* Xournal++
*
* Text editor gui (for Text Tool)
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string> // for string
#include <gdk/gdk.h> // for GdkEventKey
#include <glib.h> // for gint, gboolean, gchar
#include <gtk/gtk.h> // for GtkIMContext, GtkTextIter, GtkWidget
#include <pango/pango.h> // for PangoAttrList, PangoLayout
#include "model/OverlayBase.h"
#include "model/PageRef.h" // for PageRef
#include "util/Color.h" // for Color
#include "util/Range.h"
#include "util/raii/CStringWrapper.h"
#include "util/raii/GObjectSPtr.h"
#include "util/raii/PangoSPtr.h"
class Text;
class XojFont;
class Control;
class TextEditorCallbacks;
struct KeyEvent;
namespace xoj::util {
template <class T>
class DispatchPool;
};
namespace xoj::view {
class TextEditionView;
};
class TextEditor: public OverlayBase {
public:
TextEditor(Control* control, const PageRef& page, GtkWidget* xournalWidget, double x, double y);
virtual ~TextEditor();
/** Represents the different kinds of text selection */
enum class SelectType { WORD, PARAGRAPH, ALL };
bool onKeyPressEvent(const KeyEvent& event);
bool onKeyReleaseEvent(const KeyEvent& event);
void mousePressed(double x, double y);
void mouseMoved(double x, double y);
void mouseReleased();
/**
* @brief Returns a pointer to the edited Text element.
* Warning: The content of the Text element does not need to be up to date with the buffer's content
* Use `updateTextElementContent` to sync them
*/
Text* getTextElement() const;
bool bufferEmpty() const;
void setFont(XojFont font);
void setColor(Color color);
PangoLayout* getUpToDateLayout() const;
const std::shared_ptr<xoj::util::DispatchPool<xoj::view::TextEditionView>>& getViewPool() const;
Color getSelectionColor() const;
const Range& getCursorBox() const;
const Range& getContentBoundingBox() const;
bool isCursorVisible() const;
void deleteFromCursor(GtkDeleteType type, int count);
void copyToClipboard() const;
void cutToClipboard();
void pasteFromClipboard();
void selectAtCursor(TextEditor::SelectType ty);
private:
void toggleOverwrite();
void toggleBoldFace();
void increaseFontSize();
void decreaseFontSize();
void moveCursor(GtkMovementStep step, int count, bool extendSelection);
void backspace();
void linebreak();
void tabulation();
void afterFontChange();
void replaceBufferContent(const std::string& text);
void finalizeEdition();
void initializeEditionAt(double x, double y);
private:
/**
* @brief Add the text to the provided Pango layout.
* The added text contains both this->text, and the preedit string of the Input Method (this->preeditstring)
* This function also sets up the attributes of the preedit string (typically underlined)
*/
void setTextToPangoLayout(PangoLayout* pl) const;
void setSelectionAttributesToPangoLayout(PangoLayout* pl) const;
Range computeBoundingBox() const;
void repaintEditor(bool sizeChanged = true);
/**
* @brief Compute the cursor's location
* @return The bounding box of the cursor, in TextBox coordinates (i.e relative to the text box upper left corner)
* The bounding box is returned even if the cursor is currently not visible (blinking...)
* WARNING: The returned box may have width == 0 (if in insertion mode or at the end of a line). In this case, the
* width of the displayed cursor should be decided by the view class (depending on zoom for instance)
*/
Range computeCursorBox() const;
void repaintCursorAfterChange();
void resetImContext();
static void bufferPasteDoneCallback(GtkTextBuffer* buffer, GtkClipboard* clipboard, TextEditor* te);
static void iMCommitCallback(GtkIMContext* context, const gchar* str, TextEditor* te);
static void iMPreeditChangedCallback(GtkIMContext* context, TextEditor* te);
static bool iMRetrieveSurroundingCallback(GtkIMContext* context, TextEditor* te);
static bool imDeleteSurroundingCallback(GtkIMContext* context, gint offset, gint n_chars, TextEditor* te);
void moveCursorIterator(const GtkTextIter* newLocation, gboolean extendSelection);
void computeVirtualCursorPosition();
void jumpALine(GtkTextIter* textIter, int count);
void findPos(GtkTextIter* iter, double x, double y) const;
void markPos(double x, double y, bool extendSelection);
void contentsChanged(bool forceCreateUndoAction = false);
void updateCursorBox();
void updateTextElementContent();
private:
Control* control;
PageRef page;
/**
* @brief Pointer to the main window's widget. Used for fetching settings and clipboards, and ringing the bell.
*/
GtkWidget* xournalWidget;
/**
* @brief Text element under edition, clone of the original Text element (if any)
*/
std::unique_ptr<Text> textElement;
Text* originalTextElement;
xoj::util::GObjectSPtr<GtkIMContext> imContext;
xoj::util::GObjectSPtr<GtkTextBuffer> buffer;
xoj::util::GObjectSPtr<PangoLayout> layout;
enum class LayoutStatus { UP_TO_DATE, NEEDS_ATTRIBUTES_UPDATE, NEEDS_COMPLETE_UPDATE };
mutable LayoutStatus layoutStatus;
// InputMethod preedit data
int preeditCursor;
xoj::util::PangoAttrListSPtr preeditAttrList;
xoj::util::OwnedCString preeditString;
/**
* @brief Tracks the bounding box of the editor from the last render.
*
* Because adding or deleting lines may cause the size of the bounding box to change,
* we need to repaint the union of the current and previous bboxes.
*/
Range previousBoundingBox;
Range cursorBox;
std::shared_ptr<xoj::util::DispatchPool<xoj::view::TextEditionView>> viewPool;
/**
* @brief Coordinate of the virtual cursor, in Pango coordinates.
* (The virtual cursor is used when moving the cursor vertically (e.g. pressing up arrow), to get a good "vertical
* move" feeling, even if we pass by (say) an empty line)
*/
int virtualCursorAbscissa = 0;
// cursor blinking timings. In millisecond.
unsigned int cursorBlinkingTimeOn = 0;
unsigned int cursorBlinkingTimeOff = 0;
struct BlinkTimer {
BlinkTimer(unsigned int id = 0): id(id) {}
BlinkTimer(const BlinkTimer&) = delete;
BlinkTimer(BlinkTimer&&) = delete;
BlinkTimer& operator=(const BlinkTimer&) = delete;
BlinkTimer& operator=(BlinkTimer&&) = delete;
BlinkTimer& operator=(unsigned int newId) {
if (id) {
g_source_remove(id);
}
id = newId;
return *this;
}
~BlinkTimer() {
if (id) {
g_source_remove(id);
}
}
static bool callback(TextEditor* te);
private:
unsigned int id = 0; // handler id
} blinkTimer;
bool cursorBlink = true;
bool needImReset = false;
bool mouseDown = false;
bool cursorOverwrite = false;
bool cursorVisible = false;
// In a blinking period, how much time is the cursor visible vs not visible
static constexpr unsigned int CURSOR_ON_MULTIPLIER = 2;
static constexpr unsigned int CURSOR_OFF_MULTIPLIER = 1;
static constexpr unsigned int CURSOR_DIVIDER = CURSOR_ON_MULTIPLIER + CURSOR_OFF_MULTIPLIER;
struct KeyBindings;
static const KeyBindings keyBindings;
};
| 7,595
|
C++
|
.h
| 185
| 35.859459
| 118
| 0.712986
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,881
|
VerticalToolHandler.h
|
xournalpp_xournalpp/src/core/control/tools/VerticalToolHandler.h
|
/*
* Xournal++
*
* Vertical Space tool
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <memory> // for unique_ptr
#include <vector> // for vector
#include <cairo.h> // for cairo_surface_t, cairo_t
#include "model/ElementContainer.h" // for ElementContainer
#include "model/OverlayBase.h"
#include "model/PageRef.h" // for PageRef
#include "util/Range.h"
#include "SnapToGridInputHandler.h" // for SnapToGridInputHandler
class Element;
class Layer;
class MoveUndoAction;
class Settings;
class ZoomControl;
struct KeyEvent;
using ElementPtr = std::unique_ptr<Element>;
namespace xoj::view {
class OverlayView;
class Repaintable;
class VerticalToolView;
}; // namespace xoj::view
namespace xoj::util {
template <class T>
class DispatchPool;
}; // namespace xoj::util
/**
* Handler class for the Vertical Spacing tool.
*/
class VerticalToolHandler: public ElementContainer, public OverlayBase {
public:
/**
* @param initiallyReverse Set this to true if the user has the reverse mode
* button (e.g., Ctrl) held down when a vertical selection is started.
*/
VerticalToolHandler(const PageRef& page, Settings* settings, double y, bool initiallyReverse);
~VerticalToolHandler() override;
VerticalToolHandler(VerticalToolHandler&) = delete;
VerticalToolHandler& operator=(VerticalToolHandler&) = delete;
VerticalToolHandler(VerticalToolHandler&&) = delete;
VerticalToolHandler&& operator=(VerticalToolHandler&&) = delete;
/** Update the tool state with the new spacing position */
void currentPos(double x, double y);
bool onKeyPressEvent(const KeyEvent& event);
bool onKeyReleaseEvent(const KeyEvent& event);
std::unique_ptr<MoveUndoAction> finalize();
void forEachElement(std::function<void(Element*)> f) const override;
auto createView(xoj::view::Repaintable* parent, ZoomControl* zoomControl, const Settings* settings) const
-> std::unique_ptr<xoj::view::OverlayView>;
enum class Side {
/** elements above the reference line */
Above = -1,
/** elements below the reference line */
Below = 1,
};
inline double getStartY() const { return startY; }
inline double getEndY() const { return endY; }
inline Side getSide() const { return spacingSide; }
double getPageWidth() const;
inline auto getViewPool() const -> std::shared_ptr<xoj::util::DispatchPool<xoj::view::VerticalToolView>> {
return viewPool;
}
private:
/**
* Returns a vector of pointers to the elements we have adopted
* This function copies the element ptrs into a new vector
*/
auto refElements() const -> std::vector<Element*>;
/**
* Clear the currently moved elements, and then select all elements
* above/below startY (depending on the side) to use for the spacing.
* Lastly, redraw the elements to the buffer.
*/
void adoptElements(Side side);
/**
* @brief Get the bounding range of the collection of elements we have adopted
* @return The returned range may be empty if no elements have been adopted
*/
Range computeElementsBoundingBox() const;
PageRef page;
Layer* layer;
std::vector<ElementPtr> elements;
/**
* @brief Stores the smallest box containing all the adopted elements.
* Used to only refresh the part of the screen that needs refreshing.
*/
Range ownedElementsOriginalBoundingBox;
double startY;
double endY;
/**
* Indicates whether to move elements above or below the anchor line.
*/
Side spacingSide;
/**
* The handler for snapping points
*/
SnapToGridInputHandler snappingHandler;
std::shared_ptr<xoj::util::DispatchPool<xoj::view::VerticalToolView>> viewPool;
};
| 3,880
|
C++
|
.h
| 108
| 31.694444
| 110
| 0.714629
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,882
|
BaseShapeHandler.h
|
xournalpp_xournalpp/src/core/control/tools/BaseShapeHandler.h
|
/*
* Xournal++
*
* Handles input of the ruler
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <memory> // for shared_ptr
#include <utility> // for pair
#include <vector> // for vector
#include <gdk/gdk.h> // for GdkEventKey
#include "model/PageRef.h" // for PageRef
#include "model/Point.h" // for Point
#include "util/Range.h" // for Range
#include "InputHandler.h" // for InputHandler
#include "SnapToGridInputHandler.h" // for SnapToGridInputHandler
class PositionInputData;
namespace xoj::util {
template <class T>
class DispatchPool;
}
namespace xoj::view {
class OverlayView;
class Repaintable;
class ShapeToolView;
};
enum DIRSET_MODIFIERS { NONE = 0, SET = 1, SHIFT = 1 << 1, CONTROL = 1 << 2 };
class BaseShapeHandler: public InputHandler {
public:
BaseShapeHandler(Control* control, const PageRef& page, bool flipShift = false, bool flipControl = false);
~BaseShapeHandler() override;
void onSequenceCancelEvent() override;
bool onMotionNotifyEvent(const PositionInputData& pos, double zoom) override;
void onButtonReleaseEvent(const PositionInputData& pos, double zoom) override;
void onButtonPressEvent(const PositionInputData& pos, double zoom) override;
void onButtonDoublePressEvent(const PositionInputData& pos, double zoom) override;
bool onKeyPressEvent(const KeyEvent& event) override;
bool onKeyReleaseEvent(const KeyEvent& event) override;
std::unique_ptr<xoj::view::OverlayView> createView(xoj::view::Repaintable* parent) const override;
const std::shared_ptr<xoj::util::DispatchPool<xoj::view::ShapeToolView>>& getViewPool() const;
/**
* @brief Get the shape's points.
*/
const std::vector<Point>& getShape() const;
private:
/**
* @brief Create the shape (to be drawn and added as a stroke), depending on the last event in
* @return Pair [vector, range] where vector contains the points drawing the shape and range is the smallest range
* containing all those points. WARNING: Stroke thickness is not taken into account.
*/
virtual std::pair<std::vector<Point>, Range> createShape(bool isAltDown, bool isShiftDown, bool isControlDown) = 0;
/**
* @brief Update the current shape with the latest event info.
* Also warns the listeners about the change, usually triggering a redraw during the next screen update.
*/
void updateShape(bool isAltDown, bool isShiftDown, bool isControlDown);
/**
* @brief Cancel the current shape creation: clears all data and wipes any drawing made
*/
void cancelStroke();
bool onKeyEvent(const KeyEvent& event, bool pressed);
protected:
/**
* modifyModifiersByDrawDir
* @brief Toggle shift and control modifiers depending on initial drawing direction.
*/
void modifyModifiersByDrawDir(double width, double height, double zoom, bool changeCursor = true);
protected:
std::vector<Point> shape;
/**
* @brief Bounding box of the stroke after its last update
* WARNING: The stroke width is not taken into account (i.e. this is the snapping box)
*/
Range lastSnappingRange;
DIRSET_MODIFIERS drawModifierFixed = NONE;
bool flipShift =
false; // use to reverse Shift key modifier action. i.e. for separate Rectangle and Square Tool buttons.
bool flipControl = false; // use to reverse Control key modifier action.
bool modShift = false;
bool modControl = false;
SnapToGridInputHandler snappingHandler;
Point currPoint;
Point buttonDownPoint; // used for tapSelect and filtering - never snapped to grid.
Point startPoint; // May be snapped to grid
std::shared_ptr<xoj::util::DispatchPool<xoj::view::ShapeToolView>> viewPool;
};
| 3,864
|
C++
|
.h
| 90
| 38.911111
| 119
| 0.726788
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,883
|
CoordinateSystemHandler.h
|
xournalpp_xournalpp/src/core/control/tools/CoordinateSystemHandler.h
|
/*
* Xournal++
*
* Handles input to draw an coordinate system
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <vector> // for vector
#include "model/PageRef.h" // for PageRef
#include "BaseShapeHandler.h" // for BaseShapeHandler
class XournalView;
class CoordinateSystemHandler: public BaseShapeHandler {
public:
CoordinateSystemHandler(Control* control, const PageRef& page, bool flipShift = false, bool flipControl = false);
~CoordinateSystemHandler() override;
private:
auto createShape(bool isAltDown, bool isShiftDown, bool isControlDown)
-> std::pair<std::vector<Point>, Range> override;
};
| 717
|
C++
|
.h
| 23
| 28.434783
| 117
| 0.74818
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,884
|
ImageSizeSelection.h
|
xournalpp_xournalpp/src/core/control/tools/ImageSizeSelection.h
|
/*
* Xournal++
*
* Select a size before inserting an image
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include "model/OverlayBase.h" // for OverlayBase
#include "util/DispatchPool.h" // for Listener
#include "util/Rectangle.h" // for Rectangle
#include "view/overlays/ImageSizeSelectionView.h" // for ImageSizeSelectionView
using namespace xoj::view;
class ImageSizeSelection: public OverlayBase {
public:
ImageSizeSelection(double x, double y);
void updatePosition(double x, double y);
void finalize();
auto getSelectedSpace() const -> xoj::util::Rectangle<double>;
inline auto getViewPool() const -> const std::shared_ptr<xoj::util::DispatchPool<ImageSizeSelectionView>>& {
return viewPool;
}
private:
double startX;
double startY;
double endX;
double endY;
std::shared_ptr<xoj::util::DispatchPool<ImageSizeSelectionView>> viewPool;
};
| 1,046
|
C++
|
.h
| 32
| 29.46875
| 112
| 0.691235
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,885
|
InputHandler.h
|
xournalpp_xournalpp/src/core/control/tools/InputHandler.h
|
/*
* Xournal++
*
* Handles input and optimizes the stroke
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <memory> // for unique_ptr
#include <gdk/gdk.h> // for GdkEventKey
#include "model/OverlayBase.h"
#include "model/PageRef.h" // for PageRef
class Control;
class Point;
class Stroke;
class PositionInputData;
struct KeyEvent;
namespace xoj::view {
class OverlayView;
class Repaintable;
}; // namespace xoj::view
/**
* @brief A base class to handle pointer input
*
* The InputHandler receives various events from a XojPageView
* and updates the XojPageView to display strokes being
* drawn
*/
class InputHandler: public OverlayBase {
public:
InputHandler(Control* control, const PageRef& page);
virtual ~InputHandler();
public:
/**
* This method is called from the XojPageView as soon
* as the pointer is moved while this InputHandler
* is active. It is used to update internal data
* structures and queue repaints of the XojPageView
* if necessary
*/
virtual bool onMotionNotifyEvent(const PositionInputData& pos, double zoom) = 0;
/**
* This method is called from the XojPageView when a keypress is detected.
* It is used to update internal data structures and queue
* repaints of the XojPageView if necessary.
*/
virtual bool onKeyPressEvent(const KeyEvent& event) = 0;
virtual bool onKeyReleaseEvent(const KeyEvent& event) = 0;
/**
* The current input device for stroken, do not react on other devices (linke mices)
* This method is called from the XojPageView as soon
* as the pointer is released.
*/
virtual void onButtonReleaseEvent(const PositionInputData& pos, double zoom) = 0;
/**
* This method is called from the XojPageView as soon
* as the pointer is pressed.
*/
virtual void onButtonPressEvent(const PositionInputData& pos, double zoom) = 0;
/**
* This method is called from the XojPageView as soon
* as the pointer is pressed a second time.
*/
virtual void onButtonDoublePressEvent(const PositionInputData& pos, double zoom) = 0;
/**
* This method is called when an action taken by the pointer is canceled.
* It is used, for instance, to cancel a stroke drawn when a user starts
* to zoom on a touchscreen device.
*/
virtual void onSequenceCancelEvent() = 0;
virtual std::unique_ptr<xoj::view::OverlayView> createView(xoj::view::Repaintable* parent) const = 0;
Stroke* getStroke() const;
protected:
[[nodiscard]] static std::unique_ptr<Stroke> createStroke(Control* control);
static bool validMotion(Point p, Point q);
/**
* Smaller movements will be ignored.
* Expressed in page coordinates
*/
static constexpr double PIXEL_MOTION_THRESHOLD = 0.3;
protected:
Control* control;
PageRef page;
std::unique_ptr<Stroke> stroke;
};
| 2,993
|
C++
|
.h
| 88
| 29.988636
| 105
| 0.716464
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,886
|
EditSelectionContents.h
|
xournalpp_xournalpp/src/core/control/tools/EditSelectionContents.h
|
/*
* Xournal++
*
* The "Model" of a EditSelection
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <memory> // for unique_ptr
#include <utility> // for pair
#include <vector> // for vector
#include <cairo.h> // for cairo_surface_t, cairo_t
#include "control/ToolEnums.h" // for ToolSize
#include "model/Element.h" // for Element::Index, Element
#include "model/ElementContainer.h" // for ElementContainer
#include "model/ElementInsertionPosition.h" // for InsertionOrder
#include "model/PageRef.h" // for PageRef
#include "undo/UndoAction.h" // for UndoAction (ptr only)
#include "util/Color.h" // for Color
#include "util/Rectangle.h" // for Rectangle
#include "util/serializing/Serializable.h" // for Serializable
#include "CursorSelectionType.h" // for CursorSelectionType
class UndoRedoHandler;
class Layer;
class XojPageView;
class DeleteUndoAction;
class LineStyle;
class ObjectInputStream;
class ObjectOutputStream;
class XojFont;
class EditSelectionContents: public ElementContainer, public Serializable {
public:
EditSelectionContents(xoj::util::Rectangle<double> bounds, xoj::util::Rectangle<double> snappedBounds,
const PageRef& sourcePage, Layer* sourceLayer, XojPageView* sourceView);
~EditSelectionContents() override;
public:
/**
* Sets the line style for all strokes, returns an undo action
* (or nullptr if nothing is done)
*/
UndoActionPtr setLineStyle(LineStyle style);
/**
* Sets the tool size for pen or eraser, returns an undo action
* (or nullptr if nothing is done)
*/
UndoActionPtr setSize(ToolSize size, const double* thicknessPen, const double* thicknessHighlighter,
const double* thicknessEraser);
/**
* Set the color of all elements, return an undo action
* (Or nullptr if nothing done, e.g. because there is only an image)
*/
UndoActionPtr setColor(Color color);
/**
* Sets the font of all containing text elements, return an undo action
* (or nullptr if there are no Text elements)
*/
UndoActionPtr setFont(const XojFont& font);
/**
* Fills the undo item if the selection is deleted
* the selection is cleared after
*/
void fillUndoItem(DeleteUndoAction* undo);
/**
* Fills the stroke, return an undo action
* (Or nullptr if nothing done, e.g. because there is only an image)
*/
UndoActionPtr setFill(int alphaPen, int alphaHighligther);
public:
/**
* Add an element to the this selection
* @param orderInSourceLayer: specifies the index of the element from the source layer,
* in case we want to replace it back where it came from.
*/
void addElement(ElementPtr e, Element::Index order);
/**
* Returns all containing elements of this selection
*/
auto getElements() const -> std::vector<Element*> const&;
void forEachElement(std::function<void(Element*)> f) const override;
/**
* Returns the insert order of this selection
*/
auto getInsertionOrder() const -> const InsertionOrder&;
/** replaces all elements by a new vector of elements
* @param newElements: the elements which should replace the old elements
* */
void replaceInsertionOrder(InsertionOrder newInsertionOrder);
/**
* Returns InsertionOrder of this selection and clears it
*/
auto stealInsertionOrder() -> InsertionOrder;
public:
/**
* paints the selection
*/
void paint(cairo_t* cr, double x, double y, double rotation, double width, double height, double zoom);
/// Applies the transformation to the selected elements, empties the selection and return the modified elements
InsertionOrder makeMoveEffective(const xoj::util::Rectangle<double>& bounds,
const xoj::util::Rectangle<double>& snappedBounds, bool preserveAspectRatio);
/**
* Finish the editing
*/
void finalizeSelection(xoj::util::Rectangle<double> bounds, xoj::util::Rectangle<double> snappedBounds,
bool aspectRatio, Layer* destinationLayer);
void updateContent(xoj::util::Rectangle<double> bounds, xoj::util::Rectangle<double> snappedBounds, double rotation,
bool aspectRatio, Layer* layer, const PageRef& targetPage, UndoRedoHandler* undo,
CursorSelectionType type);
private:
/**
* Delete our internal View buffer,
* it will be recreated when the selection is painted next time
*/
void deleteViewBuffer();
/**
* Callback to redrawing the buffer asynchrony
*/
static auto repaintSelection(EditSelectionContents* selection) -> bool;
public:
/**
* Gets the original view of the contents
*/
XojPageView* getSourceView();
/**
* Gets the original X of the contents
*/
double getOriginalX() const;
/**
* Gets the original Y of the contents
*/
double getOriginalY() const;
/**
* Gets the complete original bounding box as rectangle
*/
auto getOriginalBounds() const -> xoj::util::Rectangle<double>;
public:
// Serialize interface
void serialize(ObjectOutputStream& out) const override;
void readSerialized(ObjectInputStream& in) override;
private:
/**
* The original dimensions to calculate the zoom factor for rescaling the items and the offset for moving the
* selection
*/
xoj::util::Rectangle<double> originalBounds;
xoj::util::Rectangle<double> lastBounds;
xoj::util::Rectangle<double> lastSnappedBounds;
/**
* The given rotation. Original rotation should always be zero (double)
*/
double rotation = 0;
double lastRotation = 0; // for undoing multiple rotations during one selection edit.
/**
* The offset to the original selection
*/
double relativeX = -9999999999;
double relativeY = -9999999999;
/**
* The setting for whether line width is restored after resizing operation (checked at creation time)
*/
bool restoreLineWidth;
/**
* The selected element (the only one which are handled by this instance)
*/
std::vector<Element*> selected;
/**
* Mapping of elements in the selection to the indexes from the original selection layer.
* Defines a insert order over the selection.
*
* Invariant: the insert order must be sorted by index in ascending order.
*/
InsertionOrder insertionOrder;
/**
* The rendered elements
*/
cairo_surface_t* crBuffer = nullptr;
/**
* The source id for the rescaling task
*/
guint rescaleId = 0;
/**
* Source Page for Undo operations
*/
PageRef sourcePage;
/**
* Source Layer for Undo operations
*/
Layer* sourceLayer;
/**
* Source View for Undo operations
*/
XojPageView* sourceView;
};
| 7,148
|
C++
|
.h
| 195
| 31.194872
| 120
| 0.678194
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,887
|
StrokeStabilizer.h
|
xournalpp_xournalpp/src/core/control/tools/StrokeStabilizer.h
|
/*
* Xournal++
*
* Handles input of strokes
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cmath> // for hypot
#include <cstddef> // for size_t
#include <deque> // for deque
#include <memory> // for allocator, unique_ptr
#include <string> // for operator+, char_traits
#include <glib.h> // for guint32
#include "control/tools/StrokeHandler.h" // for StrokeHandler
#include "gui/inputdevices/PositionInputData.h" // for PositionInputData
#include "model/Point.h" // for Point
#include "util/CircularBuffer.h" // for CircularBuffer
class Settings;
namespace StrokeStabilizer {
/**
* Auxiliary structures
*/
/**
* @brief A (rudimentary) structure for 2D mathematical vectors
*/
struct MathVect {
double dx{};
double dy{};
static inline double scalarProduct(MathVect u, MathVect v) { return u.dx * v.dx + u.dy * v.dy; }
inline double norm() { return std::hypot(dx, dy); }
};
/**
* @brief A structure containing the event's information relevant for the stabilizers
*/
struct Event {
Event() = default;
Event(double x, double y, double pressure): x(x), y(y), pressure(pressure) {}
Event(const PositionInputData& pos): x(pos.x), y(pos.y), pressure(pos.pressure) {}
bool operator!=(const Event& ev) { return (x != ev.x) || (y != ev.y) || (pressure != ev.pressure); }
double x{};
double y{};
double pressure{};
};
/**
* @brief Base stabilizer class. Also used as default (no stabilization).
*/
class Base {
public:
Base() = default;
virtual ~Base() = default;
/**
* @brief Initialize the stabilizer
* @param sH Pointer to the StrokeHandler instance handling the stroke
* @param zoomValue The current zoom
* @param pos The position of the button down event starting the stroke
*/
void initialize(StrokeHandler* sH, double zoomValue, const PositionInputData& pos) {
strokeHandler = sH;
zoom = zoomValue;
recordFirstEvent(pos);
}
/**
* @brief Compute stabilized coordinates for the event and paints the obtained point
* @param pos The MotionNotify event information
*/
virtual void processEvent(const PositionInputData& pos) {
strokeHandler->paintTo(Point(pos.x / zoom, pos.y / zoom, pos.pressure));
}
/**
* @brief Fill the possible gap between the last painted point and the last event received by the stabilizer.
*
* Does nothing in the base class
*/
virtual void finalizeStroke() {}
[[maybe_unused]] virtual auto getInfo() -> std::string { return "No stabilizer"; }
protected:
/**
* @brief Upon initialization, record the first event for the stabilizer's benefits.
* @param pos The first event
*
* Does nothing in the base class
*/
virtual inline void recordFirstEvent(const PositionInputData& pos){};
/**
* @brief Pointer to the StrokeHandler instance handling the stroke
*/
StrokeHandler* strokeHandler;
/**
* @brief The zoom value to be applied on all painted points
*/
double zoom;
};
/**
* @brief Abstract base class for active stabilizers
*/
class Active: public Base {
public:
Active(bool finalize): finalize(finalize) {}
~Active() override = default;
/**
* @brief Fill the possible gap between the last painted point and the last event received by the stabilizer.
* It does so by creating a quadraticSplineTo the last event's coordinates
*/
void finalizeStroke() override;
/**
* @brief Compute stabilized coordinates for the event and paints the obtained point
* @param pos The MotionNotify event information
*/
void processEvent(const PositionInputData& pos) override {
Event ev(pos);
averageAndPaint(ev, pos.timestamp);
}
protected:
/**
* @brief Add a segment to the stroke ending at the parameters coordinates
* @param ev The event whose coordinates determine the stroke's new endpoint
*/
inline void drawEvent(const Event& ev) { strokeHandler->paintTo(Point(ev.x / zoom, ev.y / zoom, ev.pressure)); }
/**
* @brief Record the event corresponding to last painted point
* @param ev The event corresponding to last painted point
*
* Does nothing in the base class.
*/
virtual inline void setLastPaintedEvent(const Event& ev) {}
/**
* @brief For stabilizers with a buffer, clear the buffer and reinitialize it with the provided data
* @param ev New event to push to the buffer
* @param timestamp The timestamp of that event
*
* Does nothing in the base class
*/
virtual inline void resetBuffer(Event& ev, guint32 timestamp) {}
/**
* @brief On stabilizers with a buffer, use it to average the input's position and paint the resulting point
* @param ev An event to add to the mix
* @param timestamp The event's timestamp
*
* In the base class, simply paint the point corresponding to the given event
*/
virtual inline void averageAndPaint(const Event& ev, guint32 timestamp) {
setLastPaintedEvent(ev);
drawEvent(ev);
}
/**
* @brief Add a quadratic spline segment from the end of the stroke to the point corresponding to the parameters, so
* that the stroke is smooth at its former endpoint
* @param ev Event whose coordinates determine the stroke's new endpoint
*/
void quadraticSplineTo(const Event& ev);
private:
/**
* @brief Get the last event received by the stabilizer
* @return The last event
*/
virtual inline Event getLastEvent() = 0;
/**
* @brief Tweak the stroke's pressure values upon finalizing the stroke
*
* Does nothing in the base class
*/
virtual inline void rebalanceStrokePressures() {}
/**
* @brief Wether or not to finalize the stroke
*/
bool finalize = true;
};
/*****************************
* PREPROCESSORS *
*****************************/
/**
* @brief Class for deadzone stabilizer/preprocessor
*/
class Deadzone: virtual public Active {
public:
Deadzone(bool finalize, double dzRadius, bool cuspDetection):
Active(finalize), deadzoneRadius(dzRadius), cuspDetection(cuspDetection) {}
~Deadzone() override = default;
/**
* @brief Compute stabilized coordinates for the event and paints the obtained point
* @param pos The MotionNotify event information
*/
void processEvent(const PositionInputData& pos) override;
[[maybe_unused]] auto getInfo() -> std::string override {
return "Deadzone stabilizer with deadzoneRadius = " + std::to_string(deadzoneRadius) +
", cusp detection = " + (cuspDetection ? "on" : "off");
}
protected:
/**
* @brief Upon initialization, record the first event for the stabilizer's benefits.
* @param pos The first event
*/
void recordFirstEvent(const PositionInputData& pos) override;
/**
* @brief Record the event corresponding to last painted point
* @param ev The event corresponding to last painted point
*/
inline void setLastPaintedEvent(const Event& ev) override { lastPaintedEvent = ev; }
/**
* @brief Get the last event received by the stabilizer
* @return The last event
*/
inline Event getLastEvent() override { return lastEvent; }
private:
/**
* @brief The deadzone radius
*/
const double deadzoneRadius;
/**
* @brief Flag to turn on/off the cusp detection
*/
const bool cuspDetection;
/**
* @brief The direction of the last event outside the deadzone
*/
MathVect lastLiveDirection = {0, 0};
/**
* @brief The last event outside the deadzone
*/
Event lastLiveEvent;
/**
* @brief The last (stabilized) painted point, center of the deadzone
*/
Event lastPaintedEvent;
/**
* @brief The last event (anywhere), used by finishStroke
*/
Event lastEvent;
/**
* @brief Tweak the stroke's pressure values upon finalizing the stroke
*/
void rebalanceStrokePressures() override;
};
/**
* @brief Class for inertial preprocessor
*
* Principle: Assign a mass to the pencil tip and simulate a spring between the tip and the pointer device.
* Friction between the tip and the paper is added by using a drag coefficient.
*
* A too small drag can lead to unwanted oscillations
*/
class Inertia: virtual public Active {
public:
Inertia(bool finalize, double drag, double mass):
Active(finalize), mass(mass), oneMinusDrag(1 - drag), speed{0.0, 0.0} {}
~Inertia() override = default;
/**
* @brief Compute stabilized coordinates for the event and paints the obtained point
* @param pos The MotionNotify event information
*/
void processEvent(const PositionInputData& pos) override;
[[maybe_unused]] auto getInfo() -> std::string override {
return "Inertia stabilizer with mass = " + std::to_string(mass) +
", drag = " + std::to_string(1 - oneMinusDrag);
}
protected:
/**
* @brief Upon initialization, record the first event for the stabilizer's benefits.
* @param pos The first event
*/
void recordFirstEvent(const PositionInputData& pos) override;
/**
* @brief Record the event corresponding to last painted point
* @param ev The event corresponding to last painted point
*/
inline void setLastPaintedEvent(const Event& ev) override { lastPaintedEvent = ev; }
/**
* @brief Get the last event received by the stabilizer
* @return The last event
*/
inline Event getLastEvent() override { return lastEvent; }
private:
/**
* @brief mass of the pen
*/
const double mass;
/**
* @brief Friction coefficient
*/
const double oneMinusDrag;
/**
* @brief Speed during the last step
*/
MathVect speed;
/**
* @brief The last (stabilized) painted point, center of the deadzone
*/
Event lastPaintedEvent;
/**
* @brief The last event (anywhere), used by finishStroke
*/
Event lastEvent;
/**
* @brief Tweak the stroke's pressure values upon finalizing the stroke
*/
void rebalanceStrokePressures() override;
};
/*****************************
* AVERAGERS *
*****************************/
/**
* @brief Class for the Velocity-based Gaussian averaging stabilizer (a.k.a. Gimp-like)
*/
class VelocityGaussian: virtual public Active {
public:
VelocityGaussian(bool finalize, double sigma): Active(finalize), twoSigmaSquared(2 * sigma * sigma) {}
~VelocityGaussian() override = default;
[[maybe_unused]] auto getInfo() -> std::string override {
return "Velocity-based gaussian weight stabilizer with "
"2σ² = " +
std::to_string(twoSigmaSquared);
}
protected:
/**
* @brief Upon initialization, record the first event for the stabilizer's benefits.
* @param pos The first event
*/
void recordFirstEvent(const PositionInputData& pos) override;
/**
* @brief Use the buffer to average the input's position and paint the resulting point
* @param ev An event to add to the mix
* @param timestamp The event's timestamp
*/
void averageAndPaint(const Event& ev, guint32 timestamp) override;
/**
* @brief For stabilizers with a buffer, clear the buffer and reinitialize it with the provided data
* @param ev New event to push to the buffer
* @param timestamp The timestamp of that event
*/
void resetBuffer(Event& ev, guint32 timestamp) override;
/**
* @brief Structure containing the event's information relevant to the VelocityGaussian stabilizer
*/
struct VelocityEvent: public Event {
VelocityEvent() = default;
VelocityEvent(double x, double y, double pressure, double velocity):
Event(x, y, pressure), velocity(velocity) {}
VelocityEvent(const PositionInputData& pos, double velocity = 0): Event(pos), velocity(velocity) {}
VelocityEvent(const Event& ev, double velocity = 0): Event(ev), velocity(velocity) {}
double velocity{};
};
/**
* @brief A queue containing the relevant information on the last events
* The beginning of the queue contains the most recent event
* The end of the queue contains the most ancient event stored
*/
std::deque<VelocityEvent> eventBuffer;
private:
/**
* @brief Get the last event received by the stabilizer
* @return The last event
*/
Event getLastEvent() override;
/**
* @brief The Gaussian parameter
*/
const double twoSigmaSquared;
/**
* @brief Timestamp of the last event received. Used to compute the velocity of the next event
*/
guint32 lastEventTimestamp;
};
class Arithmetic: virtual public Active {
public:
Arithmetic(bool finalize, size_t buffersize): Active(finalize), bufferLength(buffersize), eventBuffer(buffersize) {}
~Arithmetic() override = default;
[[maybe_unused]] auto getInfo() -> std::string override {
return "Arithmetic stabilizer with bufferLength " + std::to_string(bufferLength);
}
protected:
/**
* @brief Upon initialization, record the first event for the stabilizer's benefits.
* @param pos The first event
*/
void recordFirstEvent(const PositionInputData& pos) override;
/**
* @brief Use the buffer to average the input's position and paint the resulting point
* @param ev An event to add to the mix
* @param timestamp The event's timestamp
*/
void averageAndPaint(const Event& ev, guint32 timestamp) override;
/**
* @brief For stabilizers with a buffer, clear the buffer and reinitialize it with the provided data
* @param ev New event to push to the buffer
* @param timestamp The timestamp of that event
*/
void resetBuffer(Event& ev, guint32 timestamp) override;
/**
* @brief The maximal length of the buffer
*/
const size_t bufferLength;
/**
* @brief A circular buffer containing the relevant information on the last events
* The front of the buffer contains the most recent event
* The back of the buffer contains the most ancient event stored
*/
CircularBuffer<Event> eventBuffer;
private:
/**
* @brief Get the last event received by the stabilizer
* @return The last event received
*/
Event getLastEvent() override;
};
/*****************************
* HYBRIDS *
*****************************/
class ArithmeticDeadzone: public Arithmetic, public Deadzone {
public:
ArithmeticDeadzone(bool finalize, size_t buffersize, double dzRadius, bool cuspDetection):
Active(finalize), Arithmetic(finalize, buffersize), Deadzone(finalize, dzRadius, cuspDetection) {}
~ArithmeticDeadzone() override = default;
[[maybe_unused]] auto getInfo() -> std::string override {
return "Hybrid stabilizer:\n * " + Arithmetic::getInfo() + "\n * " + Deadzone::getInfo();
}
private:
/**
* @brief Upon initialization, record the first event for the stabilizer's benefits.
* @param pos The first event
*/
inline void recordFirstEvent(const PositionInputData& pos) override {
Arithmetic::recordFirstEvent(pos);
Deadzone::recordFirstEvent(pos);
}
/**
* @brief Get the last event received by the stabilizer
* @return The last event received
*/
inline Event getLastEvent() override { return Deadzone::getLastEvent(); }
};
class ArithmeticInertia: public Arithmetic, public Inertia {
public:
ArithmeticInertia(bool finalize, size_t buffersize, double drag, double mass):
Active(finalize), Arithmetic(finalize, buffersize), Inertia(finalize, drag, mass) {}
~ArithmeticInertia() override = default;
[[maybe_unused]] auto getInfo() -> std::string override {
return "Hybrid stabilizer:\n * " + Arithmetic::getInfo() + "\n * " + Inertia::getInfo();
}
private:
/**
* @brief Upon initialization, record the first event for the stabilizer's benefits.
* @param pos The first event
*/
inline void recordFirstEvent(const PositionInputData& pos) override {
Arithmetic::recordFirstEvent(pos);
Inertia::recordFirstEvent(pos);
}
/**
* @brief Get the last event received by the stabilizer
* @return The last event received
*/
inline Event getLastEvent() override { return Inertia::getLastEvent(); }
};
class VelocityGaussianDeadzone: public VelocityGaussian, public Deadzone {
public:
VelocityGaussianDeadzone(bool finalize, double sigma, double dzRadius, bool cuspDetection):
Active(finalize), VelocityGaussian(finalize, sigma), Deadzone(finalize, dzRadius, cuspDetection) {}
~VelocityGaussianDeadzone() override = default;
[[maybe_unused]] auto getInfo() -> std::string override {
return "Hybrid stabilizer:\n * " + VelocityGaussian::getInfo() + "\n * " + Deadzone::getInfo();
}
private:
/**
* @brief Upon initialization, record the first event for the stabilizer's benefits.
* @param pos The first event
*/
inline void recordFirstEvent(const PositionInputData& pos) override {
VelocityGaussian::recordFirstEvent(pos);
Deadzone::recordFirstEvent(pos);
}
/**
* @brief Get the last event received by the stabilizer
* @return The last event received
*/
inline Event getLastEvent() override { return Deadzone::getLastEvent(); }
};
class VelocityGaussianInertia: public VelocityGaussian, public Inertia {
public:
VelocityGaussianInertia(bool finalize, double sigma, double drag, double mass):
Active(finalize), VelocityGaussian(finalize, sigma), Inertia(finalize, drag, mass) {}
~VelocityGaussianInertia() override = default;
[[maybe_unused]] auto getInfo() -> std::string override {
return "Hybrid stabilizer:\n * " + VelocityGaussian::getInfo() + "\n * " + Inertia::getInfo();
}
private:
/**
* @brief Upon initialization, record the first event for the stabilizer's benefits.
* @param pos The first event
*/
inline void recordFirstEvent(const PositionInputData& pos) override {
VelocityGaussian::recordFirstEvent(pos);
Inertia::recordFirstEvent(pos);
}
/**
* @brief Get the last event received by the stabilizer
* @return The last event received
*/
inline Event getLastEvent() override { return Inertia::getLastEvent(); }
};
/**
* @brief Stabilizer factory: create a stabilizer of the right kind
* @param settings The Settings instance to read to determine what kind of stabilizer to create
* @return A unique point to the create stabilizer instance.
*/
std::unique_ptr<Base> get(Settings* settings);
} // namespace StrokeStabilizer
| 19,162
|
C++
|
.h
| 510
| 32.45098
| 120
| 0.676024
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,888
|
ArrowHandler.h
|
xournalpp_xournalpp/src/core/control/tools/ArrowHandler.h
|
/*
* Xournal++
*
* Handles input to draw an arrow
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <vector> // for vector
#include "model/PageRef.h" // for PageRef
#include "BaseShapeHandler.h" // for BaseShapeHandler
class Point;
class Control;
class ArrowHandler: public BaseShapeHandler {
public:
ArrowHandler(Control* control, const PageRef& page, bool doubleEnded);
~ArrowHandler() override;
private:
auto createShape(bool isAltDown, bool isShiftDown, bool isControlDown)
-> std::pair<std::vector<Point>, Range> override;
bool doubleEnded = false;
};
| 679
|
C++
|
.h
| 25
| 24.4
| 74
| 0.731066
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,889
|
LayerCtrlListener.h
|
xournalpp_xournalpp/src/core/control/layer/LayerCtrlListener.h
|
/*
* Xournal++
*
* Layer Controller listener
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
class LayerController;
class LayerCtrlListener {
public:
LayerCtrlListener();
virtual ~LayerCtrlListener();
public:
void registerListener(LayerController* handler);
void unregisterListener();
virtual void rebuildLayerMenu() = 0;
virtual void layerVisibilityChanged() = 0;
virtual void updateSelectedLayer() = 0;
private:
LayerController* handler;
};
| 558
|
C++
|
.h
| 25
| 19.44
| 52
| 0.743833
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,890
|
LayerController.h
|
xournalpp_xournalpp/src/core/control/layer/LayerController.h
|
/*
* Xournal++
*
* Handler for layer selection and hiding / showing layer
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cstddef> // for size_t
#include <list> // for list
#include <string> // for string
#include "model/DocumentChangeType.h" // for DocumentChangeType
#include "model/DocumentListener.h" // for DocumentListener
#include "model/Layer.h" // for Layer, Layer::Index
#include "model/PageRef.h" // for PageRef
class LayerCtrlListener;
class Control;
class LayerController: public DocumentListener {
public:
LayerController(Control* control);
~LayerController() override = default;
public:
void documentChanged(DocumentChangeType type) override;
void pageSelected(size_t page) override;
public:
void insertLayer(PageRef page, Layer* layer, Layer::Index layerPos);
void removeLayer(PageRef page, Layer* layer);
// Listener handling
public:
void addListener(LayerCtrlListener* listener);
void removeListener(LayerCtrlListener* listener);
void fireRebuildLayerMenu();
protected:
void fireLayerVisibilityChanged();
void fireSelectedLayerChanged();
void updateActions();
public:
/**
* Show all layer on the current page
*/
void showAllLayer();
/**
* Hide all layer on the current page
*/
void hideAllLayer();
/**
* Show / Hide all layer on the current page
*/
void showOrHideAllLayer(bool show);
void addNewLayer();
void deleteCurrentLayer();
void copyCurrentLayer();
void moveCurrentLayer(bool up);
void mergeCurrentLayerDown();
void switchToLay(Layer::Index layerId, bool hideShow = false, bool clearSelection = true);
void setLayerVisible(Layer::Index layerId, bool visible);
PageRef getCurrentPage() const;
size_t getCurrentPageId() const;
/**
* @return Layer count of the current page
*/
Layer::Index getLayerCount() const;
/**
* @return Current layer ID
*/
Layer::Index getCurrentLayerId() const;
/**
* @return Current layer name
*/
std::string getCurrentLayerName() const;
/**
* @return Get layer name by layer id
*/
std::string getLayerNameById(Layer::Index id) const;
/**
* Sets current layer name
*/
void setCurrentLayerName(const std::string& newName);
private:
Control* control;
std::list<LayerCtrlListener*> listener;
size_t selectedPage;
friend class LayerRenameUndoAction;
};
| 2,594
|
C++
|
.h
| 87
| 25.586207
| 94
| 0.698752
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,891
|
LoadHandler.h
|
xournalpp_xournalpp/src/core/control/xojfile/LoadHandler.h
|
/*
* Xournal++
*
* Loads a .xoj / .xopp document
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cstddef> // for size_t
#include <memory> // for unique_ptr
#include <optional> // for optional
#include <string> // for string
#include <vector> // for vector
#include <glib.h> // for gchar, GError, gsize, GMarkupPars...
#include <zip.h> // for zip_file_t, zip_t
#include <zipconf.h> // for zip_int64_t, zip_uint64_t
#include <zlib.h> // for gzFile
#include "model/Document.h" // for Document
#include "model/DocumentHandler.h" // for DocumentHandler
#include "model/PageRef.h" // for PageRef
#include "util/Color.h" // for Color
#include "LoadHandlerHelper.h"
#include "filesystem.h" // for path
class Image;
class Layer;
class Stroke;
class TexImage;
class Text;
enum ParserPosition {
PARSER_POS_NOT_STARTED = 1, // Waiting for opening <xounal> tag
PARSER_POS_STARTED, // Waiting for Metainfo or contents like <page>
PARSER_POS_IN_PAGE, // Starting page tag read
PARSER_POS_IN_LAYER, // Starting layer tag read
PARSER_POS_IN_STROKE, // Starting layer tag read
PARSER_POS_IN_TEXT, // Starting text tag read
PARSER_POS_IN_IMAGE, // Starting image tag read
PARSER_POS_IN_TEXIMAGE, // Starting latex tag read
PASER_POS_FINISHED // Document is parsed
};
class LoadHandler {
public:
LoadHandler();
virtual ~LoadHandler();
public:
std::unique_ptr<Document> loadDocument(fs::path const& filepath);
std::string getLastError();
bool isAttachedPdfMissing() const;
std::string getMissingPdfFilename() const;
/** @return The version of the loaded file */
int getFileVersion() const;
private:
void parseStart();
void parseContents();
void parsePage();
void parseLayer();
void parseAudio();
void parseStroke();
void parseText();
void parseImage();
void parseTexImage();
private:
void initAttributes();
std::string readLine();
zip_int64_t readContentFile(char* buffer, zip_uint64_t len);
bool closeFile();
bool openFile(fs::path const& filepath);
bool parseXml();
void fixNullPressureValues();
static void parserText(GMarkupParseContext* context, const gchar* text, gsize textLen, gpointer userdata,
GError** error);
static void parserEndElement(GMarkupParseContext* context, const gchar* elementName, gpointer userdata,
GError** error);
static void parserStartElement(GMarkupParseContext* context, const gchar* elementName, const gchar** attributeNames,
const gchar** attributeValues, gpointer userdata, GError** error);
const char* getAttrib(const char* name, bool optional = false);
double getAttribDouble(const char* name);
int getAttribInt(const char* name);
void parseBgSolid();
void parseBgPixmap();
void parseBgPdf();
void parseAttachment();
void readImage(const gchar* base64string, gsize base64stringLen);
void readTexImage(const gchar* base64string, gsize base64stringLen);
private:
static std::string parseBase64(const gchar* base64, gsize length);
/**
* Returns the contents of the zip attachment with the given file name, or
* nullopt if there is no such file.
*/
std::unique_ptr<std::string> readZipAttachment(fs::path const& filename);
fs::path getTempFileForPath(fs::path const& filename);
private:
std::string lastError;
std::string pdfMissing;
bool attachedPdfMissing;
fs::path filepath;
bool pdfFilenameParsed;
ParserPosition pos;
std::string creator;
int fileVersion;
int minimalFileVersion;
zip_t* zipFp;
zip_file_t* zipContentFile;
gzFile gzFp;
bool isGzFile = false;
std::vector<double> pressureBuffer;
std::vector<PageRef> pages;
PageRef page;
Layer* layer;
Stroke* stroke;
Text* text;
Image* image;
TexImage* teximage;
GHashTable* audioFiles = nullptr;
const char* endRootTag = "xournal";
fs::path xournalFilepath;
GError* error;
const gchar** attributeNames;
const gchar** attributeValues;
const gchar* elementName;
int loadedTimeStamp;
std::string loadedFilename;
DocumentHandler dHanlder;
std::unique_ptr<Document> doc;
friend Color LoadHandlerHelper::parseBackgroundColor(LoadHandler* loadHandler);
friend bool LoadHandlerHelper::parseColor(const char* text, Color& color, LoadHandler* loadHandler);
friend const char* LoadHandlerHelper::getAttrib(const char* name, bool optional, LoadHandler* loadHandler);
friend double LoadHandlerHelper::getAttribDouble(const char* name, LoadHandler* loadHandler);
friend int LoadHandlerHelper::getAttribInt(const char* name, LoadHandler* loadHandler);
friend bool LoadHandlerHelper::getAttribInt(const char* name, bool optional, LoadHandler* loadHandler, int& rValue);
friend size_t LoadHandlerHelper::getAttribSizeT(const char* name, LoadHandler* loadHandler);
friend bool LoadHandlerHelper::getAttribSizeT(const char* name, bool optional, LoadHandler* loadHandler,
size_t& rValue);
};
| 5,394
|
C++
|
.h
| 137
| 34.255474
| 120
| 0.697202
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,892
|
SaveHandler.h
|
xournalpp_xournalpp/src/core/control/xojfile/SaveHandler.h
|
/*
* Xournal++
*
* Saves a document
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <memory> // for unique_ptr
#include <string> // for string
#include <vector> // for vector
#include "control/xml/XmlNode.h" // for XmlNode
#include "model/BackgroundImage.h" // for BackgroundImage
#include "model/PageRef.h" // for PageRef
#include "util/Color.h" // for Color
#include "filesystem.h" // for path
class XmlPointNode;
class ProgressListener;
class AudioElement;
class Document;
class Layer;
class OutputStream;
class Stroke;
class XmlAudioNode;
class SaveHandler {
public:
SaveHandler();
public:
void prepareSave(Document* doc);
void saveTo(const fs::path& filepath, ProgressListener* listener = nullptr);
void saveTo(OutputStream* out, const fs::path& filepath, ProgressListener* listener = nullptr);
std::string getErrorMessage();
protected:
static std::string getColorStr(Color c, unsigned char alpha = 0xff);
virtual void visitPage(XmlNode* root, PageRef p, Document* doc, int id);
virtual void visitLayer(XmlNode* page, Layer* l);
virtual void visitStroke(XmlPointNode* stroke, Stroke* s);
/**
* Export the fill attributes
*/
virtual void visitStrokeExtended(XmlPointNode* stroke, Stroke* s);
virtual void writeHeader();
virtual void writeSolidBackground(XmlNode* background, PageRef p);
virtual void writeTimestamp(AudioElement* audioElement, XmlAudioNode* xmlAudioNode);
virtual void writeBackgroundName(XmlNode* background, PageRef p);
protected:
std::unique_ptr<XmlNode> root{};
bool firstPdfPageVisited;
int attachBgId;
std::string errorMessage;
std::vector<BackgroundImage> backgroundImages{};
};
| 1,825
|
C++
|
.h
| 55
| 30.127273
| 99
| 0.736902
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,893
|
XojExportHandler.h
|
xournalpp_xournalpp/src/core/control/xojfile/XojExportHandler.h
|
/*
* Xournal++
*
* Export a document for as .xoj compatible for Xournal,
* remove all additional features which break the compatibility
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include "model/PageRef.h" // for PageRef
#include "SaveHandler.h" // for SaveHandler
class AudioElement;
class Stroke;
class XmlAudioNode;
class XmlNode;
class XmlPointNode;
class XojExportHandler: public SaveHandler {
public:
XojExportHandler();
virtual ~XojExportHandler();
protected:
/**
* Export the fill attributes
*/
void visitStrokeExtended(XmlPointNode* stroke, Stroke* s) override;
void writeHeader() override;
void writeSolidBackground(XmlNode* background, PageRef p) override;
void writeTimestamp(AudioElement* audioElement, XmlAudioNode* xmlAudioNode) override;
void writeBackgroundName(XmlNode* background, PageRef p) override;
private:
};
| 968
|
C++
|
.h
| 34
| 25.705882
| 89
| 0.765659
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,894
|
LoadHandlerHelper.h
|
xournalpp_xournalpp/src/core/control/xojfile/LoadHandlerHelper.h
|
/*
* Xournal++
*
* helper methods to load a .xoj / .xopp document
*
* @author Xournal Team
* http://xournal.sf.net
*
* @license GPL
*/
#pragma once
#include <cstddef> // for size_t
#include "util/Color.h" // for Color
class LoadHandler;
namespace LoadHandlerHelper {
Color parseBackgroundColor(LoadHandler* loadHandler);
bool parseColor(const char* text, Color& color, LoadHandler* loadHandler);
const char* getAttrib(const char* name, bool optional, LoadHandler* loadHandler);
double getAttribDouble(const char* name, LoadHandler* loadHandler);
int getAttribInt(const char* name, LoadHandler* loadHandler);
bool getAttribInt(const char* name, bool optional, LoadHandler* loadHandler, int& rValue);
size_t getAttribSizeT(const char* name, LoadHandler* loadHandler);
bool getAttribSizeT(const char* name, bool optional, LoadHandler* loadHandler, size_t& rValue);
}; // namespace LoadHandlerHelper
| 914
|
C++
|
.h
| 24
| 36.458333
| 95
| 0.779412
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,895
|
Settings.h
|
xournalpp_xournalpp/src/core/control/settings/Settings.h
|
/*
* Xournal++
*
* Xournal Settings
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <array> // for array
#include <cstddef> // for size_t
#include <map> // for map
#include <memory> // for make_shared, shared_ptr
#include <optional> // for optional
#include <string> // for string, basic_string
#include <utility> // for pair
#include <vector> // for vector
#include <gdk/gdk.h> // for GdkInputSource, GdkD...
#include <glib.h> // for gchar, gboolean, gint
#include <libxml/tree.h> // for xmlNodePtr, xmlDocPtr
#include <portaudiocpp/PortAudioCpp.hxx> // for PaDeviceIndex
#include "control/tools/StrokeStabilizerEnum.h" // for AveragingMethod, Pre...
#include "model/Font.h" // for XojFont
#include "util/Color.h" // for Color
#include "LatexSettings.h" // for LatexSettings
#include "SettingsEnums.h" // for InputDeviceTypeOption
#include "ViewModes.h" // for ViewModes
#include "filesystem.h" // for path
struct Palette;
constexpr auto DEFAULT_GRID_SIZE = 14.17;
constexpr unsigned int MAX_SPACES_FOR_TAB = 8U;
class ButtonConfig;
class InputDevice;
class SAttribute {
public:
SAttribute();
SAttribute(const SAttribute& attrib);
virtual ~SAttribute();
public:
std::string sValue;
int iValue{};
double dValue{};
AttributeType type;
std::string comment;
};
class SElement final {
struct SElementData {
private:
std::map<std::string, SAttribute> attributes;
std::map<std::string, SElement> children;
friend class SElement;
};
public:
SElement() = default;
void clear();
SElement& child(const std::string& name);
void setIntHex(const std::string& name, const int value);
void setInt(const std::string& name, const int value);
void setDouble(const std::string& name, const double value);
void setBool(const std::string& name, const bool value);
void setString(const std::string& name, const std::string& value);
[[maybe_unused]] void setComment(const std::string& name, const std::string& comment);
bool getInt(const std::string& name, int& value);
[[maybe_unused]] bool getDouble(const std::string& name, double& value);
bool getBool(const std::string& name, bool& value);
bool getString(const std::string& name, std::string& value);
std::map<std::string, SAttribute>& attributes();
std::map<std::string, SElement>& children();
private:
std::shared_ptr<SElementData> element = std::make_shared<SElementData>();
};
class Settings {
public:
/*[[implicit]]*/ Settings(fs::path filepath);
Settings(const Settings& settings) = delete;
void operator=(const Settings& settings) = delete;
virtual ~Settings();
public:
bool load();
void parseData(xmlNodePtr cur, SElement& elem);
void save();
private:
void loadDefault();
void parseItem(xmlDocPtr doc, xmlNodePtr cur);
static xmlNodePtr savePropertyDouble(const gchar* key, double value, xmlNodePtr parent);
static xmlNodePtr saveProperty(const gchar* key, int value, xmlNodePtr parent);
static xmlNodePtr savePropertyUnsigned(const gchar* key, unsigned int value, xmlNodePtr parent);
static xmlNodePtr saveProperty(const gchar* key, const gchar* value, xmlNodePtr parent);
void saveData(xmlNodePtr root, const std::string& name, SElement& elem);
void saveButtonConfig();
void loadButtonConfig();
public:
// View Mode
bool loadViewMode(ViewModeId mode);
// Getter- / Setter
const std::vector<ViewMode>& getViewModes() const;
ViewModeId getActiveViewMode() const;
bool isPressureSensitivity() const;
void setPressureSensitivity(gboolean presureSensitivity);
/**
* Input device pressure options
*/
double getMinimumPressure() const;
void setMinimumPressure(double minimumPressure);
double getPressureMultiplier() const;
void setPressureMultiplier(double multiplier);
/**
* Getter, enable/disable
*/
bool isZoomGesturesEnabled() const;
void setZoomGesturesEnabled(bool enable);
/**
* The last used font
*/
XojFont& getFont();
void setFont(const XojFont& font);
/**
* The selected Toolbar
*/
void setSelectedToolbar(const std::string& name);
std::string const& getSelectedToolbar() const;
void setEdgePanSpeed(double speed);
double getEdgePanSpeed() const;
void setEdgePanMaxMult(double mult);
double getEdgePanMaxMult() const;
/**
* Set the Zoomstep for one step in percent
*/
void setZoomStep(double zoomStep);
double getZoomStep() const;
/**
* Set the Zoomstep for Ctrl + Scroll in percent
*/
void setZoomStepScroll(double zoomStepScroll);
double getZoomStepScroll() const;
/**
* Sets the screen resolution in DPI
*/
void setDisplayDpi(int dpi);
int getDisplayDpi() const;
void setAreStockIconsUsed(bool use);
bool areStockIconsUsed() const;
/**
* The last saved path
*/
void setLastSavePath(fs::path p);
fs::path const& getLastSavePath() const;
/**
* The last open path
*/
void setLastOpenPath(fs::path p);
fs::path const& getLastOpenPath() const;
void setLastImagePath(const fs::path& p);
fs::path const& getLastImagePath() const;
void setMainWndSize(int width, int height);
void setMainWndMaximized(bool max);
int getMainWndWidth() const;
int getMainWndHeight() const;
bool isMainWndMaximized() const;
bool isFullscreen() const;
bool isSidebarVisible() const;
void setSidebarVisible(bool visible);
bool isToolbarVisible() const;
void setToolbarVisible(bool visible);
int getSidebarWidth() const;
void setSidebarWidth(int width);
bool isSidebarOnRight() const;
void setSidebarOnRight(bool right);
bool isScrollbarOnLeft() const;
void setScrollbarOnLeft(bool right);
bool isMenubarVisible() const;
void setMenubarVisible(bool visible);
const bool isFilepathInTitlebarShown() const;
void setFilepathInTitlebarShown(const bool shown);
const bool isPageNumberInTitlebarShown() const;
void setPageNumberInTitlebarShown(const bool shown);
void setShowPairedPages(bool showPairedPages);
bool isShowPairedPages() const;
void setPresentationMode(bool presentationMode);
bool isPresentationMode() const;
void setPairsOffset(int numOffset);
int getPairsOffset() const;
void setEmptyLastPageAppend(EmptyLastPageAppendType emptyLastPageAppend);
EmptyLastPageAppendType getEmptyLastPageAppend() const;
void setViewColumns(int numColumns);
int getViewColumns() const;
void setViewRows(int numRows);
int getViewRows() const;
void setViewFixedRows(bool viewFixedRows);
bool isViewFixedRows() const;
void setViewLayoutVert(bool vert);
bool getViewLayoutVert() const;
void setViewLayoutR2L(bool r2l);
bool getViewLayoutR2L() const;
void setViewLayoutB2T(bool b2t);
bool getViewLayoutB2T() const;
bool isAutoloadMostRecent() const;
void setAutoloadMostRecent(bool load);
bool isAutoloadPdfXoj() const;
void setAutoloadPdfXoj(bool load);
int getAutosaveTimeout() const;
void setAutosaveTimeout(int autosave);
bool isAutosaveEnabled() const;
void setAutosaveEnabled(bool autosave);
bool getAddVerticalSpace() const;
void setAddVerticalSpace(bool space);
int getAddVerticalSpaceAmountAbove() const;
void setAddVerticalSpaceAmountAbove(int pixels);
int getAddVerticalSpaceAmountBelow() const;
void setAddVerticalSpaceAmountBelow(int pixels);
bool getAddHorizontalSpace() const;
void setAddHorizontalSpace(bool space);
int getAddHorizontalSpaceAmountRight() const;
void setAddHorizontalSpaceAmountRight(int pixels);
int getAddHorizontalSpaceAmountLeft() const;
void setAddHorizontalSpaceAmountLeft(int pixels);
bool getUnlimitedScrolling() const;
void setUnlimitedScrolling(bool enable);
bool getDrawDirModsEnabled() const;
void setDrawDirModsEnabled(bool enable);
int getDrawDirModsRadius() const;
void setDrawDirModsRadius(int pixels);
bool getTouchDrawingEnabled() const;
void setTouchDrawingEnabled(bool b);
bool getGtkTouchInertialScrollingEnabled() const;
void setGtkTouchInertialScrollingEnabled(bool b);
bool isPressureGuessingEnabled() const;
void setPressureGuessingEnabled(bool b);
bool isSnapRotation() const;
void setSnapRotation(bool b);
double getSnapRotationTolerance() const;
void setSnapRotationTolerance(double tolerance);
bool isSnapGrid() const;
void setSnapGrid(bool b);
double getSnapGridTolerance() const;
void setSnapGridTolerance(double tolerance);
double getSnapGridSize() const;
void setSnapGridSize(double gridSize);
double getStrokeRecognizerMinSize() const;
void setStrokeRecognizerMinSize(double value);
StylusCursorType getStylusCursorType() const;
void setStylusCursorType(StylusCursorType stylusCursorType);
EraserVisibility getEraserVisibility() const;
void setEraserVisibility(EraserVisibility eraserVisibility);
IconTheme getIconTheme() const;
void setIconTheme(IconTheme iconTheme);
void setThemeVariant(ThemeVariant theme);
ThemeVariant getThemeVariant() const;
SidebarNumberingStyle getSidebarNumberingStyle() const;
void setSidebarNumberingStyle(SidebarNumberingStyle numberingStyle);
bool isHighlightPosition() const;
void setHighlightPosition(bool highlight);
Color getCursorHighlightColor() const;
void setCursorHighlightColor(Color color);
double getCursorHighlightRadius() const;
void setCursorHighlightRadius(double radius);
Color getCursorHighlightBorderColor() const;
void setCursorHighlightBorderColor(Color color);
double getCursorHighlightBorderWidth() const;
void setCursorHighlightBorderWidth(double width);
ScrollbarHideType getScrollbarHideType() const;
void setScrollbarHideType(ScrollbarHideType type);
bool isScrollbarFadeoutDisabled() const;
void setScrollbarFadeoutDisabled(bool disable);
bool isAudioDisabled() const;
void setAudioDisabled(bool disable);
std::string const& getDefaultSaveName() const;
void setDefaultSaveName(const std::string& name);
std::string const& getDefaultPdfExportName() const;
void setDefaultPdfExportName(const std::string& name);
ButtonConfig* getButtonConfig(unsigned int id);
void setViewMode(ViewModeId mode, ViewMode ViewMode);
Color getBorderColor() const;
void setBorderColor(Color color);
Color getSelectionColor() const;
void setSelectionColor(Color color);
Color getBackgroundColor() const;
void setBackgroundColor(Color color);
Color getActiveSelectionColor() const;
void setActiveSelectionColor(Color color);
// Re-render pages if document zoom differs from the last render zoom by the given threshold.
double getPDFPageRerenderThreshold() const;
void setPDFPageRerenderThreshold(double threshold);
double getTouchZoomStartThreshold() const;
void setTouchZoomStartThreshold(double threshold);
int getPdfPageCacheSize() const;
[[maybe_unused]] void setPdfPageCacheSize(int size);
unsigned int getPreloadPagesBefore() const;
void setPreloadPagesBefore(unsigned int n);
unsigned int getPreloadPagesAfter() const;
void setPreloadPagesAfter(unsigned int n);
bool isEagerPageCleanup() const;
void setEagerPageCleanup(bool b);
std::string const& getPageTemplate() const;
void setPageTemplate(const std::string& pageTemplate);
fs::path const& getAudioFolder() const;
void setAudioFolder(fs::path audioFolder);
static constexpr PaDeviceIndex AUDIO_INPUT_SYSTEM_DEFAULT = -1;
PaDeviceIndex getAudioInputDevice() const;
void setAudioInputDevice(PaDeviceIndex deviceIndex);
static constexpr PaDeviceIndex AUDIO_OUTPUT_SYSTEM_DEFAULT = -1;
PaDeviceIndex getAudioOutputDevice() const;
void setAudioOutputDevice(PaDeviceIndex deviceIndex);
double getAudioSampleRate() const;
void setAudioSampleRate(double sampleRate);
double getAudioGain() const;
void setAudioGain(double gain);
unsigned int getDefaultSeekTime() const;
void setDefaultSeekTime(unsigned int t);
std::string const& getPluginEnabled() const;
void setPluginEnabled(const std::string& pluginEnabled);
std::string const& getPluginDisabled() const;
void setPluginDisabled(const std::string& pluginDisabled);
/**
* Sets #numIgnoredStylusEvents. If given a negative value writes 0 instead.
*/
void setIgnoredStylusEvents(int numEvents);
/**
* Returns #numIgnoredStylusEvents.
*/
int getIgnoredStylusEvents() const;
bool getInputSystemTPCButtonEnabled() const;
void setInputSystemTPCButtonEnabled(bool tpcButtonEnabled);
bool getInputSystemDrawOutsideWindowEnabled() const;
void setInputSystemDrawOutsideWindowEnabled(bool drawOutsideWindowEnabled);
void loadDeviceClasses();
void saveDeviceClasses();
void setDeviceClassForDevice(GdkDevice* device, InputDeviceTypeOption deviceClass);
void setDeviceClassForDevice(const std::string& deviceName, GdkInputSource deviceSource,
InputDeviceTypeOption deviceClass);
InputDeviceTypeOption getDeviceClassForDevice(GdkDevice* device) const;
InputDeviceTypeOption getDeviceClassForDevice(const std::string& deviceName, GdkInputSource deviceSource) const;
std::vector<InputDevice> getKnownInputDevices() const;
/**
* Get name, e.g. "cm"
*/
std::string const& getSizeUnit() const;
/**
* Get size index in XOJ_UNITS
*/
int getSizeUnitIndex() const;
/**
* Set Unit, e.g. "cm"
*/
void setSizeUnit(const std::string& sizeUnit);
/**
* Set size index in XOJ_UNITS
*/
void setSizeUnitIndex(int sizeUnitId);
/**
* Set StrokeFilter enabled
*/
void setStrokeFilterEnabled(bool enabled);
/**
* Get StrokeFilter enabled
*/
bool getStrokeFilterEnabled() const;
/**
* get strokeFilter settings
*/
void getStrokeFilter(int* strokeFilterIgnoreTime, double* strokeFilterIgnoreLength,
int* strokeFilterSuccessiveTime) const;
/**
* configure stroke filter
*/
void setStrokeFilter(int strokeFilterIgnoreTime, double strokeFilterIgnoreLength, int strokeFilterSuccessiveTime);
/**
* Set DoActionOnStrokeFilter enabled
*/
void setDoActionOnStrokeFiltered(bool enabled);
/**
* Get DoActionOnStrokeFilter enabled
*/
bool getDoActionOnStrokeFiltered() const;
/**
* Set TrySelectOnStrokeFilter enabled
*/
void setTrySelectOnStrokeFiltered(bool enabled);
/**
* Get TrySelectOnStrokeFilter enabled
*/
bool getTrySelectOnStrokeFiltered() const;
/**
* Set snap recognized shapes enabled
*/
void setSnapRecognizedShapesEnabled(bool enabled);
/**
* Get snap recognized shapes enabled
*/
bool getSnapRecognizedShapesEnabled() const;
/**
* Set line width restoring for resized edit selctions enabled
*/
void setRestoreLineWidthEnabled(bool enabled);
/**
* Get line width restoring enabled
*/
bool getRestoreLineWidthEnabled() const;
/**
* Set the preferred locale
*/
void setPreferredLocale(std::string const& locale);
/**
* Get the preferred locale
*/
std::string getPreferredLocale() const;
/**
* Stabilizer related getters and setters
*/
bool getStabilizerCuspDetection() const;
bool getStabilizerFinalizeStroke() const;
size_t getStabilizerBuffersize() const;
double getStabilizerDeadzoneRadius() const;
double getStabilizerDrag() const;
double getStabilizerMass() const;
double getStabilizerSigma() const;
StrokeStabilizer::AveragingMethod getStabilizerAveragingMethod() const;
StrokeStabilizer::Preprocessor getStabilizerPreprocessor() const;
void setStabilizerCuspDetection(bool cuspDetection);
void setStabilizerFinalizeStroke(bool finalizeStroke);
void setStabilizerBuffersize(size_t buffersize);
void setStabilizerDeadzoneRadius(double deadzoneRadius);
void setStabilizerDrag(double drag);
void setStabilizerMass(double mass);
void setStabilizerSigma(double sigma);
void setStabilizerAveragingMethod(StrokeStabilizer::AveragingMethod averagingMethod);
void setStabilizerPreprocessor(StrokeStabilizer::Preprocessor preprocessor);
fs::path const& getColorPaletteSetting();
void setColorPaletteSetting(fs::path palettePath);
void setNumberOfSpacesForTab(unsigned int numberSpaces);
unsigned int getNumberOfSpacesForTab() const;
void setUseSpacesAsTab(bool useSpaces);
bool getUseSpacesAsTab() const;
public:
// Custom settings
SElement& getCustomElement(const std::string& name);
/**
* Call this after you have done all custom settings changes
*/
void customSettingsChanged();
/**
* Do not save settings until transactionEnd() is called
*/
void transactionStart();
/**
* Stop transaction and save settings
*/
void transactionEnd();
LatexSettings latexSettings{};
private:
/**
* The config filepath
*/
fs::path filepath;
private:
/**
* The settings tree
*/
std::map<std::string, SElement> data;
/**
* Use pen pressure to control stroke width?
*/
bool pressureSensitivity{};
/**
* Adjust input pressure?
*/
double minimumPressure{};
double pressureMultiplier{};
/**
* If the touch zoom gestures are enabled
*/
bool zoomGesturesEnabled{};
/**
* If fullscreen is active
*/
bool fullscreenActive{};
/**
* If the sidebar is visible
*/
bool showSidebar{};
/**
* If the sidebar is visible
*/
bool showToolbar{};
/**
* The Width of the Sidebar
*/
int sidebarWidth{};
/**
* If the sidebar is on the right
*/
bool sidebarOnRight{};
/**
* Type of cursor icon to use with a stylus
*/
StylusCursorType stylusCursorType;
/**
* Visibility of eraser cursor
*/
EraserVisibility eraserVisibility;
/**
* Icon Theme
*/
IconTheme iconTheme;
/**
* Follow system's default theme variant or force one or the other
*/
ThemeVariant themeVariant;
/**
* Sidebar page number style
*/
SidebarNumberingStyle sidebarNumberingStyle;
/**
* Show a colored circle around the cursor
*/
bool highlightPosition{};
/**
* Cursor highlight color (ARGB format)
*/
Color cursorHighlightColor{};
/**
* Radius of cursor highlight circle. Note that this is limited by the size
* of the cursor in the display server (default is probably 30 pixels).
*/
double cursorHighlightRadius{};
/**
* Cursor highlight border color (ARGB format)
*/
Color cursorHighlightBorderColor{};
/**
* Width of cursor highlight border, in pixels.
*/
double cursorHighlightBorderWidth{};
/**
* If stock icons are used instead of Xournal++ icons when available
*/
bool useStockIcons{};
/**
* If the menu bar is visible on startup
*/
bool menubarVisible{};
/**
* If the filepath is shown in titlebar
*/
bool filepathShownInTitlebar{};
/**
* If the page number is shown in titlebar
*/
bool pageNumberShownInTitlebar{};
/**
* Hide the scrollbar
*/
ScrollbarHideType scrollbarHideType;
/**
* Disable scrollbar fade out (overlay scrolling)
*/
bool disableScrollbarFadeout{};
/**
* Disable the audio system
*/
bool disableAudio{};
/**
* The selected Toolbar name
*/
std::string selectedToolbar;
/**
* The last saved folder
*/
fs::path lastSavePath;
/**
* The last opened folder
*/
fs::path lastOpenPath;
/**
* The last "insert image" folder
*/
fs::path lastImagePath;
/**
* The last used font
*/
XojFont font;
/**
* Base speed (as a percentage of visible canvas) of edge pan per
* second
*/
double edgePanSpeed{};
/**
* Maximum multiplier of edge pan speed due to proportion of selection out
* of view
*/
double edgePanMaxMult{};
/**
* Zoomstep for one step
*/
double zoomStep{};
/**
* Zoomstep for Ctrl + Scroll zooming
*/
double zoomStepScroll{};
/**
* The display resolution, in pixels per inch
*/
gint displayDpi{};
/**
* If the window is maximized
*/
bool maximized{};
/**
* Width of the main window
*/
int mainWndWidth{};
/**
* Height of the main window
*/
int mainWndHeight{};
/**
* Show the scrollbar on the left side
*/
bool scrollbarOnLeft{};
/**
* Pairs pages
*/
bool showPairedPages{};
/**
* Sets presentation mode
*/
bool presentationMode{};
/**
* Offsets first page ( to align pairing )
*/
int numPairsOffset{};
/**
* Preference for appending an empty last page to the document
*/
EmptyLastPageAppendType emptyLastPageAppend{};
/**
* Use when fixed number of columns
*/
int numColumns{};
/**
* Use when fixed number of rows
*/
int numRows{};
/**
* USE fixed rows, otherwise fixed columns
*/
bool viewFixedRows{};
/**
* Layout Vertical then Horizontal
*/
bool layoutVertical{};
/**
* Layout pages right to left
*/
bool layoutRightToLeft{};
/**
* Layout Bottom to Top
*/
bool layoutBottomToTop{};
/**
* Automatically load filename.pdf.xoj / .pdf.xopp instead of filename.pdf (true/false)
*/
bool autoloadPdfXoj{};
/**
* Automatically load most recent document on application startup (true/false)
*/
bool autoloadMostRecent{};
/**
* Automatically save documents for crash recovery each x minutes
*/
int autosaveTimeout{};
/**
* Enable automatic save
*/
bool autosaveEnabled{};
/**
* Allow scroll outside the page display area (horizontal)
*/
bool addHorizontalSpace{};
/**
* How much allowance to scroll outside the page display area on the right
*/
int addHorizontalSpaceAmountRight{};
/**
* How much allowance to scroll outside the page display area on the left
*/
int addHorizontalSpaceAmountLeft{};
/**
* Allow scroll outside the page display area (vertical)
*/
bool addVerticalSpace{};
/**
* How much allowance to scroll outside the page display area above
*/
int addVerticalSpaceAmountAbove{};
/**
* How much allowance to scroll outside the page display area below
*/
int addVerticalSpaceAmountBelow{};
/**
* Enables unlimited scrolling, which automatically adds maximum space to scroll outside the page
*/
bool unlimitedScrolling{};
/**
* Emulate modifier keys based on initial direction of drawing tool ( for Rectangle, Ellipse etc. )
*/
bool drawDirModsEnabled{};
/**
* Radius at which emulated modifiers are locked on for the rest of drawing operation
*/
int drawDirModsRadius{};
/**
* Rotation snapping enabled by default
*/
bool snapRotation{};
/**
* grid snapping enabled by default
*/
bool snapGrid{};
/**
* Default name if you save a new document
*/
std::string defaultSaveName; // should be string - don't change to path
std::string defaultPdfExportName;
/**
* The button config
*/
std::array<std::unique_ptr<ButtonConfig>, BUTTON_COUNT> buttonConfig;
/**
* View-modes. Predefined: 0=default, 1=fullscreen, 2=presentation
*/
ViewModeId activeViewMode;
std::vector<ViewMode> viewModes;
/**
* The count of pages which will be cached
*/
int pdfPageCacheSize{};
/**
* Percentage by which the page's zoom must change
* for PDF pages to re-render while zooming.
*/
double pageRerenderThreshold{};
/**
* Don't start zooming with touch until the difference in distances between the
* current touch points and the original is greater than this percentage of the
* original distance.
*/
double touchZoomStartThreshold{};
/**
* The color to draw borders on selected elements
* (Page, insert image selection etc.)
*/
Color selectionBorderColor{};
/**
* Color for Text selection, Stroke selection etc.
*/
Color selectionMarkerColor{};
/**
* Color for active selection.
*/
Color activeSelectionColor{};
/**
* The color for Xournal page background
*/
Color backgroundColor{};
/**
* Page template String
*/
std::string pageTemplate;
/**
* Unit, see XOJ_UNITS
*/
std::string sizeUnit;
/**
* Audio folder for audio recording
*/
fs::path audioFolder;
/**
* Snap tolerance for the graph/dotted grid
*/
double snapGridTolerance{};
/**
* Rotation epsilon for rotation snapping feature
*/
double snapRotationTolerance{};
/// Grid size for Snapping
double snapGridSize{};
/**
* Minimum size of stroke to detect shape
*/
double strokeRecognizerMinSize{};
/// Touchscreens act like multi-touch-aware pens.
bool touchDrawing{};
/// True iff we use GTK's built-in kinetic/inertial scrolling
/// for touchscreen devices. If false, we use our own.
bool gtkTouchInertialScrolling{};
/**
* Infer pressure from speed when device pressure
* is unavailable (e.g. drawing with a mouse).
*/
bool pressureGuessing{};
/**
* The index of the audio device used for recording
*/
PaDeviceIndex audioInputDevice{};
/**
* The index of the audio device used for playback
*/
PaDeviceIndex audioOutputDevice{};
/**
* The sample rate used for recording
*/
double audioSampleRate{};
/**
* The gain by which to amplify the recorded audio samples
*/
double audioGain{};
/**
* The default time by which the playback will seek backwards and forwards
*/
unsigned int defaultSeekTime{};
/**
* List of enabled plugins (only the one which are not enabled by default)
*/
std::string pluginEnabled;
/**
* List of disabled plugins (only the one which are not disabled by default)
*/
std::string pluginDisabled;
/**
* Used to filter strokes of short time and length unless successive in order to do something else ( i.e. select
* object, float Toolbox menu ). strokeFilterIgnoreLength this many mm ( double ) strokeFilterIgnoreTime
* within this time (ms) will be ignored.. strokeFilterSuccessiveTime ...unless successive within this time.
*/
int strokeFilterIgnoreTime{};
double strokeFilterIgnoreLength{};
int strokeFilterSuccessiveTime{};
bool strokeFilterEnabled{};
bool doActionOnStrokeFiltered{};
bool trySelectOnStrokeFiltered{};
/**
* Whether snapping for recognized shapes is enabled
*/
bool snapRecognizedShapesEnabled{};
/**
* Whether the line width should be preserved in a resizing operation
*/
bool restoreLineWidthEnabled{};
/**
* How many stylus events since hitting the screen should be ignored before actually starting the action. If set to
* 0, no event will be ignored. Should not be negative.
*/
int numIgnoredStylusEvents{};
/**
* Whether Wacom parameter TabletPCButton is enabled
*/
bool inputSystemTPCButton{};
bool inputSystemDrawOutsideWindow{};
std::map<std::string, std::pair<InputDeviceTypeOption, GdkInputSource>> inputDeviceClasses = {};
/**
* "Transaction" running, do not save until the end is reached
*/
bool inTransaction{};
/** The preferred locale as its language code
* e.g. "en_US"
*/
std::string preferredLocale;
/**
* The number of pages to pre-load before the current page.
*/
unsigned int preloadPagesBefore{};
/**
* The number of pages to pre-load after the current page.
*/
unsigned int preloadPagesAfter{};
/**
* Whether to evict from the page buffer cache when scrolling.
*/
bool eagerPageCleanup{};
/**
* Stabilizer related settings
*/
bool stabilizerCuspDetection{};
bool stabilizerFinalizeStroke{};
size_t stabilizerBuffersize{};
double stabilizerDeadzoneRadius{};
double stabilizerDrag{};
double stabilizerMass{};
double stabilizerSigma{};
StrokeStabilizer::AveragingMethod stabilizerAveragingMethod{};
StrokeStabilizer::Preprocessor stabilizerPreprocessor{};
fs::path colorPaletteSetting;
/**
* Tab control settings
*/
bool useSpacesForTab{};
unsigned int numberOfSpacesForTab{};
};
| 29,754
|
C++
|
.h
| 900
| 27.612222
| 119
| 0.69701
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,896
|
PageTemplateSettings.h
|
xournalpp_xournalpp/src/core/control/settings/PageTemplateSettings.h
|
/*
* Xournal++
*
* Page template settings handler
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <optional>
#include <string> // for string
#include "model/PageType.h" // for PageType
#include "util/Color.h" // for Color
class PageTemplateSettings {
public:
PageTemplateSettings();
virtual ~PageTemplateSettings();
public:
/**
* Parse a template string
*
* @return true if valid
*/
bool parse(const std::string& tpl);
/**
* Convert to a parsable string
*/
std::string toString() const;
bool isCopyLastPageSettings() const;
void setCopyLastPageSettings(bool copyLastPageSettings);
bool isCopyLastPageSize() const;
void setCopyLastPageSize(bool copyLastPageSize);
double getPageWidth() const;
void setPageWidth(double pageWidth);
double getPageHeight() const;
void setPageHeight(double pageHeight);
Color getBackgroundColor() const;
void setBackgroundColor(Color backgroundColor);
PageType getBackgroundType();
std::optional<PageType> getPageInsertType();
void setBackgroundType(const PageType& backgroundType);
private:
/**
* Copy the settings from the last page
*/
bool copyLastPageSettings;
/**
* Copy the last page size
*/
bool copyLastPageSize;
double pageWidth;
double pageHeight;
/**
* Background color in RGB
*/
Color backgroundColor;
/**
* Background type
*/
PageType backgroundType;
};
| 1,592
|
C++
|
.h
| 63
| 20.888889
| 60
| 0.695566
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,897
|
LatexSettings.h
|
xournalpp_xournalpp/src/core/control/settings/LatexSettings.h
|
/*
* Xournal++
*
* Latex settings
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string>
#include "model/Font.h"
#include "filesystem.h"
class LatexSettings {
public:
bool autoCheckDependencies{true};
std::string defaultText{"x^2"};
fs::path globalTemplatePath{};
#ifdef __APPLE__
std::string genCmd{"/Library/TeX/texbin/pdflatex -halt-on-error -interaction=nonstopmode '{}'"};
#else
std::string genCmd{"pdflatex -halt-on-error -interaction=nonstopmode '{}'"};
#endif
/**
* LaTeX editor theme. Only used if linked with the GtkSourceView
* library.
*/
std::string sourceViewThemeId{};
bool sourceViewAutoIndent{true};
bool sourceViewSyntaxHighlight{true};
bool sourceViewShowLineNumbers{false};
/**
* Font to be used by the editor.
*/
XojFont editorFont{"Monospace", 12};
bool useCustomEditorFont{false};
bool editorWordWrap{true};
};
| 1,010
|
C++
|
.h
| 39
| 22.410256
| 100
| 0.701245
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,898
|
MetadataManager.h
|
xournalpp_xournalpp/src/core/control/settings/MetadataManager.h
|
/*
* Xournal++
*
* Last opened files with all settings
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <mutex> // for mutex
#include <vector> // for vector
#include <glib.h> // for gint64
#include "filesystem.h" // for path
class MetadataEntry {
public:
MetadataEntry();
public:
fs::path metadataFile;
bool valid;
fs::path path;
double zoom;
int page;
gint64 time;
};
class MetadataManager {
public:
MetadataManager() = default;
virtual ~MetadataManager();
public:
/**
* Get the metadata for a file
*/
static MetadataEntry getForFile(fs::path const& file);
/**
* Store the current data into metadata
*/
void storeMetadata(fs::path const& file, int page, double zoom);
/**
* Document was closed, a new document was opened etc.
*/
void documentChanged();
private:
/**
* Delete an old metadata file
*/
static void deleteMetadataFile(fs::path const& path);
/**
* Parse a single metadata file
*/
static MetadataEntry loadMetadataFile(fs::path const& path, fs::path const& file);
/**
* Store metadata to file
*/
static void storeMetadata(const MetadataEntry& m);
private:
/**
* Load the metadata list (sorted)
*/
static std::vector<MetadataEntry> loadList();
private:
std::mutex mutex;
std::unique_ptr<MetadataEntry> metadata;
};
| 1,501
|
C++
|
.h
| 65
| 19.092308
| 86
| 0.661268
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,899
|
SettingsEnums.h
|
xournalpp_xournalpp/src/core/control/settings/SettingsEnums.h
|
/*
* Xournal++
*
* Enum definition used for tools
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string> // for string
/**
* @brief Buttons that can have a configuration attached to them
* Used for ButtonConfig and ToolHandler
*
*/
enum Button {
BUTTON_ERASER,
BUTTON_MOUSE_MIDDLE,
BUTTON_MOUSE_RIGHT,
BUTTON_TOUCH,
BUTTON_DEFAULT,
BUTTON_STYLUS_ONE,
BUTTON_STYLUS_TWO,
BUTTON_COUNT
};
enum AttributeType {
ATTRIBUTE_TYPE_NONE,
ATTRIBUTE_TYPE_STRING,
ATTRIBUTE_TYPE_INT,
ATTRIBUTE_TYPE_DOUBLE,
ATTRIBUTE_TYPE_INT_HEX,
ATTRIBUTE_TYPE_BOOLEAN,
};
// use this as a bit flag
enum ScrollbarHideType {
SCROLLBAR_HIDE_NONE = 0,
SCROLLBAR_HIDE_HORIZONTAL = 1 << 1,
SCROLLBAR_HIDE_VERTICAL = 1 << 2,
SCROLLBAR_HIDE_BOTH = SCROLLBAR_HIDE_HORIZONTAL | SCROLLBAR_HIDE_VERTICAL
};
enum class EmptyLastPageAppendType {
Disabled = 0,
OnDrawOfLastPage = 1,
OnScrollToEndOfLastPage = 2,
};
/**
* The user-selectable device types
*/
enum class InputDeviceTypeOption {
Disabled = 0,
Mouse = 1,
Pen = 2,
Eraser = 3,
Touchscreen = 4,
MouseKeyboardCombo = 5,
};
enum StylusCursorType {
STYLUS_CURSOR_NONE = 0,
STYLUS_CURSOR_DOT = 1,
STYLUS_CURSOR_BIG = 2,
STYLUS_CURSOR_ARROW = 3,
};
enum EraserVisibility {
ERASER_VISIBILITY_NEVER = 0,
ERASER_VISIBILITY_ALWAYS = 1,
ERASER_VISIBILITY_HOVER = 2,
ERASER_VISIBILITY_TOUCH = 3,
};
enum IconTheme {
ICON_THEME_COLOR = 0,
ICON_THEME_LUCIDE = 1,
};
enum ThemeVariant { THEME_VARIANT_USE_SYSTEM, THEME_VARIANT_FORCE_LIGHT, THEME_VARIANT_FORCE_DARK };
/**
* The user-selectable Page Preview Decoration style
*/
enum class SidebarNumberingStyle {
/* No page numbers are displayed */
NONE = 0,
/* Page numbers are displayed below previews */
NUMBER_BELOW_PREVIEW = 1,
/* Page numbers are displayed in a circle in the lower right corner */
NUMBER_WITH_CIRCULAR_BACKGROUND = 2,
/* Page numbers are displayed in a square in the lower right corner */
NUMBER_WITH_SQUARE_BACKGROUND = 3,
/* MIN, MAX and Default values. Need to be updated when new style is added. */
MIN = SidebarNumberingStyle::NONE,
MAX = SidebarNumberingStyle::NUMBER_WITH_SQUARE_BACKGROUND,
DEFAULT = SidebarNumberingStyle::NUMBER_BELOW_PREVIEW
};
constexpr auto buttonToString(Button button) -> const char* {
switch (button) {
case BUTTON_ERASER:
return "eraser";
case BUTTON_MOUSE_MIDDLE:
return "middle";
case BUTTON_MOUSE_RIGHT:
return "right";
case BUTTON_TOUCH:
return "touch";
case BUTTON_DEFAULT:
return "default";
case BUTTON_STYLUS_ONE:
return "stylus";
case BUTTON_STYLUS_TWO:
return "stylus2";
default:
return "unknown";
}
}
constexpr auto stylusCursorTypeToString(StylusCursorType stylusCursorType) -> const char* {
switch (stylusCursorType) {
case STYLUS_CURSOR_NONE:
return "none";
case STYLUS_CURSOR_DOT:
return "dot";
case STYLUS_CURSOR_BIG:
return "big";
case STYLUS_CURSOR_ARROW:
return "arrow";
default:
return "unknown";
}
}
constexpr auto eraserVisibilityToString(EraserVisibility eraserVisibility) -> const char* {
switch (eraserVisibility) {
case ERASER_VISIBILITY_NEVER:
return "never";
case ERASER_VISIBILITY_ALWAYS:
return "always";
case ERASER_VISIBILITY_HOVER:
return "hover";
case ERASER_VISIBILITY_TOUCH:
return "touch";
default:
return "unknown";
}
}
constexpr auto iconThemeToString(IconTheme iconTheme) -> const char* {
switch (iconTheme) {
case ICON_THEME_COLOR:
return "iconsColor";
case ICON_THEME_LUCIDE:
return "iconsLucide";
default:
return "unknown";
}
}
constexpr auto themeVariantToString(ThemeVariant variant) -> const char* {
switch (variant) {
case THEME_VARIANT_USE_SYSTEM:
return "useSystem";
case THEME_VARIANT_FORCE_LIGHT:
return "forceLight";
case THEME_VARIANT_FORCE_DARK:
return "forceDark";
default:
return "unknown";
}
}
constexpr auto emptyLastPageAppendToString(EmptyLastPageAppendType appendType) -> const char* {
switch (appendType) {
case EmptyLastPageAppendType::Disabled:
return "disabled";
case EmptyLastPageAppendType::OnDrawOfLastPage:
return "onDrawOfLastPage";
case EmptyLastPageAppendType::OnScrollToEndOfLastPage:
return "onScrollOfLastPage";
default:
return "unknown";
}
}
StylusCursorType stylusCursorTypeFromString(const std::string& stylusCursorTypeStr);
EraserVisibility eraserVisibilityFromString(const std::string& eraserVisibilityStr);
IconTheme iconThemeFromString(const std::string& iconThemeStr);
ThemeVariant themeVariantFromString(const std::string& themeVariantStr);
EmptyLastPageAppendType emptyLastPageAppendFromString(const std::string& str);
| 5,354
|
C++
|
.h
| 179
| 24.094972
| 100
| 0.672099
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,900
|
ButtonConfig.h
|
xournalpp_xournalpp/src/core/control/settings/ButtonConfig.h
|
/*
* Xournal++
*
* Configuration for Mouse Buttons, Eraser and default configuration
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string> // for string
#include "control/ToolEnums.h" // for DrawingType, ToolType
#include "control/settings/SettingsEnums.h" // for Button
#include "model/LineStyle.h"
#include "util/Color.h" // for Color
class ToolHandler;
class ButtonConfig {
public:
ButtonConfig(ToolType action, Color color, ToolSize size, DrawingType drawingType, EraserType eraserMode,
StrokeType strokeType = STROKE_TYPE_NONE);
virtual ~ButtonConfig();
public:
/**
* @brief Apply Changes to the button tool in case "Don't Change" was selected for one of it's properties
* This is usually used after switching to a button tool from the toolbar tool
* Note: In case of the setting "Don't Change" for Size/DrawingType/EraserType the
* Size/DrawingType/EraserType of the corresponding tool in the toolbar is used.
*
* @param toolHandler
* @param button button to be applied
* @return true if some action was selected
* @return false if no action was selected
*/
bool applyNoChangeSettings(ToolHandler* toolHandler, Button button);
/**
* @brief Initialize Button tool
* In case of "No change" settings the property will remain in it's default value.
* As this will be overwritten during `applyNoChangeSettings` this makes sense.
*
* @param toolHandler
* @param button
*/
void initButton(ToolHandler* toolHandler, Button button);
/**
* @brief Apply the Config to the toolbar Tool
* This is used for applying the Default Button Config
*
* @param toolHandler
*/
void applyConfigToToolbarTool(ToolHandler* toolHandler);
ToolType getAction();
bool getDisableDrawing() const;
DrawingType getDrawingType();
private:
ToolType action;
Color color{};
ToolSize size;
EraserType eraserMode;
DrawingType drawingType;
StrokeType strokeType;
bool disableDrawing;
public:
std::string device;
friend class Settings;
friend class ButtonConfigGui;
};
| 2,284
|
C++
|
.h
| 67
| 29.597015
| 109
| 0.707217
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,901
|
ViewModes.h
|
xournalpp_xournalpp/src/core/control/settings/ViewModes.h
|
/*
* Xournal++
*
* View Mode struct & attribute definitions
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string> // for string
#include <vector> // for vector
#include <unordered_map> // for unordered_map
using ViewModeId = size_t;
// reserved default view mode ids
enum PresetViewModeIds {
VIEW_MODE_DEFAULT = 0,
VIEW_MODE_FULLSCREEN = 1,
VIEW_MODE_PRESENTATION = 2
};
// view mode attributes
constexpr auto ATTR_GO_FULLSCREEN = "goFullscren";
constexpr auto ATTR_SHOW_MENUBAR = "showMenubar";
constexpr auto ATTR_SHOW_TOOLBAR = "showToolbar";
constexpr auto ATTR_SHOW_SIDEBAR = "showSidebar";
struct ViewMode {
bool goFullscreen{false};
bool showMenubar{false};
bool showToolbar{false};
bool showSidebar{false};
bool operator==(const ViewMode& other) const;
};
// default ViewModes
constexpr ViewMode VIEW_MODE_STRUCT_DEFAULT{false, true, true, true};
constexpr ViewMode VIEW_MODE_STRUCT_FULLSCREEN{true, false, true, true};
constexpr ViewMode VIEW_MODE_STRUCT_PRESENTATION{true, false, true, false};
struct ViewMode settingsStringToViewMode(std::string viewModeString);
const std::string viewModeToSettingsString(struct ViewMode viewMode);
| 1,300
|
C++
|
.h
| 39
| 31.051282
| 75
| 0.75
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,902
|
ActionProperties.h
|
xournalpp_xournalpp/src/core/control/actions/ActionProperties.h
|
/**
*
*
*/
#pragma once
#include <type_traits>
#include "control/AudioController.h"
#include "control/Control.h"
#include "control/ScrollHandler.h"
#include "control/ToolEnums.h"
#include "control/UndoRedoController.h"
#include "control/layer/LayerController.h"
#include "control/settings/Settings.h"
#include "control/zoom/ZoomControl.h"
#include "enums/Action.enum.h"
#include "gui/MainWindow.h"
#include "gui/SearchBar.h"
#include "gui/XournalView.h"
#include "gui/dialog/RenameLayerDialog.h"
#include "gui/toolbarMenubar/ToolMenuHandler.h"
#include "model/Document.h"
#include "model/Font.h"
#include "model/StrokeStyle.h"
#include "model/XojPage.h"
#include "plugin/PluginController.h"
#include "util/Assert.h"
#include "util/PopupWindowWrapper.h"
#include "util/Util.h"
#include "util/XojMsgBox.h"
#include "util/i18n.h"
#include "ActionDatabase.h"
/**
* Template class to store Action properties. Expected members are:
* * a static member function
* static void callback(GSimpleAction*, GVariant*, Control*);
* * (optional) a member type state_type. If a state_type is provided, there must be a static member function
* static state_type initialState(Control* ctrl);
* * (optional) a member type parameter_type. If both are provided, parameter_type and state_type must agree.
* * (optional) a member static constexpr const char* accelerators[] = {"accel1", "accel2", nullptr} for
* accelerators that need to be set in the code rather than in the .xml files
* * (optional) a static member function
* static bool initiallyEnabled(Control*);
* Defaults to [](Control*){return true;}
* * (optional) a member type app_namespace = std::true_type if the action should be added to the app. namespace
* Otherwise, it is added to the win. namespace
*
* Note that both state_type and parameter_type must be convertible to GVariant. See util/GVariantTemplate.h
*/
template <Action action>
struct ActionProperties {};
/**
* @brief true if the Action has a parameter
*/
template <Action a, class U = void>
struct has_param: std::false_type {};
template <Action a>
struct has_param<a, std::void_t<typename ActionProperties<a>::parameter_type>>: std::true_type {};
/**
* @brief true if the Action has a state
*/
template <Action a, class U = void>
struct has_state: std::false_type {};
template <Action a>
struct has_state<a, std::void_t<typename ActionProperties<a>::state_type>>: std::true_type {};
/*** SPECIALIZATIONS ***/
/** File Menu **/
template <>
struct ActionProperties<Action::NEW_FILE> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
ctrl->clearSelectionEndText();
ctrl->newFile();
}
};
template <>
struct ActionProperties<Action::OPEN> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->askToOpenFile(); }
};
template <>
struct ActionProperties<Action::ANNOTATE_PDF> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
ctrl->clearSelectionEndText();
ctrl->askToAnnotatePdf();
}
};
template <>
struct ActionProperties<Action::SAVE> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->save(); }
};
template <>
struct ActionProperties<Action::SAVE_AS> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->saveAs(); }
};
template <>
struct ActionProperties<Action::EXPORT_AS_PDF> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->exportAsPdf(); }
};
template <>
struct ActionProperties<Action::EXPORT_AS> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->exportAs(); }
};
template <>
struct ActionProperties<Action::PRINT> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->print(); }
};
template <>
struct ActionProperties<Action::QUIT> {
using app_namespace = std::true_type;
#ifdef __APPLE__
static constexpr const char* accelerators[] = {"<Meta>Q", nullptr};
#else
static constexpr const char* accelerators[] = {"<Ctrl>Q", nullptr};
#endif
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->quit(); }
};
/** Edit Menu **/
template <>
struct ActionProperties<Action::UNDO> {
#ifdef __APPLE__
static constexpr const char* accelerators[] = {"<Meta>Z", nullptr};
#else
static constexpr const char* accelerators[] = {"<Ctrl>Z", nullptr};
#endif
static bool initiallyEnabled(Control* ctrl) { return ctrl->undoRedo->canUndo(); }
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { UndoRedoController::undo(ctrl); }
};
template <>
struct ActionProperties<Action::REDO> {
#ifdef __APPLE__
static constexpr const char* accelerators[] = {"<Meta><Shift>Z", "<Meta>Y", nullptr};
#else
static constexpr const char* accelerators[] = {"<Ctrl><Shift>Z", "<Ctrl>Y", nullptr};
#endif
static bool initiallyEnabled(Control* ctrl) { return ctrl->undoRedo->canRedo(); }
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
ctrl->clearSelectionEndText();
UndoRedoController::redo(ctrl);
}
};
template <>
struct ActionProperties<Action::CUT> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->cut(); }
};
template <>
struct ActionProperties<Action::COPY> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->copy(); }
};
template <>
struct ActionProperties<Action::PASTE> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->paste(); }
};
template <>
struct ActionProperties<Action::SEARCH> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
ctrl->clearSelectionEndText();
ctrl->getSearchBar()->showSearchBar(true);
}
};
template <>
struct ActionProperties<Action::SELECT_ALL> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->selectAllOnPage(); }
};
template <>
struct ActionProperties<Action::DELETE> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
if (!ctrl->getWindow()->getXournal()->actionDelete()) {
ctrl->deleteSelection();
}
}
};
template <>
struct ActionProperties<Action::ARRANGE_SELECTION_ORDER> {
using parameter_type = EditSelection::OrderChange;
static void callback(GSimpleAction*, GVariant* p, Control* ctrl) {
auto change = getGVariantValue<EditSelection::OrderChange>(p);
xoj_assert(change <= EditSelection::OrderChange::SendToBack);
ctrl->reorderSelection(change);
}
};
template <>
struct ActionProperties<Action::MOVE_SELECTION_LAYER_UP> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
// moveSelectionToLayer takes layer number (layerid - 1) not id
// therefore the new layer is "layerid - 1 + 1"
ctrl->moveSelectionToLayer(ctrl->getCurrentPage()->getSelectedLayerId());
}
};
template <>
struct ActionProperties<Action::MOVE_SELECTION_LAYER_DOWN> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
if (ctrl->getLayerController()->getCurrentLayerId() >= 2) {
// moveSelectionToLayer takes layer number (layerid - 1) not id
// therefore the new layer is "layerid - 1 - 1"
ctrl->moveSelectionToLayer(ctrl->getCurrentPage()->getSelectedLayerId() - 2);
}
}
};
template <>
struct ActionProperties<Action::ROTATION_SNAPPING> {
using state_type = bool;
static state_type initialState(Control* ctrl) { return ctrl->getSettings()->isSnapRotation(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
bool enable = g_variant_get_boolean(p);
ctrl->setRotationSnapping(enable);
}
};
template <>
struct ActionProperties<Action::GRID_SNAPPING> {
using state_type = bool;
static state_type initialState(Control* ctrl) { return ctrl->getSettings()->isSnapGrid(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
bool enable = g_variant_get_boolean(p);
ctrl->setGridSnapping(enable);
}
};
template <>
struct ActionProperties<Action::PREFERENCES> {
using app_namespace = std::true_type;
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->showSettings(); }
};
/** View Menu **/
template <>
struct ActionProperties<Action::PAIRED_PAGES_MODE> {
using state_type = bool;
static state_type initialState(Control* ctrl) { return ctrl->getSettings()->isShowPairedPages(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
bool enabled = g_variant_get_boolean(p);
ctrl->setViewPairedPages(enabled);
}
};
template <>
struct ActionProperties<Action::PAIRED_PAGES_OFFSET> {
using state_type = int;
static state_type initialState(Control* ctrl) { return ctrl->getSettings()->getPairsOffset(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
int offset = g_variant_get_int32(p);
ctrl->setPairsOffset(offset);
}
};
template <>
struct ActionProperties<Action::PRESENTATION_MODE> {
using state_type = bool;
static state_type initialState(Control* ctrl) { return ctrl->getSettings()->isPresentationMode(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
bool enabled = g_variant_get_boolean(p);
ctrl->setViewPresentationMode(enabled);
}
};
template <>
struct ActionProperties<Action::FULLSCREEN> {
using state_type = bool;
static constexpr state_type initialState(Control*) { return false; }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
bool enabled = g_variant_get_boolean(p);
ctrl->setViewFullscreenMode(enabled);
}
};
template <>
struct ActionProperties<Action::SHOW_SIDEBAR> {
using state_type = bool;
static state_type initialState(Control* ctrl) { return ctrl->getSettings()->isSidebarVisible(); }
static void callback(GSimpleAction*, GVariant* p, Control* ctrl) { ctrl->setShowSidebar(g_variant_get_boolean(p)); }
};
template <>
struct ActionProperties<Action::SHOW_TOOLBAR> {
using state_type = bool;
static state_type initialState(Control* ctrl) { return ctrl->getSettings()->isToolbarVisible(); }
static void callback(GSimpleAction*, GVariant* p, Control* ctrl) { ctrl->setShowToolbar(g_variant_get_boolean(p)); }
};
template <>
struct ActionProperties<Action::SET_LAYOUT_VERTICAL> {
using state_type = bool;
using parameter_type = state_type;
static state_type initialState(Control* ctrl) { return ctrl->getSettings()->getViewLayoutVert(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
bool vertical = g_variant_get_boolean(p);
ctrl->setViewLayoutVert(vertical);
}
};
template <>
struct ActionProperties<Action::SET_LAYOUT_RIGHT_TO_LEFT> {
using state_type = bool;
using parameter_type = state_type;
static state_type initialState(Control* ctrl) { return ctrl->getSettings()->getViewLayoutR2L(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
bool rightToLeft = g_variant_get_boolean(p);
ctrl->setViewLayoutR2L(rightToLeft);
}
};
template <>
struct ActionProperties<Action::SET_LAYOUT_BOTTOM_TO_TOP> {
using state_type = bool;
using parameter_type = state_type;
static state_type initialState(Control* ctrl) { return ctrl->getSettings()->getViewLayoutB2T(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
bool bottomToTop = g_variant_get_boolean(p);
ctrl->setViewLayoutB2T(bottomToTop);
}
};
template <>
struct ActionProperties<Action::SET_COLUMNS_OR_ROWS> {
using state_type = int;
using parameter_type = state_type;
static state_type initialState(Control* ctrl) {
auto* settings = ctrl->getSettings();
return settings->isViewFixedRows() ? -settings->getViewRows() : settings->getViewColumns();
}
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
int value = g_variant_get_int32(p);
xoj_assert(value != 0);
if (value > 0) {
ctrl->setViewColumns(value);
} else {
ctrl->setViewRows(std::abs(value));
}
}
};
template <>
struct ActionProperties<Action::MANAGE_TOOLBAR> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->manageToolbars(); }
};
template <>
struct ActionProperties<Action::CUSTOMIZE_TOOLBAR> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->customizeToolbars(); }
};
template <>
struct ActionProperties<Action::SHOW_MENUBAR> {
using state_type = bool;
static state_type initialState(Control* ctrl) { return ctrl->getSettings()->isMenubarVisible(); }
static void callback(GSimpleAction*, GVariant* p, Control* ctrl) { ctrl->setShowMenubar(g_variant_get_boolean(p)); }
};
/*
* Zoom callbacks are postponed to later in the UI Thread
* On slower machine this feels more fluent.
*/
template <>
struct ActionProperties<Action::ZOOM_IN> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
Util::execInUiThread([zoom = ctrl->getZoomControl()]() { zoom->zoomOneStep(ZOOM_IN); });
}
};
template <>
struct ActionProperties<Action::ZOOM_OUT> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
Util::execInUiThread([zoom = ctrl->getZoomControl()]() { zoom->zoomOneStep(ZOOM_OUT); });
}
};
template <>
struct ActionProperties<Action::ZOOM_100> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
Util::execInUiThread([zoom = ctrl->getZoomControl()]() { zoom->zoom100(); });
}
};
template <>
struct ActionProperties<Action::ZOOM_FIT> {
using state_type = bool;
static state_type initialState(Control* ctrl) { return ctrl->getZoomControl()->isZoomFitMode(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
bool enabled = g_variant_get_boolean(p);
Util::execInUiThread([enabled, zoom = ctrl->getZoomControl()]() {
if (enabled) {
zoom->updateZoomFitValue();
}
// enable/disable ZoomFit
zoom->setZoomFitMode(enabled);
});
}
};
template <>
struct ActionProperties<Action::ZOOM> {
using state_type = double;
static state_type initialState(Control* ctrl) { return ctrl->getZoomControl()->getZoom(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
double scale = g_variant_get_double(p);
xoj_assert(scale >= DEFAULT_ZOOM_MIN && scale <= DEFAULT_ZOOM_MAX);
Util::execInUiThread([scale, zoomctrl = ctrl->getZoomControl()]() {
double newZoom = zoomctrl->getZoom100Value() * scale;
zoomctrl->setZoomFitMode(false);
zoomctrl->startZoomSequence();
zoomctrl->zoomSequenceChange(newZoom, false);
zoomctrl->endZoomSequence();
});
}
};
/** Navigation menu **/
template <>
struct ActionProperties<Action::GOTO_FIRST> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->getScrollHandler()->scrollToPage(0); }
};
template <>
struct ActionProperties<Action::GOTO_PREVIOUS> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->getScrollHandler()->goToPreviousPage(); }
};
template <>
struct ActionProperties<Action::GOTO_PAGE> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->gotoPage(); }
};
template <>
struct ActionProperties<Action::GOTO_NEXT> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->getScrollHandler()->goToNextPage(); }
};
template <>
struct ActionProperties<Action::GOTO_LAST> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
ctrl->getScrollHandler()->scrollToPage(ctrl->getDocument()->getPageCount() - 1);
}
};
template <>
struct ActionProperties<Action::GOTO_NEXT_ANNOTATED_PAGE> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
ctrl->getScrollHandler()->scrollToAnnotatedPage(true);
}
};
template <>
struct ActionProperties<Action::GOTO_PREVIOUS_ANNOTATED_PAGE> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
ctrl->getScrollHandler()->scrollToAnnotatedPage(false);
}
};
/** Journal Menu **/
template <>
struct ActionProperties<Action::NEW_PAGE_BEFORE> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->insertNewPage(ctrl->getCurrentPageNo()); }
};
template <>
struct ActionProperties<Action::NEW_PAGE_AFTER> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
ctrl->insertNewPage(ctrl->getCurrentPageNo() + 1);
}
};
template <>
struct ActionProperties<Action::NEW_PAGE_AT_END> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
ctrl->insertNewPage(ctrl->getDocument()->getPageCount());
}
};
template <>
struct ActionProperties<Action::DUPLICATE_PAGE> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->duplicatePage(); }
};
template <>
struct ActionProperties<Action::MOVE_PAGE_TOWARDS_BEGINNING> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->movePageTowardsBeginning(); }
};
template <>
struct ActionProperties<Action::MOVE_PAGE_TOWARDS_END> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->movePageTowardsEnd(); }
};
template <>
struct ActionProperties<Action::APPEND_NEW_PDF_PAGES> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->appendNewPdfPages(); }
};
template <>
struct ActionProperties<Action::CONFIGURE_PAGE_TEMPLATE> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->paperTemplate(); }
};
template <>
struct ActionProperties<Action::DELETE_PAGE> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->deletePage(); }
};
template <>
struct ActionProperties<Action::PAPER_FORMAT> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->paperFormat(); }
};
template <>
struct ActionProperties<Action::PAPER_BACKGROUND_COLOR> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->changePageBackgroundColor(); }
};
/** Tool menu **/
template <>
struct ActionProperties<Action::SELECT_TOOL> {
using state_type = ToolType;
using parameter_type = state_type;
static state_type initialState(Control* ctrl) { return ctrl->getToolHandler()->getActiveTool()->getToolType(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
ToolType tt = getGVariantValue<ToolType>(p);
xoj_assert(tt < TOOL_END_ENTRY);
if (requiresClearedSelection(tt)) {
ctrl->clearSelection();
}
ctrl->selectTool(tt);
}
};
template <>
struct ActionProperties<Action::SELECT_DEFAULT_TOOL> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->selectDefaultTool(); }
};
/*
* To have the menu entries drawn as check boxes and not as radio buttons, each drawing type has a boolean-state
* action (on/off). This action cannot take a parameter: we need one callback per drawing type
*/
template <DrawingType type>
struct ActionPropDrawingTypes {
using state_type = bool;
static state_type initialState(Control* ctrl) {
return ctrl->getToolHandler()->getActiveTool()->getDrawingType() == type;
}
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
auto* actionDB = ctrl->getActionDatabase();
actionDB->setActionState(Action::TOOL_DRAW_SHAPE_RECOGNIZER, false);
actionDB->setActionState(Action::TOOL_DRAW_RECTANGLE, false);
actionDB->setActionState(Action::TOOL_DRAW_ELLIPSE, false);
actionDB->setActionState(Action::TOOL_DRAW_ARROW, false);
actionDB->setActionState(Action::TOOL_DRAW_DOUBLE_ARROW, false);
actionDB->setActionState(Action::TOOL_DRAW_COORDINATE_SYSTEM, false);
actionDB->setActionState(Action::TOOL_DRAW_LINE, false);
actionDB->setActionState(Action::TOOL_DRAW_SPLINE, false);
g_simple_action_set_state(ga, p);
bool enabled = g_variant_get_boolean(p);
ctrl->setToolDrawingType(enabled ? type : DRAWING_TYPE_DEFAULT);
}
};
template <>
struct ActionProperties<Action::TOOL_DRAW_SHAPE_RECOGNIZER>: ActionPropDrawingTypes<DRAWING_TYPE_SHAPE_RECOGNIZER> {};
template <>
struct ActionProperties<Action::TOOL_DRAW_RECTANGLE>: ActionPropDrawingTypes<DRAWING_TYPE_RECTANGLE> {};
template <>
struct ActionProperties<Action::TOOL_DRAW_ELLIPSE>: ActionPropDrawingTypes<DRAWING_TYPE_ELLIPSE> {};
template <>
struct ActionProperties<Action::TOOL_DRAW_ARROW>: ActionPropDrawingTypes<DRAWING_TYPE_ARROW> {};
template <>
struct ActionProperties<Action::TOOL_DRAW_DOUBLE_ARROW>: ActionPropDrawingTypes<DRAWING_TYPE_DOUBLE_ARROW> {};
template <>
struct ActionProperties<Action::TOOL_DRAW_COORDINATE_SYSTEM>: ActionPropDrawingTypes<DRAWING_TYPE_COORDINATE_SYSTEM> {};
template <>
struct ActionProperties<Action::TOOL_DRAW_LINE>: ActionPropDrawingTypes<DRAWING_TYPE_LINE> {};
template <>
struct ActionProperties<Action::TOOL_DRAW_SPLINE>: ActionPropDrawingTypes<DRAWING_TYPE_SPLINE> {};
template <>
struct ActionProperties<Action::SETSQUARE> {
using state_type = bool;
static constexpr state_type initialState(Control*) { return false; }
static void callback(GSimpleAction* ga, GVariant*, Control* ctrl) {
// Only one GeometryTool is activated at a time
ctrl->getActionDatabase()->setActionState(Action::COMPASS, false);
g_simple_action_set_state(ga, makeGVariant(ctrl->toggleSetsquare()));
}
};
template <>
struct ActionProperties<Action::COMPASS> {
using state_type = bool;
static constexpr state_type initialState(Control*) { return false; }
static void callback(GSimpleAction* ga, GVariant*, Control* ctrl) {
// Only one GeometryTool is activated at a time
ctrl->getActionDatabase()->setActionState(Action::SETSQUARE, false);
g_simple_action_set_state(ga, makeGVariant(ctrl->toggleCompass()));
}
};
// Pen submenu
template <>
struct ActionProperties<Action::TOOL_PEN_SIZE> {
using state_type = ToolSize;
using parameter_type = state_type;
static state_type initialState(Control* ctrl) { return ctrl->getToolHandler()->getPenSize(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
ToolSize size = getGVariantValue<ToolSize>(p);
xoj_assert(size < TOOL_SIZE_NONE);
ctrl->getToolHandler()->setPenSize(size);
ctrl->penSizeChanged();
}
};
template <>
struct ActionProperties<Action::TOOL_PEN_LINE_STYLE> {
using state_type = const std::string&;
using parameter_type = state_type;
static std::string initialState(Control* ctrl) { return ctrl->getLineStyleToSelect().value_or("none"); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
const char* styleName = g_variant_get_string(p, nullptr);
ctrl->setLineStyle(styleName);
}
};
template <>
struct ActionProperties<Action::TOOL_PEN_FILL> {
using state_type = bool;
static state_type initialState(Control* ctrl) { return ctrl->getToolHandler()->getTool(TOOL_PEN).getFill(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
bool enabled = g_variant_get_boolean(p);
ctrl->getToolHandler()->setPenFillEnabled(enabled);
}
};
template <>
struct ActionProperties<Action::TOOL_PEN_FILL_OPACITY> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->selectAlpha(OPACITY_FILL_PEN); }
};
// Eraser submenu
template <>
struct ActionProperties<Action::TOOL_ERASER_SIZE> {
using state_type = ToolSize;
using parameter_type = state_type;
static state_type initialState(Control* ctrl) { return ctrl->getToolHandler()->getEraserSize(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
ToolSize size = getGVariantValue<ToolSize>(p);
xoj_assert(size < TOOL_SIZE_NONE);
ctrl->getToolHandler()->setEraserSize(size);
ctrl->eraserSizeChanged();
}
};
template <>
struct ActionProperties<Action::TOOL_ERASER_TYPE> {
using state_type = EraserType;
using parameter_type = state_type;
static state_type initialState(Control* ctrl) { return ctrl->getToolHandler()->getEraserType(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
EraserType type = getGVariantValue<EraserType>(p);
ctrl->setEraserType(type);
}
};
// Highlighter submenu
template <>
struct ActionProperties<Action::TOOL_HIGHLIGHTER_SIZE> {
using state_type = ToolSize;
using parameter_type = state_type;
static state_type initialState(Control* ctrl) { return ctrl->getToolHandler()->getHighlighterSize(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
ToolSize size = getGVariantValue<ToolSize>(p);
xoj_assert(size < TOOL_SIZE_NONE);
ctrl->getToolHandler()->setHighlighterSize(size);
ctrl->highlighterSizeChanged();
}
};
template <>
struct ActionProperties<Action::TOOL_HIGHLIGHTER_FILL> {
using state_type = bool;
static state_type initialState(Control* ctrl) {
return ctrl->getToolHandler()->getTool(TOOL_HIGHLIGHTER).getFill();
}
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
bool enabled = g_variant_get_boolean(p);
ctrl->getToolHandler()->setHighlighterFillEnabled(enabled);
}
};
template <>
struct ActionProperties<Action::TOOL_HIGHLIGHTER_FILL_OPACITY> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->selectAlpha(OPACITY_FILL_HIGHLIGHTER); }
};
template <>
struct ActionProperties<Action::TOOL_SELECT_PDF_TEXT_MARKER_OPACITY> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
ctrl->selectAlpha(OPACITY_SELECT_PDF_TEXT_MARKER);
}
};
template <>
struct ActionProperties<Action::SELECT_FONT> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->showFontDialog(); }
};
template <>
struct ActionProperties<Action::FONT> {
using state_type = const std::string&;
using parameter_type = state_type;
static std::string initialState(Control* ctrl) { return ctrl->getSettings()->getFont().asString(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
ctrl->fontChanged(XojFont(g_variant_get_string(p, nullptr)));
}
};
template <>
struct ActionProperties<Action::AUDIO_RECORD> {
using state_type = bool;
static constexpr state_type initialState(Control*) { return false; }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
if (!ctrl->audioController) {
g_warning("Audio has been disabled");
return;
}
bool enabled = g_variant_get_boolean(p);
bool success = false;
if (enabled) {
success = ctrl->getAudioController()->startRecording();
} else {
success = ctrl->getAudioController()->stopRecording();
}
if (success) {
g_simple_action_set_state(ga, p);
} else {
g_simple_action_set_state(ga, g_variant_new_boolean(!enabled));
Util::execInUiThread([=]() {
std::string msg = _("Recorder could not be started.");
g_warning("%s", msg.c_str());
XojMsgBox::showErrorToUser(ctrl->getGtkWindow(), msg);
});
}
}
};
template <>
struct ActionProperties<Action::AUDIO_PAUSE_PLAYBACK> {
using state_type = bool;
static constexpr state_type initialState(Control*) { return false; }
static constexpr bool initiallyEnabled(Control*) { return false; }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
if (!ctrl->audioController) {
g_warning("Audio has been disabled");
return;
}
g_simple_action_set_state(ga, p);
bool enabled = g_variant_get_boolean(p);
if (enabled) {
ctrl->getAudioController()->pausePlayback();
} else {
ctrl->getAudioController()->continuePlayback();
}
}
};
template <>
struct ActionProperties<Action::AUDIO_SEEK_FORWARDS> {
static constexpr bool initiallyEnabled(Control*) { return false; }
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
if (!ctrl->audioController) {
g_warning("Audio has been disabled");
return;
}
ctrl->getAudioController()->seekForwards();
}
};
template <>
struct ActionProperties<Action::AUDIO_SEEK_BACKWARDS> {
static constexpr bool initiallyEnabled(Control*) { return false; }
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
if (!ctrl->audioController) {
g_warning("Audio has been disabled");
return;
}
ctrl->getAudioController()->seekBackwards();
}
};
template <>
struct ActionProperties<Action::AUDIO_STOP_PLAYBACK> {
static constexpr bool initiallyEnabled(Control*) { return false; }
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
if (!ctrl->audioController) {
g_warning("Audio has been disabled");
return;
}
ctrl->getAudioController()->stopPlayback();
}
};
template <>
struct ActionProperties<Action::TEX> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->runLatex(); }
};
/** Plugin menu **/
template <>
struct ActionProperties<Action::PLUGIN_MANAGER> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->pluginController->showPluginManager(); }
};
/** Help menu **/
template <>
struct ActionProperties<Action::HELP> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { XojMsgBox::showHelp(ctrl->getGtkWindow()); }
};
template <>
struct ActionProperties<Action::ABOUT> {
using app_namespace = std::true_type;
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->showAbout(); }
};
/** Generic tool config, for the toolbars **/
template <>
struct ActionProperties<Action::TOOL_SIZE> {
using state_type = ToolSize;
using parameter_type = state_type;
static state_type initialState(Control* ctrl) {
bool sizeEnable = ctrl->getToolHandler()->hasCapability(TOOL_CAP_SIZE);
return sizeEnable ? ctrl->getToolHandler()->getActiveTool()->getSize() : TOOL_SIZE_NONE;
}
static bool initiallyEnabled(Control* ctrl) { return ctrl->getToolHandler()->hasCapability(TOOL_CAP_SIZE); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
ToolSize size = getGVariantValue<ToolSize>(p);
xoj_assert(size < TOOL_SIZE_NONE);
ctrl->setToolSize(size);
}
};
template <>
struct ActionProperties<Action::TOOL_FILL> {
using state_type = bool;
static state_type initialState(Control* ctrl) {
return ctrl->getToolHandler()->hasCapability(TOOL_CAP_FILL) &&
ctrl->getToolHandler()->getActiveTool()->getFill();
}
static bool initiallyEnabled(Control* ctrl) { return ctrl->getToolHandler()->hasCapability(TOOL_CAP_FILL); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
bool enabled = g_variant_get_boolean(p);
ctrl->setFill(enabled);
}
};
template <>
struct ActionProperties<Action::TOOL_FILL_OPACITY> {
static bool initiallyEnabled(Control* ctrl) { return ctrl->getToolHandler()->hasCapability(TOOL_CAP_FILL); }
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
if (auto tt = ctrl->getToolHandler()->getToolType(); tt == TOOL_PEN) {
ctrl->selectAlpha(OPACITY_FILL_PEN);
} else if (tt == TOOL_HIGHLIGHTER) {
ctrl->selectAlpha(OPACITY_FILL_HIGHLIGHTER);
} else if (tt == TOOL_SELECT_PDF_TEXT_LINEAR || tt == TOOL_SELECT_PDF_TEXT_RECT) {
ctrl->selectAlpha(OPACITY_SELECT_PDF_TEXT_MARKER);
}
}
};
template <>
struct ActionProperties<Action::TOOL_COLOR> {
using state_type = Color;
using parameter_type = state_type;
static state_type initialState(Control* ctrl) {
bool enable = ctrl->getToolHandler()->hasCapability(TOOL_CAP_COLOR);
return enable ? ctrl->getToolHandler()->getActiveTool()->getColor() : Colors::black;
}
static bool initiallyEnabled(Control* ctrl) { return ctrl->getToolHandler()->hasCapability(TOOL_CAP_COLOR); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
ctrl->getToolHandler()->setColor(getGVariantValue<Color>(p), true);
}
};
template <>
struct ActionProperties<Action::SELECT_COLOR> {
static bool initiallyEnabled(Control* ctrl) { return ctrl->getToolHandler()->hasCapability(TOOL_CAP_COLOR); }
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->showColorChooserDialog(); }
};
// Layers
template <>
struct ActionProperties<Action::LAYER_SHOW_ALL> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->getLayerController()->showAllLayer(); }
};
template <>
struct ActionProperties<Action::LAYER_HIDE_ALL> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->getLayerController()->hideAllLayer(); }
};
template <>
struct ActionProperties<Action::LAYER_NEW> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->getLayerController()->addNewLayer(); }
};
template <>
struct ActionProperties<Action::LAYER_COPY> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->getLayerController()->copyCurrentLayer(); }
};
template <>
struct ActionProperties<Action::LAYER_MOVE_UP> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
ctrl->getLayerController()->moveCurrentLayer(true);
}
};
template <>
struct ActionProperties<Action::LAYER_MOVE_DOWN> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
ctrl->getLayerController()->moveCurrentLayer(false);
}
};
template <>
struct ActionProperties<Action::LAYER_DELETE> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) { ctrl->getLayerController()->deleteCurrentLayer(); }
};
template <>
struct ActionProperties<Action::LAYER_MERGE_DOWN> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
ctrl->getLayerController()->mergeCurrentLayerDown();
}
};
template <>
struct ActionProperties<Action::LAYER_RENAME> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
xoj::popup::PopupWindowWrapper<RenameLayerDialog> dialog(
ctrl->getGladeSearchPath(), ctrl->getUndoRedoHandler(), ctrl->getLayerController(),
ctrl->getLayerController()->getCurrentPage()->getSelectedLayer());
dialog.show(ctrl->getGtkWindow());
}
};
template <>
struct ActionProperties<Action::LAYER_GOTO_NEXT> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
PageRef p = ctrl->getCurrentPage();
auto layer = p->getSelectedLayerId();
if (layer < p->getLayerCount()) {
ctrl->getLayerController()->switchToLay(layer + 1, true);
}
}
};
template <>
struct ActionProperties<Action::LAYER_GOTO_PREVIOUS> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
PageRef p = ctrl->getCurrentPage();
auto layer = p->getSelectedLayerId();
if (layer > 0) {
ctrl->getLayerController()->switchToLay(layer - 1, true);
}
}
};
template <>
struct ActionProperties<Action::LAYER_GOTO_TOP> {
static void callback(GSimpleAction*, GVariant*, Control* ctrl) {
PageRef p = ctrl->getCurrentPage();
ctrl->getLayerController()->switchToLay(p->getLayerCount(), true);
}
};
template <>
struct ActionProperties<Action::LAYER_ACTIVE> {
using state_type = Layer::Index;
using parameter_type = state_type;
static state_type initialState(Control* ctrl) { return ctrl->getLayerController()->getCurrentLayerId(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
Layer::Index max = ctrl->getLayerController()->getLayerCount();
Layer::Index current = ctrl->getLayerController()->getCurrentLayerId();
Layer::Index n = getGVariantValue<Layer::Index>(p);
if (n != current && n <= max) {
ctrl->getLayerController()->switchToLay(n); // Will set the right state for this action
}
}
};
template <>
struct ActionProperties<Action::POSITION_HIGHLIGHTING> {
using state_type = bool;
static state_type initialState(Control* ctrl) { return ctrl->getSettings()->isHighlightPosition(); }
static void callback(GSimpleAction* ga, GVariant* p, Control* ctrl) {
g_simple_action_set_state(ga, p);
bool enable = g_variant_get_boolean(p);
ctrl->getSettings()->setHighlightPosition(enable);
}
};
| 38,242
|
C++
|
.h
| 935
| 36.315508
| 120
| 0.698686
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,903
|
ActionRef.h
|
xournalpp_xournalpp/src/core/control/actions/ActionRef.h
|
/*
* Xournal++
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <gio/gio.h>
#include "util/raii/GObjectSPtr.h"
using ActionRef = xoj::util::GObjectSPtr<GSimpleAction>;
| 254
|
C++
|
.h
| 12
| 19.333333
| 56
| 0.728033
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,904
|
ActionDatabase.h
|
xournalpp_xournalpp/src/core/control/actions/ActionDatabase.h
|
/*
* Xournal++
*
* A database for GSimpleAction corresponding to enum/Action.enum.h
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <gio/gio.h>
#include <gtk/gtk.h>
#include "enums/Action.enum.h"
#include "util/Assert.h"
#include "util/EnumIndexedArray.h"
#include "util/GVariantTemplate.h"
#include "util/raii/GObjectSPtr.h"
#include "ActionRef.h"
#include "config-debug.h" // for DEBUG_ACTION_DB
class Control;
#ifdef DEBUG_ACTION_DB
#include <iomanip>
#include <iostream>
#include "util/Color.h"
#include "util/safe_casts.h"
#include "util/serdesstream.h"
#define ACTIONDB_PRINT_DEBUG(f) std::cout << f << std::endl
template <class T, typename = void>
struct to_stream {
to_stream(const T& t): t(t) {}
const T& t;
friend std::ostream& operator<<(std::ostream& str, const to_stream& self) { return str << self.t; }
};
template <class T>
struct to_stream<T, std::enable_if_t<std::is_enum_v<T>, void>> {
to_stream(const T& t): t(t) {}
const T& t;
friend std::ostream& operator<<(std::ostream& str, const to_stream& self) {
return str << xoj::to_underlying(self.t);
}
};
template <>
struct to_stream<Color, void> {
to_stream(const Color& t): t(t) {}
const Color& t;
friend std::ostream& operator<<(std::ostream& str, const to_stream& self) {
auto s = serdes_stream<std::stringstream>();
s << std::hex << std::showbase << static_cast<uint32_t>(self.t);
return str << s.str();
}
};
#else
#define ACTIONDB_PRINT_DEBUG(f)
#endif
class ActionDatabase {
public:
ActionDatabase(Control* control);
~ActionDatabase();
void enableAction(Action a, bool enable);
ActionRef getAction(Action a) const;
bool isActionEnabled(Action a) const;
/// Disables every action
void disableAll();
/// Set the actions enabled flag depending on ActionProperties::initiallyEnabled()
void resetEnableStatus();
/**
* @brief Set the action's state, without triggering callbacks
*/
template <typename state_type>
inline void setActionState(Action a, state_type state) {
xoj_assert(gActions[a]);
g_simple_action_set_state(gActions[a].get(), makeGVariant(state));
ACTIONDB_PRINT_DEBUG("Set action \"" << Action_toString(a) << "\" state to " << to_stream(state));
}
/**
* @brief Change the action's state, triggering callbacks
*/
template <typename state_type>
inline void fireChangeActionState(Action a, state_type state) {
xoj_assert(gActions[a]);
g_action_change_state(G_ACTION(gActions[a].get()), makeGVariant(state));
ACTIONDB_PRINT_DEBUG("Fire action \"" << Action_toString(a) << "\" state change to " << to_stream(state));
}
/**
* @brief Activate the action, triggering callbacks
*/
inline void fireActivateAction(Action a) {
xoj_assert(gActions[a]);
g_action_activate(G_ACTION(gActions[a].get()), nullptr);
ACTIONDB_PRINT_DEBUG("Fire action \"" << Action_toString(a) << "\" activate");
}
template <typename param_type>
inline void fireActivateAction(Action a, param_type param) {
xoj_assert(gActions[a]);
g_action_activate(G_ACTION(gActions[a].get()), makeGVariant(param));
ACTIONDB_PRINT_DEBUG("Fire action \"" << Action_toString(a) << "\" activate with param " << to_stream(param));
}
private:
EnumIndexedArray<ActionRef, Action> gActions;
EnumIndexedArray<gulong, Action> signalIds;
Control* control;
GtkApplicationWindow* win;
class Populator;
friend class Populator;
};
| 3,665
|
C++
|
.h
| 106
| 30.358491
| 118
| 0.673907
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,905
|
ShapeRecognizerConfig.h
|
xournalpp_xournalpp/src/core/control/shaperecognizer/ShapeRecognizerConfig.h
|
/*
* Xournal++
*
* Part of the Xournal shape recognizer
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <config-debug.h>
#include <glib.h>
#define MAX_POLYGON_SIDES 4
#define SEGMENT_MAX_DET 0.045 // maximum score for a polygon segment (ideal line = 0)
#define LINE_MAX_DET 0.015 // maximum score for single line, stricter than for polygons
#define CIRCLE_MIN_DET 0.95 // minimum det. score for circle (ideal circle = 1)
#define CIRCLE_MAX_SCORE 0.10 // max circle score for circle (ideal circle = 0)
#define SLANT_TOLERANCE (5 * M_PI / 180) // ignore slanting by +/- 5 degrees
#define RECTANGLE_ANGLE_TOLERANCE (15 * M_PI / 180) // angle tolerance in rectangles
#define RECTANGLE_LINEAR_TOLERANCE 0.20 // vertex gap tolerance in rectangles
#define POLYGON_LINEAR_TOLERANCE 0.20 // vertex gap tolerance in closed polygons
#ifdef DEBUG_RECOGNIZER
#define RDEBUG(msg, ...) g_message("ShapeReco::" msg, ##__VA_ARGS__)
#else
#define RDEBUG(msg, ...)
#endif
| 1,182
|
C++
|
.h
| 27
| 42.259259
| 113
| 0.647826
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,907
|
Inertia.h
|
xournalpp_xournalpp/src/core/control/shaperecognizer/Inertia.h
|
/*
* Xournal++
*
* Part of the Xournal shape recognizer
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
class Point;
class Inertia {
public:
Inertia();
Inertia(const Inertia& inertia);
virtual ~Inertia();
public:
double centerX() const;
double centerY() const;
double xx() const;
double xy() const;
double yy() const;
double rad() const;
double det() const;
double getMass() const;
void increase(Point p1, Point p2, int coef);
void calc(const Point* pt, int start, int end);
private:
double mass{};
double sx{};
double sy{};
double sxx{};
double sxy{};
double syy{};
};
| 733
|
C++
|
.h
| 36
| 16.722222
| 51
| 0.652111
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,908
|
CircleRecognizer.h
|
xournalpp_xournalpp/src/core/control/shaperecognizer/CircleRecognizer.h
|
/*
* Xournal++
*
* Part of the Xournal shape recognizer
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <memory>
class Stroke;
class Inertia;
class CircleRecognizer {
private:
CircleRecognizer();
virtual ~CircleRecognizer();
public:
static auto recognize(Stroke* s) -> std::unique_ptr<Stroke>;
private:
static auto makeCircleShape(Stroke* originalStroke, Inertia& inertia) -> std::unique_ptr<Stroke>;
static auto scoreCircle(Stroke* s, Inertia& inertia) -> double;
};
| 579
|
C++
|
.h
| 24
| 21.708333
| 101
| 0.734545
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,909
|
ShapeRecognizer.h
|
xournalpp_xournalpp/src/core/control/shaperecognizer/ShapeRecognizer.h
|
/*
* Xournal++
*
* Xournal Shape recognizer
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <array> // for array
#include <memory>
#include "RecoSegment.h"
#include "ShapeRecognizerConfig.h" // for MAX_POLYGON_SIDES
class Stroke;
class Point;
class Inertia;
struct RecoSegment;
class ShapeRecognizer {
public:
ShapeRecognizer();
virtual ~ShapeRecognizer();
auto recognizePatterns(Stroke* stroke, double strokeMinSize) -> std::unique_ptr<Stroke>;
void resetRecognizer();
private:
auto tryRectangle() -> std::unique_ptr<Stroke>;
// function Stroke* tryArrow(); removed after commit a3f7a251282dcfea8b4de695f28ce52bf2035da2
static void optimizePolygonal(const Point* pt, int nsides, int* breaks, Inertia* ss);
int findPolygonal(const Point* pt, int start, int end, int nsides, int* breaks, Inertia* ss);
static bool isStrokeLargeEnough(Stroke* stroke, double strokeMinSize);
private:
std::array<RecoSegment, MAX_POLYGON_SIDES + 1> queue{};
int queueLength;
Stroke* stroke;
};
| 1,121
|
C++
|
.h
| 36
| 28.222222
| 97
| 0.745573
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,910
|
PageTypeHandler.h
|
xournalpp_xournalpp/src/core/control/pagetype/PageTypeHandler.h
|
/*
* Xournal++
*
* Handles different page background types
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <memory>
#include <string> // for string
#include <vector> // for vector
#include <glib.h> // for GKeyFile
#include "model/PageType.h" // for PageTypeFormat, PageType
#include "filesystem.h" // for path
class PageTypeInfo {
public:
PageType page;
std::string name;
};
class GladeSearchpath;
class PageTypeHandler {
public:
PageTypeHandler(GladeSearchpath* gladeSearchPath);
virtual ~PageTypeHandler();
public:
const std::vector<std::unique_ptr<PageTypeInfo>>& getPageTypes();
const std::vector<std::unique_ptr<PageTypeInfo>>& getSpecialPageTypes();
static PageTypeFormat getPageTypeFormatForString(const std::string& format);
static std::string getStringForPageTypeFormat(const PageTypeFormat& format);
const PageTypeInfo* getInfoOn(const PageType& pt) const;
private:
bool parseIni(fs::path const& filepath);
void loadFormat(GKeyFile* config, const char* group);
private:
std::vector<std::unique_ptr<PageTypeInfo>> types;
std::vector<std::unique_ptr<PageTypeInfo>> specialTypes;
};
| 1,244
|
C++
|
.h
| 40
| 28.3
| 80
| 0.751048
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,911
|
ZoomListener.h
|
xournalpp_xournalpp/src/core/control/zoom/ZoomListener.h
|
/*
* Xournal++
*
* Zoom change listener
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
class ZoomListener {
public:
virtual void zoomChanged() = 0;
virtual void zoomRangeValuesChanged();
virtual ~ZoomListener();
};
| 308
|
C++
|
.h
| 17
| 15.705882
| 42
| 0.708333
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,912
|
ZoomControl.h
|
xournalpp_xournalpp/src/core/control/zoom/ZoomControl.h
|
/*
* Xournal++
*
* Controls the zoom level
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cstddef> // for size_t
#include <vector> // for vector
#include <gdk/gdk.h> // for GdkEvent, GdkEventScroll, GdkEve...
#include <gtk/gtk.h> // for GtkWidget
#include "model/DocumentListener.h" // for DocumentListener
#include "util/Point.h" // for Point
#include "util/Rectangle.h" // for Rectangle
constexpr auto DEFAULT_ZOOM_MAX{7};
constexpr auto DEFAULT_ZOOM_MIN{0.3};
constexpr auto DEFAULT_ZOOM_STEP{0.1};
constexpr auto DEFAULT_ZOOM_STEP_SCROLL{0.01};
enum ZoomDirection : bool { ZOOM_OUT = false, ZOOM_IN = true };
class XournalView;
class Control;
class ZoomListener;
class ZoomControl: public DocumentListener {
public:
ZoomControl() = default;
~ZoomControl() override = default;
/**
* Zoom one step
*
* @param direction direction to zoom in or out
* @param zoomCenter position of zoom focus
*/
void zoomOneStep(ZoomDirection direction, xoj::util::Point<double> zoomCenter);
void zoomOneStep(ZoomDirection direction);
/**
* Zoom one step
*
* @param direction to zoom in or out
* @param zoomCenter position of zoom focus
*/
void zoomScroll(ZoomDirection direction, xoj::util::Point<double> zoomCenter);
/**
* Zoom so that the page fits the current size of the window
*/
void setZoomFitMode(bool isZoomFitMode);
bool isZoomFitMode() const;
/**
* Zoom so that the document completely fits the View.
*/
void setZoomPresentationMode(bool isZoomPresentationMode);
bool isZoomPresentationMode() const;
/**
* Zoom so that the displayed page on the screen has the same size as the real size
* The dpi has to be set correctly
*/
void zoom100();
/**
* @return zoom value depending zoom100Value
*/
double getZoom() const;
/**
* @return real zoom value in percent
*/
double getZoomReal() const;
/**
* Set the current zoom, does not preserve the current page position.
* Use startZoomSequence() / zoomSequnceChange() / endZoomSequence() to preserve position
* e.g. use zoomOneStep function
*
* @param zoomI zoom value depending zoom100Value
*/
void setZoom(double zoomI);
/**
* Updates the when dpi is changed.
* updates zoomMax, zoomMin, zoomStepBig, zoomStepScroll
*
* @param zoom100Val zoom value depending zoom100Value
*/
void setZoom100Value(double zoom100Val);
/**
* @return zoom value for zoom 100% depending zoom100Value
*/
double getZoom100Value() const;
/**
* Updates when, the window size changes
* @param zoom zoom value depending zoom100Value
*/
bool updateZoomFitValue(size_t pageNo = 0);
/**
* @return zoom value for zoom fit depending zoom100Value
*/
double getZoomFitValue() const;
bool updateZoomPresentationValue(size_t pageNo = 0);
void addZoomListener(ZoomListener* listener);
void removeZoomListener(ZoomListener* listener);
void initZoomHandler(GtkWidget* window, GtkWidget* widget, XournalView* v, Control* c);
/**
* Call this before any zoom is done, it saves the current page and position
*
* @param zoomCenter position of zoom focus in widget pixel coordinates. That
* is, absolute coordinates (not scaling with the document) translated to the
* top left corner of the drawing area.
*/
void startZoomSequence(xoj::util::Point<double> zoomCenter);
/**
* Call this before any zoom is done, it saves the current page and position
* zooms to the center of the visible rect
*/
void startZoomSequence();
/**
* Change the zoom within a Zoom sequence (startZoomSequence() / endZoomSequence())
*
* @param zoom Current zoom value
* @param relative If the zoom is relative to the start value (for Gesture)
*/
void zoomSequenceChange(double zoom, bool relative);
/**
* Change the zoom and zoomCenter within a Zoom sequence (startZoomSequence() / endZoomSequence())
* Used while touch pinch event
*
* @param zoom Current zoom value
* @param relative If the zoom is relative to the start value (for Gesture)
* @param scrollVector relative zoom center movement in pixels since last call
*/
void zoomSequenceChange(double zoom, bool relative, xoj::util::Point<double> scrollVector);
/// Clear all stored data from startZoomSequence()
void endZoomSequence();
/// Revert and end the current zoom sequence
void cancelZoomSequence();
/// Check if we are between calls to `startZoomSequence()` and `endZoomSequence()`
bool isZoomSequenceActive() const;
/**
* Zoom to correct position on zooming.
* This function should only be called during a zoom sequence.
*/
xoj::util::Point<double> getScrollPositionAfterZoom() const;
/// Get visible rect on xournal view, for Zoom Gesture
xoj::util::Rectangle<double> getVisibleRect();
void setZoomStep(double zoomStep);
void setZoomStepScroll(double zoomStep);
protected:
void fireZoomChanged();
void fireZoomRangeValueChanged();
void pageSizeChanged(size_t page) override;
void pageSelected(size_t page) override;
private:
void zoomFit();
void zoomPresentation();
/**
* Get this->zoom changed by a step in the given direction.
*
* @param direction Direction to change the zoom (step direction).
* @param stepSize Size of the step to take
* @return The new zoom if a step is taken in the given direction.
*/
double withZoomStep(ZoomDirection direction, double stepSize) const;
friend bool onWindowSizeChangedEvent(GtkWidget* widget, GdkEvent* event, ZoomControl* zoom);
friend bool onScrolledwindowMainScrollEvent(GtkWidget* widget, GdkEventScroll* event, ZoomControl* zoom);
friend bool onTouchpadPinchEvent(GtkWidget* widget, GdkEventTouchpadPinch* event, ZoomControl* zoom);
private:
XournalView* view = nullptr;
Control* control = nullptr;
std::vector<ZoomListener*> listener;
/**
* current Zoom value
* depends dpi (REAL_PERCENTAGE_VALUE * zoom100Value)
*/
double zoom = 1.0;
bool zoomFitMode = false;
bool zoomPresentationMode = false;
/// Zoom value for 100% depends on the dpi
double zoom100Value = 1.0;
double zoomFitValue = 1.0;
double zoomPresentationValue = 1.0;
/// Base zoom on start, for relative zoom (Gesture)
double zoomSequenceStart = -1;
/// Zoom center position in widget coordinate space, will not be zoomed!
xoj::util::Point<double> zoomWidgetPos;
/// Scroll position (top left corner of view) to scale
xoj::util::Point<double> scrollPosition;
/// Size {x, y} of the pixels before the current page that
/// do not scale.
xoj::util::Point<double> unscaledPixels;
/**
* Zoomstep value for Ctrl - and Zoom In and Out Button
* depends on dpi (REAL_PERCENTAGE_VALUE * zoom100Value)
*/
double zoomStep = DEFAULT_ZOOM_STEP;
/**
* Zoomstep value for Ctrl-Scroll zooming
* depends on dpi (REAL_PERCENTAGE_VALUE * zoom100Value)
*/
double zoomStepScroll = DEFAULT_ZOOM_STEP_SCROLL;
/**
* Zoom maximal value
* depends on dpi (REAL_PERCENTAGE_VALUE * zoom100Value)
*/
double zoomMax = DEFAULT_ZOOM_MAX;
/**
* Zoom mininmal value
* depends on dpi (REAL_PERCENTAGE_VALUE * zoom100Value)
*/
double zoomMin = DEFAULT_ZOOM_MIN;
size_t current_page = static_cast<size_t>(-1);
size_t last_page = static_cast<size_t>(-1);
bool isZoomFittingNow = false;
};
| 7,856
|
C++
|
.h
| 211
| 32.156398
| 109
| 0.695286
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,913
|
RenderJob.h
|
xournalpp_xournalpp/src/core/control/jobs/RenderJob.h
|
/*
* Xournal++
*
* A job which redraws a page or a page region
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cairo.h> // for cairo_surface_t
#include <gtk/gtk.h> // for GtkWidget
#include "Job.h" // for Job, JobType
class XojPageView;
namespace xoj::util {
template <class T>
class Rectangle;
} // namespace xoj::util
class RenderJob: public Job {
public:
RenderJob(XojPageView* view);
protected:
~RenderJob() override = default;
public:
JobType getType() override;
void* getSource() override;
void run() override;
private:
void repaintPage() const;
void repaintPageArea(double x1, double y1, double x2, double y2) const;
void rerenderRectangle(xoj::util::Rectangle<double> const& rect);
void renderToBuffer(cairo_t* cr) const;
private:
XojPageView* view;
};
| 908
|
C++
|
.h
| 36
| 22.472222
| 75
| 0.716783
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,914
|
ProgressListener.h
|
xournalpp_xournalpp/src/core/control/jobs/ProgressListener.h
|
/*
* Xournal++
*
* Interface for progress state
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
class ProgressListener {
public:
virtual void setMaximumState(size_t max) = 0;
virtual void setCurrentState(size_t state) = 0;
virtual ~ProgressListener(){};
};
class DummyProgressListener: public ProgressListener {
public:
void setMaximumState(size_t max) override{};
void setCurrentState(size_t state) override{};
~DummyProgressListener() override{};
};
| 558
|
C++
|
.h
| 23
| 21.608696
| 54
| 0.735849
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,915
|
PreviewJob.h
|
xournalpp_xournalpp/src/core/control/jobs/PreviewJob.h
|
/*
* Xournal++
*
* A job which handles preview repaint
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cairo.h> // for cairo_surface_t, cairo_t
#include "util/raii/CairoWrappers.h"
#include "Job.h" // for Job, JobType
class SidebarPreviewBaseEntry;
/**
* @brief A Job which renders a SidebarPreviewPage
*/
class PreviewJob: public Job {
public:
PreviewJob(SidebarPreviewBaseEntry* sidebar);
protected:
void onDelete() override;
~PreviewJob() override;
public:
void* getSource() override;
void run() override;
JobType getType() override;
private:
void initGraphics();
void clipToPage();
void finishPaint();
void drawPage();
private:
/**
* Graphics buffer
*/
xoj::util::CairoSurfaceSPtr buffer;
/**
* Graphics drawing
*/
xoj::util::CairoSPtr cr;
/**
* Sidebar preview
*/
SidebarPreviewBaseEntry* sidebarPreview = nullptr;
};
| 1,022
|
C++
|
.h
| 47
| 18.212766
| 54
| 0.686785
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,916
|
PdfExportJob.h
|
xournalpp_xournalpp/src/core/control/jobs/PdfExportJob.h
|
/*
* Xournal++
*
* A job to export PDF
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include "BaseExportJob.h" // for BaseExportJob
#include "filesystem.h" // for path
class Control;
class PdfExportJob: public BaseExportJob {
public:
PdfExportJob(Control* control);
protected:
~PdfExportJob() override;
public:
void run() override;
protected:
void addFilterToDialog(GtkFileChooser* dialog) override;
bool testAndSetFilepath(const fs::path& file, const char* filterName = nullptr) override;
private:
};
| 615
|
C++
|
.h
| 26
| 21.230769
| 93
| 0.741824
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,917
|
ImageExport.h
|
xournalpp_xournalpp/src/core/control/jobs/ImageExport.h
|
/*
* Xournal++
*
* Image export implementation
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cstddef> // for size_t
#include <string> // for string
#include <cairo.h> // for cairo_surface_t, cairo_t
#include "util/ElementRange.h" // for PageRangeVector, LayerRangeVector
#include "BaseExportJob.h" // for ExportBackgroundType, EXPORT_BACKGROUND_ALL
#include "filesystem.h" // for path
class Document;
class ProgressListener;
class DocumentView;
enum ExportGraphicsFormat { EXPORT_GRAPHICS_UNDEFINED, EXPORT_GRAPHICS_PDF, EXPORT_GRAPHICS_PNG, EXPORT_GRAPHICS_SVG };
/**
* @brief List of available criterion for determining a PNG export quality.
* The order must agree with the corresponding listAvailableCriterion in ui/exportSettings.glade
*/
enum ExportQualityCriterion { EXPORT_QUALITY_DPI, EXPORT_QUALITY_WIDTH, EXPORT_QUALITY_HEIGHT };
/**
* @brief A class storing the available quality parameters for PNG export
*/
class RasterImageQualityParameter {
public:
RasterImageQualityParameter(ExportQualityCriterion criterion, int value);
RasterImageQualityParameter();
~RasterImageQualityParameter();
/**
* @brief Get the quality criterion of this parameter
* @return The quality criterion
*/
ExportQualityCriterion getQualityCriterion();
/**
* @brief Get the target value of this parameter
* @return The target value
*/
int getValue();
private:
/**
* @brief Default quality is: DPI=300
*/
ExportQualityCriterion qualityCriterion = EXPORT_QUALITY_DPI;
int value = 300;
};
/**
* @brief A class handling export as images
*/
class ImageExport {
public:
ImageExport(Document* doc, fs::path file, ExportGraphicsFormat format, ExportBackgroundType exportBackground,
const PageRangeVector& exportRange);
virtual ~ImageExport();
public:
/**
* @brief Get the last error message
* @return The last error message to show to the user
*/
std::string getLastErrorMsg() const;
/**
* @brief Create one Graphics file per page
* @param stateListener A listener to track the progress
*/
void exportGraphics(ProgressListener* stateListener);
/**
* @brief Set a quality level for PNG exports
* @param qParam A quality parameter for the export
*/
void setQualityParameter(RasterImageQualityParameter qParam);
/**
* @brief Set a quality level for PNG exports
* @param criterion A quality criterion for the export
* @param value The target value of this criterion
*/
void setQualityParameter(ExportQualityCriterion criterion, int value);
/**
* @brief Select layers to export by parsing str
* @param str A string parsed to get a list of layers
*/
void setLayerRange(const char* str);
private:
/**
* @brief Create Cairo surface for a given page
* @param width the width of the page being exported
* @param height the height of the page being exported
* @param id the id of the page being exported
* @param zoomRatio the zoom ratio for PNG exports with fixed DPI
*
* @return the zoom ratio of the current page if the export type is PNG, 0.0 otherwise
* The return value may differ from that of the parameter zoomRatio
* if the export has fixed page width or height (in pixels)
*/
double createSurface(double width, double height, size_t id, double zoomRatio);
/**
* Free / store the surface
*/
bool freeSurface(size_t id);
/**
* @brief Get a filename with a (page) number appended
* @param no The appended number. If no==-1, does not append anything.
* e.g. .../export-2.png, if the no is -1, return .../export.png
*
* @return The filename
*/
fs::path getFilenameWithNumber(size_t no) const;
/**
* @brief Export a single PNG/SVG page
* @param pageId The index of the page being exported
* @param id The number of the page being exported
* @param zoomRatio The zoom ratio for PNG exports with fixed DPI
* @param format The format of the exported image
* @param view A DocumentView for drawing the page
*/
void exportImagePage(size_t pageId, size_t id, double zoomRatio, ExportGraphicsFormat format, DocumentView& view);
static constexpr size_t SINGLE_PAGE = size_t(-1);
public:
/**
* Document to export
*/
Document* doc = nullptr;
/**
* Filename for export
*/
fs::path file;
/**
* Export graphics format
*/
ExportGraphicsFormat format = EXPORT_GRAPHICS_UNDEFINED;
/**
* Do not export the Background
*/
ExportBackgroundType exportBackground = EXPORT_BACKGROUND_ALL;
/**
* The range to export
*/
const PageRangeVector& exportRange;
/**
* @brief A pointer to a range of layers to export (the same for every exported pages)
*/
std::unique_ptr<LayerRangeVector> layerRange;
/**
* @brief The export quality parameters, used if format==EXPORT_GRAPHICS_PNG
*/
RasterImageQualityParameter qualityParameter = RasterImageQualityParameter();
/**
* Export surface
*/
cairo_surface_t* surface = nullptr;
/**
* Cairo context
*/
cairo_t* cr = nullptr;
/**
* The last error message to show to the user
*/
std::string lastError;
};
| 5,508
|
C++
|
.h
| 163
| 29.02454
| 119
| 0.692395
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,918
|
SaveJob.h
|
xournalpp_xournalpp/src/core/control/jobs/SaveJob.h
|
/*
* Xournal++
*
* A job which saves a Document
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <functional>
#include <string> // for string
#include "BlockingJob.h" // for BlockingJob
class Control;
class SaveJob: public BlockingJob {
public:
SaveJob(Control* control, std::function<void(bool)> = [](bool) {});
protected:
~SaveJob() override;
public:
void run() override;
bool save();
static void updatePreview(Control* control);
protected:
void afterRun() override;
private:
std::string lastError;
/// Called after saving, with boolean parameter true on success, false on failure (error)
std::function<void(bool)> callback;
};
| 765
|
C++
|
.h
| 31
| 21.83871
| 93
| 0.711911
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,919
|
BaseExportJob.h
|
xournalpp_xournalpp/src/core/control/jobs/BaseExportJob.h
|
/*
* Xournal++
*
* Base class for Exports
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <functional>
#include <string> // for string
#include <gtk/gtk.h> // for GtkWidget
#include "BlockingJob.h" // for BlockingJob
#include "filesystem.h" // for path
/**
* @brief List of types for the export of background components.
* The order must agree with the corresponding listBackgroundType in ui/exportSettings.glade.
* It is constructed so that one can check for intermediate types using comparison.
*/
enum ExportBackgroundType { EXPORT_BACKGROUND_NONE, EXPORT_BACKGROUND_UNRULED, EXPORT_BACKGROUND_ALL };
class Control;
class BaseExportJob: public BlockingJob {
public:
BaseExportJob(Control* control, const std::string& name);
protected:
~BaseExportJob() override;
public:
void afterRun() override;
public:
virtual void showFileChooser(std::function<void()> onFileSelected, std::function<void()> onCancel);
protected:
virtual void addFilterToDialog(GtkFileChooser* dialog) = 0;
static void addFileFilterToDialog(GtkFileChooser* dialog, const std::string& name, const std::string& mimetype);
bool checkOverwriteBackgroundPDF(fs::path const& file) const;
virtual bool testAndSetFilepath(const fs::path& file, const char* filterName = nullptr);
private:
protected:
fs::path filepath;
/**
* Error message to show to the user
*/
std::string errorMsg;
class ExportType {
public:
std::string extension;
std::string mimeType;
ExportType(std::string ext, std::string mime): extension(std::move(ext)), mimeType(std::move(mime)) {}
};
};
| 1,730
|
C++
|
.h
| 51
| 30.607843
| 116
| 0.734375
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,920
|
Scheduler.h
|
xournalpp_xournalpp/src/core/control/jobs/Scheduler.h
|
/*
* Xournal++
*
* A scheduler for background jobs
*
* Some code from Evince project
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <array> // for array
#include <condition_variable> // for condition_variable
#include <deque> // for deque
#include <mutex> // for mutex
#include <string> // for string
#include <glib.h> // for GThread, GTimeVal, gpointer
class Job;
/**
* @file Scheduler.h
* @brief A file containing the definition of the Scheduler
*/
/**
* @enum JobPriority
*
* The priority of the job affects the order of execution:
* Jobs with higher priority are processed before the
* lower ones.
*/
enum JobPriority {
/**
* Urgent: used for rendering the current page
*/
JOB_PRIORITY_URGENT,
/**
* High: used for rendering thumbnail ranges
*/
JOB_PRIORITY_HIGH,
/**
* Low: used for rendering of pages not in the current range
*/
JOB_PRIORITY_LOW,
/**
* None: used for any other job (loading / saving / printing...)
*/
JOB_PRIORITY_NONE,
/**
* The number of priorities
*/
JOB_N_PRIORITIES
};
class Scheduler {
public:
Scheduler();
virtual ~Scheduler();
public:
/**
* Adds a Job to the Scheduler
*
* @param Job the job
* @param priority the desired priority
*
* The Job is now owned by the scheduler, and automatically freed if it is done
*/
void addJob(Job* job, JobPriority priority);
void start();
void stop();
/**
* Locks the complete scheduler
*/
void lock();
/**
* Unlocks the complete scheduler
*/
void unlock();
/**
* Don't render the next X ms so the scrolling performance is better
*/
void blockRerenderZoom();
/**
* Remove the blocked rendering manually
*/
void unblockRerenderZoom();
private:
static auto jobThreadCallback(Scheduler* scheduler) -> gpointer;
auto getNextJobUnlocked(bool onlyNotRender = false, bool* hasRenderJobs = nullptr) -> Job*;
static auto jobRenderThreadTimer(Scheduler* scheduler) -> bool;
protected:
bool threadRunning = true;
guint jobRenderThreadTimerId = 0;
GThread* thread = nullptr;
std::condition_variable jobQueueCond{};
std::mutex jobQueueMutex{};
std::mutex schedulerMutex{};
/**
* This is need to be sure there is no job running if we delete a page.
* If a job is, we may access deleted memory.
*/
std::mutex jobRunningMutex{};
/**
* Jobs of each priority. New jobs
* are added to the back of each queue.
*/
std::deque<Job*> queueUrgent{};
std::deque<Job*> queueHigh{};
std::deque<Job*> queueLow{};
std::deque<Job*> queueNone{};
/**
* Map (JobPriority) -> queue of that priority.
* For example,
* jobQueue[JOB_PRIORITY_URGENT] is &queueUrgent.
*/
std::array<std::deque<Job*>*, JOB_N_PRIORITIES> jobQueue{};
GTimeVal* blockRenderZoomTime = nullptr;
std::mutex blockRenderMutex{};
std::string name;
};
| 3,197
|
C++
|
.h
| 119
| 22.470588
| 95
| 0.64185
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,921
|
Job.h
|
xournalpp_xournalpp/src/core/control/jobs/Job.h
|
/*
* Xournal++
*
* A job which is done
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <atomic>
enum JobType { JOB_TYPE_BLOCKING, JOB_TYPE_PREVIEW, JOB_TYPE_RENDER, JOB_TYPE_AUTOSAVE };
/**
* A manually ref-counted class representing an asynchronous job to be used with
* the Xournal++ scheduler.
*
* Instances of Job (and its subclasses) should be constructed exclusively using
* the `new` keyword.
*/
class Job {
public:
Job();
Job(const Job&) = delete;
Job& operator=(const Job&) = delete;
Job(Job&&) = delete;
Job& operator=(Job&&) = delete;
protected:
virtual ~Job();
public:
/**
* Unref the Job, the initial refcount is set to 1 on creation
*/
void unref();
/**
* Increase the refcount
*/
void ref();
/**
* Delete Job because e.g. the source was removed
*/
void deleteJob();
public:
virtual JobType getType() = 0;
public:
/**
* this method is called
*/
virtual void execute();
virtual void* getSource();
protected:
/**
* override this method
*/
virtual void run() = 0;
/**
* This method should be called as _last_ operation in run
*
* If you call it in another position the object will be deleted before run is finished!
*/
void callAfterRun();
/**
* After run will be called from UI Thread after the Job is finished
*
* All UI Stuff should happen here
*/
virtual void afterRun();
/**
* Called when the job is to be removed from the
* scheduler.
*/
virtual void onDelete();
private:
/**
* Internal callback sent to the GLib main loop which invokes `afterRun`.
*/
static bool callAfterCallback(Job* job);
private:
unsigned int afterRunId = 0;
std::atomic<unsigned int> refCount;
};
| 1,924
|
C++
|
.h
| 81
| 19.54321
| 92
| 0.641644
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,922
|
AutosaveJob.h
|
xournalpp_xournalpp/src/core/control/jobs/AutosaveJob.h
|
/*
* Xournal++
*
* Autosave job
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string> // for string
#include "Job.h" // for Job, JobType
class Control;
class AutosaveJob: public Job {
public:
AutosaveJob(Control* control);
protected:
~AutosaveJob() override;
public:
void run() override;
void afterRun() override;
JobType getType() override;
private:
Control* control = nullptr;
std::string error;
};
| 529
|
C++
|
.h
| 27
| 16.888889
| 41
| 0.701826
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,923
|
XournalScheduler.h
|
xournalpp_xournalpp/src/core/control/jobs/XournalScheduler.h
|
/*
* Xournal++
*
* A scheduler for Xournal background tasks
*
* Some code from Evince project
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include "control/jobs/Job.h" // for JobType
#include "Scheduler.h" // for JobPriority, Scheduler
class SidebarPreviewBaseEntry;
class XojPageView;
class XournalScheduler: public Scheduler {
public:
XournalScheduler();
~XournalScheduler() override;
public:
/**
* Remove source, e.g. if a page is removed they don't need to repaint.
* Blocks until all jobs that could be using the source have finished.
*/
void removeSidebar(SidebarPreviewBaseEntry* preview);
void removePage(XojPageView* view);
/**
* Removes all PreviewJob%s / RenderJob%s scheduled to be run
*/
void removeAllJobs();
void addRepaintSidebar(SidebarPreviewBaseEntry* preview);
void addRerenderPage(XojPageView* view);
/**
* Blocks until all currently running Job%s have been executed
*/
void finishTask();
private:
/**
* Remove source, e.g. if a page is removed they don't need to repaint
*/
void removeSource(void* source, JobType type, JobPriority priority, bool awaitFinishTask = true);
bool existsSource(void* source, JobType type, JobPriority priority);
private:
};
| 1,373
|
C++
|
.h
| 46
| 26.152174
| 101
| 0.720152
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,924
|
BlockingJob.h
|
xournalpp_xournalpp/src/core/control/jobs/BlockingJob.h
|
/*
* Xournal++
*
* A job which is done in the GTK main thread, but the application is blocked
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string> // for string
#include "Job.h" // for Job, JobType
class Control;
class BlockingJob: public Job {
public:
BlockingJob(Control* control, const std::string& name);
protected:
~BlockingJob() override;
public:
void execute() override;
JobType getType() override;
protected:
static auto finished(Control* control) -> bool;
Control* control;
};
| 612
|
C++
|
.h
| 26
| 20.884615
| 77
| 0.717014
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,925
|
CustomExportJob.h
|
xournalpp_xournalpp/src/core/control/jobs/CustomExportJob.h
|
/*
* Xournal++
*
* A customized export
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <map> // for map
#include <string> // for string
#include "util/ElementRange.h" // for PageRangeVector
#include "BaseExportJob.h" // for BaseExportJob, EXPORT_BACKGROUND_ALL
#include "ImageExport.h" // for RasterImageQualityParameter, EXPORT_GRAP...
#include "filesystem.h" // for path
class Control;
class CustomExportJob: public BaseExportJob {
public:
CustomExportJob(Control* control);
protected:
~CustomExportJob() override;
public:
void run() override;
public:
void showDialogAndRun();
protected:
void afterRun() override;
void addFilterToDialog(GtkFileChooser* dialog) override;
/**
* Create one Graphics file per page
*/
void exportGraphics();
bool testAndSetFilepath(const fs::path& file, const char* filterName = nullptr) override;
private:
/**
* The range to export
*/
PageRangeVector exportRange;
/**
* @brief Quality parameter for PNG exports
*/
RasterImageQualityParameter pngQualityParameter = RasterImageQualityParameter();
/**
* Export graphics format
*/
ExportGraphicsFormat format = EXPORT_GRAPHICS_UNDEFINED;
/**
* XOJ Export, else PNG Export
*/
bool exportTypeXoj = false;
/**
* Background export type
*/
ExportBackgroundType exportBackground = EXPORT_BACKGROUND_ALL;
/**
* Export all Layers progressively
*/
bool progressiveMode = false;
std::string lastError;
std::string chosenFilterName;
std::map<std::string, ExportType> filters;
};
| 1,735
|
C++
|
.h
| 64
| 23.015625
| 93
| 0.701456
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,926
|
ToolbarDefinitions.h
|
xournalpp_xournalpp/src/core/gui/ToolbarDefinitions.h
|
/*
* Xournal++
*
* The definitions for the possibel toolbars
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
typedef struct {
/**
* The name in the glade.xml file
*/
const char* guiName;
/**
* The name in the .ini file
*/
const char* propName;
/**
* if horizontal (true) or vertical (false)
*/
bool horizontal;
} ToolbarEntryDefintion;
const static ToolbarEntryDefintion TOOLBAR_DEFINITIONS[] = {
{"tbTop1", "toolbarTop1", true}, {"tbTop2", "toolbarTop2", true},
{"tbLeft1", "toolbarLeft1", false}, {"tbLeft2", "toolbarLeft2", false},
{"tbRight1", "toolbarRight1", false}, {"tbRight2", "toolbarRight2", false},
{"tbBottom1", "toolbarBottom1", true}, {"tbBottom2", "toolbarBottom2", true},
{"tbFloat1", "toolbarFloat1", true}, // define this index below as TBFloatFirst
{"tbFloat2", "toolbarFloat2", true}, {"tbFloat3", "toolbarFloat3", true},
{"tbFloat4", "toolbarFloat4", true} // define this index below as TBFloatLast
};
const static int TOOLBAR_DEFINITIONS_LEN = G_N_ELEMENTS(TOOLBAR_DEFINITIONS);
#define TBFloatFirst 8
#define TBFloatLast 11
| 1,256
|
C++
|
.h
| 37
| 29.540541
| 88
| 0.65429
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,927
|
IconNameHelper.h
|
xournalpp_xournalpp/src/core/gui/IconNameHelper.h
|
/*
* Xournal++
*
* Helper which allows to switch between Xournal++ icons and stock icons
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string>
class Settings;
class IconNameHelper final {
public:
IconNameHelper(Settings* settings);
protected:
const Settings* settings;
public:
std::string iconName(const char* icon) const;
};
| 433
|
C++
|
.h
| 21
| 18.333333
| 72
| 0.743842
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,928
|
PageView.h
|
xournalpp_xournalpp/src/core/gui/PageView.h
|
/*
* Xournal++
*
* Displays a single page
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cstddef> // for size_t
#include <memory> // for unique_ptr, shared_ptr
#include <mutex> // for mutex
#include <string> // for string
#include <vector> // for vector
#include <cairo.h> // for cairo_t
#include <gdk/gdk.h> // for GdkEventKey, GdkRGBA, GdkRectangle
#include <gtk/gtk.h> // for GtkWidget
#include "gui/inputdevices/DeviceId.h"
#include "gui/inputdevices/InputEvents.h"
#include "model/PageListener.h" // for PageListener
#include "model/PageRef.h" // for PageRef
#include "util/Rectangle.h" // for Rectangle
#include "util/raii/CairoWrappers.h" // for CairoSurfaceSPtr
#include "view/Mask.h" // for Mask
#include "view/Repaintable.h" // for Repaintable
#include "Layout.h" // for Layout
#include "LegacyRedrawable.h" // for LegacyRedrawable
class EraseHandler;
class ImageSizeSelection;
class InputHandler;
class SearchControl;
class Selection;
class Settings;
class Text;
class TextEditor;
class VerticalToolHandler;
class XournalView;
class Element;
class PositionInputData;
class Range;
class TexImage;
class XojPdfRectangle;
class XojPdfPage;
namespace xoj::view {
class OverlayView;
class ToolView;
} // namespace xoj::view
class XojPageView: public LegacyRedrawable, public PageListener, public xoj::view::Repaintable {
public:
XojPageView(XournalView* xournal, const PageRef& page);
~XojPageView() override;
public:
void addOverlayView(std::unique_ptr<xoj::view::OverlayView>);
void rerenderPage() override;
void rerenderRect(double x, double y, double width, double height) override;
void repaintPage() const override;
void repaintArea(double x1, double y1, double x2, double y2) const override;
// Repaintable interface
void flagDirtyRegion(const Range& rg) const override;
/**
* @brief This draws the ToolView directly onto the buffer, deletes the view and repaints the given range
* Used to avoid blinking when a tool finished editing an element
*/
void drawAndDeleteToolView(xoj::view::ToolView* v, const Range& rg) override;
/**
* @brief Simply deletes an overlay and any trace of it on the display (provided the overlay is contained in the
* given range)
*/
void deleteOverlayView(xoj::view::OverlayView* v, const Range& rg) override;
double getZoom() const override;
ZoomControl* getZoomControl() const override;
Range getVisiblePart() const override;
double getWidth() const override;
double getHeight() const override;
// End of Repaintable interface
xoj::util::Rectangle<double> toWindowCoordinates(const xoj::util::Rectangle<double>& r) const override;
void setSelected(bool selected);
void setIsVisible(bool visible);
bool isSelected() const;
inline bool isVisible() const { return visible; }
void endText();
void endSpline();
bool searchTextOnPage(const std::string& text, size_t index, size_t* occurrences, XojPdfRectangle* matchRect);
bool onKeyPressEvent(const KeyEvent& event);
bool onKeyReleaseEvent(const KeyEvent& event);
bool cut();
bool copy();
bool paste();
bool actionDelete();
void deleteViewBuffer() override;
/**
* Returns whether this PageView contains the
* given point on the display
*/
bool containsPoint(int x, int y, bool local = false) const;
/**
* Returns Row assigned in current layout
*/
int getMappedRow() const;
/**
* Returns Column assigned in current layout
*/
int getMappedCol() const;
GdkRGBA getSelectionColor() override;
bool hasBuffer() const;
TextEditor* getTextEditor();
/**
* Returns a reference to the XojPage belonging to
* this PageView
*/
const PageRef getPage() const;
XournalView* getXournal() const;
/**
* Returns the width of this XojPageView as displayed
* on the display taking into account the current zoom
*/
int getDisplayWidth() const;
double getDisplayWidthDouble() const;
/**
* Returns the height of this XojPageView as displayed
* on the display taking into account the current zoom
*/
int getDisplayHeight() const;
double getDisplayHeightDouble() const;
/**
* Returns the x coordinate of this XojPageView with
* respect to the display
*/
int getX() const override;
/**
* Returns the y coordinate of this XojPageView with
* respect to the display
*/
int getY() const override;
TexImage* getSelectedTex();
Text* getSelectedText();
xoj::util::Rectangle<double> getRect() const;
public: // event handler
bool onButtonPressEvent(const PositionInputData& pos);
bool onButtonReleaseEvent(const PositionInputData& pos);
bool onButtonDoublePressEvent(const PositionInputData& pos);
bool onButtonTriplePressEvent(const PositionInputData& pos);
bool onMotionNotifyEvent(const PositionInputData& pos);
void onSequenceCancelEvent(DeviceId id);
void onTapEvent(const PositionInputData& pos);
/**
* This event fires after onButtonPressEvent and also
* if no input sequence is actively running and a stylus button was pressed
*/
bool onButtonClickEvent(const PositionInputData& pos);
/**
* This method actually repaints the XojPageView, triggering
* a rerender call if necessary
*/
bool paintPage(cairo_t* cr, GdkRectangle* rect);
public: // listener
void rectChanged(xoj::util::Rectangle<double>& rect) override;
void rangeChanged(Range& range) override;
void pageChanged() override;
void elementChanged(Element* elem) override;
void elementsChanged(const std::vector<Element*>& elements, const Range& range) override;
private:
void startText(double x, double y);
void drawLoadingPage(cairo_t* cr);
/**
* @brief Make and display a popover dialog near the given location.
*
* @param rect specifies the location of the dialog.
* @param child is added to the dialog before displaying.
* @returns a pointer to the popover dialog.
*/
GtkWidget* makePopover(const XojPdfRectangle& rect, GtkWidget* child);
/**
* @brief Display a popover with link-related actions, if one
* is at a given location on the page.
*
* @param page is the current page
* @param targetX
* @param targetY the link must contain (targetX, targetY)
* @returns true iff a URI link exists near/at (targetX, targetY) => a popover was shown
*/
bool displayLinkPopover(std::shared_ptr<XojPdfPage> page, double targetX, double targetY);
void setX(int x);
void setY(int y);
void setMappedRowCol(int row, int col); // row, column assigned by mapper during layout.
/**
* Shows the floating toolbox at the location of an input event
*/
void showFloatingToolbox(const PositionInputData& pos);
/**
* Shows the PDF toolbox at the location of an input event
*/
void showPdfToolbox(const PositionInputData& pos);
void deleteView(xoj::view::OverlayView* v);
private:
PageRef page;
XournalView* xournal = nullptr;
Settings* settings = nullptr;
std::unique_ptr<EraseHandler> eraser;
std::unique_ptr<InputHandler> inputHandler;
std::vector<std::unique_ptr<xoj::view::OverlayView>> overlayViews;
/**
* The selected (while selection)
*/
std::unique_ptr<Selection> selection;
/**
* The text editor
*/
std::unique_ptr<TextEditor> textEditor;
/**
* For image insertion with size (selects the size)
*/
std::unique_ptr<ImageSizeSelection> imageSizeSelection;
/**
* For keeping old text changes to undo!
*/
Text* oldtext;
bool visible = true;
bool selected = false;
xoj::view::Mask buffer;
std::mutex drawingMutex;
bool inEraser = false;
/**
* Vertical Space
*/
std::unique_ptr<VerticalToolHandler> verticalSpace;
/**
* Search handling
*/
std::unique_ptr<SearchControl> search;
std::mutex repaintRectMutex;
std::vector<xoj::util::Rectangle<double>> rerenderRects;
bool rerenderComplete = false;
int dispX{}; // position on display - set in Layout::layoutPages
int dispY{};
int mappedRow{};
int mappedCol{};
DeviceId currentSequenceDeviceId;
friend class RenderJob;
friend class InputHandler;
friend class BaseSelectObject;
friend class SelectObject;
friend class PlayObject;
friend class PdfFloatingToolbox;
// only function allowed to setX(), setY(), setMappedRowCol():
friend void Layout::layoutPages(int width, int height);
};
| 8,906
|
C++
|
.h
| 249
| 31.116466
| 116
| 0.706718
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,929
|
Builder.h
|
xournalpp_xournalpp/src/core/gui/Builder.h
|
/*
* Xournal++
*
* gtk_builder wrapper to parse ui files
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <iostream>
#include <string>
#include <gtk/gtk.h>
#include "util/Assert.h"
#include "util/raii/GObjectSPtr.h"
class GladeSearchpath;
class Builder final {
public:
Builder(GladeSearchpath* gladeSearchPath, const std::string& uiFile);
template <class GObjectType>
GObjectType* get(const std::string& name) {
GObjectType* res = static_cast<GObjectType*>(gtk_builder_get_object(builder.get(), name.c_str()));
xoj_assert_message(res, "ERROR: Builder::get: Could not find UI object: " + name + "\n");
return res;
}
inline GtkWidget* get(const std::string& name) { return GTK_WIDGET(get<GObject>(name)); }
private:
/**
* The Glade resources
*/
xoj::util::GObjectSPtr<GtkBuilder> builder;
};
| 946
|
C++
|
.h
| 33
| 25.242424
| 106
| 0.692478
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,930
|
LegacyRedrawable.h
|
xournalpp_xournalpp/src/core/gui/LegacyRedrawable.h
|
/*
* Xournal++
*
* Interface for GUI handling
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <gdk/gdk.h> // for GdkRGBA
class Element;
class Range;
/*
* The (base) class Redrawable (now LegacyRedrawable) is deprecated. Use xoj::view::Repaintable instead.
*
* Reasons for the deprecation:
*
* * It is basically used synonymously to XojPageView.
* * More importantly, the coexistence of Redrawable::repaint... and Redrawable::rerender... is bothersome.
* it is not clear (without diving in the code) what the difference should be.
* (repaint = ask gtk to call us back to blitt the buffer, rerender = change the buffer's content)
* The rerender... methods should not exist. The derived class should be told what happened (something changed),
* and decide by itself if the buffer should be updated or not (if there is a buffer to begin with).
*/
class [[deprecated]] LegacyRedrawable {
protected:
LegacyRedrawable() = default;
public:
LegacyRedrawable(LegacyRedrawable&&) = default;
LegacyRedrawable(LegacyRedrawable const&) = default;
virtual ~LegacyRedrawable() = default;
LegacyRedrawable& operator=(LegacyRedrawable&&) = default;
LegacyRedrawable& operator=(LegacyRedrawable const&) = default;
/**
* Call this if you only need to repaint the view, this means the buffer will be painted again,
* and all selections, text editors etc. are drawn again, but the view buffer is not refreshed.
*
* for refreshing the view buffer (if you have changed the document) call rerender.
*/
virtual void repaintArea(double x1, double y1, double x2, double y2) const = 0;
[[maybe_unused]] void repaintRect(double x, double y, double width, double height) const;
[[maybe_unused]] void repaintElement(Element* e) const;
/**
* Call this if you only need to readraw the view, this means the buffer will be painted again,
* and all selections, text edtiors etc. are drawn again, but the view buffer is not refreshed.
*
* for refreshing the view buffer (if you have changed the document) call repaint.
*/
virtual void repaintPage() const = 0;
/**
* Repaint our buffer, then redraw the widget
*/
virtual void rerenderPage() = 0;
/**
* Call this if you add an element, remove an element etc.
*/
void rerenderElement(Element* e);
void rerenderRange(const Range& r);
/**
* This updated the view buffer and then rerender the the region, call this if you changed the document
*/
virtual void rerenderRect(double x, double y, double width, double height) = 0;
/**
* Return the GTK selection color
*/
virtual GdkRGBA getSelectionColor() = 0;
virtual void deleteViewBuffer() = 0;
virtual int getX() const = 0;
virtual int getY() const = 0;
};
| 2,925
|
C++
|
.h
| 72
| 36.569444
| 115
| 0.705882
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,931
|
Shadow.h
|
xournalpp_xournalpp/src/core/gui/Shadow.h
|
/*
* Xournal++
*
* Settings Dialog
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <cairo.h> // for cairo_surface_t, cairo_t
class Shadow {
private:
Shadow();
virtual ~Shadow();
static void drawShadowEdge(cairo_t* cr, int x, int y, int width, int height, const unsigned char* edge, double r,
double g, double b);
void drawShadowImpl(cairo_t* cr, int x, int y, int width, int height);
static void paintEdge(cairo_t* cr, cairo_surface_t* image, int x, int y, int width, int height);
void drawShadowTop(cairo_t* cr, int x, int y, int width, double r, double g, double b);
void drawShadowLeft(cairo_t* cr, int x, int y, int height, double r, double g, double b);
void drawShadowRight(cairo_t* cr, int x, int y, int height, double r, double g, double b);
void drawShadowBottom(cairo_t* cr, int x, int y, int width, double r, double g, double b);
public:
/**
* This is the public interface of this class
*/
static void drawShadow(cairo_t* cr, int x, int y, int width, int height);
static int getShadowBottomRightSize();
static int getShadowTopLeftSize();
private:
static Shadow* instance;
cairo_surface_t* edgeTopLeft = nullptr;
cairo_surface_t* edgeTopRight = nullptr;
cairo_surface_t* edgeBottomLeft = nullptr;
cairo_surface_t* edgeBottomRight = nullptr;
cairo_surface_t* top = nullptr;
cairo_surface_t* right = nullptr;
cairo_surface_t* bottom = nullptr;
cairo_surface_t* left = nullptr;
};
| 1,614
|
C++
|
.h
| 42
| 33.904762
| 117
| 0.680538
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,932
|
PopoverFactory.h
|
xournalpp_xournalpp/src/core/gui/PopoverFactory.h
|
/*
* Xournal++
*
* Abstract class for creating popovers
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <gtk/gtk.h> // for GtkWidget
class PopoverFactory {
public:
PopoverFactory() = default;
virtual ~PopoverFactory() = default;
/// Creates a GtkPopover. The returned ref is floating
virtual GtkWidget* createPopover() const = 0;
};
| 440
|
C++
|
.h
| 19
| 20.631579
| 58
| 0.71223
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,933
|
MainWindow.h
|
xournalpp_xournalpp/src/core/gui/MainWindow.h
|
/*
* Xournal++
*
* The Main window
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <array> // for array
#include <atomic> // for atomic_bool
#include <cstddef> // for size_t
#include <memory> // for unique_ptr
#include <string> // for string
#include <gdk/gdk.h> // for GdkDragContext, GdkEvent
#include <glib-object.h> // for GClosure
#include <glib.h> // for gpointer, gboolean, gint
#include <gtk/gtk.h> // for GtkWidget, GtkCheckMenu...
#include "util/Point.h"
#include "util/raii/GObjectSPtr.h"
#include "GladeGui.h" // for GladeGui
#include "ToolbarDefinitions.h" // for TOOLBAR_DEFINITIONS_LEN
class Control;
class Layout;
class SpinPageAdapter;
class ScrollHandling;
class ToolMenuHandler;
class ToolbarData;
class ToolbarModel;
class XournalView;
class PdfFloatingToolbox;
class FloatingToolbox;
class GladeSearchpath;
class Menubar;
typedef std::array<xoj::util::WidgetSPtr, TOOLBAR_DEFINITIONS_LEN> ToolbarWidgetArray;
class MainWindow: public GladeGui {
public:
MainWindow(GladeSearchpath* gladeSearchPath, Control* control, GtkApplication* parent);
~MainWindow() override;
void populate(GladeSearchpath* gladeSearchPath);
public:
GMenuModel* getMenuModel() const;
void show(GtkWindow* parent) override;
void toolbarSelected(const std::string& id);
void toolbarSelected(ToolbarData* d);
ToolbarData* getSelectedToolbar() const;
private:
const ToolbarData* clearToolbar();
void loadToolbar(ToolbarData* d);
public:
/**
* reloadToolbars reloads the currently selected toolbar
*
* This is especially useful when a change in the SettingsDialog should be reflected right away
*/
void reloadToolbars();
void updatePageNumbers(size_t page, size_t pagecount, size_t pdfpage);
void setMaximized(bool maximized);
bool isMaximized() const;
void setFullscreen(bool enabled) const;
bool isDarkTheme() const;
XournalView* getXournal() const;
void setMenubarVisible(bool visible);
void setSidebarVisible(bool visible);
void setToolbarVisible(bool visible);
Control* getControl() const;
PdfFloatingToolbox* getPdfToolbox() const;
FloatingToolbox* getFloatingToolbox() const;
void updateScrollbarSidebarPosition();
void setUndoDescription(const std::string& description);
void setRedoDescription(const std::string& description);
ToolbarModel* getToolbarModel() const;
ToolMenuHandler* getToolMenuHandler() const;
void setDynamicallyGeneratedSubmenuDisabled(bool disabled);
void updateToolbarMenu();
void updateColorscheme();
const ToolbarWidgetArray& getToolbarWidgets() const;
const char* getToolbarName(GtkToolbar* toolbar) const;
Layout* getLayout() const;
[[maybe_unused]] Menubar* getMenubar() const;
/**
* Get the position of the top left corner of screen (X11) or the window (Wayland)
* relative to the Xournal Widget top left corner
*
* @see Util::toWidgetCoords()
*/
xoj::util::Point<double> getNegativeXournalWidgetPos() const;
/**
* Disable kinetic scrolling if there is a touchscreen device that was manually mapped to another enabled input
* device class. This is required so the GtkScrolledWindow does not swallow all the events.
*/
void setGtkTouchscreenScrollingForDeviceMapping();
void setGtkTouchscreenScrollingEnabled(bool enabled);
private:
void initXournalWidget();
void createToolbar();
/**
* Update the position of the separator in the paned container, adjusting it to the saved sidebar width.
* @param contentWidth should be the width of the paned container. The caller should retrieve the width
* of the container before any modifications to it, as that will reset its allocation.
*/
void updatePanedPosition(int contentWidth);
/**
* Window close Button is pressed
*/
static bool deleteEventCallback(GtkWidget* widget, GdkEvent* event, Control* control);
/**
* Window is maximized/minimized
*/
static void windowMaximizedCallback(GObject* window, GParamSpec*, MainWindow* win);
/**
* Callback for drag & drop files
*/
static void dragDataRecived(GtkWidget* widget, GdkDragContext* dragContext, gint x, gint y, GtkSelectionData* data,
guint info, guint time, MainWindow* win);
/**
* Load Overall CSS file with custom icons, other styling and potentially, user changes
*/
static void loadMainCSS(GladeSearchpath* gladeSearchPath, const gchar* cssFilename);
private:
Control* control;
std::unique_ptr<XournalView> xournal;
GtkWidget* winXournal = nullptr;
std::unique_ptr<ScrollHandling> scrollHandling;
std::atomic_bool gtkTouchscreenScrollingEnabled{true};
std::unique_ptr<PdfFloatingToolbox> pdfFloatingToolBox;
std::unique_ptr<FloatingToolbox> floatingToolbox;
// Toolbars
std::unique_ptr<ToolMenuHandler> toolbar;
ToolbarData* selectedToolbar = nullptr;
std::unique_ptr<Menubar> menubar;
bool maximized = false;
bool darkMode = false;
bool modifiedGtkSettingsTheme = false;
ToolbarWidgetArray toolbarWidgets;
bool sidebarVisible = true;
xoj::util::WidgetSPtr boxContainerWidget;
xoj::util::WidgetSPtr panedContainerWidget;
xoj::util::WidgetSPtr mainContentWidget;
xoj::util::WidgetSPtr sidebarWidget;
};
| 5,547
|
C++
|
.h
| 143
| 34.272727
| 119
| 0.739074
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,934
|
GladeGui.h
|
xournalpp_xournalpp/src/core/gui/GladeGui.h
|
/*
* Xournal++
*
* Abstract GUI class, which loads the glade objects
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <string> // for string
#include <gdk/gdk.h> // for GdkWindow
#include <gtk/gtk.h> // for GtkWidget, GtkWindow, GtkBuilder
#include "util/raii/GObjectSPtr.h"
class GladeSearchpath;
class GladeGui {
public:
GladeGui(GladeSearchpath* gladeSearchPath, const std::string& glade, const std::string& mainWnd);
virtual ~GladeGui();
virtual void show(GtkWindow* parent) = 0;
GtkWidget* get(const std::string& name);
void setThemePath(std::string themePath);
GtkWidget* getWindow() const;
GladeSearchpath* getGladeSearchPath() const;
GtkBuilder* getBuilder() const;
private:
/**
* The Glade resources
*/
xoj::util::GObjectSPtr<GtkBuilder> builder;
/**
* Our search paths
*/
GladeSearchpath* gladeSearchPath;
protected:
/**
* This window
*/
GtkWidget* window = nullptr;
};
| 1,068
|
C++
|
.h
| 41
| 22.390244
| 101
| 0.69694
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
12,935
|
FloatingToolbox.h
|
xournalpp_xournalpp/src/core/gui/FloatingToolbox.h
|
/*
* Xournal++
*
* The Floating Toolbox
*
* @author Xournal++ Team
* https://github.com/xournalpp/xournalpp
*
* @license GNU GPLv2 or later
*/
#pragma once
#include <gdk/gdk.h> // for GdkEvent, GdkRectangle
#include <glib.h> // for gboolean
#include <gtk/gtk.h> // for GtkWidget, GtkOverlay
class MainWindow;
enum FloatingToolBoxState { recalcSize = 0, configuration, noChange };
/************************
* FloatingToolbox:
* Uses a GtkOverlay to show a widget containing toolbars.
* The getOverlayPosition callback is used to position the toolbox widget relative to the users input device.
* The ui/main.glade file defines the floatingToolbox as a GtkRevealer widget - attempts to use another widget
* had issues with leave-notify-event.
*/
class FloatingToolbox {
public:
FloatingToolbox(MainWindow* theMainWindow, GtkOverlay* overlay);
virtual ~FloatingToolbox();
public:
/**
* show(x,y): Show Toolbox at centered at x,y relative to main window.
*/
void show(int x, int y);
/**
* showForConfiguration
* i.e. appear in fixed position in top left, extra space and do not hide automatically.
*/
void showForConfiguration();
void hide();
/**
* flagRecalculateSizeRequired(): trigger recalc size on next getOverlayPosition. Used when new toolbars loaded.
*/
void flagRecalculateSizeRequired();
private:
/**
* Callback for positioning overlayed floating menu
*/
static gboolean getOverlayPosition(GtkOverlay* overlay, GtkWidget* widget, GdkRectangle* allocation,
FloatingToolbox* self);
/**
* Callback to hide floating Toolbar when mouse leaves it
*/
static void handleLeaveFloatingToolbox(GtkWidget* floatingToolbox, GdkEvent* event, FloatingToolbox* self);
/**
* Show the Floating Toolbox
* ... but hide some labels depending on conditions.
*/
void show();
/**
* check if user has assigned a button to activate, or has put tools in the FloatingToolbox.
*/
bool floatingToolboxActivated();
/**
* Return number of widgets in toolbox.
* Note this includes non-tools such as spacers and separators.
*/
int countWidgets();
private:
MainWindow* mainWindow;
GtkWidget* floatingToolbox;
/**
* Communicating with getOverlayPosition callback
* */
int floatingToolboxX = 0;
int floatingToolboxY = 0;
FloatingToolBoxState floatingToolboxState = recalcSize;
};
| 2,537
|
C++
|
.h
| 76
| 28.723684
| 116
| 0.69656
|
xournalpp/xournalpp
| 10,962
| 791
| 1,098
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.