/manyears-C/Qt4GUI/aboutDialog.cpp

https://github.com/introlab/manyears · C++ · 156 lines · 119 code · 30 blank · 7 comment · 6 complexity · 082496ab7f29deea58f8c92b4842672d MD5 · raw file

  1. #include "aboutDialog.h"
  2. AboutDialog::AboutDialog()
  3. {
  4. int xImage = 20;
  5. int yImage = 20;
  6. int sideMargin = 10;
  7. int widthImage = 75;
  8. int heightImage = 75;
  9. int titleHeight = 40;
  10. int versionHeight = 20;
  11. int authorsHeight = 20;
  12. int websiteHeight = 20;
  13. int copyrightHeight = 20;
  14. int readmeHeight = 100;
  15. int buttonHeight = 25;
  16. int titleSpace = 5;
  17. int versionSpace = 2;
  18. int authorsSpace = 2;
  19. int websiteSpace = 2;
  20. int copyrightSpace = 10;
  21. int readmeSpace = 5;
  22. int widthButton = 100;
  23. int xText = widthImage + 20 + sideMargin;
  24. int yText = 10;
  25. int widthText = 500;
  26. // Read text
  27. QString resCopyright;
  28. QString resReadme;
  29. QString pathProject;
  30. QFile* pathCopyright;
  31. QFile* pathReadme;
  32. QString strCopyright;
  33. QString strReadme;
  34. QTextStream* stream;
  35. pathProject = QString(DEF_PROJECT_SOURCE_DIR);
  36. resCopyright = QString(DEF_RESOURCE_FILE_LICENSE);
  37. resCopyright = resCopyright.right(resCopyright.length() - pathProject.length());
  38. if (resCopyright.left(1) == "/")
  39. {
  40. resCopyright = ":" + resCopyright;
  41. }
  42. else
  43. {
  44. resCopyright = ":/" + resCopyright;
  45. }
  46. pathCopyright = new QFile(resCopyright);
  47. if (pathCopyright->open(QIODevice::ReadOnly | QIODevice::Text))
  48. {
  49. stream = new QTextStream(pathCopyright);
  50. strCopyright = stream->readAll();
  51. pathCopyright->close();
  52. }
  53. else
  54. {
  55. strCopyright = "";
  56. }
  57. resReadme = QString(DEF_PACKAGE_DESCRIPTION_FILE);
  58. resReadme = resReadme.right(resReadme.length() - pathProject.length());
  59. if (resReadme.left(1) == "/")
  60. {
  61. resReadme = ":" + resReadme;
  62. }
  63. else
  64. {
  65. resReadme = ":/" + resReadme;
  66. }
  67. pathReadme = new QFile(resReadme);
  68. if (pathReadme->open(QIODevice::ReadOnly | QIODevice::Text))
  69. {
  70. stream = new QTextStream(pathReadme);
  71. strReadme = stream->readAll();
  72. pathReadme->close();
  73. }
  74. else
  75. {
  76. strReadme = "";
  77. }
  78. // Create elements
  79. this->title = new QLabel(this);
  80. this->version = new QLabel(this);
  81. this->authors = new QLabel(this);
  82. this->website = new QLabel(this);
  83. this->copyright = new QLabel(this);
  84. this->readme = new QTextEdit(this);
  85. this->buttons = new QPushButton(this);
  86. this->logo = new QLabel(this);
  87. // Set information
  88. this->title->setText(QString("<FONT face = 'Tahoma' size = '6'><B>") + QString(DEF_PACKAGE_NAME) + QString("</B></FONT>"));
  89. this->version->setText(QString("<FONT face = 'Tahoma' size = '3'><B>Version: </B>") + QString(DEF_PACKAGE_VERSION) + QString("</FONT>"));
  90. this->authors->setText(QString("<FONT face = 'Tahoma' size = '3'><B>Authors: </B>") + QString(DEF_PACKAGE_VENDOR) + QString("</FONT>"));
  91. this->website->setText(QString("<FONT face = 'Tahoma' size = '3'><B>Website: </B><A href = '") + QString(DEF_NSIS_URL_INFO_ABOUT) + QString("'>") + QString(DEF_NSIS_URL_INFO_ABOUT) + QString("</A></FONT>"));
  92. this->copyright->setText(QString("<FONT face = 'Tahoma' size = '3'><B>Copyright: </B>") + strCopyright + QString("</FONT>"));
  93. this->readme->setText(strReadme);
  94. QIcon tmpImage(":/Images/logoonly.png");
  95. this->logo->setPixmap(tmpImage.pixmap(widthImage, heightImage));
  96. // Set position
  97. this->title->setGeometry(xText, yText, widthText, titleHeight);
  98. this->version->setGeometry(xText, yText + titleHeight + titleSpace, widthText, versionHeight);
  99. this->authors->setGeometry(xText, yText + titleHeight + titleSpace + versionHeight + versionSpace, widthText, authorsHeight);
  100. this->website->setGeometry(xText, yText + titleHeight + titleSpace + versionHeight + versionSpace + authorsHeight + authorsSpace, widthText, websiteHeight);
  101. this->copyright->setGeometry(xText, yText + titleHeight + titleSpace + versionHeight + versionSpace + authorsHeight + authorsSpace + websiteHeight + websiteSpace, widthText, copyrightHeight);
  102. this->readme->setGeometry(xText, yText + titleHeight + titleSpace + versionHeight + versionSpace + authorsHeight + authorsSpace + websiteHeight + websiteSpace + copyrightHeight + copyrightSpace, widthText, readmeHeight);
  103. this->buttons->setGeometry(xText + widthText - widthButton, yText + titleHeight + titleSpace + versionHeight + versionSpace + authorsHeight + authorsSpace + websiteHeight + websiteSpace + copyrightHeight + copyrightSpace + readmeHeight + readmeSpace, widthButton, buttonHeight);
  104. this->logo->setGeometry(xImage, yImage, widthImage, heightImage);
  105. // Others
  106. this->readme->setReadOnly(true);
  107. this->buttons->setText("Close");
  108. // Window
  109. this->setFixedSize(xText + widthText + sideMargin,
  110. yText + titleHeight + titleSpace + versionHeight + versionSpace + authorsHeight + authorsSpace + websiteHeight + websiteSpace + copyrightHeight + copyrightSpace + readmeHeight + readmeSpace + buttonHeight + yText);
  111. this->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Dialog);
  112. // Event
  113. QObject::connect(this->website, SIGNAL(linkActivated(QString)), this, SLOT(launchURL(QString)));
  114. QObject::connect(this->buttons, SIGNAL(clicked()), this, SLOT(closeDialog()));
  115. }
  116. AboutDialog::~AboutDialog()
  117. {
  118. }
  119. void AboutDialog::launchURL(const QString _url)
  120. {
  121. QDesktopServices::openUrl(QUrl(_url));
  122. }
  123. void AboutDialog::closeDialog()
  124. {
  125. this->close();
  126. }