1 /***************************************************************************
2  *   copyright       : (C) 2003-2007 by Pascal Brachet,Jan Sundermeyer     *
3  *   http://www.xm1math.net/texmaker/                                      *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  ***************************************************************************/
11 
12 #ifndef Header_InsertGraphics
13 #define Header_InsertGraphics
14 
15 #include "ui_insertgraphics.h"
16 
17 #include "QFileInfo"
18 #include "QListWidgetItem"
19 
20 class InsertGraphicsConfig;
21 
22 
23 class PlacementValidator : public QRegularExpressionValidator
24 {
25 	Q_OBJECT
26 
27 public:
28     explicit PlacementValidator(QObject *parent = nullptr);
29 	void fixup (QString &input) const;
30 	State validate(QString &input, int &pos) const;
31 };
32 
33 
34 class InsertGraphics : public QDialog
35 {
36 	Q_OBJECT
37 
38 public:
39     InsertGraphics(QWidget *parent = nullptr, InsertGraphicsConfig *conf = nullptr);
40 	Q_INVOKABLE QString graphicsFile() const;
41 	QString getLatexText() const;
42 	static QStringList imageFormats();
43 
44 private:
45 	enum PlacementType {PlaceHere = QListWidgetItem::UserType, PlaceTop, PlaceBottom, PlacePage};
46 
47 	InsertGraphicsConfig getConfig() const;
48 	void setConfig(const InsertGraphicsConfig &conf);
49 	bool parseCode(const QString &code, InsertGraphicsConfig &conf);
50 	bool fileNeedsInputCommand(const QString &filename) const;
51 	QString getFormattedFilename(const QString filename) const;
52 	QString getCaptionLabelString(const InsertGraphicsConfig &conf) const;
53 
54 	QString generateLabel(QString fname);
55 	Ui::InsertGraphics ui;
56 	QFileInfo texFile;
57 	QFileInfo masterTexFile;
58 	bool autoLabel;
59 
60 	static QStringList m_imageFormats;
61 	static QStringList widthUnits;
62 	static QStringList heightUnits;
63 
64 	InsertGraphicsConfig *defaultConfig;
65 
66 public slots:
67 	void setTexFile(const QFileInfo &fi);
68 	void setMasterTexFile(const QFileInfo &fi);
69 	void setGraphicsFile(const QString &file);
70 	void setCode(const QString &code);
71 
72 signals:
73 	void fileNameChanged(const QString &);
74 
75 private slots:
76 	void chooseFile();
77 	void includeOptionChanged();
78 	void leFileChanged(const QString &filename);
79 	void labelChanged(const QString &label);
80 	void updateLabel(const QString &fname);
81 	void togglePlacementCheckboxes(bool forceHide = false);
82 	void updatePlacement();
83 	void saveDefault();
84 };
85 
86 #endif
87