Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) QtAboutDialog

 

QtAboutDialog is a Qt dialog class to display an About.

 

 

 

 

 

qtaboutdialog.h

 

//---------------------------------------------------------------------------
/*
QtAboutDialog, Qt dialog for About
Copyright (C) 2011 Richel Bilderbeek

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 3 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, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppQtAboutDialog.htm
//---------------------------------------------------------------------------
#ifndef QTDIALOGABOUT_H
#define QTDIALOGABOUT_H
//---------------------------------------------------------------------------
#ifdef _WIN32
//See http://www.richelbilderbeek.nl/CppCompileErrorSwprintfHasNotBeenDeclared.htm
#undef __STRICT_ANSI__
#endif
//---------------------------------------------------------------------------
#include <string>
#include <vector>
//---------------------------------------------------------------------------
#include <QDialog>
//---------------------------------------------------------------------------
#include "about.h"
//---------------------------------------------------------------------------
namespace Ui {
  class QtAboutDialog;
}
//---------------------------------------------------------------------------
class QtAboutDialog : public QDialog
{
  Q_OBJECT

public:
  explicit QtAboutDialog(const About& about);
  ~QtAboutDialog();
  static const std::string GetVersion();
  static const std::vector<std::string> GetVersionHistory();

protected:
  void changeEvent(QEvent *e);

private:
  Ui::QtAboutDialog *ui;
};
//---------------------------------------------------------------------------
#endif // QTDIALOGABOUT_H

 

 

 

 

 

qtaboutdialog.cpp

 

//---------------------------------------------------------------------------
/*
QtAboutDialog, Qt dialog for About
Copyright (C) 2011 Richel Bilderbeek

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 3 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, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppQtAboutDialog.htm
//---------------------------------------------------------------------------
#include <string>
//---------------------------------------------------------------------------
#include <boost/foreach.hpp>
//---------------------------------------------------------------------------
#include <QScrollBar>
//---------------------------------------------------------------------------
#include "qtaboutdialog.h"
#include "ui_qtaboutdialog.h"
//---------------------------------------------------------------------------
QtAboutDialog::QtAboutDialog(const About& about)
  : ui(new Ui::QtAboutDialog)
{
  ui->setupUi(this);

  ui->label_title->setText(
    QString(about.GetFileTitle().c_str())
    + QString(", version ")
    + QString(about.GetVersion().c_str()));
  ui->label_copyright->setText(
    QString("Copyright (C) ")
    + QString(about.GetYears().c_str())
    + QString(" ")
    + QString(about.GetAuthor().c_str()));
  ui->label_author->setText(
    QString("Programmed by ")
    + QString(about.GetAuthor().c_str()));
  ui->label_date->setText(
    QString("at ")
    + about.GetProgrammedAt().c_str());
  ui->label_download->setText(
    QString(about.GetFileTitle().c_str())
    + QString(" can be downloaded from:"));
  ui->edit_url->setText(about.GetUrl().c_str());

  About about_copy = about;
  about_copy.AddLibrary("Qt version: " + std::string(QT_VERSION_STR));
  about_copy.AddLibrary("QtAboutDialog version: " + GetVersion());

  ui->label_build_date_time->setText(
      (std::string("Source code built at ")
      + std::string(__DATE__)
      + std::string(" ")
      + std::string(__TIME__)).c_str());

  #ifdef NDEBUG
  ui->label_build_type->setText("Release version");
  #else
  ui->label_build_type->setText("Debug version");
  #endif

  BOOST_FOREACH(const std::string& s,about_copy.CreateLibrariesUsedText())
  {
    ui->text_libraries->appendPlainText(s.c_str());
  }
  BOOST_FOREACH(const std::string& s,about_copy.CreateVersionHistory())
  {
    ui->text_whatsnew->appendPlainText(s.c_str());
  }
  BOOST_FOREACH(const std::string& s,about_copy.CreateLicenceText())
  {
    ui->text_licence->appendPlainText(s.c_str());
  }
  ui->text_libraries->moveCursor(QTextCursor::Start);
  ui->text_licence->moveCursor(QTextCursor::Start);
  ui->text_whatsnew->moveCursor(QTextCursor::Start);
}
//---------------------------------------------------------------------------
QtAboutDialog::~QtAboutDialog()
{
  delete ui;
}
//---------------------------------------------------------------------------
void QtAboutDialog::changeEvent(QEvent *e)
{
  QDialog::changeEvent(e);
  switch (e->type()) {
  case QEvent::LanguageChange:
    ui->retranslateUi(this);
    break;
  default:
    break;
  }
}
//---------------------------------------------------------------------------
const std::string QtAboutDialog::GetVersion()
{
  return "1.3";
}
//---------------------------------------------------------------------------
const std::vector<std::string> QtAboutDialog::GetVersionHistory()
{
  std::vector<std::string> v;
  v.push_back("2011-01-11: version 1.0: initial version of QtAboutDialog");
  v.push_back("2011-04-11: version 1.1: minor changes");
  v.push_back("2011-06-27: version 1.2: added date and time when source code is built");
  v.push_back("2011-09-11: version 1.3: display the type of build");
  return v;
}
//---------------------------------------------------------------------------


 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml