Extend manual test windowflags
Change the main window to contain a QTabWidget and add a log widget logging relevant events on the top level widgets for testing changes. In the preview window, add new window flags of Qt 5 and output geometry, margins and window state in addition. Change-Id: Icec366223b6c163d58a69034687f3d9323a91533 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
parent
f817a995b2
commit
cb0d8ffdd9
@ -26,20 +26,33 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
#include <QCheckBox>
|
||||
#include <QGroupBox>
|
||||
#include <QApplication>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include "controllerwindow.h"
|
||||
#include "controls.h"
|
||||
|
||||
//! [0]
|
||||
ControllerWindow::ControllerWindow() : previewWidget(0)
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QCheckBox>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QMainWindow>
|
||||
#include <QMenu>
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
#include <QTabWidget>
|
||||
|
||||
#include <QMoveEvent>
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
# include <QWindow>
|
||||
# include <qlogging.h>
|
||||
# include <QLibraryInfo>
|
||||
#endif
|
||||
#include <QDebug>
|
||||
|
||||
ControllerWidget::ControllerWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, previewWidget(0)
|
||||
{
|
||||
parentWindow = new QMainWindow;
|
||||
parentWindow->setWindowTitle(tr("Preview parent window"));
|
||||
@ -53,18 +66,6 @@ ControllerWindow::ControllerWindow() : previewWidget(0)
|
||||
|
||||
createTypeGroupBox();
|
||||
|
||||
quitButton = new QPushButton(tr("&Quit"));
|
||||
connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
|
||||
|
||||
QHBoxLayout *bottomLayout = new QHBoxLayout;
|
||||
bottomLayout->addStretch();
|
||||
|
||||
QPushButton *updateControlsButton = new QPushButton(tr("&Update"));
|
||||
connect(updateControlsButton, SIGNAL(clicked()), this, SLOT(updateStateControl()));
|
||||
|
||||
bottomLayout->addWidget(updateControlsButton);
|
||||
bottomLayout->addWidget(quitButton);
|
||||
|
||||
hintsControl = new HintControl;
|
||||
hintsControl->setHints(previewWindow->windowFlags());
|
||||
connect(hintsControl, SIGNAL(changed(Qt::WindowFlags)), this, SLOT(updatePreview()));
|
||||
@ -78,39 +79,30 @@ ControllerWindow::ControllerWindow() : previewWidget(0)
|
||||
typeControl->setType(previewWindow->windowFlags());
|
||||
connect(typeControl, SIGNAL(changed(Qt::WindowFlags)), this, SLOT(updatePreview()));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
||||
mainLayout->addWidget(widgetTypeGroupBox);
|
||||
mainLayout->addWidget(additionalOptionsGroupBox);
|
||||
mainLayout->addWidget(typeControl);
|
||||
mainLayout->addWidget(hintsControl);
|
||||
mainLayout->addWidget(statesControl);
|
||||
mainLayout->addLayout(bottomLayout);
|
||||
setLayout(mainLayout);
|
||||
|
||||
setWindowTitle(tr("Window Flags (Qt version %1, %2)")
|
||||
.arg(QLatin1String(qVersion()),
|
||||
#if QT_VERSION >= 0x050000
|
||||
qApp->platformName()));
|
||||
#else
|
||||
QLatin1String("<unknown>")));
|
||||
#endif
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
bool ControllerWindow::eventFilter(QObject *, QEvent *e)
|
||||
bool ControllerWidget::eventFilter(QObject *, QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::WindowStateChange)
|
||||
updateStateControl();
|
||||
return false;
|
||||
}
|
||||
|
||||
void ControllerWindow::updateStateControl()
|
||||
void ControllerWidget::updateStateControl()
|
||||
{
|
||||
if (previewWidget)
|
||||
statesControl->setStates(previewWidget->windowState());
|
||||
}
|
||||
|
||||
void ControllerWindow::updatePreview()
|
||||
void ControllerWidget::updatePreview()
|
||||
{
|
||||
const Qt::WindowFlags flags = typeControl->type() | hintsControl->hints();
|
||||
|
||||
@ -154,7 +146,7 @@ void ControllerWindow::updatePreview()
|
||||
previewWidget->setVisible(statesControl->visibleValue());
|
||||
}
|
||||
|
||||
void ControllerWindow::createTypeGroupBox()
|
||||
void ControllerWidget::createTypeGroupBox()
|
||||
{
|
||||
widgetTypeGroupBox = new QGroupBox(tr("Widget Type"));
|
||||
previewWidgetButton = createRadioButton(tr("QWidget"));
|
||||
@ -173,24 +165,181 @@ void ControllerWindow::createTypeGroupBox()
|
||||
l->addWidget(fixedSizeWindowCheckBox);
|
||||
additionalOptionsGroupBox->setLayout(l);
|
||||
}
|
||||
//! [5]
|
||||
|
||||
//! [6]
|
||||
|
||||
//! [7]
|
||||
QCheckBox *ControllerWindow::createCheckBox(const QString &text)
|
||||
QCheckBox *ControllerWidget::createCheckBox(const QString &text)
|
||||
{
|
||||
QCheckBox *checkBox = new QCheckBox(text);
|
||||
connect(checkBox, SIGNAL(clicked()), this, SLOT(updatePreview()));
|
||||
return checkBox;
|
||||
}
|
||||
//! [7]
|
||||
|
||||
//! [8]
|
||||
QRadioButton *ControllerWindow::createRadioButton(const QString &text)
|
||||
QRadioButton *ControllerWidget::createRadioButton(const QString &text)
|
||||
{
|
||||
QRadioButton *button = new QRadioButton(text);
|
||||
connect(button, SIGNAL(clicked()), this, SLOT(updatePreview()));
|
||||
return button;
|
||||
}
|
||||
//! [8]
|
||||
|
||||
static bool isTopLevel(const QObject *o)
|
||||
{
|
||||
if (o->isWidgetType())
|
||||
return static_cast<const QWidget *>(o)->isWindow();
|
||||
#if QT_VERSION >= 0x050000
|
||||
if (o->isWindowType())
|
||||
return static_cast<const QWindow *>(o)->isTopLevel();
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
static Qt::WindowState windowState(const QObject *o)
|
||||
{
|
||||
if (o->isWidgetType()) {
|
||||
Qt::WindowStates states = static_cast<const QWidget *>(o)->windowState();
|
||||
states &= ~Qt::WindowActive;
|
||||
return static_cast<Qt::WindowState>(int(states));
|
||||
}
|
||||
#if QT_VERSION >= 0x050000
|
||||
if (o->isWindowType())
|
||||
return static_cast<const QWindow *>(o)->windowState();
|
||||
#endif
|
||||
return Qt::WindowNoState;
|
||||
}
|
||||
|
||||
class EventFilter : public QObject {
|
||||
public:
|
||||
explicit EventFilter(QObject *parent = 0) : QObject(parent) {}
|
||||
|
||||
bool eventFilter(QObject *o, QEvent *e)
|
||||
{
|
||||
switch (e->type()) {
|
||||
case QEvent::Move:
|
||||
case QEvent::Resize:
|
||||
case QEvent::WindowStateChange:
|
||||
case QEvent::ApplicationActivate:
|
||||
case QEvent::ApplicationDeactivate:
|
||||
#if QT_VERSION >= 0x050000
|
||||
case QEvent::ApplicationStateChange:
|
||||
#endif
|
||||
if (isTopLevel(o))
|
||||
formatEvent(o, e);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QObject::eventFilter(o ,e);
|
||||
}
|
||||
|
||||
private:
|
||||
void formatEvent(QObject *o, QEvent *e)
|
||||
{
|
||||
static int n = 0;
|
||||
QDebug debug = qDebug().nospace();
|
||||
#if QT_VERSION >= 0x050000
|
||||
debug.noquote();
|
||||
#endif
|
||||
debug << '#' << n++ << ' ' << o->metaObject()->className();
|
||||
const QString name = o->objectName();
|
||||
if (!name.isEmpty())
|
||||
debug << "/\"" << name << '"';
|
||||
debug << ' ' << e;
|
||||
if (e->type() == QEvent::WindowStateChange)
|
||||
debug << ' ' << windowState(o);
|
||||
}
|
||||
};
|
||||
|
||||
LogWidget *LogWidget::m_instance = 0;
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
static void qt5MessageHandler(QtMsgType, const QMessageLogContext &, const QString &text)
|
||||
{
|
||||
if (LogWidget *lw = LogWidget::instance())
|
||||
lw->appendText(text);
|
||||
}
|
||||
#else // Qt 5
|
||||
static void qt4MessageHandler(QtMsgType, const char *text)
|
||||
{
|
||||
if (LogWidget *lw = LogWidget::instance())
|
||||
lw->appendText(QString::fromLocal8Bit(text));
|
||||
}
|
||||
#endif // Qt 4
|
||||
|
||||
LogWidget::LogWidget(QWidget *parent)
|
||||
: QPlainTextEdit(parent)
|
||||
{
|
||||
LogWidget::m_instance = this;
|
||||
setReadOnly(true);
|
||||
appendText(startupMessage());
|
||||
}
|
||||
|
||||
LogWidget::~LogWidget()
|
||||
{
|
||||
LogWidget::m_instance = 0;
|
||||
}
|
||||
|
||||
void LogWidget::install()
|
||||
{
|
||||
#if QT_VERSION >= 0x050000
|
||||
qInstallMessageHandler(qt5MessageHandler);
|
||||
#else
|
||||
qInstallMsgHandler(qt4MessageHandler);
|
||||
#endif
|
||||
}
|
||||
|
||||
QString LogWidget::startupMessage()
|
||||
{
|
||||
QString result;
|
||||
#if QT_VERSION >= 0x050300
|
||||
result += QLatin1String(QLibraryInfo::build());
|
||||
#else
|
||||
result += QLatin1String("Qt ") + QLatin1String(QT_VERSION_STR);
|
||||
#endif
|
||||
#if QT_VERSION >= 0x050000
|
||||
result += QLatin1Char(' ');
|
||||
result += QGuiApplication::platformName();
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
void LogWidget::appendText(const QString &message)
|
||||
{
|
||||
appendPlainText(message);
|
||||
ensureCursorVisible();
|
||||
}
|
||||
|
||||
ControllerWindow::ControllerWindow()
|
||||
{
|
||||
setWindowTitle(tr("Window Flags (Qt version %1, %2)")
|
||||
.arg(QLatin1String(qVersion()),
|
||||
#if QT_VERSION >= 0x050000
|
||||
qApp->platformName()));
|
||||
#else
|
||||
QLatin1String("<unknown>")));
|
||||
#endif
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
QTabWidget *tabWidget = new QTabWidget(this);
|
||||
ControllerWidget *controllerWidget = new ControllerWidget(tabWidget);
|
||||
tabWidget->addTab(controllerWidget, tr("Control"));
|
||||
LogWidget *logWidget = new LogWidget(tabWidget);
|
||||
tabWidget->addTab(logWidget, tr("Event log"));
|
||||
layout->addWidget(tabWidget);
|
||||
|
||||
QHBoxLayout *bottomLayout = new QHBoxLayout;
|
||||
layout->addLayout(bottomLayout);
|
||||
bottomLayout->addStretch();
|
||||
QPushButton *updateControlsButton = new QPushButton(tr("&Update"));
|
||||
connect(updateControlsButton, SIGNAL(clicked()), controllerWidget, SLOT(updateStateControl()));
|
||||
bottomLayout->addWidget(updateControlsButton);
|
||||
QPushButton *clearLogButton = new QPushButton(tr("Clear &Log"));
|
||||
connect(clearLogButton, SIGNAL(clicked()), logWidget, SLOT(clear()));
|
||||
bottomLayout->addWidget(clearLogButton);
|
||||
QPushButton *quitButton = new QPushButton(tr("&Quit"));
|
||||
connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
|
||||
quitButton->setShortcut(Qt::CTRL + Qt::Key_Q);
|
||||
bottomLayout->addWidget(quitButton);
|
||||
}
|
||||
|
||||
void ControllerWindow::registerEventFilter()
|
||||
{
|
||||
qApp->installEventFilter(new EventFilter(qApp));
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
#ifndef CONTROLLERWINDOW_H
|
||||
#define CONTROLLERWINDOW_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPlainTextEdit>
|
||||
|
||||
#include "previewwindow.h"
|
||||
|
||||
@ -46,13 +46,12 @@ class HintControl;
|
||||
class WindowStatesControl;
|
||||
class TypeControl;
|
||||
|
||||
//! [0]
|
||||
class ControllerWindow : public QWidget
|
||||
class ControllerWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ControllerWindow();
|
||||
explicit ControllerWidget(QWidget *parent = 0);
|
||||
|
||||
virtual bool eventFilter(QObject *o, QEvent *e);
|
||||
|
||||
@ -75,13 +74,37 @@ private:
|
||||
HintControl *hintsControl;
|
||||
WindowStatesControl *statesControl;
|
||||
|
||||
QPushButton *quitButton;
|
||||
|
||||
QRadioButton *previewWidgetButton;
|
||||
QRadioButton *previewDialogButton;
|
||||
QCheckBox *modalWindowCheckBox;
|
||||
QCheckBox *fixedSizeWindowCheckBox;
|
||||
};
|
||||
//! [0]
|
||||
|
||||
#endif
|
||||
class LogWidget : public QPlainTextEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LogWidget(QWidget *parent = 0);
|
||||
~LogWidget();
|
||||
|
||||
static LogWidget *instance() { return m_instance; }
|
||||
static void install();
|
||||
|
||||
public slots:
|
||||
void appendText(const QString &);
|
||||
|
||||
private:
|
||||
static QString startupMessage();
|
||||
|
||||
static LogWidget *m_instance;
|
||||
};
|
||||
|
||||
class ControllerWindow : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ControllerWindow();
|
||||
|
||||
void registerEventFilter();
|
||||
};
|
||||
|
||||
#endif // CONTROLLERWINDOW_H
|
||||
|
@ -27,13 +27,21 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QStringList>
|
||||
|
||||
#include "controllerwindow.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
QStringList arguments = QCoreApplication::arguments();
|
||||
arguments.pop_front();
|
||||
|
||||
ControllerWindow controller;
|
||||
if (!arguments.contains(QLatin1String("-l")))
|
||||
LogWidget::install();
|
||||
if (!arguments.contains(QLatin1String("-e")))
|
||||
controller.registerEventFilter();
|
||||
controller.show();
|
||||
return app.exec();
|
||||
}
|
||||
|
@ -26,136 +26,235 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QTextEdit>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QPushButton>
|
||||
#include <QGridLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QTextStream>
|
||||
#include <QTimer>
|
||||
|
||||
#include "previewwindow.h"
|
||||
|
||||
static QString windowFlagsToString(Qt::WindowFlags flags)
|
||||
static void formatWindowFlags(QTextStream &str, Qt::WindowFlags flags)
|
||||
{
|
||||
QString text;
|
||||
|
||||
Qt::WindowFlags type = (flags & Qt::WindowType_Mask);
|
||||
if (type == Qt::Window) {
|
||||
text = "Qt::Window";
|
||||
} else if (type == Qt::Dialog) {
|
||||
text = "Qt::Dialog";
|
||||
} else if (type == Qt::Sheet) {
|
||||
text = "Qt::Sheet";
|
||||
} else if (type == Qt::Drawer) {
|
||||
text = "Qt::Drawer";
|
||||
} else if (type == Qt::Popup) {
|
||||
text = "Qt::Popup";
|
||||
} else if (type == Qt::Tool) {
|
||||
text = "Qt::Tool";
|
||||
} else if (type == Qt::ToolTip) {
|
||||
text = "Qt::ToolTip";
|
||||
} else if (type == Qt::SplashScreen) {
|
||||
text = "Qt::SplashScreen";
|
||||
str << "Window flags: " << hex << showbase << unsigned(flags) << noshowbase << dec << ' ';
|
||||
switch (flags & Qt::WindowType_Mask) {
|
||||
case Qt::Window:
|
||||
str << "Qt::Window";
|
||||
break;
|
||||
case Qt::Dialog:
|
||||
str << "Qt::Dialog";
|
||||
break;
|
||||
case Qt::Sheet:
|
||||
str << "Qt::Sheet";
|
||||
break;
|
||||
case Qt::Drawer:
|
||||
str << "Qt::Drawer";
|
||||
break;
|
||||
case Qt::Popup:
|
||||
str << "Qt::Popup";
|
||||
break;
|
||||
case Qt::Tool:
|
||||
str << "Qt::Tool";
|
||||
break;
|
||||
case Qt::ToolTip:
|
||||
str << "Qt::ToolTip";
|
||||
break;
|
||||
case Qt::SplashScreen:
|
||||
str << "Qt::SplashScreen";
|
||||
break;
|
||||
}
|
||||
|
||||
if (flags & Qt::MSWindowsFixedSizeDialogHint)
|
||||
text += "\n| Qt::MSWindowsFixedSizeDialogHint";
|
||||
str << "\n| Qt::MSWindowsFixedSizeDialogHint";
|
||||
#if QT_VERSION >= 0x050000
|
||||
if (flags & Qt::BypassWindowManagerHint)
|
||||
str << "\n| Qt::BypassWindowManagerHint";
|
||||
#else
|
||||
if (flags & Qt::X11BypassWindowManagerHint)
|
||||
text += "\n| Qt::X11BypassWindowManagerHint";
|
||||
str << "\n| Qt::X11BypassWindowManagerHint";
|
||||
#endif
|
||||
if (flags & Qt::FramelessWindowHint)
|
||||
text += "\n| Qt::FramelessWindowHint";
|
||||
str << "\n| Qt::FramelessWindowHint";
|
||||
if (flags & Qt::WindowTitleHint)
|
||||
text += "\n| Qt::WindowTitleHint";
|
||||
str << "\n| Qt::WindowTitleHint";
|
||||
if (flags & Qt::WindowSystemMenuHint)
|
||||
text += "\n| Qt::WindowSystemMenuHint";
|
||||
str << "\n| Qt::WindowSystemMenuHint";
|
||||
if (flags & Qt::WindowMinimizeButtonHint)
|
||||
text += "\n| Qt::WindowMinimizeButtonHint";
|
||||
str << "\n| Qt::WindowMinimizeButtonHint";
|
||||
if (flags & Qt::WindowMaximizeButtonHint)
|
||||
text += "\n| Qt::WindowMaximizeButtonHint";
|
||||
str << "\n| Qt::WindowMaximizeButtonHint";
|
||||
if (flags & Qt::WindowCloseButtonHint)
|
||||
text += "\n| Qt::WindowCloseButtonHint";
|
||||
str << "\n| Qt::WindowCloseButtonHint";
|
||||
if (flags & Qt::WindowContextHelpButtonHint)
|
||||
text += "\n| Qt::WindowContextHelpButtonHint";
|
||||
str << "\n| Qt::WindowContextHelpButtonHint";
|
||||
if (flags & Qt::WindowShadeButtonHint)
|
||||
text += "\n| Qt::WindowShadeButtonHint";
|
||||
str << "\n| Qt::WindowShadeButtonHint";
|
||||
if (flags & Qt::WindowStaysOnTopHint)
|
||||
text += "\n| Qt::WindowStaysOnTopHint";
|
||||
str << "\n| Qt::WindowStaysOnTopHint";
|
||||
if (flags & Qt::CustomizeWindowHint)
|
||||
text += "\n| Qt::CustomizeWindowHint";
|
||||
return text;
|
||||
str << "\n| Qt::CustomizeWindowHint";
|
||||
if (flags & Qt::WindowStaysOnBottomHint)
|
||||
str << "\n| Qt::WindowStaysOnBottomHint";
|
||||
#if QT_VERSION >= 0x050000
|
||||
if (flags & Qt::WindowFullscreenButtonHint)
|
||||
str << "\n| Qt::WindowFullscreenButtonHint";
|
||||
if (flags & Qt::WindowTransparentForInput)
|
||||
str << "\n| Qt::WindowTransparentForInput";
|
||||
if (flags & Qt::WindowOverridesSystemGestures)
|
||||
str << "\n| Qt::WindowOverridesSystemGestures";
|
||||
if (flags & Qt::WindowDoesNotAcceptFocus)
|
||||
str << "\n| Qt::WindowDoesNotAcceptFocus";
|
||||
if (flags & Qt::MaximizeUsingFullscreenGeometryHint)
|
||||
str << "\n| Qt::MaximizeUsingFullscreenGeometryHint";
|
||||
if (flags & Qt::NoDropShadowWindowHint)
|
||||
str << "\n| Qt::NoDropShadowWindowHint";
|
||||
#endif // Qt 5
|
||||
}
|
||||
|
||||
static void formatWindowStates(QTextStream &str, Qt::WindowStates states)
|
||||
{
|
||||
str << "Window states: " << hex << showbase << unsigned(states) << noshowbase << dec << ' ';
|
||||
if (states & Qt::WindowActive) {
|
||||
str << "Qt::WindowActive ";
|
||||
states &= ~Qt::WindowActive;
|
||||
}
|
||||
switch (states) {
|
||||
case Qt::WindowNoState:
|
||||
str << "Qt::WindowNoState";
|
||||
break;
|
||||
case Qt::WindowMinimized:
|
||||
str << "Qt::WindowMinimized";
|
||||
break;
|
||||
case Qt::WindowMaximized:
|
||||
str << "Qt::WindowMaximized";
|
||||
break;
|
||||
case Qt::WindowFullScreen:
|
||||
str << "Qt::WindowFullScreen";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QTextStream &operator<<(QTextStream &str, const QRect &r)
|
||||
{
|
||||
str << r.width() << 'x' << r.height() << forcesign << r.x() << r.y() << noforcesign;
|
||||
return str;
|
||||
}
|
||||
|
||||
static QString formatWidgetInfo(const QWidget *w)
|
||||
{
|
||||
QString result;
|
||||
QTextStream str(&result);
|
||||
formatWindowFlags(str, w->windowFlags());
|
||||
str << '\n';
|
||||
formatWindowStates(str, w->windowState());
|
||||
const QRect frame = w->frameGeometry();
|
||||
const QRect geometry = w->geometry();
|
||||
str << "\n\nFrame: " << frame << "\nGeometry: " << geometry << "\nMargins: "
|
||||
<< (geometry.x() - frame.x()) << ", " << (geometry.top() - frame.top())
|
||||
<< ", " << (frame.right() - geometry.right()) << ", "
|
||||
<< (frame.bottom() - geometry.bottom());
|
||||
return result;
|
||||
}
|
||||
|
||||
static QPlainTextEdit *createControlPanel(QWidget *widget)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(widget);
|
||||
QPlainTextEdit *textEdit = new QPlainTextEdit;
|
||||
textEdit->setReadOnly(true);
|
||||
textEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
|
||||
layout->addWidget(textEdit);
|
||||
|
||||
QHBoxLayout *bottomLayout = new QHBoxLayout;
|
||||
layout ->addLayout(bottomLayout);
|
||||
QGridLayout *buttonLayout = new QGridLayout;
|
||||
bottomLayout->addStretch();
|
||||
bottomLayout->addLayout(buttonLayout);
|
||||
QPushButton *showNormalButton = new QPushButton(PreviewWindow::tr("Show normal"));
|
||||
QObject::connect(showNormalButton, SIGNAL(clicked()), widget, SLOT(showNormal()));
|
||||
buttonLayout->addWidget(showNormalButton, 0, 0);
|
||||
QPushButton *showMinimizedButton = new QPushButton(PreviewWindow::tr("Show minimized"));
|
||||
QObject::connect(showMinimizedButton, SIGNAL(clicked()), widget, SLOT(showMinimized()));
|
||||
buttonLayout->addWidget(showMinimizedButton, 0, 1);
|
||||
QPushButton *showMaximizedButton = new QPushButton(PreviewWindow::tr("Show maximized"));
|
||||
QObject::connect(showMaximizedButton, SIGNAL(clicked()), widget, SLOT(showMaximized()));
|
||||
buttonLayout->addWidget(showMaximizedButton, 0, 2);
|
||||
QPushButton *showFullScreenButton = new QPushButton(PreviewWindow::tr("Show fullscreen"));
|
||||
QObject::connect(showFullScreenButton, SIGNAL(clicked()), widget, SLOT(showFullScreen()));
|
||||
buttonLayout->addWidget(showFullScreenButton, 0, 3);
|
||||
|
||||
QPushButton *updateInfoButton = new QPushButton(PreviewWindow::tr("&Update Info"));
|
||||
QObject::connect(updateInfoButton, SIGNAL(clicked()), widget, SLOT(updateInfo()));
|
||||
buttonLayout->addWidget(updateInfoButton, 1, 0);
|
||||
QPushButton *closeButton = new QPushButton(PreviewWindow::tr("&Close"));
|
||||
QObject::connect(closeButton, SIGNAL(clicked()), widget, SLOT(close()));
|
||||
buttonLayout->addWidget(closeButton, 1, 3);
|
||||
|
||||
return textEdit;
|
||||
}
|
||||
|
||||
PreviewWindow::PreviewWindow(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
textEdit = new QTextEdit;
|
||||
textEdit->setReadOnly(true);
|
||||
textEdit->setLineWrapMode(QTextEdit::NoWrap);
|
||||
textEdit = createControlPanel(this);
|
||||
setWindowTitle(tr("Preview <QWidget> Qt %1").arg(QLatin1String(QT_VERSION_STR)));
|
||||
}
|
||||
|
||||
closeButton = new QPushButton(tr("&Close"));
|
||||
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
|
||||
void PreviewWindow::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
QWidget::resizeEvent(e);
|
||||
updateInfo();
|
||||
}
|
||||
|
||||
showNormalButton = new QPushButton(tr("Show normal"));
|
||||
connect(showNormalButton, SIGNAL(clicked()), this, SLOT(showNormal()));
|
||||
showMinimizedButton = new QPushButton(tr("Show minimized"));
|
||||
connect(showMinimizedButton, SIGNAL(clicked()), this, SLOT(showMinimized()));
|
||||
showMaximizedButton = new QPushButton(tr("Show maximized"));
|
||||
connect(showMaximizedButton, SIGNAL(clicked()), this, SLOT(showMaximized()));
|
||||
showFullScreenButton = new QPushButton(tr("Show fullscreen"));
|
||||
connect(showFullScreenButton, SIGNAL(clicked()), this, SLOT(showFullScreen()));
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
layout->addWidget(textEdit);
|
||||
layout->addWidget(showNormalButton);
|
||||
layout->addWidget(showMinimizedButton);
|
||||
layout->addWidget(showMaximizedButton);
|
||||
layout->addWidget(showFullScreenButton);
|
||||
layout->addWidget(closeButton);
|
||||
setLayout(layout);
|
||||
|
||||
setWindowTitle(tr("Preview <QWidget>"));
|
||||
void PreviewWindow::moveEvent(QMoveEvent *e)
|
||||
{
|
||||
QWidget::moveEvent(e);
|
||||
updateInfo();
|
||||
}
|
||||
|
||||
void PreviewWindow::setWindowFlags(Qt::WindowFlags flags)
|
||||
{
|
||||
if (flags == windowFlags())
|
||||
return;
|
||||
QWidget::setWindowFlags(flags);
|
||||
QTimer::singleShot(0, this, SLOT(updateInfo()));
|
||||
}
|
||||
|
||||
QString text = windowFlagsToString(flags);
|
||||
textEdit->setPlainText(text);
|
||||
void PreviewWindow::updateInfo()
|
||||
{
|
||||
textEdit->setPlainText(formatWidgetInfo(this));
|
||||
}
|
||||
|
||||
PreviewDialog::PreviewDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
textEdit = new QTextEdit;
|
||||
textEdit->setReadOnly(true);
|
||||
textEdit->setLineWrapMode(QTextEdit::NoWrap);
|
||||
textEdit = createControlPanel(this);
|
||||
setWindowTitle(tr("Preview <QDialog> Qt %1").arg(QLatin1String(QT_VERSION_STR)));
|
||||
}
|
||||
|
||||
closeButton = new QPushButton(tr("&Close"));
|
||||
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
|
||||
void PreviewDialog::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
QDialog::resizeEvent(e);
|
||||
updateInfo();
|
||||
}
|
||||
|
||||
showNormalButton = new QPushButton(tr("Show normal"));
|
||||
connect(showNormalButton, SIGNAL(clicked()), this, SLOT(showNormal()));
|
||||
showMinimizedButton = new QPushButton(tr("Show minimized"));
|
||||
connect(showMinimizedButton, SIGNAL(clicked()), this, SLOT(showMinimized()));
|
||||
showMaximizedButton = new QPushButton(tr("Show maximized"));
|
||||
connect(showMaximizedButton, SIGNAL(clicked()), this, SLOT(showMaximized()));
|
||||
showFullScreenButton = new QPushButton(tr("Show fullscreen"));
|
||||
connect(showFullScreenButton, SIGNAL(clicked()), this, SLOT(showFullScreen()));
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
layout->addWidget(textEdit);
|
||||
layout->addWidget(showNormalButton);
|
||||
layout->addWidget(showMinimizedButton);
|
||||
layout->addWidget(showMaximizedButton);
|
||||
layout->addWidget(showFullScreenButton);
|
||||
layout->addWidget(closeButton);
|
||||
setLayout(layout);
|
||||
|
||||
setWindowTitle(tr("Preview <QDialog>"));
|
||||
void PreviewDialog::moveEvent(QMoveEvent *e)
|
||||
{
|
||||
QDialog::moveEvent(e);
|
||||
updateInfo();
|
||||
}
|
||||
|
||||
void PreviewDialog::setWindowFlags(Qt::WindowFlags flags)
|
||||
{
|
||||
if (flags == windowFlags())
|
||||
return;
|
||||
QWidget::setWindowFlags(flags);
|
||||
|
||||
QString text = windowFlagsToString(flags);
|
||||
textEdit->setPlainText(text);
|
||||
QTimer::singleShot(0, this, SLOT(updateInfo()));
|
||||
}
|
||||
|
||||
void PreviewDialog::updateInfo()
|
||||
{
|
||||
textEdit->setPlainText(formatWidgetInfo(this));
|
||||
}
|
||||
|
@ -32,8 +32,7 @@
|
||||
#include <QDialog>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QPushButton;
|
||||
class QTextEdit;
|
||||
class QPlainTextEdit;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class PreviewWindow : public QWidget
|
||||
@ -45,13 +44,15 @@ public:
|
||||
|
||||
void setWindowFlags(Qt::WindowFlags flags);
|
||||
|
||||
public slots:
|
||||
void updateInfo();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *);
|
||||
void moveEvent(QMoveEvent *);
|
||||
|
||||
private:
|
||||
QTextEdit *textEdit;
|
||||
QPushButton *closeButton;
|
||||
QPushButton *showNormalButton;
|
||||
QPushButton *showMinimizedButton;
|
||||
QPushButton *showMaximizedButton;
|
||||
QPushButton *showFullScreenButton;
|
||||
QPlainTextEdit *textEdit;
|
||||
};
|
||||
|
||||
class PreviewDialog : public QDialog
|
||||
@ -63,13 +64,15 @@ public:
|
||||
|
||||
void setWindowFlags(Qt::WindowFlags flags);
|
||||
|
||||
public slots:
|
||||
void updateInfo();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *);
|
||||
void moveEvent(QMoveEvent *);
|
||||
|
||||
private:
|
||||
QTextEdit *textEdit;
|
||||
QPushButton *closeButton;
|
||||
QPushButton *showNormalButton;
|
||||
QPushButton *showMinimizedButton;
|
||||
QPushButton *showMaximizedButton;
|
||||
QPushButton *showFullScreenButton;
|
||||
QPlainTextEdit *textEdit;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user