# HG changeset patch # User Torsten Lilge # Date 1607118158 -3600 # Node ID 7220b59c490b891c3ad873596c8f0dedc6a2a06e # Parent a43cf0300dcd7c2e5d8f10d1f41cc18e631aa872 clean up constructing main window layout of the gui * main-window.cc (display_release_notes): use new get_screen_geometry; (display_community_news): use new get_screen_geometry; (set_window_layout): use new set_default_geometry; (construct): use new set_default_geometry; (get_screen_geometry): new method determining the geometry of the screen where the main window is located; (set_default_geometry): set main window to 2/3 and 7/8 of available size * main-window.h: new get_screen_geometry, set_default_geometry diff -r a43cf0300dcd -r 7220b59c490b libgui/src/main-window.cc --- a/libgui/src/main-window.cc Fri Dec 04 19:53:30 2020 +0100 +++ b/libgui/src/main-window.cc Fri Dec 04 22:42:38 2020 +0100 @@ -669,18 +669,11 @@ browser->document ()->adjustSize (); - // center the window on the screen where octave is running - QDesktopWidget *m_desktop = QApplication::desktop (); - QRect screen_geo = m_desktop->availableGeometry (this); - - int win_x = screen_geo.width (); // width of the screen - int win_y = screen_geo.height (); // height of the screen - - int reln_x = win_x*2/5; // desired width of release notes - int reln_y = win_y*2/3; // desired height of release notes - - m_release_notes_window->resize (reln_x, reln_y); // set size - m_release_notes_window->move (20, 20); // move to the top left corner + int win_x, win_y; + get_screen_geometry (&win_x, &win_y); + + m_release_notes_window->resize (win_x*2/5, win_y*2/3); + m_release_notes_window->move (20, 20); // move to the top left corner } if (! m_release_notes_window->isVisible ()) @@ -749,17 +742,10 @@ m_community_news_window->setLayout (vlayout); m_community_news_window->setWindowTitle (tr ("Octave Community News")); - // center the window on the screen where octave is running - QDesktopWidget *m_desktop = QApplication::desktop (); - QRect screen_geo = m_desktop->availableGeometry (this); - - int win_x = screen_geo.width (); // width of the screen - int win_y = screen_geo.height (); // height of the screen - - int news_x = win_x/2; // desired width of news window - int news_y = win_y/2; // desired height of news window - - m_community_news_window->resize (news_x, news_y); // set size and center + int win_x, win_y; + get_screen_geometry (&win_x, &win_y); + + m_community_news_window->resize (win_x/2, win_y/2); m_community_news_window->move ((win_x - m_community_news_window->width ())/2, (win_y - m_community_news_window->height ())/2); } @@ -1546,13 +1532,7 @@ restoreGeometry (mw_geometry.def.toByteArray ()); restoreState (mw_state.def.toByteArray ()); - QDesktopWidget *m_desktop = QApplication::desktop (); - QRect screen_geo = m_desktop->availableGeometry (this); - - int win_x = screen_geo.width (); // width of the screen - int win_y = screen_geo.height (); // height of the screen - - resize (std::max (width (), 2*win_x/3), std::max (height (), 7*win_y/8)); + set_default_geometry (); } show (); @@ -2102,17 +2082,7 @@ addDockWidget (Qt::LeftDockWidgetArea, m_workspace_window); addDockWidget (Qt::LeftDockWidgetArea, m_history_window); - int win_x = QApplication::desktop ()->width (); - int win_y = QApplication::desktop ()->height (); - - if (win_x > 960) - win_x = 960; - - if (win_y > 720) - win_y = 720; - - setGeometry (0, 0, win_x, win_y); // excluding frame geometry - move (0, 0); // including frame geometry + set_default_geometry (); setStatusBar (m_status_bar); @@ -2849,4 +2819,23 @@ F__mfile_encoding__ (interp, ovl (mfile_encoding)); }); } + + void main_window::get_screen_geometry (int *width, int *height) + { + QRect screen_geometry + = QApplication::desktop ()->availableGeometry (this); + + *width = screen_geometry.width (); + *height = screen_geometry.height (); + } + + void main_window::set_default_geometry () + { + int win_x, win_y; + get_screen_geometry (&win_x, &win_y); + + move (0, 0); + resize (2*win_x/3, 7*win_y/8); + } + } diff -r a43cf0300dcd -r 7220b59c490b libgui/src/main-window.h --- a/libgui/src/main-window.h Fri Dec 04 19:53:30 2020 +0100 +++ b/libgui/src/main-window.h Fri Dec 04 22:42:38 2020 +0100 @@ -296,6 +296,9 @@ void update_default_encoding (const QString& default_encoding); + void get_screen_geometry (int *width, int *height); + void set_default_geometry (void); + base_qobject& m_octave_qobj; workspace_model *m_workspace_model;