1
0
mirror of https://github.com/strawberrymusicplayer/strawberry synced 2025-01-28 16:20:26 +01:00

Add on startup options to show maximized or minimized

This commit is contained in:
Jonas Kvinge 2020-06-18 21:46:36 +02:00
parent 3b58c02db0
commit d3463250a9
5 changed files with 101 additions and 45 deletions

View File

@ -249,8 +249,9 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
collection_sort_model_(new QSortFilterProxyModel(this)),
track_position_timer_(new QTimer(this)),
track_slider_timer_(new QTimer(this)),
initialised_(false),
initialized_(false),
was_maximized_(true),
was_minimized_(false),
playing_widget_(true),
doubleclick_addmode_(BehaviourSettingsPage::AddBehaviour_Append),
doubleclick_playmode_(BehaviourSettingsPage::PlayBehaviour_Never),
@ -794,8 +795,6 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
if (settings_.contains("geometry")) {
restoreGeometry(settings_.value("geometry").toByteArray());
}
was_maximized_ = settings_.value("maximized", true).toBool();
if (was_maximized_) setWindowState(windowState() | Qt::WindowMaximized);
if (!ui_->splitter->restoreState(settings_.value("splitter_state").toByteArray())) {
ui_->splitter->setSizes(QList<int>() << 250 << width() - 250);
@ -828,7 +827,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
#else
QSettings s;
s.beginGroup(BehaviourSettingsPage::kSettingsGroup);
StartupBehaviour behaviour = StartupBehaviour(s.value("startupbehaviour", Startup_Remember).toInt());
BehaviourSettingsPage::StartupBehaviour behaviour = BehaviourSettingsPage::StartupBehaviour(s.value("startupbehaviour", BehaviourSettingsPage::Startup_Remember).toInt());
s.endGroup();
bool hidden = settings_.value("hidden", false).toBool();
if (hidden && (!QSystemTrayIcon::isSystemTrayAvailable() || !tray_icon_ || !tray_icon_->IsVisible())) {
@ -838,14 +837,26 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
}
else {
switch (behaviour) {
case Startup_AlwaysHide:
hide();
case BehaviourSettingsPage::Startup_Remember:
was_maximized_ = settings_.value("maximized", true).toBool();
if (was_maximized_) setWindowState(windowState() | Qt::WindowMaximized);
was_minimized_ = settings_.value("minimized", false).toBool();
if (was_minimized_) setWindowState(windowState() | Qt::WindowMinimized);
setVisible(!hidden);
break;
case Startup_AlwaysShow:
case BehaviourSettingsPage::Startup_Show:
show();
break;
case Startup_Remember:
setVisible(!hidden);
case BehaviourSettingsPage::Startup_Hide:
hide();
break;
case BehaviourSettingsPage::Startup_ShowMaximized:
setWindowState(windowState() | Qt::WindowMaximized);
show();
break;
case BehaviourSettingsPage::Startup_ShowMinimized:
setWindowState(windowState() | Qt::WindowMinimized);
show();
break;
}
}
@ -866,10 +877,12 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
if (!options.contains_play_options()) {
LoadPlaybackStatus();
}
if (app_->scrobbler()->IsEnabled() && !app_->scrobbler()->IsOffline()) app_->scrobbler()->Submit();
if (app_->scrobbler()->IsEnabled() && !app_->scrobbler()->IsOffline()) {
app_->scrobbler()->Submit();
}
qLog(Debug) << "Started" << QThread::currentThread();
initialised_ = true;
initialized_ = true;
}
@ -1187,9 +1200,10 @@ void MainWindow::ToggleSearchCoverAuto(const bool checked) {
void MainWindow::SaveGeometry() {
if (!initialised_) return;
if (!initialized_) return;
settings_.setValue("maximized", isMaximized());
settings_.setValue("minimized", isMinimized());
settings_.setValue("geometry", saveGeometry());
settings_.setValue("splitter_state", ui_->splitter->saveState());
@ -1375,10 +1389,12 @@ void MainWindow::SetHiddenInTray(const bool hidden) {
// Some window managers don't remember maximized state between calls to hide() and show(), so we have to remember it ourself.
if (hidden) {
was_maximized_ = isMaximized();
was_minimized_ = isMinimized();
hide();
}
else {
if (was_maximized_) showMaximized();
if (was_minimized_) { showMinimized(); }
else if (was_maximized_) showMaximized();
else show();
}

View File

@ -106,13 +106,6 @@ class MainWindow : public QMainWindow, public PlatformInterface {
static const char *kSettingsGroup;
static const char *kAllFilesFilterSpec;
// Don't change the values
enum StartupBehaviour {
Startup_Remember = 1,
Startup_AlwaysShow = 2,
Startup_AlwaysHide = 3,
};
void SetHiddenInTray(const bool hidden);
void CommandlineOptionsReceived(const CommandlineOptions& options);
@ -358,8 +351,9 @@ class MainWindow : public QMainWindow, public PlatformInterface {
QTimer *track_slider_timer_;
QSettings settings_;
bool initialised_;
bool initialized_;
bool was_maximized_;
bool was_minimized_;
bool playing_widget_;
BehaviourSettingsPage::AddBehaviour doubleclick_addmode_;
BehaviourSettingsPage::PlayBehaviour doubleclick_playmode_;

View File

@ -169,11 +169,13 @@ void BehaviourSettingsPage::Load() {
ui_->checkbox_resumeplayback->setChecked(s.value("resumeplayback", false).toBool());
ui_->checkbox_playingwidget->setChecked(s.value("playing_widget", true).toBool());
MainWindow::StartupBehaviour behaviour = MainWindow::StartupBehaviour(s.value("startupbehaviour", MainWindow::Startup_Remember).toInt());
StartupBehaviour behaviour = StartupBehaviour(s.value("startupbehaviour", Startup_Remember).toInt());
switch (behaviour) {
case MainWindow::Startup_AlwaysHide: ui_->radiobutton_alwayshide->setChecked(true); break;
case MainWindow::Startup_AlwaysShow: ui_->radiobutton_alwaysshow->setChecked(true); break;
case MainWindow::Startup_Remember: ui_->radiobutton_remember->setChecked(true); break;
case Startup_Remember: ui_->radiobutton_remember->setChecked(true); break;
case Startup_Show: ui_->radiobutton_show->setChecked(true); break;
case Startup_Hide: ui_->radiobutton_hide->setChecked(true); break;
case Startup_ShowMaximized: ui_->radiobutton_show_maximized->setChecked(true); break;
case Startup_ShowMinimized: ui_->radiobutton_show_minimized->setChecked(true); break;
}
QString name = language_map_.key(s.value("language").toString());
@ -211,10 +213,12 @@ void BehaviourSettingsPage::Save() {
s.setValue("playing_widget", ui_->checkbox_playingwidget->isChecked());
s.setValue("scrolltrayicon", ui_->checkbox_scrolltrayicon->isChecked());
MainWindow::StartupBehaviour behaviour = MainWindow::Startup_Remember;
if (ui_->radiobutton_alwayshide->isChecked()) behaviour = MainWindow::Startup_AlwaysHide;
if (ui_->radiobutton_alwaysshow->isChecked()) behaviour = MainWindow::Startup_AlwaysShow;
if (ui_->radiobutton_remember->isChecked()) behaviour = MainWindow::Startup_Remember;
StartupBehaviour behaviour = Startup_Remember;
if (ui_->radiobutton_remember->isChecked()) behaviour = Startup_Remember;
if (ui_->radiobutton_show->isChecked()) behaviour = Startup_Show;
if (ui_->radiobutton_hide->isChecked()) behaviour = Startup_Hide;
if (ui_->radiobutton_show_maximized->isChecked()) behaviour = Startup_ShowMaximized;
if (ui_->radiobutton_show_minimized->isChecked()) behaviour = Startup_ShowMinimized;
s.setValue("startupbehaviour", int(behaviour));
s.setValue("language", language_map_.contains(ui_->combobox_language->currentText()) ? language_map_[ui_->combobox_language->currentText()] : QString());
@ -242,8 +246,8 @@ void BehaviourSettingsPage::Save() {
void BehaviourSettingsPage::ShowTrayIconToggled(bool on) {
ui_->radiobutton_alwayshide->setEnabled(on);
if (!on && ui_->radiobutton_alwayshide->isChecked()) ui_->radiobutton_remember->setChecked(true);
ui_->radiobutton_hide->setEnabled(on);
if (!on && ui_->radiobutton_hide->isChecked()) ui_->radiobutton_remember->setChecked(true);
ui_->checkbox_keeprunning->setEnabled(on);
ui_->checkbox_scrolltrayicon->setEnabled(on);

View File

@ -41,6 +41,15 @@ public:
static const char *kSettingsGroup;
// Don't change the values
enum StartupBehaviour {
Startup_Remember = 1,
Startup_Show = 2,
Startup_Hide = 3,
Startup_ShowMaximized = 4,
Startup_ShowMinimized = 5,
};
enum PlayBehaviour {
PlayBehaviour_Never = 1,
PlayBehaviour_IfStopped = 2,

View File

@ -67,20 +67,6 @@
<string>On startup</string>
</property>
<layout class="QVBoxLayout" name="layout_startup">
<item>
<widget class="QRadioButton" name="radiobutton_alwaysshow">
<property name="text">
<string>Always show &amp;the main window</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radiobutton_alwayshide">
<property name="text">
<string>Alwa&amp;ys hide the main window</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radiobutton_remember">
<property name="text">
@ -91,6 +77,34 @@
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radiobutton_show">
<property name="text">
<string>Show the main window</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radiobutton_hide">
<property name="text">
<string>Hide the main window</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radiobutton_show_maximized">
<property name="text">
<string>Show the main window maximized</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radiobutton_show_minimized">
<property name="text">
<string>Show the main window minimized</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -323,6 +337,25 @@
</item>
</layout>
</widget>
<tabstops>
<tabstop>checkbox_showtrayicon</tabstop>
<tabstop>checkbox_keeprunning</tabstop>
<tabstop>checkbox_resumeplayback</tabstop>
<tabstop>checkbox_playingwidget</tabstop>
<tabstop>checkbox_scrolltrayicon</tabstop>
<tabstop>radiobutton_remember</tabstop>
<tabstop>radiobutton_show</tabstop>
<tabstop>radiobutton_hide</tabstop>
<tabstop>radiobutton_show_maximized</tabstop>
<tabstop>radiobutton_show_minimized</tabstop>
<tabstop>combobox_language</tabstop>
<tabstop>combobox_menuplaymode</tabstop>
<tabstop>combobox_previousmode</tabstop>
<tabstop>combobox_doubleclickaddmode</tabstop>
<tabstop>combobox_doubleclickplaymode</tabstop>
<tabstop>combobox_doubleclickplaylistaddmode</tabstop>
<tabstop>spinbox_seekstepsec</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>