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 <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
2aa62dad1d
commit
92dc1752d4
@ -70,7 +70,7 @@ ControllerWidget::ControllerWidget(QWidget *parent)
|
|||||||
hintsControl->setHints(previewWindow->windowFlags());
|
hintsControl->setHints(previewWindow->windowFlags());
|
||||||
connect(hintsControl, SIGNAL(changed(Qt::WindowFlags)), this, SLOT(updatePreview()));
|
connect(hintsControl, SIGNAL(changed(Qt::WindowFlags)), this, SLOT(updatePreview()));
|
||||||
|
|
||||||
statesControl = new WindowStatesControl(WindowStatesControl::WantVisibleCheckBox|WindowStatesControl::WantActiveCheckBox);
|
statesControl = new WindowStatesControl;
|
||||||
statesControl->setStates(previewWindow->windowState());
|
statesControl->setStates(previewWindow->windowState());
|
||||||
statesControl->setVisibleValue(true);
|
statesControl->setVisibleValue(true);
|
||||||
connect(statesControl, SIGNAL(changed()), this, SLOT(updatePreview()));
|
connect(statesControl, SIGNAL(changed()), this, SLOT(updatePreview()));
|
||||||
|
@ -161,97 +161,71 @@ void HintControl::slotCheckBoxChanged()
|
|||||||
emit changed(hints());
|
emit changed(hints());
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowStateControl::WindowStateControl(unsigned flags, QWidget *parent)
|
WindowStateControl::WindowStateControl(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, group(new QButtonGroup)
|
, group(new QButtonGroup)
|
||||||
, visibleCheckBox(0)
|
, restoreButton(new QCheckBox(tr("Normal")))
|
||||||
, restoreButton(new QRadioButton(tr("Normal")))
|
, minimizeButton(new QCheckBox(tr("Minimized")))
|
||||||
, minimizeButton(0)
|
, maximizeButton(new QCheckBox(tr("Maximized")))
|
||||||
, maximizeButton(new QRadioButton(tr("Maximized")))
|
, fullscreenButton(new QCheckBox(tr("Fullscreen")))
|
||||||
, fullscreenButton(new QRadioButton(tr("Fullscreen")))
|
|
||||||
{
|
{
|
||||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||||
layout->setSpacing(0);
|
group->setExclusive(false);
|
||||||
layout->setMargin(ControlLayoutMargin);
|
layout->setMargin(ControlLayoutMargin);
|
||||||
if (flags & WantVisibleCheckBox) {
|
group->addButton(restoreButton, Qt::WindowNoState);
|
||||||
visibleCheckBox = new QCheckBox(tr("Visible"));
|
restoreButton->setEnabled(false);
|
||||||
connect(visibleCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
|
layout->addWidget(restoreButton);
|
||||||
layout->addWidget(visibleCheckBox);
|
|
||||||
}
|
|
||||||
|
|
||||||
group->setExclusive(true);
|
|
||||||
if (flags & WantMinimizeRadioButton) {
|
|
||||||
minimizeButton = new QRadioButton(tr("Minimized"));
|
|
||||||
group->addButton(minimizeButton, Qt::WindowMinimized);
|
group->addButton(minimizeButton, Qt::WindowMinimized);
|
||||||
layout->addWidget(minimizeButton);
|
layout->addWidget(minimizeButton);
|
||||||
}
|
|
||||||
group->addButton(restoreButton, Qt::WindowNoState);
|
|
||||||
layout->addWidget(restoreButton);
|
|
||||||
group->addButton(maximizeButton, Qt::WindowMaximized);
|
group->addButton(maximizeButton, Qt::WindowMaximized);
|
||||||
layout->addWidget(maximizeButton);
|
layout->addWidget(maximizeButton);
|
||||||
group->addButton(fullscreenButton, Qt::WindowFullScreen);
|
group->addButton(fullscreenButton, Qt::WindowFullScreen);
|
||||||
layout->addWidget(fullscreenButton);
|
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);
|
group->blockSignals(true);
|
||||||
if (QAbstractButton *b = group->button(s))
|
foreach (QAbstractButton *button, group->buttons())
|
||||||
b->setChecked(true);
|
button->setChecked(s & Qt::WindowState(group->id(button)));
|
||||||
|
|
||||||
|
if (!(s & (Qt::WindowMaximized | Qt::WindowFullScreen)))
|
||||||
|
restoreButton->setChecked(true);
|
||||||
|
|
||||||
group->blockSignals(false);
|
group->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WindowStateControl::visibleValue() const
|
WindowStatesControl::WindowStatesControl(QWidget *parent)
|
||||||
{
|
|
||||||
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)
|
|
||||||
: QGroupBox(tr("States"), parent)
|
: QGroupBox(tr("States"), parent)
|
||||||
, visibleCheckBox(0)
|
, visibleCheckBox(new QCheckBox(tr("Visible")))
|
||||||
, activeCheckBox(0)
|
, activeCheckBox(new QCheckBox(tr("Active")))
|
||||||
, minimizeCheckBox(new QCheckBox(tr("Minimized")))
|
, stateControl(new WindowStateControl)
|
||||||
, stateControl(new WindowStateControl(0))
|
|
||||||
{
|
{
|
||||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||||
layout->setSpacing(0);
|
layout->setSpacing(0);
|
||||||
layout->setMargin(ControlLayoutMargin);
|
layout->setMargin(ControlLayoutMargin);
|
||||||
if (flags & WantVisibleCheckBox) {
|
|
||||||
visibleCheckBox = new QCheckBox(tr("Visible"));
|
|
||||||
connect(visibleCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
|
connect(visibleCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
|
||||||
layout->addWidget(visibleCheckBox);
|
layout->addWidget(visibleCheckBox);
|
||||||
}
|
|
||||||
if (flags & WantActiveCheckBox) {
|
|
||||||
activeCheckBox = new QCheckBox(tr("Active"));
|
|
||||||
connect(activeCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
|
connect(activeCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
|
||||||
layout->addWidget(activeCheckBox);
|
layout->addWidget(activeCheckBox);
|
||||||
}
|
|
||||||
layout->addWidget(minimizeCheckBox);
|
|
||||||
layout->addWidget(stateControl);
|
layout->addWidget(stateControl);
|
||||||
connect(stateControl, SIGNAL(changed()), this, SIGNAL(changed()));
|
connect(stateControl, SIGNAL(stateChanged(int)), this, SIGNAL(changed()));
|
||||||
connect(minimizeCheckBox, SIGNAL(clicked()), this, SIGNAL(changed()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::WindowStates WindowStatesControl::states() const
|
Qt::WindowStates WindowStatesControl::states() const
|
||||||
{
|
{
|
||||||
Qt::WindowStates s = stateControl->state();
|
Qt::WindowStates s = stateControl->state();
|
||||||
if (minimizeCheckBox->isChecked())
|
|
||||||
s |= Qt::WindowMinimized;
|
|
||||||
if (activeValue())
|
if (activeValue())
|
||||||
s |= Qt::WindowActive;
|
s |= Qt::WindowActive;
|
||||||
return s;
|
return s;
|
||||||
@ -259,11 +233,7 @@ Qt::WindowStates WindowStatesControl::states() const
|
|||||||
|
|
||||||
void WindowStatesControl::setStates(Qt::WindowStates s)
|
void WindowStatesControl::setStates(Qt::WindowStates s)
|
||||||
{
|
{
|
||||||
minimizeCheckBox->blockSignals(true);
|
stateControl->setState(s);
|
||||||
minimizeCheckBox->setChecked(s & Qt::WindowMinimized);
|
|
||||||
minimizeCheckBox->blockSignals(false);
|
|
||||||
s &= ~Qt::WindowMinimized;
|
|
||||||
stateControl->setState(Qt::WindowState(int(s)));
|
|
||||||
setActiveValue(s & Qt::WindowActive);
|
setActiveValue(s & Qt::WindowActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,29 +77,20 @@ private:
|
|||||||
class WindowStateControl : public QWidget {
|
class WindowStateControl : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum Flags {
|
explicit WindowStateControl(QWidget *parent= 0);
|
||||||
WantVisibleCheckBox = 0x1,
|
|
||||||
WantMinimizeRadioButton = 0x2
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit WindowStateControl(unsigned flags, QWidget *parent= 0);
|
Qt::WindowStates state() const;
|
||||||
|
void setState(Qt::WindowStates s);
|
||||||
Qt::WindowState state() const;
|
|
||||||
void setState(Qt::WindowState s);
|
|
||||||
|
|
||||||
bool visibleValue() const;
|
|
||||||
void setVisibleValue(bool);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changed();
|
void stateChanged(int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QButtonGroup *group;
|
QButtonGroup *group;
|
||||||
QCheckBox *visibleCheckBox;
|
QCheckBox *restoreButton;
|
||||||
QRadioButton *restoreButton;
|
QCheckBox *minimizeButton;
|
||||||
QRadioButton *minimizeButton;
|
QCheckBox *maximizeButton;
|
||||||
QRadioButton *maximizeButton;
|
QCheckBox *fullscreenButton;
|
||||||
QRadioButton *fullscreenButton;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Control for the Qt::WindowStates flags (normal, maximized, fullscreen exclusively
|
// Control for the Qt::WindowStates flags (normal, maximized, fullscreen exclusively
|
||||||
@ -108,12 +99,7 @@ class WindowStatesControl : public QGroupBox
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum Flags {
|
explicit WindowStatesControl(QWidget *parent= 0);
|
||||||
WantVisibleCheckBox = 0x1,
|
|
||||||
WantActiveCheckBox = 0x2
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit WindowStatesControl(unsigned flags, QWidget *parent= 0);
|
|
||||||
|
|
||||||
Qt::WindowStates states() const;
|
Qt::WindowStates states() const;
|
||||||
void setStates(Qt::WindowStates s);
|
void setStates(Qt::WindowStates s);
|
||||||
@ -129,7 +115,6 @@ signals:
|
|||||||
private:
|
private:
|
||||||
QCheckBox *visibleCheckBox;
|
QCheckBox *visibleCheckBox;
|
||||||
QCheckBox *activeCheckBox;
|
QCheckBox *activeCheckBox;
|
||||||
QCheckBox *minimizeCheckBox;
|
|
||||||
WindowStateControl *stateControl;
|
WindowStateControl *stateControl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user