comparison main/MainWindow.cpp @ 585:d882f64e60db

Update Help menu bits
author Chris Cannam
date Tue, 03 Sep 2019 13:44:05 +0100
parents f52766aa747b
children 1dfdbd017cf5
comparison
equal deleted inserted replaced
584:af488f78d029 585:d882f64e60db
83 #include <QPushButton> 83 #include <QPushButton>
84 #include <QSettings> 84 #include <QSettings>
85 #include <QScrollArea> 85 #include <QScrollArea>
86 #include <QPainter> 86 #include <QPainter>
87 #include <QWidgetAction> 87 #include <QWidgetAction>
88 #include <QTextEdit>
89 #include <QDialogButtonBox>
88 90
89 #include <iostream> 91 #include <iostream>
90 #include <cstdio> 92 #include <cstdio>
91 #include <errno.h> 93 #include <errno.h>
92 94
928 IconLoader il; 930 IconLoader il;
929 931
930 QString name = QApplication::applicationName(); 932 QString name = QApplication::applicationName();
931 QAction *action; 933 QAction *action;
932 934
935 action = new QAction(il.load("help"),
936 tr("&Help Reference"), this);
937 action->setShortcut(tr("F1"));
938 action->setStatusTip(tr("Open the %1 reference manual").arg(name));
939 connect(action, SIGNAL(triggered()), this, SLOT(help()));
940 m_keyReference->registerShortcut(action);
941 menu->addAction(action);
942
933 action = new QAction(tr("&Key and Mouse Reference"), this); 943 action = new QAction(tr("&Key and Mouse Reference"), this);
934 action->setShortcut(tr("F2")); 944 action->setShortcut(tr("F2"));
935 action->setStatusTip(tr("Open a window showing the keystrokes you can use in %1").arg(name)); 945 action->setStatusTip(tr("Open a window showing the keystrokes you can use in %1").arg(name));
936 connect(action, SIGNAL(triggered()), this, SLOT(keyReference())); 946 connect(action, SIGNAL(triggered()), this, SLOT(keyReference()));
937 m_keyReference->registerShortcut(action); 947 m_keyReference->registerShortcut(action);
938 menu->addAction(action); 948 menu->addAction(action);
939 949
940 action = new QAction(il.load("help"), 950 action = new QAction(tr("What's &New In This Release?"), this);
941 tr("&Help Reference"), this); 951 action->setStatusTip(tr("List the changes in this release (and every previous release) of %1").arg(name));
942 action->setShortcut(tr("F1")); 952 connect(action, SIGNAL(triggered()), this, SLOT(whatsNew()));
943 action->setStatusTip(tr("Open the %1 reference manual").arg(name));
944 connect(action, SIGNAL(triggered()), this, SLOT(help()));
945 m_keyReference->registerShortcut(action);
946 menu->addAction(action);
947
948
949 action = new QAction(tr("%1 on the &Web").arg(name), this);
950 action->setStatusTip(tr("Open the %1 website").arg(name));
951 connect(action, SIGNAL(triggered()), this, SLOT(website()));
952 menu->addAction(action); 953 menu->addAction(action);
953 954
954 action = new QAction(tr("&About %1").arg(name), this); 955 action = new QAction(tr("&About %1").arg(name), this);
955 action->setStatusTip(tr("Show information about %1").arg(name)); 956 action->setStatusTip(tr("Show information about %1").arg(name));
956 connect(action, SIGNAL(triggered()), this, SLOT(about())); 957 connect(action, SIGNAL(triggered()), this, SLOT(about()));
3197 { 3198 {
3198 contextHelpChanged(""); 3199 contextHelpChanged("");
3199 } 3200 }
3200 3201
3201 void 3202 void
3202 MainWindow::website()
3203 {
3204 //!!! todo: URL!
3205 openHelpUrl(tr("http://code.soundsoftware.ac.uk/projects/tony/"));
3206 }
3207
3208 void
3209 MainWindow::help() 3203 MainWindow::help()
3210 { 3204 {
3211 //!!! todo: help URL! 3205 //!!! todo: help URL!
3212 openHelpUrl(tr("http://code.soundsoftware.ac.uk/projects/tony/wiki/Reference")); 3206 openHelpUrl(tr("http://code.soundsoftware.ac.uk/projects/tony/wiki/Reference"));
3207 }
3208
3209 void
3210 MainWindow::whatsNew()
3211 {
3212 QFile changelog(":CHANGELOG");
3213 changelog.open(QFile::ReadOnly);
3214 QByteArray content = changelog.readAll();
3215 QString text = QString::fromUtf8(content);
3216
3217 QDialog *d = new QDialog(this);
3218 d->setWindowTitle(tr("What's New"));
3219
3220 QGridLayout *layout = new QGridLayout;
3221 d->setLayout(layout);
3222
3223 int row = 0;
3224
3225 QLabel *iconLabel = new QLabel;
3226 iconLabel->setPixmap(QApplication::windowIcon().pixmap(64, 64));
3227 layout->addWidget(iconLabel, row, 0);
3228
3229 layout->addWidget
3230 (new QLabel(tr("<h3>What's New in %1</h3>")
3231 .arg(QApplication::applicationName())),
3232 row++, 1);
3233 layout->setColumnStretch(2, 10);
3234
3235 QTextEdit *textEdit = new QTextEdit;
3236 layout->addWidget(textEdit, row++, 1, 1, 2);
3237
3238 if (m_newerVersionIs != "") {
3239 layout->addWidget(new QLabel(tr("<b>Note:</b> A newer version of %1 is available.<br>(Version %2 is available; you are using version %3)").arg(QApplication::applicationName()).arg(m_newerVersionIs).arg(TONY_VERSION)), row++, 1, 1, 2);
3240 }
3241
3242 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok);
3243 layout->addWidget(bb, row++, 0, 1, 3);
3244 connect(bb, SIGNAL(accepted()), d, SLOT(accept()));
3245
3246 text.replace('\r', "");
3247 text.replace(QRegExp("(.)\n +(.)"), "\\1 \\2");
3248 text.replace(QRegExp("\n - ([^\n]+)"), "\n<li>\\1</li>");
3249 text.replace(QRegExp(": *\n"), ":\n<ul>\n");
3250 text.replace(QRegExp("</li>\n\\s*\n"), "</li>\n</ul>\n\n");
3251 text.replace(QRegExp("\n(\\w[^:\n]+:)"), "\n<p><b>\\1</b></p>");
3252 // text.replace(QRegExp("<li>([^,.\n]+)([,.] +\\w)"), "<li><b>\\1</b>\\2");
3253
3254 textEdit->setHtml(text);
3255 textEdit->setReadOnly(true);
3256
3257 d->setMinimumSize(m_viewManager->scalePixelSize(520),
3258 m_viewManager->scalePixelSize(450));
3259
3260 d->exec();
3261
3262 delete d;
3213 } 3263 }
3214 3264
3215 void 3265 void
3216 MainWindow::about() 3266 MainWindow::about()
3217 { 3267 {
3232 .arg(debug ? tr("Debug") : tr("Release")); 3282 .arg(debug ? tr("Debug") : tr("Release"));
3233 aboutText += tr("<p>Using Qt framework version %1.</p>") 3283 aboutText += tr("<p>Using Qt framework version %1.</p>")
3234 .arg(QT_VERSION_STR); 3284 .arg(QT_VERSION_STR);
3235 3285
3236 aboutText += 3286 aboutText +=
3237 "<p>Copyright &copy; 2005&ndash;2015 Chris Cannam, Queen Mary University of London, and the Tony project authors: Matthias Mauch, George Fazekas, Justin Salamon, and Rachel Bittner.</p>" 3287 "<p>Copyright &copy; 2005&ndash;2019 Chris Cannam, Queen Mary University of London, and the Tony project authors: Matthias Mauch, George Fazekas, Justin Salamon, and Rachel Bittner.</p>"
3238 "<p>pYIN analysis plugin written by Matthias Mauch.</p>" 3288 "<p>pYIN analysis plugin written by Matthias Mauch.</p>"
3239 "<p>This program is free software; you can redistribute it and/or " 3289 "<p>This program is free software; you can redistribute it and/or "
3240 "modify it under the terms of the GNU General Public License as " 3290 "modify it under the terms of the GNU General Public License as "
3241 "published by the Free Software Foundation; either version 2 of the " 3291 "published by the Free Software Foundation; either version 2 of the "
3242 "License, or (at your option) any later version.<br>See the file " 3292 "License, or (at your option) any later version.<br>See the file "
3243 "COPYING included with this distribution for more information.</p>"; 3293 "COPYING included with this distribution for more information.</p>";
3244 3294
3245 QMessageBox::about(this, tr("About %1").arg(QApplication::applicationName()), aboutText); 3295 // use our own dialog so we can influence the size
3296
3297 QDialog *d = new QDialog(this);
3298
3299 d->setWindowTitle(tr("About %1").arg(QApplication::applicationName()));
3300
3301 QGridLayout *layout = new QGridLayout;
3302 d->setLayout(layout);
3303
3304 int row = 0;
3305
3306 QLabel *iconLabel = new QLabel;
3307 iconLabel->setPixmap(QApplication::windowIcon().pixmap(64, 64));
3308 layout->addWidget(iconLabel, row, 0, Qt::AlignTop);
3309
3310 QLabel *mainText = new QLabel();
3311 layout->addWidget(mainText, row, 1, 1, 2);
3312
3313 layout->setRowStretch(row, 10);
3314 layout->setColumnStretch(1, 10);
3315
3316 ++row;
3317
3318 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok);
3319 layout->addWidget(bb, row++, 0, 1, 3);
3320 connect(bb, SIGNAL(accepted()), d, SLOT(accept()));
3321
3322 mainText->setWordWrap(true);
3323 mainText->setOpenExternalLinks(true);
3324 mainText->setText(aboutText);
3325
3326 d->setMinimumSize(m_viewManager->scalePixelSize(420),
3327 m_viewManager->scalePixelSize(200));
3328
3329 d->exec();
3330
3331 delete d;
3246 } 3332 }
3247 3333
3248 void 3334 void
3249 MainWindow::keyReference() 3335 MainWindow::keyReference()
3250 { 3336 {
3252 } 3338 }
3253 3339
3254 void 3340 void
3255 MainWindow::newerVersionAvailable(QString version) 3341 MainWindow::newerVersionAvailable(QString version)
3256 { 3342 {
3343 m_newerVersionIs = version;
3344
3257 //!!! nicer URL would be nicer 3345 //!!! nicer URL would be nicer
3258 QSettings settings; 3346 QSettings settings;
3259 settings.beginGroup("NewerVersionWarning"); 3347 settings.beginGroup("NewerVersionWarning");
3260 QString tag = QString("version-%1-available-show").arg(version); 3348 QString tag = QString("version-%1-available-show").arg(version);
3261 if (settings.value(tag, true).toBool()) { 3349 if (settings.value(tag, true).toBool()) {