Subversion Repositories Scribus

Rev

Rev 5880 | Rev 6044 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
2530 craig 7
#ifndef _UTIL_H
8
#define _UTIL_H
9
 
4464 cbradney 10
#include <vector>
11
 
2530 craig 12
#include <qstring.h>
13
#include <qpixmap.h>
14
#include <qimage.h>
15
#include <qstringlist.h>
16
#include <qwidget.h>
17
#include <qmap.h>
18
#include <qpointarray.h>
19
#include <qvaluelist.h>
20
#include <qpoint.h>
21
#include <qdom.h>
22
 
3808 cbradney 23
#include "fpoint.h"
24
#include "fpointarray.h"
25
#include "pagestructs.h"
26
#include "sccolor.h"
2969 craig 27
#include "scribusapi.h"
2530 craig 28
 
29
class ScribusDoc;
5184 avox 30
class ParagraphStyle;
2530 craig 31
class QDomElement;
32
class ScribusView;
33
struct CopyPasteBuffer;
34
class PageItem;
35
struct Layer;
36
class Foi;
37
 
2969 craig 38
QColor SCRIBUS_API SetColor(ScribusDoc *currentDoc, QString color, int shad);
39
void SCRIBUS_API GetItemProps(bool newVersion, QDomElement *obj, struct CopyPasteBuffer *OB);
4449 subik 40
/*! \brief Returns a sorted list of QStrings - sorted by locale specific rules!
41
Uses compareQStrings() as rule. There is STL used!
42
\author Petr Vanek
4645 subik 43
\param aList unsorted string list
4449 subik 44
\retval QStringList sorted string list
45
 */
