From: Joel Holdsworth Date: Fri, 11 May 2012 10:17:28 +0000 (+0100) Subject: Created a custom about box with scrollable space for the supported list X-Git-Tag: pulseview-0.1.0~357 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=40eb2ff4f27ae8209271f3d6992ebdcb5de60d76 Created a custom about box with scrollable space for the supported list --- diff --git a/about.cpp b/about.cpp new file mode 100644 index 00000000..e494e2ff --- /dev/null +++ b/about.cpp @@ -0,0 +1,102 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +extern "C" { +#include +} + +#include + +#include "about.h" +#include "ui_about.h" + +extern "C" { +/* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */ +#define __STDC_FORMAT_MACROS +#include +#include +} + +About::About(QWidget *parent) : + QDialog(parent), + ui(new Ui::About) +{ + GSList *l; + struct sr_dev_driver **drivers; + struct sr_input_format **inputs; + struct sr_output_format **outputs; + struct srd_decoder *dec; + QString s; + + ui->setupUi(this); + + /* Setup the version field */ + ui->versionInfo->setText(tr("%1 %2
%3
%4") + .arg(QApplication::applicationName()) + .arg(QApplication::applicationVersion()) + .arg(tr("GNU GPL, version 2 or later")) + .arg(QApplication::organizationDomain())); + + /* Set up the supported field */ + s.append("" + tr("Supported hardware drivers:") + ""); + drivers = sr_driver_list(); + for (int i = 0; drivers[i]; ++i) { + s.append(QString("") + .arg(QString(drivers[i]->name)) + .arg(QString(drivers[i]->longname))); + } + s.append("
%1%2

"); + + s.append("" + tr("Supported input formats:") + ""); + inputs = sr_input_list(); + for (int i = 0; inputs[i]; ++i) { + s.append(QString("") + .arg(QString(inputs[i]->id)) + .arg(QString(inputs[i]->description))); + } + s.append("
%1%2

"); + + s.append("" + tr("Supported output formats:") + ""); + outputs = sr_output_list(); + for (int i = 0; outputs[i]; ++i) { + s.append(QString("") + .arg(QString(outputs[i]->id)) + .arg(QString(outputs[i]->description))); + } + s.append("
%1%2

"); + + s.append("" + tr("Supported protocol decoders:") + ""); + for (l = srd_decoder_list(); l; l = l->next) { + dec = (struct srd_decoder *)l->data; + s.append(QString("") + .arg(QString(dec->id)) + .arg(QString(dec->longname))); + } + s.append("
%1%2
"); + + supportedDoc.reset(new QTextDocument(this)); + supportedDoc->setHtml(s); + ui->supportList->setDocument(supportedDoc.get()); +} + +About::~About() +{ + delete ui; +} diff --git a/about.h b/about.h new file mode 100644 index 00000000..8e95af95 --- /dev/null +++ b/about.h @@ -0,0 +1,47 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef ABOUT_H +#define ABOUT_H + +#include + +#include + +class QTextDocument; + +namespace Ui { +class About; +} + +class About : public QDialog +{ + Q_OBJECT + +public: + explicit About(QWidget *parent = 0); + ~About(); + +private: + Ui::About *ui; + std::auto_ptr supportedDoc; +}; + +#endif // ABOUT_H diff --git a/about.ui b/about.ui new file mode 100644 index 00000000..7fa9f9b4 --- /dev/null +++ b/about.ui @@ -0,0 +1,96 @@ + + + About + + + Qt::WindowModal + + + + 0 + 0 + 600 + 400 + + + + About + + + + + + + + + + + + + + :/icons/sigrok-logo-notext.png + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + About + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + About + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp index bf9711f2..45d415dd 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -22,7 +22,7 @@ extern "C" { #include } -#include +#include "about.h" #include "mainwindow.h" #include "ui_mainwindow.h" @@ -51,53 +51,6 @@ MainWindow::~MainWindow() void MainWindow::on_actionAbout_triggered() { - GSList *l; - struct sr_dev_driver **drivers; - struct sr_input_format **inputs; - struct sr_output_format **outputs; - struct srd_decoder *dec; - - QString s = tr("%1 %2
%3
%4\n

") - .arg(QApplication::applicationName()) - .arg(QApplication::applicationVersion()) - .arg(tr("GNU GPL, version 2 or later")) - .arg(QApplication::organizationDomain()); - - s.append("" + tr("Supported hardware drivers:") + ""); - drivers = sr_driver_list(); - for (int i = 0; drivers[i]; ++i) { - s.append(QString("") - .arg(QString(drivers[i]->name)) - .arg(QString(drivers[i]->longname))); - } - s.append("
%1%2

"); - - s.append("" + tr("Supported input formats:") + ""); - inputs = sr_input_list(); - for (int i = 0; inputs[i]; ++i) { - s.append(QString("") - .arg(QString(inputs[i]->id)) - .arg(QString(inputs[i]->description))); - } - s.append("
%1%2

"); - - s.append("" + tr("Supported output formats:") + ""); - outputs = sr_output_list(); - for (int i = 0; outputs[i]; ++i) { - s.append(QString("") - .arg(QString(outputs[i]->id)) - .arg(QString(outputs[i]->description))); - } - s.append("
%1%2

"); - - s.append("" + tr("Supported protocol decoders:") + ""); - for (l = srd_decoder_list(); l; l = l->next) { - dec = (struct srd_decoder *)l->data; - s.append(QString("") - .arg(QString(dec->id)) - .arg(QString(dec->longname))); - } - s.append("
%1%2
"); - - QMessageBox::about(this, tr("About"), s); + About dlg(this); + dlg.exec(); } diff --git a/sigrok-qt2.pro b/sigrok-qt2.pro index 4741d769..b10f6cbb 100644 --- a/sigrok-qt2.pro +++ b/sigrok-qt2.pro @@ -14,11 +14,14 @@ VERSION = 0.1.0 DEFINES += APP_VERSION=\\\"$$VERSION\\\" SOURCES += main.cpp\ - mainwindow.cpp + mainwindow.cpp \ + about.cpp -HEADERS += mainwindow.h +HEADERS += mainwindow.h \ + about.h -FORMS += mainwindow.ui +FORMS += mainwindow.ui \ + about.ui RESOURCES += sigrok-qt2.qrc