1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602
|
/* mainwindow.cpp
*
* This file is part of COLLATINUS.
*
* COLLATINUS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* COLLATINVS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with COLLATINUS; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* © Yves Ouvrard, 2009 - 2016
*/
#include <QDebug>
#include <QPrinter>
#include <QPrintDialog>
#include <QStandardPaths>
#include <QDebug>
#include "flexion.h"
#include "mainwindow.h"
#include "maj.h"
/**
* \fn EditLatin::EditLatin (QWidget *parent): QTextEdit (parent)
* \brief Créateur de la classe EditLatin, dérivée de
* QTextEdit afin de pouvoir redéfinir l'action
* connectée au clic de souris sur un mot ou après
* sélection d'une portion de texte.
*/
EditLatin::EditLatin (QWidget *parent): QTextEdit (parent)
{
mainwindow = qobject_cast<MainWindow*>(parent);
}
/**
* \fn bool EditLatin::event(QEvent *event)
* \brief Captation du survol de la souris pour
* afficher dans une bulle lemmatisation et
* analyses morphologiques.
*/
bool EditLatin::event(QEvent *event)
{
switch (event->type())
{
case QEvent::ToolTip:
{
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
QPoint P = mapFromGlobal(helpEvent->globalPos());
QTextCursor tc = cursorForPosition (P);
tc.select (QTextCursor::WordUnderCursor);
QString mot = tc.selectedText();
QString txtBulle = mainwindow->lemmatiseur->lemmatiseT (mot, true, true, true, false);
txtBulle.prepend ("<p style='white-space:pre'>");
txtBulle.append ("</p>");
QToolTip::setFont (font ());
QToolTip::showText (helpEvent->globalPos(), txtBulle.trimmed (), this);
return true;
}
default: return QTextEdit::event (event);
}
}
/**
* \fn void EditLatin::mouseReleaseEvent (QMouseEvent *e)
* \brief Captation de la fin du clic de souris : ajout
* des lemmatisations et analyses morpho dans
* le dock correspondant.
*/
void EditLatin::mouseReleaseEvent (QMouseEvent *e)
{
QTextCursor cursor = textCursor();
if (!cursor.hasSelection())
cursor.select(QTextCursor::WordUnderCursor);
QString st = cursor.selectedText();
bool unSeulMot = !st.contains (' ');
MapLem ml = mainwindow->lemmatiseur->lemmatiseM (st);
// 1. dock de lemmatisation
if (!mainwindow->dockLem->visibleRegion().isEmpty())
{
if (unSeulMot && mainwindow->calepAct->isChecked())
foreach (Lemme *l, ml.keys())
mainwindow->textEditLem->append(l->ambrogio());
else
{
if (mainwindow->html())
{
mainwindow->textEditLem->append(mainwindow->lemmatiseur->lemmatiseT(st));
}
else mainwindow->textEditLem->insertPlainText(mainwindow->lemmatiseur->lemmatiseT(st));
}
}
// 2. dock scansion
if (!mainwindow->dockScand->visibleRegion().isEmpty())
mainwindow->textEditScand->setHtml(mainwindow->lemmatiseur->scandeTxt (st, false));
if (unSeulMot)
{
// 3. dock de flexion
if (!mainwindow->dockFlex->visibleRegion().isEmpty())
{
if (!ml.empty())
{
mainwindow->textBrowserFlex->clear();
mainwindow->textBrowserFlex->append (mainwindow->flechisseur->tableaux(&ml));
mainwindow->textBrowserFlex->moveCursor (QTextCursor::Start);
}
}
// 4. dock dictionnaires
QStringList lemmes = mainwindow->lemmatiseur->lemmes(ml);
if (!mainwindow->dockDic->visibleRegion().isEmpty())
mainwindow->afficheLemsDic(lemmes);
if (mainwindow->wDic->isVisible() && mainwindow->syncAct->isChecked())
mainwindow->afficheLemsDicW(lemmes);
}
QTextEdit::mouseReleaseEvent (e);
}
/**
* \fn MainWindow::MainWindow()
* \brief Créateur de la fenêtre de l'appli.
* Les différentes tâches sont regrouppées
* et confiées à des fonctions spécialisées.
*/
MainWindow::MainWindow()
{
QFile styleFile (":/res/collatinus.css");
styleFile.open (QFile::ReadOnly);
QString style (styleFile.readAll());
qApp->setStyleSheet (style);
editLatin = new EditLatin (this);
setCentralWidget(editLatin);
lemmatiseur = new Lemmat(this);
flechisseur = new Flexion (lemmatiseur);
setLangue();
createStatusBar();
createActions();
createDockWindows();
createDicWindow();
createMenus();
createToolBars();
createConnections();
createDicos();
createDicos(false);
createCibles();
setWindowTitle(tr("Collatinus 11"));
setWindowIcon(QIcon (":/res/collatinus.svg"));
setUnifiedTitleAndToolBarOnMac(true);
//setTabPosition(Qt::BottomDockWidgetArea, QTabWidget::North );
readSettings();
}
/**
* \fn void MainWindow::afficheLemsDic (bool litt, bool prim)
* \brief Surcharge. Récupère le contenu de la ligne de saisie du
* dock des dictionnaires si prim est à true,
* sinon la ligne de saisie de la fenêtre
* supplémentaire. Ce contenu est lemmatisé si litt
* est à false, puis la ou les pages/entrées
* correspondantes sont affichées, soit dans le
* dock, soit dans la fenêtre supplémentaire.
*/
void MainWindow::afficheLemsDic (bool litt, bool prim)
{
QLineEdit *lineEdit;
if (prim) lineEdit = lineEditDic;
else lineEdit = lineEditDicW;
if (lineEdit->text ().isEmpty ())
return;
lemsDic.clear();
QStringList requete;
if (!litt)
{
MapLem lm = lemmatiseur->lemmatiseM(lineEdit->text(),true);
requete = lemmatiseur->lemmes (lm);
}
if (requete.empty ()) requete << lineEdit->text ();
requete.removeDuplicates ();
if (prim) afficheLemsDic(requete, 0);
else afficheLemsDicW(requete, 0);
lineEdit->selectAll();
lineEdit->setFocus();
}
/**
* \fn void MainWindow::afficheLemsDicLitt()
* \brief Fonction de relais permettant d'utiliser
* la connexion entre une action et la fonction
* afficheLemsDic().
*/
void MainWindow::afficheLemsDicLitt()
{
afficheLemsDic(true);
}
/**
* \fn void MainWindow::afficheLemsDicW () * \brief Fonction de relais permettant d'utiliser
* la connexion entre une action et la fonction
* afficheLemsDicW().
*
*/
void MainWindow::afficheLemsDicW ()
{
afficheLemsDic (false,false);
}
/**
* \fn afficheLemsDic(true,false);
* \brief
* \brief Fonction de relais permettant d'utiliser
* la connexion entre une action et la fonction
* afficheLemsDicW(), sans lemmatisation.
*/
void MainWindow::afficheLemsDicLittW ()
{
afficheLemsDic(true,false);
}
/**
* \fn void MainWindow::afficheLemsDic(QStringList ll, int no)
* \brief Affiche la page ou les entrées de
* dictionnaire correspondant au lemme d'ordre no de la
* liste ll, et règle le texte des boutons de
* navigation.
*/
void MainWindow::afficheLemsDic(QStringList ll, int no)
{
if (textBrowserDic == 0) return;
lemsDic = ll;
if (ll.empty () || no < 0 || listeD.courant () == NULL)
return;
textBrowserDic->clear ();
textBrowserDic->setHtml (listeD.courant()->page (ll, no));
lineEditDic->setText (ll.at (no));
if (listeD.courant ()->estXml ())
{
anteButton->setText (listeD.courant()->pgPrec ());
postButton->setText (listeD.courant()->pgSuiv ());
}
else
{
anteButton->setText (tr ("Retro"));
postButton->setText (tr ("Porro"));
labelLewis->setText (QString::number (listeD.courant ()->noPageDjvu ()));
}
textBrowserDic->moveCursor(QTextCursor::Start);
}
/**
* \fn void MainWindow::afficheLemsDicW(QStringList ll, int no)
* \brief comme afficheLemsDic, mais pour le
* dictionnaire supplémentaire.
*
*/
void MainWindow::afficheLemsDicW(QStringList ll, int no)
{
if (textBrowserW == 0) return;
//lemsDic = ll;
if (ll.empty () || no < 0 || listeD.courant2 () == NULL)
return;
textBrowserW->clear ();
textBrowserW->setHtml (listeD.courant2()->page (ll, no));
lineEditDicW->setText (ll.at (no));
if (listeD.courant2()->estXml ())
{
anteButtonW->setText (listeD.courant2()->pgPrec ());
postButtonW->setText (listeD.courant2()->pgSuiv ());
}
else
{
anteButtonW->setText (tr ("Retro"));
postButtonW->setText (tr ("Porro"));
labelLewisW->setText (QString::number (listeD.courant2()->noPageDjvu ()));
}
textBrowserW->moveCursor(QTextCursor::Start);
}
/**
* \fn void MainWindow::afficheLien (QUrl url)
* \brief Prend en charge l'affichage des hyperliens de
* navigations insérés dans les pages/entrées
* des dictionnaires.
*
*/
void MainWindow::afficheLien (QUrl url)
{
if (listeD.courant()->estXml())
return;
// la ligne de liens en tête de page doit être gardée
QStringList liens = listeD.courant()->liens ();
int no = liens.indexOf(url.toString());
if (no < 0) no = 0;
afficheLemsDic(liens, no);
}
/**
* \fn void MainWindow::afficheLienW (QUrl url)
* \brief Comme afficheLien, pour le dictionnaire
* supplémentaire.
*/
void MainWindow::afficheLienW (QUrl url)
{
if (listeD.courant2()->estXml())
return;
// la ligne de liens en tête de page doit être gardée
QStringList liens = listeD.courant2()->liens ();
int no = liens.indexOf(url.toString());
if (no < 0) no = 0;
afficheLemsDicW(liens, no);
}
/**
* \fn void MainWindow::alpha()
* \brief Force la lemmatisation alphabétique de
* tout le texte, quelle que soit l'option alpha
* du lemmatiseur.
*/
void MainWindow::alpha()
{
// pour que l'action provoque le basculement à true
// de l'option alpha du lemmatiseur, supprimer la
// première et la dernière ligne.
bool tmpAlpha = lemmatiseur->optAlpha();
lemmatiseur->setAlpha(true);
lemmatiseTxt();
lemmatiseur->setAlpha(tmpAlpha);
}
/**
* \fn void MainWindow::apropos ()
* \brief Affiche les informations essentielles au
* sujet de Collatinus 11.
*/
void MainWindow::apropos ()
{
QMessageBox::about(this, tr("Collatinus 11"), tr (
"COLLATINVS\nLinguae latinae lemmatizatio \n"
"Licentia GPL, © Yves Ouvrard, 2009 - 2016 \n"
"Nonnullas partes operis scripsit Philippe Verkerk\n"
"Versio "VERSION"\n"
"Gratias illis habeo :\n"
"William Whitaker †\n"
"Jose Luis Redrejo,\n"
"Georges Khaznadar,\n"
"Matthias Bussonier,\n"
"Gérard Jeanneau,\n"
"Jean-Paul Woitrain,\n"
"Perseus Digital Library <http://www.perseus.tufts.edu>"));
}
/**
* \fn void MainWindow::changeGlossarium (QString nomDic)
* \brief Change le dictionnaire actif du dock
* dictionnaires.
*
*/
void MainWindow::changeGlossarium (QString nomDic)
{
listeD.change_courant(nomDic);
if (listeD.courant () == NULL)
return;
if (listeD.courant ()->estXml ())
labelLewis->setText ("↔"); // "\u2194"
else
{
listeD.courant ()->vide_index ();
labelLewis->clear ();
}
if (!lemsDic.empty ())
afficheLemsDic (lemsDic, lemsDic.indexOf (lineEditDic->text ()));
else if (!lineEditDic->text ().isEmpty())
afficheLemsDic (QStringList () << lineEditDic->text ());
}
/**
* \fn void MainWindow::changeGlossariumW (QString nomDic)
* \brief Comme ChangeGlossarium, pour le dictionnaire
* supplémentaire.
*/
void MainWindow::changeGlossariumW (QString nomDic)
{
listeD.change_courant2(nomDic);
if (listeD.courant2() == NULL)
return;
if (listeD.courant2()->estXml ())
labelLewisW->setText ("↔"); // "\u2194"
else
{
listeD.courant2()->vide_index ();
labelLewisW->clear ();
}
if (!lemsDic.empty ())
afficheLemsDicW(lemsDic, lemsDic.indexOf (lineEditDicW->text ()));
else if (!lineEditDicW->text ().isEmpty())
afficheLemsDicW(QStringList () << lineEditDicW->text ());
}
/**
* \fn void MainWindow::changePageDjvu (int p, bool prim)
* \brief Change la page d'un dictionnaire au format
* djvu, pour le dock dictionnaire si prim est à
* true, sinon pour le dictionnaire
* supplémentaire.
*/
void MainWindow::changePageDjvu (int p, bool prim)
{
QTextBrowser *browser;
QLabel *label;
if (prim)
{
browser = textBrowserDic;
label = labelLewis;
}
else
{
browser = textBrowserW;
label = labelLewisW;
}
browser->clear ();
if (prim) browser->setHtml (listeD.courant ()->pageDjvu (p));
else browser->setHtml (listeD.courant2()->pageDjvu (p));
label->setText (QString::number(p));
browser->moveCursor(QTextCursor::Start);
}
/**
* \fn void MainWindow::charger (QString f)
* \brief Charge le fichier nommé f dans l'éditeur
* de texte latin.
*/
void MainWindow::charger (QString f)
{
QFile file(f);
if (!file.open(QFile::ReadOnly | QFile::Text))
{
QMessageBox::warning(this, tr("Collatinus"),
tr("%1: Lecture impossible,\n%2.")
.arg(nfAb)
.arg(file.errorString()));
return;
}
QTextStream in(&file);
QApplication::setOverrideCursor(Qt::WaitCursor);
QString contenu = in.readAll ();
file.close();
editLatin->setPlainText (contenu);
QApplication::restoreOverrideCursor();
}
/**
* \fn void MainWindow::clicAnte ()
* \brief Gère le passage à la page précédente.
*/
void MainWindow::clicAnte ()
{
listeD.courant ()->vide_ligneLiens ();
if (listeD.courant ()->estXml ())
{
afficheLemsDic(QStringList () << anteButton->text ());
}
else
{
int p = labelLewis->text ().toInt ();
if (p > 0)
changePageDjvu (labelLewis->text().toInt()-1);
}
}
/**
* \fn void MainWindow::clicAnteW()
* \brief Comme clicAnte, pour le dictionnaire
* supplémentaire.
*
*/
void MainWindow::clicAnteW()
{
listeD.courant2()->vide_ligneLiens ();
if (listeD.courant2()->estXml ())
{
afficheLemsDicW(QStringList () << anteButton->text ());
}
else
{
int p = labelLewisW->text ().toInt ();
if (p > 0)
changePageDjvu(labelLewisW->text().toInt()-1, false);
}
}
/**
* \fn void MainWindow::clicPost ()
* \brief Gère le passage du dictionnaire à la page
* suivante.
*/
void MainWindow::clicPost ()
{
listeD.courant ()->vide_ligneLiens ();
if (listeD.courant ()->estXml ())
{
afficheLemsDic(QStringList () << postButton->text ());
}
else
{
int p = labelLewis->text ().toInt ();
if (p < 8888) // ATTENTION, déclarer la dernière page dans les cfg !
changePageDjvu (labelLewis->text ().toInt ()+1);
}
}
/**
* \fn void MainWindow::clicPostW()
* \brief Comme clicPost, pour le dictionnaire
* supplémentaire.
*
*/
void MainWindow::clicPostW()
{
listeD.courant2()->vide_ligneLiens ();
if (listeD.courant2()->estXml ())
{
afficheLemsDicW(QStringList () << postButtonW->text ());
}
else
{
int p = labelLewisW->text ().toInt ();
if (p < 8888) // ATTENTION, déclarer la dernière page dans les cfg !
changePageDjvu (labelLewisW->text ().toInt ()+1,false);
}
}
/**
* \fn void MainWindow::closeEvent(QCloseEvent *event)
* \brief Enregistre certains paramètres le la session
* avant fermeture de l'application.
*/
void MainWindow::closeEvent(QCloseEvent *event)
{
QSettings settings("Collatinus", "collatinus11");
settings.beginGroup("interface");
settings.setValue("langue", langueI);
settings.endGroup();
settings.beginGroup("fenetre");
settings.setValue("geometry", saveGeometry());
settings.setValue("windowState", saveState());
settings.endGroup();
settings.beginGroup("fichiers");
if (!nfAb.isEmpty()) settings.setValue("nfAb", nfAb);
settings.endGroup();
settings.beginGroup("options");
//settings.setValue("police", font.family());
settings.setValue("zoom", editLatin->font().pointSize());
// options
settings.setValue("alpha", alphaOptAct->isChecked());
settings.setValue("html", htmlAct->isChecked());
settings.setValue("formetxt", formeTAct->isChecked());
settings.setValue("majpert", majPertAct->isChecked());
settings.setValue("morpho", morphoAct->isChecked());
settings.setValue("nonrec", nonRecAct->isChecked());
settings.setValue("cible", lemmatiseur->cible());
settings.endGroup();
settings.beginGroup("dictionnaires");
settings.setValue("courant", comboGlossaria->currentIndex());
settings.setValue("wdic", wDic->isVisible());
settings.setValue("courantW", comboGlossariaW->currentIndex());
settings.setValue("posw", wDic->pos());
settings.setValue("sizew", wDic->size());
settings.setValue("sync", syncAct->isChecked());
settings.endGroup();
delete wDic;
QMainWindow::closeEvent(event);
}
void MainWindow::copie()
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->clear();
QString texte;
//if (cbTexteLatin->isChecked()) texte.append(editLatin->toPlainText());
if (cbTexteLatin->isChecked()) texte.append(editLatin->toHtml());
if (cbLemmatisation->isChecked()) texte.append(textEditLem->toHtml());
if (cbScansion->isChecked()) texte.append(textEditScand->toHtml());
QMimeData *mime = new QMimeData;
mime->setHtml(texte);
clipboard->setMimeData(mime);
}
/**
* \fn void MainWindow::createActions()
* \brief Fonction appelée par le créateur. Initialise
* toutes les actions utilisées par
* l'application.
*/
void MainWindow::createActions()
{
/*
undoAct = new QAction(QIcon(":/images/undo.png"), tr("&Undo"), this);
undoAct->setShortcuts(QKeySequence::Undo);
undoAct->setStatusTip(tr("Undo the last editing action"));
connect(undoAct, SIGNAL(triggered()), this, SLOT(undo()));
// aussi SLOT(redo())
*/
alphaAct = new QAction(QIcon(":res/edit-alpha.svg"), tr("Lancer et classer &alphabétiquement"), this);
aproposAct = new QAction(QIcon(":/res/collatinus.svg"), tr("à &Propos"), this);
balaiAct = new QAction(QIcon(":res/edit-clear.svg"), tr("&Effacer les résultats"), this);
copieAct = new QAction(QIcon(":res/copie.svg"), tr("&Copier dans un traitement de textes"), this);
deZoomAct = new QAction(QIcon(":res/dezoom.svg"), tr("Plus petit"), this);
findAct = new QAction(QIcon(":res/edit-find.svg"), tr("&Chercher"), this);
fontAct = new QAction(tr("Police de caractères"), this);
lancAct = new QAction(QIcon(":res/gear.svg"), tr("&Lancer"), this);
majAct = new QAction(tr("Télécharger lexiques et dictionnaires"), this);
nouvAct = new QAction(QIcon(":/res/document-new.svg"), tr("&Nouveau"), this);
ouvrirAct = new QAction(QIcon(":/res/document-open.svg"), tr("&Ouvrir"), this);
exportAct = new QAction(QIcon(":res/pdf.svg"), tr("Exporter en pdf"), this);
printAct = new QAction(QIcon(":res/print.svg"), tr("Im&primer"), this);
quitAct = new QAction(QIcon(":/res/power.svg"), tr("&Quitter"), this);
quitAct->setStatusTip(tr("Quitter l'application"));
reFindAct = new QAction(tr("Chercher &encore"), this);
statAct = new QAction(QIcon(":res/abacus.svg"), tr("S&tatistiques"), this);
zoomAct = new QAction(QIcon(":res/zoom.svg"), tr("Plus gros"), this);
// langues d'interface
enAct = new QAction (tr("English Interface"), this);
enAct->setCheckable(true);
frAct = new QAction (tr("Interface en français"), this);
frAct->setCheckable(true);
// raccourcis
findAct->setShortcut(QKeySequence::Find);
nouvAct->setShortcuts(QKeySequence::New);
ouvrirAct->setShortcuts(QKeySequence::Open);
printAct->setShortcuts(QKeySequence::Print);
reFindAct->setShortcut(QKeySequence(tr("Ctrl+J")));
quitAct->setShortcut(QKeySequence (tr("Ctrl+Q"))); // QKeySequence::Quit inopérant
// lemmatisation et options
// ordre alpha
alphaOptAct = new QAction(tr("ordre alpha"), this);
alphaOptAct->setCheckable(true);
// calepino
calepAct = new QAction(tr("Calepino"), this);
calepAct->setCheckable(true);
// formes du texte dans la lemmatisation
formeTAct = new QAction(tr("avec formes"), this);
formeTAct->setCheckable(true);
// lemmatisation en html
htmlAct = new QAction(tr("format html"), this);
htmlAct->setCheckable(true);
// prise en compte des majuscules
majPertAct = new QAction(tr("majuscules"), this);
majPertAct->setCheckable(true);
// analyses morpho dans la lemmatisation
morphoAct = new QAction(tr("Morpho"), this);
morphoAct->setCheckable(true);
// non reconnus en fin de lemmatisation
nonRecAct = new QAction(tr("grouper échecs"), this);
nonRecAct->setCheckable(true);
// actions pour les dictionnaires
dicAct = new QAction(QIcon(":/res/dicolem.svg"), tr("Lemmatiser et chercher"), this);
dicLittAct = new QAction(QIcon(":/res/dicolitt.svg"), tr("Chercher"), this);
dicActW = new QAction(QIcon(":/res/dicolem.svg"), tr("Lemmatiser et chercher"), this);
dicLittActW = new QAction(QIcon(":/res/dicolitt.svg"), tr("Chercher"), this);
// synchronisation des deux dictionnaires
syncAct = new QAction(tr("sync+"), this);
syncAct->setCheckable(true); // synchronisation des deux fenêtres
syncDWAct = new QAction(tr("sync->"), this);
syncWDAct = new QAction(tr("<-sync"), this);
visibleWAct = new QAction(tr("Dictionnaire +"), this);
visibleWAct->setCheckable(true);
}
/**
* \fn void MainWindow::createCibles()
* \brief Initialise toutes les actions liées aux
* fonctions de traduction.
*/
void MainWindow::createCibles()
{
grCibles = new QActionGroup (lexMenu);
foreach (QString cle, lemmatiseur->cibles().keys ())
{
QAction * action = new QAction (grCibles);
action->setText (lemmatiseur->cibles()[cle]);
action->setCheckable (true);
lexMenu->addAction(action);
connect(action, SIGNAL(triggered ()), this, SLOT(setCible ()));
}
}
/**
* \fn void MainWindow::createConnections()
* \brief Initialisation des connections qui lancent
* toutes les actions des menus et des barres d'outils.
*/
void MainWindow::createConnections()
{
// synchroniser zoom et dezoom
connect (zoomAct, SIGNAL(triggered()), editLatin, SLOT(zoomIn()));
connect (zoomAct, SIGNAL(triggered()), textBrowserDic, SLOT(zoomIn()));
connect (zoomAct, SIGNAL(triggered()), textBrowserW, SLOT(zoomIn()));
connect (zoomAct, SIGNAL(triggered()), textBrowserFlex, SLOT(zoomIn()));
connect (zoomAct, SIGNAL(triggered()), textEditLem, SLOT(zoomIn()));
connect (zoomAct, SIGNAL(triggered()), textEditScand, SLOT(zoomIn()));
connect (deZoomAct, SIGNAL(triggered()), editLatin, SLOT(zoomOut()));
connect (deZoomAct, SIGNAL(triggered()), textBrowserDic, SLOT(zoomOut()));
connect (deZoomAct, SIGNAL(triggered()), textBrowserW, SLOT(zoomOut()));
connect (deZoomAct, SIGNAL(triggered()), textBrowserFlex, SLOT(zoomOut()));
connect (deZoomAct, SIGNAL(triggered()), textEditLem, SLOT(zoomOut()));
connect (deZoomAct, SIGNAL(triggered()), textEditScand, SLOT(zoomOut()));
// connexions des lignes de saisie
connect (lineEditLem, SIGNAL(returnPressed()), this, SLOT(lemmatiseLigne()));
connect (lineEditFlex, SIGNAL(returnPressed()), this, SLOT(flechisLigne()));
connect (lineEditScand, SIGNAL(returnPressed()), this, SLOT(scandeLigne()));
// options et actions du lemmatiseur
connect(alphaOptAct, SIGNAL(toggled(bool)), lemmatiseur, SLOT(setAlpha(bool)));
connect(formeTAct, SIGNAL(toggled(bool)), lemmatiseur, SLOT(setFormeT(bool)));
connect(htmlAct, SIGNAL(toggled(bool)), lemmatiseur, SLOT(setHtml(bool)));
connect(majPertAct, SIGNAL(toggled(bool)), lemmatiseur, SLOT(setMajPert(bool)));
connect(morphoAct, SIGNAL(toggled(bool)), lemmatiseur, SLOT(setMorpho(bool)));
connect(nonRecAct, SIGNAL(toggled(bool)), lemmatiseur, SLOT(setNonRec(bool)));
// actions des dictionnaires
connect(anteButton, SIGNAL(clicked ()), this, SLOT(clicAnte ()));
connect(comboGlossaria, SIGNAL(currentIndexChanged(QString)),this,SLOT(changeGlossarium(QString)));
connect(dicAct, SIGNAL(triggered()), this, SLOT(afficheLemsDic()));
connect(dicLittAct, SIGNAL(triggered()), this, SLOT(afficheLemsDicLitt()));
connect(lineEditDic, SIGNAL(returnPressed ()), this, SLOT(afficheLemsDic()));
connect(postButton, SIGNAL(clicked ()), this, SLOT(clicPost()));
connect(syncDWAct, SIGNAL(triggered()), this, SLOT(syncDW()));
connect(textBrowserDic, SIGNAL(anchorClicked(QUrl)), this, SLOT(afficheLien(QUrl)));
connect(anteButtonW, SIGNAL(clicked ()), this, SLOT(clicAnteW()));
connect(comboGlossariaW, SIGNAL(currentIndexChanged(QString)),this,SLOT(changeGlossariumW(QString)));
connect(dicActW, SIGNAL(triggered()), this, SLOT(afficheLemsDicW()));
connect(dicLittActW, SIGNAL(triggered()), this, SLOT(afficheLemsDicLittW()));
connect(lineEditDicW, SIGNAL(returnPressed ()), this, SLOT(afficheLemsDicW()));
connect(majAct, SIGNAL(triggered()), this, SLOT(maj()));
connect(postButtonW, SIGNAL(clicked ()), this, SLOT(clicPostW()));
connect(syncWDAct, SIGNAL(triggered()), this, SLOT(syncWD()));
connect(textBrowserW, SIGNAL(anchorClicked(QUrl)), this, SLOT(afficheLienW(QUrl)));
connect(visibleWAct, SIGNAL(toggled(bool)), this, SLOT(montreWDic(bool)));
// langue d'interface
connect(frAct, SIGNAL(triggered()), this, SLOT(langueInterface()));
connect(enAct, SIGNAL(triggered()), this, SLOT(langueInterface()));
// autres actions
connect(alphaAct, SIGNAL(triggered()), this, SLOT(alpha()));
connect(aproposAct, SIGNAL(triggered()), this, SLOT(apropos()));
connect(balaiAct, SIGNAL(triggered()), this, SLOT(effaceRes()));
connect(copieAct, SIGNAL(triggered()), this, SLOT(dialogueCopie()));
connect(exportAct, SIGNAL(triggered()), this, SLOT(exportPdf()));
connect(findAct, SIGNAL(triggered()), this, SLOT(recherche()));
connect(fontAct, SIGNAL(triggered()), this, SLOT(police()));
connect(lancAct, SIGNAL(triggered()), this, SLOT(lancer()));
connect(nouvAct, SIGNAL(triggered()), this, SLOT(nouveau()));
connect(ouvrirAct, SIGNAL(triggered()), this, SLOT(ouvrir()));
connect(printAct, SIGNAL(triggered()), this, SLOT(imprimer()));
connect(quitAct, SIGNAL(triggered()), this, SLOT(close()));
connect(reFindAct, SIGNAL(triggered()), this, SLOT(rechercheBis()));
connect(statAct, SIGNAL(triggered()), this, SLOT(stat()));
}
/**
* \fn void MainWindow::createDicos(bool prim)
* \brief Chargement des index et des fichiers de
* configuration des dictionnaires.
*/
void MainWindow::createDicos(bool prim)
{
QComboBox *combo = 0;
if (prim) combo = comboGlossaria;
else combo = comboGlossariaW;
combo->clear ();
QDir chDicos (QStandardPaths::locate(QStandardPaths::AppDataLocation,
"/data/dicos",
QStandardPaths::LocateDirectory));
qDebug() << QStandardPaths::locate(QStandardPaths::AppDataLocation,
"/data/dicos",
QStandardPaths::LocateDirectory);
QStringList lcfg = chDicos.entryList (QStringList () << "*.cfg");
ldic.clear();
foreach (QString fcfg, lcfg)
{
Dictionnaire * d = new Dictionnaire (fcfg);
listeD.ajoute (d);
ldic << d->nom ();
}
combo->insertItems (0, ldic);
}
/**
* \fn void MainWindow::createMenus()
* \brief Initialisation des menus à partir des actions définies
* dans MainWindow::createActions().
*
*/
void MainWindow::createMenus()
{
fileMenu = menuBar()->addMenu(tr("&Fichier"));
fileMenu->addAction(nouvAct);
fileMenu->addAction (ouvrirAct);
fileMenu->addSeparator();
fileMenu->addAction(copieAct);
fileMenu->addAction(exportAct);
fileMenu->addAction(printAct);
fileMenu->addSeparator();
fileMenu->addAction(quitAct);
editMenu = menuBar()->addMenu(tr("&Edition"));
editMenu->addAction(findAct);
editMenu->addAction(reFindAct);
//editMenu->addAction(undoAct);
viewMenu = menuBar()->addMenu(tr("&Vue"));
viewMenu->addAction (balaiAct);
viewMenu->addAction(zoomAct);
viewMenu->addAction(deZoomAct);
viewMenu->addAction(visibleWAct);
viewMenu->addSeparator();
QActionGroup *frEngAg = new QActionGroup(this);
frAct->setActionGroup (frEngAg);
enAct->setActionGroup (frEngAg);
viewMenu->addAction(frAct);
viewMenu->addAction(enAct);
if (langueI == "fr") frAct->setChecked (true);
else if (langueI == "en") enAct->setChecked (true);
lexMenu = menuBar()->addMenu(tr("&Lexique"));
lexMenu->addAction (lancAct);
lexMenu->addAction (alphaAct);
lexMenu->addAction (statAct);
optMenu = menuBar()->addMenu(tr("&Options"));
optMenu->addAction(alphaOptAct);
optMenu->addAction(formeTAct);
optMenu->addAction(htmlAct);
optMenu->addAction(majPertAct);
optMenu->addAction(morphoAct);
optMenu->addAction(nonRecAct);
optMenu->addSeparator();
optMenu->addAction(fontAct);
optMenu->addAction(majAct);
helpMenu = menuBar()->addMenu(tr("&Aide"));
helpMenu->addAction(aproposAct);
}
/**
* \fn void MainWindow::createToolBars()
* \brief Initialisation de la barre d'outils à partir
* des actions.
*/
void MainWindow::createToolBars()
{
toolBar = new QToolBar(this);
toolBar->setObjectName("toolbar");
addToolBar(Qt::TopToolBarArea, toolBar);
toolBar->addAction(nouvAct);
toolBar->addAction(ouvrirAct);
toolBar->addAction(copieAct);
toolBar->addAction(zoomAct);
toolBar->addAction(deZoomAct);
toolBar->addAction(findAct);
toolBar->addSeparator();
toolBar->addAction(lancAct);
toolBar->addAction(alphaAct);
toolBar->addAction(statAct);
toolBar->addAction(calepAct);
toolBar->addAction(visibleWAct);
toolBar->addAction(balaiAct);
toolBar->addSeparator();
toolBar->addAction(quitAct);
}
/**
* \fn void MainWindow::createStatusBar()
* \brief Initialisation de la barre d'état. À compléter.
*
*/
void MainWindow::createStatusBar()
{
}
/**
* \fn void MainWindow::createDockWindows()
* \brief Initialisation des différents docks.
*
*/
void MainWindow::createDockWindows()
{
dockLem = new QDockWidget(tr("Lexique et morphologie"), this);
dockLem->setObjectName ("docklem");
dockLem->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::RightDockWidgetArea);
dockLem->setFloating(false);
dockLem->setFeatures(QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable);
dockWidgetLem = new QWidget (dockLem);
dockWidgetLem->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QVBoxLayout *vLayoutLem = new QVBoxLayout (dockWidgetLem);
QHBoxLayout *hLayoutLem = new QHBoxLayout ();
lineEditLem = new QLineEdit (dockWidgetLem);
// boutons d'options
QToolButton *tbCalep = new QToolButton(this);
tbCalep->setDefaultAction(calepAct);
QToolButton *tbMorpho = new QToolButton (this);
tbMorpho->setDefaultAction(morphoAct);
QToolButton *tbAlpha = new QToolButton (this);
tbAlpha->setDefaultAction(alphaOptAct);
QToolButton *tbFormeT = new QToolButton (this);
tbFormeT->setDefaultAction(formeTAct);
QToolButton *tbHtml = new QToolButton (this);
tbHtml->setDefaultAction(htmlAct);
QToolButton *tbMajPert = new QToolButton (this);
tbMajPert->setDefaultAction(majPertAct);
QToolButton *tbNonRec = new QToolButton (this);
tbNonRec->setDefaultAction(nonRecAct);
QSpacerItem *hSpacerLem = new QSpacerItem (40,20);
hLayoutLem->addWidget (lineEditLem);
hLayoutLem->addWidget (tbCalep);
hLayoutLem->addWidget (tbMorpho);
hLayoutLem->addWidget (tbAlpha);
hLayoutLem->addWidget (tbFormeT);
hLayoutLem->addWidget (tbHtml);
hLayoutLem->addWidget (tbMajPert);
hLayoutLem->addWidget (tbNonRec);
hLayoutLem->addItem (hSpacerLem);
textEditLem = new QTextEdit(dockWidgetLem);
vLayoutLem->addLayout (hLayoutLem);
vLayoutLem->addWidget (textEditLem);
dockLem->setWidget (dockWidgetLem);
dockDic = new QDockWidget(tr("Dictionnaires"), this);
dockDic->setObjectName("dockdic");
dockDic->setFloating(false);
dockDic->setFeatures(QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable);
dockDic->setAllowedAreas(Qt::BottomDockWidgetArea);
dockWidgetDic = new QWidget (dockDic);
QVBoxLayout *vLayoutDic = new QVBoxLayout (dockWidgetDic);
QHBoxLayout *hLayoutDic = new QHBoxLayout ();
lineEditDic = new QLineEdit (dockWidgetDic);
// Lemmatisation + recherche
QToolButton *tbDic = new QToolButton (this);
tbDic->setDefaultAction(dicAct);
// recherche sans lemmatisation
QToolButton *tbDicLitt = new QToolButton (this);
tbDicLitt->setDefaultAction(dicLittAct);
// dictionnaire
QToolButton *tbSync = new QToolButton(this);
tbSync->setDefaultAction(syncAct);
QToolButton *tbDicW = new QToolButton(this);
tbDicW->setDefaultAction(visibleWAct);
QToolButton *tbSyncDW = new QToolButton(this);
tbSyncDW->setDefaultAction(syncDWAct);
// choix des dictionnaires
comboGlossaria = new QComboBox (this);
anteButton = new QPushButton (this);
labelLewis = new QLabel (this);
postButton = new QPushButton (this);
QSpacerItem *hSpacerDic = new QSpacerItem (40, 20);
//, QSizePolicy::Expanding, QSizePolicy::Minimum);
hLayoutDic->addWidget(lineEditDic);
hLayoutDic->addWidget(tbDic);
hLayoutDic->addWidget(tbDicLitt);
hLayoutDic->addWidget(comboGlossaria);
hLayoutDic->addWidget(anteButton);
hLayoutDic->addWidget(labelLewis);
hLayoutDic->addWidget(postButton);
hLayoutDic->addItem (hSpacerDic);
hLayoutDic->addWidget(tbSync);
hLayoutDic->addWidget (tbDicW);
hLayoutDic->addWidget (tbSyncDW);
textBrowserDic = new QTextBrowser(dockWidgetDic);
textBrowserDic->setOpenExternalLinks(true);
vLayoutDic->addLayout (hLayoutDic);
vLayoutDic->addWidget (textBrowserDic);
dockDic->setWidget (dockWidgetDic);
dockScand = new QDockWidget(tr("Scansion"), this);
dockScand->setObjectName("dockscand");
dockScand->setFloating(false);
dockScand->setFeatures(QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable);
dockScand->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::RightDockWidgetArea);
dockWidgetScand = new QWidget (dockScand);
QVBoxLayout *vLayoutScand = new QVBoxLayout (dockWidgetScand);
QHBoxLayout *hLayoutScand = new QHBoxLayout ();
lineEditScand = new QLineEdit (dockWidgetScand);
QSpacerItem *hSpacerScand = new QSpacerItem (40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hLayoutScand->addWidget (lineEditScand);
hLayoutScand->addItem (hSpacerScand);
textEditScand = new QTextEdit(dockWidgetScand);
vLayoutScand->addLayout (hLayoutScand);
vLayoutScand->addWidget (textEditScand);
dockScand->setWidget (dockWidgetScand);
dockFlex = new QDockWidget(tr("Flexion"), this);
dockFlex->setObjectName("dockflex");
dockFlex->setFloating(false);
dockFlex->setFeatures(QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable);
dockFlex->setAllowedAreas(Qt::BottomDockWidgetArea);
dockWidgetFlex = new QWidget (dockFlex);
QVBoxLayout *vLayoutFlex = new QVBoxLayout (dockWidgetFlex);
QHBoxLayout *hLayoutFlex = new QHBoxLayout ();
lineEditFlex = new QLineEdit (dockWidgetFlex);
QSpacerItem *hSpacerFlex = new QSpacerItem (40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hLayoutFlex->addWidget (lineEditFlex);
hLayoutFlex->addItem (hSpacerFlex);
textBrowserFlex = new QTextBrowser(dockWidgetFlex);
textBrowserFlex->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
vLayoutFlex->addLayout (hLayoutFlex);
vLayoutFlex->addWidget (textBrowserFlex);
dockFlex->setWidget (dockWidgetFlex);
addDockWidget(Qt::BottomDockWidgetArea, dockLem);
addDockWidget(Qt::BottomDockWidgetArea, dockDic);
addDockWidget(Qt::BottomDockWidgetArea, dockScand);
addDockWidget(Qt::BottomDockWidgetArea, dockFlex);
tabifyDockWidget (dockLem, dockDic);
tabifyDockWidget (dockDic, dockScand);
tabifyDockWidget (dockScand, dockFlex);
setTabPosition(Qt::BottomDockWidgetArea, QTabWidget::North );
dockLem->raise();
}
/**
* \fn void MainWindow::createDicWindow()
* \brief Initialisation du widget de dictionnaire
* supplémentaire.
*/
void MainWindow::createDicWindow()
{
wDic = new QWidget ();
wDic->setObjectName("wDic");
QVBoxLayout *vLayout = new QVBoxLayout(wDic);
QHBoxLayout *hLayout = new QHBoxLayout();
lineEditDicW = new QLineEdit(wDic);
// Lemmatisation + recherche
QToolButton *tbDic = new QToolButton (this);
tbDic->setDefaultAction(dicActW);
// recherche sans lemmatisation
QToolButton *tbDicLittW = new QToolButton (this);
tbDicLittW->setDefaultAction(dicLittActW);
comboGlossariaW = new QComboBox (this);
anteButtonW = new QPushButton (this);
labelLewisW = new QLabel (this);
postButtonW = new QPushButton (this);
QSpacerItem *hSpacerDic = new QSpacerItem (40, 20);
//, QSizePolicy::Expanding, QSizePolicy::Minimum);
QToolButton *tbSyncWD = new QToolButton(this);
tbSyncWD->setDefaultAction(syncWDAct);
hLayout->addWidget(lineEditDicW);
hLayout->addWidget(tbDic);
hLayout->addWidget(tbDicLittW);
hLayout->addWidget(comboGlossariaW);
hLayout->addWidget(anteButtonW);
hLayout->addWidget(labelLewisW);
hLayout->addWidget(postButtonW);
hLayout->addItem (hSpacerDic);
hLayout->addWidget(tbSyncWD);
textBrowserW = new QTextBrowser(wDic);
textBrowserW->setOpenExternalLinks(true);
vLayout->addLayout (hLayout);
vLayout->addWidget (textBrowserW);
}
/**
* \fn void MainWindow::dialogueCopie()
* \brief Ouvre une boite de dialogue qui permet de
* sélectionner les parties à copier, et
* les place dans le presse-papier du système
*/
void MainWindow::dialogueCopie()
{
QLabel *icon = new QLabel;
icon->setPixmap(QPixmap(":/res/collatinus.ico"));
QLabel *text = new QLabel;
text->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
text->setWordWrap(true);
text->setText("<p>Pour récupérer et modifier votre travail, la meilleure manière est "
"d'ouvrir le traitement de textes de votre choix, puis de sélectionner "
"ci-dessous ce que vous voulez utiliser. Cliquez ensuite sur le bouton "
"«Appliquer». Pour terminer, revenez dans votre traitement de texte, "
"et copiez votre sélection avec un raccourci clavier, ou l'option de "
"menu <b>Édition/Coller</b>.");
cbTexteLatin = new QCheckBox (tr("Texte latin"));
cbLemmatisation = new QCheckBox (tr("Lemmatisation"));
cbScansion = new QCheckBox (tr("Scansion"));
QPushButton *appliButton = new QPushButton(tr("Appliquer"));
QPushButton *cloreButton = new QPushButton(tr("Fermer"));
QVBoxLayout *topLayout = new QVBoxLayout;
topLayout->addWidget(icon);
topLayout->addWidget(text);
QHBoxLayout *bottomLayout = new QHBoxLayout;
bottomLayout->addStretch();
bottomLayout->addWidget(appliButton);
bottomLayout->addWidget(cloreButton);
bottomLayout->addStretch();
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(topLayout);
topLayout->addWidget(cbTexteLatin);
topLayout->addWidget(cbLemmatisation);
topLayout->addWidget(cbScansion);
mainLayout->addLayout(bottomLayout);
QDialog dCopie(this);
dCopie.setModal(true);
dCopie.setWindowTitle(tr("Récupérer son travail"));
dCopie.setLayout(mainLayout);
connect(appliButton, SIGNAL(clicked()), this, SLOT(copie()));
connect(cloreButton, SIGNAL(clicked()), &dCopie, SLOT(close()));
dCopie.exec();
}
/**
* \fn bool MainWindow::dockVisible (QDockWidget *d)
* \brief renvoie true si le dock d est visible.
*
*/
bool MainWindow::dockVisible (QDockWidget *d)
{
return !d->visibleRegion().isEmpty();
}
/**
* \fn void MainWindow::effaceRes()
* \brief Efface le contenu des docs visibles.
*/
void MainWindow::effaceRes()
{
if (dockVisible(dockLem)) textEditLem->clear();
if (dockVisible(dockFlex)) textBrowserFlex->clear();
if (dockVisible(dockScand)) textEditScand->clear();
}
/**
* \fn
* \brief
*
*/
void MainWindow::exportPdf()
{
#ifndef QT_NO_PRINTER
QString nf = QFileDialog::getSaveFileName(this, "Export PDF",
QString(), "*.pdf");
if (!nf.isEmpty()) {
if (QFileInfo(nf).suffix().isEmpty())
nf.append(".pdf");
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(nf);
QTextEdit *tmpTE = new QTextEdit();
tmpTE->setHtml (editLatin->toHtml());
tmpTE->append(textEditLem->toHtml());
tmpTE->document()->print(&printer);
delete tmpTE;
}
#endif
}
/**
* \fn void MainWindow::imprimer()
* \brief Lance le dialogue d'impression pour la lemmatisation.
*/
void MainWindow::imprimer()
{
#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG)
QPrinter printer(QPrinter::HighResolution);
QPrintDialog *dlg = new QPrintDialog(&printer, this);
if (textEditLem->textCursor().hasSelection())
dlg->addEnabledOption(QAbstractPrintDialog::PrintSelection);
dlg->setWindowTitle(tr("Imprimer le texte et le lexique"));
if (dlg->exec() == QDialog::Accepted)
{
QTextEdit *tmpTE = new QTextEdit();
tmpTE->setHtml(editLatin->toHtml());
tmpTE->append(textEditLem->toHtml());
tmpTE->print(&printer);
delete tmpTE;
}
delete dlg;
#endif
}
/**
* \fn void MainWindow::langueInterface()
* \brief Sonde les actions frAct et enAct, et
* bascule l'interface dans la langue de l'action cochée.
*/
void MainWindow::langueInterface()
{
if (frAct->isChecked ())
{
langueI = "fr";
}
else if (enAct->isChecked ())
{
langueI = "en";
}
else langueI = "fr";
QMessageBox::about(this, tr("Collatinus 11"),
tr("Le changement de langue prendra effet"
"au prochain lancement de Collatinus."));
}
/**
* \fn void MainWindow::flechisLigne()
* \brief Provoque l'affichage des lemmes pouvant donner
* la forme affichée dans la ligne de saisie du dock
* Flexion.
*/
void MainWindow::flechisLigne()
{
MapLem ml = lemmatiseur->lemmatiseM (lineEditFlex->text());
if (!ml.empty())
{
textBrowserFlex->clear();
textBrowserFlex->append (flechisseur->tableaux(&ml));
//foreach (Lemme *l, ml.keys())
// textBrowserFlex->append (flechisseur->tableau(l));
}
}
/**
* \fn bool MainWindow::html()
* \brief Renvoie vrai si l'option html du lemmatiseur
* est armée.
*/
bool MainWindow::html()
{
return htmlAct->isChecked();
}
/**
* \fn void MainWindow::lancer()
* \brief Lance la lemmatisation et la scansion si
* les docks correspondants sont visibles.
*/
void MainWindow::lancer()
{
if (dockVisible(dockLem)) lemmatiseTxt();
if (dockVisible(dockScand)) scandeTxt();
}
/**
* \fn void MainWindow::lemmatiseLigne()
* \brief Lance la lemmatisation des formes *
* présentes dans la ligne de saisie du dock
* lemmatisation.
*/
void MainWindow::lemmatiseLigne()
{
textEditLem->append(lemmatiseur->lemmatiseT (lineEditLem->text()));
}
/**
* \fn void MainWindow::lemmatiseTxt()
* \brief Lance la lemmatisation de la totalité du
* texte contenu dans l'éditeur editLatin (partie supérieure
* de la fenêtre de l'application).
*/
void MainWindow::lemmatiseTxt()
{
// si la tâche dure trop longtemps :
// setUpdatesEnabled(false);
if (html())
textEditLem->setHtml(lemmatiseur->lemmatiseT(editLatin->toPlainText()));
else
textEditLem->setPlainText(lemmatiseur->lemmatiseT(editLatin->toPlainText()));
// setUpdatesEnabled(true);
}
/**
* \fn void MainWindow::maj()
* \brief Lance le dialogue de mise à jour des
* lexiques et dictionnaires.
*/
void MainWindow::maj()
{
Maj *majDial = new Maj ();
majDial->setFont(editLatin->font());
majDial->exec();
}
/**
* \fn void MainWindow::montreWDic(bool visible)
* \brief Rend visible le dictionnaire supplémentaire,
* et met à jour son contenu.
*/
void MainWindow::montreWDic(bool visible)
{
wDic->move(x()+width() + 80, y());
wDic->setVisible(visible);
lineEditDicW->setText (lineEditDic->text());
afficheLemsDicW();
lineEditDicW->clearFocus();
}
/**
* \fn void MainWindow::nouveau()
* \brief Après confirmation efface le texte et les résultats,
* permettant à l'utilisateur de recommencer /ab initio/
*/
void MainWindow::nouveau()
{
if (precaution()) return;
editLatin->clear();
textEditLem->clear();
textEditScand->clear();
}
/**
* \fn void MainWindow::ouvrir()
* \brief Affiche le dialogue d'ouverture de fichier.
*/
void MainWindow::ouvrir()
{
if (precaution ()) return;
nfAb = QFileDialog::getOpenFileName(this, "Collatinus - Ouvrir un fichier", repertoire);
if (nfAb.isEmpty()) return;
charger (nfAb);
nfAd = nfAb;
nfAd.prepend ("coll-");
}
void MainWindow::police()
{
bool ok;
QFont police = QFontDialog::getFont(&ok, font, this);
if ( ok )
{
font = police;
editLatin->setFont(font);
textEditLem->setFont(font);
textBrowserDic->setFont(font);
textBrowserW->setFont(font);
textEditScand->setFont(font);
textBrowserFlex->setFont(font);
}
}
/**
* \fn bool MainWindow::precaution()
* \brief Dialogue de précaution avant l'effacement du texte latin.
* Renvoie false si Oui/Yes a été cliqué.
*/
bool MainWindow::precaution()
{
if (!editLatin->document()->isEmpty()
|| !textEditLem->document()->isEmpty()
|| !textEditScand->document()->isEmpty())
{
int ret = QMessageBox::warning
(this, tr("Collatinus"),
tr("Un ou plusieurs onglets ont été modifiés. Effacer leur contenu ?"),
QMessageBox::Yes | QMessageBox::Default,
QMessageBox::No,
QMessageBox::Cancel | QMessageBox::Escape);
if (ret == QMessageBox::Yes)
return false;
return true;
}
return false;
}
/**
* \fn void MainWindow::readSettings()
* \brief Appelée à l'initialisation de l'application,
* pour retrouver les paramètres importants de
* la dernière session.
*/
void MainWindow::readSettings()
{
QSettings settings("Collatinus", "collatinus11");
// état de la fenêtre
settings.beginGroup("fenetre");
restoreGeometry(settings.value("geometry").toByteArray());
restoreState(settings.value("windowState").toByteArray());
settings.endGroup();
// dernier fichier chargé
settings.beginGroup("fichiers");
nfAb = settings.value ("nfAb").toString();
if (!nfAb.isEmpty() && QDir(nfAb).exists())
{
charger (nfAb);
nfAd = nfAb;
nfAd.prepend ("coll-");
}
settings.endGroup();
settings.beginGroup("options");
// police
font.setPointSize (settings.value("zoom").toInt());
//font.setFamily(settings.value("police").toString());
editLatin->setFont(font);
textEditLem->setFont(font);
textBrowserDic->setFont(font);
textBrowserW->setFont(font);
textEditScand->setFont(font);
textBrowserFlex->setFont(font);
// options de lemmatisation
alphaOptAct->setChecked (settings.value("alpha").toBool());
formeTAct->setChecked (settings.value("formetxt").toBool());
htmlAct->setChecked (settings.value("html").toBool());
majPertAct->setChecked (settings.value("majpert").toBool());
morphoAct->setChecked (settings.value("morpho").toBool());
nonRecAct->setChecked (settings.value("nonrec").toBool());
QString l = settings.value("cible").toString();
lemmatiseur->setCible (l);
foreach (QAction * action, grCibles->actions ())
if (action->text () == lemmatiseur->cibles()[l])
action->setChecked (true);
settings.endGroup();
// options appliquées au lemmatiseur
lemmatiseur->setAlpha (alphaOptAct->isChecked());
lemmatiseur->setFormeT (formeTAct->isChecked());
lemmatiseur->setHtml (htmlAct->isChecked());
lemmatiseur->setMajPert (majPertAct->isChecked());
lemmatiseur->setMorpho(morphoAct->isChecked());
settings.beginGroup("dictionnaires");
comboGlossaria->setCurrentIndex(settings.value("courant").toInt());
wDic->move(settings.value("posw").toPoint());
wDic->resize(settings.value("sizew").toSize());
wDic->setVisible(settings.value("wdic").toBool());
comboGlossariaW->setCurrentIndex(settings.value("courantW").toInt());
syncAct->setChecked(settings.value("sync").toBool());
settings.endGroup();
}
/**
* \fn void MainWindow::recherche()
* \brief Recherche dans l'éditeur de texte latin.
*/
void MainWindow::recherche()
{
bool ok;
rech = QInputDialog::getText(this, tr("Recherche"),
tr("Chercher :"), QLineEdit::Normal,
rech, &ok);
if (ok && !rech.isEmpty())
{
if (!editLatin->find (rech))
{
rech = QInputDialog::getText(this, tr("Chercher"),
tr("Retour au début ?"), QLineEdit::Normal,
rech, &ok);
if (ok && !rech.isEmpty())
{
// Retourner au debut
editLatin->moveCursor(QTextCursor::Start);
// Chercher à nouveau
editLatin->find(rech);
}
}
}
}
/**
* \fn void MainWindow::rechercheBis()
* \brief Suite de la recherche.
*
*/
void MainWindow::rechercheBis()
{
if (rech.isEmpty())
return;
bool ok = editLatin->find(rech);
if (!ok)
{
QTextCursor tc = editLatin->textCursor();
editLatin->moveCursor(QTextCursor::Start);
ok = editLatin->find(rech);
if (!ok) editLatin->setTextCursor(tc);
}
}
/**
* \fn void MainWindow::scandeLigne()
* \brief scande le contenu de la ligne de saisie du
* dock Scansion, et affiche le résultat.
*/
void MainWindow::scandeLigne()
{
textEditScand->setHtml(lemmatiseur->scandeTxt (lineEditScand->text(), false));
}
/**
* \fn void MainWindow::scandeTxt()
* \brief Lance la scansion du texte latin, et affiche le
* résultat dans le dock scansion.
*/
void MainWindow::scandeTxt()
{
textEditScand->setHtml(lemmatiseur->scandeTxt (editLatin->toPlainText(), false));
}
/**
* \fn void MainWindow::setCible()
* \brief Coordonne la langue cible cochée dans le menu
* et la langue cible du lemmatiseur.
*/
void MainWindow::setCible()
{
QAction * action = grCibles->checkedAction ();
foreach (QString cle, lemmatiseur->cibles().keys())
{
if (lemmatiseur->cibles()[cle] == action->text ())
{
lemmatiseur->setCible(cle);
break;
}
}
}
/**
* \fn void MainWindow::setLangue()
* \brief lis la langue d'interface, et
* procède aux initialisations.
*/
void MainWindow::setLangue()
{
QSettings settings("Collatinus", "collatinus11");
settings.beginGroup("interface");
langueI = settings.value("langue").toString();
settings.endGroup();
if (!langueI.isEmpty())
{
translator = new QTranslator(qApp);
translator->load(QString("/usr/share/collatinus")+"/collatinus_"+langueI);
qApp->installTranslator(translator);
}
else langueI = "fr";
}
/**
* \fn void MainWindow::stat()
* \brief Affiche les statistiques de lemmatisation et
* de scansion si le dock correspondant est visible.
*/
void MainWindow::stat()
{
if (dockVisible(dockLem))
{
textEditLem->setHtml(lemmatiseur->frequences(editLatin->toPlainText()).join(""));
}
if (dockVisible(dockScand))
textEditScand->setHtml(lemmatiseur->scandeTxt (editLatin->toPlainText(), true));
}
/**
* \fn void MainWindow::syncDW()
* \brief effectue dans le dictionnaire supplémentaire
* la même recherche que celle qui a été faite dans le
* principal.
*/
void MainWindow::syncDW()
{
if (wDic->isVisible())
{
lineEditDicW->setText(lineEditDic->text());
afficheLemsDicW ();
}
else montreWDic(true);
}
/**
* \fn void MainWindow::syncWD()
* \brief effectue dans le dictionnaire principal
* la même recherche que celle qui a été faite dans le
* supplémentaire.
*/
void MainWindow::syncWD()
{
lineEditDic->setText(lineEditDicW->text());
afficheLemsDic();
}
|