Skip to content

Commit

Permalink
windowflags test: Don't assume window states can not be compound
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
torarnv committed Feb 9, 2017
1 parent 2aa62da commit 92dc175
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 88 deletions.
2 changes: 1 addition & 1 deletion tests/manual/windowflags/controllerwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
96 changes: 33 additions & 63 deletions tests/manual/windowflags/controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,109 +161,79 @@ 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);
group->blockSignals(false);
}
foreach (QAbstractButton *button, group->buttons())
button->setChecked(s & Qt::WindowState(group->id(button)));

bool WindowStateControl::visibleValue() const
{
return visibleCheckBox && visibleCheckBox->isChecked();
}
if (!(s & (Qt::WindowMaximized | Qt::WindowFullScreen)))
restoreButton->setChecked(true);

void WindowStateControl::setVisibleValue(bool v)
{
if (visibleCheckBox) {
visibleCheckBox->blockSignals(true);
visibleCheckBox->setChecked(v);
visibleCheckBox->blockSignals(false);
}
group->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;
}

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);
}

Expand Down
33 changes: 9 additions & 24 deletions tests/manual/windowflags/controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,20 @@ private slots:
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
Expand All @@ -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);
Expand All @@ -129,7 +115,6 @@ class WindowStatesControl : public QGroupBox
private:
QCheckBox *visibleCheckBox;
QCheckBox *activeCheckBox;
QCheckBox *minimizeCheckBox;
WindowStateControl *stateControl;
};

Expand Down

0 comments on commit 92dc175

Please sign in to comment.