insilmaril@0
|
1 |
#include "texteditor.h"
|
insilmaril@0
|
2 |
|
insilmaril@0
|
3 |
#include <iostream>
|
insilmaril@53
|
4 |
#include <cstdlib>
|
insilmaril@0
|
5 |
#include <typeinfo>
|
insilmaril@0
|
6 |
|
insilmaril@53
|
7 |
#include "noteobj.h"
|
insilmaril@53
|
8 |
#include "settings.h"
|
insilmaril@0
|
9 |
|
insilmaril@0
|
10 |
extern int statusbarTime;
|
insilmaril@53
|
11 |
extern Settings settings;
|
insilmaril@53
|
12 |
|
insilmaril@53
|
13 |
extern QAction *actionViewToggleNoteEditor;
|
insilmaril@53
|
14 |
|
insilmaril@53
|
15 |
extern QString iconPath;
|
insilmaril@53
|
16 |
extern QString vymName;
|
insilmaril@0
|
17 |
|
insilmaril@0
|
18 |
using namespace std;
|
insilmaril@0
|
19 |
|
insilmaril@0
|
20 |
|
insilmaril@0
|
21 |
///////////////////////////////////////////////////////////////////////
|
insilmaril@0
|
22 |
///////////////////////////////////////////////////////////////////////
|
insilmaril@0
|
23 |
|
insilmaril@53
|
24 |
|
insilmaril@0
|
25 |
TextEditor::TextEditor()
|
insilmaril@0
|
26 |
{
|
insilmaril@0
|
27 |
printer = new QPrinter( QPrinter::HighResolution );
|
insilmaril@53
|
28 |
printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
|
insilmaril@0
|
29 |
|
insilmaril@53
|
30 |
e = new QTextEdit( this);
|
insilmaril@0
|
31 |
e->setFocus();
|
insilmaril@53
|
32 |
e->setTextFormat(Qt::RichText); // default
|
insilmaril@0
|
33 |
e->setTabStopWidth (20); // unit is pixel
|
insilmaril@53
|
34 |
e->setColor (Qt::black);
|
insilmaril@53
|
35 |
e->setAutoFillBackground (true);
|
insilmaril@0
|
36 |
connect (e, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
|
insilmaril@0
|
37 |
setCentralWidget( e );
|
insilmaril@53
|
38 |
statusBar()->message( tr("Ready","Statusbar message"), statusbarTime);
|
insilmaril@53
|
39 |
setCaption(vymName +" - " +tr ("Note Editor","Window caption"));
|
insilmaril@53
|
40 |
|
insilmaril@53
|
41 |
|
insilmaril@53
|
42 |
connect(e, SIGNAL(currentCharFormatChanged(const QTextCharFormat &)),
|
insilmaril@53
|
43 |
this, SLOT(formatChanged(const QTextCharFormat &)));
|
insilmaril@53
|
44 |
|
insilmaril@53
|
45 |
|
insilmaril@0
|
46 |
|
insilmaril@0
|
47 |
// Toolbars
|
insilmaril@0
|
48 |
setupFileActions();
|
insilmaril@0
|
49 |
setupEditActions();
|
insilmaril@0
|
50 |
setupFormatActions();
|
insilmaril@0
|
51 |
setupSettingsActions();
|
insilmaril@0
|
52 |
|
insilmaril@0
|
53 |
// Various states
|
insilmaril@53
|
54 |
blockChangedSignal=false;
|
insilmaril@0
|
55 |
setInactive();
|
insilmaril@0
|
56 |
|
insilmaril@0
|
57 |
// Load Settings
|
insilmaril@53
|
58 |
resize (settings.value ( "/satellite/noteeditor/geometry/size", QSize(450,600)).toSize());
|
insilmaril@53
|
59 |
move (settings.value ( "/satellite/noteeditor/geometry/pos", QPoint (250,50)).toPoint());
|
insilmaril@0
|
60 |
|
insilmaril@53
|
61 |
setShowWithMain (settings.value ( "/satellite/noteeditor/showWithMain",true).toBool());
|
insilmaril@0
|
62 |
|
insilmaril@53
|
63 |
varFont.fromString( settings.value
|
insilmaril@53
|
64 |
("/satellite/noteeditor/fonts/varFont",
|
insilmaril@53
|
65 |
"Nimbus Sans l,14,-1,5,48,0,0,0,0,0").toString()
|
insilmaril@0
|
66 |
);
|
insilmaril@53
|
67 |
fixedFont.fromString (settings.value(
|
insilmaril@53
|
68 |
"/satellite/noteeditor/fonts/fixedFont",
|
insilmaril@53
|
69 |
"Courier,14,-1,5,48,0,0,0,1,0").toString()
|
insilmaril@0
|
70 |
);
|
insilmaril@53
|
71 |
QString s=settings.value ("/satellite/noteeditor/fonts/fonthintDefault","variable").toString();
|
insilmaril@0
|
72 |
if (s == "fixed")
|
insilmaril@0
|
73 |
{
|
insilmaril@0
|
74 |
actionSettingsFonthintDefault->setOn (true);
|
insilmaril@0
|
75 |
e->setCurrentFont (fixedFont);
|
insilmaril@0
|
76 |
} else
|
insilmaril@0
|
77 |
{
|
insilmaril@0
|
78 |
actionSettingsFonthintDefault->setOn (false);
|
insilmaril@0
|
79 |
e->setCurrentFont (varFont);
|
insilmaril@0
|
80 |
}
|
insilmaril@53
|
81 |
filenameHint="";
|
insilmaril@53
|
82 |
|
insilmaril@53
|
83 |
// Restore position of toolbars
|
insilmaril@53
|
84 |
restoreState (settings.value("/satellite/noteeditor/state",0).toByteArray());
|
insilmaril@53
|
85 |
|
insilmaril@53
|
86 |
// Save settings in vymrc
|
insilmaril@53
|
87 |
settings.setValue("/mainwindow/printerName",printer->printerName());
|
insilmaril@0
|
88 |
}
|
insilmaril@0
|
89 |
|
insilmaril@0
|
90 |
|
insilmaril@0
|
91 |
TextEditor::~TextEditor()
|
insilmaril@0
|
92 |
{
|
insilmaril@0
|
93 |
if (printer) delete printer;
|
insilmaril@0
|
94 |
// Save Settings
|
insilmaril@53
|
95 |
settings.setValue( "/satellite/noteeditor/geometry/size", size() );
|
insilmaril@53
|
96 |
settings.setValue( "/satellite/noteeditor/geometry/pos", pos() );
|
insilmaril@53
|
97 |
settings.setValue ("/satellite/noteeditor/state",saveState(0));
|
insilmaril@0
|
98 |
|
insilmaril@53
|
99 |
settings.setValue( "/satellite/noteeditor/showWithMain",showwithmain);
|
insilmaril@0
|
100 |
|
insilmaril@0
|
101 |
QString s;
|
insilmaril@0
|
102 |
if (actionSettingsFonthintDefault->isOn() )
|
insilmaril@0
|
103 |
s="fixed";
|
insilmaril@0
|
104 |
else
|
insilmaril@0
|
105 |
s="variable";
|
insilmaril@53
|
106 |
settings.setValue( "/satellite/noteeditor/fonts/fonthintDefault",s );
|
insilmaril@53
|
107 |
settings.setValue("/satellite/noteeditor/fonts/varFont", varFont.toString() );
|
insilmaril@53
|
108 |
settings.setValue("/satellite/noteeditor/fonts/fixedFont", fixedFont.toString() );
|
insilmaril@53
|
109 |
|
insilmaril@53
|
110 |
|
insilmaril@0
|
111 |
}
|
insilmaril@0
|
112 |
|
insilmaril@0
|
113 |
bool TextEditor::isEmpty()
|
insilmaril@0
|
114 |
{
|
insilmaril@53
|
115 |
if (e->toPlainText().length()>0)
|
insilmaril@0
|
116 |
return false;
|
insilmaril@0
|
117 |
else
|
insilmaril@0
|
118 |
return true;
|
insilmaril@0
|
119 |
}
|
insilmaril@0
|
120 |
|
insilmaril@0
|
121 |
void TextEditor::setShowWithMain(bool v)
|
insilmaril@0
|
122 |
{
|
insilmaril@0
|
123 |
showwithmain=v;
|
insilmaril@0
|
124 |
}
|
insilmaril@0
|
125 |
|
insilmaril@0
|
126 |
bool TextEditor::showWithMain()
|
insilmaril@0
|
127 |
{
|
insilmaril@0
|
128 |
return showwithmain;
|
insilmaril@0
|
129 |
}
|
insilmaril@0
|
130 |
|
insilmaril@53
|
131 |
|
insilmaril@0
|
132 |
void TextEditor::setFontHint (const QString &fh)
|
insilmaril@0
|
133 |
{
|
insilmaril@0
|
134 |
if (fh=="fixed")
|
insilmaril@0
|
135 |
actionFormatUseFixedFont->setOn (true);
|
insilmaril@0
|
136 |
else
|
insilmaril@0
|
137 |
actionFormatUseFixedFont->setOn (false);
|
insilmaril@0
|
138 |
}
|
insilmaril@0
|
139 |
|
insilmaril@0
|
140 |
|
insilmaril@0
|
141 |
QString TextEditor::getFontHint()
|
insilmaril@0
|
142 |
{
|
insilmaril@0
|
143 |
if (actionFormatUseFixedFont->isOn())
|
insilmaril@0
|
144 |
return "fixed";
|
insilmaril@0
|
145 |
else
|
insilmaril@0
|
146 |
return "var";
|
insilmaril@0
|
147 |
}
|
insilmaril@0
|
148 |
|
insilmaril@0
|
149 |
QString TextEditor::getFontHintDefault()
|
insilmaril@0
|
150 |
{
|
insilmaril@0
|
151 |
if (actionSettingsFonthintDefault->isOn())
|
insilmaril@0
|
152 |
return "fixed";
|
insilmaril@0
|
153 |
else
|
insilmaril@0
|
154 |
return "var";
|
insilmaril@0
|
155 |
}
|
insilmaril@0
|
156 |
|
insilmaril@0
|
157 |
void TextEditor::setFilename(const QString &fn)
|
insilmaril@0
|
158 |
{
|
insilmaril@0
|
159 |
if (state==filledEditor)
|
insilmaril@53
|
160 |
{
|
insilmaril@0
|
161 |
if (fn.isEmpty() )
|
insilmaril@0
|
162 |
{
|
insilmaril@0
|
163 |
filename="";
|
insilmaril@53
|
164 |
statusBar()->message( tr("No filename available for this note.","Statusbar message"), statusbarTime );
|
insilmaril@0
|
165 |
}
|
insilmaril@0
|
166 |
else
|
insilmaril@0
|
167 |
{
|
insilmaril@0
|
168 |
filename=fn;
|
insilmaril@53
|
169 |
statusBar()->message( tr(QString( "Current filename is %1" ).arg( filename ),"Statusbar message"), statusbarTime );
|
insilmaril@0
|
170 |
}
|
insilmaril@53
|
171 |
}
|
insilmaril@0
|
172 |
}
|
insilmaril@0
|
173 |
|
insilmaril@0
|
174 |
QString TextEditor::getFilename()
|
insilmaril@0
|
175 |
{
|
insilmaril@0
|
176 |
return filename;
|
insilmaril@0
|
177 |
}
|
insilmaril@0
|
178 |
|
insilmaril@53
|
179 |
void TextEditor::setFilenameHint(const QString &fnh)
|
insilmaril@0
|
180 |
{
|
insilmaril@53
|
181 |
filenameHint=fnh;
|
insilmaril@53
|
182 |
}
|
insilmaril@53
|
183 |
|
insilmaril@53
|
184 |
QString TextEditor::getFilenameHint()
|
insilmaril@53
|
185 |
{
|
insilmaril@53
|
186 |
return filenameHint;
|
insilmaril@53
|
187 |
}
|
insilmaril@53
|
188 |
|
insilmaril@53
|
189 |
bool TextEditor::findText(const QString &t, const QTextDocument::FindFlags &flags)
|
insilmaril@53
|
190 |
{
|
insilmaril@53
|
191 |
if (e->find (t,flags))
|
insilmaril@0
|
192 |
return true;
|
insilmaril@0
|
193 |
else
|
insilmaril@0
|
194 |
return false;
|
insilmaril@0
|
195 |
}
|
insilmaril@0
|
196 |
|
insilmaril@0
|
197 |
void TextEditor::setupFileActions()
|
insilmaril@0
|
198 |
{
|
insilmaril@53
|
199 |
QToolBar *tb = addToolBar ( tr("Note Actions") );
|
insilmaril@53
|
200 |
tb->setObjectName ("noteEditorFileActions");
|
insilmaril@53
|
201 |
QMenu *fileMenu = menuBar()->addMenu( tr( "&Note","Menubar" ));
|
insilmaril@0
|
202 |
|
insilmaril@0
|
203 |
QAction *a;
|
insilmaril@53
|
204 |
a = new QAction( QPixmap( iconPath+"fileopen.png"), tr( "&Import..." ),this);
|
insilmaril@53
|
205 |
a->setStatusTip (tr( "Import","Status tip for Note menu" ) );
|
insilmaril@53
|
206 |
a->setShortcut( Qt::CTRL + Qt::Key_O );
|
insilmaril@0
|
207 |
connect( a, SIGNAL( activated() ), this, SLOT( textLoad() ) );
|
insilmaril@53
|
208 |
tb->addAction (a);
|
insilmaril@53
|
209 |
fileMenu->addAction (a);
|
insilmaril@0
|
210 |
actionFileLoad=a;
|
insilmaril@0
|
211 |
|
insilmaril@53
|
212 |
fileMenu->addSeparator();
|
insilmaril@53
|
213 |
a = new QAction( QPixmap(iconPath+"filesave.png" ), tr( "&Export..." ),this);
|
insilmaril@53
|
214 |
a->setStatusTip (tr( "Export Note (HTML)","Status tip for Note menu" ) );
|
insilmaril@53
|
215 |
a->setShortcut( Qt::CTRL + Qt::Key_S );
|
insilmaril@0
|
216 |
connect( a, SIGNAL( activated() ), this, SLOT( textSave() ) );
|
insilmaril@53
|
217 |
tb->addAction (a);
|
insilmaril@53
|
218 |
fileMenu->addAction (a);
|
insilmaril@0
|
219 |
actionFileSave=a;
|
insilmaril@0
|
220 |
|
insilmaril@53
|
221 |
a = new QAction( QPixmap(), tr( "Export &As... (HTML)" ), this);
|
insilmaril@53
|
222 |
a->setStatusTip (tr( "Export Note As (HTML) ","Status tip for Note Menu" ));
|
insilmaril@0
|
223 |
connect( a, SIGNAL( activated() ), this, SLOT( textSaveAs() ) );
|
insilmaril@53
|
224 |
fileMenu->addAction (a);
|
insilmaril@0
|
225 |
actionFileSaveAs=a;
|
insilmaril@0
|
226 |
|
insilmaril@53
|
227 |
a = new QAction(QPixmap(), tr( "Export &As...(ASCII)" ), this);
|
insilmaril@53
|
228 |
a->setStatusTip ( tr( "Export Note As (ASCII) ","Status tip for note menu" ) );
|
insilmaril@53
|
229 |
a->setShortcut(Qt::ALT + Qt::Key_X );
|
insilmaril@0
|
230 |
connect( a, SIGNAL( activated() ), this, SLOT( textExportAsASCII() ) );
|
insilmaril@53
|
231 |
fileMenu->addAction (a);
|
insilmaril@0
|
232 |
actionFileSaveAs=a;
|
insilmaril@0
|
233 |
|
insilmaril@53
|
234 |
fileMenu->addSeparator();
|
insilmaril@53
|
235 |
a = new QAction( QPixmap(iconPath+"fileprint.png" ), tr( "&Print..." ),this);
|
insilmaril@53
|
236 |
a->setStatusTip (tr( "Print Note","Status tip for note menu" ) );
|
insilmaril@53
|
237 |
a->setShortcut( Qt::CTRL + Qt::Key_P );
|
insilmaril@0
|
238 |
connect( a, SIGNAL( activated() ), this, SLOT( textPrint() ) );
|
insilmaril@53
|
239 |
tb->addAction (a);
|
insilmaril@53
|
240 |
fileMenu->addAction (a);
|
insilmaril@0
|
241 |
actionFilePrint=a;
|
insilmaril@0
|
242 |
}
|
insilmaril@0
|
243 |
|
insilmaril@0
|
244 |
void TextEditor::setupEditActions()
|
insilmaril@0
|
245 |
{
|
insilmaril@53
|
246 |
QToolBar *tb = addToolBar ( tr( "Edit Actions" ));
|
insilmaril@53
|
247 |
tb->setObjectName ("noteEditorEditActions");
|
insilmaril@53
|
248 |
QMenu *editMenu = menuBar()->addMenu ( tr( "&Edit" ));
|
insilmaril@0
|
249 |
|
insilmaril@0
|
250 |
QAction *a;
|
insilmaril@53
|
251 |
a = new QAction(QPixmap(iconPath+"undo.png"), tr( "&Undo" ), this );
|
insilmaril@53
|
252 |
a->setStatusTip ( tr( "Undo","Status tip for note menu" ) );
|
insilmaril@53
|
253 |
a->setShortcut(Qt::CTRL + Qt::Key_Z );
|
insilmaril@0
|
254 |
connect( a, SIGNAL( activated() ), e, SLOT( undo() ) );
|
insilmaril@53
|
255 |
editMenu->addAction (a);
|
insilmaril@53
|
256 |
tb->addAction (a);
|
insilmaril@0
|
257 |
actionEditUndo=a;
|
insilmaril@0
|
258 |
|
insilmaril@53
|
259 |
a = new QAction(QPixmap(iconPath+"redo.png" ), tr( "&Redo" ),this);
|
insilmaril@53
|
260 |
a->setStatusTip ( tr( "Redo","Status tip for note menu" ) );
|
insilmaril@53
|
261 |
a->setShortcut( Qt::CTRL + Qt::Key_Y );
|
insilmaril@0
|
262 |
connect( a, SIGNAL( activated() ), e, SLOT( redo() ) );
|
insilmaril@53
|
263 |
editMenu->addAction (a);
|
insilmaril@53
|
264 |
tb->addAction (a);
|
insilmaril@0
|
265 |
actionEditRedo=a;
|
insilmaril@0
|
266 |
|
insilmaril@53
|
267 |
editMenu->addSeparator();
|
insilmaril@53
|
268 |
a = new QAction(QPixmap(), tr( "Select and copy &all" ),this);
|
insilmaril@53
|
269 |
a->setStatusTip ( tr( "Select and copy all","Status tip for note menu" ) );
|
insilmaril@53
|
270 |
a->setShortcut( Qt::CTRL + Qt::Key_A );
|
insilmaril@0
|
271 |
connect( a, SIGNAL( activated() ), this, SLOT( editCopyAll() ) );
|
insilmaril@53
|
272 |
editMenu->addAction (a);
|
insilmaril@0
|
273 |
|
insilmaril@53
|
274 |
editMenu->addSeparator();
|
insilmaril@53
|
275 |
a = new QAction(QPixmap(iconPath+"editcopy.png" ), tr( "&Copy" ),this);
|
insilmaril@53
|
276 |
a->setStatusTip ( tr( "Copy","Status tip for note menu" ) );
|
insilmaril@53
|
277 |
a->setShortcut( Qt::CTRL + Qt::Key_C );
|
insilmaril@0
|
278 |
connect( a, SIGNAL( activated() ), e, SLOT( copy() ) );
|
insilmaril@53
|
279 |
editMenu->addAction (a);
|
insilmaril@53
|
280 |
tb->addAction (a);
|
insilmaril@0
|
281 |
actionEditCopy=a;
|
insilmaril@0
|
282 |
|
insilmaril@53
|
283 |
a = new QAction(QPixmap(iconPath+"editcut.png" ), tr( "Cu&t" ),this);
|
insilmaril@53
|
284 |
a->setStatusTip ( tr( "Cut","Status tip for note menu" ) );
|
insilmaril@53
|
285 |
a->setShortcut( Qt::CTRL + Qt::Key_X );
|
insilmaril@0
|
286 |
connect( a, SIGNAL( activated() ), e, SLOT( cut() ) );
|
insilmaril@53
|
287 |
editMenu->addAction (a);
|
insilmaril@53
|
288 |
tb->addAction (a);
|
insilmaril@0
|
289 |
actionEditCut=a;
|
insilmaril@0
|
290 |
|
insilmaril@53
|
291 |
a = new QAction(QPixmap(iconPath+"editpaste.png" ), tr( "&Paste" ),this);
|
insilmaril@53
|
292 |
a->setStatusTip ( tr( "Paste","Status tip for note menu" ) );
|
insilmaril@53
|
293 |
a->setShortcut( Qt::CTRL + Qt::Key_V );
|
insilmaril@0
|
294 |
connect( a, SIGNAL( activated() ), e, SLOT( paste() ) );
|
insilmaril@53
|
295 |
editMenu->addAction (a);
|
insilmaril@53
|
296 |
tb->addAction (a);
|
insilmaril@0
|
297 |
actionEditPaste=a;
|
insilmaril@0
|
298 |
|
insilmaril@53
|
299 |
a = new QAction( QPixmap( iconPath+"edittrash.png"), tr( "&Delete All" ), this);
|
insilmaril@53
|
300 |
a->setStatusTip (tr( "Delete all","Status tip for note menu" ) );
|
insilmaril@0
|
301 |
connect( a, SIGNAL( activated() ), e, SLOT( clear() ) );
|
insilmaril@53
|
302 |
editMenu->addAction (a);
|
insilmaril@53
|
303 |
tb->addAction (a);
|
insilmaril@0
|
304 |
actionEditDeleteAll=a;
|
insilmaril@0
|
305 |
|
insilmaril@0
|
306 |
}
|
insilmaril@0
|
307 |
|
insilmaril@0
|
308 |
void TextEditor::setupFormatActions()
|
insilmaril@0
|
309 |
{
|
insilmaril@53
|
310 |
QToolBar *tb = addToolBar ( tr("Format Actions" ));
|
insilmaril@53
|
311 |
tb->setObjectName ("noteEditorFormatActions");
|
insilmaril@53
|
312 |
QMenu *formatMenu = menuBar()->addMenu ( tr( "F&ormat" ));
|
insilmaril@0
|
313 |
|
insilmaril@0
|
314 |
QAction *a;
|
insilmaril@0
|
315 |
|
insilmaril@53
|
316 |
a = new QAction( QPixmap(iconPath+"formatfixedfont.png"), tr( "&Font hint" ), Qt::ALT + Qt::Key_I, this, "fontHint" );
|
insilmaril@53
|
317 |
a->setStatusTip (tr( "Toggle font hint for the whole text","Status tip for note menu" ) );
|
insilmaril@0
|
318 |
a->setToggleAction (true);
|
insilmaril@53
|
319 |
a->setOn (settings.value("/noteeditor/fonts/useFixedByDefault",false).toBool() );
|
insilmaril@0
|
320 |
connect( a, SIGNAL( activated() ), this, SLOT( toggleFonthint() ) );
|
insilmaril@53
|
321 |
formatMenu->addAction (a);
|
insilmaril@53
|
322 |
tb->addAction (a);
|
insilmaril@0
|
323 |
actionFormatUseFixedFont=a;
|
insilmaril@0
|
324 |
|
insilmaril@53
|
325 |
comboFont = new QComboBox;
|
insilmaril@53
|
326 |
tb->addWidget (comboFont);
|
insilmaril@53
|
327 |
QFontDatabase fontDB;
|
insilmaril@53
|
328 |
comboFont->insertStringList( fontDB.families() );
|
insilmaril@0
|
329 |
connect( comboFont, SIGNAL( activated( const QString & ) ),
|
insilmaril@0
|
330 |
this, SLOT( textFamily( const QString & ) ) );
|
insilmaril@53
|
331 |
comboFont->addItem( QApplication::font().family() );
|
insilmaril@53
|
332 |
comboSize = new QComboBox;
|
insilmaril@53
|
333 |
tb->addWidget (comboSize);
|
insilmaril@53
|
334 |
QList<int> sizes=fontDB.standardSizes();
|
insilmaril@53
|
335 |
QList<int>::iterator i = sizes.begin();
|
insilmaril@53
|
336 |
while (i != sizes.end())
|
insilmaril@53
|
337 |
{
|
insilmaril@53
|
338 |
++i; // increment i before using it
|
insilmaril@53
|
339 |
comboSize->insertItem ( QString::number(*i));
|
insilmaril@53
|
340 |
}
|
insilmaril@0
|
341 |
connect( comboSize, SIGNAL( activated( const QString & ) ),
|
insilmaril@0
|
342 |
this, SLOT( textSize( const QString & ) ) );
|
insilmaril@53
|
343 |
comboSize->addItem ( QString::number( QApplication::font().pointSize() ) );
|
insilmaril@0
|
344 |
|
insilmaril@53
|
345 |
formatMenu->addSeparator();
|
insilmaril@0
|
346 |
|
insilmaril@0
|
347 |
QPixmap pix( 16, 16 );
|
insilmaril@0
|
348 |
pix.fill( e->color());
|
insilmaril@53
|
349 |
a = new QAction( pix, tr( "&Color..." ), this);
|
insilmaril@53
|
350 |
formatMenu->addAction (a);
|
insilmaril@53
|
351 |
tb->addAction (a);
|
insilmaril@53
|
352 |
connect( a, SIGNAL( activated() ), this, SLOT( textColor() ) );
|
insilmaril@53
|
353 |
actionTextColor=a;
|
insilmaril@0
|
354 |
|
insilmaril@53
|
355 |
a = new QAction( QPixmap (iconPath+"text_bold.png"), tr( "&Bold" ), this);
|
insilmaril@53
|
356 |
a->setShortcut(Qt::CTRL + Qt::Key_B );
|
insilmaril@53
|
357 |
connect( a, SIGNAL( activated() ), this, SLOT( textBold() ) );
|
insilmaril@53
|
358 |
tb->addAction (a);
|
insilmaril@53
|
359 |
formatMenu->addAction (a);
|
insilmaril@53
|
360 |
a->setToggleAction( true );
|
insilmaril@53
|
361 |
actionTextBold=a;
|
insilmaril@53
|
362 |
|
insilmaril@53
|
363 |
a = new QAction( QPixmap(iconPath+"text_italic.png"), tr( "&Italic" ), this);
|
insilmaril@53
|
364 |
a->setShortcut(Qt::CTRL + Qt::Key_I);
|
insilmaril@53
|
365 |
connect( a, SIGNAL( activated() ), this, SLOT( textItalic() ) );
|
insilmaril@53
|
366 |
tb->addAction (a);
|
insilmaril@53
|
367 |
formatMenu->addAction (a);
|
insilmaril@53
|
368 |
a->setToggleAction( true );
|
insilmaril@53
|
369 |
actionTextItalic=a;
|
insilmaril@53
|
370 |
|
insilmaril@53
|
371 |
a = new QAction( QPixmap (iconPath+"text_under.png"), tr( "&Underline" ), this);
|
insilmaril@53
|
372 |
a->setShortcut(Qt::CTRL + Qt::Key_U );
|
insilmaril@53
|
373 |
connect( a, SIGNAL( activated() ), this, SLOT( textUnderline() ) );
|
insilmaril@53
|
374 |
tb->addAction (a);
|
insilmaril@53
|
375 |
formatMenu->addAction (a);
|
insilmaril@53
|
376 |
a->setToggleAction( true );
|
insilmaril@53
|
377 |
actionTextUnderline=a;
|
insilmaril@53
|
378 |
formatMenu->addSeparator();
|
insilmaril@0
|
379 |
|
insilmaril@53
|
380 |
QActionGroup *grp2 = new QActionGroup( this );
|
insilmaril@53
|
381 |
grp2->setExclusive(true);
|
insilmaril@53
|
382 |
a = new QAction( QPixmap (iconPath+"text_sub.png"), tr( "Subs&cript" ),grp2 );
|
insilmaril@53
|
383 |
a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_B );
|
insilmaril@53
|
384 |
a->setToggleAction( true );
|
insilmaril@53
|
385 |
tb->addAction (a);
|
insilmaril@53
|
386 |
formatMenu->addAction (a);
|
insilmaril@53
|
387 |
connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
|
insilmaril@53
|
388 |
actionAlignSubScript=a;
|
insilmaril@53
|
389 |
|
insilmaril@53
|
390 |
a = new QAction( QPixmap (iconPath+"text_super.png"), tr( "Su&perscript" ),grp2 );
|
insilmaril@53
|
391 |
a->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_P );
|
insilmaril@53
|
392 |
a->setToggleAction( true );
|
insilmaril@53
|
393 |
tb->addAction (a);
|
insilmaril@53
|
394 |
formatMenu->addAction (a);
|
insilmaril@53
|
395 |
connect(a, SIGNAL(activated()), this, SLOT(textVAlign()));
|
insilmaril@53
|
396 |
actionAlignSuperScript=a;
|
insilmaril@0
|
397 |
QActionGroup *grp = new QActionGroup( this );
|
insilmaril@0
|
398 |
connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
|
insilmaril@0
|
399 |
|
insilmaril@53
|
400 |
formatMenu->addSeparator();
|
insilmaril@0
|
401 |
|
insilmaril@53
|
402 |
a = new QAction( QPixmap (iconPath+"text_left.png"), tr( "&Left" ),grp );
|
insilmaril@53
|
403 |
a->setShortcut( Qt::CTRL+Qt::Key_L );
|
insilmaril@53
|
404 |
a->setToggleAction( true );
|
insilmaril@53
|
405 |
tb->addAction (a);
|
insilmaril@53
|
406 |
formatMenu->addAction (a);
|
insilmaril@53
|
407 |
actionAlignLeft=a;
|
insilmaril@53
|
408 |
a = new QAction( QPixmap (iconPath+"text_center.png"), tr( "C&enter" ),grp);
|
insilmaril@53
|
409 |
a->setShortcut( Qt::CTRL + Qt::Key_E);
|
insilmaril@53
|
410 |
a->setToggleAction( true );
|
insilmaril@53
|
411 |
tb->addAction (a);
|
insilmaril@53
|
412 |
formatMenu->addAction (a);
|
insilmaril@53
|
413 |
actionAlignCenter=a;
|
insilmaril@53
|
414 |
a = new QAction( QPixmap (iconPath+"text_right.png" ), tr( "&Right" ), grp);
|
insilmaril@53
|
415 |
a->setShortcut(Qt::CTRL + Qt::Key_R );
|
insilmaril@53
|
416 |
a->setToggleAction( true );
|
insilmaril@53
|
417 |
tb->addAction (a);
|
insilmaril@53
|
418 |
formatMenu->addAction (a);
|
insilmaril@53
|
419 |
actionAlignRight=a;
|
insilmaril@53
|
420 |
a = new QAction( QPixmap ( iconPath+"text_block.png"), tr( "&Justify" ), grp );
|
insilmaril@53
|
421 |
a->setShortcut(Qt::CTRL + Qt::Key_J );
|
insilmaril@53
|
422 |
a->setToggleAction( true );
|
insilmaril@53
|
423 |
tb->addAction (a);
|
insilmaril@53
|
424 |
formatMenu->addAction (a);
|
insilmaril@53
|
425 |
actionAlignJustify=a;
|
insilmaril@0
|
426 |
}
|
insilmaril@0
|
427 |
|
insilmaril@0
|
428 |
void TextEditor::setupSettingsActions()
|
insilmaril@0
|
429 |
{
|
insilmaril@53
|
430 |
QMenu *settingsMenu = menuBar()->addMenu ( tr( "&Settings" ));
|
insilmaril@0
|
431 |
|
insilmaril@0
|
432 |
QAction *a;
|
insilmaril@53
|
433 |
a = new QAction(tr( "Set &fixed font" ), this);
|
insilmaril@53
|
434 |
a->setStatusTip ( tr( "Set fixed font","Status tip for note menu" ));
|
insilmaril@0
|
435 |
connect( a, SIGNAL( activated() ), this, SLOT( setFixedFont() ) );
|
insilmaril@53
|
436 |
settingsMenu->addAction (a);
|
insilmaril@0
|
437 |
actionSettingsFixedFont=a;
|
insilmaril@0
|
438 |
|
insilmaril@53
|
439 |
a = new QAction(tr( "Set &variable font" ), this);
|
insilmaril@53
|
440 |
a->setStatusTip ( tr( "Set variable font","Status tip for note menu" ) );
|
insilmaril@0
|
441 |
connect( a, SIGNAL( activated() ), this, SLOT( setVarFont() ) );
|
insilmaril@53
|
442 |
settingsMenu->addAction (a);
|
insilmaril@0
|
443 |
actionSettingsVarFont=a;
|
insilmaril@0
|
444 |
|
insilmaril@53
|
445 |
a = new QAction(tr( "&fixed font is default" ), this);
|
insilmaril@53
|
446 |
a->setStatusTip (tr( "Used fixed font by default","Status tip for note menu" ) );
|
insilmaril@0
|
447 |
a->setToggleAction (true);
|
insilmaril@0
|
448 |
// set state later in constructor...
|
insilmaril@53
|
449 |
settingsMenu->addAction (a);
|
insilmaril@0
|
450 |
actionSettingsFonthintDefault=a;
|
insilmaril@0
|
451 |
}
|
insilmaril@0
|
452 |
|
insilmaril@0
|
453 |
void TextEditor::textLoad()
|
insilmaril@0
|
454 |
{
|
insilmaril@0
|
455 |
if (state!=inactiveEditor)
|
insilmaril@0
|
456 |
{
|
insilmaril@53
|
457 |
if (!isEmpty())
|
insilmaril@0
|
458 |
{
|
insilmaril@53
|
459 |
QMessageBox mb( vymName + " - " +tr("Note Editor"),
|
insilmaril@0
|
460 |
"Loading will overwrite the existing note",
|
insilmaril@0
|
461 |
QMessageBox::Warning,
|
insilmaril@0
|
462 |
QMessageBox::Yes | QMessageBox::Default,
|
insilmaril@0
|
463 |
QMessageBox::Cancel,
|
insilmaril@0
|
464 |
0 );
|
insilmaril@0
|
465 |
mb.setButtonText( QMessageBox::Yes, "Load note" );
|
insilmaril@0
|
466 |
switch( mb.exec() ) {
|
insilmaril@0
|
467 |
case QMessageBox::Cancel:
|
insilmaril@0
|
468 |
return;
|
insilmaril@0
|
469 |
break;
|
insilmaril@0
|
470 |
}
|
insilmaril@0
|
471 |
}
|
insilmaril@0
|
472 |
// Load note
|
insilmaril@0
|
473 |
QFileDialog *fd=new QFileDialog( this);
|
insilmaril@53
|
474 |
QStringList types;
|
insilmaril@53
|
475 |
types<< "VYM notes (*.html)" <<
|
insilmaril@53
|
476 |
"ASCII texts (*.txt)" <<
|
insilmaril@53
|
477 |
"All filed (*)";
|
insilmaril@53
|
478 |
fd->setFilters (types);
|
insilmaril@53
|
479 |
fd->setDirectory (QDir().current());
|
insilmaril@0
|
480 |
fd->show();
|
insilmaril@0
|
481 |
QString fn;
|
insilmaril@0
|
482 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@0
|
483 |
fn = fd->selectedFile();
|
insilmaril@0
|
484 |
|
insilmaril@0
|
485 |
if ( !fn.isEmpty() )
|
insilmaril@0
|
486 |
{
|
insilmaril@0
|
487 |
QFile f( fn );
|
insilmaril@53
|
488 |
if ( !f.open( QIODevice::ReadOnly ) )
|
insilmaril@0
|
489 |
return;
|
insilmaril@0
|
490 |
|
insilmaril@0
|
491 |
QTextStream ts( &f );
|
insilmaril@0
|
492 |
setText( ts.read() );
|
insilmaril@0
|
493 |
editorChanged();
|
insilmaril@0
|
494 |
}
|
insilmaril@0
|
495 |
}
|
insilmaril@0
|
496 |
}
|
insilmaril@0
|
497 |
|
insilmaril@0
|
498 |
void TextEditor::closeEvent( QCloseEvent* ce )
|
insilmaril@0
|
499 |
{
|
insilmaril@53
|
500 |
ce->accept(); // TextEditor can be reopened with show()
|
insilmaril@53
|
501 |
showwithmain=false;
|
insilmaril@53
|
502 |
hide();
|
insilmaril@53
|
503 |
emit (windowClosed() );
|
insilmaril@53
|
504 |
return;
|
insilmaril@0
|
505 |
}
|
insilmaril@0
|
506 |
|
insilmaril@0
|
507 |
QString TextEditor::getText()
|
insilmaril@0
|
508 |
{
|
insilmaril@53
|
509 |
if (e->toPlainText().isEmpty())
|
insilmaril@53
|
510 |
return "";
|
insilmaril@53
|
511 |
else
|
insilmaril@53
|
512 |
return e->text();
|
insilmaril@0
|
513 |
}
|
insilmaril@0
|
514 |
|
insilmaril@0
|
515 |
void TextEditor::editorChanged()
|
insilmaril@0
|
516 |
{
|
insilmaril@0
|
517 |
if (isEmpty())
|
insilmaril@0
|
518 |
state=emptyEditor;
|
insilmaril@0
|
519 |
else
|
insilmaril@0
|
520 |
state=filledEditor;
|
insilmaril@0
|
521 |
|
insilmaril@0
|
522 |
if (state==emptyEditor)
|
insilmaril@53
|
523 |
setState (emptyEditor);
|
insilmaril@0
|
524 |
else
|
insilmaril@53
|
525 |
setState (filledEditor);
|
insilmaril@0
|
526 |
// SLOT is LinkableMapObj, which will update systemFlag
|
insilmaril@53
|
527 |
if (!blockChangedSignal) emit (textHasChanged() );
|
insilmaril@0
|
528 |
}
|
insilmaril@0
|
529 |
|
insilmaril@0
|
530 |
|
insilmaril@0
|
531 |
void TextEditor::setText(QString t)
|
insilmaril@0
|
532 |
{
|
insilmaril@53
|
533 |
blockChangedSignal=true;
|
insilmaril@0
|
534 |
e->setReadOnly(false);
|
insilmaril@0
|
535 |
e->setText(t);
|
insilmaril@0
|
536 |
enableActions();
|
insilmaril@53
|
537 |
blockChangedSignal=false;
|
insilmaril@0
|
538 |
}
|
insilmaril@0
|
539 |
|
insilmaril@0
|
540 |
void TextEditor::setInactive()
|
insilmaril@0
|
541 |
{
|
insilmaril@53
|
542 |
state=inactiveEditor;
|
insilmaril@0
|
543 |
setText("");
|
insilmaril@53
|
544 |
setState (inactiveEditor);
|
insilmaril@0
|
545 |
e->setReadOnly (true);
|
insilmaril@0
|
546 |
|
insilmaril@0
|
547 |
disableActions();
|
insilmaril@0
|
548 |
}
|
insilmaril@0
|
549 |
|
insilmaril@0
|
550 |
void TextEditor::editCopyAll()
|
insilmaril@0
|
551 |
{
|
insilmaril@0
|
552 |
e->selectAll();
|
insilmaril@0
|
553 |
e->copy();
|
insilmaril@0
|
554 |
}
|
insilmaril@0
|
555 |
|
insilmaril@0
|
556 |
void TextEditor::textSaveAs()
|
insilmaril@0
|
557 |
{
|
insilmaril@0
|
558 |
QString fn = QFileDialog::getSaveFileName( QString::null, "VYM Note (HTML) (*.html);;All files (*)",
|
insilmaril@0
|
559 |
this,"export note dialog",tr("Export Note to single file") );
|
insilmaril@0
|
560 |
|
insilmaril@0
|
561 |
if ( !fn.isEmpty() )
|
insilmaril@0
|
562 |
{
|
insilmaril@0
|
563 |
QFile file (fn);
|
insilmaril@0
|
564 |
if (file.exists())
|
insilmaril@0
|
565 |
{
|
insilmaril@53
|
566 |
QMessageBox mb( vymName,
|
insilmaril@53
|
567 |
tr("The file %1\nexists already.\nDo you want to overwrite it?","dialog 'save note as'").arg(fn),
|
insilmaril@0
|
568 |
QMessageBox::Warning,
|
insilmaril@0
|
569 |
QMessageBox::Yes | QMessageBox::Default,
|
insilmaril@0
|
570 |
QMessageBox::Cancel | QMessageBox::Escape,
|
insilmaril@53
|
571 |
Qt::NoButton );
|
insilmaril@0
|
572 |
mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
|
insilmaril@0
|
573 |
mb.setButtonText( QMessageBox::No, tr("Cancel"));
|
insilmaril@0
|
574 |
switch( mb.exec() ) {
|
insilmaril@0
|
575 |
case QMessageBox::Yes:
|
insilmaril@0
|
576 |
// save
|
insilmaril@0
|
577 |
filename = fn;
|
insilmaril@0
|
578 |
textSave();
|
insilmaril@0
|
579 |
return;
|
insilmaril@0
|
580 |
case QMessageBox::Cancel:
|
insilmaril@0
|
581 |
// do nothing
|
insilmaril@0
|
582 |
break;
|
insilmaril@0
|
583 |
}
|
insilmaril@0
|
584 |
} else
|
insilmaril@0
|
585 |
{
|
insilmaril@0
|
586 |
filename = fn;
|
insilmaril@0
|
587 |
textSave();
|
insilmaril@0
|
588 |
return;
|
insilmaril@0
|
589 |
}
|
insilmaril@0
|
590 |
}
|
insilmaril@53
|
591 |
statusBar()->message(tr( "Couldn't export note ","dialog 'save note as'") + fn, statusbarTime );
|
insilmaril@0
|
592 |
}
|
insilmaril@0
|
593 |
|
insilmaril@0
|
594 |
|
insilmaril@0
|
595 |
void TextEditor::textSave()
|
insilmaril@0
|
596 |
{
|
insilmaril@0
|
597 |
if ( filename.isEmpty() )
|
insilmaril@0
|
598 |
{
|
insilmaril@0
|
599 |
textSaveAs();
|
insilmaril@0
|
600 |
return;
|
insilmaril@0
|
601 |
}
|
insilmaril@0
|
602 |
|
insilmaril@0
|
603 |
QString text = e->text();
|
insilmaril@0
|
604 |
QFile f( filename );
|
insilmaril@53
|
605 |
if ( !f.open( QIODevice::WriteOnly ) )
|
insilmaril@0
|
606 |
{
|
insilmaril@0
|
607 |
statusBar()->message( QString("Could not write to %1").arg(filename),
|
insilmaril@0
|
608 |
statusbarTime );
|
insilmaril@0
|
609 |
return;
|
insilmaril@0
|
610 |
}
|
insilmaril@0
|
611 |
|
insilmaril@0
|
612 |
QTextStream t( &f );
|
insilmaril@0
|
613 |
t << text;
|
insilmaril@0
|
614 |
f.close();
|
insilmaril@0
|
615 |
|
insilmaril@0
|
616 |
e->setModified( FALSE );
|
insilmaril@0
|
617 |
|
insilmaril@0
|
618 |
statusBar()->message( QString( "Note exported as %1" ).arg( filename ), statusbarTime );
|
insilmaril@0
|
619 |
}
|
insilmaril@0
|
620 |
|
insilmaril@0
|
621 |
void TextEditor::textExportAsASCII()
|
insilmaril@0
|
622 |
{
|
insilmaril@53
|
623 |
QString text = NoteObj (e->text()).getNoteASCII();
|
insilmaril@53
|
624 |
QString fn,s;
|
insilmaril@53
|
625 |
if (!filenameHint.isEmpty())
|
insilmaril@53
|
626 |
{
|
insilmaril@53
|
627 |
if (!filenameHint.contains (".txt"))
|
insilmaril@53
|
628 |
s=filenameHint+".txt";
|
insilmaril@53
|
629 |
else
|
insilmaril@53
|
630 |
s=filenameHint;
|
insilmaril@53
|
631 |
} else
|
insilmaril@53
|
632 |
s=QString::null;
|
insilmaril@53
|
633 |
fn = QFileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") );
|
insilmaril@0
|
634 |
int ret=-1;
|
insilmaril@0
|
635 |
|
insilmaril@0
|
636 |
if ( !fn.isEmpty() )
|
insilmaril@0
|
637 |
{
|
insilmaril@0
|
638 |
QFile file (fn);
|
insilmaril@0
|
639 |
if (file.exists())
|
insilmaril@0
|
640 |
{
|
insilmaril@53
|
641 |
QMessageBox mb( vymName,
|
insilmaril@53
|
642 |
tr("The file %1\nexists already.\nDo you want to overwrite it?","dialog 'save note as'").arg(fn),
|
insilmaril@0
|
643 |
QMessageBox::Warning,
|
insilmaril@0
|
644 |
QMessageBox::Yes | QMessageBox::Default,
|
insilmaril@0
|
645 |
QMessageBox::Cancel | QMessageBox::Escape,
|
insilmaril@53
|
646 |
Qt::NoButton );
|
insilmaril@0
|
647 |
mb.setButtonText( QMessageBox::Yes, tr("Overwrite") );
|
insilmaril@0
|
648 |
mb.setButtonText( QMessageBox::No, tr("Cancel"));
|
insilmaril@0
|
649 |
ret=mb.exec();
|
insilmaril@0
|
650 |
}
|
insilmaril@0
|
651 |
if (ret==QMessageBox::Cancel)
|
insilmaril@0
|
652 |
return;
|
insilmaril@0
|
653 |
|
insilmaril@0
|
654 |
// save
|
insilmaril@53
|
655 |
if ( !file.open( QIODevice::WriteOnly ) )
|
insilmaril@0
|
656 |
statusBar()->message( QString("Could not write to %1").arg(filename),
|
insilmaril@0
|
657 |
statusbarTime );
|
insilmaril@0
|
658 |
else
|
insilmaril@0
|
659 |
{
|
insilmaril@0
|
660 |
QTextStream t( &file );
|
insilmaril@0
|
661 |
t << text;
|
insilmaril@0
|
662 |
file.close();
|
insilmaril@0
|
663 |
|
insilmaril@0
|
664 |
statusBar()->message( QString( "Note exported as %1" ).arg( fn ), statusbarTime );
|
insilmaril@0
|
665 |
}
|
insilmaril@0
|
666 |
}
|
insilmaril@0
|
667 |
}
|
insilmaril@0
|
668 |
|
insilmaril@0
|
669 |
|
insilmaril@0
|
670 |
void TextEditor::textPrint()
|
insilmaril@0
|
671 |
{
|
insilmaril@0
|
672 |
|
insilmaril@53
|
673 |
QTextDocument *document = e->document();
|
insilmaril@53
|
674 |
QPrinter printer;
|
insilmaril@53
|
675 |
|
insilmaril@53
|
676 |
QPrintDialog *dialog = new QPrintDialog(&printer, this);
|
insilmaril@53
|
677 |
dialog->setWindowTitle(tr("Print Note"));
|
insilmaril@53
|
678 |
if (dialog->exec() != QDialog::Accepted)
|
insilmaril@53
|
679 |
return;
|
insilmaril@53
|
680 |
|
insilmaril@53
|
681 |
document->print(&printer);
|
insilmaril@0
|
682 |
}
|
insilmaril@0
|
683 |
|
insilmaril@0
|
684 |
void TextEditor::textEditUndo()
|
insilmaril@0
|
685 |
{
|
insilmaril@0
|
686 |
}
|
insilmaril@0
|
687 |
|
insilmaril@0
|
688 |
void TextEditor::toggleFonthint()
|
insilmaril@0
|
689 |
{
|
insilmaril@0
|
690 |
setUpdatesEnabled (false);
|
insilmaril@53
|
691 |
e->selectAll ();
|
insilmaril@0
|
692 |
if (!actionFormatUseFixedFont->isOn() )
|
insilmaril@0
|
693 |
e->setCurrentFont (varFont);
|
insilmaril@0
|
694 |
else
|
insilmaril@0
|
695 |
e->setCurrentFont (fixedFont);
|
insilmaril@53
|
696 |
e->selectAll ();
|
insilmaril@0
|
697 |
setUpdatesEnabled (true);
|
insilmaril@0
|
698 |
repaint();
|
insilmaril@0
|
699 |
}
|
insilmaril@0
|
700 |
|
insilmaril@0
|
701 |
void TextEditor::setFixedFont()
|
insilmaril@0
|
702 |
{
|
insilmaril@0
|
703 |
bool ok;
|
insilmaril@0
|
704 |
QFont font =QFontDialog::getFont(
|
insilmaril@0
|
705 |
&ok, fixedFont, this );
|
insilmaril@0
|
706 |
if ( ok )
|
insilmaril@0
|
707 |
// font is set to the font the user selected
|
insilmaril@0
|
708 |
fixedFont=font;
|
insilmaril@0
|
709 |
}
|
insilmaril@0
|
710 |
|
insilmaril@0
|
711 |
void TextEditor::setVarFont()
|
insilmaril@0
|
712 |
{
|
insilmaril@0
|
713 |
bool ok;
|
insilmaril@0
|
714 |
QFont font =QFontDialog::getFont(
|
insilmaril@0
|
715 |
&ok, varFont, this );
|
insilmaril@0
|
716 |
if ( ok )
|
insilmaril@0
|
717 |
// font is set to the font the user selected
|
insilmaril@0
|
718 |
varFont=font;
|
insilmaril@0
|
719 |
}
|
insilmaril@0
|
720 |
|
insilmaril@0
|
721 |
void TextEditor::textBold()
|
insilmaril@0
|
722 |
{
|
insilmaril@0
|
723 |
e->setBold( actionTextBold->isOn() );
|
insilmaril@0
|
724 |
}
|
insilmaril@0
|
725 |
|
insilmaril@0
|
726 |
void TextEditor::textUnderline()
|
insilmaril@0
|
727 |
{
|
insilmaril@0
|
728 |
e->setUnderline( actionTextUnderline->isOn() );
|
insilmaril@0
|
729 |
}
|
insilmaril@0
|
730 |
|
insilmaril@0
|
731 |
void TextEditor::textItalic()
|
insilmaril@0
|
732 |
{
|
insilmaril@0
|
733 |
e->setItalic( actionTextItalic->isOn() );
|
insilmaril@0
|
734 |
}
|
insilmaril@0
|
735 |
|
insilmaril@0
|
736 |
void TextEditor::textFamily( const QString &f )
|
insilmaril@0
|
737 |
{
|
insilmaril@0
|
738 |
e->setFamily( f );
|
insilmaril@0
|
739 |
}
|
insilmaril@0
|
740 |
|
insilmaril@0
|
741 |
void TextEditor::textSize( const QString &p )
|
insilmaril@0
|
742 |
{
|
insilmaril@0
|
743 |
e->setPointSize( p.toInt() );
|
insilmaril@0
|
744 |
}
|
insilmaril@0
|
745 |
|
insilmaril@0
|
746 |
|
insilmaril@0
|
747 |
void TextEditor::textColor()
|
insilmaril@0
|
748 |
{
|
insilmaril@0
|
749 |
QColor col = QColorDialog::getColor( e->color(), this );
|
insilmaril@53
|
750 |
if ( !col.isValid() ) return;
|
insilmaril@0
|
751 |
e->setColor( col );
|
insilmaril@0
|
752 |
QPixmap pix( 16, 16 );
|
insilmaril@53
|
753 |
pix.fill( Qt::black );
|
insilmaril@0
|
754 |
actionTextColor->setIconSet( pix );
|
insilmaril@0
|
755 |
}
|
insilmaril@0
|
756 |
|
insilmaril@0
|
757 |
void TextEditor::textAlign( QAction *a )
|
insilmaril@0
|
758 |
{
|
insilmaril@0
|
759 |
if ( a == actionAlignLeft )
|
insilmaril@53
|
760 |
e->setAlignment( Qt::AlignLeft );
|
insilmaril@0
|
761 |
else if ( a == actionAlignCenter )
|
insilmaril@53
|
762 |
e->setAlignment( Qt::AlignHCenter );
|
insilmaril@0
|
763 |
else if ( a == actionAlignRight )
|
insilmaril@53
|
764 |
e->setAlignment( Qt::AlignRight );
|
insilmaril@0
|
765 |
else if ( a == actionAlignJustify )
|
insilmaril@53
|
766 |
e->setAlignment( Qt::AlignJustify );
|
insilmaril@0
|
767 |
}
|
insilmaril@0
|
768 |
|
insilmaril@53
|
769 |
void TextEditor::textVAlign()
|
insilmaril@53
|
770 |
{
|
insilmaril@53
|
771 |
QTextCharFormat format;
|
insilmaril@53
|
772 |
|
insilmaril@53
|
773 |
if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
|
insilmaril@53
|
774 |
format.setVerticalAlignment(QTextCharFormat::AlignSuperScript);
|
insilmaril@53
|
775 |
} else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
|
insilmaril@53
|
776 |
format.setVerticalAlignment(QTextCharFormat::AlignSubScript);
|
insilmaril@53
|
777 |
} else {
|
insilmaril@53
|
778 |
format.setVerticalAlignment(QTextCharFormat::AlignNormal);
|
insilmaril@53
|
779 |
}
|
insilmaril@53
|
780 |
e->mergeCurrentCharFormat(format);
|
insilmaril@53
|
781 |
}
|
insilmaril@53
|
782 |
|
insilmaril@53
|
783 |
|
insilmaril@0
|
784 |
void TextEditor::fontChanged( const QFont &f )
|
insilmaril@0
|
785 |
{
|
insilmaril@53
|
786 |
int i=comboFont->findText(f.family());
|
insilmaril@53
|
787 |
if (i>=0) comboFont->setCurrentIndex (i);
|
insilmaril@53
|
788 |
i=comboSize->findText(QString::number(f.pointSize()));
|
insilmaril@53
|
789 |
if (i>=0) comboSize->setCurrentIndex(i);
|
insilmaril@0
|
790 |
actionTextBold->setOn( f.bold() );
|
insilmaril@0
|
791 |
actionTextItalic->setOn( f.italic() );
|
insilmaril@0
|
792 |
actionTextUnderline->setOn( f.underline() );
|
insilmaril@0
|
793 |
}
|
insilmaril@0
|
794 |
|
insilmaril@0
|
795 |
void TextEditor::colorChanged( const QColor &c )
|
insilmaril@0
|
796 |
{
|
insilmaril@0
|
797 |
QPixmap pix( 16, 16 );
|
insilmaril@0
|
798 |
pix.fill( c );
|
insilmaril@0
|
799 |
actionTextColor->setIconSet( pix );
|
insilmaril@0
|
800 |
}
|
insilmaril@0
|
801 |
|
insilmaril@53
|
802 |
void TextEditor::formatChanged( const QTextCharFormat &f )
|
insilmaril@53
|
803 |
{
|
insilmaril@53
|
804 |
fontChanged(f.font());
|
insilmaril@53
|
805 |
colorChanged(f.foreground().color());
|
insilmaril@53
|
806 |
alignmentChanged(e->alignment());
|
insilmaril@53
|
807 |
verticalAlignmentChanged (f.verticalAlignment());
|
insilmaril@53
|
808 |
}
|
insilmaril@53
|
809 |
|
insilmaril@0
|
810 |
void TextEditor::alignmentChanged( int a )
|
insilmaril@0
|
811 |
{
|
insilmaril@53
|
812 |
if ( ( a == Qt::AlignLeft ) || ( a & Qt::AlignLeft ))
|
insilmaril@53
|
813 |
actionAlignLeft->setOn( true );
|
insilmaril@53
|
814 |
else if ( ( a & Qt::AlignHCenter ) )
|
insilmaril@53
|
815 |
actionAlignCenter->setOn( true );
|
insilmaril@53
|
816 |
else if ( ( a & Qt::AlignRight ) )
|
insilmaril@53
|
817 |
actionAlignRight->setOn( true );
|
insilmaril@53
|
818 |
else if ( ( a & Qt::AlignJustify ) )
|
insilmaril@53
|
819 |
actionAlignJustify->setOn( true );
|
insilmaril@53
|
820 |
}
|
insilmaril@53
|
821 |
|
insilmaril@53
|
822 |
void TextEditor::verticalAlignmentChanged(QTextCharFormat::VerticalAlignment a)
|
insilmaril@53
|
823 |
{
|
insilmaril@53
|
824 |
actionAlignSubScript->setOn (false);
|
insilmaril@53
|
825 |
actionAlignSuperScript->setOn (false);
|
insilmaril@53
|
826 |
switch (a)
|
insilmaril@53
|
827 |
{
|
insilmaril@53
|
828 |
case QTextCharFormat::AlignSuperScript:
|
insilmaril@53
|
829 |
actionAlignSuperScript->setOn (true);
|
insilmaril@53
|
830 |
break;
|
insilmaril@53
|
831 |
case QTextCharFormat::AlignSubScript:
|
insilmaril@53
|
832 |
actionAlignSubScript->setOn (true);
|
insilmaril@53
|
833 |
break;
|
insilmaril@53
|
834 |
default: ;
|
insilmaril@53
|
835 |
}
|
insilmaril@0
|
836 |
}
|
insilmaril@0
|
837 |
|
insilmaril@0
|
838 |
|
insilmaril@0
|
839 |
|
insilmaril@0
|
840 |
void TextEditor::enableActions()
|
insilmaril@0
|
841 |
{
|
insilmaril@0
|
842 |
actionFileLoad->setEnabled(true);
|
insilmaril@0
|
843 |
actionFileSave->setEnabled(true);
|
insilmaril@0
|
844 |
actionFileSaveAs->setEnabled(true);
|
insilmaril@0
|
845 |
actionFilePrint->setEnabled(true);
|
insilmaril@0
|
846 |
actionEditUndo->setEnabled(true);
|
insilmaril@0
|
847 |
actionEditRedo->setEnabled(true);
|
insilmaril@0
|
848 |
actionEditCopy->setEnabled(true);
|
insilmaril@0
|
849 |
actionEditCut->setEnabled(true);
|
insilmaril@0
|
850 |
actionEditPaste->setEnabled(true);
|
insilmaril@0
|
851 |
actionEditDeleteAll->setEnabled(true);
|
insilmaril@0
|
852 |
actionFormatUseFixedFont->setEnabled(true);
|
insilmaril@0
|
853 |
}
|
insilmaril@0
|
854 |
|
insilmaril@0
|
855 |
void TextEditor::disableActions()
|
insilmaril@0
|
856 |
{
|
insilmaril@0
|
857 |
actionFileLoad->setEnabled(false);
|
insilmaril@0
|
858 |
actionFileSave->setEnabled(false);
|
insilmaril@0
|
859 |
actionFileSaveAs->setEnabled(false);
|
insilmaril@0
|
860 |
actionFilePrint->setEnabled(false);
|
insilmaril@0
|
861 |
actionEditUndo->setEnabled(false);
|
insilmaril@0
|
862 |
actionEditRedo->setEnabled(false);
|
insilmaril@0
|
863 |
actionEditCopy->setEnabled(false);
|
insilmaril@0
|
864 |
actionEditCut->setEnabled(false);
|
insilmaril@0
|
865 |
actionEditPaste->setEnabled(false);
|
insilmaril@0
|
866 |
actionEditDeleteAll->setEnabled(false);
|
insilmaril@0
|
867 |
actionFormatUseFixedFont->setEnabled(false);
|
insilmaril@0
|
868 |
}
|
insilmaril@0
|
869 |
|
insilmaril@53
|
870 |
void TextEditor::setState (EditorState s)
|
insilmaril@53
|
871 |
{
|
insilmaril@53
|
872 |
|
insilmaril@53
|
873 |
QPalette p=palette();
|
insilmaril@53
|
874 |
QColor c;
|
insilmaril@53
|
875 |
switch (s)
|
insilmaril@53
|
876 |
{
|
insilmaril@53
|
877 |
case emptyEditor: c=QColor (150,150,150); break;
|
insilmaril@53
|
878 |
case filledEditor: c=QColor (255,255,255); break;
|
insilmaril@53
|
879 |
case inactiveEditor: c=QColor (0,0,0);
|
insilmaril@53
|
880 |
}
|
insilmaril@53
|
881 |
p.setColor(QPalette::Active, static_cast<QPalette::ColorRole>(9), c);
|
insilmaril@53
|
882 |
p.setColor(QPalette::Inactive, static_cast<QPalette::ColorRole>(9), c);
|
insilmaril@53
|
883 |
e->setPalette(p);
|
insilmaril@53
|
884 |
}
|
insilmaril@0
|
885 |
|
insilmaril@53
|
886 |
|