zz_aboutDialog.cpp

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

mercurial