forked from kleintom/Cstitch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patternMetadata.h
167 lines (143 loc) · 5.36 KB
/
patternMetadata.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//
// Copyright 2010, 2011 Tom Klein.
//
// This file is part of cstitch.
//
// cstitch is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef PATTERNMETADATA_H
#define PATTERNMETADATA_H
#include <QtWidgets/QPlainTextEdit>
#include "cancelAcceptDialogBase.h"
class QComboBox;
class QSettings;
class QVBoxLayout;
class QHBoxLayout;
class QGroupBox;
class QLabel;
class QSpinBox;
class QSettings;
// a QPlainTextEdit that always has a fixed line width (scrollbar is
// always visible) and returns as its text the first n lines, where n is
// specified at construction
class fixedWidthTextEdit : public QPlainTextEdit {
Q_OBJECT
public:
fixedWidthTextEdit(int fixedPixelWidth, int numberOfLines,
QWidget* parent)
: QPlainTextEdit(parent), fixedPixelWidth_(fixedPixelWidth),
numberOfLines_(numberOfLines) {
setTabChangesFocus(true);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
}
// return the first numberOfLines_ lines of text
QString startText() const {
QTextCursor cursor = textCursor();
// move to start of document
cursor.movePosition(QTextCursor::Start);
for (int i = 1; i < numberOfLines_; ++i) {
// move down a line (noop if there's no line to move down to)
cursor.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor);
}
cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
return cursor.selectedText().replace(QChar(0x2029), '\n');
}
private:
const int fixedPixelWidth_; // max width of the user's string in pixels
// number of maxPixelWidth_ lines of input we allow
const int numberOfLines_;
};
// class patternMetadata
//
// A dialog to get user input for the pdf pattern metadata: pattern title,
// pattern created by, original image (photo) by.
// Note that there's currently no way to produce pdf output with active
// hyperlinks, part of the reason we don't have explicit fields for such
// information.
//
class patternMetadata : public cancelAcceptDialogBase {
Q_OBJECT
public:
patternMetadata(int pdfWidth, int titleFontSize, int patternByFontSize,
int photoByFontSize, QWidget* parent);
void constructSymbolPreview(const QSettings& settings);
QString title() const { return titleEdit_->startText(); }
QString patternBy() const { return patternByEdit_->startText(); }
QString photoBy() const { return photoByEdit_->startText(); }
// use QSettings to save the current input fields to disk
void saveSettings() const;
int titleFontSize() const { return titleFontSize_; }
int patternByFontSize() const { return patternByFontSize_; }
int photoByFontSize() const { return photoByFontSize_; }
int pdfSymbolSize() const;
private slots:
// insert the text of the currently selected license at the current point
void insertPatternByLicense();
// insert the text of the currently selected license at the current point
void insertPhotoByLicense();
// clear all info fields
void clearMetadata();
// update the symbol size preview to reflect <newSymbolSize>
void updateSymbolSize(int newSymbolSize);
private:
// load text for <editor> from <settings> using the settings key
// <settingsKey>
void loadSettings(const QSettings& settings,
const QString& settingsKey,
fixedWidthTextEdit* editor);
// load <box> with copyright/license options (use the actual copyright
// symbol if <font> provides it, else use (c)); add "derived from"
// options if <derived>
void loadLicenses(QComboBox* box, const QFont& font, bool derived);
private:
QVBoxLayout* widgetLayout_;
QGroupBox* metadataBox_;
QVBoxLayout* metadataLayout_;
//// pattern title
QLabel* titleLabel_;
fixedWidthTextEdit* titleEdit_;
const QString titleSettingsKey_;
const int titleFontSize_;
// number of lines we'll use from the pattern by and photo by edits
const int linesToKeep_;
//// "pattern by" information
QLabel* patternByLabel_;
fixedWidthTextEdit* patternByEdit_;
// the QSettings key string to use for patternByEdit_
const QString patternBySettingsKey_;
const int patternByFontSize_;
QHBoxLayout* patternByLicenseLayout_;
QPushButton* patternByLicenseButton_;
QComboBox* patternByLicenses_;
//// "photo by" information
QLabel* photoByLabel_;
fixedWidthTextEdit* photoByEdit_;
// the QSettings key string to use for photoByEdit_
const QString photoBySettingsKey_;
const int photoByFontSize_;
QHBoxLayout* photoByLicenseLayout_;
QPushButton* photoByLicenseButton_;
QComboBox* photoByLicenses_;
QPushButton* clearMetadataButton_;
//// symbol size selection
QGroupBox* symbolSizeBox_;
QVBoxLayout* symbolSizeLayout_;
QHBoxLayout* symbolSizeTitleLayout_;
QLabel* symbolSizeTitle_;
QSpinBox* symbolSizeSpinBox_;
QString symbolSizeKey_;
QHBoxLayout* symbolPreviewLayout_;
QLabel* symbolPreview_;
};
#endif