Improve windowflags, windowgeometry manual tests.

- Make them compile with 4.8 for comparison
- Add Active to WindowStates control
- Add -layout option to windowgeometry

Change-Id: I052330eb8689883c104a0552708ea700c7cd790a
Reviewed-by: Joerg Bornemann <joerg.bornemann@nokia.com>
Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com>
This commit is contained in:
Friedemann Kleint 2012-07-11 15:12:26 +02:00 committed by Qt by Nokia
parent 7f2a64f403
commit 09d3ebbf2a
8 changed files with 62 additions and 21 deletions

View File

@ -39,14 +39,14 @@
** **
****************************************************************************/ ****************************************************************************/
#include <QtWidgets/QMainWindow> #include <QMainWindow>
#include <QtWidgets/QLabel> #include <QLabel>
#include <QtWidgets/QPushButton> #include <QPushButton>
#include <QtWidgets/QRadioButton> #include <QRadioButton>
#include <QtWidgets/QCheckBox> #include <QCheckBox>
#include <QtWidgets/QGroupBox> #include <QGroupBox>
#include <QtWidgets/QApplication> #include <QApplication>
#include <QtWidgets/QHBoxLayout> #include <QHBoxLayout>
#include "controllerwindow.h" #include "controllerwindow.h"
#include "controls.h" #include "controls.h"
@ -75,7 +75,7 @@ ControllerWindow::ControllerWindow()
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); statesControl = new WindowStatesControl(WindowStatesControl::WantVisibleCheckBox|WindowStatesControl::WantActiveCheckBox);
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()));
@ -94,7 +94,12 @@ ControllerWindow::ControllerWindow()
setLayout(mainLayout); setLayout(mainLayout);
setWindowTitle(tr("Window Flags (Qt version %1, %2)") setWindowTitle(tr("Window Flags (Qt version %1, %2)")
.arg(QLatin1String(qVersion()), qApp->platformName())); .arg(QLatin1String(qVersion()),
#if QT_VERSION >= 0x050000
qApp->platformName()));
#else
QLatin1String("<unknown>")));
#endif
updatePreview(); updatePreview();
} }

View File

@ -42,7 +42,7 @@
#ifndef CONTROLLERWINDOW_H #ifndef CONTROLLERWINDOW_H
#define CONTROLLERWINDOW_H #define CONTROLLERWINDOW_H
#include <QtWidgets/QWidget> #include <QWidget>
#include "previewwindow.h" #include "previewwindow.h"

View File

@ -98,6 +98,9 @@ HintControl::HintControl(QWidget *parent)
layout->addWidget(windowStaysOnBottomCheckBox, 6, 1); layout->addWidget(windowStaysOnBottomCheckBox, 6, 1);
layout->addWidget(customizeWindowHintCheckBox, 5, 0); layout->addWidget(customizeWindowHintCheckBox, 5, 0);
layout->addWidget(transparentForInputCheckBox, 6, 0); layout->addWidget(transparentForInputCheckBox, 6, 0);
#if QT_VERSION < 0x050000
transparentForInputCheckBox->setEnabled(false);
#endif
} }
Qt::WindowFlags HintControl::hints() const Qt::WindowFlags HintControl::hints() const
@ -129,8 +132,10 @@ Qt::WindowFlags HintControl::hints() const
flags |= Qt::WindowStaysOnBottomHint; flags |= Qt::WindowStaysOnBottomHint;
if (customizeWindowHintCheckBox->isChecked()) if (customizeWindowHintCheckBox->isChecked())
flags |= Qt::CustomizeWindowHint; flags |= Qt::CustomizeWindowHint;
#if QT_VERSION >= 0x050000
if (transparentForInputCheckBox->isChecked()) if (transparentForInputCheckBox->isChecked())
flags |= Qt::WindowTransparentForInput; flags |= Qt::WindowTransparentForInput;
#endif
return flags; return flags;
} }
@ -149,7 +154,9 @@ void HintControl::setHints(Qt::WindowFlags flags)
windowStaysOnTopCheckBox->setChecked(flags & Qt::WindowStaysOnTopHint); windowStaysOnTopCheckBox->setChecked(flags & Qt::WindowStaysOnTopHint);
windowStaysOnBottomCheckBox->setChecked(flags & Qt::WindowStaysOnBottomHint); windowStaysOnBottomCheckBox->setChecked(flags & Qt::WindowStaysOnBottomHint);
customizeWindowHintCheckBox->setChecked(flags & Qt::CustomizeWindowHint); customizeWindowHintCheckBox->setChecked(flags & Qt::CustomizeWindowHint);
#if QT_VERSION >= 0x050000
transparentForInputCheckBox->setChecked(flags & Qt::WindowTransparentForInput); transparentForInputCheckBox->setChecked(flags & Qt::WindowTransparentForInput);
#endif
} }
void HintControl::slotCheckBoxChanged() void HintControl::slotCheckBoxChanged()
@ -220,6 +227,7 @@ void WindowStateControl::setVisibleValue(bool v)
WindowStatesControl::WindowStatesControl(unsigned flags, QWidget *parent) WindowStatesControl::WindowStatesControl(unsigned flags, QWidget *parent)
: QGroupBox(tr("States"), parent) : QGroupBox(tr("States"), parent)
, visibleCheckBox(0) , visibleCheckBox(0)
, activeCheckBox(0)
, minimizeCheckBox(new QCheckBox(tr("Minimized"))) , minimizeCheckBox(new QCheckBox(tr("Minimized")))
, stateControl(new WindowStateControl(0)) , stateControl(new WindowStateControl(0))
{ {
@ -231,6 +239,11 @@ WindowStatesControl::WindowStatesControl(unsigned flags, QWidget *parent)
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()));
layout->addWidget(activeCheckBox);
}
layout->addWidget(minimizeCheckBox); layout->addWidget(minimizeCheckBox);
layout->addWidget(stateControl); layout->addWidget(stateControl);
connect(stateControl, SIGNAL(changed()), this, SIGNAL(changed())); connect(stateControl, SIGNAL(changed()), this, SIGNAL(changed()));
@ -242,6 +255,8 @@ Qt::WindowStates WindowStatesControl::states() const
Qt::WindowStates s = stateControl->state(); Qt::WindowStates s = stateControl->state();
if (minimizeCheckBox->isChecked()) if (minimizeCheckBox->isChecked())
s |= Qt::WindowMinimized; s |= Qt::WindowMinimized;
if (activeValue())
s |= Qt::WindowActive;
return s; return s;
} }
@ -252,6 +267,7 @@ void WindowStatesControl::setStates(Qt::WindowStates s)
minimizeCheckBox->blockSignals(false); minimizeCheckBox->blockSignals(false);
s &= ~Qt::WindowMinimized; s &= ~Qt::WindowMinimized;
stateControl->setState(Qt::WindowState(int(s))); stateControl->setState(Qt::WindowState(int(s)));
setActiveValue(s & Qt::WindowActive);
} }
bool WindowStatesControl::visibleValue() const bool WindowStatesControl::visibleValue() const
@ -268,6 +284,20 @@ void WindowStatesControl::setVisibleValue(bool v)
} }
} }
bool WindowStatesControl::activeValue() const
{
return activeCheckBox && activeCheckBox->isChecked();
}
void WindowStatesControl::setActiveValue(bool v)
{
if (activeCheckBox) {
activeCheckBox->blockSignals(true);
activeCheckBox->setChecked(v);
activeCheckBox->blockSignals(false);
}
}
TypeControl::TypeControl(QWidget *parent) TypeControl::TypeControl(QWidget *parent)
: QGroupBox(tr("Type"), parent) : QGroupBox(tr("Type"), parent)
, group(new QButtonGroup) , group(new QButtonGroup)

