PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/gle-graphics-4.2.4c/src/gui/about.cpp

#
C++ | 170 lines | 124 code | 16 blank | 30 comment | 3 complexity | 139f1d29a28bee26dd2ad292b65fa722 MD5 | raw file
Possible License(s): GPL-2.0
  1. /***********************************************************************************
  2. * QGLE - A Graphical Interface to GLE *
  3. * Copyright (C) 2006 A. S. Budden & J. Struyf *
  4. * *
  5. * This program is free software; you can redistribute it and/or *
  6. * modify it under the terms of the GNU General Public License *
  7. * as published by the Free Software Foundation; either version 2 *
  8. * of the License, or (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the Free Software *
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
  18. * *
  19. * Also add information on how to contact you by electronic and paper mail. *
  20. ***********************************************************************************/
  21. /***************************************************************
  22. * about.cpp: The class implementation for the about box. *
  23. ***************************************************************/
  24. #include <QtGui>
  25. #include "about.h"
  26. #include "qgle_statics.h"
  27. #include "qgle_definitions.h"
  28. #include "../gle/gle-interface/gle-interface.h"
  29. class MyQTextBrowser : public QTextBrowser {
  30. public:
  31. MyQTextBrowser();
  32. virtual ~MyQTextBrowser();
  33. virtual QSize sizeHint () const;
  34. };
  35. MyQTextBrowser::MyQTextBrowser() {
  36. }
  37. MyQTextBrowser::~MyQTextBrowser() {
  38. }
  39. QSize MyQTextBrowser::sizeHint() const {
  40. QSizeF size = document()->size();
  41. return QSize((int)size.width()+5, (int)size.height()+10);
  42. }
  43. AboutBox::AboutBox(QWidget* par, GLEInterface* gleInterface) : QDialog(par) {
  44. m_gleInterface = gleInterface;
  45. // Set the window title and size
  46. setWindowTitle(tr("About %1").arg(APP_NAME));
  47. QHBoxLayout *top = new QHBoxLayout();
  48. QVBoxLayout *left = new QVBoxLayout();
  49. QLabel* icon = new QLabel(this);
  50. icon->setPixmap(QPixmap(":/images/gle_shadow.png").scaled(QSize(64, 64)));
  51. left->addWidget(icon);
  52. left->addStretch(1);
  53. top->addLayout(left);
  54. QWidget* license = createLicensePanel();
  55. QTabWidget* tabWidget = new QTabWidget();
  56. tabWidget->addTab(createAboutPanel(), tr("About"));
  57. tabWidget->addTab(createContributorsPanel(), tr("Contributors"));
  58. tabWidget->addTab(license, tr("License"));
  59. top->addWidget(tabWidget);
  60. QPushButton *okButton = new QPushButton(tr("Close"));
  61. connect(okButton, SIGNAL(clicked()), this, SLOT(close()));
  62. QHBoxLayout *buttonLayout = new QHBoxLayout();
  63. buttonLayout->addStretch(1);
  64. buttonLayout->addWidget(okButton);
  65. QVBoxLayout *layout = new QVBoxLayout();
  66. layout->addLayout(top);
  67. layout->addLayout(buttonLayout);
  68. setLayout(layout);
  69. }
  70. // SLOT: show a given URL
  71. void AboutBox::showURL(const QUrl& url) {
  72. QDesktopServices::openUrl(url);
  73. }
  74. QTextBrowser* AboutBox::createAboutPanel()
  75. {
  76. // Create a label to display readme.txt
  77. MyQTextBrowser* label = new MyQTextBrowser();
  78. label->setOpenLinks(false);
  79. connect(label, SIGNAL(anchorClicked(const QUrl&)), this, SLOT(showURL(const QUrl&)));
  80. QFile file(":/about.html");
  81. // Open the file as a read only text file
  82. if (file.open(QIODevice::ReadOnly | QIODevice::Text))
  83. {
  84. QString html(file.readAll().constData());
  85. html.replace(tr("*VERSION*"), QString::fromUtf8(m_gleInterface->getGLEVersion().c_str()));
  86. html.replace(tr("*DATE*"), QString::fromUtf8(m_gleInterface->getGLEBuildDate().c_str()));
  87. label->setHtml(html);
  88. }
  89. label->document()->setTextWidth(m_minWidth);
  90. return label;
  91. }
  92. QWidget* AboutBox::createContributorsPanel()
  93. {
  94. QString html(tr(""
  95. "<h2>Contributors</h2>"
  96. "<p>"
  97. "The following people have given their time and talent to help support the GLE/QGLE effort (in alphabetical order)."
  98. "</p>"
  99. ""
  100. "<ul>"
  101. "<li>A. S. Budden: programming (QGLE), packager for Arch Linux</li>"
  102. "<li>Andrey G. Grozin: packager for Gentoo Linux</li>"
  103. "<li>Axel Rohde: 3.3f-h versions (these were 32 bit DOS and OS/2 ports)</li>"
  104. "<li>Bryn Jeffries: programming (Linux)</li>"
  105. "<li>Chris Pugmire: original program creation and design</li>"
  106. "<li>Christoph Brendes: programming</li>"
  107. "<li>David Parfitt: documentation (GLE users guide)</li>"
  108. "<li>Edd Edmondson: packager for Mac OS/X"
  109. "<li>Jan Struyf: programming (and current 4.x series maintainer)</li>"
  110. "<li>Laurence Abbott: programming</li>"
  111. "<li>Michal Vyskocil: packager for openSUSE</li>"
  112. "<li>Stephen Blundell: documentation (GLE users guide)</li>"
  113. "<li>Steve Wilkinson: programming (user interface)</li>"
  114. "<li>Terje R&oslash;sten: packager for Fedora Core</li>"
  115. "<li>Vincent LaBella: resurrected 3.3h to GLE 4.0 C++ code base</li>"
  116. "<li>Zbigniew Kisiel: testing</li>"
  117. "</ul>"
  118. "<p>&nbsp;</p>"
  119. ""));
  120. QTextBrowser* label = new QTextBrowser();
  121. label->setOpenLinks(false);
  122. label->setHtml(html);
  123. return label;
  124. }
  125. QWidget* AboutBox::createLicensePanel()
  126. {
  127. // Create a label to display readme.txt
  128. QTextEdit* label = new QTextEdit();
  129. label->setReadOnly(true);
  130. QString fileName(QString::fromUtf8(m_gleInterface->getManualLocation().c_str()));
  131. fileName.resize(fileName.lastIndexOf(QDir::separator()));
  132. fileName += QDir::separator();
  133. fileName += tr("LICENSE.txt");
  134. GLEInterface* iface = GLEGetInterfacePointer();
  135. std::string licenseFileTxt;
  136. bool res = iface->readFileOrGZIPTxt(fileName.toUtf8().constData(), &licenseFileTxt);
  137. if (res) {
  138. QFont font;
  139. // Set the font to be fixed pitch
  140. font.setFixedPitch(true);
  141. font.setFamily("Courier");
  142. font.setStretch(QFont::Condensed);
  143. label->setLineWrapMode(QTextEdit::NoWrap);
  144. label->setFont(font);
  145. label->setTextColor(Qt::black);
  146. // Get the text and put it in the label
  147. label->setPlainText(licenseFileTxt.c_str());
  148. QFontMetrics fm(font);
  149. m_minWidth = fm.width("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
  150. } else {
  151. label->setPlainText(tr("File not found: '%1'").arg(fileName));
  152. }
  153. return label;
  154. }