Seamly2D
Code documentation
def.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file def.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 11 6, 2015
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2015 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #include "def.h"
53 
54 #include <QApplication>
55 #include <QChar>
56 #include <QColor>
57 #include <QComboBox>
58 #include <QCursor>
59 #include <QDir>
60 #include <QDirIterator>
61 #include <QFileInfo>
62 #include <QGuiApplication>
63 #include <QImage>
64 #include <QLatin1Char>
65 #include <QList>
66 #include <QMap>
67 #include <QMessageLogger>
68 #include <QObject>
69 #include <QPixmap>
70 #include <QPrinterInfo>
71 #include <QProcess>
72 #include <QRgb>
73 #include <QStaticStringData>
74 #include <QStringData>
75 #include <QStringDataPtr>
76 #include <QtDebug>
77 #include <QPixmapCache>
78 #include <QGraphicsItem>
79 #include <QDesktopServices>
80 #include <QUrl>
81 
82 #include "vabstractapplication.h"
83 
84 //functions
85 const QString degTorad_F = QStringLiteral("degTorad");
86 const QString radTodeg_F = QStringLiteral("radTodeg");
87 const QString sin_F = QStringLiteral("sin");
88 const QString cos_F = QStringLiteral("cos");
89 const QString tan_F = QStringLiteral("tan");
90 const QString asin_F = QStringLiteral("asin");
91 const QString acos_F = QStringLiteral("acos");
92 const QString atan_F = QStringLiteral("atan");
93 const QString sinh_F = QStringLiteral("sinh");
94 const QString cosh_F = QStringLiteral("cosh");
95 const QString tanh_F = QStringLiteral("tanh");
96 const QString asinh_F = QStringLiteral("asinh");
97 const QString acosh_F = QStringLiteral("acosh");
98 const QString atanh_F = QStringLiteral("atanh");
99 const QString sinD_F = QStringLiteral("sinD");
100 const QString cosD_F = QStringLiteral("cosD");
101 const QString tanD_F = QStringLiteral("tanD");
102 const QString asinD_F = QStringLiteral("asinD");
103 const QString acosD_F = QStringLiteral("acosD");
104 const QString atanD_F = QStringLiteral("atanD");
105 const QString log2_F = QStringLiteral("log2");
106 const QString log10_F = QStringLiteral("log10");
107 const QString log_F = QStringLiteral("log");
108 const QString ln_F = QStringLiteral("ln");
109 const QString exp_F = QStringLiteral("exp");
110 const QString sqrt_F = QStringLiteral("sqrt");
111 const QString sign_F = QStringLiteral("sign");
112 const QString rint_F = QStringLiteral("rint");
113 const QString abs_F = QStringLiteral("abs");
114 const QString min_F = QStringLiteral("min");
115 const QString max_F = QStringLiteral("max");
116 const QString sum_F = QStringLiteral("sum");
117 const QString avg_F = QStringLiteral("avg");
118 const QString fmod_F = QStringLiteral("fmod");
119 
120 const QStringList builInFunctions = QStringList() << degTorad_F << radTodeg_F
121  << sin_F << cos_F << tan_F << asin_F << acos_F << atan_F
122  << sinh_F << cosh_F << tanh_F << asinh_F << acosh_F << atanh_F
123  << sinD_F << cosD_F << tanD_F << asinD_F << acosD_F << atanD_F
124  << log2_F << log10_F << log_F << ln_F << exp_F << sqrt_F
125  << sign_F << rint_F << abs_F << min_F << max_F << sum_F
126  << avg_F << fmod_F;
127 
128 // Postfix operators
129 const QString cm_Oprt = QStringLiteral("cm");
130 const QString mm_Oprt = QStringLiteral("mm");
131 const QString in_Oprt = QStringLiteral("in");
132 
133 const QStringList builInPostfixOperators = QStringList() << cm_Oprt
134  << mm_Oprt
135  << in_Oprt;
136 
137 const QString pl_size = QStringLiteral("size");
138 const QString pl_height = QStringLiteral("height");
139 const QString pl_date = QStringLiteral("date");
140 const QString pl_time = QStringLiteral("time");
141 const QString pl_patternName = QStringLiteral("patternName");
142 const QString pl_patternNumber = QStringLiteral("patternNumber");
143 const QString pl_author = QStringLiteral("author");
144 const QString pl_customer = QStringLiteral("customer");
145 const QString pl_pExt = QStringLiteral("pExt");
146 const QString pl_pFileName = QStringLiteral("pFileName");
147 const QString pl_mFileName = QStringLiteral("mFileName");
148 const QString pl_mExt = QStringLiteral("mExt");
149 const QString pl_pLetter = QStringLiteral("pLetter");
150 const QString pl_pAnnotation = QStringLiteral("pAnnotation");
151 const QString pl_pOrientation = QStringLiteral("pOrientation");
152 const QString pl_pRotation = QStringLiteral("pRotation");
153 const QString pl_pTilt = QStringLiteral("pTilt");
154 const QString pl_pFoldPosition = QStringLiteral("pFoldPosition");
155 const QString pl_pName = QStringLiteral("pName");
156 const QString pl_pQuantity = QStringLiteral("pQuantity");
157 const QString pl_mFabric = QStringLiteral("mFabric");
158 const QString pl_mLining = QStringLiteral("mLining");
159 const QString pl_mInterfacing = QStringLiteral("mInterfacing");
160 const QString pl_mInterlining = QStringLiteral("mInterlining");
161 const QString pl_wCut = QStringLiteral("wCut");
162 const QString pl_wOnFold = QStringLiteral("wOnFold");
163 
164 const QStringList labelTemplatePlaceholders = QStringList() << pl_size
165  << pl_height
166  << pl_date
167  << pl_time
168  << pl_patternName
170  << pl_author
171  << pl_customer
172  << pl_pExt
173  << pl_pFileName
174  << pl_mFileName
175  << pl_mExt
176  << pl_pLetter
177  << pl_pAnnotation
178  << pl_pOrientation
179  << pl_pRotation
180  << pl_pTilt
182  << pl_pName
183  << pl_pQuantity
184  << pl_mFabric
185  << pl_mLining
186  << pl_mInterfacing
187  << pl_mInterlining
188  << pl_wCut
189  << pl_wOnFold;
190 
191 const QString cursorArrowOpenHand = QStringLiteral("://cursor/cursor-arrow-openhand.png");
192 const QString cursorArrowCloseHand = QStringLiteral("://cursor/cursor-arrow-closehand.png");
193 
194 // From documantation: If you use QStringLiteral you should avoid declaring the same literal in multiple places: This
195 // furthermore blows up the binary sizes.
196 const QString degreeSymbol = QStringLiteral("°");
197 const QString trueStr = QStringLiteral("true");
198 const QString falseStr = QStringLiteral("false");
199 
200 const QString unitMM = QStringLiteral("mm");
201 const QString unitCM = QStringLiteral("cm");
202 const QString unitINCH = QStringLiteral("inch");
203 const QString unitPX = QStringLiteral("px");
204 
205 //---------------------------------------------------------------------------------------------------------------------
206 void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int hotX, int hotY)
207 {
208 #ifndef QT_NO_CURSOR
209  SCASSERT(item != nullptr)
210 
211  QPixmap pixmap;
212 
213  if (not QPixmapCache::find(pixmapPath, &pixmap))
214  {
215  pixmap = QPixmap(pixmapPath);
216  QPixmapCache::insert(pixmapPath, pixmap);
217  }
218 
219  item->setCursor(QCursor(pixmap, hotX, hotY));
220 #else
221  Q_UNUSED(item)
222  Q_UNUSED(pixmapPath)
223  Q_UNUSED(hotX)
224  Q_UNUSED(hotY)
225 #endif
226 }
227 
228 const qreal PrintDPI = 96.0;
229 
230 //---------------------------------------------------------------------------------------------------------------------
231 double ToPixel(double val, const Unit &unit)
232 {
233  switch (unit)
234  {
235  case Unit::Mm:
236  return (val / 25.4) * PrintDPI;
237  case Unit::Cm:
238  return ((val * 10.0) / 25.4) * PrintDPI;
239  case Unit::Inch:
240  return val * PrintDPI;
241  case Unit::Px:
242  return val;
243  default:
244  break;
245  }
246  return 0;
247 }
248 
249 //---------------------------------------------------------------------------------------------------------------------
250 double FromPixel(double pix, const Unit &unit)
251 {
252  switch (unit)
253  {
254  case Unit::Mm:
255  return (pix / PrintDPI) * 25.4;
256  case Unit::Cm:
257  return ((pix / PrintDPI) * 25.4) / 10.0;
258  case Unit::Inch:
259  return pix / PrintDPI;
260  case Unit::Px:
261  return pix;
262  default:
263  break;
264  }
265  return 0;
266 }
267 
268 //---------------------------------------------------------------------------------------------------------------------
269 qreal UnitConvertor(qreal value, const Unit &from, const Unit &to)
270 {
271  switch (from)
272  {
273  case Unit::Mm:
274  switch (to)
275  {
276  case Unit::Mm:
277  return value;
278  case Unit::Cm:
279  return value / 10.0;
280  case Unit::Inch:
281  return value / 25.4;
282  case Unit::Px:
283  return (value / 25.4) * PrintDPI;
284  default:
285  break;
286  }
287  break;
288  case Unit::Cm:
289  switch (to)
290  {
291  case Unit::Mm:
292  return value * 10.0;
293  case Unit::Cm:
294  return value;
295  case Unit::Inch:
296  return value / 2.54;
297  case Unit::Px:
298  return ((value * 10.0) / 25.4) * PrintDPI;
299  default:
300  break;
301  }
302  break;
303  case Unit::Inch:
304  switch (to)
305  {
306  case Unit::Mm:
307  return value * 25.4;
308  case Unit::Cm:
309  return value * 2.54;
310  case Unit::Inch:
311  return value;
312  case Unit::Px:
313  return value * PrintDPI;
314  default:
315  break;
316  }
317  break;
318  case Unit::Px:
319  switch (to)
320  {
321  case Unit::Mm:
322  return (value / PrintDPI) * 25.4;
323  case Unit::Cm:
324  return ((value / PrintDPI) * 25.4) / 10.0;
325  case Unit::Inch:
326  return value / PrintDPI;
327  case Unit::Px:
328  return value;
329  default:
330  break;
331  }
332  break;
333  default:
334  break;
335  }
336  return 0;
337 }
338 
339 //---------------------------------------------------------------------------------------------------------------------
340 /**
341  * @brief UnitConvertor Converts the values of the given margin from given unit to the new unit.
342  * returns a new instand of QMarginsF.
343  *
344  * @param margin
345  * @param from
346  * @param to
347  * @return
348  */
349 QMarginsF UnitConvertor(const QMarginsF &margins, const Unit &from, const Unit &to)
350 {
351  const qreal left = UnitConvertor(margins.left(),from, to);
352  const qreal top = UnitConvertor(margins.top(),from, to);
353  const qreal right = UnitConvertor(margins.right(),from, to);
354  const qreal bottom = UnitConvertor(margins.bottom(),from, to);
355 
356  return QMarginsF(left, top, right, bottom);
357 }
358 
359 
360 //---------------------------------------------------------------------------------------------------------------------
361 QStringList SupportedLocales()
362 {
363  const QStringList locales = QStringList() << QStringLiteral("ru_RU")
364  << QStringLiteral("uk_UA")
365  << QStringLiteral("de_DE")
366  << QStringLiteral("cs_CZ")
367  << QStringLiteral("he_IL")
368  << QStringLiteral("fr_FR")
369  << QStringLiteral("it_IT")
370  << QStringLiteral("nl_NL")
371  << QStringLiteral("id_ID")
372  << QStringLiteral("es_ES")
373  << QStringLiteral("fi_FI")
374  << QStringLiteral("en_US")
375  << QStringLiteral("en_CA")
376  << QStringLiteral("en_IN")
377  << QStringLiteral("ro_RO")
378  << QStringLiteral("zh_CN")
379  << QStringLiteral("pt_BR")
380  << QStringLiteral("el_GR");
381 
382  return locales;
383 }
384 
385 //---------------------------------------------------------------------------------------------------------------------
386 /**
387  * @brief strippedName the function call around curFile to exclude the path to the file.
388  * @param fullFileName full path to the file.
389  * @return file name.
390  */
391 QString strippedName(const QString &fullFileName)
392 {
393  return QFileInfo(fullFileName).fileName();
394 }
395 
396 /**
397  * @brief makeHeaderName make a 1 char tablewidgetitem header name based on a translated string.
398  * @param name full name of header item.
399  * @return 1 char name.
400  */
401 QString makeHeaderName(const QString &name)
402 {
403  QString headerStr = QObject::tr("%1").arg(name);
404  return headerStr.left(1).toUpper();
405 }
406 
407 //---------------------------------------------------------------------------------------------------------------------
408 QString RelativeMPath(const QString &patternPath, const QString &absoluteMPath)
409 {
410  if (patternPath.isEmpty() || absoluteMPath.isEmpty())
411  {
412  return absoluteMPath;
413  }
414 
415  if (QFileInfo(absoluteMPath).isRelative())
416  {
417  return absoluteMPath;
418  }
419 
420  return QFileInfo(patternPath).absoluteDir().relativeFilePath(absoluteMPath);
421 }
422 
423 //---------------------------------------------------------------------------------------------------------------------
424 QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath)
425 {
426  if (patternPath.isEmpty() || relativeMPath.isEmpty())
427  {
428  return relativeMPath;
429  }
430 
431  if (QFileInfo(relativeMPath).isAbsolute())
432  {
433  return relativeMPath;
434  }
435 
436  return QFileInfo(QFileInfo(patternPath).absoluteDir(), relativeMPath).absoluteFilePath();
437 }
438 
439 //---------------------------------------------------------------------------------------------------------------------
440 QSharedPointer<QPrinter> PreparePrinter(const QPrinterInfo &info, QPrinter::PrinterMode mode)
441 {
442  QPrinterInfo tmpInfo = info;
443  if(tmpInfo.isNull() || tmpInfo.printerName().isEmpty())
444  {
445  const QStringList list = QPrinterInfo::availablePrinterNames();
446 
447  if(list.isEmpty())
448  {
449  return QSharedPointer<QPrinter>();
450  }
451  else
452  {
453  tmpInfo = QPrinterInfo::printerInfo(list.first());
454  }
455  }
456 
457  auto printer = QSharedPointer<QPrinter>(new QPrinter(tmpInfo, mode));
458  printer->setResolution(static_cast<int>(PrintDPI));
459  return printer;
460 }
461 
462 //---------------------------------------------------------------------------------------------------------------------
464 {
465  QPageLayout layout = printer->pageLayout();
466  layout.setUnits(QPageLayout::Millimeter);
467  const QMarginsF minMargins = layout.minimumMargins();
468  QMarginsF min;
469  min.setLeft(UnitConvertor(minMargins.left(), Unit::Mm, Unit::Px));
470  min.setRight(UnitConvertor(minMargins.right(), Unit::Mm, Unit::Px));
471  min.setTop(UnitConvertor(minMargins.top(), Unit::Mm, Unit::Px));
472  min.setBottom(UnitConvertor(minMargins.bottom(), Unit::Mm, Unit::Px));
473  return min;
474 }
475 
476 //---------------------------------------------------------------------------------------------------------------------
478 {
479  if (printer.isNull())
480  {
481  return QMarginsF();
482  }
483 
484  // We can't use Unit::Px because our dpi in most cases is different
485  return UnitConvertor(printer->pageLayout().margins(), Unit::Mm, Unit::Px);
486 }
487 
488 //---------------------------------------------------------------------------------------------------------------------
489 QPixmap darkenPixmap(const QPixmap &pixmap)
490 {
491  QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
492  const int imgh = img.height();
493  const int imgw = img.width();
494  for (int y = 0; y < imgh; ++y)
495  {
496  for (int x = 0; x < imgw; ++x)
497  {
498  int h, s, v;
499  QRgb pixel = img.pixel(x, y);
500  const int a = qAlpha(pixel);
501  QColor hsvColor(pixel);
502  hsvColor.getHsv(&h, &s, &v);
503  s = qMin(100, s * 2);
504  v = v / 2;
505  hsvColor.setHsv(h, s, v);
506  pixel = hsvColor.rgb();
507  img.setPixel(x, y, qRgba(qRed(pixel), qGreen(pixel), qBlue(pixel), a));
508  }
509  }
510  return QPixmap::fromImage(img);
511 }
512 
513 //---------------------------------------------------------------------------------------------------------------------
514 void ShowInGraphicalShell(const QString &filePath)
515 {
516  QStringList args;
517 #ifdef Q_OS_MAC
518  args << "-e";
519  args << "tell application \"Finder\"";
520  args << "-e";
521  args << "activate";
522  args << "-e";
523  args << "select POSIX file \""+filePath+"\"";
524  args << "-e";
525  args << "end tell";
526  QProcess::startDetached(QStringLiteral("osascript"), args);
527 #elif defined(Q_OS_WIN)
528  QProcess::startDetached(QStringLiteral("explorer"), QStringList{"/select", QDir::toNativeSeparators(filePath)});
529 #else
530  QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(filePath).path()));
531 #endif
532 
533 }
534 
535 const QString LONG_OPTION_NO_HDPI_SCALING = QStringLiteral("no-scaling");
536 
537 //---------------------------------------------------------------------------------------------------------------------
538 bool IsOptionSet(int argc, char *argv[], const char *option)
539 {
540  for (int i = 1; i < argc; ++i)
541  {
542  if (!qstrcmp(argv[i], option))
543  {
544  return true;
545  }
546  }
547  return false;
548 }
549 
550 //---------------------------------------------------------------------------------------------------------------------
551 void InitHighDpiScaling(int argc, char *argv[])
552 {
553  /* For more info see: http://doc.qt.io/qt-5/highdpi.html */
554  if (IsOptionSet(argc, argv, qPrintable(QLatin1String("--") + LONG_OPTION_NO_HDPI_SCALING)))
555  {
556  QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
557  }
558  else
559  {
560  QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // DPI support
561  }
562 }
563 //---------------------------------------------------------------------------------------------------------------------
564 
565 const QString strSlit = QStringLiteral("slit");
566 const QString strTNotch = QStringLiteral("tNotch");
567 const QString strUNotch = QStringLiteral("uNotch");
568 const QString strVInternal = QStringLiteral("vInternal");
569 const QString strVExternal = QStringLiteral("vExternal");
570 const QString strCastle = QStringLiteral("castle");
571 const QString strDiamond = QStringLiteral("diamond");
572 
573 //---------------------------------------------------------------------------------------------------------------------
575 {
576  switch(type)
577  {
578  case NotchType::Slit:
579  return strSlit;
580  case NotchType::TNotch:
581  return strTNotch;
582  case NotchType::UNotch:
583  return strUNotch;
585  return strVInternal;
587  return strVExternal;
588  case NotchType::Castle:
589  return strCastle;
590  case NotchType::Diamond:
591  return strDiamond;
592  default:
593  break;
594  }
595 
596  return strSlit;
597 }
598 
599 //---------------------------------------------------------------------------------------------------------------------
600 NotchType stringToNotchType(const QString &value)
601 {
602  const QStringList values = QStringList() << strSlit << strTNotch << strUNotch << strVInternal << strVExternal
603  << strCastle << strDiamond;
604 
605  switch(values.indexOf(value))
606  {
607  case 0:
608  return NotchType::Slit;
609  case 1:
610  return NotchType::TNotch;
611  case 2:
612  return NotchType::UNotch;
613  case 3:
614  return NotchType::VInternal;
615  case 4:
616  return NotchType::VExternal;
617  case 5:
618  return NotchType::Castle;
619  case 6:
620  return NotchType::Diamond;
621  default:
622  break;
623  }
624  return NotchType::Slit;
625 }
626 
627 const QString strStraightforward = QStringLiteral("straightforward");
628 const QString strBisector = QStringLiteral("bisector");
629 const QString strIntersection = QStringLiteral("intersection");
630 
631 //---------------------------------------------------------------------------------------------------------------------
633 {
634  switch(type)
635  {
637  return strStraightforward;
639  return strBisector;
641  return strIntersection;
642  default:
643  break;
644  }
645 
646  return strStraightforward;
647 }
648 
649 //---------------------------------------------------------------------------------------------------------------------
650 NotchSubType stringToNotchSubType(const QString &value)
651 {
652  const QStringList values = QStringList() << strStraightforward << strBisector << strIntersection;
653 
654  switch(values.indexOf(value))
655  {
656  case 0:
658  case 1:
659  return NotchSubType::Bisector;
660  case 2:
662  default:
663  break;
664  }
666 }
667 
668 
669 //---------------------------------------------------------------------------------------------------------------------
670 Unit StrToUnits(const QString &unit)
671 {
672  const QStringList units = QStringList() << unitMM << unitCM << unitINCH << unitPX;
673  Unit result = Unit::Cm;
674  switch (units.indexOf(unit))
675  {
676  case 0:// mm
677  result = Unit::Mm;
678  break;
679  case 2:// inch
680  result = Unit::Inch;
681  break;
682  case 3:// px
683  result = Unit::Px;
684  break;
685  case 1:// cm
686  default:
687  result = Unit::Cm;
688  break;
689  }
690  return result;
691 }
692 
693 //---------------------------------------------------------------------------------------------------------------------
694 /**
695  * @brief UnitsToStr translate unit to string.
696  *
697  * This method used when need write unit in xml file and for showing unit in dialogs.
698  * @param unit curent unit
699  * @param translate true if need show translated name. Default value false.
700  * @return string reprezantation for unit.
701  */
702 QString UnitsToStr(const Unit &unit, const bool translate)
703 {
704  QString result;
705  switch (unit)
706  {
707  case Unit::Mm:
708  translate ? result = QObject::tr("mm") : result = unitMM;
709  break;
710  case Unit::Inch:
711  translate ? result = QObject::tr("inch") : result = unitINCH;
712  break;
713  case Unit::Px:
714  translate ? result = QObject::tr("px") : result = unitPX;
715  break;
716  case Unit::Cm:
717  default:
718  translate ? result = QObject::tr("cm") : result = unitCM;
719  break;
720  }
721  return result;
722 }
723 
724 //---------------------------------------------------------------------------------------------------------------------
725 void InitLanguages(QComboBox *combobox)
726 {
727  SCASSERT(combobox != nullptr)
728  combobox->clear();
729 
730  QStringList fileNames;
731  QDirIterator it(qApp->translationsPath(), QStringList("seamly2d_*.qm"), QDir::Files, QDirIterator::Subdirectories);
732  while (it.hasNext())
733  {
734  it.next();
735  fileNames.append(it.fileName());
736  }
737 
738  bool englishUS = false;
739  const QString en_US = QStringLiteral("en_US");
740 
741  for (int i = 0; i < fileNames.size(); ++i)
742  {
743  // get locale extracted by filename
744  QString locale;
745  locale = fileNames.at(i); // "seamly2d_de_De.qm"
746  locale.truncate(locale.lastIndexOf('.')); // "seamly2d_de_De"
747  locale.remove(0, locale.indexOf('_') + 1); // "de_De"
748 
749  if (not englishUS)
750  {
751  englishUS = (en_US == locale);
752  }
753 
754  QLocale loc = QLocale(locale);
755  QString lang = loc.nativeLanguageName();
756  QIcon ico(QString("%1/%2.png").arg(":/flags").arg(QLocale::countryToString(loc.country())));
757 
758  combobox->addItem(ico, lang, locale);
759  }
760 
761  if (combobox->count() == 0 || not englishUS)
762  {
763  // English language is internal and doens't have own *.qm file.
764  QIcon ico(QString(":/flags/United States.png"));
765  QString lang = QLocale(en_US).nativeLanguageName();
766  combobox->addItem(ico, lang, en_US);
767  }
768 
769  // set default translators and language checked
770  qint32 index = combobox->findData(qApp->Settings()->GetLocale());
771  if (index != -1)
772  {
773  combobox->setCurrentIndex(index);
774  }
775 }
const QString pl_size
Definition: def.cpp:137
const QString asinD_F
Definition: def.cpp:102
const QString pl_customer
Definition: def.cpp:144
Unit StrToUnits(const QString &unit)
Definition: def.cpp:670
const QString log10_F
Definition: def.cpp:106
const QString strDiamond
Definition: def.cpp:571
QString makeHeaderName(const QString &name)
makeHeaderName make a 1 char tablewidgetitem header name based on a translated string.
Definition: def.cpp:401
const QString cursorArrowOpenHand
Definition: def.cpp:191
const QStringList builInFunctions
Definition: def.cpp:120
const QString cm_Oprt
Definition: def.cpp:129
const QString pl_pExt
Definition: def.cpp:145
double ToPixel(double val, const Unit &unit)
Definition: def.cpp:231
const QString tanh_F
Definition: def.cpp:95
QSharedPointer< QPrinter > PreparePrinter(const QPrinterInfo &info, QPrinter::PrinterMode mode)
Definition: def.cpp:440
void InitHighDpiScaling(int argc, char *argv[])
Definition: def.cpp:551
QPixmap darkenPixmap(const QPixmap &pixmap)
Definition: def.cpp:489
const QString pl_mExt
Definition: def.cpp:148
const QString ln_F
Definition: def.cpp:108
const QString pl_pFoldPosition
Definition: def.cpp:154
QMarginsF GetPrinterFields(const QSharedPointer< QPrinter > &printer)
Definition: def.cpp:477
const QString mm_Oprt
Definition: def.cpp:130
const qreal PrintDPI
Definition: def.cpp:228
const QString tanD_F
Definition: def.cpp:101
const QString pl_wCut
Definition: def.cpp:161
const QString acos_F
Definition: def.cpp:91
const QString pl_author
Definition: def.cpp:143
const QString sum_F
Definition: def.cpp:116
QString notchSubTypeToString(NotchSubType type)
Definition: def.cpp:632
const QString pl_time
Definition: def.cpp:140
const QString unitMM
Definition: def.cpp:200
const QString tan_F
Definition: def.cpp:89
const QString strCastle
Definition: def.cpp:570
const QString pl_pQuantity
Definition: def.cpp:156
const QString LONG_OPTION_NO_HDPI_SCALING
Definition: def.cpp:535
const QString strIntersection
Definition: def.cpp:629
const QString atan_F
Definition: def.cpp:92
const QString min_F
Definition: def.cpp:114
const QString sin_F
Definition: def.cpp:87
const QStringList labelTemplatePlaceholders
Definition: def.cpp:164
QString strippedName(const QString &fullFileName)
strippedName the function call around curFile to exclude the path to the file.
Definition: def.cpp:391
void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int hotX, int hotY)
Definition: def.cpp:206
const QString strStraightforward
Definition: def.cpp:627
const QString pl_mFileName
Definition: def.cpp:147
const QString pl_patternName
Definition: def.cpp:141
const QString acosD_F
Definition: def.cpp:103
const QString pl_pAnnotation
Definition: def.cpp:150
const QString cosD_F
Definition: def.cpp:100
const QString in_Oprt
Definition: def.cpp:131
const QString sinD_F
Definition: def.cpp:99
const QString pl_pName
Definition: def.cpp:155
const QString unitCM
Definition: def.cpp:201
void ShowInGraphicalShell(const QString &filePath)
Definition: def.cpp:514
const QString cursorArrowCloseHand
Definition: def.cpp:192
const QString pl_wOnFold
Definition: def.cpp:162
const QString sinh_F
Definition: def.cpp:93
const QString rint_F
Definition: def.cpp:112
const QStringList builInPostfixOperators
Definition: def.cpp:133
const QString pl_patternNumber
Definition: def.cpp:142
QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath)
Definition: def.cpp:424
const QString strSlit
Definition: def.cpp:565
const QString cos_F
Definition: def.cpp:88
const QString avg_F
Definition: def.cpp:117
const QString acosh_F
Definition: def.cpp:97
const QString pl_mLining
Definition: def.cpp:158
const QString atanD_F
Definition: def.cpp:104
const QString atanh_F
Definition: def.cpp:98
bool IsOptionSet(int argc, char *argv[], const char *option)
Definition: def.cpp:538
const QString degreeSymbol
Definition: def.cpp:196
const QString log2_F
Definition: def.cpp:105
const QString asinh_F
Definition: def.cpp:96
const QString fmod_F
Definition: def.cpp:118
void InitLanguages(QComboBox *combobox)
Definition: def.cpp:725
const QString pl_pFileName
Definition: def.cpp:146
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.
Definition: def.cpp:702
const QString cosh_F
Definition: def.cpp:94
const QString unitPX
Definition: def.cpp:203
const QString radTodeg_F
Definition: def.cpp:86
const QString strTNotch
Definition: def.cpp:566
const QString abs_F
Definition: def.cpp:113
const QString strVInternal
Definition: def.cpp:568
const QString sign_F
Definition: def.cpp:111
const QString pl_date
Definition: def.cpp:139
QStringList SupportedLocales()
Definition: def.cpp:361
const QString pl_mInterfacing
Definition: def.cpp:159
const QString sqrt_F
Definition: def.cpp:110
const QString unitINCH
Definition: def.cpp:202
const QString strUNotch
Definition: def.cpp:567
const QString pl_mFabric
Definition: def.cpp:157
const QString pl_pOrientation
Definition: def.cpp:151
QString RelativeMPath(const QString &patternPath, const QString &absoluteMPath)
Definition: def.cpp:408
double FromPixel(double pix, const Unit &unit)
Definition: def.cpp:250
const QString pl_pRotation
Definition: def.cpp:152
const QString asin_F
Definition: def.cpp:90
const QString trueStr
Definition: def.cpp:197
const QString pl_mInterlining
Definition: def.cpp:160
const QString degTorad_F
Definition: def.cpp:85
const QString falseStr
Definition: def.cpp:198
QMarginsF GetMinPrinterFields(const QSharedPointer< QPrinter > &printer)
Definition: def.cpp:463
NotchType stringToNotchType(const QString &value)
Definition: def.cpp:600
const QString pl_pTilt
Definition: def.cpp:153
const QString max_F
Definition: def.cpp:115
const QString exp_F
Definition: def.cpp:109
const QString pl_height
Definition: def.cpp:138
const QString strBisector
Definition: def.cpp:628
const QString strVExternal
Definition: def.cpp:569
const QString pl_pLetter
Definition: def.cpp:149
QString notchTypeToString(NotchType type)
Definition: def.cpp:574
qreal UnitConvertor(qreal value, const Unit &from, const Unit &to)
Definition: def.cpp:269
const QString log_F
Definition: def.cpp:107
NotchSubType stringToNotchSubType(const QString &value)
Definition: def.cpp:650
NotchType
Definition: def.h:123
#define SCASSERT(cond)
Definition: def.h:317
NotchSubType
Definition: def.h:137
Unit
Definition: def.h:105
#define qApp
Definition: vapplication.h:67
#define translate(context, source)
Definition: vcmdexport.cpp:41