Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

licensewindow.w 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. @* Presenting License Information.
  2. \noindent Typica has its own copyright and license information, but it also
  3. relies on other projects which have their own copyright and license information
  4. which must be preserved, but it is better to present this information in a way
  5. that someone interested can quickly examine the license of any particular work.
  6. I would like to present this as a two panel window where the left side contains a
  7. list of the various projects and the right side contains a web view. Clicking
  8. an item in the list on the left should bring up the appropriate license
  9. document on the right.
  10. @(licensewindow.h@>=
  11. #include <QMainWindow>
  12. #include <QListWidgetItem>
  13. #include <QWebView>
  14. #ifndef TypicaLicenseHeader
  15. #define TypicaLicenseHeader
  16. class LicenseWindow : public QMainWindow@/
  17. {
  18. @[Q_OBJECT@]@;
  19. public:@/
  20. LicenseWindow();
  21. @[private slots@]:@/
  22. void setWebView(QListWidgetItem *current, QListWidgetItem *);
  23. private:@/
  24. QWebView *view;
  25. };
  26. #endif
  27. @ Implementation is in a separate file.
  28. @(licensewindow.cpp@>=
  29. @<License window headers@>@;
  30. @<License window implementation@>@;
  31. @ The constructor is responsible for setting up the structure of the window and
  32. setting its initial content.
  33. @<License window implementation@>=
  34. LicenseWindow::LicenseWindow()
  35. : QMainWindow(NULL), view(new QWebView)
  36. {
  37. QSplitter *split = new QSplitter;
  38. QListWidget *projects = new QListWidget;
  39. @<Add items to license list@>@;
  40. connect(projects, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
  41. this, SLOT(setWebView(QListWidgetItem*, QListWidgetItem*)));
  42. split->addWidget(projects);
  43. split->addWidget(view);
  44. setCentralWidget(split);
  45. }
  46. @ Each item in the |projects| list contains a |QUrl| pointing to an HTML
  47. document in the resources compiled in with \pn{}. When an item in the list is
  48. selected, the appropriate document is loaded in the web view. The previously
  49. selected item is unused.
  50. @<License window implementation@>=
  51. void LicenseWindow::setWebView(QListWidgetItem *current, QListWidgetItem *)
  52. {
  53. view->load(current->data(Qt::UserRole).toUrl());
  54. }
  55. @ Each item in the list provides the name of the project to display in the list
  56. and the location of the relevant license. This section must be updated any time
  57. the external projects used changes. At present only projects which are used
  58. directly by \pn{} are included here but it would not be a bad idea to audit
  59. projects that are used indirectly and include these as well. The item with
  60. the license for \pn{} is the initial selection and the web view is set
  61. appropriately here as the |currentItemChanged| signal is not connected until
  62. after this code executes.
  63. @<Add items to license list@>=
  64. QListWidgetItem *item = new QListWidgetItem("Typica", projects);
  65. item->setData(Qt::UserRole, QVariant(QUrl("qrc:/resources/html/licenses/typica.html")));
  66. projects->setCurrentItem(item);
  67. setWebView(item, NULL);
  68. item = new QListWidgetItem("d3.js", projects);
  69. item->setData(Qt::UserRole, QVariant(QUrl("qrc:/resources/html/licenses/d3.html")));
  70. item = new QListWidgetItem("Entypo", projects);
  71. item->setData(Qt::UserRole, QVariant(QUrl("qrc:/resources/html/licenses/entypo.html")));
  72. item = new QListWidgetItem("Tango Desktop Project", projects);
  73. item->setData(Qt::UserRole, QVariant(QUrl("qrc:/resources/html/licenses/tango.html")));
  74. item = new QListWidgetItem("QextSerialPort", projects);
  75. item->setData(Qt::UserRole, QVariant(QUrl("qrc:/resources/html/licenses/qextserialport.html")));
  76. item = new QListWidgetItem("Qt", projects);
  77. item->setData(Qt::UserRole, QVariant(QUrl("qrc:/resources/html/licenses/qt.html")));
  78. @ Several headers are required.
  79. @<License window headers@>=
  80. #include "licensewindow.h"
  81. #include <QSplitter>
  82. #include <QListWidget>
  83. #include <QVariant>
  84. #include <QUrl>