19 #include "DebugWindow_p.h"
20 #include "DockRegistry_p.h"
21 #include "FloatingWindow_p.h"
23 #include "LayoutWidget_p.h"
25 #include "ObjectViewer_p.h"
26 #include "Qt5Qt6Compat_p.h"
28 #include <QVBoxLayout>
29 #include <QHBoxLayout>
30 #include <QPushButton>
33 #include <QMessageBox>
34 #include <QApplication>
35 #include <QMouseEvent>
37 #include <QFileDialog>
38 #include <QAbstractNativeEventFilter>
49 using namespace KDDockWidgets::Debug;
57 ~DebugAppEventFilter();
58 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
59 bool nativeEventFilter(
const QByteArray &eventType,
void *message, qintptr *)
override
61 bool nativeEventFilter(
const QByteArray &eventType,
void *message,
long *)
override
65 if (eventType !=
"windows_generic_MSG")
67 auto msg =
static_cast<MSG *
>(message);
69 if (msg->message == WM_NCCALCSIZE)
70 qDebug() <<
"Got WM_NCCALCSIZE!" << message;
80 DebugAppEventFilter::~DebugAppEventFilter()
84 DebugWindow::DebugWindow(
QWidget *parent)
86 , m_objectViewer(this)
90 layout->addWidget(&m_objectViewer);
93 button->setText(QStringLiteral(
"Dump Debug"));
94 layout->addWidget(button);
98 layout->addLayout(hlay);
103 button->setText(QStringLiteral(
"Toggle float"));
104 hlay->addWidget(button);
105 hlay->addWidget(spin);
108 auto docks = DockRegistry::self()->dockwidgets();
109 const int index = spin->value();
110 if (index >= docks.size()) {
112 QStringLiteral(
"Max index is %1").arg(docks.size() - 1));
114 auto dw = docks.at(index);
115 dw->setFloating(!dw->isFloating());
120 layout->addLayout(hlay);
123 lineedit->setPlaceholderText(tr(
"DockWidget unique name"));
124 button->setText(QStringLiteral(
"Show"));
125 hlay->addWidget(button);
126 hlay->addWidget(lineedit);
129 auto dw = DockRegistry::self()->dockByName(lineedit->text());
134 QStringLiteral(
"Could not find DockWidget with name %1").arg(lineedit->text()));
139 button->setText(QStringLiteral(
"Float all visible docks"));
140 layout->addWidget(button);
142 for (
auto dw : DockRegistry::self()->dockwidgets()) {
143 if (dw->isVisible() && !dw->isFloating()) {
144 dw->setFloating(true);
150 button->setText(QStringLiteral(
"Show All DockWidgets"));
151 layout->addWidget(button);
154 const auto docks = DockRegistry::self()->dockwidgets();
155 for (
auto dw : docks) {
162 button->setText(QStringLiteral(
"Save layout"));
163 layout->addWidget(button);
166 QString message = saver.
saveToFile(QStringLiteral(
"layout.json")) ? QStringLiteral(
"Saved!")
167 : QStringLiteral(
"Error!");
172 button->setText(QStringLiteral(
"Restore layout"));
173 layout->addWidget(button);
177 : QStringLiteral(
"Error!");
182 button->setText(QStringLiteral(
"Pick Widget"));
183 layout->addWidget(button);
189 m_isPickingWidget = &loop;
193 m_isPickingWidget =
nullptr;
194 qApp->restoreOverrideCursor();
198 button->setText(QStringLiteral(
"check sanity"));
199 layout->addWidget(button);
201 const auto mainWindows = DockRegistry::self()->mainwindows();
203 mainWindow->layoutWidget()->checkSanity();
206 const auto floatingWindows = DockRegistry::self()->floatingWindows();
207 for (FloatingWindow *floatingWindow : floatingWindows) {
208 floatingWindow->layoutWidget()->checkSanity();
213 button->setText(QStringLiteral(
"Detach central widget"));
214 layout->addWidget(button);
216 const auto mainWindows = DockRegistry::self()->mainwindows();
217 if (mainWindows.isEmpty())
219 auto mainwindow = mainWindows.at(0);
220 auto centralWidget = mainwindow->centralWidget();
221 centralWidget->setParent(
nullptr,
Qt::Window);
222 if (!centralWidget->isVisible()) {
223 centralWidget->show();
228 button->setText(QStringLiteral(
"Repaint all widgets"));
229 layout->addWidget(button);
231 const auto topLevelWidgets = qApp->topLevelWidgets();
232 for (
auto w : topLevelWidgets)
233 repaintWidgetRecursive(w);
237 button->setText(QStringLiteral(
"resize by 1x1"));
238 layout->addWidget(button);
240 const auto layouts = DockRegistry::self()->layouts();
241 for (
auto l : layouts) {
248 button->setText(QStringLiteral(
"Raise #0 (after 3s timeout)"));
249 layout->addWidget(button);
252 const auto docks = DockRegistry::self()->dockwidgets();
253 if (!docks.isEmpty())
254 docks.constFirst()->raise();
260 button->setText(QStringLiteral(
"Dump native windows"));
261 layout->addWidget(button);
269 void DebugWindow::dumpWindow(
QWidget *w)
272 HWND hwnd = HWND(w->
winId());
276 GetWindowRect(hwnd, &rect);
277 GetClientRect(hwnd, &clientRect);
280 << QStringLiteral(
" ClientRect=%1,%2 %3x%4").arg(clientRect.left).arg(clientRect.top).arg(clientRect.right - clientRect.left + 1).arg(clientRect.bottom - clientRect.top + 1)
281 << QStringLiteral(
" WindowRect=%1,%2 %3x%4").arg(rect.left).arg(rect.top).arg(rect.right - rect.left + 1).arg(rect.bottom - rect.top + 1)
287 if (
auto childW = qobject_cast<QWidget *>(child)) {
294 void DebugWindow::dumpWindows()
296 for (
QWidget *w : qApp->topLevelWidgets()) {
304 void DebugWindow::repaintWidgetRecursive(
QWidget *w)
308 if (
auto childW = qobject_cast<QWidget *>(child)) {
309 repaintWidgetRecursive(childW);
314 void DebugWindow::dumpDockWidgetInfo()
320 for (FloatingWindow *fw : floatingWindows) {
321 qDebug() << fw <<
"; affinities=" << fw->affinities();
322 fw->layoutWidget()->dumpLayout();
326 qDebug() << mw <<
"; affinities=" << mw->affinities();
327 mw->layoutWidget()->dumpLayout();
331 qDebug() << dw <<
"; affinities=";
335 void DebugWindow::mousePressEvent(
QMouseEvent *event)
337 if (!m_isPickingWidget)
340 QWidget *w = qApp->widgetAt(Qt5Qt6Compat::eventGlobalPos(event));
341 qDebug() <<
"Widget at pos" << Qt5Qt6Compat::eventGlobalPos(event) <<
"is"
346 if (m_isPickingWidget)
347 m_isPickingWidget->quit();