annotate libgui/src/release-notes.cc @ 30690:e2c8c852399e

replace use of depreciated QDesktopWidget in GUI * gui-utils.cc: include QApplication, QRect and QScreen; (get_screen_geometry): return QRect with geometry of primary screen; (adjust_to_screen): adjust given QRect to be completely on the screen that contains the largest part of the QRect, use a default geometry if no part is on an available screen * gui-utils.h: include QRect; new function get_screen_geometry and adjust_to_screen * community-news.cc: do not include QDesktopWidget, but gui-utils.h; (get_screen_geometry); move function to gui-utils.cc; * community-news.h: move get_screen_geometry to gui-utils.h * find-dialog.cc: do not include QDesktopWidget, but gui-utils.h; (restore_settings): use new function adjust_to_screen * main-window.cc: do not include QDesktopWidget, but gui-utils.h; (get_screen_geometry: move function to gui-utils.cc * main-window.h: move function get_screen_geometry to gui.utils.h; * octave-dock-widget.cc: do not include QDesktopWidget, but gui-utils.h QScreen and QWindow; (handle_settings): use adjust_to_screen and QGuiApplication->primaryScreen * release-notes.cc: do not include QDesktopWidget, but gui-utils.h and QScreen; (get_screen_geometry): move to gui-utils.cc; * release-notes.h: move get:screen_geometry to gui-utils.h * terminal-dock-widget.cc: do not include QDesktopWidget but QScreen; (terminal_dock_widget): use QGuiApplication->primaryScreen instead of QDesktopWidget->screenGeometry * welcome-wizard.cc: remove include of QDesktopWidget
author Torsten Lilge <ttl-octave@mailbox.org>
date Sun, 30 Jan 2022 16:41:44 +0100
parents 796f54d4ddbf
children 04601f6c47f4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29836
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 ////////////////////////////////////////////////////////////////////////
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30398
diff changeset
3 // Copyright (C) 2011-2022 The Octave Project Developers
29836
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 //
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 // distribution or <https://octave.org/copyright/>.
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 //
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 // This file is part of Octave.
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 //
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 // under the terms of the GNU General Public License as published by
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 // (at your option) any later version.
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 //
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 // GNU General Public License for more details.
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 //
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 // You should have received a copy of the GNU General Public License
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 // along with Octave; see the file COPYING. If not, see
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 // <https://www.gnu.org/licenses/>.
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 //
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 ////////////////////////////////////////////////////////////////////////
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #if defined (HAVE_CONFIG_H)
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 # include "config.h"
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #endif
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
30690
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
30 #include <QApplication>
29836
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include <QFile>
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include <QIcon>
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include <QLayout>
30690
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
34 #include <QScreen>
29836
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include <QTextBrowser>
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 #include <QTextStream>
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 #include <QThread>
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include "release-notes.h"
30690
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
40 #include "gui-utils.h"
29836
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 #include "gui-preferences-nr.h"
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 #include "news-reader.h"
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 #include "octave-qobject.h"
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 #include "defaults.h"
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 namespace octave
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 {
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 release_notes::release_notes (void)
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 : QWidget (nullptr), m_browser (nullptr),
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 m_release_notes_icon (":/actions/icons/logo.png")
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 {
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 #if 0
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 // The following code was in main-window.cc. How should that be
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 // handled here?
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 if (dw_icon_set_names[icon_set_found].name != "NONE")
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 m_release_notes_icon = dw_icon_set_names[icon_set_found].path
30398
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29836
diff changeset
58 + "ReleaseWidget.png";
29836
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 else
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 m_release_notes_icon = ":/actions/icons/logo.png";
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 #endif
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 std::string news_file = config::oct_etc_dir () + "/NEWS";
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 QString news;
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 QFile *file = new QFile (QString::fromStdString (news_file));
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 if (file->open (QFile::ReadOnly))
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 {
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 QTextStream *stream = new QTextStream (file);
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 news = stream->readAll ();
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 if (! news.isEmpty ())
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 {
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 // Convert '<', '>' which would be interpreted as HTML
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 news.replace ("<", "&lt;");
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 news.replace (">", "&gt;");
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 // Add HTML tags for pre-formatted text
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 news.prepend ("<pre>");
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 news.append ("</pre>");
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 }
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 else
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 news = (tr ("The release notes file '%1' is empty.")
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 . arg (QString::fromStdString (news_file)));
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 }
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 else
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 news = (tr ("The release notes file '%1' cannot be read.")
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 . arg (QString::fromStdString (news_file)));
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 m_browser = new QTextBrowser (this);
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 m_browser->setText (news);
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 QVBoxLayout *vlayout = new QVBoxLayout;
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 vlayout->addWidget (m_browser);
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 setLayout (vlayout);
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 setWindowTitle (tr ("Octave Release Notes"));
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 m_browser->document ()->adjustSize ();
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 int win_x, win_y;
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 get_screen_geometry (win_x, win_y);
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 resize (win_x*2/5, win_y*2/3);
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 move (20, 20); // move to the top left corner
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 }
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 void release_notes::display (void)
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 {
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 if (! isVisible ())
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 show ();
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 else if (isMinimized ())
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 showNormal ();
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 setWindowIcon (QIcon (m_release_notes_icon));
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 raise ();
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 activateWindow ();
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 }
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120
56465c0739fa allow release notes window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 }