2969 craig 46
QStringList SCRIBUS_API sortQStringList(QStringList aList);
47
void SCRIBUS_API ReOrderText(ScribusDoc *currentDoc, ScribusView *view);
48
void SCRIBUS_API WordAndPara(PageItem *currItem, int *w, int *p, int *c, int *wN, int *pN, int *cN);
49
bool SCRIBUS_API overwrite(QWidget *parent, QString filename);
50
FPoint SCRIBUS_API getMaxClipF(FPointArray* Clip);
51
FPoint SCRIBUS_API getMinClipF(FPointArray* Clip);
52
QString SCRIBUS_API Path2Relative(QString Path);
53
QByteArray SCRIBUS_API ComputeMD5Sum(QByteArray *in);
54
char SCRIBUS_API *toHex( uchar u );
55
QString SCRIBUS_API String2Hex(QString *in, bool lang = true);
56
QString SCRIBUS_API CompressStr(QString *in);
5234 fschmid 57
QByteArray SCRIBUS_API CompressArray(QByteArray *in);
2969 craig 58
void SCRIBUS_API Level2Layer(ScribusDoc *currentDoc, struct Layer *ll, int Level);
2937 cbradney 59
//int Layer2Level(ScribusDoc *currentDoc, int LayerNr);
2969 craig 60
void SCRIBUS_API BezierPoints(QPointArray *ar, QPoint n1, QPoint n2, QPoint n3, QPoint n4);
61
double SCRIBUS_API xy2Deg(double x, double y);
62
QPointArray SCRIBUS_API FlattenPath(FPointArray ina, QValueList<uint> &Segs);
63
QPointArray SCRIBUS_API RegularPolygon(double w, double h, uint c, bool star, double factor, double rota);
64
FPointArray SCRIBUS_API RegularPolygonF(double w, double h, uint c, bool star, double factor, double rota);
65
QPixmap SCRIBUS_API *getSmallPixmap(QColor rgb);
66
QPixmap SCRIBUS_API *getWidePixmap(QColor rgb);
4449 subik 67
/*! \brief Create a cool all-infos pixmaps for the specified color.
68
\param col Scribus color
69
\retval QPixmap image with various icons depending on the col properties.
70
*/
3497 avox 71
QPixmap SCRIBUS_API *getFancyPixmap(ScColor col);
4449 subik 72
/*! \brief Put toPaint pixmap into target at the x, y place.
73
There is handled the alpha channel/transparency too. In the beginning
74
is the target pixmap filled with all_transparent mask. In the case of
75
the painting of tiPaint into x, y place, there is this pixmap enabled
76
in alpha mask too.
77
\param toPaint a pixmap to be painted into target
78
\param target a base pixmap. Some kind of painter.
79
\param x coordinate
80
\param y coordinate
81
*/
5361 cbradney 82
void SCRIBUS_API paintAlert(QPixmap &toPaint, QPixmap &target, int x = 0, int y = 0, bool useMask = true);
2969 craig 83
QPixmap SCRIBUS_API loadIcon(QString nam);
84
uint SCRIBUS_API getDouble(QString in, bool raw);
4449 subik 85
//! \brief WARNING: loadText is INCORRECT - use loadRawText instead!
2969 craig 86
bool SCRIBUS_API loadText(QString nam, QString *Buffer);
4449 subik 87
/*! \brief Replacement version of loadText that returns a QCString as an out parameter.
88
The QCString is filled with the contents of the specified file. The return
89
byte string is of unknown encoding; the caller must handle encoding issues.
90
There is no need to preallocate the buffer, and the new data replaces any
91
old contents. */
3646 craig 92
bool SCRIBUS_API loadRawText(const QString & filename, QCString & buf);
5234 fschmid 93
bool SCRIBUS_API loadRawBytes(const QString & filename, QByteArray & buf);
2969 craig 94
QString SCRIBUS_API GetAttr(QDomElement *el, QString at, QString def="0");
5880 jghali 95
QImage SCRIBUS_API ProofImage(QImage *Im, ScribusDoc* doc);
4449 subik 96
/**
97
* @brief Synchronously execute a new process, optionally saving its output
98
   *
99
   * Create a new process via QProcess and wait until finished.  Return the
100
   * process exit code. Exit code 1 is returned if the process could not be
101
   * started or terminated abnormally.
102
   *
103
   * Note that the argument list is handled exactly as documented by QProcess.
104
   * In particular, no shell metacharacter expansion is performed (so you can't
105
   * use $HOME for example, and no quoting is required or appropriate), and each
106
   * list entry is one argument.
107
   *
108
   * If output file paths are provided, any existing file will be truncated and
109
   * overwritten.
110
   *
111
   * @param args Arguments, as per QProcess documentation.
112
   * @param fileStdErr Path to save error output to, or "" to discard.
113
   * @param fileStdOut Path to save normal output to, or "" to discard.
114
   * @return Program exit code, or 1 on failure.
115
   *
116
*/
4194 fschmid 117
int SCRIBUS_API System(const QStringList & args, const QString fileStdErr = "", const QString fileStdOut = "");
2969 craig 118
int SCRIBUS_API copyFile(QString source, QString target);
119
int SCRIBUS_API moveFile(QString source, QString target);
4449 subik 120
/*!
121
 \fn QString checkFileExtension(const QString &currName, const QString &extension)
122
 \author Craig Bradney
123
 \brief A quick function to make sure a filename has the correct extension and add it if not
124
 \param currName Current filename
125
 \param extension File extension to ensure exists
126
 */
2969 craig 127
QString SCRIBUS_API checkFileExtension(const QString &, const QString &);
4449 subik 128
//! \brief On Windows, return short path name, else return longPath;
2969 craig 129
QString SCRIBUS_API getShortPathName(QString longPath);
4449 subik 130
/*! \brief Creates a common name for page exports (SVG, bitmap, EPS).
131
   Output format is: documentname-page01.extension
132
   \param pageNo number of the exported page (begins from 1)
133
   \param extension "svg" or e.g. "png" etc.
134
   \retval QString standardized filename
135
   \author Petr Vanek
136
 */
