LibrePCB Developers Documentation
shortcutsreferencegenerator.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_EDITOR_SHORTCUTSREFERENCEGENERATOR_H
21#define LIBREPCB_EDITOR_SHORTCUTSREFERENCEGENERATOR_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include <QtCore>
27#include <QtWidgets>
28
29/*******************************************************************************
30 * Namespace / Forward Declarations
31 ******************************************************************************/
32namespace librepcb {
33
34class FilePath;
35
36namespace editor {
37
38class EditorCommand;
39class EditorCommandCategory;
40class EditorCommandSet;
41
42/*******************************************************************************
43 * Class ShortcutsReferenceGenerator
44 ******************************************************************************/
45
56public:
57 enum class Flag {
58 Bold = (1 << 0),
59 Italic = (1 << 1),
60 AlignCenter = (1 << 8),
61 AlignRight = (1 << 9),
62 };
63 Q_DECLARE_FLAGS(Flags, Flag)
64
65 // Constructors / Destructor
68 delete;
69 explicit ShortcutsReferenceGenerator(EditorCommandSet& commands) noexcept;
71
72 // General Methods
83 bool generatePdf(const FilePath& fp);
84
85 // Operator Overloadings
87 const ShortcutsReferenceGenerator& rhs) = delete;
88
89private: // Methods
90 void drawSectionTitle(QPdfWriter& writer, QPainter& painter, qreal x1,
91 qreal x2, qreal y, const QString& text) const noexcept;
92 void drawCommandCategory(QPdfWriter& writer, QPainter& painter, qreal x,
93 qreal y, EditorCommandCategory& cat) const noexcept;
94 void drawRow(QPdfWriter& writer, QPainter& painter, qreal x, qreal y,
95 qreal totalWidth, qreal shortcutsWidth, const QString& text,
96 const QString& shortcuts, bool gray) const noexcept;
97 int drawText(QPdfWriter& writer, QPainter& painter, qreal x, qreal y,
98 qreal size, qreal maxLength, const QString& text,
99 Flags flags = Flags()) const noexcept;
100 int mmToPx(QPdfWriter& writer, qreal mm) const noexcept;
101
102private: // Data
104
105 static constexpr qreal sPageWidth = 270;
106 static constexpr qreal sPageHeight = 190;
107 static constexpr qreal sCategoryTextSize = 3;
108 static constexpr qreal sRowTextSize = 2.5;
109 static constexpr qreal sRowHeight = 3;
110 static constexpr qreal sCategorySpacing = 5;
111 static constexpr qreal sColumnSpacing = 3.5;
112 static constexpr qreal sColumnWidth = (sPageWidth - 3 * sColumnSpacing) / 4;
113 static constexpr qreal sShortcutsWidth = 28;
114};
115
116} // namespace editor
117} // namespace librepcb
118
119Q_DECLARE_OPERATORS_FOR_FLAGS(
121
122/*******************************************************************************
123 * End of File
124 ******************************************************************************/
125
126#endif
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
Category for librepcb::editor::EditorCommand.
Definition: editorcommandcategory.h:42
Collection of all commands across all editors.
Definition: editorcommandset.h:49
Helper to generate a keyboard shortcuts reference PDF.
Definition: shortcutsreferencegenerator.h:55
int drawText(QPdfWriter &writer, QPainter &painter, qreal x, qreal y, qreal size, qreal maxLength, const QString &text, Flags flags=Flags()) const noexcept
Definition: shortcutsreferencegenerator.cpp:215
static constexpr qreal sCategorySpacing
Definition: shortcutsreferencegenerator.h:110
EditorCommandSet & mCommands
Definition: shortcutsreferencegenerator.h:103
Flag
Definition: shortcutsreferencegenerator.h:57
void drawCommandCategory(QPdfWriter &writer, QPainter &painter, qreal x, qreal y, EditorCommandCategory &cat) const noexcept
Definition: shortcutsreferencegenerator.cpp:174
static constexpr qreal sShortcutsWidth
Definition: shortcutsreferencegenerator.h:113
static constexpr qreal sRowHeight
Definition: shortcutsreferencegenerator.h:109
static constexpr qreal sColumnSpacing
Definition: shortcutsreferencegenerator.h:111
static constexpr qreal sPageHeight
Definition: shortcutsreferencegenerator.h:106
void drawRow(QPdfWriter &writer, QPainter &painter, qreal x, qreal y, qreal totalWidth, qreal shortcutsWidth, const QString &text, const QString &shortcuts, bool gray) const noexcept
Definition: shortcutsreferencegenerator.cpp:199
static constexpr qreal sCategoryTextSize
Definition: shortcutsreferencegenerator.h:107
static constexpr qreal sColumnWidth
Definition: shortcutsreferencegenerator.h:112
static constexpr qreal sPageWidth
Definition: shortcutsreferencegenerator.h:105
int mmToPx(QPdfWriter &writer, qreal mm) const noexcept
Definition: shortcutsreferencegenerator.cpp:243
bool generatePdf(const FilePath &fp)
Generate the PDF.
Definition: shortcutsreferencegenerator.cpp:60
static constexpr qreal sRowTextSize
Definition: shortcutsreferencegenerator.h:108
void drawSectionTitle(QPdfWriter &writer, QPainter &painter, qreal x1, qreal x2, qreal y, const QString &text) const noexcept
Definition: shortcutsreferencegenerator.cpp:160
Definition: occmodel.cpp:77