From 92dc1752d477cfa5ea72e6a0489d21a42213371c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 3 Feb 2017 15:55:49 +0100 Subject: [PATCH] windowflags test: Don't assume window states can not be compound The controls need to reflect the facts that e.g. maximized and fullscreen can both be set at the same time, the same way a window can be minimized and fullscreen. Change-Id: I7f3e354a5efaefb9f51e6b1f24fa35980fe35899 Reviewed-by: Friedemann Kleint --- tests/manual/windowflags/controllerwindow.cpp | 2 +- tests/manual/windowflags/controls.cpp | 98 +++++++------------ tests/manual/windowflags/controls.h | 33 ++----- 3 files changed, 44 insertions(+), 89 deletions(-) diff --git a/tests/manual/windowflags/controllerwindow.cpp b/tests/manual/windowflags/controllerwindow.cpp index 42c7516402..3654bfbad0 100644 --- a/tests/manual/windowflags/controllerwindow.cpp +++ b/tests/manual/windowflags/controllerwindow.cpp @@ -70,7 +70,7 @@ ControllerWidget::ControllerWidget(QWidget *parent) hintsControl->setHints(previewWindow->windowFlags()); connect(hintsControl, SIGNAL(changed(Qt::WindowFlags)), this, SLOT(updatePreview())); - statesControl = new WindowStatesControl(WindowStatesControl::WantVisibleCheckBox|WindowStatesControl::WantActiveCheckBox); + statesControl = new WindowStatesControl; statesControl->setStates(previewWindow->windowState()); statesControl->setVisibleValue(true); connect(statesControl, SIGNAL(changed()), this, SLOT(updatePreview())); diff --git a/tests/manual/windowflags/controls.cpp b/tests/manual/windowflags/controls.cpp index 319f6aac8e..c167e5f8bf 100644 --- a/tests/manual/windowflags/controls.cpp +++ b/tests/manual/windowflags/controls.cpp @@ -161,97 +161,71 @@ void HintControl::slotCheckBoxChanged() emit changed(hints()); } -WindowStateControl::WindowStateControl(unsigned flags, QWidget *parent) +WindowStateControl::WindowStateControl(QWidget *parent) : QWidget(parent) , group(new QButtonGroup) - , visibleCheckBox(0) - , restoreButton(new QRadioButton(tr("Normal"))) - , minimizeButton(0) - , maximizeButton(new QRadioButton(tr("Maximized"))) - , fullscreenButton(new QRadioButton(tr("Fullscreen"))) + , restoreButton(new QCheckBox(tr("Normal"))) + , minimizeButton(new QCheckBox(tr("Minimized"))) + , maximizeButton(new QCheckBox(tr("Maximized"))) + , fullscreenButton(new QCheckBox(tr("Fullscreen"))) { QHBoxLayout *layout = new QHBoxLayout(this); - layout->setSpacing(0); + group->setExclusive(false); layout->setMargin(ControlLayoutMargin); - if (flags & WantVisibleCheckBox) { - visibleCheckBox = new QCheckBox(tr("Visible")); - connect(visibleCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - layout->addWidget(visibleCheckBox); - } - - group->setExclusive(true); - if (flags & WantMinimizeRadioButton) { - minimizeButton = new QRadioButton(tr("Minimized")); - group->addButton(minimizeButton, Qt::WindowMinimized); - layout->addWidget(minimizeButton); - } group->addButton(restoreButton, Qt::WindowNoState); + restoreButton->setEnabled(false); layout->addWidget(restoreButton); + group->addButton(minimizeButton, Qt::WindowMinimized); + layout->addWidget(minimizeButton); group->addButton(maximizeButton, Qt::WindowMaximized); layout->addWidget(maximizeButton); group->addButton(fullscreenButton, Qt::WindowFullScreen); layout->addWidget(fullscreenButton); - connect(group, SIGNAL(buttonReleased(int)), this, SIGNAL(changed())); + connect(group, SIGNAL(buttonReleased(int)), this, SIGNAL(stateChanged(int))); } -Qt::WindowState WindowStateControl::state() const +Qt::WindowStates WindowStateControl::state() const { - return Qt::WindowState(group->checkedId()); + Qt::WindowStates states; + foreach (QAbstractButton *button, group->buttons()) { + if (button->isChecked()) + states |= Qt::WindowState(group->id(button)); + } + return states; } -void WindowStateControl::setState(Qt::WindowState s) +void WindowStateControl::setState(Qt::WindowStates s) { group->blockSignals(true); - if (QAbstractButton *b = group->button(s)) - b->setChecked(true); + foreach (QAbstractButton *button, group->buttons()) + button->setChecked(s & Qt::WindowState(group->id(button))); + + if (!(s & (Qt::WindowMaximized | Qt::WindowFullScreen))) + restoreButton->setChecked(true); + group->blockSignals(false); } -bool WindowStateControl::visibleValue() const -{ - return visibleCheckBox && visibleCheckBox->isChecked(); -} - -void WindowStateControl::setVisibleValue(bool v) -{ - if (visibleCheckBox) { - visibleCheckBox->blockSignals(true); - visibleCheckBox->setChecked(v); - visibleCheckBox->blockSignals(false); - } -} - -WindowStatesControl::WindowStatesControl(unsigned flags, QWidget *parent) +WindowStatesControl::WindowStatesControl(QWidget *parent) : QGroupBox(tr("States"), parent) - , visibleCheckBox(0) - , activeCheckBox(0) - , minimizeCheckBox(new QCheckBox(tr("Minimized"))) - , stateControl(new WindowStateControl(0)) + , visibleCheckBox(new QCheckBox(tr("Visible"))) + , activeCheckBox(new QCheckBox(tr("Active"))) + , stateControl(new WindowStateControl) { QHBoxLayout *layout = new QHBoxLayout(this); layout->setSpacing(0); layout->setMargin(ControlLayoutMargin); - if (flags & WantVisibleCheckBox) { - visibleCheckBox = new QCheckBox(tr("Visible")); - connect(visibleCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - layout->addWidget(visibleCheckBox); - } - if (flags & WantActiveCheckBox) { - activeCheckBox = new QCheckBox(tr("Active")); - connect(activeCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - layout->addWidget(activeCheckBox); - } - layout->addWidget(minimizeCheckBox); + connect(visibleCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + layout->addWidget(visibleCheckBox); + connect(activeCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + layout->addWidget(activeCheckBox); layout->addWidget(stateControl); - connect(stateControl, SIGNAL(changed()), this, SIGNAL(changed())); - connect(minimizeCheckBox, SIGNAL(clicked()), this, SIGNAL(changed())); + connect(stateControl, SIGNAL(stateChanged(int)), this, SIGNAL(changed())); } Qt::WindowStates WindowStatesControl::states() const { Qt::WindowStates s = stateControl->state(); - if (minimizeCheckBox->isChecked()) - s |= Qt::WindowMinimized; if (activeValue()) s |= Qt::WindowActive; return s; @@ -259,11 +233,7 @@ Qt::WindowStates WindowStatesControl::states() const void WindowStatesControl::setStates(Qt::WindowStates s) { - minimizeCheckBox->blockSignals(true); - minimizeCheckBox->setChecked(s & Qt::WindowMinimized); - minimizeCheckBox->blockSignals(false); - s &= ~Qt::WindowMinimized; - stateControl->setState(Qt::WindowState(int(s))); + stateControl->setState(s); setActiveValue(s & Qt::WindowActive); } diff --git a/tests/manual/windowflags/controls.h b/tests/manual/windowflags/controls.h index 79faaaa9c3..e140d813cc 100644 --- a/tests/manual/windowflags/controls.h +++ b/tests/manual/windowflags/controls.h @@ -77,29 +77,20 @@ private: class WindowStateControl : public QWidget { Q_OBJECT public: - enum Flags { - WantVisibleCheckBox = 0x1, - WantMinimizeRadioButton = 0x2 - }; + explicit WindowStateControl(QWidget *parent= 0); - explicit WindowStateControl(unsigned flags, QWidget *parent= 0); - - Qt::WindowState state() const; - void setState(Qt::WindowState s); - - bool visibleValue() const; - void setVisibleValue(bool); + Qt::WindowStates state() const; + void setState(Qt::WindowStates s); signals: - void changed(); + void stateChanged(int); private: QButtonGroup *group; - QCheckBox *visibleCheckBox; - QRadioButton *restoreButton; - QRadioButton *minimizeButton; - QRadioButton *maximizeButton; - QRadioButton *fullscreenButton; + QCheckBox *restoreButton; + QCheckBox *minimizeButton; + QCheckBox *maximizeButton; + QCheckBox *fullscreenButton; }; // Control for the Qt::WindowStates flags (normal, maximized, fullscreen exclusively @@ -108,12 +99,7 @@ class WindowStatesControl : public QGroupBox { Q_OBJECT public: - enum Flags { - WantVisibleCheckBox = 0x1, - WantActiveCheckBox = 0x2 - }; - - explicit WindowStatesControl(unsigned flags, QWidget *parent= 0); + explicit WindowStatesControl(QWidget *parent= 0); Qt::WindowStates states() const; void setStates(Qt::WindowStates s); @@ -129,7 +115,6 @@ signals: private: QCheckBox *visibleCheckBox; QCheckBox *activeCheckBox; - QCheckBox *minimizeCheckBox; WindowStateControl *stateControl; };