23#include "Qt5Qt6Compat_p.h"
25#include "kddockwidgets/core/MainWindow.h"
26#include "kddockwidgets/core/FloatingWindow.h"
27#include "kddockwidgets/core/Layout.h"
37#include <QApplication>
41#include <QAbstractNativeEventFilter>
58 DebugAppEventFilter() =
default;
59 ~DebugAppEventFilter()
override;
60#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
67 if (eventType !=
"windows_generic_MSG")
69 auto msg =
static_cast<MSG *
>(message);
71 if (msg->message == WM_NCCALCSIZE)
72 qDebug() <<
"Got WM_NCCALCSIZE!" << message;
82DebugAppEventFilter::~DebugAppEventFilter()
88 , m_objectViewer(this)
95 button->setText(QStringLiteral(
"Dump Debug"));
105 button->setText(QStringLiteral(
"Toggle float"));
106 hlay->addWidget(button);
107 hlay->addWidget(spin);
111 const int index = spin->value();
112 if (index >= docks.size()) {
114 QStringLiteral(
"Max index is %1").arg(docks.size() - 1));
116 auto dw = docks.at(index);
117 dw->setFloating(!dw->isFloating());
125 lineedit->setPlaceholderText(
tr(
"DockWidget unique name"));
126 button->setText(QStringLiteral(
"Show"));
127 hlay->addWidget(button);
128 hlay->addWidget(lineedit);
136 nullptr, QStringLiteral(
"Could not find"),
137 QStringLiteral(
"Could not find DockWidget with name %1").arg(lineedit->text()));
142 button->setText(QStringLiteral(
"Float all visible docks"));
146 for (
auto dw : docks) {
147 if (dw->isVisible() && !dw->isFloating()) {
148 dw->setFloating(
true);
154 button->setText(QStringLiteral(
"Show All DockWidgets"));
159 for (
auto dw : docks) {
166 button->setText(QStringLiteral(
"Save layout"));
171 ? QStringLiteral(
"Saved!")
172 : QStringLiteral(
"Error!");
177 button->setText(QStringLiteral(
"Restore layout"));
182 ? QStringLiteral(
"Restored!")
183 : QStringLiteral(
"Error!");
188 button->setText(QStringLiteral(
"Pick Widget"));
195 m_isPickingWidget = &loop;
199 m_isPickingWidget =
nullptr;
200 qGuiApp->restoreOverrideCursor();
204 button->setText(QStringLiteral(
"check sanity"));
209 mainWindow->layout()->checkSanity();
213 for (
auto floatingWindow : floatingWindows) {
214 floatingWindow->layout()->checkSanity();
219 button->setText(QStringLiteral(
"Detach central widget"));
223 if (mainWindows.isEmpty())
225 auto mainwindow = mainWindows.at(0);
227 qobject_cast<QMainWindow *>(QtWidgets::MainWindow::asQWidget(mainwindow))
229 centralWidget->setParent(
nullptr,
Qt::Window);
230 if (!centralWidget->isVisible()) {
231 centralWidget->show();
236 button->setText(QStringLiteral(
"Repaint all widgets"));
239 const auto topLevelWidgets = qApp->topLevelWidgets();
240 for (
auto w : topLevelWidgets)
241 repaintWidgetRecursive(w);
245 button->setText(QStringLiteral(
"Raise #0 (after 3s timeout)"));
250 if (!docks.isEmpty())
251 docks.constFirst()->raise();
257 button->setText(QStringLiteral(
"Dump native windows"));
266void DebugWindow::dumpWindow(
QWidget *w)
269 HWND hwnd = HWND(w->
winId());
273 GetWindowRect(hwnd, &
rect);
274 GetClientRect(hwnd, &clientRect);
277 << QStringLiteral(
" ClientRect=%1,%2 %3x%4")
278 .arg(clientRect.left)
280 .arg(clientRect.right - clientRect.left + 1)
281 .arg(clientRect.bottom - clientRect.top + 1)
282 << QStringLiteral(
" WindowRect=%1,%2 %3x%4")
291 if (
auto childW = qobject_cast<QWidget *>(child)) {
298void DebugWindow::dumpWindows()
300 for (
QWidget *w : qApp->topLevelWidgets()) {
308void DebugWindow::repaintWidgetRecursive(
QWidget *w)
312 if (
auto childW = qobject_cast<QWidget *>(child)) {
313 repaintWidgetRecursive(childW);
318void DebugWindow::dumpDockWidgetInfo()
326 qDebug() << fw <<
"; affinities=" << fw->affinities();
327 fw->layout()->dumpLayout();
331 qDebug() << mw <<
"; affinities=" << mw->affinities();
332 mw->layout()->dumpLayout();
336 qDebug() << dw <<
"; affinities=";
342 if (!m_isPickingWidget)
345 QWidget *w = qApp->widgetAt(Qt5Qt6Compat::eventGlobalPos(
event));
346 qDebug() <<
"Widget at pos" << Qt5Qt6Compat::eventGlobalPos(
event) <<
"is" << w
350 if (m_isPickingWidget)
351 m_isPickingWidget->
quit();
Window to show debug information. Used for debugging only, for apps that don't support GammaRay.
Class to save and restore dockwidget layouts.
The MainWindow base-class. MainWindow and MainWindowBase are only split in two so we can share some c...
virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *result)=0
int exec(QEventLoop::ProcessEventsFlags flags)
QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
const QObjectList & children() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString tr(const char *sourceText, const char *disambiguation, int n)
QMainWindow sub-class to enable KDDockWidgets support.