1 /***************************************************************************
2 * 2007-2021 by Peter Semiletov *
3 * peter.semiletov@gmail.com *
4
5 started at 08 November 2007
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 ***************************************************************************/
22
23
24
25 #include <math.h>
26 #include <algorithm>
27 #include <iostream>
28 #include <stdlib.h>
29
30 #if QT_VERSION >= 0x050000
31 #include <QRegularExpression>
32 #else
33 #include <QRegExp>
34 #endif
35
36 #if QT_VERSION < 0x050500
37 #include <QRegExp>
38 #endif
39
40 #include <QElapsedTimer>
41 #include <QDockWidget>
42 #include <QFileSystemModel>
43 #include <QMimeData>
44 #include <QStyleFactory>
45 #include <QLabel>
46 #include <QPushButton>
47 #include <QToolButton>
48 #include <QToolBar>
49 #include <QClipboard>
50 #include <QFileDialog>
51 #include <QMenuBar>
52 #include <QGroupBox>
53 #include <QImageWriter>
54 #include <QColorDialog>
55 #include <QTextCodec>
56 #include <QMimeData>
57 #include <QScrollArea>
58 #include <QXmlStreamReader>
59 #include <QDebug>
60 #include <QPainter>
61 #include <QInputDialog>
62 #include <QSettings>
63 #include <QLibraryInfo>
64 #include <QFontDialog>
65 #include <QUrl>
66
67 #ifdef PRINTER_ENABLE
68 #include <QPrinter>
69 #include <QPrintDialog>
70 #include <QAbstractPrintDialog>
71 #endif
72
73 #include "tea.h"
74 #include "utils.h"
75 #include "gui_utils.h"
76 #include "libretta_calc.h"
77 #include "textproc.h"
78 #include "logmemo.h"
79 #include "tzipper.h"
80 #include "wavinfo.h"
81 #include "exif_reader.h"
82
83 #include "spellchecker.h"
84
85
86 //′
87 const int UQS = 8242;
88 //″
89 const int UQD = 8243;
90 //°
91 const int UQDG = 176;
92
93
94
95 bool MyProxyStyle::b_altmenu = false;
96 int MyProxyStyle::cursor_blink_time = 1;
97
98 extern QSettings *settings;
99 extern QMenu *menu_current_files;
100 extern QHash <QString, QString> global_palette;
101 extern bool b_recent_off;
102 extern bool b_destroying_all;
103 extern int recent_list_max_items;
104 extern bool boring;
105
106
107 CTEA *main_window;
108 CDox *documents;
109 //QVariantMap hs_path;
110
111 QString current_version_number;
112 std::vector <CTextListWnd*> text_window_list;
113 QHash <QString, QHash<QString, QString> > hash_markup;
114
115 enum {
116 FM_ENTRY_MODE_NONE = 0,
117 FM_ENTRY_MODE_OPEN,
118 FM_ENTRY_MODE_SAVE
119 };
120
121
122 /*
123 ===========================
124 CDarkerWindow
125 ===========================
126 */
127
128
closeEvent(QCloseEvent * event)129 void CDarkerWindow::closeEvent (QCloseEvent *event)
130 {
131 event->accept();
132 }
133
134
CDarkerWindow()135 CDarkerWindow::CDarkerWindow()
136 {
137 setAttribute (Qt::WA_DeleteOnClose);
138 setWindowFlags (Qt::Tool);
139 setWindowTitle (tr ("Darker palette"));
140
141 slider = new QSlider (Qt::Horizontal);
142 slider->setMinimum (0);
143 slider->setMaximum (200);
144
145 QVBoxLayout *v_box = new QVBoxLayout;
146 setLayout (v_box);
147 v_box->addWidget (slider);
148
149 slider->setValue (settings->value ("darker_val", "100").toInt() - 100);
150
151 connect (slider, SIGNAL(valueChanged(int)), this, SLOT(slot_valueChanged(int)));
152 }
153
154
slot_valueChanged(int value)155 void CDarkerWindow::slot_valueChanged (int value)
156 {
157 settings->setValue ("darker_val", value + 100);
158
159 documents->apply_settings();
160 main_window->update_stylesheet (main_window->fname_stylesheet);
161 }
162
163
164 /*
165 ===========================
166 CTextListWnd
167 ===========================
168 */
169
170
closeEvent(QCloseEvent * event)171 void CTextListWnd::closeEvent (QCloseEvent *event)
172 {
173 event->accept();
174 }
175
176
~CTextListWnd()177 CTextListWnd::~CTextListWnd()
178 {
179 vector<CTextListWnd*>::iterator it = std::find (text_window_list.begin(), text_window_list.end(), this);
180 text_window_list.erase (it);
181 }
182
183
CTextListWnd(const QString & title,const QString & label_text)184 CTextListWnd::CTextListWnd (const QString &title, const QString &label_text)
185 {
186 setAttribute (Qt::WA_DeleteOnClose);
187 QVBoxLayout *lt = new QVBoxLayout;
188
189 QLabel *l = new QLabel (label_text);
190 list = new QListWidget (this);
191
192 lt->addWidget (l);
193 lt->addWidget (list);
194
195 setLayout (lt);
196 setWindowTitle (title);
197
198 text_window_list.push_back (this);
199 }
200
201
202 /*
203 ===========================
204 About window
205 ===========================
206 */
207
208
closeEvent(QCloseEvent * event)209 void CAboutWindow::closeEvent (QCloseEvent *event)
210 {
211 event->accept();
212 }
213
214
update_image()215 void CAboutWindow::update_image()
216 {
217 QImage img (400, 100, QImage::Format_ARGB32);
218 QPainter painter (&img);
219
220 QFont f;
221 f.setPixelSize (25);
222
223 painter.setPen (Qt::gray);
224 painter.setFont (f);
225
226 for (int y = 1; y < 100; y += 25)
227 for (int x = 1; x < 400; x += 25)
228 {
229 QColor color;
230
231 int i = rand() % 5;
232
233 switch (i)
234 {
235 case 0: color = 0xfff3f9ff;
236 break;
237
238 case 1: color = 0xffbfffb0;
239 break;
240
241 case 2: color = 0xffa5a5a6;
242 break;
243
244 case 3: color = 0xffebffe9;
245 break;
246
247 case 4: color = 0xffbbf6ff;
248 break;
249 }
250
251 painter.fillRect (x, y, 25, 25, QBrush (color));
252
253 if (i == 0)
254 painter.drawText (x, y + 25, "0");
255
256 if (i == 1)
257 painter.drawText (x, y + 25, "1");
258 }
259
260 QString txt = "TEA";
261
262 QFont f2 ("Monospace");
263 f2.setPixelSize (75);
264 painter.setFont (f2);
265
266 painter.setPen (Qt::black);
267 painter.drawText (4, 80, txt);
268
269 painter.setPen (Qt::red);
270 painter.drawText (2, 76, txt);
271
272 logo->setPixmap (QPixmap::fromImage (img));
273 }
274
275
CAboutWindow()276 CAboutWindow::CAboutWindow()
277 {
278 setAttribute (Qt::WA_DeleteOnClose);
279
280 QStringList sl_t = qstring_load (":/AUTHORS").split ("##");
281
282 logo = new QLabel;
283 update_image();
284
285 QTimer *timer = new QTimer(this);
286 connect(timer, SIGNAL(timeout()), this, SLOT(update_image()));
287 timer->start (1000);
288
289 QTabWidget *tw = new QTabWidget (this);
290
291 QPlainTextEdit *page_code = new QPlainTextEdit();
292 QPlainTextEdit *page_thanks = new QPlainTextEdit();
293 QPlainTextEdit *page_translators = new QPlainTextEdit();
294 // QPlainTextEdit *page_maintainers = new QPlainTextEdit();
295
296 if (sl_t.size() == 3)
297 {
298 page_code->setPlainText (sl_t[0].trimmed());
299 page_thanks->setPlainText (sl_t[2].trimmed());
300 page_translators->setPlainText (sl_t[1].trimmed());
301 //page_maintainers->setPlainText (sl_t[2].trimmed());
302 }
303
304 tw->addTab (page_code, tr ("Code"));
305 tw->addTab (page_thanks, tr ("Acknowledgements"));
306 tw->addTab (page_translators, tr ("Translations"));
307 //tw->addTab (page_maintainers, tr ("Packages"));
308
309 QVBoxLayout *layout = new QVBoxLayout();
310
311 layout->addWidget(logo);
312 layout->addWidget(tw);
313
314 setLayout (layout);
315 setWindowTitle (tr ("About"));
316 }
317
318
319 /*
320 ===========================
321 Local utility functions
322 ===========================
323 */
324
325
326 //for the further compatibility
int_to_tabpos(int i)327 QTabWidget::TabPosition int_to_tabpos (int i)
328 {
329 QTabWidget::TabPosition p = QTabWidget::North;
330
331 switch (i)
332 {
333 case 0:
334 p = QTabWidget::North;
335 break;
336 case 1:
337 p = QTabWidget::South;
338 break;
339 case 2:
340 p = QTabWidget::West;
341 break;
342 case 3:
343 p = QTabWidget::East;
344 break;
345 }
346
347 return p;
348 }
349
350
toggle_fname_header_source(const QString & fileName)351 QString toggle_fname_header_source (const QString &fileName)
352 {
353 QFileInfo f (fileName);
354
355 QString ext = f.suffix();
356
357 if (ext == "c" || ext == "cpp" || ext == "cxx" || ext == "cc" || ext == "c++" ||
358 ext == "m" || ext == "mm")
359 {
360 if (file_exists (f.absolutePath() + "/" + f.baseName () + ".h"))
361 return f.absolutePath() + "/" + f.baseName () + ".h";
362 else
363 if (file_exists (f.absolutePath() + "/" + f.baseName () + ".hxx"))
364 return f.absolutePath() + "/" + f.baseName () + ".hxx";
365 else
366 if (file_exists (f.absolutePath() + "/" + f.baseName () + ".h++"))
367 return f.absolutePath() + "/" + f.baseName () + ".h++";
368 else
369 if (file_exists (f.absolutePath() + "/" + f.baseName () + ".hh"))
370 return f.absolutePath() + "/" + f.baseName () + ".hh";
371 else
372 if (file_exists (f.absolutePath() + "/" + f.baseName () + ".hpp"))
373 return f.absolutePath() + "/" + f.baseName () + ".hpp";
374 }
375 else
376 if (ext == "h" || ext == "h++" || ext == "hxx" || ext == "hh" || ext == "hpp")
377 {
378 if (file_exists (f.absolutePath() + "/" + f.baseName () + ".c"))
379 return f.absolutePath() + "/" + f.baseName () + ".c";
380 else
381 if (file_exists (f.absolutePath() + "/" + f.baseName () + ".cpp"))
382 return f.absolutePath() + "/" + f.baseName () + ".cpp";
383 else
384 if (file_exists (f.absolutePath() + "/" + f.baseName () + ".cxx"))
385 return f.absolutePath() + "/" + f.baseName () + ".cxx";
386 else
387 if (file_exists (f.absolutePath() + "/" + f.baseName () + ".c++"))
388 return f.absolutePath() + "/" + f.baseName () + ".c++";
389 else
390 if (file_exists (f.absolutePath() + "/" + f.baseName () + ".cc"))
391 return f.absolutePath() + "/" + f.baseName () + ".cc";
392 else
393 if (file_exists (f.absolutePath() + "/" + f.baseName () + ".m"))
394 return f.absolutePath() + "/" + f.baseName () + ".m";
395 else
396 if (file_exists (f.absolutePath() + "/" + f.baseName () + ".mm"))
397 return f.absolutePath() + "/" + f.baseName () + ".mm";
398 }
399
400 return fileName;
401 }
402
403
closeEvent(QCloseEvent * event)404 void CTEA::closeEvent (QCloseEvent *event)
405 {
406 if (main_tab_widget->currentIndex() == idx_tab_tune)
407 leaving_options();
408
409 qstring_save (dir_config + "/last_used_charsets", sl_last_used_charsets.join ("\n").trimmed());
410
411 if (settings->value("session_restore", false).toBool())
412 {
413 QString fname_session = dir_sessions + "/def-session-777";
414 documents->save_to_session (fname_session);
415 }
416
417 if (settings->value("save_buffers", true).toBool())
418 documents->save_buffers (fname_saved_buffers);
419
420
421 write_search_options();
422 write_settings();
423
424 qstring_save (fname_fif, sl_fif_history.join ("\n"));
425
426 hash_save_keyval (fname_autosaving_files, documents->autosave_files);
427
428
429 delete documents;
430 delete img_viewer;
431
432 #if defined (HUNSPELL_ENABLE) || defined (ASPELL_ENABLE)
433 delete spellchecker;
434 #endif
435
436 delete shortcuts;
437
438 if (text_window_list.size() > 0)
439 for (vector <size_t>::size_type i = 0; i < text_window_list.size(); i++)
440 text_window_list[i]->close();
441
442 event->accept();
443 deleteLater();
444 }
445
446
dragEnterEvent(QDragEnterEvent * event)447 void CTEA::dragEnterEvent (QDragEnterEvent *event)
448 {
449 if (event->mimeData()->hasFormat ("text/uri-list"))
450 event->acceptProposedAction();
451 }
452
453
dropEvent(QDropEvent * event)454 void CTEA::dropEvent (QDropEvent *event)
455 {
456 if (! event->mimeData()->hasUrls())
457 return;
458
459 QString fName;
460 QFileInfo info;
461
462 QList<QUrl> l = event->mimeData()->urls();
463
464 for (QList <QUrl>::iterator u = l.begin(); u != l.end(); ++u)
465 {
466 fName = u->toLocalFile();
467
468 info.setFile (fName);
469 if (info.isFile())
470 documents->open_file (fName, cb_fman_codecs->currentText());
471 }
472
473 event->accept();
474 }
475
476
477 /*
478 ===========================
479 Main window slots
480 ===========================
481 */
482
pageChanged(int index)483 void CTEA::pageChanged (int index)
484 {
485 if (b_destroying_all || index == -1)
486 return;
487
488 CDocument *d = documents->items[index];
489 if (! d)
490 return;
491
492 d->update_title (settings->value ("full_path_at_window_title", 1).toBool());
493 d->update_status();
494
495 if (file_exists (d->file_name))
496 documents->dir_last = get_file_path (d->file_name);
497
498 documents->update_project (d->file_name);
499
500 update_labels_menu();
501 }
502
503
logmemo_double_click(const QString & txt)504 void CTEA::logmemo_double_click (const QString &txt)
505 {
506 if (documents->hash_project.isEmpty() || documents->fname_current_project.isEmpty())
507 return;
508
509 QStringList parsed = txt.split (":");
510 if (parsed.size() == 0)
511 return;
512
513 QString source_fname;
514 QString source_line;
515 QString source_col;
516
517 source_fname = parsed[0];
518
519 if (parsed.size() > 1)
520 source_line = parsed[1];
521
522 if (parsed.size() > 2)
523 source_col = parsed[2];
524
525 if (source_fname.startsWith(".."))
526 source_fname.remove (0, 2);
527
528 QFileInfo dir_source (documents->fname_current_project);
529 QString source_dir = dir_source.absolutePath();
530
531 source_fname = source_dir + "/" + source_fname;
532
533 log->no_jump = true;
534 CDocument *d = documents->open_file (source_fname, "UTF-8");
535 log->no_jump = false;
536
537 if (! d)
538 return;
539
540 QTextCursor cur = d->textCursor();
541 if (cur.isNull())
542 return;
543
544 cur.movePosition (QTextCursor::Start);
545 cur.movePosition (QTextCursor::Down, QTextCursor::MoveAnchor, source_line.toInt() - 1);
546 cur.movePosition (QTextCursor::Right, QTextCursor::MoveAnchor, source_col.toInt() - 1);
547 cur.select (QTextCursor::WordUnderCursor);
548 d->setTextCursor (cur);
549 d->setFocus();
550 }
551
552
receiveMessage(const QString & msg)553 void CTEA::receiveMessage (const QString &msg)
554 {
555 if (! msg.isEmpty())
556 documents->open_file (msg, "UTF-8");
557 }
558
559
receiveMessageShared(const QStringList & msg)560 void CTEA::receiveMessageShared (const QStringList &msg)
561 {
562 for (int i = 0; i < msg.size(); i++)
563 {
564 QFileInfo f (msg.at(i));
565
566 if (! f.isAbsolute())
567 {
568 QString fullname (QDir::currentPath());
569 fullname.append ("/").append (msg.at(i));
570 documents->open_file (fullname, charset);
571 }
572 else
573 documents->open_file (msg.at(i), charset);
574 }
575
576 show();
577 activateWindow();
578 raise();
579 }
580
581
tb_stop_clicked()582 void CTEA::tb_stop_clicked()
583 {
584 boring = true;
585 }
586
587
read_settings()588 void CTEA::read_settings()
589 {
590 MyProxyStyle::cursor_blink_time = settings->value ("cursor_blink_time", 0).toInt();
591 qApp->setCursorFlashTime (MyProxyStyle::cursor_blink_time);
592 MyProxyStyle::b_altmenu = settings->value ("b_altmenu", "0").toBool();
593
594 recent_list_max_items = settings->value ("recent_list.max_items", 21).toInt();
595
596 main_tab_widget->setTabPosition (int_to_tabpos (settings->value ("ui_tabs_align", "0").toInt()));
597 tab_editor->setTabPosition (int_to_tabpos (settings->value ("docs_tabs_align", "0").toInt()));
598
599 markup_mode = settings->value ("markup_mode", "HTML").toString();
600 charset = settings->value ("charset", "UTF-8").toString();
601 fname_def_palette = settings->value ("fname_def_palette", ":/palettes/TEA").toString();
602
603 QPoint pos = settings->value ("pos", QPoint (1, 200)).toPoint();
604 QSize size = settings->value ("size", QSize (800, 512)).toSize();
605
606 if (mainSplitter)
607 mainSplitter->restoreState (settings->value ("splitterSizes").toByteArray());
608
609 resize (size);
610 move (pos);
611 }
612
613
write_settings()614 void CTEA::write_settings()
615 {
616 if (mainSplitter)
617 settings->setValue ("splitterSizes", mainSplitter->saveState());
618
619 settings->setValue ("pos", pos());
620 settings->setValue ("size", size());
621 settings->setValue ("charset", charset);
622 settings->setValue ("spl_fman", spl_fman->saveState());
623 settings->setValue ("dir_last", documents->dir_last);
624 settings->setValue ("fname_def_palette", fname_def_palette);
625 settings->setValue ("markup_mode", markup_mode);
626 settings->setValue ("VER_NUMBER", QString (current_version_number));
627 settings->setValue ("state", saveState());
628 settings->setValue ("word_wrap", cb_wordwrap->isChecked());
629 settings->setValue ("show_linenums", cb_show_linenums->isChecked());
630 settings->setValue ("fif_at_toolbar", cb_fif_at_toolbar->isChecked());
631 settings->setValue ("save_buffers", cb_save_buffers->isChecked());
632
633 delete settings;
634 }
635
636
read_search_options()637 void CTEA::read_search_options()
638 {
639 menu_find_whole_words->setChecked (settings->value ("find_whole_words", "0").toBool());
640 menu_find_case->setChecked (settings->value ("find_case", "0").toBool());
641 menu_find_regexp->setChecked (settings->value ("find_regexp", "0").toBool());
642 menu_find_fuzzy->setChecked (settings->value ("find_fuzzy", "0").toBool());
643 menu_find_from_cursor->setChecked (settings->value ("find_from_cursor", "1").toBool());
644 }
645
646
write_search_options()647 void CTEA::write_search_options()
648 {
649 settings->setValue ("find_whole_words", menu_find_whole_words->isChecked());
650 settings->setValue ("find_case", menu_find_case->isChecked());
651 settings->setValue ("find_regexp", menu_find_regexp->isChecked());
652 settings->setValue ("find_fuzzy", menu_find_fuzzy->isChecked());
653 settings->setValue ("find_from_cursor", menu_find_from_cursor->isChecked());
654 }
655
656
657 /*
658 ===================
659 File manager slots
660 ===================
661 */
662
663
fman_drives_changed(const QString & path)664 void CTEA::fman_drives_changed (const QString & path)
665 {
666 if (! ui_update)
667 fman->nav (path);
668 }
669
670
fman_current_file_changed(const QString & full_path,const QString & just_name)671 void CTEA::fman_current_file_changed (const QString &full_path, const QString &just_name)
672 {
673 if (! is_dir (full_path))
674 ed_fman_fname->setText (just_name);
675 else
676 ed_fman_fname->setText ("");
677
678 if (b_preview && is_image (full_path))
679 {
680 if (! img_viewer->window_mini.isVisible())
681 {
682 img_viewer->window_mini.show();
683 activateWindow();
684 fman->setFocus();
685 }
686
687 img_viewer->set_image_mini (full_path);
688 }
689 }
690
691
fman_file_activated(const QString & full_path)692 void CTEA::fman_file_activated (const QString &full_path)
693 {
694 if (file_get_ext (full_path) == ("zip"))
695 {
696 CZipper z;
697 QStringList sl = z.unzip_list (full_path);
698
699 for (int i = 0; i < sl.size(); i++)
700 sl[i] = sl[i] + "<br>";
701
702 log->log (sl.join("\n"));
703 return;
704 }
705
706
707 if (is_image (full_path))
708 {
709 CDocument *d = documents->get_current();
710 if (! d)
711 return;
712
713 d->insert_image (full_path);
714 main_tab_widget->setCurrentIndex (idx_tab_edit);
715 return;
716 }
717
718 CDocument *d = documents->open_file (full_path, cb_fman_codecs->currentText());
719 if (d)
720 charset = d->charset;
721
722 add_to_last_used_charsets (cb_fman_codecs->currentText());
723 main_tab_widget->setCurrentIndex (idx_tab_edit);
724 }
725
726
fman_dir_changed(const QString & full_path)727 void CTEA::fman_dir_changed (const QString &full_path)
728 {
729 ui_update = true;
730 ed_fman_path->setText (full_path);
731
732 #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
733 cb_fman_drives->setCurrentIndex (cb_fman_drives->findText (full_path.left(3).toUpper()));
734 #endif
735
736 ui_update = false;
737 }
738
739
fman_fname_entry_confirm()740 void CTEA::fman_fname_entry_confirm()
741 {
742 if (fm_entry_mode == FM_ENTRY_MODE_OPEN)
743 fman_open();
744
745 if (fm_entry_mode == FM_ENTRY_MODE_SAVE)
746 cb_button_saves_as();
747 }
748
749
fman_naventry_confirm()750 void CTEA::fman_naventry_confirm()
751 {
752 fman->nav (ed_fman_path->text());
753 }
754
755
fman_add_bmk()756 void CTEA::fman_add_bmk()
757 {
758 sl_places_bmx.prepend (ed_fman_path->text());
759 qstring_save (fname_places_bookmarks, sl_places_bmx.join ("\n"));
760 update_places_bookmarks();
761 }
762
763
fman_del_bmk()764 void CTEA::fman_del_bmk()
765 {
766 int i = lv_places->currentRow();
767 if (i < 5) //TEA built-in bookmark, don't remove
768 return;
769
770 if (i > sl_places_bmx.size() + 4) // -- GTK places
771 {
772 qDebug() << "GTK bookmarks, i: " << i;
773 return;
774 }
775
776 //else TEA places
777
778 qDebug() << "TEA places, i: " << i;
779
780 QString s = lv_places->item(i)->text();
781 if (s.isEmpty())
782 return;
783
784 sl_places_bmx.removeAt (sl_places_bmx.indexOf (s)); // поменять на индекс i + 5
785 //sl_places_bmx.removeAt (i);
786
787 qstring_save (fname_places_bookmarks, sl_places_bmx.join ("\n"));
788 update_places_bookmarks();
789 }
790
791
fman_open()792 void CTEA::fman_open()
793 {
794 QString f = ed_fman_fname->text().trimmed();
795 QStringList li = fman->get_sel_fnames();
796
797 if (path_is_abs (f)) //if file name entry is the full path and not empty
798 {
799 CDocument *d = documents->open_file (f, cb_fman_codecs->currentText());
800 if (d)
801 {
802 charset = d->charset;
803 add_to_last_used_charsets (cb_fman_codecs->currentText());
804 main_tab_widget->setCurrentIndex (idx_tab_edit);
805 }
806
807 return;
808 }
809
810 //if file name entry == just filename
811 if (li.size() == 0 && ! f.isEmpty())
812 {
813 QString fname (fman->dir.path());
814 fname.append ("/").append (f);
815 CDocument *d = documents->open_file (fname, cb_fman_codecs->currentText());
816 if (d)
817 {
818 charset = d->charset;
819 add_to_last_used_charsets (cb_fman_codecs->currentText());
820 main_tab_widget->setCurrentIndex (idx_tab_edit);
821 }
822
823 return;
824 }
825
826 //if file[s] selected at files list
827
828 bool opened = false;
829
830 for (int i = 0; i < li.size(); i++)
831 {
832 CDocument *d = 0;
833 d = documents->open_file (li.at(i), cb_fman_codecs->currentText());
834 if (d)
835 {
836 charset = d->charset;
837 opened = true;
838 }
839 }
840
841 add_to_last_used_charsets (cb_fman_codecs->currentText());
842
843 if (opened)
844 main_tab_widget->setCurrentIndex (idx_tab_edit);
845 }
846
847
fman_places_itemActivated(QListWidgetItem * item)848 void CTEA::fman_places_itemActivated (QListWidgetItem *item)
849 {
850 int i = lv_places->currentRow();
851 QString s = item->text();
852
853 vector <QString> v;
854
855 v.push_back (dir_templates);
856 v.push_back (dir_snippets);
857 v.push_back (dir_scripts);
858 v.push_back (dir_tables);
859 v.push_back (dir_config);
860
861 if (i < 5)
862 s = v[i];
863
864 //if (i > sl_places_bmx.size() + 4)
865 // s = sl_gtk_bookmarks[i - (sl_places_bmx.size() + 6)];
866
867 fman->nav (s);
868 }
869
870
cb_button_saves_as()871 void CTEA::cb_button_saves_as()
872 {
873 CDocument *d = documents->get_current();
874
875 if (! d || ed_fman_fname->text().isEmpty())
876 return;
877
878 QString fn = ed_fman_fname->text();
879 QString filename;
880
881 if (path_is_abs (fn)) //if file name entry is the full path and not empty
882 filename = fn;
883 else
884 {
885 filename = fman->dir.path();
886 filename.append ("/").append (ed_fman_fname->text());
887 }
888
889 if (path_is_dir (filename))
890 return;
891
892 if (file_exists (filename))
893 if (QMessageBox::warning (this, "TEA",
894 tr ("%1 already exists\n"
895 "Do you want to overwrite?")
896 .arg (filename),
897 QMessageBox::Yes | QMessageBox::Default,
898 QMessageBox::Cancel | QMessageBox::Escape) == QMessageBox::Cancel)
899 return;
900
901
902 d->file_save_with_name (filename, cb_fman_codecs->currentText());
903 d->set_markup_mode();
904
905 add_to_last_used_charsets (cb_fman_codecs->currentText());
906
907 d->set_hl();
908
909 QFileInfo f (d->file_name);
910 documents->dir_last = f.path();
911 update_dyn_menus();
912
913 shortcuts->load_from_file (shortcuts->fname);
914
915 fman->refresh();
916 main_tab_widget->setCurrentIndex (idx_tab_edit);
917 }
918
919
920
921 /*
922 void CTEA::ide_ctags()
923 {
924 if (documents->hash_project.isEmpty())
925 return;
926
927 if (documents->fname_current_project.isEmpty())
928 return;
929
930 QFileInfo source_dir (documents->fname_current_project);
931
932 QString command_ctags = hash_get_val (documents->hash_project,
933 "command_ctags", "ctags -R");
934
935 QProcess *process = new QProcess (this);
936 process->setWorkingDirectory (source_dir.absolutePath());
937
938 connect (process, SIGNAL(readyReadStandardOutput()), this, SLOT(process_readyReadStandardOutput()));
939
940 process->setProcessChannelMode (QProcess::MergedChannels) ;
941 process->start (command_ctags, QIODevice::ReadWrite);
942
943 if (! process->waitForFinished())
944 return;
945
946 //else parse ctags file
947 }
948
949
950
951 void CTEA::ide_gtags()
952 {
953 if (documents->hash_project.isEmpty())
954 return;
955
956 if (documents->fname_current_project.isEmpty())
957 return;
958
959 QFileInfo source_dir (documents->fname_current_project);
960
961 QString command_gtags = hash_get_val (documents->hash_project,
962 "command_gtags", "gtags");
963
964 QProcess *process = new QProcess (this);
965 process->setWorkingDirectory (source_dir.absolutePath());
966
967 // connect (process, SIGNAL(readyReadStandardOutput()), this, SLOT(process_readyReadStandardOutput()));
968
969 if (file_exists (source_dir.absolutePath() + "/GTAGS"))
970 command_gtags = "global -u";
971
972
973 process->setProcessChannelMode (QProcess::MergedChannels) ;
974 process->start (command_gtags, QIODevice::ReadWrite);
975
976 if (! process->waitForStarted())
977 return;
978
979 if (! process->waitForFinished())
980 return;
981
982 }
983
984 void CTEA::ide_global_definition()
985 {
986 if (documents->hash_project.isEmpty())
987 return;
988
989 if (documents->fname_current_project.isEmpty())
990 return;
991
992 CDocument *d = documents->get_current();
993 if (! d)
994 return;
995
996 QString sel_text = d->get();
997
998 QFileInfo source_dir (documents->fname_current_project);
999
1000 QString command = hash_get_val (documents->hash_project,
1001 "command_global_definition", "global -a -x --result=grep");
1002
1003
1004 command = command + " " + sel_text;
1005
1006 QProcess *process = new QProcess (this);
1007 process->setWorkingDirectory (source_dir.absolutePath());
1008
1009 process->setProcessChannelMode (QProcess::MergedChannels) ;
1010 process->start (command, QIODevice::ReadWrite);
1011
1012 if (! process->waitForStarted())
1013 return;
1014
1015 if (! process->waitForFinished())
1016 return;
1017
1018 QByteArray a = process->readAll();
1019 if (a.isEmpty())
1020 return;
1021
1022 QString s(a);
1023 //value_t 28 lib/optional/libffi/ffi.cpp struct value_t {
1024
1025 //if (s.indexOf ('\t') != -1)
1026 // qDebug() << "TAB!";
1027
1028
1029
1030 //qDebug() << "4";
1031
1032 //parse output
1033
1034 QStringList sl_output = s.split ("\n");
1035 if (sl_output.size() == -1)
1036 return;
1037
1038 ///home/rox/devel/tea-qt/main.cpp:36:int main (int argc, char *argv[])
1039
1040
1041 foreach (QString str, sl_output)
1042 {
1043 if (! str.isEmpty())
1044 {
1045 int idx_path = str.indexOf (":");
1046 QString str_path = str.left (idx_path);
1047
1048 int idx_line = str.indexOf (":", idx_path + 1);
1049 QString str_line = str.mid (idx_path + 1, idx_line - idx_path);
1050
1051 // int idx_pattern = str.indexOf (":", idx_line + 1);
1052 QString str_pattern = str.right (str.size() - idx_line + 1);
1053
1054 qDebug() << "path: " << str_path;
1055 qDebug() << "line: " << str_line;
1056 qDebug() << "pattern: " << str_pattern;
1057
1058
1059 }
1060 }
1061
1062
1063 qDebug() << "3";
1064 }
1065
1066
1067 void CTEA::ide_global_references()
1068 {
1069
1070
1071 }
1072 */
1073
1074
1075 /*
1076 ===================
1077 File menu callbacks
1078 ===================
1079 */
1080
test()1081 void CTEA::test()
1082 {
1083 /* CIconvCharsetConverter c;
1084 QByteArray ba = file_load ("/home/rox/devel/test/1251.txt");
1085
1086 QString s = c.to_utf16 ("CP1251", ba.data(), ba.size());
1087 qDebug() << s;*/
1088
1089 // QIconvCodec c;
1090 }
1091
1092
file_new()1093 void CTEA::file_new()
1094 {
1095 last_action = sender();
1096 documents->create_new();
1097 main_tab_widget->setCurrentIndex (idx_tab_edit);
1098 }
1099
1100
file_open()1101 void CTEA::file_open()
1102 {
1103 last_action = sender();
1104
1105 if (! settings->value ("use_trad_dialogs", "0").toBool())
1106 {
1107 CDocument *d = documents->get_current();
1108
1109 if (d)
1110 {
1111 if (file_exists (d->file_name))
1112 fman->nav (get_file_path (d->file_name));
1113 }
1114 else
1115 fman->nav (documents->dir_last);
1116
1117 main_tab_widget->setCurrentIndex (idx_tab_fman);
1118 fm_entry_mode = FM_ENTRY_MODE_OPEN;
1119
1120 return;
1121 }
1122
1123 //ELSE use the traditional dialog
1124
1125 QFileDialog dialog (this);
1126 QSize size = settings->value ("dialog_size", QSize (width(), height())).toSize();
1127 dialog.resize (size);
1128
1129 dialog.setFilter (QDir::AllEntries | QDir::Hidden);
1130 dialog.setOption (QFileDialog::DontUseNativeDialog, true);
1131
1132 QList<QUrl> sidebarUrls = dialog.sidebarUrls();
1133 QList<QUrl> sidebarUrls_old = dialog.sidebarUrls();
1134
1135 sidebarUrls.append (QUrl::fromLocalFile (dir_templates));
1136 sidebarUrls.append (QUrl::fromLocalFile (dir_snippets));
1137 sidebarUrls.append (QUrl::fromLocalFile (dir_sessions));
1138 sidebarUrls.append (QUrl::fromLocalFile (dir_scripts));
1139 sidebarUrls.append (QUrl::fromLocalFile (dir_tables));
1140
1141 #ifdef Q_OS_UNIX
1142
1143 QDir volDir ("/mnt");
1144 QStringList volumes (volDir.entryList (volDir.filter() | QDir::NoDotAndDotDot));
1145
1146 QDir volDir2 ("/media");
1147 QStringList volumes2 (volDir2.entryList (volDir.filter() | QDir::NoDotAndDotDot));
1148
1149 for (int i = 0; i < volumes.size(); i++)
1150 sidebarUrls.append (QUrl::fromLocalFile ("/mnt/" + volumes.at(i)));
1151
1152 for (int i = 0; i < volumes2.size(); i++)
1153 sidebarUrls.append (QUrl::fromLocalFile ("/media/" + volumes2.at(i)));
1154
1155 #endif
1156
1157 dialog.setSidebarUrls (sidebarUrls);
1158
1159 dialog.setFileMode (QFileDialog::ExistingFiles);
1160 dialog.setAcceptMode (QFileDialog::AcceptOpen);
1161
1162 CDocument *d = documents->get_current();
1163 if (d)
1164 {
1165 if (file_exists (d->file_name))
1166 dialog.setDirectory (get_file_path (d->file_name));
1167 }
1168 else
1169 dialog.setDirectory (documents->dir_last);
1170
1171 dialog.setNameFilter (tr ("All (*);;Text files (*.txt);;Markup files (*.xml *.html *.htm *.);;C/C++ (*.c *.h *.cpp *.hh *.c++ *.h++ *.cxx)"));
1172
1173 QLabel *l = new QLabel (tr ("Charset"));
1174 QComboBox *cb_codecs = new QComboBox (&dialog);
1175 dialog.layout()->addWidget (l);
1176 dialog.layout()->addWidget (cb_codecs);
1177
1178 if (sl_last_used_charsets.size () > 0)
1179 cb_codecs->addItems (sl_last_used_charsets + sl_charsets);
1180 else
1181 {
1182 cb_codecs->addItems (sl_charsets);
1183 cb_codecs->setCurrentIndex (sl_charsets.indexOf ("UTF-8"));
1184 }
1185
1186 QStringList fileNames;
1187
1188 if (dialog.exec())
1189 {
1190 dialog.setSidebarUrls (sidebarUrls_old);
1191
1192 fileNames = dialog.selectedFiles();
1193
1194 for (int i = 0; i < fileNames.size(); i++)
1195 {
1196 CDocument *dc = documents->open_file (fileNames.at(i), cb_codecs->currentText());
1197 if (dc)
1198 charset = dc->charset;
1199
1200 add_to_last_used_charsets (cb_codecs->currentText());
1201 }
1202 }
1203 else
1204 dialog.setSidebarUrls (sidebarUrls_old);
1205
1206 settings->setValue ("dialog_size", dialog.size());
1207 update_dyn_menus();
1208 }
1209
1210
file_open_at_cursor()1211 void CTEA::file_open_at_cursor()
1212 {
1213 if (main_tab_widget->currentIndex() == idx_tab_fman)
1214 {
1215 fman_preview_image();
1216 return;
1217 }
1218
1219 CDocument *d = documents->get_current();
1220 if (! d)
1221 return;
1222
1223 QString fname = d->get_filename_at_cursor();
1224
1225 if (fname.isEmpty())
1226 return;
1227
1228 if (is_image (fname))
1229 {
1230 if (settings->value ("override_img_viewer", 0).toBool()) //external image viewer
1231 {
1232 QString command = settings->value ("img_viewer_override_command", "display %s").toString();
1233 command = command.replace ("%s", fname);
1234 QProcess::startDetached (command, QStringList());
1235 return;
1236 }
1237 else
1238 {
1239 if (file_get_ext (fname) == "gif")
1240 {
1241 CGIFWindow *w = new CGIFWindow;
1242 w->load_image (fname);
1243 return;
1244 }
1245 else //not GIF
1246 {
1247 if (! img_viewer->window_full.isVisible())
1248 {
1249 img_viewer->window_full.show();
1250 activateWindow();
1251 }
1252
1253 img_viewer->set_image_full (fname);
1254 return;
1255 }
1256 }
1257 }
1258
1259
1260 if (fname.startsWith ("#")) //HTML inner label
1261 {
1262 QString t = fname;
1263 t.remove (0, 1);
1264 t.prepend ("name=\"");
1265 if (d->find (t))
1266 return;
1267
1268 t = fname;
1269 t.remove (0, 1);
1270 t.prepend ("id=\"");
1271 d->find (t);
1272
1273 return;
1274 }
1275
1276 documents->open_file (fname, d->charset);
1277 }
1278
1279
file_last_opened()1280 void CTEA::file_last_opened()
1281 {
1282 last_action = sender();
1283
1284 if (documents->recent_files.size() > 0)
1285 {
1286 documents->open_file_triplex (documents->recent_files[0]);
1287 documents->recent_files.removeAt (0);
1288 documents->update_recent_menu();
1289 }
1290 }
1291
1292
file_crapbook()1293 void CTEA::file_crapbook()
1294 {
1295 last_action = sender();
1296
1297 if (! QFile::exists (fname_crapbook))
1298 qstring_save (fname_crapbook, tr ("you can put here notes, etc"));
1299
1300 documents->open_file (fname_crapbook, "UTF-8");
1301 }
1302
1303
file_notes()1304 void CTEA::file_notes()
1305 {
1306 last_action = sender();
1307
1308 CDocument *d = documents->get_current();
1309 if (! d)
1310 return;
1311
1312 if (! file_exists (d->file_name))
1313 return;
1314
1315 QString fname = d->file_name + ".notes";
1316
1317 if (! file_exists (fname))
1318 qstring_save (fname, tr ("put your notes (for this file) here and they will be saved automatically"));
1319
1320 documents->open_file (fname, "UTF-8");
1321 }
1322
1323
file_save()1324 bool CTEA::file_save()
1325 {
1326 last_action = sender();
1327
1328 CDocument *d = documents->get_current();
1329 if (! d)
1330 return false;
1331
1332 if (d->isReadOnly())
1333 {
1334 log->log (tr ("This file is opened in the read-only mode. You can save it with another name using <b>Save as</b>"));
1335 return false;
1336 }
1337
1338 if (file_exists (d->file_name))
1339 d->file_save_with_name (d->file_name, d->charset);
1340 else
1341 return file_save_as();
1342
1343 if (d->file_name == fname_bookmarks)
1344 update_bookmarks();
1345
1346 if (d->file_name == fname_programs)
1347 update_programs();
1348
1349 return true;
1350 }
1351
1352
file_save_as()1353 bool CTEA::file_save_as()
1354 {
1355 last_action = sender();
1356
1357 CDocument *d = documents->get_current();
1358 if (! d)
1359 return false;
1360
1361 if (! settings->value ("use_trad_dialogs", "0").toBool())
1362 {
1363 main_tab_widget->setCurrentIndex (idx_tab_fman);
1364 fm_entry_mode = FM_ENTRY_MODE_SAVE;
1365
1366 if (file_exists (d->file_name))
1367 fman->nav (get_file_path (d->file_name));
1368 else
1369 fman->nav (documents->dir_last);
1370
1371 ed_fman_fname->setFocus();
1372
1373 return true;
1374 }
1375
1376
1377 //ELSE standard dialog
1378
1379 QFileDialog dialog (this);
1380 QSize size = settings->value ("dialog_size", QSize (width(), height())).toSize();
1381 dialog.resize (size);
1382
1383 dialog.setFilter (QDir::AllEntries | QDir::Hidden);
1384 dialog.setOption (QFileDialog::DontUseNativeDialog, true);
1385
1386 QList<QUrl> sidebarUrls = dialog.sidebarUrls();
1387 QList<QUrl> sidebarUrls_old = dialog.sidebarUrls();
1388
1389 sidebarUrls.append (QUrl::fromLocalFile(dir_templates));
1390 sidebarUrls.append (QUrl::fromLocalFile(dir_snippets));
1391 sidebarUrls.append (QUrl::fromLocalFile(dir_sessions));
1392 sidebarUrls.append (QUrl::fromLocalFile(dir_scripts));
1393 sidebarUrls.append (QUrl::fromLocalFile(dir_tables));
1394
1395 #ifdef Q_OS_LINUX
1396
1397 QDir volDir ("/mnt");
1398 QStringList volumes (volDir.entryList (volDir.filter() | QDir::NoDotAndDotDot));
1399
1400 QDir volDir2 ("/media");
1401 QStringList volumes2 (volDir2.entryList (volDir2.filter() | QDir::NoDotAndDotDot));
1402
1403 for (int i = 0; i < volumes.size(); i++)
1404 sidebarUrls.append (QUrl::fromLocalFile ("/mnt/" + volumes.at(i)));
1405
1406 for (int i = 0; i < volumes2.size(); i++)
1407 sidebarUrls.append (QUrl::fromLocalFile ("/media/" + volumes2.at(i)));
1408
1409
1410 #endif
1411
1412 dialog.setSidebarUrls (sidebarUrls);
1413
1414 dialog.setFileMode (QFileDialog::AnyFile);
1415 dialog.setAcceptMode (QFileDialog::AcceptSave);
1416 dialog.setDirectory (documents->dir_last);
1417
1418 QLabel *l = new QLabel (tr ("Charset"));
1419 QComboBox *cb_codecs = new QComboBox (&dialog);
1420 dialog.layout()->addWidget (l);
1421 dialog.layout()->addWidget (cb_codecs);
1422
1423 if (sl_last_used_charsets.size () > 0)
1424 cb_codecs->addItems (sl_last_used_charsets + sl_charsets);
1425 else
1426 {
1427 cb_codecs->addItems (sl_charsets);
1428 cb_codecs->setCurrentIndex (sl_charsets.indexOf ("UTF-8"));
1429 }
1430
1431 if (dialog.exec())
1432 {
1433 dialog.setSidebarUrls (sidebarUrls_old);
1434
1435 QString fileName = dialog.selectedFiles().at(0);
1436
1437 if (file_exists (fileName))
1438 {
1439 int ret = QMessageBox::warning (this, "TEA",
1440 tr ("%1 already exists\n"
1441 "Do you want to overwrite?")
1442 .arg (fileName),
1443 QMessageBox::Yes | QMessageBox::Default,
1444 QMessageBox::Cancel | QMessageBox::Escape);
1445
1446 if (ret == QMessageBox::Cancel)
1447 return false;
1448 }
1449
1450 d->file_save_with_name (fileName, cb_codecs->currentText());
1451 d->set_markup_mode();
1452 d->set_hl();
1453
1454 add_to_last_used_charsets (cb_codecs->currentText());
1455 update_dyn_menus();
1456
1457 QFileInfo f (d->file_name);
1458 documents->dir_last = f.path();
1459 }
1460 else
1461 dialog.setSidebarUrls (sidebarUrls_old);
1462
1463 settings->setValue ("dialog_size", dialog.size());
1464 return true;
1465 }
1466
1467
file_save_bak()1468 void CTEA::file_save_bak()
1469 {
1470 last_action = sender();
1471
1472 CDocument *d = documents->get_current();
1473 if (! d)
1474 return;
1475
1476 if (! file_exists (d->file_name))
1477 return;
1478
1479 QString fname = d->file_name + ".bak";
1480 d->file_save_with_name_plain (fname);
1481 log->log (tr ("%1 is saved").arg (fname));
1482 }
1483
1484
file_save_version()1485 void CTEA::file_save_version()
1486 {
1487 last_action = sender();
1488
1489 CDocument *d = documents->get_current();
1490 if (! d)
1491 return;
1492
1493 if (! file_exists (d->file_name))
1494 return;
1495
1496 QDate date = QDate::currentDate();
1497 QFileInfo fi;
1498 fi.setFile (d->file_name);
1499
1500 QString version_timestamp_fmt = settings->value ("version_timestamp_fmt", "yyyy-MM-dd").toString();
1501 QTime t = QTime::currentTime();
1502
1503 QString fname = fi.absoluteDir().absolutePath() +
1504 "/" +
1505 fi.baseName() +
1506 "-" +
1507 date.toString (version_timestamp_fmt) +
1508 "-" +
1509 t.toString ("hh-mm-ss") +
1510 "." +
1511 fi.suffix();
1512
1513
1514 if (d->file_save_with_name_plain (fname))
1515 log->log (tr ("%1 - saved").arg (fname));
1516 else
1517 log->log (tr ("Cannot save %1").arg (fname));
1518 }
1519
1520
file_session_save_as()1521 void CTEA::file_session_save_as()
1522 {
1523 last_action = sender();
1524
1525 if (documents->items.size() == 0)
1526 return;
1527
1528 bool ok;
1529 QString name = QInputDialog::getText (this, tr ("Enter the name"),
1530 tr ("Name:"), QLineEdit::Normal,
1531 tr ("new_session"), &ok);
1532 if (! ok || name.isEmpty())
1533 return;
1534
1535 QString fname = dir_sessions + "/" + name;
1536 documents->save_to_session (fname);
1537 update_sessions();
1538 }
1539
1540
file_reload()1541 void CTEA::file_reload()
1542 {
1543 last_action = sender();
1544
1545 CDocument *d = documents->get_current();
1546 if (d)
1547 d->reload (d->charset);
1548 }
1549
1550
file_reload_enc_itemDoubleClicked(QListWidgetItem * item)1551 void CTEA::file_reload_enc_itemDoubleClicked (QListWidgetItem *item)
1552 {
1553 CDocument *d = documents->get_current();
1554 if (d)
1555 d->reload (item->text());
1556 }
1557
1558
file_reload_enc()1559 void CTEA::file_reload_enc()
1560 {
1561 last_action = sender();
1562
1563 CTextListWnd *w = new CTextListWnd (tr ("Reload with encoding"), tr ("Charset"));
1564
1565 if (sl_last_used_charsets.size () > 0)
1566 w->list->addItems (sl_last_used_charsets + sl_charsets);
1567 else
1568 w->list->addItems (sl_charsets);
1569
1570 connect (w->list, SIGNAL(itemDoubleClicked (QListWidgetItem *)),
1571 this, SLOT(file_reload_enc_itemDoubleClicked ( QListWidgetItem *)));
1572
1573 w->show();
1574 }
1575
1576
file_set_eol_unix()1577 void CTEA::file_set_eol_unix()
1578 {
1579 last_action = sender();
1580
1581 CDocument *d = documents->get_current();
1582 if (d)
1583 d->eol = "\n";
1584 }
1585
1586
file_set_eol_win()1587 void CTEA::file_set_eol_win()
1588 {
1589 last_action = sender();
1590
1591 CDocument *d = documents->get_current();
1592 if (d)
1593 d->eol = "\r\n";
1594 }
1595
1596
file_set_eol_mac()1597 void CTEA::file_set_eol_mac()
1598 {
1599 last_action = sender();
1600
1601 CDocument *d = documents->get_current();
1602 if (d)
1603 d->eol = "\r";
1604 }
1605
1606
file_set_autosaving_file()1607 void CTEA::file_set_autosaving_file()
1608 {
1609 last_action = sender();
1610
1611 CDocument *d = documents->get_current();
1612 if (! d)
1613 return;
1614
1615 if (! file_exists (d->file_name))
1616 return;
1617
1618 documents->autosave_files.insert (d->file_name, d->file_name);
1619 }
1620
1621
file_unset_autosaving_file()1622 void CTEA::file_unset_autosaving_file()
1623 {
1624 last_action = sender();
1625
1626 CDocument *d = documents->get_current();
1627 if (! d)
1628 return;
1629
1630 if (! file_exists (d->file_name))
1631 return;
1632
1633 documents->autosave_files.remove (d->file_name);
1634 }
1635
1636
1637 #ifdef PRINTER_ENABLE
file_print()1638 void CTEA::file_print()
1639 {
1640 last_action = sender();
1641
1642 CDocument *d = documents->get_current();
1643 if (! d)
1644 return;
1645
1646 QPrintDialog *dialog = new QPrintDialog (&printer, this);
1647
1648 dialog->setWindowTitle (tr ("Print document"));
1649
1650 if (d->textCursor().hasSelection())
1651 dialog->addEnabledOption (QAbstractPrintDialog::PrintSelection);
1652
1653 if (dialog->exec() != QDialog::Accepted)
1654 return;
1655
1656 d->print (&printer);
1657 }
1658 #endif
1659
file_add_to_bookmarks()1660 void CTEA::file_add_to_bookmarks()
1661 {
1662 last_action = sender();
1663
1664 CDocument *d = documents->get_current();
1665 if (! d)
1666 return;
1667
1668 if (! file_exists (d->file_name))
1669 return;
1670
1671 bool found = false;
1672 QStringList l_bookmarks = qstring_load (fname_bookmarks).split("\n");
1673
1674 for (int i = 0; i < l_bookmarks.size(); i++)
1675 {
1676 if (l_bookmarks.at(i).contains (d->file_name)) //update the bookmark
1677 {
1678 l_bookmarks[i] = d->get_triplex();
1679 found = true;
1680 break;
1681 }
1682 }
1683
1684 if (! found) //else just add new bookbmark
1685 l_bookmarks.prepend (d->get_triplex());
1686
1687 QString bookmarks = l_bookmarks.join ("\n").trimmed();
1688
1689 qstring_save (fname_bookmarks, bookmarks);
1690 update_bookmarks();
1691 }
1692
1693
file_find_obsolete_paths()1694 void CTEA::file_find_obsolete_paths()
1695 {
1696 QStringList l_bookmarks = qstring_load (fname_bookmarks).split ("\n");
1697
1698 for (int i = 0; i < l_bookmarks.size(); i++)
1699 {
1700 QStringList t = l_bookmarks[i].split (",");
1701 if (! file_exists (t[0]))
1702 l_bookmarks[i] = "#" + l_bookmarks[i]; //comment out the bookmark line
1703 }
1704
1705 QString bookmarks = l_bookmarks.join ("\n").trimmed();
1706
1707 qstring_save (fname_bookmarks, bookmarks);
1708 update_bookmarks();
1709 }
1710
1711
file_open_bookmarks_file()1712 void CTEA::file_open_bookmarks_file()
1713 {
1714 last_action = sender();
1715 documents->open_file (fname_bookmarks, "UTF-8");
1716 }
1717
1718
file_open_programs_file()1719 void CTEA::file_open_programs_file()
1720 {
1721 last_action = sender();
1722
1723 #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
1724
1725 if (! file_exists (fname_programs))
1726 qstring_save (fname_programs, tr ("#external programs list. example:\nopera=\"C:\\Program Files\\Opera\\opera.exe \" \"%s\""));
1727
1728 #else
1729
1730 if (! file_exists (fname_programs))
1731 qstring_save (fname_programs, tr ("#external programs list. example:\nff=firefox file:///%s"));
1732
1733 #endif
1734
1735 documents->open_file (fname_programs, "UTF-8");
1736 }
1737
1738
file_open_bookmark()1739 void CTEA::file_open_bookmark()
1740 {
1741 last_action = sender();
1742 documents->open_file_triplex (qobject_cast<QAction *>(last_action)->text());
1743 main_tab_widget->setCurrentIndex (idx_tab_edit);
1744 }
1745
1746
file_use_template()1747 void CTEA::file_use_template()
1748 {
1749 last_action = sender();
1750
1751 QAction *a = qobject_cast<QAction *>(sender());
1752 QString txt = qstring_load (a->data().toString());
1753
1754 CDocument *d = documents->create_new();
1755 if (d)
1756 d->put (txt);
1757 }
1758
1759
file_open_session()1760 void CTEA::file_open_session()
1761 {
1762 last_action = sender();
1763
1764 QAction *a = qobject_cast<QAction *>(sender());
1765 documents->load_from_session (a->data().toString());
1766 }
1767
1768
file_recent_off()1769 void CTEA::file_recent_off()
1770 {
1771 last_action = sender();
1772 b_recent_off = ! b_recent_off;
1773 }
1774
1775
file_close()1776 void CTEA::file_close()
1777 {
1778 last_action = sender();
1779 documents->close_current();
1780 }
1781
1782 /*
1783 ===================
1784 Edit menu callbacks
1785 ===================
1786 */
1787
1788
ed_copy()1789 void CTEA::ed_copy()
1790 {
1791 last_action = sender();
1792
1793 if (main_tab_widget->currentIndex() == idx_tab_edit)
1794 {
1795 CDocument *d = documents->get_current();
1796 if (d)
1797 d->copy();
1798 }
1799 else
1800 if (main_tab_widget->currentIndex() == idx_tab_learn)
1801 man->copy();
1802 }
1803
1804
ed_paste()1805 void CTEA::ed_paste()
1806 {
1807 last_action = sender();
1808
1809 CDocument *d = documents->get_current();
1810 if (d)
1811 d->paste();
1812 }
1813
1814
ed_cut()1815 void CTEA::ed_cut()
1816 {
1817 last_action = sender();
1818
1819 CDocument *d = documents->get_current();
1820 if (d)
1821 d->cut();
1822 }
1823
1824
ed_block_start()1825 void CTEA::ed_block_start()
1826 {
1827 last_action = sender();
1828
1829 CDocument *d = documents->get_current();
1830 if (d)
1831 d->rect_block_start();
1832 }
1833
1834
ed_block_end()1835 void CTEA::ed_block_end()
1836 {
1837 last_action = sender();
1838
1839 CDocument *d = documents->get_current();
1840 if (d)
1841 d->rect_block_end();
1842 }
1843
1844
ed_block_copy()1845 void CTEA::ed_block_copy()
1846 {
1847 last_action = sender();
1848
1849 CDocument *d = documents->get_current();
1850 if (! d)
1851 return;
1852
1853 if (! d->has_rect_selection())
1854 return;
1855
1856 QApplication::clipboard()->setText (d->rect_sel_get());
1857 }
1858
1859
ed_block_paste()1860 void CTEA::ed_block_paste()
1861 {
1862 last_action = sender();
1863
1864 CDocument *d = documents->get_current();
1865 if (d)
1866 d->rect_sel_replace (QApplication::clipboard()->text());
1867 }
1868
1869
ed_block_cut()1870 void CTEA::ed_block_cut()
1871 {
1872 last_action = sender();
1873
1874 CDocument *d = documents->get_current();
1875 if (d)
1876 d->rect_sel_cut();
1877 }
1878
1879
ed_copy_current_fname()1880 void CTEA::ed_copy_current_fname()
1881 {
1882 last_action = sender();
1883
1884 CDocument *d = documents->get_current();
1885 if (d)
1886 QApplication::clipboard()->setText (d->file_name);
1887 }
1888
1889
ed_undo()1890 void CTEA::ed_undo()
1891 {
1892 last_action = sender();
1893
1894 CDocument *d = documents->get_current();
1895 if (d)
1896 d->undo();
1897 }
1898
1899
ed_redo()1900 void CTEA::ed_redo()
1901 {
1902 last_action = sender();
1903
1904 CDocument *d = documents->get_current();
1905 if (d)
1906 d->redo();
1907 }
1908
1909
ed_indent()1910 void CTEA::ed_indent()
1911 {
1912 last_action = sender();
1913
1914 CDocument *d = documents->get_current();
1915 if (d)
1916 d->indent();
1917 }
1918
1919
ed_unindent()1920 void CTEA::ed_unindent()
1921 {
1922 last_action = sender();
1923
1924 CDocument *d = documents->get_current();
1925 if (d)
1926 d->un_indent();
1927 }
1928
1929
ed_indent_by_first_line()1930 void CTEA::ed_indent_by_first_line()
1931 {
1932 last_action = sender();
1933
1934 CDocument *d = documents->get_current();
1935 if (! d)
1936 return;
1937
1938 QStringList sl = d->get().split (QChar::ParagraphSeparator);
1939 if (sl.size() == 0)
1940 return;
1941
1942 QString x = sl[0];
1943 QChar c = x[0];
1944 int pos = 0;
1945
1946 if (c == ' ' || c == '\t')
1947 for (int i = 0; i < x.size(); i++)
1948 if (x[i] != c)
1949 {
1950 pos = i;
1951 break;
1952 }
1953
1954 QString fill_string;
1955 fill_string.fill (c, pos);
1956
1957 for (int i = 0; i < sl.size(); i++)
1958 {
1959 QString s = sl[i].trimmed();
1960 s.prepend (fill_string);
1961 sl[i] = s;
1962 }
1963
1964 QString t = sl.join ("\n");
1965
1966 d->put (t);
1967 }
1968
1969
ed_comment()1970 void CTEA::ed_comment()
1971 {
1972 last_action = sender();
1973
1974 CDocument *d = documents->get_current();
1975 if (! d)
1976 return;
1977
1978 if (! d->highlighter)
1979 return;
1980
1981 if (d->highlighter->comment_mult.isEmpty() && d->highlighter->comment_single.isEmpty())
1982 return;
1983
1984 QString t = d->get();
1985 QString result;
1986
1987 bool is_multiline = true;
1988
1989 int sep_pos = t.indexOf (QChar::ParagraphSeparator);
1990 if (sep_pos == -1 || sep_pos == t.size() - 1)
1991 is_multiline = false;
1992
1993 if (is_multiline)
1994 result = d->highlighter->comment_mult;
1995 else
1996 result = d->highlighter->comment_single;
1997
1998 if (is_multiline && result.isEmpty())
1999 {
2000 QStringList sl = t.split (QChar::ParagraphSeparator);
2001 for (int i = 0; i < sl.size(); i++)
2002 {
2003 QString x = d->highlighter->comment_single;
2004 sl[i] = x.replace ("%s", sl[i]);
2005 }
2006
2007 QString z = sl.join("\n");
2008 d->put (z);
2009
2010 return;
2011 }
2012
2013 d->put (result.replace ("%s", t));
2014 }
2015
2016
ed_set_as_storage_file()2017 void CTEA::ed_set_as_storage_file()
2018 {
2019 last_action = sender();
2020
2021 CDocument *d = documents->get_current();
2022 if (d)
2023 fname_storage_file = d->file_name;
2024 }
2025
2026
ed_copy_to_storage_file()2027 void CTEA::ed_copy_to_storage_file()
2028 {
2029 last_action = sender();
2030
2031 CDocument *dsource = documents->get_current();
2032 if (! dsource)
2033 return;
2034
2035 CDocument *ddest = documents->get_document_by_fname (fname_storage_file);
2036 if (ddest)
2037 {
2038 QString t = dsource->get();
2039 ddest->put (t);
2040 ddest->put ("\n");
2041 }
2042 else
2043 log->log (tr ("The storage file is closed or not set."));
2044 }
2045
2046
ed_capture_clipboard_to_storage_file()2047 void CTEA::ed_capture_clipboard_to_storage_file()
2048 {
2049 last_action = sender();
2050 capture_to_storage_file = qobject_cast<QAction *>(sender())->isChecked();
2051 //was capture_to_storage_file = ! capture_to_storage_file;
2052 }
2053
2054
2055 /*
2056 ===================
2057 Markup menu callbacks
2058 ===================
2059 */
2060
2061
mrkup_mode_choosed()2062 void CTEA::mrkup_mode_choosed()
2063 {
2064 last_action = sender();
2065
2066 QAction *a = qobject_cast<QAction *>(sender());
2067 markup_mode = a->text();
2068 documents->markup_mode = markup_mode;
2069
2070 CDocument *d = documents->get_current();
2071 if (d)
2072 d->markup_mode = markup_mode;
2073 }
2074
2075
mrkup_header()2076 void CTEA::mrkup_header()
2077 {
2078 last_action = sender();
2079
2080 CDocument *d = documents->get_current();
2081 if (! d)
2082 return;
2083
2084 QAction *a = qobject_cast<QAction *>(sender());
2085
2086 QString r;
2087
2088 if (documents->markup_mode == "Markdown")
2089 {
2090 QString t;
2091 int n = a->text().toLower()[1].digitValue();
2092 t.fill ('#', n);
2093 r = t + " " + d->get();
2094 }
2095 else
2096 r = QString ("<%1>%2</%1>").arg (
2097 a->text().toLower()).arg (
2098 d->get());
2099
2100 d->put (r);
2101 }
2102
2103
mrkup_align_center()2104 void CTEA::mrkup_align_center()
2105 {
2106 last_action = sender();
2107 markup_text ("align_center");
2108 }
2109
2110
mrkup_align_left()2111 void CTEA::mrkup_align_left()
2112 {
2113 last_action = sender();
2114 markup_text ("align_left");
2115 }
2116
2117
mrkup_align_right()2118 void CTEA::mrkup_align_right()
2119 {
2120 last_action = sender();
2121 markup_text ("align_right");
2122 }
2123
2124
mrkup_align_justify()2125 void CTEA::mrkup_align_justify()
2126 {
2127 last_action = sender();
2128 markup_text ("align_justify");
2129 }
2130
2131
mrkup_bold()2132 void CTEA::mrkup_bold()
2133 {
2134 last_action = sender();
2135 markup_text ("bold");
2136 }
2137
2138
mrkup_italic()2139 void CTEA::mrkup_italic()
2140 {
2141 last_action = sender();
2142 markup_text ("italic");
2143 }
2144
2145
mrkup_underline()2146 void CTEA::mrkup_underline()
2147 {
2148 last_action = sender();
2149 markup_text ("underline");
2150 }
2151
mrkup_link()2152 void CTEA::mrkup_link()
2153 {
2154 last_action = sender();
2155 markup_text ("link");
2156 }
2157
2158
mrkup_para()2159 void CTEA::mrkup_para()
2160 {
2161 last_action = sender();
2162 markup_text ("para");
2163 }
2164
2165
mrkup_color()2166 void CTEA::mrkup_color()
2167 {
2168 last_action = sender();
2169
2170 CDocument *d = documents->get_current();
2171 if (! d)
2172 return;
2173
2174 QColor color = QColorDialog::getColor (Qt::green, this);
2175 if (! color.isValid())
2176 return;
2177
2178 QString s;
2179
2180 if (d->textCursor().hasSelection())
2181 s = QString ("<span style=\"color:%1;\">%2</span>")
2182 .arg (color.name())
2183 .arg (d->get());
2184 else
2185 s = color.name();
2186
2187 d->put (s);
2188 }
2189
2190
mrkup_br()2191 void CTEA::mrkup_br()
2192 {
2193 last_action = sender();
2194 markup_text ("newline");
2195 }
2196
2197
mrkup_nbsp()2198 void CTEA::mrkup_nbsp()
2199 {
2200 last_action = sender();
2201 CDocument *d = documents->get_current();
2202 if (d)
2203 d->put (" ");
2204 }
2205
2206
markup_ins_image()2207 void CTEA::markup_ins_image()
2208 {
2209 last_action = sender();
2210
2211 CDocument *d = documents->get_current();
2212 if (! d)
2213 return;
2214
2215 main_tab_widget->setCurrentIndex (idx_tab_fman);
2216
2217 if (file_exists (d->file_name))
2218 fman->nav (get_file_path (d->file_name));
2219 }
2220
2221
mrkup_text_to_html()2222 void CTEA::mrkup_text_to_html()
2223 {
2224 last_action = sender();
2225
2226 CDocument *d = documents->get_current();
2227 if (! d)
2228 return;
2229
2230 QStringList l;
2231
2232 if (d->textCursor().hasSelection())
2233 l = d->get().split (QChar::ParagraphSeparator);
2234 else
2235 l = d->toPlainText().split("\n");
2236
2237 QString result;
2238
2239 if (d->markup_mode == "HTML")
2240 result += "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n";
2241 else
2242 result += "<!DOCTYPE html PUBLIC \"-//W3C//DTD 1.0 Transitional//EN\" \"http://www.w3.org/TR/1/DTD/1-transitional.dtd\">\n";
2243
2244 result += "<html>\n"
2245 "<head>\n"
2246 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n"
2247 "<style type=\"text/css\">\n"
2248 ".p1\n"
2249 "{\n"
2250 "margin: 0px 0px 0px 0px;\n"
2251 "padding: 0px 0px 0px 0px;\n"
2252 "text-indent: 1.5em;\n"
2253 "text-align: justify;\n"
2254 "}\n"
2255 "</style>\n"
2256 "<title></title>\n"
2257 "</head>\n"
2258 "<body>\n";
2259
2260 for (int i = 0; i < l.size(); i++)
2261 {
2262 QString t = l.at(i).simplified();
2263
2264 if (t.isEmpty())
2265 {
2266 if (d->markup_mode == "HTML")
2267 result += "<br>\n";
2268 else
2269 result += "<br />\n";
2270 }
2271 else
2272 result += "<p class=\"p1\">" + t + "</p>\n";
2273 }
2274
2275 result += "</body>\n</html>";
2276
2277 CDocument *doc = documents->create_new();
2278
2279 if (doc)
2280 doc->put (result);
2281 }
2282
2283
mrkup_tags_to_entities()2284 void CTEA::mrkup_tags_to_entities()
2285 {
2286 last_action = sender();
2287
2288 CDocument *d = documents->get_current();
2289 if (d)
2290 d->put (str_to_entities (d->get()));
2291 }
2292
2293
mrkup_antispam_email()2294 void CTEA::mrkup_antispam_email()
2295 {
2296 last_action = qobject_cast<QAction *>(sender());
2297
2298 CDocument *d = documents->get_current();
2299 if (! d)
2300 return;
2301
2302 QString s = d->get();
2303 QString result;
2304
2305 for (int i = 0; i < s.size(); i++)
2306 result = result + "&#" + QString::number (s.at (i).unicode()) + ";";
2307
2308 d->put (result);
2309 }
2310
2311
mrkup_document_weight()2312 void CTEA::mrkup_document_weight()
2313 {
2314 last_action = sender();
2315
2316 CDocument *d = documents->get_current();
2317 if (! d)
2318 return;
2319
2320 QString result;
2321 QStringList l = html_get_by_patt (d->toPlainText(), "src=\"");
2322
2323 QFileInfo f (d->file_name);
2324 QUrl baseUrl (d->file_name);
2325
2326 vector <pair <QString, qint64> > files;
2327 files.push_back(make_pair(d->file_name, f.size()));
2328
2329 int size_total = 0;
2330 int files_total = 1;
2331
2332 for (int i = 0; i < l.size(); i++)
2333 {
2334 QUrl relativeUrl (l.at(i));
2335 QString resolved = baseUrl.resolved (relativeUrl).toString();
2336 QFileInfo info (resolved);
2337
2338 if (! info.exists())
2339 files.push_back(std::make_pair(tr ("%1 is not found<br>").arg (resolved), info.size()));
2340 else
2341 {
2342 files.push_back(std::make_pair(resolved, info.size()));
2343 size_total += info.size();
2344 ++files_total;
2345 }
2346 }
2347
2348 std::sort (files.begin(), files.end());
2349
2350 for (vector <pair <QString, qint64> >::iterator p = files.begin(); p != files.end(); ++p)
2351 {
2352 result += tr ("%1 kbytes %2 <br>").arg (QString::number (p->second / 1024)).arg (p->first);
2353 }
2354
2355 result.prepend (tr ("Total size = %1 kbytes in %2 files<br>").arg (QString::number (size_total / 1024))
2356 .arg (QString::number (files_total)));
2357
2358 log->log (result);
2359 }
2360
2361
mrkup_preview_color()2362 void CTEA::mrkup_preview_color()
2363 {
2364 last_action = sender();
2365
2366 CDocument *d = documents->get_current();
2367 if (! d)
2368 return;
2369
2370 if (! d->textCursor().hasSelection())
2371 return;
2372
2373 QString color = d->get();
2374
2375 if (QColor::colorNames().indexOf (color) == -1)
2376 {
2377 color = color.remove (";");
2378 if (! color.startsWith ("#"))
2379 color = "#" + color;
2380 }
2381 else
2382 {
2383 QColor c (color);
2384 color = c.name();
2385 }
2386
2387 QString style = QString ("color:%1; font-weight:bold;").arg (color);
2388 log->log (tr ("<span style=\"%1\">COLOR SAMPLE</span>").arg (style));
2389 }
2390
2391
mrkup_strip_html_tags()2392 void CTEA::mrkup_strip_html_tags()
2393 {
2394 last_action = sender();
2395
2396 CDocument *d = documents->get_current();
2397 if (! d)
2398 return;
2399
2400 QString text;
2401
2402 if (d->textCursor().hasSelection())
2403 text = d->get();
2404 else
2405 text = d->toPlainText();
2406
2407 if (d->textCursor().hasSelection())
2408 d->put (strip_html (text));
2409 else
2410 d->setPlainText (strip_html (text));
2411 }
2412
2413
mrkup_rename_selected()2414 void CTEA::mrkup_rename_selected()
2415 {
2416 last_action = sender();
2417
2418 CDocument *d = documents->get_current();
2419 if (! d)
2420 return;
2421
2422 if (! d->textCursor().hasSelection())
2423 {
2424 log->log (tr ("Select the file name first!"));
2425 return;
2426 }
2427
2428 QString fname = d->get_filename_at_cursor();
2429
2430 if (fname.isEmpty())
2431 return;
2432
2433 if (documents->get_document_by_fname (fname))
2434 {
2435 log->log (tr("You are trying to rename the opened file, please close it first!"));
2436 return;
2437 }
2438
2439 QString newname = fif_get_text();
2440 if (newname.isEmpty())
2441 return;
2442
2443 QFileInfo fi (fname);
2444 if (! fi.exists() && ! fi.isWritable())
2445 return;
2446
2447 QString newfpath = fi.path() + "/" + newname;
2448 QFile::rename (fname, newfpath);
2449 update_dyn_menus();
2450 fman->refresh();
2451
2452 QDir dir (d->file_name);
2453 QString new_name = dir.relativeFilePath (newfpath);
2454
2455 if (new_name.startsWith (".."))
2456 new_name = new_name.remove (0, 1);
2457
2458 if (d->get().startsWith ("./") && ! new_name.startsWith ("./"))
2459 new_name = "./" + new_name;
2460
2461 if (! d->get().startsWith ("./") && new_name.startsWith ("./"))
2462 new_name = new_name.remove (0, 2);
2463
2464 if (d->textCursor().hasSelection())
2465 d->put (new_name.trimmed());
2466 }
2467
2468
2469 /*
2470 ===================
2471 Search menu callbacks
2472 ===================
2473 */
2474
2475
search_find()2476 void CTEA::search_find()
2477 {
2478 last_action = sender();
2479
2480 if (main_tab_widget->currentIndex() == idx_tab_edit)
2481 {
2482 CDocument *d = documents->get_current();
2483 if (! d)
2484 return;
2485
2486 QTextCursor cr;
2487
2488 int from = 0;
2489
2490 if (settings->value ("find_from_cursor", "1").toBool())
2491 from = d->textCursor().position();
2492
2493 d->text_to_search = fif_get_text();
2494
2495 #if QT_VERSION >= 0x050500
2496 if (menu_find_regexp->isChecked())
2497 cr = d->document()->find (QRegularExpression (d->text_to_search), from, get_search_options());
2498 #else
2499 if (menu_find_regexp->isChecked())
2500 cr = d->document()->find (QRegExp (d->text_to_search), from, get_search_options());
2501 #endif
2502
2503 /*
2504 #if QT_VERSION < 0x050000
2505 cr = d->document()->find (QRegExp (d->text_to_search), from, get_search_options());
2506 #else
2507 cr = d->document()->find (QRegularExpression (d->text_to_search), from, get_search_options());
2508 #endif
2509 */
2510 if (menu_find_fuzzy->isChecked())
2511 {
2512 int pos = str_fuzzy_search (d->toPlainText(), d->text_to_search, from, settings->value ("fuzzy_q", "60").toInt());
2513 if (pos != -1)
2514 {
2515 from = pos + d->text_to_search.length() - 1;
2516 //set selection:
2517 cr = d->textCursor();
2518 cr.setPosition (from, QTextCursor::MoveAnchor);
2519 cr.movePosition (QTextCursor::Right, QTextCursor::KeepAnchor, d->text_to_search.length());
2520
2521 if (! cr.isNull())
2522 d->setTextCursor (cr);
2523 }
2524 return;
2525 }
2526 else //normal search
2527 cr = d->document()->find (d->text_to_search, from, get_search_options());
2528
2529 if (! cr.isNull())
2530 d->setTextCursor (cr);
2531 else
2532 log->log(tr ("not found!"));
2533 }
2534 else
2535 if (main_tab_widget->currentIndex() == idx_tab_learn)
2536 man_find_find();
2537 else
2538 if (main_tab_widget->currentIndex() == idx_tab_tune)
2539 opt_shortcuts_find();
2540 else
2541 if (main_tab_widget->currentIndex() == idx_tab_fman)
2542 fman_find();
2543 }
2544
2545
search_find_next()2546 void CTEA::search_find_next()
2547 {
2548 last_action = sender();
2549
2550 if (main_tab_widget->currentIndex() == idx_tab_edit)
2551 {
2552 CDocument *d = documents->get_current();
2553 if (! d)
2554 return;
2555
2556 QTextCursor cr;
2557 if (menu_find_regexp->isChecked())
2558
2559 #if QT_VERSION >= 0x050500
2560 if (menu_find_regexp->isChecked())
2561 cr = d->document()->find (QRegularExpression (d->text_to_search), d->textCursor().position(), get_search_options());
2562 #else
2563 //#if QT_VERSION < 0x050500
2564 if (menu_find_regexp->isChecked())
2565 cr = d->document()->find (QRegExp (d->text_to_search), d->textCursor().position(), get_search_options());
2566 //#endif
2567 #endif
2568
2569 if (menu_find_fuzzy->isChecked())
2570 {
2571 int pos = str_fuzzy_search (d->toPlainText(), d->text_to_search, d->textCursor().position(), settings->value ("fuzzy_q", "60").toInt());
2572 if (pos != -1)
2573 {
2574 cr = d->textCursor();
2575 cr.setPosition (pos, QTextCursor::MoveAnchor);
2576 cr.movePosition (QTextCursor::Right, QTextCursor::KeepAnchor, d->text_to_search.length());
2577
2578 if (! cr.isNull())
2579 d->setTextCursor (cr);
2580 }
2581 return;
2582 }
2583 else
2584 cr = d->document()->find (d->text_to_search, d->textCursor().position(), get_search_options());
2585
2586 if (! cr.isNull())
2587 d->setTextCursor (cr);
2588 }
2589 else
2590 if (main_tab_widget->currentIndex() == idx_tab_learn)
2591 man_find_next();
2592 else
2593 if (main_tab_widget->currentIndex() == idx_tab_tune)
2594 opt_shortcuts_find_next();
2595 else
2596 if (main_tab_widget->currentIndex() == idx_tab_fman)
2597 fman_find_next();
2598 }
2599
2600
search_find_prev()2601 void CTEA::search_find_prev()
2602 {
2603 last_action = sender();
2604
2605 if (main_tab_widget->currentIndex() == idx_tab_edit)
2606 {
2607 CDocument *d = documents->get_current();
2608 if (! d)
2609 return;
2610
2611 QTextCursor cr;
2612
2613 #if QT_VERSION >= 0x050500
2614 if (menu_find_regexp->isChecked())
2615 cr = d->document()->find (QRegularExpression (d->text_to_search), d->textCursor().position(), get_search_options() | QTextDocument::FindBackward);
2616 #endif
2617
2618 #if QT_VERSION < 0x050500
2619 if (menu_find_regexp->isChecked())
2620 cr = d->document()->find (QRegExp (d->text_to_search), d->textCursor().position(), get_search_options() | QTextDocument::FindBackward);
2621 #endif
2622
2623 if (! menu_find_regexp->isChecked())
2624 cr = d->document()->find (d->text_to_search,
2625 d->textCursor(),
2626 get_search_options() | QTextDocument::FindBackward);
2627
2628
2629 if (! cr.isNull())
2630 d->setTextCursor (cr);
2631 }
2632 else
2633 if (main_tab_widget->currentIndex() == idx_tab_learn)
2634 man_find_prev();
2635 else
2636 if (main_tab_widget->currentIndex() == idx_tab_tune)
2637 opt_shortcuts_find_prev();
2638 else
2639 if (main_tab_widget->currentIndex() == idx_tab_fman)
2640 fman_find_prev();
2641 }
2642
2643
search_mark_all()2644 void CTEA::search_mark_all()
2645 {
2646 last_action = sender();
2647
2648 CDocument *d = documents->get_current();
2649 if (! d)
2650 return;
2651
2652 int darker_val = settings->value ("darker_val", 100).toInt();
2653
2654 QString text_color = hash_get_val (global_palette, "text", "black");
2655 QString back_color = hash_get_val (global_palette, "background", "white");
2656 QString t_text_color = QColor (text_color).darker(darker_val).name();
2657 QString t_back_color = QColor (back_color).darker(darker_val).name();
2658
2659 bool cont_search = true;
2660
2661 int pos_save = d->textCursor().position();
2662
2663 d->selectAll();
2664
2665 QTextCharFormat f = d->currentCharFormat();
2666 f.setBackground (QColor (t_back_color));
2667 f.setForeground (QColor (t_text_color));
2668 d->mergeCurrentCharFormat (f);
2669
2670 d->textCursor().clearSelection();
2671
2672 int from;
2673
2674 if (settings->value ("find_from_cursor", "1").toBool())
2675 from = d->textCursor().position();
2676 else
2677 from = 0;
2678
2679 d->text_to_search = fif_get_text();
2680 QTextCursor cr;
2681
2682 while (cont_search)
2683 {
2684
2685 #if (QT_VERSION_MAJOR < 5)
2686 if (menu_find_regexp->isChecked())
2687 cr = d->document()->find (QRegExp (d->text_to_search), from, get_search_options());
2688 #else
2689 if (menu_find_regexp->isChecked())
2690 cr = d->document()->find (QRegularExpression (d->text_to_search), from, get_search_options());
2691 #endif
2692 else
2693 if (menu_find_fuzzy->isChecked()) //fuzzy search
2694 {
2695 int pos = str_fuzzy_search (d->toPlainText(), d->text_to_search, from, settings->value ("fuzzy_q", "60").toInt());
2696 if (pos != -1)
2697 {
2698 //set selection:
2699 cr = d->textCursor();
2700 cr.setPosition (pos, QTextCursor::MoveAnchor);
2701 cr.movePosition (QTextCursor::Right, QTextCursor::KeepAnchor, d->text_to_search.length());
2702
2703 if (! cr.isNull())
2704 d->setTextCursor (cr);
2705 }
2706 else
2707 cont_search = false;
2708 }
2709 else //normal search
2710 cr = d->document()->find (d->text_to_search, from, get_search_options());
2711
2712 if (! cr.isNull())
2713 {
2714 d->setTextCursor (cr);
2715 QTextCharFormat fm = cr.blockCharFormat();
2716 fm.setBackground (QColor (hash_get_val (global_palette, "backgroundmark", "red")));
2717 fm.setForeground (QColor (hash_get_val (global_palette, "foregroundmark", "blue")));
2718
2719 cr.mergeCharFormat (fm);
2720 d->setTextCursor (cr);
2721 }
2722 else
2723 cont_search = false;
2724
2725 from = d->textCursor().position();
2726 }
2727
2728 d->document()->setModified (false);
2729 d->goto_pos (pos_save);
2730 }
2731
2732
search_unmark()2733 void CTEA::search_unmark()
2734 {
2735 last_action = sender();
2736
2737 CDocument *d = documents->get_current();
2738 if (! d)
2739 return;
2740
2741 int darker_val = settings->value ("darker_val", 100).toInt();
2742
2743 QString text_color = hash_get_val (global_palette, "text", "black");
2744 QString back_color = hash_get_val (global_palette, "background", "white");
2745
2746 QString t_text_color = QColor (text_color).darker(darker_val).name();
2747 QString t_back_color = QColor (back_color).darker(darker_val).name();
2748
2749 d->selectAll();
2750
2751 QTextCharFormat f = d->currentCharFormat();
2752 f.setBackground (QColor (t_back_color));
2753 f.setForeground (QColor (t_text_color));
2754 d->mergeCurrentCharFormat (f);
2755 d->textCursor().clearSelection();
2756 }
2757
2758
search_in_files_results_dclicked(QListWidgetItem * item)2759 void CTEA::search_in_files_results_dclicked (QListWidgetItem *item)
2760 {
2761 documents->open_file_triplex (item->text());
2762 main_tab_widget->setCurrentIndex (idx_tab_edit);
2763 }
2764
2765
search_in_files()2766 void CTEA::search_in_files()
2767 {
2768 last_action = sender();
2769
2770 if (main_tab_widget->currentIndex() != idx_tab_fman)
2771 return;
2772
2773 QString text_to_search = fif_get_text();
2774
2775 if (text_to_search.isEmpty())
2776 return;
2777
2778 QStringList lresult;
2779 QString charset = cb_fman_codecs->currentText();
2780 QString path = fman->dir.path();
2781
2782 CFTypeChecker fc;
2783
2784 progress_show();
2785
2786 log->log (tr ("Getting files list..."));
2787 qApp->processEvents();
2788
2789 CFilesList lf;
2790 lf.get (path);
2791
2792 log->log (tr ("Searching..."));
2793 qApp->processEvents();
2794
2795 //pb_status->show();
2796
2797 progress_show();
2798
2799 pb_status->setRange (0, lf.list.size());
2800 pb_status->setFormat (tr ("%p% completed"));
2801 pb_status->setTextVisible (true);
2802
2803 for (int i = 0; i < lf.list.size(); i++)
2804 {
2805 if (i % 100 == 0)
2806 qApp->processEvents();
2807
2808 if (boring)
2809 break;
2810
2811 pb_status->setValue (i);
2812
2813 QString fname = lf.list[i];
2814
2815 if (! fc.check (fname))
2816 continue;
2817
2818 log->log (fname);
2819
2820 CTio *tio = documents->tio_handler.get_for_fname (fname);
2821 tio->charset = charset;
2822
2823 if (! tio->load (fname))
2824 log->log (tr ("cannot open %1 because of: %2")
2825 .arg (fname)
2826 .arg (tio->error_string));
2827
2828 Qt::CaseSensitivity cs = Qt::CaseInsensitive;
2829 if (menu_find_case->isChecked())
2830 cs = Qt::CaseSensitive;
2831
2832 int index = tio->data.indexOf (text_to_search, 0, cs);
2833 if (index != -1)
2834 lresult.append (fname + "," + charset + "," + QString::number (index));
2835 }
2836
2837 //pb_status->hide();
2838 progress_hide();
2839
2840 CTextListWnd *w = new CTextListWnd (tr ("Search results"), tr ("Files"));
2841 w->move (this->x(), this->y());
2842
2843 w->list->addItems (lresult);
2844
2845 connect (w->list, SIGNAL(itemDoubleClicked ( QListWidgetItem *)),
2846 this, SLOT(search_in_files_results_dclicked ( QListWidgetItem *)));
2847
2848 w->resize (width() - 10, (int) height() / 2);
2849 w->show();
2850 }
2851
2852
search_whole_words_mode()2853 void CTEA::search_whole_words_mode()
2854 {
2855 menu_find_fuzzy->setChecked (false);
2856 }
2857
2858
search_from_cursor_mode()2859 void CTEA::search_from_cursor_mode()
2860 {
2861 settings->setValue ("find_from_cursor", menu_find_from_cursor->isChecked());
2862 }
2863
2864
search_regexp_mode()2865 void CTEA::search_regexp_mode()
2866 {
2867 menu_find_fuzzy->setChecked (false);
2868 }
2869
2870
search_fuzzy_mode()2871 void CTEA::search_fuzzy_mode()
2872 {
2873 menu_find_whole_words->setChecked (false);
2874 menu_find_regexp->setChecked (false);;
2875 }
2876
2877
search_replace_with()2878 void CTEA::search_replace_with()
2879 {
2880 last_action = sender();
2881
2882 CDocument *d = documents->get_current();
2883 if (d)
2884 d->put (fif_get_text());
2885 }
2886
2887
search_replace_all()2888 void CTEA::search_replace_all()
2889 {
2890 last_action = sender();
2891
2892 Qt::CaseSensitivity cs = Qt::CaseInsensitive;
2893 if (menu_find_case->isChecked())
2894 cs = Qt::CaseSensitive;
2895
2896 QStringList l = fif_get_text().split ("~");
2897 if (l.size() < 2)
2898 return;
2899
2900 if (main_tab_widget->currentIndex() == idx_tab_edit)
2901 {
2902 CDocument *d = documents->get_current();
2903 if (! d)
2904 return;
2905
2906 QString s = d->get();
2907
2908 #if (QT_VERSION_MAJOR < 5)
2909 if (menu_find_regexp->isChecked())
2910 s = s.replace (QRegExp (l[0]), l[1]);
2911 else
2912 s = s.replace (l[0], l[1], cs);
2913 #else
2914
2915 if (menu_find_regexp->isChecked())
2916 s = s.replace (QRegularExpression (l[0]), l[1]);
2917 else
2918 s = s.replace (l[0], l[1], cs);
2919
2920 #endif
2921
2922 d->put (s);
2923 }
2924 else
2925 if (main_tab_widget->currentIndex() == idx_tab_fman)
2926 {
2927 QStringList sl = fman->get_sel_fnames();
2928
2929 if (sl.size() < 1)
2930 return;
2931
2932 char *charset = cb_fman_codecs->currentText().toLatin1().data();
2933
2934 for (QList <QString>::iterator fname = sl.begin(); fname != sl.end(); ++fname)
2935 {
2936 QString f = qstring_load ((*fname), charset);
2937 QString r;
2938
2939 #if (QT_VERSION_MAJOR < 5)
2940
2941 if (menu_find_regexp->isChecked())
2942 r = f.replace (QRegExp (l[0]), l[1]);
2943 else
2944 r = f.replace (l[0], l[1], cs);
2945
2946 #else
2947
2948 if (menu_find_regexp->isChecked())
2949 r = f.replace (QRegularExpression (l[0]), l[1]);
2950 else
2951 r = f.replace (l[0], l[1], cs);
2952
2953 #endif
2954
2955 qstring_save ((*fname), r, charset);
2956 log->log (tr ("%1 is processed and saved").arg ((*fname)));
2957 }
2958 }
2959 }
2960
2961
search_replace_all_at_ofiles()2962 void CTEA::search_replace_all_at_ofiles()
2963 {
2964 last_action = sender();
2965
2966 QStringList l = fif_get_text().split ("~");
2967 if (l.size() < 2)
2968 return;
2969
2970 int c = documents->items.size();
2971 if (c == 0)
2972 return;
2973
2974 Qt::CaseSensitivity cs = Qt::CaseInsensitive;
2975 if (menu_find_case->isChecked())
2976 cs = Qt::CaseSensitive;
2977
2978 for (vector <size_t>::size_type i = 0; i < documents->items.size(); i++)
2979 {
2980 CDocument *d = documents->items[i];
2981 QString s;
2982
2983 #if QT_VERSION < 0x050000
2984
2985 if (menu_find_regexp->isChecked())
2986 s = d->toPlainText().replace (QRegExp (l[0]), l[1]);
2987 else
2988 s = d->toPlainText().replace (l[0], l[1], cs);
2989
2990 #else
2991
2992 if (menu_find_regexp->isChecked())
2993 s = d->toPlainText().replace (QRegularExpression (l[0]), l[1]);
2994 else
2995 s = d->toPlainText().replace (l[0], l[1], cs);
2996
2997 #endif
2998
2999 d->selectAll();
3000 d->put (s);
3001 }
3002 }
3003
3004
3005 /*
3006 ===================
3007 Fn menu callbacks
3008 ===================
3009 */
3010
3011
fn_repeat()3012 void CTEA::fn_repeat()
3013 {
3014 if (last_action)
3015 qobject_cast<QAction *>(last_action)->trigger();
3016 }
3017
3018
fn_scale_image()3019 void CTEA::fn_scale_image()
3020 {
3021 last_action = sender();
3022
3023 CDocument *d = documents->get_current();
3024 if (! d)
3025 return;
3026
3027 QString fname = d->get_filename_at_cursor();
3028
3029 if (! is_image (fname))
3030 return;
3031
3032 QImage source (fname);
3033 if (source.isNull())
3034 return;
3035
3036 QString t = fif_get_text();
3037 if (t.indexOf ("~") == -1)
3038 return;
3039
3040 QFileInfo fi (fname);
3041
3042 QStringList params = t.split ("~");
3043
3044 if (params.size() < 2)
3045 {
3046 log->log (tr("Incorrect parameters at FIF"));
3047 return;
3048 }
3049
3050 QString fnameout = params[0].replace ("%filename", fi.fileName());
3051 fnameout = fnameout.replace ("%basename", fi.baseName());
3052 fnameout = fnameout.replace ("%s", fname);
3053
3054 fnameout = fnameout.replace ("%ext", fi.suffix());
3055 fnameout = fi.absolutePath() + "/" + fnameout;
3056
3057 bool scale_by_side = true;
3058
3059 if (params[1].indexOf("%") != -1)
3060 scale_by_side = false;
3061
3062 int side = 800;
3063 int percent = 100;
3064
3065 if (scale_by_side)
3066 side = params[1].toInt();
3067 else
3068 {
3069 params[1].chop (1);
3070 percent = params[1].toInt();
3071 }
3072
3073 Qt::TransformationMode transformMode = Qt::FastTransformation;
3074 if (settings->value ("img_filter", 0).toBool())
3075 transformMode = Qt::SmoothTransformation;
3076
3077 int quality = settings->value ("img_quality", "-1").toInt();
3078
3079 if (settings->value ("cb_exif_rotate", 1).toBool())
3080 {
3081 int exif_orientation = get_exif_orientation (fname);
3082
3083 QTransform transform;
3084 qreal angle = 0;
3085
3086 if (exif_orientation == 3)
3087 angle = 180;
3088 else
3089 if (exif_orientation == 6)
3090 angle = 90;
3091 else
3092 if (exif_orientation == 8)
3093 angle = 270;
3094
3095 if (angle != 0)
3096 {
3097 transform.rotate (angle);
3098 source = source.transformed (transform);
3099 }
3100 }
3101
3102 QImage dest;
3103
3104 if (scale_by_side && side)
3105 dest = image_scale_by (source, true, side, transformMode);
3106 else
3107 if (percent)
3108 dest = image_scale_by (source, false, percent, transformMode);
3109
3110 QString fmt (settings->value ("output_image_fmt", "jpg").toString());
3111
3112 fnameout = change_file_ext (fnameout, fmt);
3113
3114 if (! dest.save (fnameout, fmt.toLatin1().constData(), quality))
3115 log->log (tr("Cannot save: %1").arg (fnameout));
3116 else
3117 log->log (tr("Saved: %1").arg (fnameout));
3118 }
3119
3120
fn_use_snippet()3121 void CTEA::fn_use_snippet()
3122 {
3123 last_action = sender();
3124
3125 CDocument *d = documents->get_current();
3126 if (! d)
3127 return;
3128
3129 QAction *a = qobject_cast<QAction *>(sender());
3130 QString s = qstring_load (a->data().toString());
3131 if (s.isEmpty())
3132 return;
3133
3134 if (s.contains ("%s"))
3135 s = s.replace ("%s", d->get());
3136
3137 d->put (s);
3138 }
3139
3140
fn_run_script()3141 void CTEA::fn_run_script()
3142 {
3143 last_action = sender();
3144
3145 CDocument *d = documents->get_current();
3146 if (! d)
3147 return;
3148
3149 QAction *a = qobject_cast<QAction *>(sender());
3150
3151 QString fname = a->data().toString();
3152 QString ext = file_get_ext (fname);
3153
3154 if (! d->textCursor().hasSelection())
3155 return;
3156
3157 QString intrp;
3158
3159 if (ext == "rb")
3160 intrp = "ruby";
3161 else
3162 if (ext == "py")
3163 intrp = "python";
3164 else
3165 if (ext == "pl")
3166 intrp = "perl";
3167 else
3168 if (ext == "sh")
3169 intrp = "sh";
3170 else
3171 if (ext == "lua")
3172 intrp = "lua";
3173 else
3174 if (ext == "bat" || ext == "btm" || ext == "cmd")
3175 intrp = "cmd.exe";
3176
3177 if (intrp.isEmpty())
3178 return;
3179
3180 qstring_save (fname_tempfile, d->get());
3181 qstring_save (fname_tempparamfile, fif_get_text());
3182
3183 QString command = QString ("%1 %2 %3 %4").arg (
3184 intrp).arg (
3185 fname).arg (
3186 fname_tempfile).arg (
3187 fname_tempparamfile);
3188
3189 QProcess *process = new QProcess (this);
3190 connect(process, SIGNAL(finished ( int, QProcess::ExitStatus )), this, SLOT(cb_script_finished (int, QProcess::ExitStatus )));
3191
3192 process->start (command, QStringList());
3193 }
3194
3195
cb_script_finished(int exitCode,QProcess::ExitStatus exitStatus)3196 void CTEA::cb_script_finished (int exitCode, QProcess::ExitStatus exitStatus)
3197 {
3198 CDocument *d = documents->get_current();
3199 if (! d)
3200 return;
3201
3202 QString s = qstring_load (fname_tempfile);
3203 if (! s.isEmpty())
3204 d->put(s);
3205
3206 QFile f (fname_tempfile);
3207 f.remove();
3208 f.setFileName (fname_tempparamfile);
3209 f.remove();
3210 }
3211
3212
fn_use_table()3213 void CTEA::fn_use_table()
3214 {
3215 last_action = sender();
3216 QAction *a = qobject_cast<QAction *>(sender());
3217
3218 if (main_tab_widget->currentIndex() == idx_tab_edit)
3219 {
3220 CDocument *d = documents->get_current();
3221 if (! d)
3222 return;
3223
3224 QString text;
3225
3226 if (d->textCursor().hasSelection())
3227 text = d->get();
3228 else
3229 text = d->toPlainText();
3230
3231 if (d->textCursor().hasSelection())
3232 d->put (apply_table (text, a->data().toString(), menu_find_regexp->isChecked()));
3233 else
3234 d->setPlainText (apply_table (text, a->data().toString(), menu_find_regexp->isChecked()));
3235 }
3236 else
3237 if (main_tab_widget->currentIndex() == idx_tab_fman)
3238 {
3239 QStringList sl = fman->get_sel_fnames();
3240
3241 if (sl.size() < 1)
3242 return;
3243
3244 char *charset = cb_fman_codecs->currentText().toLatin1().data();
3245
3246 for (QList <QString>::const_iterator fname = sl.begin(); fname != sl.end(); ++fname)
3247 {
3248 QString f = qstring_load ((*fname), charset);
3249 QString r = apply_table (f, a->data().toString(), menu_find_regexp->isChecked());
3250 qstring_save ((*fname), r, charset);
3251 log->log (tr ("%1 is processed and saved").arg ((*fname)));
3252 }
3253 }
3254 }
3255
3256
fn_insert_loremipsum()3257 void CTEA::fn_insert_loremipsum()
3258 {
3259 last_action = sender();
3260
3261 CDocument *d = documents->get_current();
3262 if (d)
3263 d->put (qstring_load (":/text-data/lorem-ipsum"));
3264 }
3265
3266
fn_insert_template_tea()3267 void CTEA::fn_insert_template_tea()
3268 {
3269 last_action = sender();
3270
3271 CDocument *d = documents->get_current();
3272 if (d)
3273 d->put (qstring_load (":/text-data/template-teaproject"));
3274 }
3275
3276
fn_insert_template_html()3277 void CTEA::fn_insert_template_html()
3278 {
3279 last_action = sender();
3280
3281 CDocument *d = documents->get_current();
3282 if (d)
3283 d->put (qstring_load (":/text-data/template-html"));
3284 }
3285
3286
fn_insert_template_html5()3287 void CTEA::fn_insert_template_html5()
3288 {
3289 last_action = sender();
3290
3291 CDocument *d = documents->get_current();
3292 if (d)
3293 d->put (qstring_load (":/text-data/template-html5"));
3294 }
3295
3296
fn_insert_cpp()3297 void CTEA::fn_insert_cpp()
3298 {
3299 last_action = sender();
3300
3301 CDocument *d = documents->get_current();
3302 if (d)
3303 d->put (qstring_load (":/text-data/tpl_cpp.cpp"));
3304 }
3305
3306
fn_insert_c()3307 void CTEA::fn_insert_c()
3308 {
3309 last_action = sender();
3310
3311 CDocument *d = documents->get_current();
3312 if (d)
3313 d->put (qstring_load (":/text-data/tpl_c.c"));
3314 }
3315
3316
fn_insert_date()3317 void CTEA::fn_insert_date()
3318 {
3319 last_action = sender();
3320
3321 CDocument *d = documents->get_current();
3322 if (d)
3323 d->put (QDate::currentDate ().toString (settings->value("date_format", "dd/MM/yyyy").toString()));
3324 }
3325
3326
fn_insert_time()3327 void CTEA::fn_insert_time()
3328 {
3329 last_action = sender();
3330
3331 CDocument *d = documents->get_current();
3332 if (d)
3333 d->put (QTime::currentTime ().toString (settings->value("time_format", "hh:mm:ss").toString()));
3334 }
3335
3336
fn_case_up()3337 void CTEA::fn_case_up()
3338 {
3339 last_action = sender();
3340
3341 CDocument *d = documents->get_current();
3342 if (d)
3343 d->put (d->get().toUpper());
3344 }
3345
3346
fn_case_down()3347 void CTEA::fn_case_down()
3348 {
3349 last_action = sender();
3350
3351 CDocument *d = documents->get_current();
3352 if (d)
3353 d->put (d->get().toLower());
3354 }
3355
3356
fn_case_cap_sentences()3357 void CTEA::fn_case_cap_sentences()
3358 {
3359 last_action = sender();
3360
3361 CDocument *d = documents->get_current();
3362 if (!d)
3363 return;
3364
3365 QString t = d->toPlainText();
3366
3367 bool cap = false;
3368
3369 for (int i = 0; i < t.size(); i++)
3370 {
3371 QChar c = t.at(i);
3372
3373 if (c.isDigit())
3374 {
3375 cap = false; //probably timecode
3376 continue;
3377 }
3378
3379 if (c == '.' || c == '?' || c == '!')
3380 {
3381 cap = true;
3382 continue;
3383 }
3384
3385 if (t.at(i).isLetter() && cap)
3386 {
3387 t[i] = t.at(i).toUpper();
3388 cap = false;
3389 }
3390 }
3391
3392
3393 d->put (t);
3394 }
3395
3396
3397
fn_sort_casecare()3398 void CTEA::fn_sort_casecare()
3399 {
3400 last_action = sender();
3401
3402 CDocument *d = documents->get_current();
3403 if (d)
3404 d->put (qstringlist_process (d->get(), fif_get_text(), QSTRL_PROC_FLT_WITH_SORTCASECARE));
3405 }
3406
3407
fn_sort_casecareless()3408 void CTEA::fn_sort_casecareless()
3409 {
3410 last_action = sender();
3411
3412 CDocument *d = documents->get_current();
3413 if (d)
3414 d->put (qstringlist_process (d->get(), fif_get_text(), QSTRL_PROC_FLT_WITH_SORTNOCASECARE));
3415 }
3416
3417
fn_sort_casecare_sep()3418 void CTEA::fn_sort_casecare_sep()
3419 {
3420 last_action = sender();
3421
3422 CDocument *d = documents->get_current();
3423 if (d)
3424 d->put (qstringlist_process (d->get(), fif_get_text(), QSTRL_PROC_FLT_WITH_SORTCASECARE_SEP));
3425 }
3426
3427
fn_sort_length()3428 void CTEA::fn_sort_length()
3429 {
3430 last_action = sender();
3431
3432 CDocument *d = documents->get_current();
3433 if (d)
3434 d->put (qstringlist_process (d->get(), fif_get_text(), QSTRL_PROC_FLT_WITH_SORTLEN));
3435 }
3436
3437
fn_flip_a_list()3438 void CTEA::fn_flip_a_list()
3439 {
3440 last_action = sender();
3441
3442 CDocument *d = documents->get_current();
3443 if (d)
3444 d->put (qstringlist_process (d->get(), fif_get_text(), QSTRL_PROC_LIST_FLIP));
3445 }
3446
3447
fn_flip_a_list_sep()3448 void CTEA::fn_flip_a_list_sep()
3449 {
3450 last_action = sender();
3451
3452 CDocument *d = documents->get_current();
3453 if (d)
3454 d->put (qstringlist_process (d->get(), fif_get_text(), QSTRL_PROC_LIST_FLIP_SEP));
3455 }
3456
3457
3458 int latex_table_sort_col;
3459
latex_table_sort_fn(const QStringList & l1,const QStringList & l2)3460 bool latex_table_sort_fn (const QStringList &l1, const QStringList &l2)
3461 {
3462 return l1.at (latex_table_sort_col) < l2.at (latex_table_sort_col);
3463 }
3464
3465
fn_cells_latex_table_sort_by_col_abc()3466 void CTEA::fn_cells_latex_table_sort_by_col_abc()
3467 {
3468 last_action = sender();
3469
3470 CDocument *d = documents->get_current();
3471 if (! d)
3472 return;
3473
3474 QString t = d->get();
3475
3476 if (t.isEmpty())
3477 return;
3478
3479 QStringList fiftxt = fif_get_text().split("~");
3480
3481 if (fiftxt.size() < 2)
3482 return;
3483
3484 QString sep = fiftxt[0];
3485
3486 latex_table_sort_col = fiftxt[1].toInt();
3487
3488 if (t.indexOf (sep) == -1)
3489 return;
3490
3491 QStringList sl_temp = t.split (QChar::ParagraphSeparator);
3492
3493 QList <QStringList> output;
3494
3495 for (QList <QString>::iterator s = sl_temp.begin(); s != sl_temp.end(); ++s)
3496 {
3497 if (! s->isEmpty())
3498 {
3499 QStringList sl_parsed = s->split (sep);
3500 if (latex_table_sort_col + 1 <= sl_parsed.size())
3501 output.append (sl_parsed);
3502 }
3503 }
3504
3505 std::sort (output.begin(), output.end(), latex_table_sort_fn);
3506
3507 sl_temp.clear();
3508
3509 for (int i = 0; i < output.size(); i++)
3510 {
3511 sl_temp.append (output.at(i).join (sep));
3512 }
3513
3514 t = sl_temp.join ("\n");
3515
3516 d->put (t);
3517 }
3518
3519
fn_cells_swap_cells()3520 void CTEA::fn_cells_swap_cells()
3521 {
3522 last_action = sender();
3523
3524 CDocument *d = documents->get_current();
3525 if (! d)
3526 return;
3527
3528 QStringList fiftxt = fif_get_text().split("~");
3529
3530 if (fiftxt.size() < 3)
3531 return;
3532
3533 int col1 = fiftxt[1].toInt();
3534 int col2 = fiftxt[2].toInt();
3535
3536 QString sep = fiftxt[0];
3537
3538 QString t = d->get();
3539
3540 if (t.isEmpty())
3541 return;
3542
3543 if (t.indexOf (sep) == -1)
3544 return;
3545
3546 int imax = int (fmax (col1, col2));
3547
3548 QStringList sl_temp = t.split (QChar::ParagraphSeparator);
3549
3550 QList <QStringList> output;
3551
3552 for (QList <QString>::iterator v = sl_temp.begin(); v != sl_temp.end(); ++v)
3553 {
3554 if (! v->isEmpty())
3555 {
3556 QStringList sl_parsed = v->split (sep);
3557 if (imax + 1 <= sl_parsed.size())
3558 {
3559 strlist_swap (sl_parsed, col1, col2);
3560 output.append (sl_parsed);
3561 }
3562 }
3563 }
3564
3565 sl_temp.clear();
3566
3567 for (int i = 0; i < output.size(); i++)
3568 sl_temp.append (output.at(i).join (sep));
3569
3570 t = sl_temp.join ("\n");
3571
3572 d->put (t);
3573 }
3574
3575
fn_cells_delete_by_col()3576 void CTEA::fn_cells_delete_by_col()
3577 {
3578 last_action = sender();
3579
3580 CDocument *d = documents->get_current();
3581 if (! d)
3582 return;
3583
3584 QStringList fiftxt = fif_get_text().split("~");
3585
3586 if (fiftxt.size() < 2)
3587 return;
3588
3589 int col1 = fiftxt[1].toInt();
3590
3591 QString sep = fiftxt[0];
3592
3593 QString t = d->get();
3594
3595 if (t.isEmpty())
3596 return;
3597
3598 if (t.indexOf (sep) == -1)
3599 return;
3600
3601 QStringList sl_temp = t.split (QChar::ParagraphSeparator);
3602
3603 QList <QStringList> output;
3604
3605 for (QList <QString>::iterator v = sl_temp.begin(); v != sl_temp.end(); ++v)
3606 {
3607 if (! v->isEmpty())
3608 {
3609 QStringList sl_parsed = v->split (sep);
3610 if (col1 + 1 <= sl_parsed.size())
3611 {
3612 sl_parsed.removeAt (col1);
3613 output.append (sl_parsed);
3614 }
3615 }
3616 }
3617
3618 sl_temp.clear();
3619
3620 for (int i = 0; i < output.size(); i++)
3621 sl_temp.append (output.at(i).join (sep));
3622
3623 t = sl_temp.join ("\n");
3624
3625 d->put (t);
3626 }
3627
3628
fn_cells_copy_by_col()3629 void CTEA::fn_cells_copy_by_col()
3630 {
3631 last_action = sender();
3632
3633 CDocument *d = documents->get_current();
3634 if (! d)
3635 return;
3636
3637 QStringList fiftxt = fif_get_text().split("~");
3638
3639 if (fiftxt.size() < 2)
3640 return;
3641
3642 QString sep = fiftxt[0];
3643
3644 int col1 = fiftxt[1].toInt();
3645 int col2 = 0;
3646
3647 if (fiftxt.size() == 3)
3648 col2 = fiftxt[2].toInt();
3649
3650 QString t = d->get();
3651
3652 if (t.isEmpty())
3653 return;
3654
3655 if (t.indexOf (sep) == -1)
3656 return;
3657
3658 QStringList sl_temp = t.split (QChar::ParagraphSeparator);
3659
3660 QList <QStringList> output;
3661
3662 if (col2 > 0)
3663 for (QList <QString>::iterator v = sl_temp.begin(); v != sl_temp.end(); ++v)
3664 {
3665 if (! v->isEmpty())
3666 {
3667 QStringList sl_parsed = v->split (sep);
3668 if (col2 + 1 <= sl_parsed.size())
3669 {
3670 QStringList tl = sl_parsed.mid (col1, col2 - col1 + 1);
3671 output.append (tl);
3672 }
3673 }
3674 }
3675 else
3676 for (QList <QString>::iterator v = sl_temp.begin(); v != sl_temp.end(); ++v)
3677 {
3678 if (! v->isEmpty())
3679 {
3680 QStringList sl_parsed = v->split (sep);
3681 if (col1 + 1 <= sl_parsed.size())
3682 {
3683 QStringList tl = sl_parsed.mid (col1, 1);
3684 output.append (tl);
3685 }
3686 }
3687 }
3688
3689 sl_temp.clear();
3690
3691 for (int i = 0; i < output.size(); i++)
3692 sl_temp.append (output.at(i).join (sep));
3693
3694 t = sl_temp.join ("\n");
3695
3696 QApplication::clipboard()->setText (t);
3697 }
3698
3699
fn_filter_rm_duplicates()3700 void CTEA::fn_filter_rm_duplicates()
3701 {
3702 last_action = sender();
3703
3704 CDocument *d = documents->get_current();
3705 if (d)
3706 d->put (qstringlist_process (d->get(), fif_get_text(), QSTRL_PROC_FLT_REMOVE_DUPS));
3707 }
3708
3709
fn_filter_rm_empty()3710 void CTEA::fn_filter_rm_empty()
3711 {
3712 last_action = sender();
3713
3714 CDocument *d = documents->get_current();
3715 if (d)
3716 d->put (qstringlist_process (d->get(), fif_get_text(), QSTRL_PROC_FLT_REMOVE_EMPTY));
3717 }
3718
3719
fn_filter_rm_less_than()3720 void CTEA::fn_filter_rm_less_than()
3721 {
3722 last_action = sender();
3723
3724 CDocument *d = documents->get_current();
3725 if (d)
3726 d->put (qstringlist_process (d->get(), fif_get_text(), QSTRL_PROC_FLT_LESS));
3727 }
3728
3729
fn_filter_rm_greater_than()3730 void CTEA::fn_filter_rm_greater_than()
3731 {
3732 last_action = sender();
3733
3734 CDocument *d = documents->get_current();
3735 if (d)
3736 d->put (qstringlist_process (d->get(), fif_get_text(), QSTRL_PROC_FLT_GREATER));
3737 }
3738
3739
fn_filter_delete_before_sep()3740 void CTEA::fn_filter_delete_before_sep()
3741 {
3742 last_action = sender();
3743 fn_filter_delete_by_sep (true);
3744 }
3745
3746
fn_filter_delete_after_sep()3747 void CTEA::fn_filter_delete_after_sep()
3748 {
3749 last_action = sender();
3750 fn_filter_delete_by_sep (false);
3751 }
3752
3753
fn_filter_with_regexp()3754 void CTEA::fn_filter_with_regexp()
3755 {
3756 last_action = sender();
3757
3758 CDocument *d = documents->get_current();
3759 if (d)
3760 d->put (qstringlist_process (d->get(), fif_get_text(), QSTRL_PROC_FLT_WITH_REGEXP));
3761 }
3762
3763
fn_filter_by_repetitions()3764 void CTEA::fn_filter_by_repetitions()
3765 {
3766 last_action = sender();
3767
3768 CDocument *d = documents->get_current();
3769 if (! d)
3770 return;
3771
3772 QString result;
3773
3774 QString pattern = fif_get_text();
3775
3776 vector <int> positions;
3777
3778 for (int i = 0; i < pattern.size(); ++i)
3779 {
3780 if (pattern[i] == '1')
3781 positions.push_back (i);
3782 }
3783
3784 QStringList words = d->get().split (QChar::ParagraphSeparator);
3785
3786 for (int i = 0; i < words.size(); ++i)
3787 {
3788 QString wrd = words[i];
3789
3790 if (pattern.size() > wrd.size())
3791 continue;
3792
3793 QChar ch = wrd [positions[0]];
3794
3795 size_t count = 0;
3796
3797 for (size_t j = 0; j < positions.size(); ++j)
3798 {
3799 if (wrd[positions[j]] == ch)
3800 count++;
3801 }
3802
3803 if (count == positions.size())
3804 {
3805 result += wrd;
3806 result += "\n";
3807 }
3808 }
3809
3810 if (! result.isEmpty())
3811 d->put (result);
3812 }
3813
3814
fn_math_evaluate()3815 void CTEA::fn_math_evaluate()
3816 {
3817 last_action = sender();
3818
3819 CDocument *d = documents->get_current();
3820 if (! d)
3821 return;
3822
3823 QString s = d->get();
3824 std::string utf8_text = s.toUtf8().constData();
3825 double f = calculate (utf8_text);
3826 QString fs = s.setNum (f);
3827
3828 log->log (fs);
3829 }
3830
3831
fn_math_number_arabic_to_roman()3832 void CTEA::fn_math_number_arabic_to_roman()
3833 {
3834 last_action = sender();
3835
3836 CDocument *d = documents->get_current();
3837 if (d)
3838 d->put (arabicToRoman (d->get().toUInt()));
3839 }
3840
3841
fn_math_number_roman_to_arabic()3842 void CTEA::fn_math_number_roman_to_arabic()
3843 {
3844 last_action = sender();
3845
3846 CDocument *d = documents->get_current();
3847 if (d)
3848 d->put (QString::number(get_arab_num (d->get().toUpper().toStdString())));
3849 }
3850
3851
fn_math_number_dec_to_bin()3852 void CTEA::fn_math_number_dec_to_bin()
3853 {
3854 last_action = sender();
3855
3856 CDocument *d = documents->get_current();
3857 if (d)
3858 d->put (int_to_binary (d->get().toInt()));
3859 }
3860
3861
fn_math_number_bin_to_dec()3862 void CTEA::fn_math_number_bin_to_dec()
3863 {
3864 last_action = sender();
3865
3866 CDocument *d = documents->get_current();
3867 if (d)
3868 d->put (QString::number (bin_to_decimal (d->get())));
3869 }
3870
3871
fn_math_number_flip_bits()3872 void CTEA::fn_math_number_flip_bits()
3873 {
3874 last_action = sender();
3875
3876 CDocument *d = documents->get_current();
3877 if (!d)
3878 return;
3879
3880 QString s = d->get();
3881 for (int i = 0; i < s.size(); i++)
3882 {
3883 if (s[i] == '1')
3884 s[i] = '0';
3885 else
3886 if (s[i] == '0')
3887 s[i] = '1';
3888 }
3889
3890 d->put (s);
3891 }
3892
3893
fn_math_sum_by_last_col()3894 void CTEA::fn_math_sum_by_last_col()
3895 {
3896 last_action = sender();
3897
3898 CDocument *d = documents->get_current();
3899 if (! d)
3900 return;
3901
3902 QString t = d->get();
3903
3904 if (t.isEmpty())
3905 return;
3906
3907 t = t.replace (",", ".");
3908
3909 double sum = 0.0;
3910
3911 QStringList l = t.split (QChar::ParagraphSeparator);
3912
3913 for (int i = 0; i < l.size(); i++)
3914 {
3915 if (l[i].isNull())
3916 continue;
3917
3918 if (l[i].startsWith ("//") || l[i].startsWith ("#") || l[i].startsWith (";"))
3919 continue;
3920
3921 QStringList lt = l[i].split (" ");
3922 if (lt.size() > 0)
3923 {
3924 QString s = lt.at (lt.size() - 1);
3925 if (! s.isNull())
3926 {
3927 std::string utf8_text = s.toUtf8().constData();
3928 double f = calculate (utf8_text);
3929 sum += f;
3930 }
3931 }
3932 }
3933
3934 log->log (tr ("sum: %1").arg (sum));
3935 }
3936
3937
3938
fn_math_enum()3939 void CTEA::fn_math_enum()
3940 {
3941 last_action = sender();
3942
3943 CDocument *d = documents->get_current();
3944 if (! d)
3945 return;
3946
3947 QStringList source = d->get().split (QChar::ParagraphSeparator);
3948
3949 int pad = 0;
3950 int end = source.size() - 1;
3951 int step = 1;
3952 QString result;
3953 QString prefix;
3954
3955 QStringList params = fif_get_text().split ("~");
3956
3957 if (params.size() > 0)
3958 step = params[0].toInt();
3959
3960 if (params.size() > 1)
3961 pad = params[1].toInt();
3962
3963 if (params.size() > 2)
3964 prefix = params[2];
3965
3966 if (step == 0)
3967 step = 1;
3968
3969 for (int c = 0; c <= end; c++)
3970 {
3971 QString n;
3972 n = n.setNum (((c + 1) * step));
3973 if (pad != 0)
3974 n = n.rightJustified (pad, '0');
3975
3976 result = result + n + prefix + source.at(c) + '\n';
3977 }
3978
3979 d->put (result);
3980 }
3981
3982
3983 //UTF-16BE, UTF-32BE
3984 //′
3985 //#define UQS 8242
3986 //″
3987 //#define UQD 8243
3988 //°
3989 //#define UQDG 176
3990
3991 //degrees minutes seconds: 40° 26′ 46″ N 79° 58′ 56″ W
3992 //to
3993 //decimal degrees: 40.446° N 79.982° W
fn_math_number_dms2dc()3994 void CTEA::fn_math_number_dms2dc()
3995 {
3996 last_action = sender();
3997
3998 CDocument *d = documents->get_current();
3999 if (! d)
4000 return;
4001
4002 QString t = d->get();
4003 t = t.remove (" ");
4004
4005 t = t.replace ('\'', QChar (UQS));
4006 t = t.replace ('"', QChar (UQD));
4007
4008 QChar north_or_south = ('N');
4009 if (t.contains ('S'))
4010 north_or_south = 'S';
4011
4012 QChar east_or_west = ('E');
4013 if (t.contains ('W'))
4014 east_or_west = 'W';
4015
4016 QStringList l = t.split (north_or_south);
4017
4018 QString latitude = l[0];
4019 QString longtitude = l[1];
4020
4021 // qDebug() << "latitude " << latitude;
4022 // qDebug() << "longtitude " << longtitude;
4023
4024 int iqdg = latitude.indexOf (QChar (UQDG));
4025 int iqs = latitude.indexOf (QChar (UQS));
4026 int iqd = latitude.indexOf (QChar (UQD));
4027
4028 QString degrees1 = latitude.left (iqdg);
4029 QString minutes1 = latitude.mid (iqdg + 1, iqs - iqdg - 1);
4030 QString seconds1 = latitude.mid (iqs + 1, iqd - iqs - 1);
4031
4032 double lat_decimal_degrees = degrees1.toDouble() + (double) (minutes1.toDouble() / 60) + (double) (seconds1.toDouble() / 3600);
4033 QString lat_decimal_degrees_N = QString::number (lat_decimal_degrees, 'f', 3) + QChar (UQDG) + north_or_south;
4034
4035 iqdg = longtitude.indexOf (QChar (UQDG));
4036 iqs = longtitude.indexOf (QChar (UQS));
4037 iqd = longtitude.indexOf (QChar (UQD));
4038
4039 degrees1 = longtitude.left (iqdg);
4040 minutes1 = longtitude.mid (iqdg + 1, iqs - iqdg - 1);
4041 seconds1 = longtitude.mid (iqs + 1, iqd - iqs - 1);
4042
4043 double longt_decimal_degrees = degrees1.toDouble() + (double) (minutes1.toDouble() / 60) + (double) (seconds1.toDouble() / 3600);
4044
4045 QString longt_decimal_degrees_N = QString::number (longt_decimal_degrees, 'f', 3) + QChar (UQDG) + east_or_west;
4046
4047 log->log (lat_decimal_degrees_N + " " + longt_decimal_degrees_N);
4048 // qDebug() << "decimal_degrees " << decimal_degrees;
4049 // qDebug() << "decimal_degrees_N " << decimal_degrees_N;
4050 }
4051
4052 /*
4053 degrees = floor (decimal_degrees)
4054 minutes = floor (60 * (decimal_degrees - degrees))
4055 seconds = 3600 * (decimal_degrees - degrees) - 60 * minites
4056
4057 */
4058
4059 //decimal degrees: 40.446° N 79.982° W
4060 //to
4061 //degrees minutes seconds: 40° 26′ 46″ N 79° 58′ 56″ W
4062
fn_math_number_dd2dms()4063 void CTEA::fn_math_number_dd2dms()
4064 {
4065 last_action = sender();
4066
4067 CDocument *d = documents->get_current();
4068 if (! d)
4069 return;
4070
4071 QString t = d->get();
4072 t = t.remove (" ");
4073 t = t.remove (QChar (UQDG));
4074
4075 QChar north_or_south = ('N');
4076 if (t.contains ('S'))
4077 north_or_south = 'S';
4078
4079 QChar east_or_west = ('E');
4080 if (t.contains ('W'))
4081 east_or_west = 'W';
4082
4083 QStringList l = t.split (north_or_south);
4084
4085 QString latitude = l[0];
4086
4087 #if QT_VERSION < 0x050000
4088 QString longtitude = l[1].remove (QRegExp("[a-zA-Z\\s]"));
4089 #else
4090 QString longtitude = l[1].remove (QRegularExpression("[a-zA-Z\\s]"));
4091 #endif
4092
4093 double degrees = floor (latitude.toDouble());
4094 double minutes = floor (60 * (latitude.toDouble() - degrees));
4095 double seconds = round (3600 * (latitude.toDouble() - degrees) - 60 * minutes);
4096
4097 double degrees2 = floor (longtitude.toDouble());
4098 double minutes2 = floor (60 * (longtitude.toDouble() - degrees2));
4099 double seconds2 = round (3600 * (longtitude.toDouble() - degrees2) - 60 * minutes2);
4100
4101
4102 QString result = QString::number (degrees) + QChar (UQDG) + QString::number (minutes) + QChar (UQS) +
4103 QString::number (seconds) + QChar (UQD) +
4104 north_or_south + " " +
4105 QString::number (degrees2) + QChar (UQDG) + QString::number (minutes2)
4106 + QChar (UQS) + QString::number (seconds2) + QChar (UQD) +
4107 east_or_west;
4108
4109 log->log (result);
4110 }
4111
4112
fn_morse_from_ru()4113 void CTEA::fn_morse_from_ru()
4114 {
4115 last_action = sender();
4116
4117 CDocument *d = documents->get_current();
4118 if (d)
4119 d->put (morse_from_lang (d->get().toUpper(), "ru"));
4120 }
4121
4122
fn_morse_to_ru()4123 void CTEA::fn_morse_to_ru()
4124 {
4125 last_action = sender();
4126
4127 CDocument *d = documents->get_current();
4128 if (d)
4129 d->put (morse_to_lang (d->get(), "ru"));
4130 }
4131
4132
fn_morse_from_en()4133 void CTEA::fn_morse_from_en()
4134 {
4135 last_action = sender();
4136
4137 CDocument *d = documents->get_current();
4138 if (d)
4139 d->put (morse_from_lang (d->get().toUpper(), "en"));
4140 }
4141
4142
fn_morse_to_en()4143 void CTEA::fn_morse_to_en()
4144 {
4145 last_action = sender();
4146
4147 CDocument *d = documents->get_current();
4148 if (d)
4149 d->put (morse_to_lang (d->get(), "en"));
4150 }
4151
4152
fn_analyze_text_stat()4153 void CTEA::fn_analyze_text_stat()
4154 {
4155 last_action = sender();
4156
4157 CDocument *d = documents->get_current();
4158 if (! d)
4159 return;
4160
4161 bool b_sel = d->textCursor().hasSelection();
4162
4163 QString s;
4164
4165 if (b_sel)
4166 s = d->get();
4167 else
4168 s = d->toPlainText();
4169
4170 int c = s.length();
4171 int purechars = 0;
4172 int lines = 1;
4173
4174 for (int i = 0; i < c; ++ i)
4175 {
4176 QChar ch = s.at (i);
4177
4178 if (ch.isLetterOrNumber() || ch.isPunct())
4179 purechars++;
4180
4181 if (! b_sel)
4182 {
4183 if (ch == '\n')
4184 lines++;
4185 }
4186 else
4187 if (ch == QChar::ParagraphSeparator)
4188 lines++;
4189 }
4190
4191
4192 QString result = tr ("chars: %1<br>chars without spaces: %2<br>lines: %3<br>author's sheets: %4")
4193 .arg (QString::number (c))
4194 .arg (QString::number (purechars))
4195 .arg (QString::number (lines))
4196 .arg (QString::number (c / 40000));
4197
4198 log->log (result);
4199 }
4200
4201
fn_analyze_extract_words()4202 void CTEA::fn_analyze_extract_words()
4203 {
4204 last_action = sender();
4205
4206 CDocument *d = documents->get_current();
4207 if (! d)
4208 return;
4209
4210 QStringList w = d->get_words();
4211
4212 CDocument *nd = documents->create_new();
4213 if (nd)
4214 nd->put (w.join("\n"));
4215 }
4216
4217
fn_analyze_stat_words_lengths()4218 void CTEA::fn_analyze_stat_words_lengths()
4219 {
4220 last_action = sender();
4221
4222 CDocument *d = documents->get_current();
4223 if (! d)
4224 return;
4225
4226 unsigned long lengths[33] = { };
4227
4228 QStringList w = d->get_words();
4229
4230 for (int i =0; i < w.size(); i++)
4231 {
4232 int len = w.at(i).length();
4233 if (len <= 32)
4234 lengths[len]++;
4235 }
4236
4237 QStringList l;
4238
4239 QString col1 = tr ("Word length: ");
4240 QString col2 = tr ("Number:");
4241
4242 l.append (col1 + col2);
4243
4244 for (int i = 1; i <= 32; i++)
4245 {
4246 QString s = QString::number (i) + col1.fill ('_', col1.length()) + QString::number (lengths[i]);
4247 l.append (s);
4248 }
4249
4250 CDocument *nd = documents->create_new();
4251 if (nd)
4252 nd->put (l.join("\n"));
4253 }
4254
4255
fn_analyze_count()4256 void CTEA::fn_analyze_count()
4257 {
4258 last_action = sender();
4259 count_substring (false);
4260 }
4261
4262
fn_analyze_count_rx()4263 void CTEA::fn_analyze_count_rx()
4264 {
4265 last_action = sender();
4266 count_substring (true);
4267 }
4268
4269
pr_bigger_than(const pair<const QString &,int> & a,const pair<const QString &,int> & b)4270 bool pr_bigger_than (const pair<const QString &,int> &a,
4271 const pair<const QString &,int> &b)
4272 {
4273 return (a.second > b.second);
4274 }
4275
4276
pr_bigger_than_str(const pair<const QString &,int> & a,const pair<const QString &,int> & b)4277 bool pr_bigger_than_str (const pair<const QString &,int> &a,
4278 const pair<const QString &,int> &b)
4279 {
4280 return (a.first < b.first);
4281 }
4282
4283
pr_bigger_than_str_len(const pair<const QString &,int> & a,const pair<const QString &,int> & b)4284 bool pr_bigger_than_str_len (const pair<const QString &,int> &a,
4285 const pair<const QString &,int> &b)
4286 {
4287 return (a.first.size() < b.first.size());
4288 }
4289
4290
fn_analyze_get_words_count()4291 void CTEA::fn_analyze_get_words_count()
4292 {
4293 last_action = sender();
4294 run_unitaz (0);
4295 }
4296
4297
fn_analyze_unitaz_abc()4298 void CTEA::fn_analyze_unitaz_abc()
4299 {
4300 last_action = sender();
4301 run_unitaz (1);
4302 }
4303
4304
fn_analyze_unitaz_len()4305 void CTEA::fn_analyze_unitaz_len()
4306 {
4307 last_action = sender();
4308 run_unitaz (2);
4309 }
4310
4311
fn_text_apply_to_each_line()4312 void CTEA::fn_text_apply_to_each_line()
4313 {
4314 last_action = sender();
4315
4316 CDocument *d = documents->get_current();
4317 if (! d)
4318 return;
4319
4320 QStringList sl = d->get().split (QChar::ParagraphSeparator);
4321 QString t = fif_get_text();
4322
4323 if (t.isEmpty())
4324 return;
4325
4326 if (t.startsWith ("@@"))
4327 {
4328 QString fname = dir_snippets + QDir::separator() + t;
4329
4330 if (! file_exists (fname))
4331 {
4332 log->log (tr ("snippet %1 is not exists").arg (fname));
4333 return;
4334 }
4335
4336 t = t.remove (0, 2);
4337 t = qstring_load (fname);
4338 }
4339
4340 for (QList <QString>::iterator i = sl.begin(); i != sl.end(); ++i)
4341 {
4342 QString ts (t);
4343 (*i) = ts.replace ("%s", (*i));
4344 }
4345
4346 QString x = sl.join ("\n");
4347
4348 d->put (x);
4349 }
4350
4351
fn_text_reverse()4352 void CTEA::fn_text_reverse()
4353 {
4354 last_action = sender();
4355 CDocument *d = documents->get_current();
4356 if (! d)
4357 return;
4358
4359 QString s = d->get();
4360
4361 if (! s.isEmpty())
4362 d->put (string_reverse (s));
4363 }
4364
4365
fn_text_escape()4366 void CTEA::fn_text_escape()
4367 {
4368 last_action = sender();
4369
4370 CDocument *d = documents->get_current();
4371
4372 #if (QT_VERSION_MAJOR < 5)
4373 if (d)
4374 d->put (QRegExp::escape (d->get()));
4375 #else
4376 if (d)
4377 d->put (QRegularExpression::escape (d->get()));
4378 #endif
4379 }
4380
fn_text_remove_formatting()4381 void CTEA::fn_text_remove_formatting()
4382 {
4383 last_action = sender();
4384
4385 CDocument *d = documents->get_current();
4386 if (d)
4387 d->put (d->get().simplified());
4388 }
4389
4390
fn_text_compress()4391 void CTEA::fn_text_compress()
4392 {
4393 last_action = sender();
4394
4395 CDocument *d = documents->get_current();
4396 if (! d)
4397 return;
4398
4399 QString s = d->get();
4400
4401 s = s.remove ('\n');
4402 s = s.remove ('\t');
4403 s = s.remove (' ');
4404 s = s.remove (QChar::ParagraphSeparator);
4405 d->put (s);
4406 }
4407
4408
fn_text_compare_two_strings()4409 void CTEA::fn_text_compare_two_strings()
4410 {
4411 last_action = sender();
4412
4413 QStringList l = fif_get_text().split ("~");
4414 if (l.size() < 2)
4415 return;
4416
4417 if (l[0].size() < l[1].size())
4418 return;
4419
4420 QString s;
4421
4422 for (int i = 0; i < l[0].size(); i++)
4423 {
4424 if (l[0][i] == l[1][i])
4425 s = QString::number (i + 1) + ": " + l[0][i] + " == " + l[1][i];
4426 else
4427 s = QString::number (i + 1) + ": " + l[0][i] + " != " + l[1][i];
4428
4429 log->log (s);
4430 }
4431 }
4432
4433
fn_text_remove_formatting_at_each_line()4434 void CTEA::fn_text_remove_formatting_at_each_line()
4435 {
4436 last_action = sender();
4437
4438 CDocument *d = documents->get_current();
4439 if (d)
4440 d->put (qstringlist_process (d->get(), "", QSTRL_PROC_REMOVE_FORMATTING));
4441 }
4442
4443
fn_text_remove_trailing_spaces()4444 void CTEA::fn_text_remove_trailing_spaces()
4445 {
4446 last_action = sender();
4447
4448 CDocument *d = documents->get_current();
4449 if (! d)
4450 return;
4451
4452 QStringList sl = d->get().split (QChar::ParagraphSeparator);
4453
4454 for (QList <QString>::iterator s = sl.begin(); s != sl.end(); ++s)
4455 {
4456 if (s->isEmpty())
4457 continue;
4458
4459 if (s->at (s->size() - 1).isSpace())
4460 {
4461 int index = s->size() - 1;
4462 while (s->at (--index).isSpace())
4463 ;
4464
4465 s->truncate (index + 1);
4466 }
4467 }
4468
4469 QString x = sl.join ("\n");
4470
4471 d->put (x);
4472 }
4473
4474
fn_text_anagram()4475 void CTEA::fn_text_anagram()
4476 {
4477 last_action = sender();
4478
4479 CDocument *d = documents->get_current();
4480 if (! d)
4481 return;
4482
4483 QString t = d->get();
4484 if (t.isEmpty())
4485 return;
4486
4487 QString txt = anagram (t).join("\n");
4488
4489 d = documents->create_new();
4490 if (d)
4491 d->put (txt);
4492 }
4493
4494
fn_text_regexp_match_check()4495 void CTEA::fn_text_regexp_match_check()
4496 {
4497 last_action = sender();
4498
4499 CDocument *d = documents->get_current();
4500 if (! d)
4501 return;
4502
4503 QString t = d->get();
4504 if (t.isEmpty())
4505 return;
4506
4507 QString fiftxt = fif_get_text();
4508
4509 #if QT_VERSION >= 0x050000
4510 QRegularExpression r (fiftxt);
4511 QRegularExpressionMatch match = r.match(t);
4512 if (match.hasMatch())
4513 log->log (tr ("matched"));
4514 else
4515 log->log (tr ("does not"));
4516
4517 #else
4518 QRegExp r (fiftxt);
4519 if (r.exactMatch(t))
4520 log->log (tr ("matched"));
4521 else
4522 log->log (tr ("does not"));
4523
4524 #endif
4525 }
4526
4527
fn_quotes_to_angle()4528 void CTEA::fn_quotes_to_angle()
4529 {
4530 last_action = sender();
4531
4532 CDocument *d = documents->get_current();
4533 if (! d)
4534 return;
4535
4536 QString source = d->get();
4537 if (! source.isEmpty())
4538 d->put (conv_quotes (source, "\u00AB", "\u00BB"));
4539 }
4540
4541
fn_quotes_curly()4542 void CTEA::fn_quotes_curly()
4543 {
4544 last_action = sender();
4545
4546 CDocument *d = documents->get_current();
4547 if (! d)
4548 return;
4549
4550 QString source = d->get();
4551 if (! source.isEmpty())
4552 d->put (conv_quotes (source, "\u201C", "\u201D"));
4553 }
4554
4555
fn_quotes_tex_curly()4556 void CTEA::fn_quotes_tex_curly()
4557 {
4558 last_action = sender();
4559
4560 CDocument *d = documents->get_current();
4561 if (! d)
4562 return;
4563
4564 QString source = d->get();
4565 if (! source.isEmpty())
4566 d->put (conv_quotes (source, "``", "\'\'"));
4567 }
4568
4569
fn_quotes_tex_angle_01()4570 void CTEA::fn_quotes_tex_angle_01()
4571 {
4572 last_action = sender();
4573
4574 CDocument *d = documents->get_current();
4575 if (! d)
4576 return;
4577
4578 QString source = d->get();
4579 if (! source.isEmpty())
4580 d->put (conv_quotes (source, "<<", ">>"));
4581 }
4582
4583
fn_quotes_tex_angle_02()4584 void CTEA::fn_quotes_tex_angle_02()
4585 {
4586 last_action = sender();
4587
4588 CDocument *d = documents->get_current();
4589 if (! d)
4590 return;
4591
4592 QString source = d->get();
4593 if (! source.isEmpty())
4594 d->put (conv_quotes (source, "\\glqq", "\\grqq"));
4595 }
4596
4597
4598 #if defined (HUNSPELL_ENABLE) || defined (ASPELL_ENABLE)
4599
fn_change_spell_lang()4600 void CTEA::fn_change_spell_lang()
4601 {
4602 last_action = sender();
4603
4604 QAction *a = qobject_cast<QAction *>(sender());
4605 settings->setValue ("spell_lang", a->text());
4606 spellchecker->change_lang (a->text());
4607 spellchecker->load_dict();
4608
4609 fn_spell_check();
4610 }
4611
4612
ends_with_badchar(const QString & s)4613 bool ends_with_badchar (const QString &s)
4614 {
4615 if (s.endsWith ("\""))
4616 return true;
4617
4618 if (s.endsWith ("»"))
4619 return true;
4620
4621 if (s.endsWith ("\\"))
4622 return true;
4623
4624 return false;
4625 }
4626
4627
fn_spell_check()4628 void CTEA::fn_spell_check()
4629 {
4630 last_action = sender();
4631
4632 CDocument *d = documents->get_current();
4633 if (! d)
4634 return;
4635
4636 QColor color_error = QColor (hash_get_val (global_palette, "error", "red"));
4637
4638 QElapsedTimer time_start;
4639 time_start.start();
4640
4641 pb_status->show();
4642 pb_status->setRange (0, d->toPlainText().size() - 1);
4643 pb_status->setFormat (tr ("%p% completed"));
4644 pb_status->setTextVisible (true);
4645
4646 int i = 0;
4647
4648 QTextCursor cr = d->textCursor();
4649
4650 int pos = cr.position();
4651 int savepos = pos;
4652
4653 QString text = d->toPlainText();
4654 int text_size = text.size();
4655
4656 //delete all underlines
4657 cr.setPosition (0);
4658 cr.movePosition (QTextCursor::End, QTextCursor::KeepAnchor);
4659 QTextCharFormat f = cr.blockCharFormat();
4660 f.setFontUnderline (false);
4661 cr.mergeCharFormat (f);
4662
4663 cr.setPosition (0);
4664 cr.movePosition (QTextCursor::Start, QTextCursor::MoveAnchor);
4665
4666 do
4667 {
4668 pos = cr.position();
4669 if (pos >= text_size)
4670 break;
4671
4672 QChar c = text.at (pos);
4673
4674 if (char_is_bad (c))
4675 while (char_is_bad (c))
4676 {
4677 cr.movePosition (QTextCursor::NextCharacter);
4678
4679 pos = cr.position();
4680
4681 if (pos < text_size)
4682 c = text.at (pos);
4683 else
4684 break;
4685 }
4686
4687 cr.movePosition (QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
4688
4689 QString stext = cr.selectedText();
4690 if (! stext.isEmpty() && ends_with_badchar (stext)) //extend selection
4691 {
4692 cr.movePosition (QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);
4693 stext = cr.selectedText();
4694 }
4695
4696 if (! stext.isEmpty())
4697 if (! spellchecker->check (stext))
4698 {
4699 f = cr.blockCharFormat();
4700 f.setUnderlineStyle (QTextCharFormat::SpellCheckUnderline);
4701 f.setUnderlineColor (color_error);
4702 cr.mergeCharFormat (f);
4703 }
4704
4705 i++;
4706
4707 if (i % 512 == 0)
4708 pb_status->setValue (i);
4709 }
4710 while (cr.movePosition (QTextCursor::NextWord));
4711
4712 cr.setPosition (savepos);
4713 d->document()->setModified (false);
4714
4715 pb_status->hide();
4716
4717 log->log (tr("elapsed milliseconds: %1").arg (time_start.elapsed()));
4718 }
4719
4720
fn_spell_add_to_dict()4721 void CTEA::fn_spell_add_to_dict()
4722 {
4723 last_action = sender();
4724
4725 CDocument *d = documents->get_current();
4726 if (! d)
4727 return;
4728
4729 QTextCursor cr = d->textCursor();
4730 cr.select (QTextCursor::WordUnderCursor); //плохо работает
4731 spellchecker->add_to_user_dict (cr.selectedText());
4732 }
4733
4734
fn_spell_remove_from_dict()4735 void CTEA::fn_spell_remove_from_dict()
4736 {
4737 last_action = qobject_cast<QAction *>(sender());
4738
4739 CDocument *d = documents->get_current();
4740 if (! d)
4741 return;
4742
4743 QTextCursor cr = d->textCursor();
4744 cr.select (QTextCursor::WordUnderCursor);
4745 spellchecker->remove_from_user_dict (cr.selectedText());
4746 }
4747
4748
fn_spell_suggest_callback()4749 void CTEA::fn_spell_suggest_callback()
4750 {
4751 last_action = sender();
4752
4753 CDocument *d = documents->get_current();
4754 if (! d)
4755 return;
4756
4757 QAction *act = qobject_cast<QAction *>(sender());
4758 QString new_text = act->text();
4759
4760 QTextCursor cr = d->textCursor();
4761
4762 cr.select (QTextCursor::WordUnderCursor);
4763 QString s = cr.selectedText();
4764 if (s.isEmpty())
4765 return;
4766
4767 if (s[0].isUpper())
4768 new_text[0] = new_text[0].toUpper();
4769
4770 cr.insertText (new_text);
4771 d->setTextCursor (cr);
4772 }
4773
4774
fn_spell_suggest()4775 void CTEA::fn_spell_suggest()
4776 {
4777 last_action = sender();
4778
4779 CDocument *d = documents->get_current();
4780 if (! d)
4781 return;
4782
4783 QTextCursor cr = d->textCursor();
4784 cr.select (QTextCursor::WordUnderCursor);
4785 QString s = cr.selectedText();
4786 if (s.isEmpty())
4787 return;
4788
4789 QStringList l = spellchecker->get_suggestions_list (s);
4790
4791 QMenu *m = new QMenu (this);
4792 create_menu_from_list (this, m, l, SLOT (fn_spell_suggest_callback()));
4793 m->popup (mapToGlobal (d->cursorRect().topLeft()));
4794 }
4795
4796 #endif
4797
4798
4799 /*
4800 ====================
4801 Cal menu
4802 ===================
4803 */
4804
calendar_update()4805 void CTEA::calendar_update()
4806 {
4807 if (settings->value ("start_week_on_sunday", "0").toBool())
4808 calendar->setFirstDayOfWeek (Qt::Sunday);
4809 else
4810 calendar->setFirstDayOfWeek (Qt::Monday);
4811
4812 int year = calendar->yearShown();
4813 int month = calendar->monthShown();
4814
4815 QDate dbase (year, month, 1);
4816
4817 QTextCharFormat format_past;
4818 QTextCharFormat format_future;
4819 QTextCharFormat format_normal;
4820
4821 format_past.setFontStrikeOut (true);
4822 format_future.setFontUnderline (true);
4823
4824 format_future.setForeground (Qt::red);
4825 format_future.setBackground (Qt::darkBlue);
4826
4827 format_normal.setForeground (Qt::white);
4828 format_normal.setBackground (Qt::black);
4829
4830 format_past.setForeground (Qt::white);
4831 format_past.setBackground (Qt::darkGray);
4832
4833
4834 int days_count = dbase.daysInMonth();
4835
4836 for (int day = 1; day <= days_count; day++)
4837 {
4838 QDate date (year, month, day);
4839 QString sdate;
4840
4841 // sdate = sdate.sprintf ("%02d-%02d-%02d", year, month, day);
4842
4843 sdate += QString("%1").arg (year, 2, 10, QChar('0'));
4844 sdate += "-";
4845 sdate += QString("%1").arg (month, 2, 10, QChar('0'));
4846 sdate += "-";
4847 sdate += QString("%1").arg (day, 2, 10, QChar('0'));
4848
4849 QString fname = dir_days + "/" + sdate;
4850
4851 if (file_exists (fname))
4852 {
4853 if (date < QDate::currentDate())
4854 calendar->setDateTextFormat (date, format_past);
4855 else
4856 if (date >= QDate::currentDate())
4857 calendar->setDateTextFormat (date, format_future);
4858 }
4859 else
4860 calendar->setDateTextFormat (date, format_normal);
4861 }
4862 }
4863
4864 /*
4865 void CTEA::create_moon_phase_algos()
4866 {
4867 moon_phase_algos.insert (MOON_PHASE_TRIG2, tr ("Trigonometric 2"));
4868 moon_phase_algos.insert (MOON_PHASE_TRIG1, tr ("Trigonometric 1"));
4869 moon_phase_algos.insert (MOON_PHASE_CONWAY, tr ("Conway"));
4870 moon_phase_algos.insert (MOON_PHASE_LEUESHKANOV, tr ("Leueshkanov"));
4871 }
4872 */
4873
cal_moon_mode()4874 void CTEA::cal_moon_mode()
4875 {
4876 calendar->moon_mode = ! calendar->moon_mode;
4877 calendar->do_update();
4878 settings->setValue ("moon_mode", calendar->moon_mode);
4879 }
4880
4881
cal_set_date_a()4882 void CTEA::cal_set_date_a()
4883 {
4884 date1 = calendar->selectedDate();
4885 }
4886
4887
cal_set_date_b()4888 void CTEA::cal_set_date_b()
4889 {
4890 date2 = calendar->selectedDate();
4891 }
4892
4893
cal_add_days()4894 void CTEA::cal_add_days()
4895 {
4896 QDate selected = calendar->selectedDate();
4897 selected = selected.addDays (fif_get_text().toInt());
4898 calendar->setSelectedDate (selected);
4899 }
4900
4901
cal_add_months()4902 void CTEA::cal_add_months()
4903 {
4904 QDate selected = calendar->selectedDate();
4905 selected = selected.addMonths (fif_get_text().toInt());
4906 calendar->setSelectedDate (selected);
4907 }
4908
4909
cal_add_years()4910 void CTEA::cal_add_years()
4911 {
4912 QDate selected = calendar->selectedDate();
4913 selected = selected.addYears (fif_get_text().toInt());
4914 calendar->setSelectedDate (selected);
4915 }
4916
4917
cal_set_to_current()4918 void CTEA::cal_set_to_current()
4919 {
4920 calendar->showToday();
4921 calendar->setSelectedDate (QDate::currentDate());
4922 }
4923
4924
cal_gen_mooncal()4925 void CTEA::cal_gen_mooncal()
4926 {
4927 int jdate1 = date1.toJulianDay();
4928 int jdate2 = date2.toJulianDay();
4929
4930 QString s;
4931
4932 QString date_format = settings->value("date_format", "dd/MM/yyyy").toString();
4933
4934 for (int d = jdate1; d <= jdate2; d++)
4935 {
4936 QDate date = QDate::fromJulianDay (d);
4937 int moon_day = moon_phase_trig2 (date.year(), date.month(), date.day());
4938
4939 s += date.toString (date_format);
4940 s += " = ";
4941 s += QString::number (moon_day);
4942 s += "\n";
4943 }
4944
4945 CDocument *nd = documents->create_new();
4946 nd->put (s);
4947 main_tab_widget->setCurrentIndex (idx_tab_edit);
4948 }
4949
4950
cal_diff_days()4951 void CTEA::cal_diff_days()
4952 {
4953 int days = date2.daysTo (date1);
4954 if (days < 0)
4955 days = ~ days;
4956
4957 log->log (QString::number (days));
4958 }
4959
4960
cal_remove()4961 void CTEA::cal_remove()
4962 {
4963 QString fname = dir_days + "/" + calendar->selectedDate().toString ("yyyy-MM-dd");
4964 QFile::remove (fname);
4965 calendar_update();
4966 }
4967
4968
4969 /*
4970 ===================
4971 IDE menu callbacks
4972 ===================
4973 */
4974
4975
ide_run()4976 void CTEA::ide_run()
4977 {
4978 last_action = sender();
4979
4980 if (documents->hash_project.isEmpty())
4981 return;
4982
4983 if (documents->fname_current_project.isEmpty())
4984 return;
4985
4986 QFileInfo source_dir (documents->fname_current_project);
4987
4988 QString dir_build = hash_get_val (documents->hash_project,
4989 "dir_build", source_dir.absolutePath());
4990
4991 if (! path_is_abs (dir_build)) //dir is not absolute path
4992 dir_build = source_dir.absolutePath() + "/" + dir_build;
4993
4994 QString command_run = hash_get_val (documents->hash_project, "command_run", "");
4995
4996 QProcess *process = new QProcess (this);
4997 process->setWorkingDirectory (dir_build);
4998
4999 connect (process, SIGNAL(readyReadStandardOutput()), this, SLOT(process_readyReadStandardOutput()));
5000 process->setProcessChannelMode (QProcess::MergedChannels) ;
5001
5002 process->start (command_run, QStringList());
5003 }
5004
5005
ide_build()5006 void CTEA::ide_build()
5007 {
5008 last_action = sender();
5009
5010 if (documents->hash_project.isEmpty())
5011 return;
5012
5013 if (documents->fname_current_project.isEmpty())
5014 return;
5015
5016 QFileInfo source_dir (documents->fname_current_project);
5017
5018 QString dir_build = hash_get_val (documents->hash_project, "dir_build", source_dir.absolutePath());
5019
5020 if (! path_is_abs (dir_build)) //dir is not absolute path
5021 dir_build = source_dir.absolutePath() + "/" + dir_build;
5022
5023 QString command_build = hash_get_val (documents->hash_project, "command_build", "make");
5024
5025 QProcess *process = new QProcess (this);
5026 process->setWorkingDirectory (dir_build);
5027
5028 connect (process, SIGNAL(readyReadStandardOutput()), this, SLOT(process_readyReadStandardOutput()));
5029
5030 process->setProcessChannelMode (QProcess::MergedChannels) ;
5031 process->start (command_build, QStringList());
5032 }
5033
5034
ide_clean()5035 void CTEA::ide_clean()
5036 {
5037 last_action = sender();
5038
5039 if (documents->hash_project.isEmpty())
5040 return;
5041
5042 if (documents->fname_current_project.isEmpty())
5043 return;
5044
5045 QFileInfo source_dir (documents->fname_current_project);
5046
5047 QString dir_build = hash_get_val (documents->hash_project, "dir_build", source_dir.absolutePath());
5048
5049
5050 if (! path_is_abs (dir_build)) //dir is not absolute path
5051 dir_build = source_dir.absolutePath() + "/" + dir_build;
5052
5053 QString command_clean = hash_get_val (documents->hash_project, "command_clean", "make");
5054
5055 QProcess *process = new QProcess (this);
5056 process->setWorkingDirectory (dir_build);
5057
5058 connect (process, SIGNAL(readyReadStandardOutput()), this, SLOT(process_readyReadStandardOutput()));
5059
5060 process->setProcessChannelMode (QProcess::MergedChannels) ;
5061 process->start (command_clean, QStringList());
5062 }
5063
5064
ide_toggle_hs()5065 void CTEA::ide_toggle_hs()
5066 {
5067 last_action = sender();
5068
5069 CDocument *d = documents->get_current();
5070 if (! d)
5071 return;
5072
5073 if (file_exists (d->file_name))
5074 documents->open_file (toggle_fname_header_source (d->file_name), d->charset);
5075 }
5076
5077
5078 /*
5079 ===================
5080 Nav menu callbacks
5081 ===================
5082 */
5083
5084
nav_save_pos()5085 void CTEA::nav_save_pos()
5086 {
5087 last_action = sender();
5088
5089 CDocument *d = documents->get_current();
5090 if (d)
5091 d->position = d->textCursor().position();
5092 }
5093
5094
nav_goto_pos()5095 void CTEA::nav_goto_pos()
5096 {
5097 last_action = sender();
5098
5099 CDocument *d = documents->get_current();
5100 if (! d)
5101 return;
5102
5103 QTextCursor cr = d->textCursor();
5104 cr.setPosition (d->position);
5105 d->setTextCursor (cr);
5106 }
5107
5108
nav_goto_line()5109 void CTEA::nav_goto_line()
5110 {
5111 last_action = sender();
5112
5113 CDocument *d = documents->get_current();
5114 if (! d)
5115 return;
5116
5117 QTextCursor cr = d->textCursor();
5118 cr.movePosition (QTextCursor::Start);
5119 cr.movePosition (QTextCursor::NextBlock, QTextCursor::MoveAnchor, fif_get_text().toInt() - 1);
5120
5121 d->setTextCursor (cr);
5122 d->setFocus();
5123 }
5124
5125
nav_goto_right_tab()5126 void CTEA::nav_goto_right_tab()
5127 {
5128 last_action = sender();
5129
5130 int i;
5131
5132 if (tab_editor->currentIndex() == (tab_editor->count() - 1))
5133 i = 0;
5134 else
5135 i = tab_editor->currentIndex() + 1;
5136
5137 if (tab_editor->count() > 0)
5138 tab_editor->setCurrentIndex (i);
5139 }
5140
5141
nav_goto_left_tab()5142 void CTEA::nav_goto_left_tab()
5143 {
5144 last_action = sender();
5145
5146 int i;
5147
5148 if (tab_editor->currentIndex() == 0)
5149 i = tab_editor->count() - 1;
5150 else
5151 i = tab_editor->currentIndex() - 1;
5152
5153 if (tab_editor->count() > 0)
5154 tab_editor->setCurrentIndex (i);
5155 }
5156
5157
nav_focus_to_fif()5158 void CTEA::nav_focus_to_fif()
5159 {
5160 last_action = sender();
5161 fif->setFocus (Qt::OtherFocusReason);
5162 }
5163
5164
nav_focus_to_editor()5165 void CTEA::nav_focus_to_editor()
5166 {
5167 last_action = sender();
5168
5169 CDocument *d = documents->get_current();
5170 if (d)
5171 d->setFocus (Qt::OtherFocusReason);
5172 }
5173
5174
nav_labels_update_list()5175 void CTEA::nav_labels_update_list()
5176 {
5177 last_action = sender();
5178
5179 CDocument *d = documents->get_current();
5180 if (! d)
5181 return;
5182
5183 d->update_labels();
5184 update_labels_menu();
5185 }
5186
5187
5188 /*
5189 ===================
5190 Fm menu callbacks
5191 ===================
5192 */
5193
5194
fman_multi_rename_zeropad()5195 void CTEA::fman_multi_rename_zeropad()
5196 {
5197 last_action = sender();
5198
5199 QString fiftxt = fif_get_text();
5200 int finalsize = fiftxt.toInt();
5201 if (finalsize < 1)
5202 finalsize = 10;
5203
5204 QStringList sl = fman->get_sel_fnames();
5205
5206 if (sl.size() < 1)
5207 return;
5208
5209 for (int i = 0; i < sl.size(); i++)
5210 {
5211 QString fname = sl[i];
5212 QFileInfo fi (fname);
5213
5214 if (fi.exists() && fi.isWritable())
5215 {
5216 int zeroes_to_add = finalsize - fi.baseName().length();
5217
5218 QString newname = fi.baseName();
5219 QString ext = file_get_ext (fname);
5220
5221 #if (QT_VERSION_MAJOR < 5)
5222 newname.remove(QRegExp("[a-zA-Z\\s]"));
5223 #else
5224 newname.remove(QRegularExpression("[a-zA-Z\\s]"));
5225 #endif
5226
5227 if (newname.isEmpty())
5228 continue;
5229
5230 QString pad = "0";
5231 pad = pad.repeated (zeroes_to_add);
5232 newname = pad + newname;
5233
5234 QString newfpath (fi.path());
5235 newfpath.append ("/").append (newname);
5236 newfpath.append (".");
5237 newfpath.append (ext);
5238
5239 QFile::rename (fname, newfpath);
5240 }
5241 }
5242
5243 update_dyn_menus();
5244 fman->refresh();
5245 }
5246
5247
fman_multi_rename_del_n_first_chars()5248 void CTEA::fman_multi_rename_del_n_first_chars()
5249 {
5250 last_action = sender();
5251
5252 QString fiftxt = fif_get_text();
5253 int todel = fiftxt.toInt();
5254 if (todel < 1)
5255 todel = 1;
5256
5257 QStringList sl = fman->get_sel_fnames();
5258
5259 if (sl.size() < 1)
5260 return;
5261
5262 for (int i = 0; i < sl.size(); i++)
5263 {
5264 QFileInfo fi (sl.at(i));
5265
5266 if (fi.exists() && fi.isWritable())
5267 {
5268 QString newname = fi.fileName();
5269 newname = newname.mid (todel);
5270
5271 QString newfpath (fi.path());
5272 newfpath.append ("/").append (newname);
5273 QFile::rename (sl.at(i), newfpath);
5274 }
5275 }
5276
5277 update_dyn_menus();
5278 fman->refresh();
5279 }
5280
5281
fman_multi_rename_replace()5282 void CTEA::fman_multi_rename_replace()
5283 {
5284 last_action = sender();
5285
5286 QStringList l = fif_get_text().split ("~");
5287 if (l.size() < 2)
5288 return;
5289
5290 QStringList sl = fman->get_sel_fnames();
5291
5292 if (sl.size() < 1)
5293 return;
5294
5295 for (int i = 0; i < sl.size(); i++)
5296 {
5297 QFileInfo fi (sl.at(i));
5298
5299 if (fi.exists() && fi.isWritable())
5300 {
5301 QString newname = fi.fileName();
5302 newname = newname.replace (l[0], l[1]);
5303
5304 QString newfpath (fi.path());
5305 newfpath.append ("/").append (newname);
5306 QFile::rename (sl.at(i), newfpath);
5307 }
5308 }
5309
5310 update_dyn_menus();
5311 fman->refresh();
5312 }
5313
5314
fman_multi_rename_apply_template()5315 void CTEA::fman_multi_rename_apply_template()
5316 {
5317 last_action = sender();
5318
5319 QString fiftxt = fif_get_text();
5320
5321 QStringList sl = fman->get_sel_fnames();
5322
5323 if (sl.size() < 1)
5324 return;
5325
5326 for (int i = 0; i < sl.size(); i++)
5327 {
5328 QFileInfo fi (sl.at(i));
5329
5330 if (fi.exists() && fi.isWritable())
5331 {
5332 QString ext = file_get_ext (sl.at(i));
5333 QString newname = fiftxt;
5334 newname = newname.replace ("%filename", fi.fileName());
5335 newname = newname.replace ("%ext", ext);
5336 newname = newname.replace ("%basename", fi.baseName());
5337
5338 QString newfpath (fi.path());
5339 newfpath.append ("/").append (newname);
5340 QFile::rename (sl.at(i), newfpath);
5341 }
5342 }
5343
5344 update_dyn_menus();
5345 fman->refresh();
5346 }
5347
5348
fman_fileop_create_dir()5349 void CTEA::fman_fileop_create_dir()
5350 {
5351 last_action = sender();
5352
5353 bool ok;
5354 QString newdir = QInputDialog::getText (this, tr ("Enter the name"),
5355 tr ("Name:"), QLineEdit::Normal,
5356 tr ("new_directory"), &ok);
5357 if (! ok || newdir.isEmpty())
5358 return;
5359
5360 QString dname = fman->dir.path() + "/" + newdir;
5361
5362 QDir d;
5363 if (d.mkpath (dname))
5364 fman->nav (dname);
5365 }
5366
5367
fman_fileop_rename()5368 void CTEA::fman_fileop_rename()
5369 {
5370 last_action = sender();
5371
5372 QString fname = fman->get_sel_fname();
5373 if (fname.isEmpty())
5374 return;
5375
5376 QFileInfo fi (fname);
5377 if (! fi.exists() && ! fi.isWritable())
5378 return;
5379
5380 bool ok;
5381 QString newname = QInputDialog::getText (this, tr ("Enter the name"),
5382 tr ("Name:"), QLineEdit::Normal,
5383 tr ("new"), &ok);
5384 if (! ok || newname.isEmpty())
5385 return;
5386
5387 QString newfpath = fi.path() + "/" + newname;
5388 QFile::rename (fname, newfpath);
5389 update_dyn_menus();
5390 fman->refresh();
5391
5392 QModelIndex index = fman->index_from_name (newname);
5393 fman->selectionModel()->setCurrentIndex (index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
5394 fman->scrollTo (index, QAbstractItemView::PositionAtCenter);
5395 }
5396
5397
fman_fileop_delete()5398 void CTEA::fman_fileop_delete()
5399 {
5400 last_action = sender();
5401
5402 QString fname = fman->get_sel_fname();
5403 if (fname.isEmpty())
5404 return;
5405
5406 int i = fman->get_sel_index(); //save the index
5407
5408 QFileInfo fi (fname);
5409 if (! fi.exists() && ! fi.isWritable())
5410 return;
5411
5412 if (QMessageBox::warning (this, "TEA",
5413 tr ("Are you sure to delete\n"
5414 "%1?").arg (fname),
5415 QMessageBox::Yes | QMessageBox::Default,
5416 QMessageBox::No | QMessageBox::Escape) == QMessageBox::No)
5417 return;
5418
5419 QFile::remove (fname);
5420 update_dyn_menus();
5421 fman->refresh();
5422
5423 QModelIndex index = fman->index_from_idx (i);
5424 if (! index.isValid())
5425 index = fman->index_from_idx (0);
5426
5427 fman->selectionModel()->setCurrentIndex (index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
5428 fman->scrollTo (index, QAbstractItemView::PositionAtCenter);
5429 }
5430
5431
fm_fileinfo_info()5432 void CTEA::fm_fileinfo_info()
5433 {
5434 last_action = sender();
5435
5436 QString fname;
5437
5438 if (main_tab_widget->currentIndex() == idx_tab_fman)
5439 fname = fman->get_sel_fname();
5440 else
5441 {
5442 CDocument *d = documents->get_current();
5443 if (d)
5444 fname = d->file_name;
5445 }
5446
5447 QFileInfo fi (fname);
5448 if (! fi.exists())
5449 return;
5450
5451 QStringList l;
5452
5453 //detect EOL
5454
5455 QFile f (fname);
5456
5457 if (f.open (QIODevice::ReadOnly))
5458 {
5459 QString n (tr("End of line: "));
5460 QByteArray barr = f.readAll();
5461
5462 int nl = barr.count ('\n');
5463 int cr = barr.count ('\r');
5464
5465 if (nl > 0 && cr == 0)
5466 n += "UNIX";
5467
5468 if (nl > 0 && cr > 0)
5469 n += "Windows";
5470
5471 if (nl == 0 && cr > 0)
5472 n += "Mac";
5473
5474 l.append (n);
5475 }
5476
5477 l.append (tr ("file name: %1").arg (fi.absoluteFilePath()));
5478 l.append (tr ("size: %1 kbytes").arg (QString::number (fi.size() / 1024)));
5479 l.append (tr ("last modified: %1").arg (fi.lastModified().toString ("yyyy-MM-dd@hh:mm:ss")));
5480
5481 if (file_get_ext (fname) == "wav")
5482 {
5483 CWavReader wr;
5484 wr.get_info (fname);
5485 l.append (tr ("bits per sample: %1").arg (wr.wav_chunk_fmt.bits_per_sample));
5486 l.append (tr ("number of channels: %1").arg (wr.wav_chunk_fmt.num_channels));
5487 l.append (tr ("sample rate: %1").arg (wr.wav_chunk_fmt.sample_rate));
5488 if (wr.wav_chunk_fmt.bits_per_sample == 16)
5489 l.append (tr ("RMS for all channels: %1 dB").arg (wr.rms));
5490 }
5491
5492 log->log (l.join ("<br>"));
5493 }
5494
5495
fman_fileinfo_count_lines_in_selected_files()5496 void CTEA::fman_fileinfo_count_lines_in_selected_files()
5497 {
5498 last_action = sender();
5499
5500 QString ft = fif_get_text();
5501 if (ft.isEmpty())
5502 return;
5503
5504 QStringList sl = fman->get_sel_fnames();
5505
5506 if (sl.size() < 1)
5507 return;
5508
5509 long int sum = 0;
5510
5511 for (int i = 0; i < sl.size(); i++)
5512 {
5513 QByteArray f = file_load (sl.at(i));
5514 sum += f.count ('\n');
5515 }
5516
5517 log->log (tr ("There are %1 lines at %2 files").arg (sum).arg (sl.size()));
5518 }
5519
5520
fman_zip_create()5521 void CTEA::fman_zip_create()
5522 {
5523 last_action = sender();
5524
5525 bool ok;
5526
5527 QString name = QInputDialog::getText (this, tr ("Enter the archive name"),
5528 tr ("Name:"), QLineEdit::Normal,
5529 tr ("new_archive"), &ok);
5530
5531 if (! ok)
5532 return;
5533
5534 fman->zipper.files_list.clear();
5535 fman->zipper.archive_name = name;
5536
5537 if (! name.endsWith (".zip"))
5538 name.append (".zip");
5539
5540 fman->zipper.archive_fullpath = fman->dir.path() + "/" + name;
5541 }
5542
5543
fman_zip_add()5544 void CTEA::fman_zip_add()
5545 {
5546 last_action = sender();
5547
5548 QString f = ed_fman_fname->text().trimmed();
5549 QStringList li = fman->get_sel_fnames();
5550
5551 if (! f.isEmpty())
5552 if (f[0] == '/')
5553 {
5554 fman->zipper.files_list.append (f);
5555 return;
5556 }
5557
5558 if (li.size() == 0)
5559 {
5560 QString fname = fman->dir.path() + "/" + f;
5561 fman->zipper.files_list.append (fname);
5562 return;
5563 }
5564
5565 for (int i = 0; i < li.size(); i++)
5566 fman->zipper.files_list.append (li.at(i));
5567 }
5568
5569
fman_zip_save()5570 void CTEA::fman_zip_save()
5571 {
5572 last_action = sender();
5573
5574 fman->zipper.pack_prepared();
5575 fman->refresh();
5576 }
5577
5578
fman_zip_info()5579 void CTEA::fman_zip_info()
5580 {
5581 last_action = sender();
5582
5583 QString fn = fman->get_sel_fname();
5584 if (fn.isEmpty())
5585 return;
5586
5587 CZipper z;
5588
5589 QStringList sl = z.unzip_list (fn);
5590
5591 for (int i = 0; i < sl.size(); i++)
5592 sl[i] = sl[i].append ("<br>");
5593
5594 log->log (sl.join("\n"));
5595 }
5596
5597
fman_zip_unpack()5598 void CTEA::fman_zip_unpack()
5599 {
5600 last_action = sender();
5601
5602 CZipper z;
5603
5604 QString f = ed_fman_fname->text().trimmed();
5605 QStringList li = fman->get_sel_fnames();
5606
5607 if (! f.isEmpty())
5608 if (f[0] == '/')
5609 {
5610 z.unzip (f, fman->dir.path());
5611 return;
5612 }
5613
5614 if (li.size() == 0)
5615 {
5616 QString fname (fman->dir.path());
5617 fname.append ("/").append (f);
5618 z.unzip (fname, fman->dir.path());
5619 return;
5620 }
5621
5622 for (QList <QString>::iterator fname = li.begin(); fname != li.end(); ++fname)
5623 {
5624 z.unzip ((*fname), fman->dir.path());
5625 log->log ((*fname) + tr (" is unpacked"));
5626 }
5627 }
5628
5629
fman_img_conv_by_side()5630 void CTEA::fman_img_conv_by_side()
5631 {
5632 last_action = sender();
5633
5634 int side = fif_get_text().toInt();
5635 if (side != 0)
5636 fman_convert_images (true, side);
5637 }
5638
5639
fman_img_conv_by_percent()5640 void CTEA::fman_img_conv_by_percent()
5641 {
5642 last_action = sender();
5643
5644 int percent = fif_get_text().toInt();
5645 if (percent != 0)
5646 fman_convert_images (false, percent);
5647 }
5648
5649
fman_img_make_gallery()5650 void CTEA::fman_img_make_gallery()
5651 {
5652 last_action = sender();
5653
5654 CDocument *d = documents->get_current();
5655 if (! d)
5656 return;
5657
5658 if (! file_exists (d->file_name))
5659 return;
5660
5661 int side = settings->value ("ed_side_size", 110).toInt();
5662 int thumbs_per_row = settings->value ("ed_thumbs_per_row", 4).toInt();
5663
5664 QString link_options = settings->value ("ed_link_options", "target=\"_blank\"").toString();
5665 if (! link_options.startsWith (" "))
5666 link_options.prepend (" ");
5667
5668 QString dir_out (fman->dir.absolutePath());
5669
5670 QString table ("<table>\n\n");
5671
5672 Qt::TransformationMode transformMode = Qt::FastTransformation;
5673
5674 pb_status->show();
5675 pb_status->setFormat (tr ("%p% completed"));
5676 pb_status->setTextVisible (true);
5677
5678 QStringList li = fman->get_sel_fnames();
5679 int quality = settings->value ("img_quality", "-1").toInt();
5680
5681 pb_status->setRange (0, li.size() - 1 );
5682
5683 int x = 0;
5684 int col = 0;
5685
5686 for (int i = 0; i < li.size(); i++)
5687 {
5688 QString fname = li[i];
5689 if (is_image (fname))
5690 {
5691 QFileInfo fi (fname);
5692
5693 if (fi.baseName().startsWith ("tmb_"))
5694 continue;
5695
5696 QImage source (fname);
5697 if (! source.isNull())
5698 {
5699 qApp->processEvents();
5700
5701 QImage dest = image_scale_by (source, true, side, transformMode);
5702
5703 QString dest_fname (dir_out);
5704 dest_fname.append ("/");
5705 dest_fname.append ("tmb_");
5706 dest_fname.append (fi.fileName());
5707 dest_fname = change_file_ext (dest_fname, "jpg");
5708
5709 dest.save (dest_fname, 0, quality);
5710
5711 QFileInfo inf (d->file_name);
5712 QDir dir (inf.absolutePath());
5713
5714 QString tmb = get_insert_image (d->file_name, dest_fname, d->markup_mode);
5715 QString cell = "<a href=\"%source\"" + link_options +">%thumb</a>";
5716 cell.replace ("%source", dir.relativeFilePath (fname));
5717 cell.replace ("%thumb", tmb);
5718
5719 if (col == 0)
5720 table += "<tr>\n\n";
5721
5722 table += "<td>\n";
5723
5724 table += cell;
5725
5726 table += "</td>\n";
5727
5728 col++;
5729 if (col == thumbs_per_row)
5730 {
5731 table += "</tr>\n\n";
5732 col = 0;
5733 }
5734
5735 pb_status->setValue (x++);
5736 }
5737 }
5738 }
5739
5740 pb_status->hide();
5741 fman->refresh();
5742
5743 if (! table.endsWith ("</tr>\n\n"))
5744 table += "</tr>\n\n";
5745
5746 table += "</table>\n";
5747
5748 if (d)
5749 d->put (table);
5750 }
5751
5752
fman_home()5753 void CTEA::fman_home()
5754 {
5755 last_action = sender();
5756
5757 #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
5758 fman->nav ("c:\\");
5759 #else
5760 fman->nav (QDir::homePath());
5761 #endif
5762 }
5763
5764
fman_refresh()5765 void CTEA::fman_refresh()
5766 {
5767 last_action = sender();
5768
5769 fman->refresh();
5770 }
5771
5772
fman_preview_image()5773 void CTEA::fman_preview_image()
5774 {
5775 last_action = sender();
5776
5777 QString fname = fman->get_sel_fname();
5778 if (fname.isEmpty())
5779 return;
5780
5781 if (is_image (fname))
5782 {
5783 if (file_get_ext (fname) == "gif")
5784 {
5785 CGIFWindow *w = new CGIFWindow;
5786 w->load_image (fname);
5787 return;
5788 }
5789
5790 img_viewer->window_full.show();
5791 img_viewer->set_image_full (fname);
5792 }
5793 }
5794
5795
fman_select_by_regexp()5796 void CTEA::fman_select_by_regexp()
5797 {
5798 last_action = sender();
5799 fman_items_select_by_regexp (true);
5800 }
5801
5802
fman_deselect_by_regexp()5803 void CTEA::fman_deselect_by_regexp()
5804 {
5805 last_action = sender();
5806 fman_items_select_by_regexp (false);
5807 }
5808
5809
5810 /*
5811 ===================
5812 View menu callbacks
5813 ===================
5814 */
5815
5816
view_use_theme()5817 void CTEA::view_use_theme()
5818 {
5819 last_action = sender();
5820 QAction *a = qobject_cast<QAction *>(sender());
5821
5822 QString css_fname = a->data().toString() + "/" + "stylesheet.css";
5823
5824 if (! file_exists (css_fname))
5825 {
5826 log->log (tr ("There is no stylesheet file"));
5827 return;
5828 }
5829
5830 update_stylesheet (css_fname);
5831 fname_stylesheet = css_fname;
5832 settings->setValue ("fname_stylesheet", fname_stylesheet);
5833 }
5834
5835
view_use_palette()5836 void CTEA::view_use_palette()
5837 {
5838 last_action = sender();
5839
5840 QAction *a = qobject_cast<QAction *>(sender());
5841 QString fname = dir_palettes + "/" + a->text();
5842
5843 if (! file_exists (fname))
5844 fname = ":/palettes/" + a->text();
5845
5846 fname_def_palette = fname;
5847 load_palette (fname);
5848
5849 update_stylesheet (fname_stylesheet);
5850 documents->apply_settings();
5851 }
5852
5853
view_use_profile()5854 void CTEA::view_use_profile()
5855 {
5856 last_action = sender();
5857 QAction *a = qobject_cast<QAction *>(sender());
5858
5859 QSettings s (a->data().toString(), QSettings::IniFormat);
5860
5861 QPoint pos = s.value ("pos", QPoint (1, 200)).toPoint();
5862 QSize size = s.value ("size", QSize (600, 420)).toSize();
5863
5864 if (mainSplitter/* && ! settings->value ("ui_mode", 0).toBool()*/)
5865 mainSplitter->restoreState (s.value ("splitterSizes").toByteArray());
5866
5867 resize (size);
5868 move (pos);
5869
5870 fname_def_palette = s.value ("fname_def_palette", ":/palettes/TEA").toString();
5871 load_palette (fname_def_palette);
5872
5873 settings->setValue ("fname_def_palette", fname_def_palette);
5874 settings->setValue ("word_wrap", s.value ("word_wrap", "1").toBool());
5875 settings->setValue ("show_linenums", s.value ("show_linenums", "0").toBool());
5876 settings->setValue ("additional_hl", s.value ("additional_hl", "0").toBool());
5877 settings->setValue ("show_margin", s.value ("show_margin", "0").toBool());
5878
5879 settings->setValue ("editor_font_name", s.value ("editor_font_name", "Serif").toString());
5880 settings->setValue ("editor_font_size", s.value ("editor_font_size", "14").toInt());
5881 settings->setValue ("logmemo_font", s.value ("logmemo_font", "Monospace").toString());
5882 settings->setValue ("logmemo_font_size", s.value ("logmemo_font_size", "14").toInt());
5883 settings->setValue ("app_font_name", s.value ("app_font_name", "Sans").toString());
5884 settings->setValue ("app_font_size", s.value ("app_font_size", "12").toInt());
5885
5886 cb_wordwrap->setChecked (s.value ("word_wrap", "1").toBool());
5887
5888 cb_show_linenums->setChecked (s.value ("show_linenums", "0").toBool());
5889 cb_hl_current_line->setChecked (s.value ("additional_hl", "0").toBool());
5890 cb_show_margin->setChecked (s.value ("show_margin", "0").toBool());
5891
5892 update_stylesheet (fname_stylesheet);
5893 documents->apply_settings();
5894 }
5895
5896
view_profile_save_as()5897 void CTEA::view_profile_save_as()
5898 {
5899 last_action = sender();
5900
5901 bool ok;
5902 QString name = QInputDialog::getText (this, tr ("Enter the name"),
5903 tr ("Name:"), QLineEdit::Normal,
5904 tr ("new_profile"), &ok);
5905 if (! ok || name.isEmpty())
5906 return;
5907
5908 QString fname (dir_profiles);
5909 fname.append ("/").append (name);
5910
5911 QSettings s (fname, QSettings::IniFormat);
5912
5913 s.setValue ("fname_def_palette", fname_def_palette);
5914
5915 s.setValue ("word_wrap", settings->value ("word_wrap", "1").toBool());
5916 s.setValue ("show_linenums", settings->value ("show_linenums", "0").toBool());
5917 s.setValue ("additional_hl", settings->value ("additional_hl", "0").toBool());
5918
5919 s.setValue ("pos", pos());
5920 s.setValue ("size", size());
5921
5922 if (mainSplitter /*&& ! settings->value ("ui_mode", 0).toBool()*/)
5923 s.setValue ("splitterSizes", mainSplitter->saveState());
5924
5925 s.setValue ("editor_font_name", settings->value ("editor_font_name", "Monospace").toString());
5926 s.setValue ("editor_font_size", settings->value ("editor_font_size", "16").toInt());
5927
5928 s.setValue ("logmemo_font", settings->value ("logmemo_font", "Monospace").toString());
5929 s.setValue ("logmemo_font_size", settings->value ("logmemo_font_size", "12").toInt());
5930
5931 s.setValue ("app_font_name", settings->value ("app_font_name", "Sans").toString());
5932 s.setValue ("app_font_size", settings->value ("app_font_size", "12").toInt());
5933
5934 s.sync();
5935
5936 update_profiles();
5937 shortcuts->load_from_file (shortcuts->fname);
5938 }
5939
5940
view_toggle_wrap()5941 void CTEA::view_toggle_wrap()
5942 {
5943 last_action = sender();
5944
5945 CDocument *d = documents->get_current();
5946 if (d)
5947 d->set_word_wrap (! d->get_word_wrap());
5948 }
5949
5950
view_hide_error_marks()5951 void CTEA::view_hide_error_marks()
5952 {
5953 last_action = sender();
5954
5955 CDocument *d = documents->get_current();
5956 if (! d)
5957 return;
5958
5959 QTextCursor cr = d->textCursor();
5960
5961 //delete all underlines
5962 cr.setPosition (0);
5963 cr.movePosition (QTextCursor::End, QTextCursor::KeepAnchor);
5964 QTextCharFormat f = cr.blockCharFormat();
5965 f.setFontUnderline (false);
5966 cr.mergeCharFormat (f);
5967 d->document()->setModified (false);
5968 }
5969
5970
view_toggle_fs()5971 void CTEA::view_toggle_fs()
5972 {
5973 last_action = sender();
5974 setWindowState(windowState() ^ Qt::WindowFullScreen);
5975 }
5976
5977
view_stay_on_top()5978 void CTEA::view_stay_on_top()
5979 {
5980 last_action = sender();
5981
5982 Qt::WindowFlags flags = windowFlags();
5983 flags ^= Qt::WindowStaysOnTopHint;
5984 setWindowFlags (flags );
5985 show();
5986 activateWindow();
5987 }
5988
5989
view_darker()5990 void CTEA::view_darker()
5991 {
5992 last_action = sender();
5993 CDarkerWindow *wd = new CDarkerWindow;
5994 wd->show();
5995 }
5996
5997
5998 /*
5999 ===================
6000 ? menu callbacks
6001 ===================
6002 */
6003
6004
help_show_about()6005 void CTEA::help_show_about()
6006 {
6007 CAboutWindow *a = new CAboutWindow();
6008 a->move (x() + 20, y() + 20);
6009 a->show();
6010 }
6011
6012
help_show_news()6013 void CTEA::help_show_news()
6014 {
6015 QString fname = ":/NEWS";
6016 if (QLocale::system().name().left(2) == "ru")
6017 fname = ":/NEWS-RU";
6018
6019 CDocument *d = documents->open_file (fname, "UTF-8");
6020 if (d)
6021 d->setReadOnly (true);
6022 }
6023
6024
help_show_todo()6025 void CTEA::help_show_todo()
6026 {
6027 CDocument *d = documents->open_file (":/TODO", "UTF-8");
6028 if (d)
6029 d->setReadOnly (true);
6030 }
6031
6032
help_show_changelog()6033 void CTEA::help_show_changelog()
6034 {
6035 CDocument *d = documents->open_file (":/ChangeLog", "UTF-8");
6036 if (d)
6037 d->setReadOnly (true);
6038 }
6039
6040
help_show_gpl()6041 void CTEA::help_show_gpl()
6042 {
6043 CDocument *d = documents->open_file (":/COPYING", "UTF-8");
6044 if (d)
6045 d->setReadOnly (true);
6046 }
6047
6048
6049 /*
6050 ====================================
6051 Application stuff inits and updates
6052 ====================================
6053 */
6054
6055
CTEA()6056 CTEA::CTEA()
6057 {
6058 mainSplitter = 0;
6059 ui_update = true;
6060 boring = false;
6061 b_destroying_all = false;
6062 last_action = 0;
6063 b_recent_off = false;
6064 lv_menuitems = NULL;
6065 fm_entry_mode = FM_ENTRY_MODE_NONE;
6066 calendar = 0;
6067 capture_to_storage_file = false;
6068
6069 date1 = QDate::currentDate();
6070 date2 = QDate::currentDate();
6071
6072 idx_tab_edit = 0;
6073 idx_tab_tune = 0;
6074 idx_tab_fman = 0;
6075 idx_tab_learn = 0;
6076 idx_tab_calendar = 0;
6077 idx_tab_keyboard = 0;
6078
6079 create_paths();
6080
6081 QString sfilename = dir_config + "/tea.conf";
6082 settings = new QSettings (sfilename, QSettings::IniFormat);
6083
6084 QString lng = settings->value ("lng", QLocale::system().name()).toString().left(2).toLower();
6085
6086 if (! file_exists (":/translations/" + lng + ".qm"))
6087 lng = "en";
6088
6089 #if QT_VERSION >= 0x060000
6090 if (transl_app.load (QString ("qt_%1").arg (lng), QLibraryInfo::path (QLibraryInfo::TranslationsPath)))
6091 qApp->installTranslator (&transl_app);
6092 #else
6093 if (transl_system.load (QString ("qt_%1").arg (lng), QLibraryInfo::location (QLibraryInfo::TranslationsPath)))
6094 qApp->installTranslator (&transl_system);
6095 #endif
6096
6097 if (transl_app.load (":/translations/" + lng))
6098 qApp->installTranslator (&transl_app);
6099
6100 fname_stylesheet = settings->value ("fname_stylesheet", ":/themes/TEA").toString();
6101 theme_dir = get_file_path (fname_stylesheet) + "/";
6102
6103 l_charset = new QLabel;
6104 l_status = new QLabel;
6105
6106 pb_status = new QProgressBar;
6107 pb_status->setRange (0, 0);
6108
6109 tb_stop = new QToolButton;
6110 tb_stop->setIcon (style()->standardIcon(QStyle::SP_MediaStop));
6111 connect (tb_stop, SIGNAL(clicked()), this, SLOT(tb_stop_clicked()));
6112
6113 statusBar()->addWidget (l_status);
6114 statusBar()->addPermanentWidget (pb_status);
6115 statusBar()->addPermanentWidget (tb_stop);
6116 statusBar()->addPermanentWidget (l_charset);
6117
6118 // pb_status->hide();
6119 progress_hide();
6120
6121 create_actions();
6122 create_menus();
6123 create_toolbars();
6124
6125 update_styles();
6126 update_bookmarks();
6127 update_templates();
6128 update_tables();
6129 update_snippets();
6130 update_sessions();
6131 update_scripts();
6132 update_programs();
6133 update_palettes();
6134 update_themes();
6135 update_charsets();
6136 update_profiles();
6137 create_markup_hash();
6138
6139 setMinimumSize (12, 12);
6140
6141 if (! settings->value ("ui_mode", 0).toBool())
6142 create_main_widget_splitter();
6143 else
6144 create_main_widget_docked();
6145
6146 idx_prev = 0;
6147 connect (main_tab_widget, SIGNAL(currentChanged(int)), this, SLOT(main_tab_page_changed(int)));
6148
6149 read_settings();
6150 read_search_options();
6151
6152 documents = new CDox();
6153 documents->parent_wnd = this;
6154 documents->tab_widget = tab_editor;
6155 documents->main_tab_widget = main_tab_widget;
6156
6157 documents->menu_recent = menu_file_recent;
6158 documents->recent_list_fname = dir_config + "/tea_recent";
6159 documents->reload_recent_list();
6160 documents->update_recent_menu();
6161 documents->log = log;
6162 documents->markup_mode = markup_mode;
6163 documents->dir_config = dir_config;
6164 documents->todo.dir_days = dir_days;
6165 documents->fname_crapbook = fname_crapbook;
6166
6167 documents->fname_saved_buffers = fname_saved_buffers;
6168 documents->l_status_bar = l_status;
6169 documents->l_charset = l_charset;
6170
6171 documents->autosave_files = hash_load_keyval (fname_autosaving_files);
6172
6173
6174 load_palette (fname_def_palette);
6175
6176 update_stylesheet (fname_stylesheet);
6177 documents->apply_settings();
6178
6179 documents->todo.load_dayfile();
6180
6181 update_hls();
6182
6183 #if defined (HUNSPELL_ENABLE) || defined (ASPELL_ENABLE)
6184 setup_spellcheckers();
6185 #endif
6186
6187 shortcuts = new CShortcuts (this);
6188 shortcuts->fname = dir_config + "/shortcuts";
6189 shortcuts->load_from_file (shortcuts->fname);
6190
6191 sl_fif_history = qstring_load (fname_fif).split ("\n");
6192 cmb_fif->addItems (sl_fif_history);
6193 cmb_fif->clearEditText();
6194
6195 create_fman();
6196 create_options();
6197 create_calendar();
6198 create_manual();
6199
6200 update_fonts();
6201
6202 documents->dir_last = settings->value ("dir_last", QDir::homePath()).toString();
6203 b_preview = settings->value ("b_preview", false).toBool();
6204
6205 img_viewer = new CImgViewer;
6206
6207 restoreState (settings->value ("state", QByteArray()).toByteArray());
6208
6209 current_version_number = VERSION_NUMBER;
6210 if (current_version_number.indexOf ('\"') != -1)
6211 {
6212 current_version_number.remove (0, 1);
6213 current_version_number.remove (current_version_number.size() - 1, 1);
6214 }
6215
6216 QString vn = settings->value ("VER_NUMBER", "").toString();
6217 if (vn.isEmpty() || vn != QString (current_version_number))
6218 help_show_news();
6219
6220 if (settings->value ("session_restore", false).toBool())
6221 {
6222 QString fname_session (dir_sessions);
6223 fname_session.append ("/def-session-777");
6224 documents->load_from_session (fname_session);
6225 }
6226
6227 if (settings->value ("save_buffers", true).toBool())
6228 documents->load_from_buffers (fname_saved_buffers);
6229
6230
6231 handle_args();
6232 ui_update = false;
6233
6234 setIconSize (QSize (icon_size, icon_size));
6235 tb_fman_dir->setIconSize (QSize (icon_size, icon_size));
6236
6237 QClipboard *clipboard = QApplication::clipboard();
6238 connect (clipboard , SIGNAL(dataChanged()), this, SLOT(clipboard_dataChanged()));
6239
6240 setAcceptDrops (true);
6241
6242 log->log (tr ("<b>TEA %1</b> by Peter Semiletov | tea.ourproject.org<br>Support TEA on www.patreon.com/semiletov<br>Git: github.com/psemiletov/tea-qt<br>AUR: aur.archlinux.org/packages/tea-qt-git").arg (QString (current_version_number)));
6243
6244 QTextCursor cr = log->textCursor();
6245 cr.movePosition (QTextCursor::Start);
6246 log->setTextCursor (cr);
6247
6248 QString icon_fname = ":/icons/tea-icon-v3-0" + settings->value ("icon_fname", "1").toString() + ".png";
6249 qApp->setWindowIcon (QIcon (icon_fname));
6250 idx_tab_edit_activate();
6251 }
6252
6253
handle_args()6254 void CTEA::handle_args()
6255 {
6256 QStringList l = qApp->arguments();
6257 int size = l.size();
6258 if (size < 2)
6259 return;
6260
6261 QString charset = settings->value ("cmdline_default_charset", "UTF-8").toString();//"UTF-8";
6262
6263 for (int i = 1; i < size; i++)
6264 {
6265 QString t = l.at(i);
6266 if (t.startsWith("--charset"))
6267 {
6268 QStringList pair = t.split ("=");
6269 if (pair.size() > 1)
6270 charset = pair[1];
6271 }
6272 else
6273 {
6274 QFileInfo f (l.at(i));
6275
6276 if (! f.isAbsolute())
6277 {
6278 QString fullname (QDir::currentPath());
6279 fullname.append ("/").append (l.at(i));
6280 documents->open_file (fullname, charset);
6281 }
6282 else
6283 documents->open_file (l.at(i), charset);
6284 }
6285 }
6286 }
6287
6288
create_paths()6289 void CTEA::create_paths()
6290 {
6291 portable_mode = false;
6292
6293 QStringList l = qApp->arguments();
6294 if (l.contains ("--p"))
6295 portable_mode = true;
6296
6297 QDir dr;
6298 if (! portable_mode)
6299 dir_config = dr.homePath();
6300 else
6301 dir_config = QCoreApplication::applicationDirPath();
6302
6303 #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
6304 dir_config.append ("/tea");
6305 #else
6306 dir_config.append ("/.config/tea");
6307 #endif
6308
6309 // hs_path["dir_config"] = dir_config;
6310
6311 dr.setPath (dir_config);
6312 if (! dr.exists())
6313 dr.mkpath (dir_config);
6314
6315 fname_crapbook = dir_config + "/crapbook.txt";
6316 // hs_path["fname_crapbook"] = fname_crapbook;
6317
6318 fname_saved_buffers = dir_config + "/saved_buffers.txt";
6319 //hs_path["saved_buffers"] = fname_saved_buffers;
6320
6321 fname_autosaving_files = dir_config + "/autosaving_files.txt";
6322 //hs_path["autosaving_files"] = fname_autosaving_files;
6323
6324 fname_fif = dir_config + "/fif";
6325 //hs_path["fname_fif"] = fname_fif;
6326
6327 fname_bookmarks = dir_config + "/tea_bmx";
6328 //hs_path["fname_bookmarks"] = fname_bookmarks;
6329
6330 fname_programs = dir_config + "/programs";
6331 //hs_path["fname_programs"] = fname_programs;
6332
6333 fname_places_bookmarks = dir_config + "/places_bookmarks";
6334 //hs_path["fname_places_bookmarks"] = fname_places_bookmarks;
6335
6336 fname_tempfile = QDir::tempPath() + "/tea.tmp";
6337 //hs_path["fname_tempfile"] = fname_tempfile;
6338
6339 fname_tempparamfile = QDir::tempPath() + "/teaparam.tmp";
6340 //hs_path["fname_tempparamfile"] = fname_tempparamfile;
6341
6342 dir_tables = dir_config + "/tables";
6343
6344 dr.setPath (dir_tables);
6345 if (! dr.exists())
6346 dr.mkpath (dir_tables);
6347
6348 dir_user_dict = dir_config + "/dictionaries";
6349
6350 dr.setPath (dir_user_dict);
6351 if (! dr.exists())
6352 dr.mkpath (dir_user_dict);
6353
6354 dir_profiles = dir_config + "/profiles";
6355
6356 dr.setPath (dir_profiles);
6357 if (! dr.exists())
6358 dr.mkpath (dir_profiles);
6359
6360 dir_templates = dir_config + "/templates";
6361
6362 dr.setPath (dir_templates);
6363 if (! dr.exists())
6364 dr.mkpath (dir_templates);
6365
6366 dir_snippets = dir_config + "/snippets";
6367
6368 dr.setPath (dir_snippets);
6369 if (! dr.exists())
6370 dr.mkpath (dir_snippets);
6371
6372 dir_scripts = dir_config + "/scripts";
6373
6374 dr.setPath (dir_scripts);
6375 if (! dr.exists())
6376 dr.mkpath (dir_scripts);
6377
6378 dir_days = dir_config + "/days";
6379
6380 dr.setPath (dir_days);
6381 if (! dr.exists())
6382 dr.mkpath (dir_days);
6383
6384 dir_sessions = dir_config + "/sessions";
6385
6386 dr.setPath (dir_sessions);
6387 if (! dr.exists())
6388 dr.mkpath (dir_sessions);
6389
6390 dir_themes = dir_config + "/themes";
6391
6392 dr.setPath (dir_themes);
6393 if (! dr.exists())
6394 dr.mkpath (dir_themes);
6395
6396 dir_hls = dir_config + "/hls";
6397
6398 dr.setPath (dir_hls);
6399 if (! dr.exists())
6400 dr.mkpath (dir_hls);
6401
6402 dir_palettes = dir_config + "/palettes";
6403
6404 dr.setPath (dir_palettes);
6405 if (! dr.exists())
6406 dr.mkpath (dir_palettes);
6407 }
6408
6409
6410
6411 #if defined (HUNSPELL_ENABLE) || defined (ASPELL_ENABLE)
6412
setup_spellcheckers()6413 void CTEA::setup_spellcheckers()
6414 {
6415
6416 #ifdef HUNSPELL_ENABLE
6417 spellcheckers.append ("Hunspell");
6418 #endif
6419
6420 #ifdef ASPELL_ENABLE
6421 spellcheckers.append ("Aspell");
6422 #endif
6423
6424 cur_spellchecker = settings->value ("cur_spellchecker", "Hunspell").toString();
6425
6426 if (spellcheckers.size() > 0)
6427 if (! spellcheckers.contains (cur_spellchecker))
6428 cur_spellchecker = spellcheckers[0];
6429
6430 #ifdef ASPELL_ENABLE
6431 if (cur_spellchecker == "Aspell")
6432 {
6433 QString lang = settings->value ("spell_lang", QLocale::system().name().left(2)).toString();
6434 #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
6435 QString win32_aspell_path = settings->value ("win32_aspell_path", aspell_default_dict_path()).toString();
6436 spellchecker = new CAspellchecker (lang, win32_aspell_path);
6437 #else
6438 spellchecker = new CAspellchecker (lang);
6439 #endif
6440 }
6441
6442 #endif
6443
6444
6445 #ifdef HUNSPELL_ENABLE
6446 if (cur_spellchecker == "Hunspell")
6447 spellchecker = new CHunspellChecker (settings->value ("spell_lang", QLocale::system().name().left(2)).toString(), settings->value ("hunspell_dic_path", hunspell_default_dict_path()).toString(), dir_user_dict);
6448 #endif
6449
6450 create_spellcheck_menu();
6451 }
6452
6453
create_spellcheck_menu()6454 void CTEA::create_spellcheck_menu()
6455 {
6456 menu_spell_langs->clear();
6457 spellchecker->get_speller_modules_list();
6458
6459 if (spellchecker->modules_list.size() > 0)
6460 create_menu_from_list (this, menu_spell_langs, spellchecker->modules_list, SLOT(fn_change_spell_lang()));
6461 }
6462
6463 #endif
6464
6465
create_main_widget_splitter()6466 void CTEA::create_main_widget_splitter()
6467 {
6468 QWidget *main_widget = new QWidget;
6469 QVBoxLayout *v_box = new QVBoxLayout;
6470 main_widget->setLayout (v_box);
6471
6472 main_tab_widget = new QTabWidget;
6473 main_tab_widget->setObjectName ("main_tab_widget");
6474 main_tab_widget->setTabShape (QTabWidget::Triangular);
6475
6476 tab_editor = new QTabWidget;
6477 tab_editor->setUsesScrollButtons (true);
6478
6479 #if (QT_VERSION_MAJOR >= 4 && QT_VERSION_MINOR >= 5)
6480 tab_editor->setMovable (true);
6481 #endif
6482
6483 tab_editor->setObjectName ("tab_editor");
6484
6485 QPushButton *bt_close = new QPushButton ("X", this);
6486 connect (bt_close, SIGNAL(clicked()), this, SLOT(file_close()));
6487 tab_editor->setCornerWidget (bt_close);
6488
6489 log = new CLogMemo;
6490
6491 connect (log, SIGNAL(double_click (QString)),
6492 this, SLOT(logmemo_double_click (QString)));
6493
6494 mainSplitter = new QSplitter (Qt::Vertical);
6495 v_box->addWidget (mainSplitter);
6496
6497 main_tab_widget->setMinimumHeight (10);
6498 log->setMinimumHeight (10);
6499
6500 mainSplitter->addWidget (main_tab_widget);
6501 mainSplitter->addWidget (log);
6502
6503 // FIF creation code
6504
6505 if (! settings->value ("fif_at_toolbar", 0).toBool())
6506 {
6507 cmb_fif = new QComboBox;
6508 cmb_fif->setInsertPolicy (QComboBox::InsertAtTop);
6509 cmb_fif->setObjectName ("FIF");
6510
6511 cmb_fif->setEditable (true);
6512 cmb_fif->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed);
6513
6514 fif = cmb_fif->lineEdit();
6515 fif->setStatusTip (tr ("The famous input field. Use for search/replace, function parameters"));
6516
6517 connect (fif, SIGNAL(returnPressed()), this, SLOT(search_find()));
6518
6519 QHBoxLayout *lt_fte = new QHBoxLayout;
6520
6521 v_box->addLayout (lt_fte, 0);
6522
6523 int tleft = 1;
6524 int tright = 1;
6525 int ttop = 1;
6526 int tbottom = 1;
6527
6528 v_box->getContentsMargins(&tleft, &ttop, &tright, &tbottom);
6529 v_box->setContentsMargins(tleft, 1, tright, 1);
6530
6531 QToolBar *tb_fif = new QToolBar;
6532
6533 QAction *act_fif_find = tb_fif->addAction (style()->standardIcon(QStyle::SP_ArrowForward), "");
6534 act_fif_find->setToolTip (tr ("Find"));
6535 connect (act_fif_find, SIGNAL(triggered()), this, SLOT(search_find()));
6536
6537 QAction *act_fif_find_prev = tb_fif->addAction (style()->standardIcon(QStyle::SP_ArrowUp), "");
6538 act_fif_find_prev->setToolTip (tr ("Find previous"));
6539 connect (act_fif_find_prev, SIGNAL(triggered()), this, SLOT(search_find_prev()));
6540
6541 QAction *act_fif_find_next = tb_fif->addAction (style()->standardIcon(QStyle::SP_ArrowDown), "");
6542 act_fif_find_next->setToolTip (tr ("Find next"));
6543 connect (act_fif_find_next, SIGNAL(triggered()), this, SLOT(search_find_next()));
6544
6545 QLabel *l_fif = new QLabel (tr ("FIF"));
6546
6547 lt_fte->addWidget (l_fif, 0, Qt::AlignRight);
6548 lt_fte->addWidget (cmb_fif, 0);
6549
6550 lt_fte->addWidget (tb_fif, 0);
6551 }
6552
6553 mainSplitter->setStretchFactor (1, 1);
6554
6555 idx_tab_edit = main_tab_widget->addTab (tab_editor, tr ("editor"));
6556 setCentralWidget (main_widget);
6557
6558 connect (tab_editor, SIGNAL(currentChanged(int)), this, SLOT(pageChanged(int)));
6559 }
6560
6561
create_main_widget_docked()6562 void CTEA::create_main_widget_docked()
6563 {
6564 setDockOptions (QMainWindow::AnimatedDocks | QMainWindow::AllowNestedDocks);
6565
6566 QWidget *main_widget = new QWidget;
6567 QVBoxLayout *v_box = new QVBoxLayout;
6568 main_widget->setLayout (v_box);
6569 setCentralWidget (main_widget);
6570
6571 main_tab_widget = new QTabWidget;
6572 main_tab_widget->setObjectName ("main_tab_widget");
6573 v_box->addWidget (main_tab_widget);
6574
6575 main_tab_widget->setTabShape (QTabWidget::Triangular);
6576
6577 tab_editor = new QTabWidget;
6578 tab_editor->setUsesScrollButtons (true);
6579
6580 //#if QT_VERSION >= 0x040500
6581 #if (QT_VERSION_MAJOR >= 4 && QT_VERSION_MINOR >= 5)
6582 tab_editor->setMovable (true);
6583 #endif
6584
6585 tab_editor->setObjectName ("tab_editor");
6586
6587 QPushButton *bt_close = new QPushButton ("X", this);
6588 connect (bt_close, SIGNAL(clicked()), this, SLOT(file_close()));
6589 tab_editor->setCornerWidget (bt_close);
6590
6591 QDockWidget *dock_logmemo = new QDockWidget (tr ("logmemo"), this);
6592 dock_logmemo->setFeatures (QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
6593 dock_logmemo->setAllowedAreas (Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
6594
6595 log = new CLogMemo (dock_logmemo);
6596
6597 connect (log, SIGNAL(double_click (QString)),
6598 this, SLOT(logmemo_double_click (QString)));
6599
6600 dock_logmemo->setWidget (log);
6601 dock_logmemo->setObjectName ("dock_log");
6602 addDockWidget (Qt::BottomDockWidgetArea, dock_logmemo);
6603
6604
6605 // FIF creation code
6606
6607 if (! settings->value ("fif_at_toolbar", 0).toBool())
6608 {
6609 QDockWidget *dock_fif = new QDockWidget (tr ("famous input field"), this);
6610 dock_fif->setAllowedAreas (Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
6611 dock_fif->setObjectName ("dock_fif");
6612 dock_fif->setFeatures (QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
6613
6614 QWidget *w_fif = new QWidget (dock_fif);
6615 w_fif->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Maximum);
6616
6617 cmb_fif = new QComboBox;
6618 cmb_fif->setObjectName ("FIF");
6619 cmb_fif->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed);
6620
6621 cmb_fif->setEditable (true);
6622 fif = cmb_fif->lineEdit();
6623 fif->setStatusTip (tr ("The famous input field. Use for search/replace, function parameters"));
6624
6625 connect (fif, SIGNAL(returnPressed()), this, SLOT(search_find()));
6626
6627 QHBoxLayout *lt_fte = new QHBoxLayout;
6628 w_fif->setLayout (lt_fte);
6629
6630 QToolBar *tb_fif = new QToolBar;
6631
6632 QAction *act_fif_find = tb_fif->addAction (style()->standardIcon(QStyle::SP_ArrowForward), "");
6633 act_fif_find->setToolTip (tr ("Find"));
6634 connect (act_fif_find, SIGNAL(triggered()), this, SLOT(search_find()));
6635
6636 QAction *act_fif_find_next = tb_fif->addAction (style()->standardIcon(QStyle::SP_ArrowDown), "");
6637 act_fif_find_next->setToolTip (tr ("Find next"));
6638 connect (act_fif_find_next, SIGNAL(triggered()), this, SLOT(search_find_next()));
6639
6640 QAction *act_fif_find_prev = tb_fif->addAction (style()->standardIcon(QStyle::SP_ArrowUp), "");
6641 act_fif_find_prev->setToolTip (tr ("Find previous"));
6642 connect (act_fif_find_prev, SIGNAL(triggered()), this, SLOT(search_find_prev()));
6643
6644 QLabel *l_fif = new QLabel (tr ("FIF"));
6645
6646 lt_fte->addWidget (l_fif, 0, Qt::AlignRight);
6647 lt_fte->addWidget (cmb_fif, 0);
6648 lt_fte->addWidget (tb_fif, 0);
6649
6650 dock_fif->setWidget (w_fif);
6651 addDockWidget (Qt::BottomDockWidgetArea, dock_fif);
6652 }
6653
6654 idx_tab_edit = main_tab_widget->addTab (tab_editor, tr ("editor"));
6655
6656 connect (tab_editor, SIGNAL(currentChanged(int)), this, SLOT(pageChanged(int)));
6657 }
6658
6659
create_actions()6660 void CTEA::create_actions()
6661 {
6662 icon_size = settings->value ("icon_size", "32").toInt();
6663
6664 act_test = new QAction (get_theme_icon("file-save.png"), tr ("Test"), this);
6665 connect (act_test, SIGNAL(triggered()), this, SLOT(test()));
6666
6667 filesAct = new QAction (get_theme_icon ("current-list.png"), tr ("Files"), this);
6668
6669 act_labels = new QAction (get_theme_icon ("labels.png"), tr ("Labels"), this);
6670 connect (act_labels, SIGNAL(triggered()), this, SLOT(nav_labels_update_list()));
6671
6672 newAct = new QAction (get_theme_icon ("file-new.png"), tr ("New"), this);
6673
6674 newAct->setShortcut (QKeySequence ("Ctrl+N"));
6675 newAct->setStatusTip (tr ("Create a new file"));
6676 connect (newAct, SIGNAL(triggered()), this, SLOT(file_new()));
6677
6678 QIcon ic_file_open = get_theme_icon ("file-open.png");
6679 ic_file_open.addFile (get_theme_icon_fname ("file-open-active.png"), QSize(), QIcon::Active);
6680
6681 openAct = new QAction (ic_file_open, tr ("Open file"), this);
6682
6683 openAct->setStatusTip (tr ("Open an existing file"));
6684 connect (openAct, SIGNAL(triggered()), this, SLOT(file_open()));
6685
6686 QIcon ic_file_save = get_theme_icon ("file-save.png");
6687 ic_file_save.addFile (get_theme_icon_fname ("file-save-active.png"), QSize(), QIcon::Active);
6688
6689 saveAct = new QAction (ic_file_save, tr ("Save"), this);
6690 saveAct->setShortcut (QKeySequence ("Ctrl+S"));
6691 saveAct->setStatusTip (tr ("Save the document to disk"));
6692 connect (saveAct, SIGNAL(triggered()), this, SLOT(file_save()));
6693
6694 saveAsAct = new QAction (get_theme_icon ("file-save-as.png"), tr ("Save As"), this);
6695 saveAsAct->setStatusTip (tr ("Save the document under a new name"));
6696 connect (saveAsAct, SIGNAL(triggered()), this, SLOT(file_save_as()));
6697
6698 exitAct = new QAction (tr ("Exit"), this);
6699 exitAct->setShortcut (QKeySequence ("Ctrl+Q"));
6700 exitAct->setStatusTip (tr ("Exit the application"));
6701 connect (exitAct, SIGNAL(triggered()), this, SLOT(close()));
6702
6703 QIcon ic_edit_cut = get_theme_icon ("edit-cut.png");
6704 ic_edit_cut.addFile (get_theme_icon_fname ("edit-cut-active.png"), QSize(), QIcon::Active);
6705
6706 cutAct = new QAction (ic_edit_cut, tr ("Cut"), this);
6707 cutAct->setShortcut (QKeySequence ("Ctrl+X"));
6708 cutAct->setStatusTip (tr ("Cut the current selection's contents to the clipboard"));
6709 connect (cutAct, SIGNAL(triggered()), this, SLOT(ed_cut()));
6710
6711 QIcon ic_edit_copy = get_theme_icon ("edit-copy.png");
6712 ic_edit_copy.addFile (get_theme_icon_fname ("edit-copy-active.png"), QSize(), QIcon::Active);
6713
6714 copyAct = new QAction (ic_edit_copy, tr("Copy"), this);
6715 copyAct->setShortcut (QKeySequence ("Ctrl+C"));
6716 copyAct->setStatusTip (tr ("Copy the current selection's contents to the clipboard"));
6717 connect (copyAct, SIGNAL(triggered()), this, SLOT(ed_copy()));
6718
6719 QIcon ic_edit_paste = get_theme_icon ("edit-paste.png");
6720 ic_edit_paste.addFile (get_theme_icon_fname ("edit-paste-active.png"), QSize(), QIcon::Active);
6721
6722 pasteAct = new QAction (ic_edit_paste, tr("Paste"), this);
6723 pasteAct->setShortcut (QKeySequence ("Ctrl+V"));
6724 pasteAct->setStatusTip (tr ("Paste the clipboard's contents into the current selection"));
6725 connect (pasteAct, SIGNAL(triggered()), this, SLOT(ed_paste()));
6726
6727 undoAct = new QAction (tr ("Undo"), this);
6728 undoAct->setShortcut (QKeySequence ("Ctrl+Z"));
6729 connect (undoAct, SIGNAL(triggered()), this, SLOT(ed_undo()));
6730
6731 redoAct = new QAction (tr ("Redo"), this);
6732 connect (redoAct, SIGNAL(triggered()), this, SLOT(ed_redo()));
6733
6734 aboutAct = new QAction (tr ("About"), this);
6735 connect (aboutAct, SIGNAL(triggered()), this, SLOT(help_show_about()));
6736
6737 aboutQtAct = new QAction (tr ("About Qt"), this);
6738 connect (aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
6739 }
6740
6741
create_menus()6742 void CTEA::create_menus()
6743 {
6744 /*
6745 ===================
6746 File menu
6747 ===================
6748 */
6749
6750 menu_file = menuBar()->addMenu (tr ("File"));
6751 menu_file->setTearOffEnabled (true);
6752
6753 // menu_file->addAction (act_test);
6754
6755 menu_file->addAction (newAct);
6756 add_to_menu (menu_file, tr ("Open"), SLOT(file_open()), "Ctrl+O", get_theme_icon_fname ("file-open.png"));
6757 add_to_menu (menu_file, tr ("Last closed file"), SLOT(file_last_opened()));
6758 add_to_menu (menu_file, tr ("Open at cursor"), SLOT(file_open_at_cursor()), "F2");
6759 add_to_menu (menu_file, tr ("Crapbook"), SLOT(file_crapbook()));
6760 add_to_menu (menu_file, tr ("Notes"), SLOT(file_notes()));
6761
6762 menu_file->addSeparator();
6763
6764 menu_file->addAction (saveAct);
6765 menu_file->addAction (saveAsAct);
6766
6767 QMenu *tm = menu_file->addMenu (tr ("Save as different"));
6768 tm->setTearOffEnabled (true);
6769
6770 add_to_menu (tm, tr ("Save .bak"), SLOT(file_save_bak()), "Ctrl+B");
6771 add_to_menu (tm, tr ("Save timestamped version"), SLOT(file_save_version()));
6772 add_to_menu (tm, tr ("Save session"), SLOT(file_session_save_as()));
6773
6774 menu_file->addSeparator();
6775
6776 menu_file_actions = menu_file->addMenu (tr ("File actions"));
6777 add_to_menu (menu_file_actions, tr ("Reload"), SLOT(file_reload()));
6778 add_to_menu (menu_file_actions, tr ("Reload with encoding"), SLOT(file_reload_enc()));
6779 menu_file_actions->addSeparator();
6780 add_to_menu (menu_file_actions, tr ("Set UNIX end of line"), SLOT(file_set_eol_unix()));
6781 add_to_menu (menu_file_actions, tr ("Set Windows end of line"), SLOT(file_set_eol_win()));
6782 add_to_menu (menu_file_actions, tr ("Set old Mac end of line (CR)"), SLOT(file_set_eol_mac()));
6783 menu_file_actions->addSeparator();
6784 add_to_menu (menu_file_actions, tr ("Set as autosaving file"), SLOT(file_set_autosaving_file()));
6785 add_to_menu (menu_file_actions, tr ("Unset the autosaving file"), SLOT(file_unset_autosaving_file()));
6786
6787
6788 menu_file_recent = menu_file->addMenu (tr ("Recent files"));
6789
6790 menu_file_bookmarks = menu_file->addMenu (tr ("Bookmarks"));
6791
6792 menu_file_edit_bookmarks = menu_file->addMenu (tr ("Edit bookmarks"));
6793 add_to_menu (menu_file_edit_bookmarks, tr ("Add to bookmarks"), SLOT(file_add_to_bookmarks()));
6794 add_to_menu (menu_file_edit_bookmarks, tr ("Find obsolete paths"), SLOT(file_find_obsolete_paths()));
6795
6796 menu_file_templates = menu_file->addMenu (tr ("Templates"));
6797 menu_file_sessions = menu_file->addMenu (tr ("Sessions"));
6798
6799 menu_file_configs = menu_file->addMenu (tr ("Configs"));
6800 add_to_menu (menu_file_configs, tr ("Bookmarks list"), SLOT(file_open_bookmarks_file()));
6801 add_to_menu (menu_file_configs, tr ("Programs list"), SLOT(file_open_programs_file()));
6802
6803 menu_file->addSeparator();
6804
6805 add_to_menu (menu_file, tr ("Do not add to recent"), SLOT(file_recent_off()))->setCheckable (true);
6806
6807 #ifdef PRINTER_ENABLE
6808 add_to_menu (menu_file, tr ("Print"), SLOT(file_print()));
6809 #endif
6810
6811 add_to_menu (menu_file, tr ("Close current"), SLOT(file_close()), "Ctrl+W");
6812
6813 menu_file->addAction (exitAct);
6814
6815 /*
6816 ===================
6817 Edit menu
6818 ===================
6819 */
6820
6821 menu_edit = menuBar()->addMenu (tr ("Edit"));
6822 menu_edit->setTearOffEnabled (true);
6823
6824 menu_edit->addAction (cutAct);
6825 menu_edit->addAction (copyAct);
6826 menu_edit->addAction (pasteAct);
6827
6828 menu_edit->addSeparator();
6829
6830 add_to_menu (menu_edit, tr ("Block start"), SLOT(ed_block_start()));
6831 add_to_menu (menu_edit, tr ("Block end"), SLOT(ed_block_end()));
6832 add_to_menu (menu_edit, tr ("Copy block"), SLOT(ed_block_copy()));
6833 add_to_menu (menu_edit, tr ("Paste block"), SLOT(ed_block_paste()));
6834 add_to_menu (menu_edit, tr ("Cut block"), SLOT(ed_block_cut()));
6835
6836 menu_edit->addSeparator();
6837
6838 add_to_menu (menu_edit, tr ("Copy current file name"), SLOT(ed_copy_current_fname()));
6839
6840 menu_edit->addSeparator();
6841
6842 menu_edit->addAction (undoAct);
6843 menu_edit->addAction (redoAct);
6844
6845 menu_edit->addSeparator();
6846
6847 add_to_menu (menu_edit, tr ("Indent (tab)"), SLOT(ed_indent()));
6848 add_to_menu (menu_edit, tr ("Un-indent (shift+tab)"), SLOT(ed_unindent()));
6849 add_to_menu (menu_edit, tr ("Indent by first line"), SLOT(ed_indent_by_first_line()));
6850
6851 menu_edit->addSeparator();
6852
6853 add_to_menu (menu_edit, tr ("Comment selection"), SLOT(ed_comment()));
6854
6855 menu_edit->addSeparator();
6856
6857 add_to_menu (menu_edit, tr ("Set as storage file"), SLOT(ed_set_as_storage_file()));
6858 add_to_menu (menu_edit, tr ("Copy to storage file"), SLOT(ed_copy_to_storage_file()));
6859 add_to_menu (menu_edit, tr ("Start/stop capture clipboard to storage file"), SLOT(ed_capture_clipboard_to_storage_file()))->setCheckable (true);
6860
6861
6862 /*
6863 ===================
6864 Markup menu
6865 ===================
6866 */
6867
6868 menu_markup = menuBar()->addMenu (tr ("Markup"));
6869 menu_markup->setTearOffEnabled (true);
6870
6871 tm = menu_markup->addMenu (tr ("Mode"));
6872 tm->setTearOffEnabled (true);
6873
6874 create_menu_from_list (this, tm,
6875 QString ("HTML XHTML Docbook LaTeX Markdown Lout DokuWiki MediaWiki").split (" "),
6876 SLOT (mrkup_mode_choosed()));
6877
6878 tm = menu_markup->addMenu (tr ("Header"));
6879 tm->setTearOffEnabled (true);
6880
6881 create_menu_from_list (this, tm,
6882 QString ("H1 H2 H3 H4 H5 H6").split (" "),
6883 SLOT (mrkup_header()));
6884
6885 tm = menu_markup->addMenu (tr ("Align"));
6886 tm->setTearOffEnabled (true);
6887
6888 add_to_menu (tm, tr ("Center"), SLOT(mrkup_align_center()));
6889 add_to_menu (tm, tr ("Left"), SLOT(mrkup_align_left()));
6890 add_to_menu (tm, tr ("Right"), SLOT(mrkup_align_right()));
6891 add_to_menu (tm, tr ("Justify"), SLOT(mrkup_align_justify()));
6892
6893 add_to_menu (menu_markup, tr ("Bold"), SLOT(mrkup_bold()), "Alt+B");
6894 add_to_menu (menu_markup, tr ("Italic"), SLOT(mrkup_italic()), "Alt+I");
6895 add_to_menu (menu_markup, tr ("Underline"), SLOT(mrkup_underline()));
6896
6897 add_to_menu (menu_markup, tr ("Link"), SLOT(mrkup_link()), "Alt+L");
6898 add_to_menu (menu_markup, tr ("Paragraph"), SLOT(mrkup_para()), "Alt+P");
6899 add_to_menu (menu_markup, tr ("Color"), SLOT(mrkup_color()));
6900
6901 add_to_menu (menu_markup, tr ("Break line"), SLOT(mrkup_br()), "Ctrl+Return");
6902 add_to_menu (menu_markup, tr ("Non-breaking space"), SLOT(mrkup_nbsp()), "Ctrl+Space");
6903 add_to_menu (menu_markup, tr ("Insert image"), SLOT(markup_ins_image()));
6904
6905 tm = menu_markup->addMenu (tr ("[X]HTML tools"));
6906 tm->setTearOffEnabled (true);
6907
6908 add_to_menu (tm, tr ("Text to [X]HTML"), SLOT(mrkup_text_to_html()));
6909 add_to_menu (tm, tr ("Convert tags to entities"), SLOT(mrkup_tags_to_entities()));
6910 add_to_menu (tm, tr ("Antispam e-mail"), SLOT(mrkup_antispam_email()));
6911 add_to_menu (tm, tr ("Document weight"), SLOT(mrkup_document_weight()));
6912 add_to_menu (tm, tr ("Preview selected color"), SLOT(mrkup_preview_color()));
6913 add_to_menu (tm, tr ("Strip HTML tags"), SLOT(mrkup_strip_html_tags()));
6914 add_to_menu (tm, tr ("Rename selected file"), SLOT(mrkup_rename_selected()));
6915
6916 /*
6917 ===================
6918 Search menu
6919 ===================
6920 */
6921
6922 menu_search = menuBar()->addMenu (tr ("Search"));
6923 menu_search->setTearOffEnabled (true);
6924
6925 add_to_menu (menu_search, tr ("Find"), SLOT(search_find()), "Ctrl+F");
6926 add_to_menu (menu_search, tr ("Find next"), SLOT(search_find_next()), "F3");
6927 add_to_menu (menu_search, tr ("Find previous"), SLOT(search_find_prev()),"Ctrl+F3");
6928
6929 menu_search->addSeparator();
6930
6931 add_to_menu (menu_search, tr ("Find in files"), SLOT(search_in_files()));
6932
6933 menu_search->addSeparator();
6934
6935 add_to_menu (menu_search, tr ("Replace with"), SLOT(search_replace_with()));
6936 add_to_menu (menu_search, tr ("Replace all"), SLOT(search_replace_all()));
6937 add_to_menu (menu_search, tr ("Replace all in opened files"), SLOT(search_replace_all_at_ofiles()));
6938
6939 menu_search->addSeparator();
6940
6941 add_to_menu (menu_search, tr ("Mark all found"), SLOT(search_mark_all()));
6942 add_to_menu (menu_search, tr ("Unmark"), SLOT(search_unmark()));
6943
6944 menu_search->addSeparator();
6945
6946 menu_find_case = menu_search->addAction (tr ("Case sensitive"));
6947 menu_find_case->setCheckable (true);
6948
6949 menu_find_whole_words = menu_search->addAction (tr ("Whole words"));
6950 menu_find_whole_words->setCheckable (true);
6951 connect (menu_find_whole_words, SIGNAL(triggered()), this, SLOT(search_whole_words_mode()));
6952
6953 menu_find_from_cursor = menu_search->addAction (tr ("From cursor"));
6954 menu_find_from_cursor->setCheckable (true);
6955 connect (menu_find_from_cursor, SIGNAL(triggered()), this, SLOT(search_from_cursor_mode()));
6956
6957 menu_find_regexp = menu_search->addAction (tr ("Regexp mode"));
6958 menu_find_regexp->setCheckable (true);
6959 connect (menu_find_regexp, SIGNAL(triggered()), this, SLOT(search_regexp_mode()));
6960
6961 menu_find_fuzzy = menu_search->addAction (tr ("Fuzzy mode"));
6962 menu_find_fuzzy->setCheckable (true);
6963 connect (menu_find_fuzzy, SIGNAL(triggered()), this, SLOT(search_fuzzy_mode()));
6964
6965
6966 /*
6967 ===================
6968 Functions menu
6969 ===================
6970 */
6971
6972
6973 menu_functions = menuBar()->addMenu (tr ("Functions"));
6974 menu_functions->setTearOffEnabled (true);
6975
6976 add_to_menu (menu_functions, tr ("Repeat last"), SLOT(fn_repeat()));
6977
6978 menu_instr = menu_functions->addMenu (tr ("Tools"));
6979 menu_instr->setTearOffEnabled (true);
6980 add_to_menu (menu_instr, tr ("Scale image"), SLOT(fn_scale_image()));
6981
6982 menu_fn_snippets = menu_functions->addMenu (tr ("Snippets"));
6983 menu_fn_scripts = menu_functions->addMenu (tr ("Scripts"));
6984 menu_fn_tables = menu_functions->addMenu (tr ("Tables"));
6985
6986 tm = menu_functions->addMenu (tr ("Place"));
6987 tm->setTearOffEnabled (true);
6988
6989 add_to_menu (tm, "Lorem ipsum", SLOT(fn_insert_loremipsum()));
6990 add_to_menu (tm, tr ("TEA project template"), SLOT(fn_insert_template_tea()));
6991 add_to_menu (tm, tr ("HTML template"), SLOT(fn_insert_template_html()));
6992 add_to_menu (tm, tr ("HTML5 template"), SLOT(fn_insert_template_html5()));
6993 add_to_menu (tm, tr ("C++ template"), SLOT(fn_insert_cpp()));
6994 add_to_menu (tm, tr ("C template"), SLOT(fn_insert_c()));
6995 add_to_menu (tm, tr ("Date"), SLOT(fn_insert_date()));
6996 add_to_menu (tm, tr ("Time"), SLOT(fn_insert_time()));
6997
6998
6999 tm = menu_functions->addMenu (tr ("Case"));
7000 tm->setTearOffEnabled (true);
7001
7002 add_to_menu (tm, tr ("UPCASE"), SLOT(fn_case_up()),"Ctrl+Up");
7003 add_to_menu (tm, tr ("lower case"), SLOT(fn_case_down()),"Ctrl+Down");
7004 add_to_menu (tm, tr ("Capitalize sentences"), SLOT(fn_case_cap_sentences()));
7005
7006
7007 tm = menu_functions->addMenu (tr ("Sort"));
7008 tm->setTearOffEnabled (true);
7009
7010 add_to_menu (tm, tr ("Sort case sensitively"), SLOT(fn_sort_casecare()));
7011 add_to_menu (tm, tr ("Sort case insensitively"), SLOT(fn_sort_casecareless()));
7012 add_to_menu (tm, tr ("Sort case sensitively, with separator"), SLOT(fn_sort_casecare_sep()));
7013 add_to_menu (tm, tr ("Sort by length"), SLOT(fn_sort_length()));
7014
7015 add_to_menu (tm, tr ("Flip a list"), SLOT(fn_flip_a_list()));
7016 add_to_menu (tm, tr ("Flip a list with separator"), SLOT(fn_flip_a_list_sep()));
7017
7018
7019 tm = menu_functions->addMenu (tr ("Cells"));
7020 tm->setTearOffEnabled (true);
7021
7022 add_to_menu (tm, tr ("Sort table by column ABC"), SLOT(fn_cells_latex_table_sort_by_col_abc()));
7023 add_to_menu (tm, tr ("Swap cells"), SLOT(fn_cells_swap_cells()));
7024 add_to_menu (tm, tr ("Delete by column"), SLOT(fn_cells_delete_by_col()));
7025 add_to_menu (tm, tr ("Copy by column[s]"), SLOT(fn_cells_copy_by_col()));
7026
7027
7028 tm = menu_functions->addMenu (tr ("Filter"));
7029 tm->setTearOffEnabled (true);
7030
7031 add_to_menu (tm, tr ("Remove duplicates"), SLOT(fn_filter_rm_duplicates()));
7032 add_to_menu (tm, tr ("Remove empty lines"), SLOT(fn_filter_rm_empty()));
7033 add_to_menu (tm, tr ("Remove lines < N size"), SLOT(fn_filter_rm_less_than()));
7034 add_to_menu (tm, tr ("Remove lines > N size"), SLOT(fn_filter_rm_greater_than()));
7035 add_to_menu (tm, tr ("Remove before delimiter at each line"), SLOT(fn_filter_delete_before_sep()));
7036 add_to_menu (tm, tr ("Remove after delimiter at each line"), SLOT(fn_filter_delete_after_sep()));
7037 add_to_menu (tm, tr ("Filter with regexp"), SLOT(fn_filter_with_regexp()));
7038 add_to_menu (tm, tr ("Filter by repetitions"), SLOT(fn_filter_by_repetitions()));
7039
7040
7041 tm = menu_functions->addMenu (tr ("Math"));
7042 tm->setTearOffEnabled (true);
7043
7044 add_to_menu (tm, tr ("Evaluate"), SLOT(fn_math_evaluate()), "F4");
7045 add_to_menu (tm, tr ("Arabic to Roman"), SLOT(fn_math_number_arabic_to_roman()));
7046 add_to_menu (tm, tr ("Roman to Arabic"), SLOT(fn_math_number_roman_to_arabic()));
7047 add_to_menu (tm, tr ("Decimal to binary"), SLOT(fn_math_number_dec_to_bin()));
7048 add_to_menu (tm, tr ("Binary to decimal"), SLOT(fn_math_number_bin_to_dec()));
7049 add_to_menu (tm, tr ("Flip bits (bitwise complement)"), SLOT(fn_math_number_flip_bits()));
7050 add_to_menu (tm, tr ("Enumerate"), SLOT(fn_math_enum()));
7051 add_to_menu (tm, tr ("Sum by last column"), SLOT(fn_math_sum_by_last_col()));
7052 add_to_menu (tm, tr ("deg min sec > dec degrees"), SLOT(fn_math_number_dms2dc()));
7053 add_to_menu (tm, tr ("dec degrees > deg min sec"), SLOT(fn_math_number_dd2dms()));
7054
7055
7056 tm = menu_functions->addMenu (tr ("Morse code"));
7057 tm->setTearOffEnabled (true);
7058
7059 add_to_menu (tm, tr ("From Russian to Morse"), SLOT(fn_morse_from_ru()));
7060 add_to_menu (tm, tr ("From Morse To Russian"), SLOT(fn_morse_to_ru()));
7061 add_to_menu (tm, tr ("From English to Morse"), SLOT(fn_morse_from_en()));
7062 add_to_menu (tm, tr ("From Morse To English"), SLOT(fn_morse_to_en()));
7063
7064
7065 tm = menu_functions->addMenu (tr ("Analyze"));
7066 tm->setTearOffEnabled (true);
7067
7068 add_to_menu (tm, tr ("Text statistics"), SLOT(fn_analyze_text_stat()));
7069 add_to_menu (tm, tr ("Extract words"), SLOT(fn_analyze_extract_words()));
7070 add_to_menu (tm, tr ("Words lengths"), SLOT(fn_analyze_stat_words_lengths()));
7071 add_to_menu (tm, tr ("Count the substring"), SLOT(fn_analyze_count()));
7072 add_to_menu (tm, tr ("Count the substring (regexp)"), SLOT(fn_analyze_count_rx()));
7073 add_to_menu (tm, tr ("UNITAZ quantity sorting"), SLOT(fn_analyze_get_words_count()));
7074 add_to_menu (tm, tr ("UNITAZ sorting by alphabet"), SLOT(fn_analyze_unitaz_abc()));
7075 add_to_menu (tm, tr ("UNITAZ sorting by length"), SLOT(fn_analyze_unitaz_len()));
7076
7077
7078 tm = menu_functions->addMenu (tr ("Text"));
7079 tm->setTearOffEnabled (true);
7080
7081 add_to_menu (tm, tr ("Apply to each line"), SLOT(fn_text_apply_to_each_line()),"Alt+E");
7082 add_to_menu (tm, tr ("Remove formatting"), SLOT(fn_text_remove_formatting()));
7083 add_to_menu (tm, tr ("Remove formatting at each line"), SLOT(fn_text_remove_formatting_at_each_line()));
7084 add_to_menu (tm, tr ("Remove trailing spaces"), SLOT(fn_text_remove_trailing_spaces()));
7085 add_to_menu (tm, tr ("Compress"), SLOT(fn_text_compress()));
7086 add_to_menu (tm, tr ("Anagram"), SLOT(fn_text_anagram()));
7087 add_to_menu (tm, tr ("Escape regexp"), SLOT(fn_text_escape()));
7088 add_to_menu (tm, tr ("Reverse"), SLOT(fn_text_reverse()));
7089 add_to_menu (tm, tr ("Compare two strings"), SLOT(fn_text_compare_two_strings()));
7090 add_to_menu (tm, tr ("Check regexp match"), SLOT(fn_text_regexp_match_check()));
7091
7092
7093 tm = menu_functions->addMenu (tr ("Quotes"));
7094 tm->setTearOffEnabled (true);
7095
7096 add_to_menu (tm, tr ("Straight to double angle quotes"), SLOT(fn_quotes_to_angle()));
7097 add_to_menu (tm, tr ("Straight to curly double quotes"), SLOT(fn_quotes_curly()));
7098 add_to_menu (tm, tr ("LaTeX: Straight to curly double quotes"), SLOT(fn_quotes_tex_curly()));
7099 add_to_menu (tm, tr ("LaTeX: Straight to double angle quotes"), SLOT(fn_quotes_tex_angle_01()));
7100 add_to_menu (tm, tr ("LaTeX: Straight to double angle quotes v2"), SLOT(fn_quotes_tex_angle_02()));
7101
7102
7103 #if defined (HUNSPELL_ENABLE) || defined (ASPELL_ENABLE)
7104 menu_functions->addSeparator();
7105
7106 menu_spell_langs = menu_functions->addMenu (tr ("Spell-checker languages"));
7107 menu_spell_langs->setTearOffEnabled (true);
7108
7109 add_to_menu (menu_functions, tr ("Spell check"), SLOT(fn_spell_check()), "", get_theme_icon_fname ("fn-spell-check.png"));
7110 add_to_menu (menu_functions, tr ("Suggest"), SLOT(fn_spell_suggest()));
7111 add_to_menu (menu_functions, tr ("Add to dictionary"), SLOT(fn_spell_add_to_dict()));
7112 add_to_menu (menu_functions, tr ("Remove from dictionary"), SLOT(fn_spell_remove_from_dict()));
7113
7114 menu_functions->addSeparator();
7115
7116 #endif
7117
7118
7119 /*
7120 ====================
7121 Cal menu
7122 ===================
7123 */
7124
7125 menu_cal = menuBar()->addMenu (tr ("Calendar"));
7126 menu_cal->setTearOffEnabled (true);
7127
7128 add_to_menu (menu_cal, tr ("Moon mode on/off"), SLOT(cal_moon_mode()));
7129 add_to_menu (menu_cal, tr ("Mark first date"), SLOT(cal_set_date_a()));
7130 add_to_menu (menu_cal, tr ("Mark last date"), SLOT(cal_set_date_b()));
7131
7132 menu_cal_add = menu_cal->addMenu (tr ("Add or subtract"));
7133 menu_cal_add->setTearOffEnabled (true);
7134
7135 add_to_menu (menu_cal_add, tr ("Days"), SLOT(cal_add_days()));
7136 add_to_menu (menu_cal_add, tr ("Months"), SLOT(cal_add_months()));
7137 add_to_menu (menu_cal_add, tr ("Years"), SLOT(cal_add_years()));
7138
7139 menu_cal->addSeparator();
7140
7141 add_to_menu (menu_cal, tr ("Go to current date"), SLOT(cal_set_to_current()));
7142 add_to_menu (menu_cal, tr ("Calculate moon days between dates"), SLOT(cal_gen_mooncal()));
7143 add_to_menu (menu_cal, tr ("Number of days between two dates"), SLOT(cal_diff_days()));
7144 add_to_menu (menu_cal, tr ("Remove day record"), SLOT(cal_remove()));
7145
7146 /*
7147 ====================
7148 Run menu
7149 ===================
7150 */
7151
7152 menu_programs = menuBar()->addMenu (tr ("Run"));
7153
7154 /*
7155 ====================
7156 IDE menu
7157 ===================
7158 */
7159
7160
7161 menu_ide = menuBar()->addMenu (tr ("IDE"));;
7162 menu_ide->setTearOffEnabled (true);
7163
7164 add_to_menu (menu_ide, tr ("Run program"), SLOT(ide_run()));
7165 add_to_menu (menu_ide, tr ("Build program"), SLOT(ide_build()));
7166 add_to_menu (menu_ide, tr ("Clean program"), SLOT(ide_clean()));
7167
7168 menu_ide->addSeparator();
7169
7170 add_to_menu (menu_ide, tr ("Toggle header/source"), SLOT(ide_toggle_hs()));
7171
7172 /*
7173 ===================
7174 Nav menu
7175 ===================
7176 */
7177
7178
7179 menu_nav = menuBar()->addMenu (tr ("Nav"));
7180 menu_nav->setTearOffEnabled (true);
7181
7182 add_to_menu (menu_nav, tr ("Save position"), SLOT(nav_save_pos()));
7183 add_to_menu (menu_nav, tr ("Go to saved position"), SLOT(nav_goto_pos()));
7184 add_to_menu (menu_nav, tr ("Go to line"), SLOT(nav_goto_line()),"Alt+G");
7185 add_to_menu (menu_nav, tr ("Next tab"), SLOT(nav_goto_right_tab()));
7186 add_to_menu (menu_nav, tr ("Prev tab"), SLOT(nav_goto_left_tab()));
7187 add_to_menu (menu_nav, tr ("Focus the Famous input field"), SLOT(nav_focus_to_fif()), "Ctrl+F");
7188 add_to_menu (menu_nav, tr ("Focus the editor"), SLOT(nav_focus_to_editor()));
7189
7190 menu_labels = menu_nav->addMenu (tr ("Labels"));
7191 add_to_menu (menu_nav, tr ("Refresh labels"), SLOT(nav_labels_update_list()));
7192
7193 menu_current_files = menu_nav->addMenu (tr ("Current files"));
7194
7195 /*
7196 ===================
7197 Fm menu callbacks
7198 ===================
7199 */
7200
7201 menu_fm = menuBar()->addMenu (tr ("Fm"));
7202 menu_fm->setTearOffEnabled (true);
7203
7204 menu_fm_multi_rename = menu_fm->addMenu (tr ("Multi-rename"));
7205 menu_fm_multi_rename->setTearOffEnabled (true);
7206
7207 add_to_menu (menu_fm_multi_rename, tr ("Zero pad file names"), SLOT(fman_multi_rename_zeropad()));
7208 add_to_menu (menu_fm_multi_rename, tr ("Delete N first chars at file names"), SLOT(fman_multi_rename_del_n_first_chars()));
7209 add_to_menu (menu_fm_multi_rename, tr ("Replace in file names"), SLOT(fman_multi_rename_replace()));
7210 add_to_menu (menu_fm_multi_rename, tr ("Apply template"), SLOT(fman_multi_rename_apply_template()));
7211
7212 menu_fm_file_ops = menu_fm->addMenu (tr ("File operations"));
7213 menu_fm_file_ops->setTearOffEnabled (true);
7214
7215 add_to_menu (menu_fm_file_ops, tr ("Create new directory"), SLOT(fman_fileop_create_dir()));
7216 add_to_menu (menu_fm_file_ops, tr ("Rename"), SLOT(fman_fileop_rename()));
7217 add_to_menu (menu_fm_file_ops, tr ("Delete file"), SLOT(fman_fileop_delete()));
7218
7219
7220 menu_fm_file_infos = menu_fm->addMenu (tr ("File information"));
7221 menu_fm_file_infos->setTearOffEnabled (true);
7222
7223 add_to_menu (menu_fm_file_infos, tr ("Count lines in selected files"), SLOT(fman_fileinfo_count_lines_in_selected_files()));
7224 add_to_menu (menu_fm_file_infos, tr ("Full info"), SLOT(fm_fileinfo_info()));
7225
7226 menu_fm_zip = menu_fm->addMenu (tr ("ZIP"));
7227 menu_fm_zip->setTearOffEnabled (true);
7228
7229 menu_fm_zip->addSeparator();
7230
7231 add_to_menu (menu_fm_zip, tr ("Create new ZIP"), SLOT(fman_zip_create()));
7232 add_to_menu (menu_fm_zip, tr ("Add to ZIP"), SLOT(fman_zip_add()));
7233 add_to_menu (menu_fm_zip, tr ("Save ZIP"), SLOT(fman_zip_save()));
7234
7235 menu_fm_zip->addSeparator();
7236
7237 add_to_menu (menu_fm_zip, tr ("List ZIP content"), SLOT(fman_zip_info()));
7238 add_to_menu (menu_fm_zip, tr ("Unpack ZIP to current directory"), SLOT(fman_zip_unpack()));
7239
7240 menu_fm_img_conv = menu_fm->addMenu (tr ("Images"));
7241 menu_fm_img_conv->setTearOffEnabled (true);
7242
7243 add_to_menu (menu_fm_img_conv, tr ("Scale by side"), SLOT(fman_img_conv_by_side()));
7244 add_to_menu (menu_fm_img_conv, tr ("Scale by percentages"), SLOT(fman_img_conv_by_percent()));
7245 add_to_menu (menu_fm_img_conv, tr ("Create web gallery"), SLOT(fman_img_make_gallery()));
7246
7247 add_to_menu (menu_fm, tr ("Go to home dir"), SLOT(fman_home()));
7248 add_to_menu (menu_fm, tr ("Refresh current dir"), SLOT(fman_refresh()));
7249 add_to_menu (menu_fm, tr ("Preview image"), SLOT(fman_preview_image()));
7250 add_to_menu (menu_fm, tr ("Select by regexp"), SLOT(fman_select_by_regexp()));
7251 add_to_menu (menu_fm, tr ("Deselect by regexp"), SLOT(fman_deselect_by_regexp()));
7252
7253 /*
7254 ===================
7255 View menu
7256 ===================
7257 */
7258
7259 menu_view = menuBar()->addMenu (tr ("View"));
7260 menu_view->setTearOffEnabled (true);
7261
7262 menu_view_themes = menu_view->addMenu (tr ("Themes"));
7263 menu_view_themes->setTearOffEnabled (true);
7264
7265 menu_view_palettes = menu_view->addMenu (tr ("Palettes"));
7266 menu_view_palettes->setTearOffEnabled (true);
7267
7268 //menu_view_hl = menu_view->addMenu (tr ("Highlighting mode"));
7269 //menu_view_hl->setTearOffEnabled (true);
7270
7271 menu_view_profiles = menu_view->addMenu (tr ("Profiles"));
7272 menu_view_profiles->setTearOffEnabled (true);
7273
7274 add_to_menu (menu_view, tr ("Save profile"), SLOT(view_profile_save_as()));
7275 add_to_menu (menu_view, tr ("Toggle word wrap"), SLOT(view_toggle_wrap()));
7276 add_to_menu (menu_view, tr ("Hide error marks"), SLOT(view_hide_error_marks()));
7277 add_to_menu (menu_view, tr ("Toggle fullscreen"), SLOT(view_toggle_fs()));
7278 add_to_menu (menu_view, tr ("Stay on top"), SLOT(view_stay_on_top()));
7279 add_to_menu (menu_view, tr ("Darker"), SLOT(view_darker()));
7280
7281 /*
7282 ===================
7283 ? menu
7284 ===================
7285 */
7286
7287 helpMenu = menuBar()->addMenu ("?");
7288 helpMenu->setTearOffEnabled (true);
7289
7290 helpMenu->addAction (aboutAct);
7291 helpMenu->addAction (aboutQtAct);
7292 add_to_menu (helpMenu, tr ("NEWS"), SLOT(help_show_news()));
7293 add_to_menu (helpMenu, "TODO", SLOT(help_show_todo()));
7294 add_to_menu (helpMenu, "ChangeLog", SLOT(help_show_changelog()));
7295 add_to_menu (helpMenu, tr ("License"), SLOT(help_show_gpl()));
7296 }
7297
7298
7299 /*************************
7300 ----------------------
7301 OPTIONS PAGE UI
7302 ----------------------
7303 *************************/
7304
create_options()7305 void CTEA::create_options()
7306 {
7307 tab_options = new QTabWidget;
7308
7309 idx_tab_tune = main_tab_widget->addTab (tab_options, tr ("options"));
7310
7311 /*
7312 ----------------------
7313 OPTIONS::INTERFACE
7314 ----------------------
7315 */
7316
7317 QWidget *page_interface = new QWidget (tab_options);
7318 page_interface->setObjectName ("page_interface");
7319
7320 QVBoxLayout *page_interface_layout = new QVBoxLayout;
7321 page_interface_layout->setAlignment (Qt::AlignTop);
7322
7323 QStringList sl_ui_modes;
7324 sl_ui_modes << tr ("Classic") << tr ("Docked");
7325
7326 cmb_ui_mode = new_combobox (page_interface_layout,
7327 tr ("UI mode (TEA restart needed)"),
7328 sl_ui_modes,
7329 settings->value ("ui_mode", 0).toInt());
7330
7331
7332 QStringList sl_lngs = read_dir_entries (":/translations");
7333
7334 for (QList <QString>::iterator i = sl_lngs.begin(); i != sl_lngs.end(); ++i)
7335 {
7336 (*i) = i->left(2);
7337 }
7338
7339 sl_lngs.append ("en");
7340
7341 QString lng = settings->value ("lng", QLocale::system().name()).toString().left(2).toLower();
7342
7343 if (! file_exists (":/translations/" + lng + ".qm"))
7344 lng = "en";
7345
7346 cmb_lng = new_combobox (page_interface_layout,
7347 tr ("UI language (TEA restart needed)"),
7348 sl_lngs,
7349 settings->value ("lng", lng).toString());
7350
7351
7352 QString default_style = qApp->style()->objectName();
7353 if (default_style == "GTK+") //can be buggy, so disable it
7354 default_style = "Cleanlooks";
7355
7356 cmb_styles = new_combobox (page_interface_layout,
7357 tr ("UI style (TEA restart needed)"),
7358 QStyleFactory::keys(),
7359 settings->value ("ui_style", default_style).toString());
7360
7361
7362 connect (cmb_styles, SIGNAL(currentIndexChanged (int)),
7363 this, SLOT(slot_style_currentIndexChanged (int)));
7364
7365
7366 QPushButton *bt_font_interface = new QPushButton (tr ("Interface font"), this);
7367 connect (bt_font_interface, SIGNAL(clicked()), this, SLOT(slot_font_interface_select()));
7368
7369 QPushButton *bt_font_editor = new QPushButton (tr ("Editor font"), this);
7370 connect (bt_font_editor, SIGNAL(clicked()), this, SLOT(slot_font_editor_select()));
7371
7372 QPushButton *bt_font_logmemo = new QPushButton (tr ("Logmemo font"), this);
7373 connect (bt_font_logmemo, SIGNAL(clicked()), this, SLOT(slot_font_logmemo_select()));
7374
7375 page_interface_layout->addWidget (bt_font_interface);
7376 page_interface_layout->addWidget (bt_font_editor);
7377 page_interface_layout->addWidget (bt_font_logmemo);
7378
7379 QStringList sl_tabs_align;
7380
7381 sl_tabs_align.append (tr ("Up"));
7382 sl_tabs_align.append (tr ("Bottom"));
7383 sl_tabs_align.append (tr ("Left"));
7384 sl_tabs_align.append (tr ("Right"));
7385
7386 int ui_tab_align = settings->value ("ui_tabs_align", "3").toInt();
7387 main_tab_widget->setTabPosition (int_to_tabpos (ui_tab_align ));
7388
7389 QComboBox *cmb_ui_tabs_align = new_combobox (page_interface_layout,
7390 tr ("GUI tabs align"),
7391 sl_tabs_align,
7392 ui_tab_align);
7393
7394 connect (cmb_ui_tabs_align, SIGNAL(currentIndexChanged (int)),
7395 this, SLOT(cmb_ui_tabs_currentIndexChanged (int)));
7396
7397 int docs_tab_align = settings->value ("docs_tabs_align", "0").toInt();
7398 tab_editor->setTabPosition (int_to_tabpos (docs_tab_align));
7399
7400
7401 QComboBox *cmb_docs_tabs_align = new_combobox (page_interface_layout,
7402 tr ("Documents tabs align"),
7403 sl_tabs_align,
7404 docs_tab_align);
7405
7406 connect (cmb_docs_tabs_align, SIGNAL(currentIndexChanged (int)),
7407 this, SLOT(cmb_docs_tabs_currentIndexChanged (int)));
7408
7409
7410 QStringList sl_icon_sizes;
7411 sl_icon_sizes << "16" << "24" << "32" << "48" << "64";
7412
7413 cmb_icon_size = new_combobox (page_interface_layout,
7414 tr ("Icons size"),
7415 sl_icon_sizes,
7416 settings->value ("icon_size", "32").toString());
7417
7418 connect (cmb_icon_size, SIGNAL(currentIndexChanged (int)),
7419 this, SLOT(cmb_icon_sizes_currentIndexChanged (int)));
7420
7421 QStringList sl_tea_icons;
7422 sl_tea_icons.append ("1");
7423 sl_tea_icons.append ("2");
7424 sl_tea_icons.append ("3");
7425
7426 cmb_tea_icons = new_combobox (page_interface_layout,
7427 tr ("TEA program icon"),
7428 sl_tea_icons,
7429 settings->value ("icon_fname", "1").toString());
7430
7431 connect (cmb_tea_icons, SIGNAL(currentIndexChanged (int)),
7432 this, SLOT(cmb_tea_icons_currentIndexChanged (int)));
7433
7434 cb_fif_at_toolbar = new QCheckBox (tr ("FIF at the top (restart needed)"), tab_options);
7435 cb_fif_at_toolbar->setChecked (settings->value ("fif_at_toolbar", "0").toBool());
7436 page_interface_layout->addWidget (cb_fif_at_toolbar);
7437
7438 cb_show_linenums = new QCheckBox (tr ("Show line numbers"), tab_options);
7439 cb_show_linenums->setChecked (settings->value ("show_linenums", "0").toBool());
7440 page_interface_layout->addWidget (cb_show_linenums);
7441
7442 cb_wordwrap = new QCheckBox (tr ("Word wrap"), tab_options);
7443 cb_wordwrap->setChecked (settings->value ("word_wrap", "1").toBool());
7444 page_interface_layout->addWidget (cb_wordwrap);
7445
7446 cb_hl_enabled = new QCheckBox (tr ("Syntax highlighting enabled"), tab_options);
7447 cb_hl_enabled->setChecked (settings->value ("hl_enabled", "1").toBool());
7448 page_interface_layout->addWidget (cb_hl_enabled);
7449
7450 cb_hl_current_line = new QCheckBox (tr ("Highlight current line"), tab_options);
7451 cb_hl_current_line->setChecked (settings->value ("additional_hl", "0").toBool());
7452 page_interface_layout->addWidget (cb_hl_current_line);
7453
7454 cb_hl_brackets = new QCheckBox (tr ("Highlight paired brackets"), tab_options);
7455 cb_hl_brackets->setChecked (settings->value ("hl_brackets", "0").toBool());
7456 page_interface_layout->addWidget (cb_hl_brackets);
7457
7458 cb_auto_indent = new QCheckBox (tr ("Automatic indent"), tab_options);
7459 cb_auto_indent->setChecked (settings->value ("auto_indent", "0").toBool());
7460 page_interface_layout->addWidget (cb_auto_indent);
7461
7462 cb_spaces_instead_of_tabs = new QCheckBox (tr ("Use spaces instead of tabs"), tab_options);
7463 cb_spaces_instead_of_tabs->setChecked (settings->value ("spaces_instead_of_tabs", "1").toBool());
7464 page_interface_layout->addWidget (cb_spaces_instead_of_tabs);
7465
7466 spb_tab_sp_width = new_spin_box (page_interface_layout,
7467 tr ("Tab width in spaces"), 1, 64,
7468 settings->value ("tab_sp_width", 8).toInt());
7469
7470 cb_cursor_xy_visible = new QCheckBox (tr ("Show cursor position"), tab_options);
7471 cb_cursor_xy_visible->setChecked (settings->value ("cursor_xy_visible", "1").toBool());
7472 page_interface_layout->addWidget (cb_cursor_xy_visible);
7473
7474 cb_center_on_cursor = new QCheckBox (tr ("Cursor center on scroll"), tab_options);
7475 cb_center_on_cursor->setChecked (settings->value ("center_on_scroll", "1").toBool());
7476 page_interface_layout->addWidget (cb_center_on_cursor);
7477
7478 spb_cursor_blink_time = new_spin_box (page_interface_layout,
7479 tr ("Cursor blink time (msecs, zero is OFF)"), 0, 10000,
7480 settings->value ("cursor_blink_time", 0).toInt());
7481
7482
7483 spb_cursor_width = new_spin_box (page_interface_layout,
7484 tr ("Cursor width"), 1, 5,
7485 settings->value ("cursor_width", 2).toInt());
7486
7487
7488
7489 cb_show_margin = new QCheckBox (tr ("Show margin at"), tab_options);
7490 cb_show_margin->setChecked (settings->value ("show_margin", "0").toBool());
7491
7492 spb_margin_pos = new QSpinBox;
7493 spb_margin_pos->setValue (settings->value ("margin_pos", 72).toInt());
7494
7495 QHBoxLayout *lt_margin = new QHBoxLayout;
7496
7497 lt_margin->insertWidget (-1, cb_show_margin, 0, Qt::AlignLeft);
7498 lt_margin->insertWidget (-1, spb_margin_pos, 1, Qt::AlignLeft);
7499
7500 page_interface_layout->addLayout (lt_margin);
7501
7502 cb_full_path_at_window_title = new QCheckBox (tr ("Show full path at window title"), tab_options);
7503 cb_full_path_at_window_title->setChecked (settings->value ("full_path_at_window_title", "1").toBool());
7504 page_interface_layout->addWidget (cb_full_path_at_window_title);
7505
7506 page_interface->setLayout (page_interface_layout);
7507 page_interface->show();
7508
7509
7510 QScrollArea *scra_interface = new QScrollArea;
7511 scra_interface->setWidgetResizable (true);
7512 scra_interface->setWidget (page_interface);
7513
7514 tab_options->addTab (scra_interface, tr ("Interface"));
7515
7516 /*
7517 ----------------------
7518 OPTIONS::COMMON
7519 ----------------------
7520 */
7521
7522 QWidget *page_common = new QWidget (tab_options);
7523 QVBoxLayout *page_common_layout = new QVBoxLayout;
7524 page_common_layout->setAlignment (Qt::AlignTop);
7525
7526 cb_altmenu = new QCheckBox (tr ("Use Alt key to access main menu"), tab_options);
7527 cb_altmenu->setChecked (MyProxyStyle::b_altmenu);
7528
7529 connect (cb_altmenu, SIGNAL(stateChanged (int)),
7530 this, SLOT(cb_altmenu_stateChanged (int)));
7531
7532 cb_wasd = new QCheckBox (tr ("Use Left Alt + WASD as additional cursor keys"), tab_options);
7533 cb_wasd->setChecked (settings->value ("wasd", "0").toBool());
7534
7535
7536 #if defined(JOYSTICK_SUPPORTED)
7537
7538 cb_use_joystick = new QCheckBox (tr ("Use joystick as cursor keys"), tab_options);
7539 cb_use_joystick->setChecked (settings->value ("use_joystick", "0").toBool());
7540 connect (cb_use_joystick, SIGNAL(stateChanged (int)),
7541 this, SLOT(cb_use_joystick_stateChanged (int)));
7542 #endif
7543
7544 cb_auto_img_preview = new QCheckBox (tr ("Automatic preview images at file manager"), tab_options);
7545 cb_auto_img_preview->setChecked (settings->value ("b_preview", "0").toBool());
7546
7547 cb_session_restore = new QCheckBox (tr ("Restore the last session on start-up"), tab_options);
7548 cb_session_restore->setChecked (settings->value ("session_restore", "0").toBool());
7549
7550 cb_use_enca_for_charset_detection = new QCheckBox (tr ("Use Enca for charset detection"), tab_options);
7551 cb_use_enca_for_charset_detection->setChecked (settings->value ("use_enca_for_charset_detection", 0).toBool());
7552
7553 cb_override_img_viewer = new QCheckBox (tr ("Use external image viewer for F2"), tab_options);
7554 cb_override_img_viewer->setChecked (settings->value ("override_img_viewer", 0).toBool());
7555
7556 ed_img_viewer_override = new QLineEdit (this);
7557 ed_img_viewer_override->setText (settings->value ("img_viewer_override_command", "display %s").toString());
7558
7559 QHBoxLayout *hb_imgvovr = new QHBoxLayout;
7560
7561 hb_imgvovr->addWidget (cb_override_img_viewer);
7562 hb_imgvovr->addWidget (ed_img_viewer_override);
7563
7564 hb_imgvovr->insertWidget (-1, cb_override_img_viewer, 0, Qt::AlignLeft);
7565 hb_imgvovr->insertWidget (-1, ed_img_viewer_override, 1, Qt::AlignLeft);
7566
7567 cb_use_trad_dialogs = new QCheckBox (tr ("Use traditional File Save/Open dialogs"), tab_options);
7568 cb_use_trad_dialogs->setChecked (settings->value ("use_trad_dialogs", "0").toBool());
7569
7570 cb_start_on_sunday = new QCheckBox (tr ("Start week on Sunday"), tab_options);
7571 cb_start_on_sunday->setChecked (settings->value ("start_week_on_sunday", "0").toBool());
7572
7573 cb_northern_hemisphere = new QCheckBox (tr ("Northern hemisphere"), this);
7574 cb_northern_hemisphere->setChecked (settings->value ("northern_hemisphere", "1").toBool());
7575
7576 page_common_layout->addWidget (cb_start_on_sunday);
7577 page_common_layout->addWidget (cb_northern_hemisphere);
7578
7579 QStringList sl_moon_algos;
7580 sl_moon_algos << "0" << "1" << "2" << "3";
7581
7582 /*
7583 cmb_moon_phase_algos = new_combobox (page_common_layout,
7584 tr ("Moon phase algorithm"),
7585 moon_phase_algos.values(),
7586 settings->value ("moon_phase_algo", MOON_PHASE_TRIG2).toInt());
7587 */
7588
7589
7590 cmb_moon_phase_algos = new_combobox (page_common_layout,
7591 tr ("Moon phase algorithm"),
7592 sl_moon_algos,
7593 settings->value ("moon_phase_algo", MOON_PHASE_TRIG2).toInt());
7594
7595 cmb_moon_phase_algos->setToolTip (tr ("0 - Trigonometrical v2, 1 - Trigonometrical v1, 2 - Conway, 3 - Leueshkanov"));
7596
7597
7598 cmb_cmdline_default_charset = new_combobox (page_common_layout,
7599 tr ("Charset for file open from command line"),
7600 sl_charsets,
7601 sl_charsets.indexOf (settings->value ("cmdline_default_charset", "UTF-8").toString()));
7602
7603 cmb_zip_charset_in = new_combobox (page_common_layout,
7604 tr ("ZIP unpacking: file names charset"),
7605 sl_charsets,
7606 sl_charsets.indexOf (settings->value ("zip_charset_in", "UTF-8").toString()));
7607
7608
7609 cmb_zip_charset_out = new_combobox (page_common_layout,
7610 tr ("ZIP packing: file names charset"),
7611 sl_charsets,
7612 sl_charsets.indexOf (settings->value ("zip_charset_out", "UTF-8").toString()));
7613
7614 page_common_layout->addWidget (cb_altmenu);
7615 page_common_layout->addWidget (cb_wasd);
7616
7617 #if defined(JOYSTICK_SUPPORTED)
7618 page_common_layout->addWidget (cb_use_joystick);
7619 #endif
7620
7621 page_common_layout->addWidget (cb_auto_img_preview);
7622 page_common_layout->addWidget (cb_session_restore);
7623 page_common_layout->addWidget (cb_use_trad_dialogs);
7624 page_common_layout->addWidget (cb_use_enca_for_charset_detection);
7625
7626 page_common_layout->addLayout (hb_imgvovr);
7627
7628
7629
7630 QGroupBox *gb_common_autosave = new QGroupBox (tr ("Autosaving"));
7631 QVBoxLayout *vb_common_autosave = new QVBoxLayout;
7632 vb_common_autosave->setAlignment (Qt::AlignTop);
7633 gb_common_autosave->setLayout (vb_common_autosave);
7634
7635 cb_save_buffers = new QCheckBox (tr ("Temporary save unsaved buffers on exit"), tab_options);
7636 cb_save_buffers->setChecked (settings->value ("save_buffers", "0").toBool());
7637 vb_common_autosave->addWidget (cb_save_buffers);
7638
7639 cb_autosave = new QCheckBox (tr ("Autosave buffers and autosaving files (each N seconds)"), tab_options);
7640 cb_autosave->setChecked (settings->value ("autosave", "0").toBool());
7641
7642 spb_autosave_period = new QSpinBox;
7643 spb_autosave_period->setMinimum (5);
7644 spb_autosave_period->setValue (settings->value ("autosave_period", 30).toInt());
7645
7646 QHBoxLayout *lt_autosave = new QHBoxLayout;
7647
7648 lt_autosave->insertWidget (-1, cb_autosave, 0, Qt::AlignLeft);
7649 lt_autosave->insertWidget (-1, spb_autosave_period, 1, Qt::AlignLeft);
7650
7651 vb_common_autosave->addLayout (lt_autosave);
7652
7653
7654
7655 page_common_layout->addWidget (gb_common_autosave);
7656
7657
7658 page_common->setLayout (page_common_layout);
7659 page_common->show();
7660
7661 QScrollArea *scra_common = new QScrollArea;
7662 scra_common->setWidgetResizable (true);
7663 scra_common->setWidget (page_common);
7664
7665 tab_options->addTab (scra_common, tr ("Common"));
7666
7667
7668 /*
7669 ----------------------
7670 OPTIONS::FUNCTIONS
7671 ----------------------
7672 */
7673
7674 QWidget *page_functions = new QWidget (tab_options);
7675 QVBoxLayout *page_functions_layout = new QVBoxLayout;
7676 page_functions_layout->setAlignment (Qt::AlignTop);
7677
7678 QGroupBox *gb_labels = new QGroupBox (tr ("Labels"));
7679 QVBoxLayout *vb_labels = new QVBoxLayout;
7680 gb_labels->setLayout (vb_labels);
7681
7682 ed_label_start = new_line_edit (vb_labels, tr ("Label starts with: "), settings->value ("label_start", "[?").toString());
7683 ed_label_end = new_line_edit (vb_labels, tr ("Label ends with: "), settings->value ("label_end", "?]").toString());
7684
7685 page_functions_layout->addWidget (gb_labels);
7686
7687 QGroupBox *gb_datetime = new QGroupBox (tr ("Date and time"));
7688 QVBoxLayout *vb_datetime = new QVBoxLayout;
7689 gb_datetime->setLayout (vb_datetime);
7690
7691 ed_date_format = new_line_edit (vb_datetime, tr ("Date format"), settings->value ("date_format", "dd/MM/yyyy").toString());
7692 ed_time_format = new_line_edit (vb_datetime, tr ("Time format"), settings->value ("time_format", "hh:mm:ss").toString());
7693
7694 page_functions_layout->addWidget (gb_datetime);
7695
7696 QLabel *l_t = 0;
7697
7698 #if defined (HUNSPELL_ENABLE) || defined (ASPELL_ENABLE)
7699
7700 QGroupBox *gb_spell = new QGroupBox (tr ("Spell checking"));
7701 QVBoxLayout *vb_spell = new QVBoxLayout;
7702 gb_spell->setLayout(vb_spell);
7703
7704 QHBoxLayout *hb_spellcheck_engine = new QHBoxLayout;
7705
7706 cmb_spellcheckers = new_combobox (hb_spellcheck_engine,
7707 tr ("Spell checker engine"),
7708 spellcheckers,
7709 cur_spellchecker);
7710
7711 vb_spell->addLayout (hb_spellcheck_engine);
7712
7713 #ifdef HUNSPELL_ENABLE
7714
7715 QHBoxLayout *hb_spellcheck_path = new QHBoxLayout;
7716 l_t = new QLabel (tr ("Hunspell dictionaries directory"));
7717
7718 ed_spellcheck_path = new QLineEdit (this);
7719
7720 ed_spellcheck_path->setText (settings->value ("hunspell_dic_path", hunspell_default_dict_path()).toString());/*QDir::homePath ()).toString()*/
7721 ed_spellcheck_path->setReadOnly (true);
7722
7723 QPushButton *pb_choose_path = new QPushButton (tr ("Select"), this);
7724
7725 connect (pb_choose_path, SIGNAL(clicked()), this, SLOT(pb_choose_hunspell_path_clicked()));
7726
7727 hb_spellcheck_path->addWidget (l_t);
7728 hb_spellcheck_path->addWidget (ed_spellcheck_path);
7729 hb_spellcheck_path->addWidget (pb_choose_path);
7730
7731 vb_spell->addLayout (hb_spellcheck_path);
7732
7733 #endif
7734
7735
7736 #ifdef ASPELL_ENABLE
7737
7738 #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
7739
7740 QHBoxLayout *hb_aspellcheck_path = new QHBoxLayout;
7741 l_t = new QLabel (tr ("Aspell directory"));
7742
7743 ed_aspellcheck_path = new QLineEdit (this);
7744 ed_aspellcheck_path->setText (settings->value ("win32_aspell_path", aspell_default_dict_path()).toString());
7745 ed_aspellcheck_path->setReadOnly (true);
7746
7747 QPushButton *pb_choose_path2 = new QPushButton (tr ("Select"), this);
7748
7749 connect (pb_choose_path2, SIGNAL(clicked()), this, SLOT(pb_choose_aspell_path_clicked()));
7750
7751 hb_aspellcheck_path->addWidget (l_t);
7752 hb_aspellcheck_path->addWidget (ed_aspellcheck_path);
7753 hb_aspellcheck_path->addWidget (pb_choose_path2);
7754
7755 vb_spell->addLayout (hb_aspellcheck_path);
7756
7757 #endif
7758
7759 #endif
7760
7761 connect (cmb_spellcheckers, SIGNAL(currentIndexChanged (int)),
7762 this, SLOT(cmb_spellchecker_currentIndexChanged (int)));
7763
7764 page_functions_layout->addWidget (gb_spell);
7765
7766 #endif
7767
7768
7769 QGroupBox *gb_func_misc = new QGroupBox (tr ("Miscellaneous"));
7770 QVBoxLayout *vb_func_misc = new QVBoxLayout;
7771 vb_func_misc->setAlignment (Qt::AlignTop);
7772 gb_func_misc->setLayout (vb_func_misc);
7773
7774 spb_fuzzy_q = new_spin_box (vb_func_misc, tr ("Fuzzy search factor"), 10, 100, settings->value ("fuzzy_q", "60").toInt());
7775
7776 page_functions_layout->addWidget (gb_func_misc);
7777
7778 page_functions->setLayout (page_functions_layout);
7779 page_functions->show();
7780
7781 QScrollArea *scra_functions = new QScrollArea;
7782 scra_functions->setWidgetResizable (true);
7783 scra_functions->setWidget (page_functions);
7784
7785 tab_options->addTab (scra_functions, tr ("Functions"));
7786
7787 /*
7788 ----------------------
7789 OPTIONS::IMAGES
7790 ----------------------
7791 */
7792
7793
7794 QWidget *page_images = new QWidget (tab_options);
7795 QVBoxLayout *page_images_layout = new QVBoxLayout;
7796 page_images_layout->setAlignment (Qt::AlignTop);
7797
7798 QGroupBox *gb_images = new QGroupBox (tr ("Miscellaneous"));
7799 QVBoxLayout *vb_images = new QVBoxLayout;
7800 vb_images->setAlignment (Qt::AlignTop);
7801
7802 gb_images->setLayout (vb_images);
7803
7804 cmb_output_image_fmt = new_combobox (vb_images,
7805 tr ("Image conversion output format"),
7806 bytearray_to_stringlist (QImageWriter::supportedImageFormats()),
7807 settings->value ("output_image_fmt", "jpg").toString());
7808
7809 cb_output_image_flt = new QCheckBox (tr ("Scale images with bilinear filtering"), this);
7810 cb_output_image_flt->setChecked (settings->value ("img_filter", 0).toBool());
7811
7812 vb_images->addWidget (cb_output_image_flt);
7813
7814 spb_img_quality = new_spin_box (vb_images, tr ("Output images quality"), -1, 100, settings->value ("img_quality", "-1").toInt());
7815
7816 cb_exif_rotate = new QCheckBox (tr ("Apply hard rotation by EXIF data"), this);
7817 cb_exif_rotate->setChecked (settings->value ("cb_exif_rotate", 1).toBool());
7818
7819 cb_output_image_flt = new QCheckBox (tr ("Scale images with bilinear filtering"), this);
7820 cb_output_image_flt->setChecked (settings->value ("img_filter", 0).toBool());
7821
7822 vb_images->addWidget (cb_output_image_flt);
7823
7824 cb_zip_after_scale = new QCheckBox (tr ("Zip directory with processed images"), this);
7825 cb_zip_after_scale->setChecked (settings->value ("img_post_proc", 0).toBool());
7826
7827 vb_images->addWidget (cb_zip_after_scale);
7828 vb_images->addWidget (cb_exif_rotate);
7829 page_images_layout->addWidget (gb_images);
7830
7831 QGroupBox *gb_webgallery = new QGroupBox (tr ("Web gallery options"));
7832 QVBoxLayout *vb_webgal = new QVBoxLayout;
7833 vb_webgal->setAlignment (Qt::AlignTop);
7834
7835 ed_side_size = new_line_edit (vb_webgal, tr ("Size of the side"), settings->value ("ed_side_size", "110").toString());
7836 ed_link_options = new_line_edit (vb_webgal, tr ("Link options"), settings->value ("ed_link_options", "target=\"_blank\"").toString());
7837 ed_cols_per_row = new_line_edit (vb_webgal, tr ("Columns per row"), settings->value ("ed_cols_per_row", "4").toString());
7838
7839 gb_webgallery->setLayout(vb_webgal);
7840 page_images_layout->addWidget (gb_webgallery);
7841
7842 QGroupBox *gb_exif = new QGroupBox (tr ("EXIF"));
7843 QVBoxLayout *vb_exif = new QVBoxLayout;
7844 gb_exif->setLayout(vb_exif);
7845 page_images_layout->addWidget (gb_exif);
7846
7847 cb_zor_use_exif= new QCheckBox (tr ("Use EXIF orientation at image viewer"), this);
7848 cb_zor_use_exif->setChecked (settings->value ("zor_use_exif_orientation", 0).toBool());
7849 vb_exif->addWidget (cb_zor_use_exif);
7850
7851
7852 page_images->setLayout (page_images_layout);
7853
7854 QScrollArea *scra_images = new QScrollArea;
7855 scra_images->setWidgetResizable (true);
7856 scra_images->setWidget (page_images);
7857
7858 tab_options->addTab (scra_images, tr ("Images"));
7859
7860
7861 /*
7862 ----------------------
7863 OPTIONS::KEYBOARD
7864 ----------------------
7865 */
7866
7867
7868 QWidget *page_keyboard = new QWidget (tab_options);
7869
7870 QHBoxLayout *lt_h = new QHBoxLayout;
7871 QHBoxLayout *lt_shortcut = new QHBoxLayout;
7872 QVBoxLayout *lt_vkeys = new QVBoxLayout;
7873 QVBoxLayout *lt_vbuttons = new QVBoxLayout;
7874
7875 lv_menuitems = new QListWidget;
7876
7877 lt_vkeys->addWidget (lv_menuitems);
7878
7879 connect (lv_menuitems, SIGNAL(currentItemChanged (QListWidgetItem *, QListWidgetItem *)),
7880 this, SLOT(slot_lv_menuitems_currentItemChanged (QListWidgetItem *, QListWidgetItem *)));
7881
7882 ent_shtcut = new CShortcutEntry;
7883 QLabel *l_shortcut = new QLabel (tr ("Shortcut"));
7884
7885 lt_shortcut->addWidget (l_shortcut);
7886 lt_shortcut->addWidget (ent_shtcut);
7887
7888 lt_vbuttons->addLayout (lt_shortcut);
7889
7890 QPushButton *pb_assign_hotkey = new QPushButton (tr ("Assign"), this);
7891 QPushButton *pb_remove_hotkey = new QPushButton (tr ("Remove"), this);
7892
7893 connect (pb_assign_hotkey, SIGNAL(clicked()), this, SLOT(pb_assign_hotkey_clicked()));
7894 connect (pb_remove_hotkey, SIGNAL(clicked()), this, SLOT(pb_remove_hotkey_clicked()));
7895
7896 lt_vbuttons->addWidget (pb_assign_hotkey);
7897 lt_vbuttons->addWidget (pb_remove_hotkey, 0, Qt::AlignTop);
7898
7899 lt_h->addLayout (lt_vkeys);
7900 lt_h->addLayout (lt_vbuttons);
7901
7902 page_keyboard->setLayout (lt_h);
7903 page_keyboard->show();
7904
7905 idx_tab_keyboard = tab_options->addTab (page_keyboard, tr ("Keyboard"));
7906 }
7907
7908
create_calendar()7909 void CTEA::create_calendar()
7910 {
7911 calendar = new CCalendarWidget (this, dir_days);
7912
7913 calendar->moon_mode = settings->value ("moon_mode", "0").toBool();
7914 calendar->northern_hemisphere = settings->value ("northern_hemisphere", "1").toBool();
7915 calendar->moon_phase_algo = settings->value ("moon_phase_algo", MOON_PHASE_TRIG2).toInt();
7916 calendar->setGridVisible (true);
7917 calendar->setVerticalHeaderFormat (QCalendarWidget::NoVerticalHeader);
7918
7919 if (settings->value ("start_on_sunday", "0").toBool())
7920 calendar->setFirstDayOfWeek (Qt::Sunday);
7921 else
7922 calendar->setFirstDayOfWeek (Qt::Monday);
7923
7924 connect (calendar, SIGNAL(clicked (QDate)), this, SLOT(calendar_clicked (QDate)));
7925 connect (calendar, SIGNAL(activated (QDate)), this, SLOT(calendar_activated (QDate)));
7926 connect (calendar, SIGNAL(currentPageChanged (int, int)), this, SLOT(calendar_currentPageChanged (int, int)));
7927
7928 idx_tab_calendar = main_tab_widget->addTab (calendar, tr ("dates"));
7929 }
7930
7931
create_toolbars()7932 void CTEA::create_toolbars()
7933 {
7934 openAct->setMenu (menu_file_recent);
7935 filesAct->setMenu (menu_current_files);
7936 act_labels->setMenu (menu_labels);
7937
7938 fileToolBar = addToolBar (tr ("File"));
7939 fileToolBar->setObjectName ("fileToolBar");
7940 fileToolBar->addAction (newAct);
7941 fileToolBar->addAction (openAct);
7942 fileToolBar->addAction (saveAct);
7943
7944 editToolBar = addToolBar (tr ("Edit"));
7945 editToolBar->setObjectName ("editToolBar");
7946 editToolBar->addAction (cutAct);
7947 editToolBar->addAction (copyAct);
7948 editToolBar->addAction (pasteAct);
7949
7950 if (! settings->value ("fif_at_toolbar", 0).toBool())
7951 {
7952 editToolBar->addSeparator();
7953 editToolBar->addAction (act_labels);
7954 }
7955
7956 filesToolBar = addToolBar (tr ("Files"));
7957 filesToolBar->setObjectName ("filesToolBar");
7958
7959 filesToolBar->setIconSize (QSize (icon_size, icon_size));
7960
7961 QToolButton *tb_current_list = new QToolButton();
7962 tb_current_list->setIcon (get_theme_icon ("current-list.png"));
7963
7964 tb_current_list->setMenu (menu_current_files);
7965 tb_current_list->setPopupMode(QToolButton::InstantPopup);
7966 filesToolBar->addWidget (tb_current_list);
7967
7968 if (settings->value ("fif_at_toolbar", 0).toBool())
7969 {
7970 fifToolBar = addToolBar (tr ("FIF"));
7971 fifToolBar->setObjectName ("fifToolBar");
7972
7973 cmb_fif = new QComboBox;
7974 cmb_fif->setInsertPolicy (QComboBox::InsertAtTop);
7975 cmb_fif->setObjectName ("FIF");
7976
7977 cmb_fif->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Fixed);
7978
7979 cmb_fif->setEditable (true);
7980 fif = cmb_fif->lineEdit();
7981 connect (fif, SIGNAL(returnPressed()), this, SLOT(search_find()));
7982
7983 fifToolBar->addWidget (cmb_fif);
7984
7985 QAction *act_fif_find = fifToolBar->addAction (style()->standardIcon(QStyle::SP_ArrowForward), "");
7986 act_fif_find->setToolTip (tr ("Find"));
7987 connect (act_fif_find, SIGNAL(triggered()), this, SLOT(search_find()));
7988
7989 QAction *act_fif_find_next = fifToolBar->addAction (style()->standardIcon(QStyle::SP_ArrowDown), "");
7990 act_fif_find_next->setToolTip (tr ("Find next"));
7991 connect (act_fif_find_next, SIGNAL(triggered()), this, SLOT(search_find_next()));
7992
7993 QAction *act_fif_find_prev = fifToolBar->addAction (style()->standardIcon(QStyle::SP_ArrowUp), "");
7994 act_fif_find_prev->setToolTip (tr ("Find previous"));
7995 connect (act_fif_find_prev, SIGNAL(triggered()), this, SLOT(search_find_prev()));
7996 }
7997 }
7998
7999
create_manual()8000 void CTEA::create_manual()
8001 {
8002 QWidget *wd_man = new QWidget (this);
8003
8004 QVBoxLayout *lv_t = new QVBoxLayout;
8005
8006 QString loc = QLocale::system().name().left (2).toLower();
8007 QString ts = settings->value ("lng", loc).toString();
8008
8009 QString filename (":/manuals/");
8010 filename = filename + ts + ".html";
8011
8012 if (! file_exists (filename))
8013 filename = ":/manuals/en.html";
8014
8015 man_search_value = "";
8016
8017 QHBoxLayout *lh_controls = new QHBoxLayout();
8018
8019 QPushButton *bt_back = new QPushButton ("<");
8020 QPushButton *bt_forw = new QPushButton (">");
8021
8022 lh_controls->addWidget (bt_back);
8023 lh_controls->addWidget (bt_forw);
8024
8025 man = new QTextBrowser;
8026 man->setOpenExternalLinks (true);
8027 man->setSource (QUrl ("qrc" + filename));
8028
8029 connect (bt_back, SIGNAL(clicked()), man, SLOT(backward()));
8030 connect (bt_forw, SIGNAL(clicked()), man, SLOT(forward()));
8031
8032 lv_t->addLayout (lh_controls);
8033 lv_t->addWidget (man);
8034
8035 wd_man->setLayout (lv_t);
8036
8037 idx_tab_learn = main_tab_widget->addTab (wd_man, tr ("manual"));
8038 }
8039
8040
create_fman()8041 void CTEA::create_fman()
8042 {
8043 QWidget *wd_fman = new QWidget (this);
8044
8045 QVBoxLayout *lav_main = new QVBoxLayout;
8046 QVBoxLayout *lah_controls = new QVBoxLayout;
8047 QHBoxLayout *lah_topbar = new QHBoxLayout;
8048
8049 QLabel *l_t = new QLabel (tr ("Name"));
8050 ed_fman_fname = new QLineEdit;
8051 connect (ed_fman_fname, SIGNAL(returnPressed()), this, SLOT(fman_fname_entry_confirm()));
8052
8053 ed_fman_path = new QLineEdit;
8054 connect (ed_fman_path, SIGNAL(returnPressed()), this, SLOT(fman_naventry_confirm()));
8055
8056 tb_fman_dir = new QToolBar;
8057 tb_fman_dir->setObjectName ("tb_fman_dir");
8058
8059 QAction *act_fman_go = new QAction (style()->standardIcon(QStyle::SP_ArrowForward), tr ("Go"), this);
8060 connect (act_fman_go, SIGNAL(triggered()), this, SLOT(fman_naventry_confirm()));
8061
8062 QAction *act_fman_home = new QAction (style()->standardIcon(QStyle::SP_DirHomeIcon), tr ("Home"), this);
8063 connect (act_fman_home, SIGNAL(triggered()), this, SLOT(fman_home()));
8064
8065 QAction *act_fman_refresh = new QAction (style()->standardIcon(QStyle::SP_BrowserReload), tr ("Refresh"), this);
8066 QAction *act_fman_ops = new QAction (style()->standardIcon(QStyle::SP_DriveHDIcon), tr ("Actions"), this);
8067 act_fman_ops->setMenu (menu_fm_file_ops);
8068
8069 tb_fman_dir->addAction (act_fman_go);
8070 tb_fman_dir->addAction (act_fman_home);
8071 tb_fman_dir->addAction (act_fman_refresh);
8072 tb_fman_dir->addAction (act_fman_ops);
8073
8074 #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
8075
8076 cb_fman_drives = new QComboBox;
8077 lah_topbar->addWidget (cb_fman_drives);
8078
8079 QFileInfoList l_drives = QDir::drives();
8080 for (QList <QFileInfo>::iterator fi = l_drives.begin(); fi != l_drives.end(); ++fi)
8081 cb_fman_drives->addItem (fi->path());
8082
8083 #endif
8084
8085 lah_topbar->addWidget (ed_fman_path);
8086 lah_topbar->addWidget (tb_fman_dir);
8087
8088 lah_controls->addWidget (l_t);
8089 lah_controls->addWidget (ed_fman_fname);
8090
8091 l_t = new QLabel (tr ("Charset"));
8092
8093 QPushButton *bt_magicenc = new QPushButton ("?", this);
8094 bt_magicenc->setToolTip (tr ("Guess encoding!"));
8095 connect (bt_magicenc, SIGNAL(clicked()), this, SLOT(guess_enc()));
8096
8097 /*
8098 #if QT_VERSION >= 0x051100
8099 bt_magicenc->setMaximumWidth (QApplication::fontMetrics().horizontalAdvance("???"));
8100 #else
8101 bt_magicenc->setMaximumWidth (QApplication::fontMetrics().width ("???"));
8102 #endif
8103 */
8104
8105 cb_fman_codecs = new QComboBox;
8106
8107 if (sl_last_used_charsets.size () > 0)
8108 cb_fman_codecs->addItems (sl_last_used_charsets + sl_charsets);
8109 else
8110 {
8111 cb_fman_codecs->addItems (sl_charsets);
8112 cb_fman_codecs->setCurrentIndex (sl_charsets.indexOf ("UTF-8"));
8113 }
8114
8115 QPushButton *bt_fman_open = new QPushButton (tr ("Open"), this);
8116 connect (bt_fman_open, SIGNAL(clicked()), this, SLOT(fman_open()));
8117 bt_fman_open->setToolTip (tr ("Open a file from the file name provided above"));
8118
8119 QPushButton *bt_fman_save_as = new QPushButton (tr ("Save as"), this);
8120 connect (bt_fman_save_as, SIGNAL(clicked()), this, SLOT(cb_button_saves_as()));
8121 bt_fman_save_as->setToolTip (tr ("Save the current opened file with the name provided above"));
8122
8123 lah_controls->addWidget (l_t);
8124
8125 QHBoxLayout *lt_hb = new QHBoxLayout;
8126
8127 lt_hb->addWidget (cb_fman_codecs);
8128 lt_hb->addWidget (bt_magicenc);
8129
8130 lah_controls->addLayout (lt_hb);
8131
8132 lah_controls->addWidget (bt_fman_open);
8133 lah_controls->addWidget (bt_fman_save_as);
8134
8135 fman = new CFMan;
8136
8137 connect (fman, SIGNAL(file_activated (QString)), this, SLOT(fman_file_activated (QString)));
8138 connect (fman, SIGNAL(dir_changed (QString)), this, SLOT(fman_dir_changed (QString)));
8139 connect (fman, SIGNAL(current_file_changed (QString, QString)), this, SLOT(fman_current_file_changed (QString, QString)));
8140
8141 connect (act_fman_refresh, SIGNAL(triggered()), fman, SLOT(refresh()));
8142
8143 #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
8144 connect (cb_fman_drives, SIGNAL(currentIndexChanged (QString)),
8145 this, SLOT(fman_drives_changed(QString)));
8146 #endif
8147
8148 w_right = new QWidget (this);
8149
8150 w_right->setMinimumWidth (10);
8151
8152 QVBoxLayout *lw_right = new QVBoxLayout;
8153 w_right->setLayout (lw_right);
8154 lw_right->addLayout (lah_controls);
8155
8156 QFrame *vline = new QFrame;
8157 vline->setFrameStyle (QFrame::HLine);
8158 lw_right->addWidget (vline);
8159
8160 QLabel *l_bookmarks = new QLabel (tr ("<b>Bookmarks</b>"));
8161 lw_right->addWidget (l_bookmarks);
8162
8163 QHBoxLayout *lah_places_bar = new QHBoxLayout;
8164 QPushButton *bt_add_bmk = new QPushButton ("+");
8165 QPushButton *bt_del_bmk = new QPushButton ("-");
8166 lah_places_bar->addWidget (bt_add_bmk);
8167 lah_places_bar->addWidget (bt_del_bmk);
8168
8169 connect (bt_add_bmk, SIGNAL(clicked()), this, SLOT(fman_add_bmk()));
8170 connect (bt_del_bmk, SIGNAL(clicked()), this, SLOT(fman_del_bmk()));
8171
8172 lv_places = new QListWidget;
8173 //lv_places->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn);
8174
8175 update_places_bookmarks();
8176 connect (lv_places, SIGNAL(itemActivated (QListWidgetItem *)), this, SLOT(fman_places_itemActivated (QListWidgetItem *)));
8177
8178 QVBoxLayout *vbox = new QVBoxLayout;
8179 vbox->addLayout (lah_places_bar);
8180 vbox->addWidget (lv_places);
8181
8182 lw_right->addLayout (vbox);
8183
8184 //commented out with Qt6
8185 // fman->setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
8186
8187 spl_fman = new QSplitter (this);
8188 spl_fman->setChildrenCollapsible (true);
8189
8190 spl_fman->addWidget (fman);
8191 spl_fman->addWidget (w_right);
8192
8193 spl_fman->restoreState (settings->value ("spl_fman").toByteArray());
8194
8195 lav_main->addLayout (lah_topbar);
8196 lav_main->addWidget (spl_fman);
8197
8198 wd_fman->setLayout (lav_main);
8199
8200 fman_home();
8201
8202 idx_tab_fman = main_tab_widget->addTab (wd_fman, tr ("files"));
8203 }
8204
8205
create_markup_hash()8206 void CTEA::create_markup_hash()
8207 {
8208 QHash<QString, QString> h1;
8209
8210 h1["Docbook"] = "<emphasis role=\"bold\">%s</emphasis>";
8211 h1["LaTeX"] = "\\textbf{%s}";
8212 h1["HTML"] = "<b>%s</b>";
8213 h1["XHTML"] = "<b>%s</b>";
8214 h1["Lout"] = "@B{%s}";
8215 h1["MediaWiki"] = "'''%s'''";
8216 h1["DokuWiki"] = "**%s**";
8217 h1["Markdown"] = "**%s**";
8218
8219 hash_markup.insert ("bold", h1);
8220
8221 QHash<QString, QString> h2;
8222
8223 h2["Docbook"] = "<emphasis role=\"italic\">%s</emphasis>";
8224 h2["LaTeX"] = "\\textit{%s}";
8225 h2["HTML"] = "<i>%s</i>";
8226 h2["XHTML"] = "<i>%s</i>";
8227 h2["Lout"] = "@I{%s}";
8228 h2["MediaWiki"] = "''%s''";
8229 h2["DokuWiki"] = "//%s//";
8230 h2["Markdown"] = "*%s*";
8231
8232 hash_markup.insert ("italic", h2);
8233
8234 QHash<QString, QString> h3;
8235
8236 h3["HTML"] = "<p style=\"text-align:justify;\">%s</p>";
8237 h3["XHTML"] = "<p style=\"text-align:justify;\">%s</p>";
8238
8239 hash_markup.insert ("align_justify", h3);
8240
8241 QHash<QString, QString> h4;
8242
8243 h4["LaTeX"] = "\\begin{center}%s\\end{center}";
8244 h4["HTML"] = "<p style=\"text-align:center;\">%s</p>";
8245 h4["XHTML"] = "<p style=\"text-align:center;\">%s</p>";
8246
8247 hash_markup.insert ("align_center", h4);
8248
8249 QHash<QString, QString> h5;
8250
8251 h5["LaTeX"] = "\\begin{flushleft}%s\\end{flushleft}";
8252 h5["HTML"] = "<p style=\"text-align:left;\">%s</p>";
8253 h5["XHTML"] = "<p style=\"text-align:left;\">%s</p>";
8254
8255 hash_markup.insert ("align_left", h5);
8256
8257 QHash<QString, QString> h6;
8258
8259 h6["LaTeX"] = "\\begin{flushright}%s\\end{flushright}";
8260 h6["HTML"] = "<p style=\"text-align:right;\">%s</p>";
8261 h6["XHTML"] = "<p style=\"text-align:right;\">%s</p>";
8262
8263 hash_markup.insert ("align_right", h6);
8264
8265 QHash<QString, QString> h7;
8266
8267 h7["Docbook"] = "<emphasis role=\"underline\">%s</emphasis>";
8268 h7["LaTeX"] = "\\underline{%s}";
8269 h7["HTML"] = "<u>%s</u>";
8270 h7["XHTML"] = "<u>%s</u>";
8271 h7["Lout"] = "@Underline{%s}";
8272 h7["MediaWiki"] = "<u>%s</u>";
8273 h7["DokuWiki"] = "__%s__";
8274
8275 hash_markup.insert ("underline", h7);
8276
8277 QHash<QString, QString> h8;
8278
8279 h8["Docbook"] = "<para>%s</para>";
8280 h8["HTML"] = "<p>%s</p>";
8281 h8["XHTML"] = "<p>%s</p>";
8282 h8["Lout"] = "@PP%s";
8283
8284 hash_markup.insert ("para", h8);
8285
8286 QHash<QString, QString> h9;
8287
8288 h9["Docbook"] = "<ulink url=\"\">%s</ulink>";
8289 h9["HTML"] = "<a href=\"\">%s</a>";
8290 h9["XHTML"] = "<a href=\"\">%s</a>";
8291 h9["LaTeX"] = "\\href{}{%s}";
8292 h9["Markdown"] = "[](%s)";
8293
8294 hash_markup.insert ("link", h9);
8295
8296 QHash<QString, QString> h10;
8297
8298 h10["LaTeX"] = "\\newline";
8299 h10["HTML"] = "<br>";
8300 h10["XHTML"] = "<br />";
8301 h10["Lout"] = "@LLP";
8302 h10["MediaWiki"] = "<br />";
8303 h10["DokuWiki"] = "\\\\ ";
8304 h10["Markdown"] = " \n";
8305
8306 hash_markup.insert ("newline", h10);
8307 }
8308
8309
update_stylesheet(const QString & f)8310 void CTEA::update_stylesheet (const QString &f)
8311 {
8312 //Update paletted stuff
8313
8314 int darker_val = settings->value ("darker_val", 100).toInt();
8315
8316 QFontInfo fi = QFontInfo (qApp->font());
8317
8318 QString fontsize = "font-size:" + settings->value ("app_font_size", fi.pointSize()).toString() + "pt;";
8319 QString fontfamily = "font-family:" + settings->value ("app_font_name", qApp->font().family()).toString() + ";";
8320
8321 QString edfontsize = "font-size:" + settings->value ("editor_font_size", "16").toString() + "pt;";
8322 QString edfontfamily = "font-family:" + settings->value ("editor_font_name", "Serif").toString() + ";";
8323
8324 QString logmemo_fontsize = "font-size:" + settings->value ("logmemo_font_size", "12").toString() + "pt;";
8325 QString logmemo_font = "font-family:" + settings->value ("logmemo_font", "Monospace").toString() + ";";
8326
8327 QString stylesheet;
8328
8329 stylesheet = "QWidget, QWidget * {" + fontfamily + fontsize + "}\n";
8330 stylesheet += "QPlainTextEdit, QPlainTextEdit * {" + edfontfamily + edfontsize + "}\n";
8331 stylesheet += "QTextEdit {" + edfontfamily + edfontsize + "}\n";
8332 stylesheet += "CLogMemo {" + logmemo_font + logmemo_fontsize + "}\n";
8333 stylesheet += "CLineNumberArea {" + edfontfamily + edfontsize + "}\n";
8334
8335 QString text_color = hash_get_val (global_palette, "text", "black");
8336 QString t_text_color = QColor (text_color).darker(darker_val).name();
8337
8338 QString back_color = hash_get_val (global_palette, "background", "white");
8339 QString t_back_color = QColor (back_color).darker(darker_val).name();
8340
8341 QString sel_back_color = hash_get_val (global_palette, "sel-background", "black");
8342 QString sel_text_color = hash_get_val (global_palette, "sel-text", "white");
8343
8344 QString t_sel_text_color = QColor (sel_text_color).darker(darker_val).name();
8345 QString t_sel_back_color = QColor (sel_back_color).darker(darker_val).name();
8346
8347 QString css_plain_text_edit = QString ("QPlainTextEdit {color: %1; background-color: %2; selection-color: %3; selection-background-color: %4;}\n").arg (
8348 t_text_color).arg (
8349 t_back_color).arg (
8350 t_sel_text_color).arg (
8351 t_sel_back_color);
8352
8353 stylesheet += css_plain_text_edit;
8354
8355 QString css_tea_edit = QString ("CTEAEdit {color: %1; background-color: %2; selection-color: %3; selection-background-color: %4;}\n").arg (
8356 t_text_color).arg (
8357 t_back_color).arg (
8358 t_sel_text_color).arg (
8359 t_sel_back_color);
8360
8361 stylesheet += css_tea_edit;
8362
8363 QString css_tea_man = QString ("QTextBrowser {color: %1; background-color: %2; selection-color: %3; selection-background-color: %4;}\n").arg (
8364 t_text_color).arg (
8365 t_back_color).arg (
8366 t_sel_text_color).arg (
8367 t_sel_back_color);
8368
8369 stylesheet += css_tea_man;
8370
8371 QString css_fif = QString ("QComboBox#FIF { color: %1; background-color: %2; selection-color: %3; selection-background-color: %4;}\n").arg (
8372 t_text_color).arg (
8373 t_back_color).arg (
8374 t_sel_text_color).arg (
8375 t_sel_back_color);
8376
8377 stylesheet += css_fif;
8378
8379 //Update themed stuff
8380
8381 QString cssfile = qstring_load (f);
8382 QString css_path = get_file_path (f) + "/";
8383
8384 cssfile = cssfile.replace ("./", css_path);
8385 cssfile += stylesheet;
8386
8387 qApp->setStyleSheet ("");
8388 qApp->setStyleSheet (cssfile);
8389 }
8390
8391
update_styles()8392 void CTEA::update_styles()
8393 {
8394 #if QT_VERSION >= 0x050000
8395 QString default_style = qApp->style()->objectName();
8396
8397 if (default_style == "GTK+") //can be buggy
8398 default_style = "Fusion";
8399
8400 #else
8401
8402 QString default_style = qApp->style()->objectName();
8403
8404 if (default_style == "GTK+") //can be buggy
8405 default_style = "Cleanlooks";
8406
8407 #endif
8408
8409 fname_stylesheet = settings->value ("fname_stylesheet", ":/themes/TEA").toString();
8410
8411 MyProxyStyle *ps = new MyProxyStyle (QStyleFactory::create (settings->value ("ui_style", default_style).toString()));
8412
8413 QApplication::setStyle (ps);
8414 }
8415
8416
update_dyn_menus()8417 void CTEA::update_dyn_menus()
8418 {
8419 update_templates();
8420 update_snippets();
8421 update_scripts();
8422 update_palettes();
8423 update_themes();
8424 update_tables();
8425 update_profiles();
8426 update_labels_menu();
8427 }
8428
8429
update_fonts()8430 void CTEA::update_fonts()
8431 {
8432 documents->apply_settings();
8433 }
8434
8435
update_bookmarks()8436 void CTEA::update_bookmarks()
8437 {
8438 if (! file_exists (fname_bookmarks))
8439 return;
8440
8441 QString bookmarks = qstring_load (fname_bookmarks);
8442 if (bookmarks.isEmpty())
8443 return;
8444
8445 menu_file_bookmarks->clear();
8446 create_menu_from_list (this, menu_file_bookmarks,
8447 bookmarks.split ("\n"),
8448 SLOT (file_open_bookmark()));
8449 }
8450
8451
update_templates()8452 void CTEA::update_templates()
8453 {
8454 menu_file_templates->clear();
8455
8456 create_menu_from_dir (this,
8457 menu_file_templates,
8458 dir_templates,
8459 SLOT (file_use_template())
8460 );
8461 }
8462
8463
update_snippets()8464 void CTEA::update_snippets()
8465 {
8466 menu_fn_snippets->clear();
8467 create_menu_from_dir (this,
8468 menu_fn_snippets,
8469 dir_snippets,
8470 SLOT (fn_use_snippet())
8471 );
8472 }
8473
8474
update_sessions()8475 void CTEA::update_sessions()
8476 {
8477 menu_file_sessions->clear();
8478 create_menu_from_dir (this,
8479 menu_file_sessions,
8480 dir_sessions,
8481 SLOT (file_open_session())
8482 );
8483 }
8484
8485
update_palettes()8486 void CTEA::update_palettes()
8487 {
8488 menu_view_palettes->clear();
8489
8490 QStringList l1 = read_dir_entries (dir_palettes);
8491 QStringList l2 = read_dir_entries (":/palettes");
8492 l1 += l2;
8493
8494 create_menu_from_list (this, menu_view_palettes,
8495 l1,
8496 SLOT (view_use_palette()));
8497 }
8498
8499
update_labels_menu()8500 void CTEA::update_labels_menu()
8501 {
8502 menu_labels->clear();
8503
8504 CDocument *d = documents->get_current();
8505 if (d)
8506 create_menu_from_list (this, menu_labels, d->labels, SLOT(select_label()));
8507 }
8508
8509
update_themes()8510 void CTEA::update_themes()
8511 {
8512 menu_view_themes->clear();
8513
8514 create_menu_from_themes (this,
8515 menu_view_themes,
8516 ":/themes",
8517 SLOT (view_use_theme())
8518 );
8519
8520 create_menu_from_themes (this,
8521 menu_view_themes,
8522 dir_themes,
8523 SLOT (view_use_theme())
8524 );
8525 }
8526
8527
update_hls()8528 void CTEA::update_hls()
8529 {
8530
8531 CFilesList lf;
8532 lf.get (":/hls");
8533
8534 QStringList l (lf.list);
8535
8536 lf.get (dir_hls);
8537 l << lf.list;
8538
8539 for (int i = 0; i < l.size(); i++)
8540 {
8541 QString fname = l[i];
8542
8543 QString buffer = qstring_load_first_line (fname);
8544 QString rgxp = string_between (buffer, "pattern=\"", "\"");
8545
8546 if (! rgxp.isEmpty())
8547 {
8548
8549 #if QT_VERSION >= 0x050000
8550
8551 QRegularExpression re (rgxp, QRegularExpression::CaseInsensitiveOption);
8552 if (re.isValid())
8553 documents->hl_files.push_back (std::make_pair (re, fname));
8554
8555 #else
8556
8557 QRegExp re (rgxp, Qt::CaseInsensitive, QRegExp::RegExp2);
8558 if (re.isValid())
8559 documents->hl_files.push_back(std::make_pair (re, fname));
8560
8561 #endif
8562 }
8563 }
8564 }
8565
8566
update_tables()8567 void CTEA::update_tables()
8568 {
8569 menu_fn_tables->clear();
8570
8571 create_menu_from_dir (this,
8572 menu_fn_tables,
8573 dir_tables,
8574 SLOT (fn_use_table())
8575 );
8576 }
8577
update_scripts()8578 void CTEA::update_scripts()
8579 {
8580 menu_fn_scripts->clear();
8581
8582 create_menu_from_dir (this,
8583 menu_fn_scripts,
8584 dir_scripts,
8585 SLOT (fn_run_script())
8586 );
8587 }
8588
8589 //KDE: $HOME/.local/share/user-places.xbel GNOME $HOME/.config/gtk-3.0/bookmarks
8590
update_places_bookmarks()8591 void CTEA::update_places_bookmarks()
8592 {
8593 lv_places->clear();
8594
8595 QStringList sl_items;
8596 sl_items << tr ("templates");
8597 sl_items << tr ("snippets");
8598 sl_items << tr ("scripts");
8599 sl_items << tr ("tables");
8600 sl_items << tr ("configs");
8601
8602 lv_places->addItems (sl_items);
8603
8604 if (! file_exists (fname_places_bookmarks))
8605 return;
8606
8607 sl_places_bmx = qstring_load (fname_places_bookmarks).split ("\n");
8608
8609 sl_places_bmx.removeAll (QString (""));
8610
8611 if (sl_places_bmx.size() != 0)
8612 lv_places->addItems (sl_places_bmx);
8613
8614 QString fname_gtk_bookmarks = QDir::homePath() + "/" + ".gtk-bookmarks";
8615 if (! file_exists (fname_gtk_bookmarks))
8616 return;
8617
8618 lv_places->addItem (tr ("GTK Bookmarks:"));
8619
8620 QStringList sl_gtk_bookmarks = qstring_load (fname_gtk_bookmarks).split ("\n");
8621
8622 QStringList sl_filtered;
8623
8624 int sz = sl_gtk_bookmarks.size();
8625
8626 for (int i = 0; i < sz; i++)
8627 {
8628 QString s = sl_gtk_bookmarks.at(i);
8629 //int pos = s.lastIndexOf ('/');
8630 //if (pos == -1)
8631 // continue;
8632
8633 //QString t = s.right (s.size() - ++pos);
8634
8635 s = s.remove ("file://");
8636
8637 if (s.contains ("%"))
8638 s = QUrl::fromPercentEncoding (s.toLatin1().constData());
8639
8640 sl_filtered.append (s);
8641 }
8642
8643 if (sl_filtered.size() > 0)
8644 lv_places->addItems (sl_filtered);
8645 }
8646
8647
update_programs()8648 void CTEA::update_programs()
8649 {
8650 if (! file_exists (fname_programs))
8651 return;
8652
8653 programs = hash_load_keyval (fname_programs);
8654 if (programs.count() < 0)
8655 return;
8656
8657 menu_programs->clear();
8658
8659 QStringList sl = programs.keys();
8660 sl.sort();
8661
8662 create_menu_from_list (this, menu_programs,
8663 sl,
8664 SLOT (run_program()));
8665 }
8666
8667
update_logmemo_palette()8668 void CTEA::update_logmemo_palette()
8669 {
8670 int darker_val = settings->value ("darker_val", 100).toInt();
8671
8672 QString text_color = hash_get_val (global_palette, "text", "black");
8673 QString back_color = hash_get_val (global_palette, "background", "white");
8674 QString sel_back_color = hash_get_val (global_palette, "sel-background", "black");
8675 QString sel_text_color = hash_get_val (global_palette, "sel-text", "white");
8676
8677 QString t_text_color = QColor (text_color).darker(darker_val).name();
8678 QString t_back_color = QColor (back_color).darker(darker_val).name();
8679 QString t_sel_text_color = QColor (sel_text_color).darker(darker_val).name();
8680 QString t_sel_back_color = QColor (sel_back_color).darker(darker_val).name();
8681
8682 QString sheet = QString ("QPlainTextEdit { color: %1; background-color: %2; selection-color: %3; selection-background-color: %4;}").arg (
8683 t_text_color).arg (
8684 t_back_color).arg (
8685 t_sel_text_color).arg (
8686 t_sel_back_color);
8687
8688 log->setStyleSheet (sheet);
8689
8690 sheet = QString ("QLineEdit { color: %1; background-color: %2; selection-color: %3; selection-background-color: %4;}").arg (
8691 t_text_color).arg (
8692 t_back_color).arg (
8693 t_sel_text_color).arg (
8694 t_sel_back_color);
8695
8696 fif->setStyleSheet (sheet);
8697 }
8698
8699
update_charsets()8700 void CTEA::update_charsets()
8701 {
8702 QString fname = dir_config + "/last_used_charsets";
8703
8704 if (! file_exists (fname))
8705 qstring_save (fname, "UTF-8");
8706
8707 sl_last_used_charsets = qstring_load (fname).split ("\n");
8708
8709 QList<QByteArray> acodecs = QTextCodec::availableCodecs();
8710
8711 for (QList <QByteArray>::iterator codec = acodecs.begin(); codec != acodecs.end(); ++codec)
8712 sl_charsets.prepend ((*codec));
8713
8714 sl_charsets.sort();
8715 }
8716
8717
update_profiles()8718 void CTEA::update_profiles()
8719 {
8720 menu_view_profiles->clear();
8721 create_menu_from_dir (this,
8722 menu_view_profiles,
8723 dir_profiles,
8724 SLOT (view_use_profile())
8725 );
8726 }
8727
8728
opt_update_keyb()8729 void CTEA::opt_update_keyb()
8730 {
8731 if (! lv_menuitems)
8732 return;
8733
8734 lv_menuitems->clear();
8735 shortcuts->captions_iterate();
8736 lv_menuitems->addItems (shortcuts->captions);
8737 }
8738
8739
8740 /*
8741 =====================
8742 Misc callbacks
8743 =====================
8744 */
8745
8746
select_label()8747 void CTEA::select_label()
8748 {
8749 last_action = sender();
8750 QAction *Act = qobject_cast<QAction *>(sender());
8751
8752 CDocument *d = documents->get_current();
8753 if (! d)
8754 return;
8755
8756 QTextCursor cr;
8757
8758 QString text_to_find = settings->value ("label_start", "[?").toString()
8759 + Act->text()
8760 + settings->value ("label_end", "?]").toString();
8761
8762 cr = d->document()->find (text_to_find);
8763
8764 if (! cr.isNull())
8765 d->setTextCursor (cr);
8766 }
8767
8768
run_program()8769 void CTEA::run_program()
8770 {
8771 last_action = sender();
8772
8773 CDocument *d = documents->get_current();
8774 if (! d)
8775 return;
8776
8777 QAction *a = qobject_cast<QAction *>(sender());
8778 QString command = programs.value(a->text());
8779 if (command.isEmpty())
8780 return;
8781
8782 if (main_tab_widget->currentIndex() == idx_tab_edit)
8783 {
8784 if (! file_exists (d->file_name))
8785 {
8786 QMessageBox::critical (this, "!", tr ("Save the file first!"), QMessageBox::Ok, QMessageBox::Ok);
8787 return;
8788 }
8789
8790 QFileInfo fi (d->file_name);
8791
8792 command = command.replace ("%s", d->file_name);
8793 command = command.replace ("%basename", fi.baseName());
8794 command = command.replace ("%filename", fi.fileName());
8795 command = command.replace ("%ext", fi.suffix());
8796 command = command.replace ("%dir", fi.canonicalPath());
8797
8798 QString fname = d->get_filename_at_cursor();
8799 if (! fname.isEmpty())
8800 command = command.replace ("%i", fname);
8801 }
8802 else
8803 if (main_tab_widget->currentIndex() == idx_tab_fman)
8804 command = command.replace ("%s", fman->get_sel_fname());
8805
8806 QProcess *process = new QProcess (this);
8807
8808 connect (process, SIGNAL(readyReadStandardOutput()), this, SLOT(process_readyReadStandardOutput()));
8809 process->setProcessChannelMode (QProcess::MergedChannels) ;
8810
8811 process->start (command, QStringList());
8812 }
8813
8814
guess_enc()8815 void CTEA::guess_enc()
8816 {
8817 QString enc;
8818 QString fn = fman->get_sel_fname();
8819
8820 if (! file_exists (fn))
8821 return;
8822
8823 if (settings->value ("use_enca_for_charset_detection", 0).toBool())
8824 {
8825 enc = guess_enc_for_file (fn);
8826 if (enc == "err")
8827 {
8828 log->log (tr ("Enca is not installed, falling back to the built-in detection"));
8829 CCharsetMagic cm;
8830 enc = cm.guess_for_file (fn);
8831 }
8832 }
8833 else
8834 {
8835 CCharsetMagic cm;
8836 enc = cm.guess_for_file (fn);
8837 }
8838
8839 if (! enc.isEmpty())
8840 cb_fman_codecs->setCurrentIndex (cb_fman_codecs->findText (enc, Qt::MatchFixedString));
8841 }
8842
8843
clipboard_dataChanged()8844 void CTEA::clipboard_dataChanged()
8845 {
8846 if (! capture_to_storage_file)
8847 return;
8848
8849 CDocument *ddest = documents->get_document_by_fname (fname_storage_file);
8850 if (ddest)
8851 {
8852 QString t = QApplication::clipboard()->text();
8853
8854 QString tpl = "%s\n";
8855
8856 QString ftemplate = dir_config + "/cliptpl.txt";
8857 if (file_exists (ftemplate))
8858 tpl = qstring_load (ftemplate);
8859
8860 tpl = tpl.replace ("%time", QTime::currentTime().toString (settings->value("time_format", "hh:mm:ss").toString()));
8861 tpl = tpl.replace ("%date", QDate::currentDate().toString (settings->value("date_format", "dd/MM/yyyy").toString()));
8862
8863 QString text_to_insert = tpl.replace ("%s", t);
8864
8865 ddest->put (text_to_insert);
8866 }
8867 }
8868
8869
main_tab_page_changed(int index)8870 void CTEA::main_tab_page_changed (int index)
8871 {
8872 if (idx_prev == idx_tab_fman)
8873 if (img_viewer && img_viewer->window_mini.isVisible())
8874 img_viewer->window_mini.close();
8875
8876 if (idx_prev == idx_tab_tune)
8877 leaving_options();
8878
8879 idx_prev = index;
8880
8881 if (index == idx_tab_fman)
8882 {
8883 fman->setFocus();
8884 fm_entry_mode = FM_ENTRY_MODE_NONE;
8885 idx_tab_fman_activate();
8886 }
8887
8888 if (index == idx_tab_calendar)
8889 {
8890 calendar_update();
8891 idx_tab_calendar_activate();
8892 }
8893
8894 if (index == idx_tab_edit)
8895 idx_tab_edit_activate();
8896
8897 if (index == idx_tab_tune)
8898 idx_tab_tune_activate();
8899
8900 if (index == idx_tab_learn)
8901 idx_tab_learn_activate();
8902 }
8903
8904
calendar_clicked(const QDate & date)8905 void CTEA::calendar_clicked (const QDate &date)
8906 {
8907 QString fname = dir_days + "/" + date.toString ("yyyy-MM-dd");
8908
8909 if (file_exists (fname))
8910 {
8911 QString s = qstring_load (fname);
8912 log->log (s);
8913 }
8914 }
8915
8916
calendar_activated(const QDate & date)8917 void CTEA::calendar_activated (const QDate &date)
8918 {
8919 QString fname = dir_days + "/" + date.toString ("yyyy-MM-dd");
8920
8921 bool fresh = false;
8922
8923 if (settings->value ("cal_run_1st", true).toBool())
8924 {
8925 if (! file_exists (fname))
8926 qstring_save (fname, tr ("Enter your daily notes here.\nTo use time-based reminders, specify the time signature in 24-hour format [hh:mm], i.e.:\n[06:00]good morning!\n[20:10]go to theatre"));
8927
8928 settings->setValue ("cal_run_1st", false);
8929 fresh = true;
8930 }
8931 else
8932 if (! file_exists (fname))
8933 {
8934 qstring_save (fname, tr ("Enter your daily notes here."));
8935 fresh = true;
8936 }
8937
8938 CDocument *d = documents->open_file (fname, "UTF-8");
8939 if (! d)
8940 return;
8941
8942 // if (fresh)
8943 // d->selectAll();
8944
8945 main_tab_widget->setCurrentIndex (idx_tab_edit);
8946 }
8947
8948
calendar_currentPageChanged(int year,int month)8949 void CTEA::calendar_currentPageChanged (int year, int month)
8950 {
8951 calendar_update();
8952 }
8953
8954
8955
process_readyReadStandardOutput()8956 void CTEA::process_readyReadStandardOutput()
8957 {
8958 QProcess *p = qobject_cast<QProcess *>(sender());
8959 QByteArray a = p->readAllStandardOutput()/*.data()*/;
8960 QTextCodec *c = QTextCodec::codecForLocale();
8961 QString t = c->toUnicode (a);
8962
8963 log->terminal_output = true;
8964 log->log (t);
8965 log->terminal_output = false;
8966 }
8967
8968
8969 /*
8970 ===========================
8971 Application misc. methods
8972 ===========================
8973 */
8974
8975
load_eclipse_theme_xml(const QString & fname)8976 QHash <QString, QString> CTEA::load_eclipse_theme_xml (const QString &fname)
8977 {
8978 QHash <QString, QString> result;
8979
8980 QString temp = qstring_load (fname);
8981 QXmlStreamReader xml (temp);
8982
8983 while (! xml.atEnd())
8984 {
8985 xml.readNext();
8986
8987 QString tag_name = xml.name().toString();
8988
8989 if (xml.isStartElement())
8990 {
8991 if (tag_name == "colorTheme")
8992 {
8993 log->log (xml.attributes().value ("id").toString());
8994 log->log (xml.attributes().value ("name").toString());
8995 log->log (xml.attributes().value ("modified").toString());
8996 log->log (xml.attributes().value ("author").toString());
8997 log->log (xml.attributes().value ("website").toString());
8998 }
8999
9000 if (tag_name == "singleLineComment")
9001 {
9002 QString t = xml.attributes().value ("color").toString();
9003 if (! t.isEmpty())
9004 result.insert ("single comment", t);
9005 }
9006
9007 if (tag_name == "class")
9008 {
9009 QString t = xml.attributes().value ("color").toString();
9010 if (! t.isEmpty())
9011 {
9012 result.insert ("class", t);
9013 result.insert ("type", t);
9014 }
9015 }
9016
9017 if (tag_name == "operator")
9018 {
9019 QString t = xml.attributes().value ("color").toString();
9020 if (! t.isEmpty())
9021 result.insert ("operator", t);
9022 }
9023
9024 if (tag_name == "string")
9025 {
9026 QString t = xml.attributes().value ("color").toString();
9027 if (! t.isEmpty())
9028 result.insert ("quotes", t);
9029 }
9030
9031 if (tag_name == "multiLineComment")
9032 {
9033 QString t = xml.attributes().value ("color").toString();
9034 if (! t.isEmpty())
9035 result.insert ("mcomment-start", t);
9036 }
9037
9038 if (tag_name == "foreground")
9039 {
9040 QString t = xml.attributes().value ("color").toString();
9041 if (! t.isEmpty())
9042 {
9043 result.insert ("text", t);
9044 result.insert ("functions", t);
9045 result.insert ("modifiers", t);
9046 result.insert ("margin_color", t);
9047 result.insert ("digits", t);
9048 result.insert ("digits-float", t);
9049 result.insert ("label", t);
9050 result.insert ("include", t);
9051 result.insert ("preproc", t);
9052 }
9053 }
9054
9055 if (tag_name == "background")
9056 {
9057 QString t = xml.attributes().value ("color").toString();
9058 if (! t.isEmpty())
9059 {
9060 result.insert ("background", t);
9061 result.insert ("linenums_bg", t);
9062 }
9063 }
9064
9065 if (tag_name == "selectionForeground")
9066 {
9067 QString t = xml.attributes().value ("color").toString();
9068 if (! t.isEmpty())
9069 result.insert ("sel-text", t);
9070 }
9071
9072 if (tag_name == "selectionBackground")
9073 {
9074 QString t = xml.attributes().value ("color").toString();
9075 if (! t.isEmpty())
9076 result.insert ("sel-background", t);
9077 }
9078
9079 if (tag_name == "keyword")
9080 {
9081 QString t = xml.attributes().value ("color").toString();
9082 if (! t.isEmpty())
9083 {
9084 result.insert ("keywords", t);
9085 result.insert ("tags", t);
9086 }
9087 }
9088
9089 if (tag_name == "currentLine")
9090 {
9091 QString t = xml.attributes().value ("color").toString();
9092 if (! t.isEmpty())
9093 result.insert ("cur_line_color", t);
9094 }
9095
9096 if (tag_name == "bracket")
9097 {
9098 QString t = xml.attributes().value ("color").toString();
9099 if (! t.isEmpty())
9100 result.insert ("brackets", t);
9101 }
9102
9103 }//is start
9104
9105 if (xml.hasError())
9106 qDebug() << "xml parse error";
9107
9108 } //cycle
9109
9110
9111 result.insert ("error", "red");
9112
9113 return result;
9114 }
9115
9116
load_palette(const QString & fileName)9117 void CTEA::load_palette (const QString &fileName)
9118 {
9119 if (! file_exists (fileName))
9120 return;
9121
9122 global_palette.clear();
9123
9124 if (file_get_ext (fileName) == "xml")
9125 global_palette = load_eclipse_theme_xml (fileName);
9126 else
9127 global_palette = hash_load_keyval (fileName);
9128 }
9129
9130
fman_convert_images(bool by_side,int value)9131 void CTEA::fman_convert_images (bool by_side, int value)
9132 {
9133 srand (QTime::currentTime().msec());
9134
9135 QString dir_out ("images-out-");
9136
9137 dir_out.append (QString::number (rand() % 777));
9138 dir_out.prepend ("/");
9139 dir_out.prepend (fman->dir.absolutePath());
9140
9141 if (! fman->dir.mkpath (dir_out))
9142 return;
9143
9144 Qt::TransformationMode transformMode = Qt::FastTransformation;
9145 if (settings->value ("img_filter", 0).toBool())
9146 transformMode = Qt::SmoothTransformation;
9147
9148 pb_status->show();
9149 pb_status->setFormat (tr ("%p% completed"));
9150 pb_status->setTextVisible (true);
9151
9152 QStringList li = fman->get_sel_fnames();
9153
9154 int quality = settings->value ("img_quality", "-1").toInt();
9155
9156 pb_status->setRange (0, li.size() - 1 );
9157 int i = 0;
9158
9159 for (QList <QString>::iterator fname = li.begin(); fname != li.end(); ++fname)
9160 {
9161 if (! is_image ((*fname)))
9162 continue;
9163
9164 QImage source ((*fname));
9165
9166 if (source.isNull())
9167 continue;
9168
9169 qApp->processEvents();
9170
9171 if (settings->value ("cb_exif_rotate", 1).toBool())
9172 {
9173 int exif_orientation = get_exif_orientation ((*fname));
9174
9175 QTransform transform;
9176 qreal angle = 0;
9177
9178 if (exif_orientation == 3)
9179 angle = 180;
9180 else
9181 if (exif_orientation == 6)
9182 angle = 90;
9183 else
9184 if (exif_orientation == 8)
9185 angle = 270;
9186 if (angle != 0)
9187 {
9188 transform.rotate (angle);
9189 source = source.transformed (transform);
9190 }
9191 }
9192
9193
9194 QImage dest = image_scale_by (source, by_side, value, transformMode);
9195 QString fmt (settings->value ("output_image_fmt", "jpg").toString());
9196 QFileInfo fi ((*fname));
9197
9198 QString dest_fname (dir_out);
9199 dest_fname.append ("/");
9200 dest_fname.append (fi.fileName());
9201 dest_fname = change_file_ext (dest_fname, fmt);
9202
9203 if (! dest.save (dest_fname, fmt.toLatin1().constData(), quality))
9204 qDebug() << "Cannot save " << dest_fname;
9205
9206 pb_status->setValue (i++);
9207 }
9208
9209 pb_status->hide();
9210
9211 if (settings->value ("img_post_proc", 0).toBool())
9212 {
9213 CZipper zipper;
9214 zipper.zip_directory (fman->dir.absolutePath(), dir_out);
9215 }
9216
9217 fman->refresh();
9218 }
9219
9220
get_search_options()9221 QTextDocument::FindFlags CTEA::get_search_options()
9222 {
9223 QTextDocument::FindFlags flags; //= 0;
9224
9225 if (menu_find_whole_words->isChecked())
9226 flags = flags | QTextDocument::FindWholeWords;
9227
9228 if (menu_find_case->isChecked())
9229 flags = flags | QTextDocument::FindCaseSensitively;
9230
9231 return flags;
9232 }
9233
9234
fif_get_text()9235 QString CTEA::fif_get_text()
9236 {
9237 QString t = fif->text();
9238
9239 int i = sl_fif_history.indexOf (t);
9240
9241 if (i != -1)
9242 {
9243 sl_fif_history.removeAt (i);
9244 sl_fif_history.prepend (t);
9245 }
9246 else
9247 sl_fif_history.prepend (t);
9248
9249 if (sl_fif_history.count() > 77)
9250 sl_fif_history.removeLast();
9251
9252 return t;
9253 }
9254
9255
add_to_menu(QMenu * menu,const QString & caption,const char * method,const QString & shortkt,const QString & iconpath)9256 QAction* CTEA::add_to_menu (QMenu *menu,
9257 const QString &caption,
9258 const char *method,
9259 const QString &shortkt,
9260 const QString &iconpath
9261 )
9262 {
9263 QAction *act = new QAction (caption, this);
9264
9265 if (! shortkt.isEmpty())
9266 act->setShortcut (shortkt);
9267
9268 if (! iconpath.isEmpty())
9269 act->setIcon (QIcon (iconpath));
9270
9271 connect (act, SIGNAL(triggered()), this, method);
9272 menu->addAction (act);
9273 return act;
9274 }
9275
9276
get_theme_icon(const QString & name)9277 QIcon CTEA::get_theme_icon (const QString &name)
9278 {
9279 QString fname = theme_dir + "icons/" + name;
9280
9281 if (file_exists (fname))
9282 return QIcon (fname);
9283
9284 return QIcon (":/icons/" + name);
9285 }
9286
9287
get_theme_icon_fname(const QString & name)9288 QString CTEA::get_theme_icon_fname (const QString &name)
9289 {
9290 QString fname = theme_dir + "icons/" + name;
9291
9292 if (file_exists (fname))
9293 return fname;
9294
9295 return ":/icons/" + name;
9296 }
9297
9298
leaving_options()9299 void CTEA::leaving_options()
9300 {
9301 settings->setValue ("date_format", ed_date_format->text());
9302 settings->setValue ("time_format", ed_time_format->text());
9303 settings->setValue ("img_viewer_override_command", ed_img_viewer_override->text());
9304 settings->setValue ("wasd", cb_wasd->isChecked());
9305
9306 settings->setValue ("ui_mode", cmb_ui_mode->currentIndex());
9307
9308 #if defined(JOYSTICK_SUPPORTED)
9309 settings->setValue ("use_joystick", cb_use_joystick->isChecked());
9310 #endif
9311
9312 settings->setValue ("full_path_at_window_title", cb_full_path_at_window_title->isChecked());
9313 settings->setValue ("word_wrap", cb_wordwrap->isChecked());
9314
9315 #if QT_VERSION >= 0x050000
9316 // settings->setValue ("qregexpsyntaxhl", cb_use_qregexpsyntaxhl->isChecked());
9317 #endif
9318
9319 settings->setValue ("additional_hl", cb_hl_current_line->isChecked());
9320 settings->setValue ("session_restore", cb_session_restore->isChecked());
9321 settings->setValue ("show_linenums", cb_show_linenums->isChecked());
9322 settings->setValue ("hl_enabled", cb_hl_enabled->isChecked());
9323 settings->setValue ("hl_brackets", cb_hl_brackets->isChecked());
9324 settings->setValue ("auto_indent", cb_auto_indent->isChecked());
9325 settings->setValue ("spaces_instead_of_tabs", cb_spaces_instead_of_tabs->isChecked());
9326 settings->setValue ("cursor_xy_visible", cb_cursor_xy_visible->isChecked());
9327 settings->setValue ("tab_sp_width", spb_tab_sp_width->value());
9328 settings->setValue ("center_on_scroll", cb_center_on_cursor->isChecked());
9329 settings->setValue ("show_margin", cb_show_margin->isChecked());
9330 settings->setValue ("margin_pos", spb_margin_pos->value());
9331 settings->setValue ("b_preview", cb_auto_img_preview->isChecked());
9332 settings->setValue ("cursor_blink_time", spb_cursor_blink_time->value());
9333 settings->setValue ("autosave_period", spb_autosave_period->value());
9334 settings->setValue ("autosave", cb_autosave->isChecked());
9335
9336 documents->timer_autosave.stop();
9337 documents->timer_autosave.setInterval (spb_autosave_period->value() * 1000);
9338 documents->timer_autosave.start();
9339
9340
9341 MyProxyStyle::cursor_blink_time = spb_cursor_blink_time->value();
9342
9343 qApp->setCursorFlashTime (spb_cursor_blink_time->value());
9344
9345 settings->setValue ("cursor_width", spb_cursor_width->value());
9346 settings->setValue ("override_img_viewer", cb_override_img_viewer->isChecked());
9347 settings->setValue ("use_enca_for_charset_detection", cb_use_enca_for_charset_detection->isChecked());
9348 settings->setValue ("use_trad_dialogs", cb_use_trad_dialogs->isChecked());
9349 settings->setValue ("start_week_on_sunday", cb_start_on_sunday->isChecked());
9350 settings->setValue ("northern_hemisphere", cb_northern_hemisphere->isChecked());
9351
9352 calendar->northern_hemisphere = bool (cb_northern_hemisphere->isChecked());
9353
9354 /*
9355 int i = moon_phase_algos.key (cmb_moon_phase_algos->currentText());
9356 settings->setValue ("moon_phase_algo", i);
9357 calendar->moon_phase_algo = i;
9358 */
9359
9360
9361 int i = cmb_moon_phase_algos->currentText().toInt();
9362 settings->setValue ("moon_phase_algo", i);
9363 calendar->moon_phase_algo = i;
9364
9365 settings->setValue ("lng", cmb_lng->currentText());
9366
9367 settings->setValue ("zip_charset_in", cmb_zip_charset_in->currentText());
9368 settings->setValue ("zip_charset_out", cmb_zip_charset_out->currentText());
9369 settings->setValue ("cmdline_default_charset", cmb_cmdline_default_charset->currentText());
9370 settings->setValue ("label_end", ed_label_end->text());
9371 settings->setValue ("label_start", ed_label_start->text());
9372 settings->setValue ("output_image_fmt", cmb_output_image_fmt->currentText());
9373 settings->setValue ("img_filter", cb_output_image_flt->isChecked());
9374 settings->setValue("fuzzy_q", spb_fuzzy_q->value());
9375 settings->setValue("img_quality", spb_img_quality->value());
9376 settings->setValue ("img_post_proc", cb_zip_after_scale->isChecked());
9377 settings->setValue ("cb_exif_rotate", cb_exif_rotate->isChecked());
9378 settings->setValue ("zor_use_exif_orientation", cb_zor_use_exif->isChecked());
9379 settings->setValue ("ed_side_size", ed_side_size->text());
9380 settings->setValue ("ed_link_options", ed_link_options->text());
9381 settings->setValue ("ed_cols_per_row", ed_cols_per_row->text());
9382
9383 b_preview = settings->value ("b_preview", false).toBool();
9384
9385 calendar->do_update();
9386 documents->apply_settings();
9387 }
9388
9389
add_to_last_used_charsets(const QString & s)9390 void CTEA::add_to_last_used_charsets (const QString &s)
9391 {
9392 int i = sl_last_used_charsets.indexOf (s);
9393 if (i == -1)
9394 sl_last_used_charsets.prepend (s);
9395 else
9396 sl_last_used_charsets.move (i, 0);
9397
9398 if (sl_last_used_charsets.size() > 3)
9399 sl_last_used_charsets.removeLast();
9400 }
9401
9402
count_substring(bool use_regexp)9403 void CTEA::count_substring (bool use_regexp)
9404 {
9405 CDocument *d = documents->get_current();
9406 if (! d)
9407 return;
9408
9409 QString text;
9410
9411 if (d->textCursor().hasSelection())
9412 text = d->get();
9413 else
9414 text = d->toPlainText();
9415
9416 int count = 0;
9417 Qt::CaseSensitivity cs = Qt::CaseInsensitive;
9418
9419 if (menu_find_case->isChecked())
9420 cs = Qt::CaseSensitive;
9421
9422 #if (QT_VERSION_MAJOR < 5)
9423
9424 if (use_regexp)
9425 count = text.count (QRegExp (fif_get_text()));
9426 else
9427 count = text.count (fif_get_text(), cs);
9428
9429 #else
9430
9431 if (use_regexp)
9432 count = text.count (QRegularExpression (fif_get_text()));
9433 else
9434 count = text.count (fif_get_text(), cs);
9435
9436 #endif
9437
9438 log->log (tr ("%1 number of occurrences of %2 is found").arg (count).arg (fif->text()));
9439 }
9440
9441
run_unitaz(int mode)9442 void CTEA::run_unitaz (int mode)
9443 {
9444 CDocument *d = documents->get_current();
9445 if (! d)
9446 return;
9447
9448 //pb_status->show();
9449
9450 progress_show();
9451
9452 pb_status->setFormat (tr ("%p% completed"));
9453 pb_status->setTextVisible (true);
9454
9455 QElapsedTimer time_start;
9456 time_start.start();
9457
9458 int c = 0;
9459
9460 QStringList total = d->get_words();
9461 QHash <QString, int> h;
9462
9463 pb_status->setRange (0, total.size() - 1);
9464
9465 for (int j = 0; j < total.size(); j++)
9466 {
9467 if (c % 100 == 0)
9468 qApp->processEvents();
9469
9470 if (boring)
9471 break;
9472
9473 QHash<QString, int>::iterator i = h.find (total.at(j).toLower());
9474 if (i != h.end())
9475 i.value() += 1;
9476 else
9477 h.insert(total.at(j).toLower(), 1);
9478
9479 pb_status->setValue (c++);
9480 }
9481
9482 vector <pair <QString, int> > uwords;
9483
9484 QList <QString> keys = h.keys();
9485 int sz = keys.size();
9486
9487 uwords.reserve (sz);
9488
9489 for (int i = 0; i < sz; i++)
9490 uwords.push_back (make_pair(keys.at(i),h.value (keys.at(i))));
9491
9492 if (mode == 0)
9493 std::sort (uwords.begin(), uwords.end(), pr_bigger_than);
9494 if (mode == 1)
9495 std::sort (uwords.begin(), uwords.end(), pr_bigger_than_str);
9496 if (mode == 2)
9497 std::sort (uwords.begin(), uwords.end(), pr_bigger_than_str_len);
9498
9499 QStringList outp;
9500
9501 for (size_t i = 0; i < uwords.size(); i++)
9502 outp.append (uwords.at(i).first + " = " + QString::number (uwords.at(i).second));
9503
9504 double diff = static_cast <double> (total.size()) / static_cast <double> (uwords.size());
9505 double diff_per_cent = get_percent (static_cast <double> (total.size()), static_cast <double> (uwords.size()));
9506
9507 outp.prepend (tr ("total to unique per cent diff: %1").arg (diff_per_cent, 0, 'f', 6));
9508 outp.prepend (tr ("total / unique: %1").arg (diff, 0, 'f', 6));
9509 outp.prepend (tr ("words unique: %1").arg (uwords.size()));
9510 outp.prepend (tr ("words total: %1").arg (total.size()));
9511 outp.prepend (tr ("text analysis of: %1").arg (d->file_name));
9512 outp.prepend (tr ("UNITAZ: UNIverlsal Text AnalyZer"));
9513
9514 log->log (tr("elapsed milliseconds: %1").arg (time_start.elapsed()));
9515
9516 CDocument *nd = documents->create_new();
9517 nd->put (outp.join ("\n"));
9518
9519 //pb_status->hide();
9520 progress_hide();
9521
9522 }
9523
9524
markup_text(const QString & mode)9525 void CTEA::markup_text (const QString &mode)
9526 {
9527 CDocument *d = documents->get_current();
9528 if (! d)
9529 return;
9530
9531 QString t = hash_markup[mode][d->markup_mode];
9532
9533 if (! t.isEmpty())
9534 d->put (t.replace ("%s", d->get()));
9535 }
9536
9537
fman_items_select_by_regexp(bool mode)9538 void CTEA::fman_items_select_by_regexp (bool mode)
9539 {
9540 QString ft = fif_get_text();
9541 if (ft.isEmpty())
9542 return;
9543
9544 #if QT_VERSION >= 0x050F00
9545 l_fman_find = fman->mymodel->findItems (ft, Qt::MatchRegularExpression);
9546 #else
9547 l_fman_find = fman->mymodel->findItems (ft, Qt::MatchRegExp);
9548 #endif
9549
9550 if (l_fman_find.size() < 1)
9551 return;
9552
9553 QItemSelectionModel *m = fman->selectionModel();
9554 for (int i = 0; i < l_fman_find.size(); i++)
9555 if (mode)
9556 m->select (fman->mymodel->indexFromItem (l_fman_find[i]), QItemSelectionModel::Select | QItemSelectionModel::Rows);
9557 else
9558 m->select (fman->mymodel->indexFromItem (l_fman_find[i]), QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
9559 }
9560
9561
fn_filter_delete_by_sep(bool mode)9562 void CTEA::fn_filter_delete_by_sep (bool mode)
9563 {
9564 CDocument *d = documents->get_current();
9565 if (! d)
9566 return;
9567
9568 QStringList sl = d->get().split (QChar::ParagraphSeparator);
9569
9570 QString t = fif_get_text();
9571
9572 for (int i = 0; i < sl.size(); i++)
9573 {
9574 int n = sl[i].indexOf (t);
9575 if (n != -1)
9576 {
9577 QString s = sl[i];
9578 if (mode)
9579 s = s.right (s.size() - n);
9580 else
9581 s = s.left (n);
9582
9583 sl[i] = s;
9584 }
9585 }
9586
9587 QString x = sl.join ("\n");
9588
9589 d->put (x);
9590 }
9591
9592
fman_find()9593 void CTEA::fman_find()
9594 {
9595 QString ft = fif_get_text();
9596 if (ft.isEmpty())
9597 return;
9598
9599 l_fman_find = fman->mymodel->findItems (ft, Qt::MatchStartsWith);
9600
9601 if (l_fman_find.size() < 1)
9602 return;
9603
9604 fman_find_idx = 0;
9605 fman->setCurrentIndex (fman->mymodel->indexFromItem (l_fman_find[fman_find_idx]));
9606 }
9607
9608
fman_find_next()9609 void CTEA::fman_find_next()
9610 {
9611 QString ft = fif_get_text();
9612 if (ft.isEmpty())
9613 return;
9614
9615 if (l_fman_find.size() < 1)
9616 return;
9617
9618 if (fman_find_idx < (l_fman_find.size() - 1))
9619 fman_find_idx++;
9620
9621 fman->setCurrentIndex (fman->mymodel->indexFromItem (l_fman_find[fman_find_idx]));
9622 }
9623
9624
fman_find_prev()9625 void CTEA::fman_find_prev()
9626 {
9627 QString ft = fif_get_text();
9628 if (ft.isEmpty())
9629 return;
9630
9631 if (l_fman_find.size() < 1)
9632 return;
9633
9634 if (fman_find_idx != 0)
9635 fman_find_idx--;
9636
9637 fman->setCurrentIndex (fman->mymodel->indexFromItem (l_fman_find[fman_find_idx]));
9638 }
9639
9640
opt_shortcuts_find()9641 void CTEA::opt_shortcuts_find()
9642 {
9643 int from = 0;
9644
9645 QString fiftxt = fif_get_text();
9646
9647 if (opt_shortcuts_string_to_find == fiftxt)
9648 from = lv_menuitems->currentRow();
9649
9650 opt_shortcuts_string_to_find = fiftxt;
9651
9652 if (from == -1)
9653 from = 0;
9654
9655 #if QT_VERSION < 0x050000
9656 int index = shortcuts->captions.indexOf (QRegExp (opt_shortcuts_string_to_find + ".*",
9657 Qt::CaseInsensitive), from);
9658 #else
9659 int index = shortcuts->captions.indexOf (QRegularExpression (opt_shortcuts_string_to_find + ".*",
9660 QRegularExpression::CaseInsensitiveOption), from);
9661 #endif
9662
9663 if (index != -1)
9664 lv_menuitems->setCurrentRow (index);
9665 }
9666
9667
opt_shortcuts_find_next()9668 void CTEA::opt_shortcuts_find_next()
9669 {
9670 int from = lv_menuitems->currentRow();
9671 if (from == -1)
9672 from = 0;
9673
9674 #if QT_VERSION < 0x050000
9675 int index = shortcuts->captions.indexOf (QRegExp (opt_shortcuts_string_to_find + ".*",
9676 Qt::CaseInsensitive), from + 1);
9677 #else
9678 int index = shortcuts->captions.indexOf (QRegularExpression (opt_shortcuts_string_to_find + ".*",
9679 QRegularExpression::CaseInsensitiveOption), from + 1);
9680
9681 #endif
9682
9683 if (index != -1)
9684 lv_menuitems->setCurrentRow (index);
9685 }
9686
9687
opt_shortcuts_find_prev()9688 void CTEA::opt_shortcuts_find_prev()
9689 {
9690 int from = lv_menuitems->currentRow();
9691 if (from == -1)
9692 from = 0;
9693
9694 #if QT_VERSION < 0x050000
9695 int index = shortcuts->captions.lastIndexOf (QRegExp (opt_shortcuts_string_to_find + ".*",
9696 Qt::CaseInsensitive), from - 1);
9697 #else
9698
9699 int index = shortcuts->captions.lastIndexOf (QRegularExpression (opt_shortcuts_string_to_find + ".*",
9700 QRegularExpression::CaseInsensitiveOption), from - 1);
9701 #endif
9702
9703 if (index != -1)
9704 lv_menuitems->setCurrentRow (index);
9705 }
9706
9707
idx_tab_edit_activate()9708 void CTEA::idx_tab_edit_activate()
9709 {
9710 menu_file->menuAction()->setVisible (true);
9711 menu_edit->menuAction()->setVisible (true);
9712 menu_programs->menuAction()->setVisible (true);
9713 menu_cal->menuAction()->setVisible (false);
9714 menu_markup->menuAction()->setVisible (true);
9715 menu_functions->menuAction()->setVisible (true);
9716 menu_search->menuAction()->setVisible (true);
9717 menu_nav->menuAction()->setVisible (true);
9718 menu_fm->menuAction()->setVisible (false);
9719 menu_view->menuAction()->setVisible (true);
9720 helpMenu->menuAction()->setVisible (true);
9721 }
9722
9723
idx_tab_calendar_activate()9724 void CTEA::idx_tab_calendar_activate()
9725 {
9726 menu_file->menuAction()->setVisible (true);
9727 menu_edit->menuAction()->setVisible (false);
9728 menu_cal->menuAction()->setVisible (true);
9729 menu_programs->menuAction()->setVisible (true);
9730 menu_markup->menuAction()->setVisible (false);
9731 menu_functions->menuAction()->setVisible (false);
9732 menu_search->menuAction()->setVisible (false);
9733 menu_nav->menuAction()->setVisible (false);
9734 menu_fm->menuAction()->setVisible (false);
9735 menu_view->menuAction()->setVisible (true);
9736 helpMenu->menuAction()->setVisible (true);
9737 }
9738
9739
idx_tab_tune_activate()9740 void CTEA::idx_tab_tune_activate()
9741 {
9742 opt_update_keyb();
9743
9744 menu_file->menuAction()->setVisible (true);
9745 menu_edit->menuAction()->setVisible (false);
9746 menu_programs->menuAction()->setVisible (true);
9747 menu_markup->menuAction()->setVisible (false);
9748 menu_functions->menuAction()->setVisible (true);
9749 menu_search->menuAction()->setVisible (false);
9750 menu_nav->menuAction()->setVisible (false);
9751 menu_fm->menuAction()->setVisible (false);
9752 menu_view->menuAction()->setVisible (true);
9753 helpMenu->menuAction()->setVisible (true);
9754 menu_cal->menuAction()->setVisible (false);
9755 }
9756
9757
idx_tab_fman_activate()9758 void CTEA::idx_tab_fman_activate()
9759 {
9760 menu_file->menuAction()->setVisible (true);
9761 menu_edit->menuAction()->setVisible (false);
9762 menu_programs->menuAction()->setVisible (true);
9763 menu_markup->menuAction()->setVisible (false);
9764 menu_functions->menuAction()->setVisible (true);
9765 menu_search->menuAction()->setVisible (true);
9766 menu_nav->menuAction()->setVisible (false);
9767 menu_fm->menuAction()->setVisible (true);
9768 menu_view->menuAction()->setVisible (true);
9769 helpMenu->menuAction()->setVisible (true);
9770 menu_cal->menuAction()->setVisible (false);
9771 }
9772
9773
idx_tab_learn_activate()9774 void CTEA::idx_tab_learn_activate()
9775 {
9776 menu_file->menuAction()->setVisible (true);
9777 menu_edit->menuAction()->setVisible (false);
9778 menu_programs->menuAction()->setVisible (true);
9779 menu_markup->menuAction()->setVisible (false);
9780 menu_functions->menuAction()->setVisible (false);
9781 menu_search->menuAction()->setVisible (true);
9782 menu_nav->menuAction()->setVisible (false);
9783 menu_fm->menuAction()->setVisible (false);
9784 menu_view->menuAction()->setVisible (true);
9785 helpMenu->menuAction()->setVisible (true);
9786 menu_cal->menuAction()->setVisible (false);
9787 }
9788
9789
man_find_find()9790 void CTEA::man_find_find()
9791 {
9792 QString fiftxt = fif_get_text();
9793 man->find (fiftxt, get_search_options());
9794 man_search_value = fiftxt;
9795 }
9796
9797
man_find_next()9798 void CTEA::man_find_next()
9799 {
9800 man->find (man_search_value, get_search_options());
9801 }
9802
9803
man_find_prev()9804 void CTEA::man_find_prev()
9805 {
9806 man->find (man_search_value, get_search_options() | QTextDocument::FindBackward);
9807 }
9808
9809
progress_show()9810 void CTEA::progress_show()
9811 {
9812 pb_status->show();
9813 tb_stop->show();
9814 boring = false;
9815 }
9816
9817
progress_hide()9818 void CTEA::progress_hide()
9819 {
9820 pb_status->hide();
9821 tb_stop->hide();
9822 boring = false;
9823 }
9824
9825
9826 /*
9827 ====================
9828 Tune page callbacks
9829 ====================
9830 */
9831
9832 #if defined(JOYSTICK_SUPPORTED)
9833
cb_use_joystick_stateChanged(int state)9834 void CTEA::cb_use_joystick_stateChanged (int state)
9835 {
9836 bool b;
9837 if (state == Qt::Unchecked)
9838 b = false;
9839 else
9840 b = true;
9841
9842 settings->setValue ("use_joystick", b);
9843
9844 if (b)
9845 documents->timer_joystick.start (100);
9846 else
9847 documents->timer_joystick.stop();
9848 }
9849
9850 #endif
9851
cb_altmenu_stateChanged(int state)9852 void CTEA::cb_altmenu_stateChanged (int state)
9853 {
9854 if (state == Qt::Unchecked)
9855 MyProxyStyle::b_altmenu = false;
9856 else
9857 MyProxyStyle::b_altmenu = true;
9858
9859 settings->setValue ("b_altmenu", MyProxyStyle::b_altmenu);
9860 }
9861
9862
cmb_ui_tabs_currentIndexChanged(int i)9863 void CTEA::cmb_ui_tabs_currentIndexChanged (int i)
9864 {
9865 main_tab_widget->setTabPosition (int_to_tabpos (i));
9866 settings->setValue ("ui_tabs_align", i);
9867 }
9868
9869
cmb_docs_tabs_currentIndexChanged(int i)9870 void CTEA::cmb_docs_tabs_currentIndexChanged (int i)
9871 {
9872 tab_editor->setTabPosition (int_to_tabpos (i));
9873
9874 settings->setValue ("docs_tabs_align", i);
9875 }
9876
9877
cmb_icon_sizes_currentIndexChanged(int index)9878 void CTEA::cmb_icon_sizes_currentIndexChanged (int index)
9879 {
9880
9881 QComboBox *cmb = qobject_cast<QComboBox*>(sender());
9882
9883 QString text = cmb->currentText();
9884
9885 settings->setValue ("icon_size", text);
9886
9887 icon_size = settings->value ("icon_size", "32").toInt();
9888
9889 setIconSize (QSize (text.toInt(), text.toInt()));
9890 tb_fman_dir->setIconSize (QSize (text.toInt(), text.toInt()));
9891 filesToolBar->setIconSize (QSize (text.toInt(), text.toInt()));
9892 }
9893
9894
cmb_tea_icons_currentIndexChanged(int)9895 void CTEA::cmb_tea_icons_currentIndexChanged (int)
9896 {
9897 QComboBox *cmb = qobject_cast<QComboBox*>(sender());
9898 QString text = cmb->currentText();
9899
9900 settings->setValue ("icon_fname", text);
9901
9902 QString icon_fname = ":/icons/tea-icon-v3-0" + text + ".png";
9903
9904 qApp->setWindowIcon (QIcon (icon_fname));
9905 }
9906
9907
pb_assign_hotkey_clicked()9908 void CTEA::pb_assign_hotkey_clicked()
9909 {
9910 if (! lv_menuitems->currentItem())
9911 return;
9912
9913 if (ent_shtcut->text().isEmpty())
9914 return;
9915
9916 shortcuts->set_new_shortcut (lv_menuitems->currentItem()->text(), ent_shtcut->text());
9917 shortcuts->save_to_file (shortcuts->fname);
9918 }
9919
9920
pb_remove_hotkey_clicked()9921 void CTEA::pb_remove_hotkey_clicked()
9922 {
9923 if (! lv_menuitems->currentItem())
9924 return;
9925
9926 shortcuts->set_new_shortcut (lv_menuitems->currentItem()->text(), "");
9927 ent_shtcut->setText ("");
9928 shortcuts->save_to_file (shortcuts->fname);
9929 }
9930
9931
slot_lv_menuitems_currentItemChanged(QListWidgetItem * current,QListWidgetItem * previous)9932 void CTEA::slot_lv_menuitems_currentItemChanged (QListWidgetItem *current, QListWidgetItem *previous)
9933 {
9934 if (! current)
9935 return;
9936
9937 QAction *a = shortcuts->find_by_caption (current->text());
9938 if (a)
9939 ent_shtcut->setText (a->shortcut().toString());
9940 }
9941
9942
slot_font_logmemo_select()9943 void CTEA::slot_font_logmemo_select()
9944 {
9945 bool ok;
9946 QFont font = QFontDialog::getFont(&ok, QFont(settings->value ("logmemo_font", "Monospace").toString(), settings->value ("logmemo_font_size", "12").toInt()), this);
9947 if (! ok)
9948 return;
9949
9950 settings->setValue ("logmemo_font", font.family());
9951 settings->setValue ("logmemo_font_size", font.pointSize());
9952 update_stylesheet (fname_stylesheet);
9953 }
9954
9955
slot_font_interface_select()9956 void CTEA::slot_font_interface_select()
9957 {
9958 bool ok;
9959 QFontInfo fi = QFontInfo (qApp->font());
9960 QFont font = QFontDialog::getFont (&ok, QFont (settings->value ("app_font_name", "Sans").toString(), settings->value ("app_font_size", fi.pointSize()).toInt()), this);
9961 if (! ok)
9962 return;
9963
9964 settings->setValue ("app_font_name", font.family());
9965 settings->setValue ("app_font_size", font.pointSize());
9966 update_stylesheet (fname_stylesheet);
9967 }
9968
9969
slot_font_editor_select()9970 void CTEA::slot_font_editor_select()
9971 {
9972 bool ok;
9973 QFont font = QFontDialog::getFont(&ok, QFont(settings->value ("editor_font_name", "Serif").toString(), settings->value ("editor_font_size", "16").toInt()), this);
9974 if (! ok)
9975 return;
9976
9977 settings->setValue ("editor_font_name", font.family());
9978 settings->setValue ("editor_font_size", font.pointSize());
9979 update_stylesheet (fname_stylesheet);
9980 }
9981
9982
slot_style_currentIndexChanged(int)9983 void CTEA::slot_style_currentIndexChanged (int)
9984 {
9985 QComboBox *cmb = qobject_cast<QComboBox*>(sender());
9986 QString text = cmb->currentText();
9987
9988 if (text == "GTK+") //because it is buggy with some Qt versions. sorry!
9989 return;
9990
9991 QStyle *style = QStyleFactory::create (text);
9992 if (style == 0)
9993 return;
9994
9995 settings->setValue ("ui_style", text);
9996 }
9997
9998
9999 #if defined (HUNSPELL_ENABLE) || defined (ASPELL_ENABLE)
cmb_spellchecker_currentIndexChanged(int)10000 void CTEA::cmb_spellchecker_currentIndexChanged (int)
10001 {
10002 QComboBox *cmb = qobject_cast<QComboBox*>(sender());
10003 QString text = cmb->currentText();
10004
10005 cur_spellchecker = text;
10006
10007 settings->setValue ("cur_spellchecker", cur_spellchecker);
10008
10009 delete spellchecker;
10010
10011 if (! spellcheckers.contains (cur_spellchecker) && spellcheckers.size() > 0)
10012 cur_spellchecker = spellcheckers[0];
10013
10014 #ifdef ASPELL_ENABLE
10015 if (cur_spellchecker == "Aspell")
10016 spellchecker = new CAspellchecker (settings->value ("spell_lang", QLocale::system().name().left(2)).toString());
10017 #endif
10018
10019 #ifdef HUNSPELL_ENABLE
10020 if (cur_spellchecker == "Hunspell")
10021 spellchecker = new CHunspellChecker (settings->value ("spell_lang", QLocale::system().name().left(2)).toString(), hunspell_default_dict_path());
10022 #endif
10023
10024 settings->setValue ("spell_lang", "");
10025
10026 create_spellcheck_menu();
10027 }
10028 #endif
10029
10030
10031 #ifdef HUNSPELL_ENABLE
pb_choose_hunspell_path_clicked()10032 void CTEA::pb_choose_hunspell_path_clicked()
10033 {
10034 QString path = QFileDialog::getExistingDirectory (this, tr ("Open Directory"), hunspell_default_dict_path(),
10035 QFileDialog::ShowDirsOnly |
10036 QFileDialog::DontResolveSymlinks);
10037 if (path.isEmpty())
10038 return;
10039
10040 settings->setValue ("hunspell_dic_path", path);
10041 ed_spellcheck_path->setText (path);
10042
10043 if (spellchecker)
10044 delete spellchecker;
10045
10046 setup_spellcheckers();
10047 create_spellcheck_menu();
10048 }
10049 #endif
10050
10051
10052 #ifdef ASPELL_ENABLE
10053
pb_choose_aspell_path_clicked()10054 void CTEA::pb_choose_aspell_path_clicked()
10055 {
10056 QString path = QFileDialog::getExistingDirectory (this, tr ("Open Directory"), "/",
10057 QFileDialog::ShowDirsOnly |
10058 QFileDialog::DontResolveSymlinks);
10059 if (path.isEmpty())
10060 return;
10061
10062 settings->setValue ("win32_aspell_path", path);
10063 ed_aspellcheck_path->setText (path);
10064
10065 if (spellchecker)
10066 delete spellchecker;
10067
10068 setup_spellcheckers();
10069 create_spellcheck_menu();
10070 }
10071 #endif
10072