GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
welcome-wizard.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2011-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <QApplication>
31 #include <QDesktopWidget>
32 #include <QHBoxLayout>
33 #include <QPushButton>
34 #include <QVBoxLayout>
35 
36 #if defined (OCTAVE_USE_WINDOWS_API)
37  #define WIN32_LEAN_AND_MEAN
38  #include <windows.h>
39 #endif
40 
41 #include "gui-preferences-nr.h"
42 #include "octave-qobject.h"
43 #include "welcome-wizard.h"
44 
45 namespace octave
46 {
47  static QLabel *
48  make_octave_logo (QWidget *p = nullptr, int height = 100)
49  {
50  QLabel *logo = new QLabel (p);
51  QPixmap logo_pixmap (":/actions/icons/logo.png");
52  logo->setPixmap (logo_pixmap.scaledToHeight (height));
53  return logo;
54  };
55 
57  : QDialog (p), m_octave_qobj (oct_qobj), m_page_ctor_list (),
58  m_page_list_iterator (),
59  m_current_page (initial_page::create (oct_qobj, this)),
60  m_allow_web_connect_state (false),
61  m_max_height (0), m_max_width (0)
62  {
66 
68 
69  setWindowTitle (tr ("Welcome to GNU Octave"));
70 
71  setEnabled (true);
72 
73  setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
74 
75  // Create all pages for pre-setting the minimal required size for all pages
76  show_page ();
77  adjust_size ();
78  next_page ();
79  adjust_size ();
80  next_page ();
81  adjust_size ();
82  // now go back to the first page
83  previous_page ();
84  previous_page ();
85 
86  // Set the size determined above
87  resize (m_max_width, m_max_height);
88 
89 #if defined (OCTAVE_USE_WINDOWS_API)
90  // HACK to forceshow of dialog if started minimized
91  ShowWindow (reinterpret_cast<HWND> (winId ()), SW_SHOWNORMAL);
92 #endif
93  }
94 
96  {
97  // Get adjusted size for the current page
98  adjustSize ();
99  QSize sz = size ();
100 
101  // Update the max. size of the three pages if required
102 
103  if (sz.height () > m_max_height)
104  m_max_height = sz.height ();
105 
106  if (sz.width () > m_max_width)
107  m_max_width = sz.width ();
108  }
109 
111  {
112  m_allow_web_connect_state = state == Qt::Checked;
113  }
114 
116  {
117  delete m_current_page;
118  delete layout ();
119 
120  m_current_page = (*m_page_list_iterator) (m_octave_qobj, this);
121 
122  QVBoxLayout *new_layout = new QVBoxLayout ();
123  setLayout (new_layout);
124 
125  new_layout->addWidget (m_current_page);
126  }
127 
129  {
131 
132  show_page ();
133  }
134 
136  {
138 
139  show_page ();
140  }
141 
143  {
144  // Create default settings file.
145 
147  rmgr.reload_settings ();
148 
150 
151  if (settings)
152  {
153  settings->setValue (nr_allow_connection.key,
155 
156  settings->sync ();
157  }
158 
159  QDialog::accept ();
160  }
161 
163  : QWidget (wizard),
164  m_title (new QLabel (tr ("Welcome to Octave!"), this)),
165  m_message (new QLabel (this)),
166  m_logo (make_octave_logo (this)),
167  m_next (new QPushButton (tr ("Next"), this)),
168  m_cancel (new QPushButton (tr ("Cancel"), this))
169  {
170  QFont ft;
171  ft.setPointSize (20);
172  m_title->setFont (ft);
173 
174  resource_manager& rmgr = oct_qobj.get_resource_manager ();
175 
176  m_message->setText
177  (tr ("<html><body>\n"
178  "<p>You seem to be using the Octave graphical interface for the first time on this computer.\n"
179  "Click 'Next' to create a configuration file and launch Octave.</p>\n"
180  "<p>The configuration file is stored in<br>%1.</p>\n"
181  "</body></html>").
182  arg (rmgr.get_settings_file ()));
183  m_message->setWordWrap (true);
184  m_message->setMinimumWidth (400);
185 
186  QVBoxLayout *message_layout = new QVBoxLayout;
187 
188  message_layout->addWidget (m_title);
189  message_layout->addWidget (m_message);
190 
191  QHBoxLayout *message_and_logo = new QHBoxLayout;
192 
193  message_and_logo->addLayout (message_layout);
194  message_and_logo->addStretch (10);
195  message_and_logo->addWidget (m_logo, 0, Qt::AlignTop);
196 
197  QHBoxLayout *button_bar = new QHBoxLayout;
198 
199  button_bar->addStretch (10);
200  button_bar->addWidget (m_next);
201  button_bar->addWidget (m_cancel);
202 
203  QVBoxLayout *page_layout = new QVBoxLayout (this);
204  setLayout (page_layout);
205 
206  page_layout->addLayout (message_and_logo);
207  page_layout->addStretch (10);
208  page_layout->addSpacing (20);
209  page_layout->addLayout (button_bar);
210 
211  setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
212 
213  m_next->setDefault (true);
214  m_next->setFocus ();
215 
216  connect (m_next, SIGNAL (clicked ()), wizard, SLOT (next_page ()));
217  connect (m_cancel, SIGNAL (clicked ()), wizard, SLOT (reject ()));
218  }
219 
221  welcome_wizard *wizard)
222  : QWidget (wizard),
223  m_title (new QLabel (tr ("Community News"), this)),
224  m_message (new QLabel (this)),
225  m_checkbox (new QCheckBox (this)),
226  m_checkbox_message (new QLabel (this)),
227  m_logo (make_octave_logo (this)),
228  m_previous (new QPushButton (tr ("Previous"), this)),
229  m_next (new QPushButton (tr ("Next"), this)),
230  m_cancel (new QPushButton (tr ("Cancel"), this))
231  {
232  QFont ft;
233  ft.setPointSize (20);
234  m_title->setFont (ft);
235 
236  m_message->setText
237  (tr ("<html><body>\n"
238  "<p>When Octave starts, it will optionally check the Octave web site for current news and information about the Octave community.\n"
239  "The check will happen at most once each day and news will only be displayed if there is something new since the last time you viewed the news.</p>\n"
240  "<p>You may also view the news by selecting the \"Community News\" item in the \"Help\" menu, or by visiting\n"
241  "<a href=\"https://octave.org/community-news.html\">https://octave.org/community-news.html</a>.</p>\n"
242  "</body></html>"));
243  m_message->setWordWrap (true);
244  m_message->setMinimumWidth (400);
245  m_message->setOpenExternalLinks (true);
246 
247  QVBoxLayout *message_layout = new QVBoxLayout;
248 
249  message_layout->addWidget (m_title);
250  message_layout->addWidget (m_message);
251 
252  QHBoxLayout *message_and_logo = new QHBoxLayout;
253 
254  message_and_logo->addLayout (message_layout);
255  message_and_logo->addStretch (10);
256  message_and_logo->addWidget (m_logo, 0, Qt::AlignTop);
257 
258  QHBoxLayout *checkbox_layout = new QHBoxLayout;
259 
260  bool allow_connection = nr_allow_connection.def.toBool ();
261  if (allow_connection)
262  m_checkbox->setCheckState (Qt::Checked);
263  else
264  m_checkbox->setCheckState (Qt::Unchecked);
265 
266  m_checkbox_message->setText
267  (tr ("<html><head>\n"
268  "<style>\n"
269  "a:link { text-decoration: underline; color: #0000ff; }\n"
270  "</style>\n"
271  "</head><body>\n"
272  "<p>Allow Octave to connect to the Octave web site when it starts to display current news and information about the Octave community.</p>\n"
273  "</body></html>"));
274  m_checkbox_message->setWordWrap (true);
275  m_checkbox_message->setOpenExternalLinks (true);
276  m_checkbox_message->setMinimumWidth (500);
277 
278  checkbox_layout->addWidget (m_checkbox, 0, Qt::AlignTop);
279  checkbox_layout->addSpacing (20);
280  checkbox_layout->addWidget (m_checkbox_message, 0, Qt::AlignTop);
281  checkbox_layout->addStretch (10);
282 
283  QVBoxLayout *message_logo_and_checkbox = new QVBoxLayout;
284 
285  message_logo_and_checkbox->addLayout (message_and_logo);
286  message_logo_and_checkbox->addSpacing (20);
287  message_logo_and_checkbox->addLayout (checkbox_layout);
288 
289  QHBoxLayout *button_bar = new QHBoxLayout;
290 
291  button_bar->addStretch (10);
292  button_bar->addWidget (m_previous);
293  button_bar->addWidget (m_next);
294  button_bar->addWidget (m_cancel);
295 
296  QVBoxLayout *page_layout = new QVBoxLayout (this);
297  setLayout (page_layout);
298 
299  page_layout->addLayout (message_logo_and_checkbox);
300  page_layout->addStretch (10);
301  page_layout->addSpacing (20);
302  page_layout->addLayout (button_bar);
303 
304  setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
305 
306  m_next->setDefault (true);
307  m_next->setFocus ();
308 
309  connect (m_checkbox, SIGNAL (stateChanged (int)),
310  wizard, SLOT (handle_web_connect_option (int)));
311 
312  connect (m_previous, SIGNAL (clicked ()), wizard, SLOT (previous_page ()));
313  connect (m_next, SIGNAL (clicked ()), wizard, SLOT (next_page ()));
314  connect (m_cancel, SIGNAL (clicked ()), wizard, SLOT (reject ()));
315  }
316 
318  : QWidget (wizard),
319  m_title (new QLabel (tr ("Enjoy!"), this)),
320  m_message (new QLabel (this)),
321  m_logo (make_octave_logo (this)),
322  m_links (new QLabel (this)),
323  m_previous (new QPushButton (tr ("Previous"), this)),
324  m_finish (new QPushButton (tr ("Finish"), this)),
325  m_cancel (new QPushButton (tr ("Cancel"), this))
326  {
327  QFont ft;
328  ft.setPointSize (20);
329  m_title->setFont (ft);
330 
331  m_message->setText
332  (tr ("<html><body>\n"
333  "<p>We hope you find Octave to be a useful tool.</p>\n"
334  "<p>If you encounter problems, there are a number of ways to get help, including commercial support options, a mailing list, a wiki, and other community-based support channels.\n"
335  "You can find more information about each of these by visiting <a href=\"https://octave.org/support.html\">https://octave.org/support.html</a> (opens in external browser).</p>\n"
336  "</body></html>"));
337  m_message->setWordWrap (true);
338  m_message->setMinimumWidth (400);
339  m_message->setOpenExternalLinks (true);
340 
341  QVBoxLayout *message_layout = new QVBoxLayout;
342 
343  message_layout->addWidget (m_title);
344  message_layout->addWidget (m_message);
345 
346  QHBoxLayout *message_and_logo = new QHBoxLayout;
347 
348  message_and_logo->addLayout (message_layout);
349  message_and_logo->addStretch (10);
350  message_and_logo->addWidget (m_logo, 0, Qt::AlignTop);
351 
352  m_links->setText
353  (tr ("<html><head>\n"
354  "<style>\n"
355  "a:link { text-decoration: underline; color: #0000ff; }\n"
356  "</style>\n"
357  "</head><body>\n"
358  "<p>For more information about Octave:</p>\n"
359  "<ul>\n"
360  "<li>Visit <a href=\"https://octave.org\">https://octave.org</a> (opens in external browser)</li>\n"
361  "<li>Get the documentation online as <a href=\"https://www.gnu.org/software/octave/doc/interpreter/index.html\">html</a>- or <a href=\"https://www.gnu.org/software/octave/octave.pdf\">pdf</a>-document (opens in external browser)</li>\n"
362  "<li>Open the documentation browser of the Octave GUI with the help menu</li>\n"
363  "</ul>\n"
364  "</body></html>"));
365  m_links->setWordWrap (true);
366  m_links->setOpenExternalLinks (true);
367 
368  QHBoxLayout *button_bar = new QHBoxLayout;
369 
370  button_bar->addStretch (10);
371  button_bar->addWidget (m_previous);
372  button_bar->addWidget (m_finish);
373  button_bar->addWidget (m_cancel);
374 
375  QVBoxLayout *page_layout = new QVBoxLayout (this);
376  setLayout (page_layout);
377 
378  page_layout->addLayout (message_and_logo);
379  page_layout->addSpacing (20);
380  page_layout->addWidget (m_links);
381  page_layout->addStretch (10);
382  page_layout->addSpacing (20);
383  page_layout->addLayout (button_bar);
384 
385  setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
386 
387  m_finish->setDefault (true);
388  m_finish->setFocus ();
389 
390  connect (m_previous, SIGNAL (clicked ()), wizard, SLOT (previous_page ()));
391  connect (m_finish, SIGNAL (clicked ()), wizard, SLOT (accept ()));
392  connect (m_cancel, SIGNAL (clicked ()), wizard, SLOT (reject ()));
393  }
394 }
Base class for Octave interfaces that use Qt.
resource_manager & get_resource_manager(void)
QPushButton * m_cancel
QPushButton * m_previous
final_page(base_qobject &oct_qobj, welcome_wizard *wizard)
QPushButton * m_finish
static QWidget * create(base_qobject &oct_qobj, welcome_wizard *wizard)
initial_page(base_qobject &oct_qobj, welcome_wizard *wizard)
static QWidget * create(base_qobject &oct_qobj, welcome_wizard *wizard)
QPushButton * m_cancel
QPushButton * m_next
gui_settings * get_settings(void) const
setup_community_news(base_qobject &oct_qobj, welcome_wizard *wizard)
static QWidget * create(base_qobject &oct_qobj, welcome_wizard *wizard)
QList< page_creator_fptr > m_page_ctor_list
QList< page_creator_fptr >::iterator m_page_list_iterator
void handle_web_connect_option(int state)
base_qobject & m_octave_qobj
welcome_wizard(base_qobject &oct_qobj, QWidget *parent=nullptr)
const gui_pref nr_allow_connection("news/allow_web_connection", QVariant(false))
static uint32_t state[624]
Definition: randmtzig.cc:190
static QLabel * make_octave_logo(QWidget *p=nullptr, int height=100)
const QString key
const QVariant def