| 26 #include "common.h" |
26 #include "common.h" |
| 27 #include "aboutDialog.h" |
27 #include "aboutDialog.h" |
| 28 |
28 |
| 29 AboutDialog::AboutDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { |
29 AboutDialog::AboutDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { |
| 30 QWidget* mainTab, *licenseTab; |
30 QWidget* mainTab, *licenseTab; |
| 31 QTabWidget* tabs = new QTabWidget; |
|
| 32 |
31 |
| 33 { |
32 // Application icon - in full 64 x 64 glory. |
| 34 mainTab = new QWidget; |
33 QLabel* icon = new QLabel; |
| |
34 icon->setPixmap (getIcon ("ldforge")); |
| |
35 |
| |
36 // Heading - application label and copyright information |
| |
37 QLabel* title = new QLabel (fmt ("<b>" APPNAME " v%d.%d</b><br />" |
| |
38 "Copyright (C) 2013 Santeri Piippo", |
| |
39 VERSION_MAJOR, VERSION_MINOR)); |
| |
40 |
| |
41 // Body text |
| |
42 QLabel* info = new QLabel ( |
| |
43 "<p>This software is intended for usage as a parts<br />" |
| |
44 "authoring tool for the <a href=\"http://ldraw.org/\">LDraw</a> parts library.</p>" |
| 35 |
45 |
| 36 // Application icon - in full 64 x 64 glory. |
46 "<p>" APPNAME " is free software, and you are welcome<br />" |
| 37 QLabel* icon = new QLabel; |
47 "to redistribute it under the terms of GPL v3. See the<br />" |
| 38 icon->setPixmap (getIcon ("ldforge")); |
48 "LICENSE text file for details. If the license text is not<br />" |
| |
49 "available for some reason, see<br />" |
| |
50 "<a href=\"http://www.gnu.org/licenses/\">http://www.gnu.org/licenses/</a> for the license terms.</p>" |
| 39 |
51 |
| 40 // Heading - application label and copyright information |
52 "<p>The application icon is derived from " |
| 41 QLabel* title = new QLabel (fmt ("<b>" APPNAME " v%d.%d</b><br />" |
53 "<a href=\"http://en.wikipedia.org/wiki/File:Anvil,_labelled_en.svg\">this image</a>.</p>" |
| 42 "Copyright (C) 2013 Santeri Piippo", |
54 ); |
| 43 VERSION_MAJOR, VERSION_MINOR)); |
|
| 44 |
|
| 45 // Body text |
|
| 46 QLabel* info = new QLabel ( |
|
| 47 "<p>This software is intended for usage as a parts<br />" |
|
| 48 "authoring tool for the <a href=\"http://ldraw.org/\">LDraw</a> parts library.</p>" |
|
| 49 |
|
| 50 "<p>" APPNAME " is free software, and you are welcome<br />" |
|
| 51 "to redistribute it under the terms of GPL v3. See the LICENSE<br />" |
|
| 52 "text file or the license tab in this dialog for details. If the<br />" |
|
| 53 "license text is not available for some reason, see<br />" |
|
| 54 "<a href=\"http://www.gnu.org/licenses/\">http://www.gnu.org/licenses/</a>" |
|
| 55 "for the license terms.</p>" |
|
| 56 |
|
| 57 "<p>The application icon is derived from " |
|
| 58 "<a href=\"http://en.wikipedia.org/wiki/File:Anvil,_labelled_en.svg\">this image</a>.</p>" |
|
| 59 ); |
|
| 60 |
|
| 61 // Rest in peace, James. |
|
| 62 QLabel* memorial = new QLabel ("In living memory of James Jessiman."); |
|
| 63 |
|
| 64 QVBoxLayout* layout = new QVBoxLayout; |
|
| 65 layout->addWidget (icon); |
|
| 66 layout->addWidget (title); |
|
| 67 layout->addWidget (info); |
|
| 68 layout->addWidget (memorial); |
|
| 69 |
|
| 70 // Align everything to the center. |
|
| 71 for (QLabel* label : vector<QLabel*> ({icon, title, info, memorial})) |
|
| 72 label->setAlignment (Qt::AlignCenter); |
|
| 73 |
|
| 74 mainTab->setLayout (layout); |
|
| 75 tabs->addTab (mainTab, "About " APPNAME); |
|
| 76 } |
|
| 77 |
55 |
| 78 { |
56 // Rest in peace, James. |
| 79 licenseTab = new QWidget; |
57 QLabel* memorial = new QLabel ("In living memory of James Jessiman."); |
| 80 |
58 |
| 81 QTextEdit* license = new QTextEdit; |
59 // Align everything to the center. |
| 82 license->setReadOnly (true); |
60 for (QLabel* label : vector<QLabel*> ({icon, title, info, memorial})) |
| 83 |
61 label->setAlignment (Qt::AlignCenter); |
| 84 QFont font ("Monospace"); |
|
| 85 font.setStyleHint (QFont::TypeWriter); |
|
| 86 font.setPixelSize (10); |
|
| 87 |
|
| 88 license->setFont (font); |
|
| 89 |
|
| 90 // Make the text view wide enough to display the license text. |
|
| 91 // Why isn't 80 sufficient here? |
|
| 92 license->setMinimumWidth (license->fontMetrics ().width ('a') * 85); |
|
| 93 |
|
| 94 // Try open the license text |
|
| 95 FILE* fp = fopen ("LICENSE", "r"); |
|
| 96 |
|
| 97 if (fp == null) { |
|
| 98 // Failed; tell the user how to get the license text instead. |
|
| 99 setlocale (LC_ALL, "C"); |
|
| 100 char const* text = "Couldn't open LICENSE: %s.<br />" |
|
| 101 "See <a href=\"http://www.gnu.org/licenses/\">http://www.gnu.org/licenses/</a> for the GPLv3 text."; |
|
| 102 |
|
| 103 license->setHtml (fmt (text, strerror (errno))); |
|
| 104 } else { |
|
| 105 // Figure out file size |
|
| 106 fseek (fp, 0, SEEK_END); |
|
| 107 const size_t length = ftell (fp); |
|
| 108 rewind (fp); |
|
| 109 |
|
| 110 // Init text buffer and write pointer |
|
| 111 char* licenseText = new char[length]; |
|
| 112 char* writePtr = &licenseText[0]; |
|
| 113 |
|
| 114 // Read in the license text |
|
| 115 while (true) { |
|
| 116 *writePtr = fgetc (fp); |
|
| 117 |
|
| 118 if (feof (fp)) |
|
| 119 break; |
|
| 120 |
|
| 121 writePtr++; |
|
| 122 } |
|
| 123 |
|
| 124 // Add terminating null character and add the license text to the |
|
| 125 // license dialog text view. |
|
| 126 *writePtr = '\0'; |
|
| 127 license->setText (licenseText); |
|
| 128 |
|
| 129 // And dump the trash on the way out. |
|
| 130 delete[] licenseText; |
|
| 131 } |
|
| 132 |
|
| 133 QVBoxLayout* layout = new QVBoxLayout; |
|
| 134 layout->addWidget (license); |
|
| 135 licenseTab->setLayout (layout); |
|
| 136 tabs->addTab (licenseTab, "License"); |
|
| 137 } |
|
| 138 |
62 |
| 139 QDialogButtonBox* buttons = new QDialogButtonBox (QDialogButtonBox::Close); |
63 QDialogButtonBox* buttons = new QDialogButtonBox (QDialogButtonBox::Close); |
| 140 QPushButton* helpButton = new QPushButton; |
64 QPushButton* helpButton = new QPushButton; |
| 141 |
65 |
| 142 helpButton->setText ("Mail Author"); |
66 helpButton->setText ("Mail Author"); |
| 143 helpButton->setIcon (getIcon ("mail")); |
67 helpButton->setIcon (getIcon ("mail")); |
| 144 buttons->addButton (static_cast<QAbstractButton*> (helpButton), QDialogButtonBox::HelpRole); |
68 buttons->addButton (static_cast<QAbstractButton*> (helpButton), QDialogButtonBox::HelpRole); |
| 145 connect (buttons, SIGNAL (helpRequested ()), this, SLOT (slot_mail ())); |
69 connect (buttons, SIGNAL (helpRequested ()), this, SLOT (slot_mail ())); |
| 146 connect (buttons, SIGNAL (rejected ()), this, SLOT (reject ())); |
70 connect (buttons, SIGNAL (rejected ()), this, SLOT (reject ())); |
| 147 |
71 |
| 148 QVBoxLayout* layout = new QVBoxLayout; |
72 QVBoxLayout* layout = new QVBoxLayout (this); |
| 149 layout->addWidget (tabs); |
73 layout->addWidget (icon); |
| |
74 layout->addWidget (title); |
| |
75 layout->addWidget (info); |
| |
76 layout->addWidget (memorial); |
| 150 layout->addWidget (buttons); |
77 layout->addWidget (buttons); |
| 151 setLayout (layout); |
78 |
| 152 setWindowTitle ("About " APPNAME); |
79 setWindowTitle ("About " APPNAME); |
| 153 } |
80 } |
| 154 |
81 |
| 155 void AboutDialog::slot_mail () { |
82 void AboutDialog::slot_mail () { |
| 156 QDesktopServices::openUrl (QUrl ("mailto:Santeri Piippo <arezey@gmail.com>?subject=LDForge")); |
83 QDesktopServices::openUrl (QUrl ("mailto:Santeri Piippo <arezey@gmail.com>?subject=LDForge")); |