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"
34#include <QApplication>
38#include <QAbstractNativeEventFilter>
49using namespace KDDockWidgets::Debug;
57 ~DebugAppEventFilter();
58#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
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;
80DebugAppEventFilter::~DebugAppEventFilter()
84DebugWindow::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);
269void 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)
286 for (
QObject *child : w->children()) {
287 if (
auto childW = qobject_cast<QWidget *>(child)) {
294void DebugWindow::dumpWindows()
296 for (
QWidget *w : qApp->topLevelWidgets()) {
304void DebugWindow::repaintWidgetRecursive(
QWidget *w)
307 for (
QObject *child : w->children()) {
308 if (
auto childW = qobject_cast<QWidget *>(child)) {
309 repaintWidgetRecursive(childW);
314void 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=";
335void 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();
Class to save and restore dockwidget layouts.
QMainWindow sub-class to enable KDDockWidgets support.
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)