annotate libgui/src/gui-utils.cc @ 31616:726d2628752c

eliminate unused default_settings variable from resource manager * resource-manager.h, resource-manager.cc (resource_manager::m_default_settings): Delete member variable, accessor function, and all uses.
author John W. Eaton <jwe@octave.org>
date Fri, 02 Dec 2022 10:10:19 -0500
parents e2c8c852399e
children c6d54dd31a7e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29220
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
1 ////////////////////////////////////////////////////////////////////////
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 // Copyright (C) 2000-2022 The Octave Project Developers
29220
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
4 //
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
6 // distribution or <https://octave.org/copyright/>.
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
7 //
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
8 // This file is part of Octave.
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
9 //
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
11 // under the terms of the GNU General Public License as published by
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
13 // (at your option) any later version.
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
14 //
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
18 // GNU General Public License for more details.
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
19 //
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
20 // You should have received a copy of the GNU General Public License
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
21 // along with Octave; see the file COPYING. If not, see
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
22 // <https://www.gnu.org/licenses/>.
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
23 //
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
24 ////////////////////////////////////////////////////////////////////////
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
25
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
26 #if defined (HAVE_CONFIG_H)
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
27 # include "config.h"
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
28 #endif
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.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>
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
31 #include <QRect>
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
32 #include <QScreen>
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
33
29220
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
34 #include "gui-utils.h"
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
35
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
36 namespace octave
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
37 {
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
38 OCTGUI_API QColor
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
39 interpolate_color (const QColor& col1, const QColor& col2,
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
40 double fs, double fv)
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
41 {
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
42 qreal h1, s1, v1, h2, s2, v2;
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
43
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
44 col1.getHsvF (&h1, &s1, &v1);
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
45 col2.getHsvF (&h2, &s2, &v2);
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
46
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
47 return QColor::fromHsvF (h1, s1*fs, v1 + fv*(v2 - v1));
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
48 }
30690
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
49
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
50 OCTGUI_API void
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
51 get_screen_geometry (int& width, int& height)
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
52 {
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
53 QRect geom = QGuiApplication::primaryScreen ()->availableGeometry ();
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
54
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
55 width = geom.width ();
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
56 height = geom.height ();
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
57 }
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
58
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
59
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
60 OCTGUI_API void
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
61 adjust_to_screen (QRect& actual_geometry, const QRect& default_geometry)
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
62 {
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
63
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
64 // Get the screen that holds the largest part of the given actual geometry
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
65
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
66 const QScreen *actual_screen = nullptr; // no screen found yet
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
67 QRect actual_screen_geom = QRect (); // geometry of found screen
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
68 int intersected_area_max = 0; // max. intersected area
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
69
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
70 const int area_actual_geometry
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
71 = actual_geometry.width () * actual_geometry.height ();
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
72 QRect intersection;
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
73
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
74 foreach (const QScreen *screen, QGuiApplication::screens())
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
75 {
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
76 QRect screen_geom = screen->availableGeometry ();
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
77 intersection = screen_geom.intersected (actual_geometry);
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
78 if (! intersection.isEmpty ())
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
79 {
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
80 int area = intersection.width () * intersection.height ();
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
81 if (area > intersected_area_max)
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
82 {
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
83 actual_screen = screen;
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
84 actual_screen_geom = screen->availableGeometry ();
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
85 if (area == area_actual_geometry)
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
86 return; // Actual geom is completely on a screen: return
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
87 intersected_area_max = area;
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
88 }
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
89 }
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
90 }
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
91
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
92 // If the actual geometry is on no screen, use deault geometry
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
93
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
94 if (actual_screen == nullptr)
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
95 {
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
96 actual_geometry = default_geometry;
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
97 return;
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
98 }
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
99
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
100 // There is a screen that holds a part of the actual geometry.
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
101 // Now adjust actual geometry to this screen
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
102
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
103 // Get some properties of the actual and intersected geometry
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
104 int agx1, agy1, agx2, agy2;
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
105 actual_geometry.getCoords (&agx1, &agy1, &agx2, &agy2);
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
106 int isx1, isy1, isx2, isy2;
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
107 intersection.getCoords (&isx1, &isy1, &isx2, &isy2);
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
108
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
109 // Make the intersection the same size as the actual geometry
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
110 if ((agx1 == isx1) && (agx2 != isx2))
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
111 isx1 = isx1 - agx2 + isx2;
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
112 if ((agx1 != isx1) && (agx2 == isx2))
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
113 isx2 = isx2 + agx2 - isx2;
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
114 if ((agy1 == isy1) && (agy2 != isy2))
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
115 isy1 = isy1 - agy2 + isy2;
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
116 if ((agy1 != isy1) && (agy2 == isy2))
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
117 isy2 = isy2 + agy2 - isy2;
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
118
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
119 // And compute again the intersection with the screen if this resizing
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
120 // led to corners outside the screen
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
121 actual_geometry = actual_screen_geom.intersected (
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
122 QRect (QPoint (isx1,isy1), QPoint (isx2,isy2)));
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
123 }
e2c8c852399e replace use of depreciated QDesktopWidget in GUI
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
124
29220
ab8aa1bb3c2f add gui utilities with first function for color interpolation
Torsten Lilge <ttl-octave@mailbox.org>
parents:
diff changeset
125 }