5781 cbradney 137
QString SCRIBUS_API getFileNameByPage(ScribusDoc* currDoc, uint pageNo, QString extension);
3240 fschmid 138
void SCRIBUS_API sDebug(QString message);
3689 cbradney 139
inline double SCRIBUS_API square(double);
140
inline double SCRIBUS_API distance(double, double);
4754 cbradney 141
/*! \brief Constrains an angle of rotation to 45 degree intervals
142
   Will make code simpler and reduce interval or provide as a parameter
143
   \param double angle Angle in degrees
144
   \retval double Constrained angle
145
 */
146
double SCRIBUS_API constrainAngle(double angle);
3757 cbradney 147
const QString SCRIBUS_API getStringFromSequence(DocumentSectionType type, uint position);
3784 cbradney 148
const QString SCRIBUS_API arabicToRoman(uint i);
149
const QString SCRIBUS_API numberToLetterSequence(uint i);
150
void SCRIBUS_API parsePagesString(QString pages, std::vector<int>* pageNs, int sourcePageCount);
5184 avox 151
 
152
#ifndef NLS_CONFORMANCE
5581 jghali 153
int SCRIBUS_API findParagraphStyle(ScribusDoc* doc, const ParagraphStyle& parStyle);
2530 craig 154
#endif
5184 avox 155
 
5557 subik 156
/*! \brief painting the QCheckBox as pixmap.
157
painting the QCheckBox as pixmap. PV for bug #2057.
158
There is no allowed to have more than 1 checkbox in a common QListViewItem
159
(QCheckListItem or how is it named...). Using a QTable is 12-13x times slower
160
than using a QListView. So I choose painting 2 checkboxes as 2 QPixmaps
161
and using a setPixmap method for their changing.
162
\author Petr Vanek */
5712 fschmid 163
QPixmap SCRIBUS_API getQCheckBoxPixmap(const bool checked, const QColor background);
5890 subik 164
 
165
/*! \brief Convert a color in RGB space to HSV space (Hue, Saturation, Value).
166
 * \param red the red component (modified in place).
167
 * \param green the green component (modified in place).
168
 * \param blue the blue component (modified in place).
169
 */
5712 fschmid 170
unsigned char SCRIBUS_API INT_MULT ( unsigned char a, unsigned char b );
5890 subik 171
/*! \brief Convert a color in HSV space to RGB space.
172
 * \param hue the hue component (modified in place).
173
 * \param saturation the saturation component (modified in place).
174
 * \param value the value component (modified in place).
175
 */
5712 fschmid 176
void SCRIBUS_API RGBTOHSV ( uchar& red, uchar& green, uchar& blue );
5890 subik 177
/*! \brief Convert a color in RGB space to HLS space (Hue, Lightness, Saturation).
178
 * \param red the red component (modified in place).
179
 * \param green the green component (modified in place).
180
 * \param blue the blue component (modified in place).
181
 */
5712 fschmid 182
void SCRIBUS_API HSVTORGB ( uchar& hue, uchar& saturation, uchar& value );
183
void SCRIBUS_API RGBTOHLS ( uchar& red, uchar& green, uchar& blue );
5890 subik 184
/*! \brief Implement the HLS "double hex-cone".
185
 * \param n1 lightness fraction (?)
186
 * \param n2 saturation fraction (?)
187
 * \param hue hue "angle".
188
 * \return HLS value.
189
 */
5712 fschmid 190
int SCRIBUS_API HLSVALUE ( double n1, double n2, double hue );
5890 subik 191
/*! \brief Convert a color in HLS space to RGB space.
192
 * \param hue the hue component (modified in place).
193
 * \param lightness the lightness component (modified in place).
194
 * \param saturation the saturation component (modified in place).
195
 */
5712 fschmid 196
void SCRIBUS_API HLSTORGB ( uchar& hue, uchar& lightness, uchar& saturation );
5557 subik 197
 
5890 subik 198
/*! \brief performance measurements.
199
It prints given message with it current timestamp.
200
Useful for duration holes finding.
201
\author Petr Vanek */
202
void tDebug(QString message);
203
 
5184 avox 204
#endif