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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
/***************************************************************************
* Copyright (C) 2004 by Antonio Fasolato *
* Antonio.Fasolato@poste.it *
* *
* This program 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef MAINWIDGET_H
#define MAINWIDGET_H
#include "MainWidgetBase.h"
#include <tqstring.h>
#include <tqprocess.h>
#include <tqstringlist.h>
#include <tqpixmap.h>
#include <tqclipboard.h>
#include <tqevent.h>
#include <tqlabel.h>
#include <kurl.h>
#include <vector>
using namespace std;
class Options;
//! The app's main widget
/*!
* \author Antonio Fasolato <Antonio.Fasolato@poste.it>
* \version 1.2
*
* This is the widget containing all the facilities to work with the image the user is tracing. It shows the current image and potrace output (if it exists), an interface to set the options and the buttons to control the execution of potrace.
*/
class MainWidget : public MainWidgetBase
{
Q_OBJECT
TQ_OBJECT
//! For simplicity
friend class potracegui;
public:
//! Default constructor (all parameters are simply passed to MainWidgetBase)
MainWidget(TQWidget* tqparent = 0, const char* name = 0, WFlags fl = 0 );
//! Default destructor
~MainWidget();
private:
//! Contains the temporary file name used while tracing
TQString m_tmpFilename;
//! Contains the input file name for autotrace
TQString m_tmpInputFilename;
//! Contains the real file name where to save the traced image
TQString m_outputFilename;
//! The process of potrace (used to abort it and to control its exit status)
TQProcess tracer;
//! To know if the tracing has exited normally, or it has been interrupted
bool aborted;
//! To know if the current document is different from the saved one
bool m_changed;
//! The history of the options (not used yet, it will permit undo/redo in the future)
vector<Options *> m_state;
//! The history of the previews (not used yet, it will permit undo/redo in the future)
vector<TQPixmap> m_oldPreviews;
//! The current options
vector<Options *>::iterator m_currentState;
//! The current preview image
vector<TQPixmap>::iterator m_currentPreview;
//! Label to display the original image
TQLabel *originalLabel;
//! Label to display the traced image
TQLabel *previewLabel;
//! Retrives an image from an URL
/*!
* \param url The url of the image
*
* Retrives an image from an URL and loads into the original image viewer: if it is a local file, it simply loads it, if it is a remote URL, first it downloads it, then it loads it.<BR>
* After loading the image, it resets the options for the document (unless otherwise specified by the user.)
*/
void getImageFromURL(KURL url);
//! Gets the options from m_currentState and sets up all the widget from this informations
/*!
* \sa getOptions()
*/
void readOptions();
//! Gets the options from all the widget and saves them into m_currentState
/*!
* \sa readOptions()
*/
void getOptions();
//! Gets the options for potrace from all the widget and saves them into m_currentState
/*!
* \sa readOptions()
*/
void getPotraceOptions();
//! Gets the options for autotrace from all the widget and saves them into m_currentState
/*!
* \sa readOptions()
*/
void getAutotraceOptions();
//! Creates the command line for tracing
/*!
* It reads m_currentState and creates from all the options a commandline to be executed
* \returns A TQStringList that can be used as a commandline to a TQProcess
*/
TQStringList createCommandLine();
//! Creates the command line for tracing with potrace
/*!
* It reads m_currentState and creates from all the options a commandline to be executed
* \returns A TQStringList that can be used as a commandline to a TQProcess
*/
TQStringList createPotraceCommandLine();
//! Creates the command line for tracing with autotrace
/*!
* It reads m_currentState and creates from all the options a commandline to be executed
* \returns A TQStringList that can be used as a commandline to a TQProcess
*/
TQStringList createAutotraceCommandLine();
//! Sets m_tmpFilename to a new temporary filename (generated through mkstemp())
bool createTmpFilename();
//! Deletes the file pointed by m_tmpFilename
bool deleteTmpFilename();
//! Shows a KDialog whit nformations
/*!
* \param caption The caption of the dialog
* \param text The text to display into the dialog
* \returns The code of the dialog button pressed.
*/
int notificationDialog(TQString caption, TQString text);
//! Accepts only a KURL
void dragEnterEvent(TQDragEnterEvent* event);
//! Receives a KURL and loads it.
/*!
* \sa getImageFromURL()
*/
void dropEvent(TQDropEvent* event);
private slots:
//! Opens a file (whith a KFileDialog)
void fileOpen();
//! Saves the current image
void fileSave();
//! Saves the current image whith an alternate name
void fileSaveAs();
//! Closes the file (and the window)
void fileClose();
//! Cuts the original image into the clipboard
void cut();
//! Copies the current image into the clipboard
void copy();
//! Gets an image (if any) from the clipboard
void paste();
//! Executed when the tracer process has ended.
/*!
* Executed when the tracer process has ended. If the process was successful it loads the traced image into the preview widget (unless otherways specified by the user)
*/
void tracerExited();
//! Closes tracer stdin after passing the original image to it
void writeCompleted();
//! Executes potrace whith the options specified by the user
/*!
* \sa createCommandLine()
*/
void trace();
//! Reverts to the default options
void defaultOptions();
//! When an output format for potrace has been selected, it shows the relevant options
void showOptions(const TQString &selection);
//! When a backend has been selected, it shows the relevant options
void backendChoosen(const TQString &back);
//! Syncronize margins if corresponding checkbox is checked
void marginValueChanged( double newValue);
signals:
//! Emitted to change the statusbar
/*!
* \param message The message to display into the statusbar
*/
void signalChangeStatusbar(TQString message);
protected:
bool marginValueSynconizingNecessary;
};
#endif
|