Reference documentation for deal.II version 8.4.2
info_message.cpp
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2010 - 2013 by Martin Steigemann and Wolfgang Bangerth
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 
17 #include <QtGui>
18 
19 #include "info_message.h"
20 
21 
22 namespace dealii
23 {
24  namespace ParameterGui
25  {
26  InfoMessage::InfoMessage(QWidget *parent)
27  : QDialog(parent, 0)
28  {
29  show_again = true; // this variable stores, if the
30  // the info message should be shown again
31  QGridLayout * grid = new QGridLayout(this);
32 
33  icon = new QLabel(this); // set an icon
34 #ifndef QT_NO_MESSAGEBOX
35  icon->setPixmap(QMessageBox::standardIcon(QMessageBox::Information));
36  icon->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
37 #endif
38  grid->addWidget(icon, 0, 0, Qt::AlignTop); // add the icon in the upper left corner
39 
40  message = new QTextEdit(this); // set the new message
41  message->setReadOnly(true);
42  grid->addWidget(message, 0, 1); // and add the message on the right
43 
44  again = new QCheckBox(this); // add a check box
45  again->setChecked(true);
46  again->setText(QErrorMessage::tr("&Show this message again"));
47  grid->addWidget(again, 1, 1, Qt::AlignTop);
48 
49  ok = new QPushButton(this); // and finally a OK button
50  ok->setText(QErrorMessage::tr("&OK"));
51 #ifdef QT_SOFTKEYS_ENABLED
52  ok_action = new QAction(ok); // define the action for the button
53  ok_action->setSoftKeyRole(QAction::PositiveSoftKey);
54  ok_action->setText(ok->text());
55  connect(ok_action, SIGNAL(triggered()), this, SLOT(accept()));
56  addAction(ok_action);
57 #endif
58  connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
59  ok->setFocus(); // aand set the focus on the button
60  grid->addWidget(ok, 2, 0, 1, 2, Qt::AlignCenter);
61 
62  grid->setColumnStretch(1, 42);
63  grid->setRowStretch(0, 42);
64  // load settings from an ini-file
65  QString settings_file = QDir::currentPath() + "/settings.ini";
66 
67  settings = new QSettings (settings_file, QSettings::IniFormat);
68 
69  settings->beginGroup("infoMessage"); // we store settings of this class in the
70  show_again = settings->value("showInformation", true).toBool(); //group infoMessage
71  settings->endGroup();
72  }
73 
74 
75 
76  void InfoMessage::setInfoMessage(const QString &message)
77  {
78  this->message->setText(message); // set the message
79  }
80 
81 
82 
84  {
85  if (show_again) // and show the message
86  show();
87  }
88 
89 
90 
91  void InfoMessage::done(int r)
92  {
93  if(!again->isChecked()) // if the box is not checked,
94  { // store this to settings
95  settings->beginGroup("infoMessage");
96  settings->setValue("showInformation", false);
97  settings->endGroup();
98  };
99 
100  QDialog::done(r);
101  }
102  }
103 }
104 
void setInfoMessage(const QString &message)