View File

@ -121,7 +121,8 @@ class WindowStatesControl : public QGroupBox
Q_OBJECT Q_OBJECT
public: public:
enum Flags { enum Flags {
WantVisibleCheckBox = 0x1 WantVisibleCheckBox = 0x1,
WantActiveCheckBox = 0x2
}; };
explicit WindowStatesControl(unsigned flags, QWidget *parent= 0); explicit WindowStatesControl(unsigned flags, QWidget *parent= 0);
@ -131,12 +132,15 @@ public:
bool visibleValue() const; bool visibleValue() const;
void setVisibleValue(bool); void setVisibleValue(bool);
bool activeValue() const;
void setActiveValue(bool v);
signals: signals:
void changed(); void changed();
private: private:
QCheckBox *visibleCheckBox; QCheckBox *visibleCheckBox;
QCheckBox *activeCheckBox;
QCheckBox *minimizeCheckBox; QCheckBox *minimizeCheckBox;
WindowStateControl *stateControl; WindowStateControl *stateControl;
}; };

View File

@ -39,9 +39,9 @@
** **
****************************************************************************/ ****************************************************************************/
#include <QtWidgets/QTextEdit> #include <QTextEdit>
#include <QtWidgets/QPushButton> #include <QPushButton>
#include <QtWidgets/QVBoxLayout> #include <QVBoxLayout>
#include "previewwindow.h" #include "previewwindow.h"

View File

@ -42,8 +42,7 @@
#ifndef PREVIEWWINDOW_H #ifndef PREVIEWWINDOW_H
#define PREVIEWWINDOW_H #define PREVIEWWINDOW_H
#include <QtWidgets/QWidget> #include <QDialog>
#include <QtWidgets/QDialog>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QPushButton; class QPushButton;

View File

@ -1,5 +1,3 @@
QT += widgets
HEADERS = controllerwindow.h \ HEADERS = controllerwindow.h \
previewwindow.h \ previewwindow.h \
controls.h controls.h
@ -9,4 +7,4 @@ SOURCES = controllerwindow.cpp \
main.cpp \ main.cpp \
controls.cpp controls.cpp
QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

View File

@ -269,7 +269,7 @@ private:
WidgetWindowControl::WidgetWindowControl(QWidget *w ) WidgetWindowControl::WidgetWindowControl(QWidget *w )
: BaseWindowControl(w) : BaseWindowControl(w)
, m_statesControl(new WindowStatesControl(WindowStatesControl::WantVisibleCheckBox)) , m_statesControl(new WindowStatesControl(WindowStatesControl::WantVisibleCheckBox | WindowStatesControl::WantActiveCheckBox))
{ {
setTitle(w->windowTitle()); setTitle(w->windowTitle());
m_layout->addWidget(m_statesControl, 2, 0); m_layout->addWidget(m_statesControl, 2, 0);
@ -435,6 +435,11 @@ ControllerWidget::ControllerWidget(QWidget *parent)
x += 800; x += 800;
m_testWidget->setWindowTitle(tr("TestWidget")); m_testWidget->setWindowTitle(tr("TestWidget"));
if (args.contains(QLatin1String("-layout"))) {
QVBoxLayout *layout = new QVBoxLayout(m_testWidget.data());
QLabel *label = new QLabel("Hallo");
layout->addWidget(label);
}
m_testWidget->move(x, y); m_testWidget->move(x, y);
m_testWidget->resize(200, 200); m_testWidget->resize(200, 200);
m_testWidget->show(); m_testWidget->show();