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(
"resize by 1x1"));
249 for (
auto l : layouts) {
250 auto tlw = l->view()->rootView();
251 tlw->resize(tlw->size() +
QSize(1, 1));
256 button->setText(QStringLiteral(
"Raise #0 (after 3s timeout)"));
261 if (!docks.isEmpty())
262 docks.constFirst()->raise();
268 button->setText(QStringLiteral(
"Dump native windows"));
277void DebugWindow::dumpWindow(
QWidget *w)
280 HWND hwnd = HWND(w->
winId());
284 GetWindowRect(hwnd, &
rect);
285 GetClientRect(hwnd, &clientRect);
288 << QStringLiteral(
" ClientRect=%1,%2 %3x%4")
289 .arg(clientRect.left)
291 .arg(clientRect.right - clientRect.left + 1)
292 .arg(clientRect.bottom - clientRect.top + 1)
293 << QStringLiteral(
" WindowRect=%1,%2 %3x%4")
302 if (
auto childW = qobject_cast<QWidget *>(child)) {
309void DebugWindow::dumpWindows()
311 for (
QWidget *w : qApp->topLevelWidgets()) {
319void DebugWindow::repaintWidgetRecursive(
QWidget *w)
323 if (
auto childW = qobject_cast<QWidget *>(child)) {
324 repaintWidgetRecursive(childW);
329void DebugWindow::dumpDockWidgetInfo()
337 qDebug() << fw <<
"; affinities=" << fw->affinities();
338 fw->layout()->dumpLayout();
342 qDebug() << mw <<
"; affinities=" << mw->affinities();
343 mw->layout()->dumpLayout();
347 qDebug() << dw <<
"; affinities=";
353 if (!m_isPickingWidget)
356 QWidget *w = qApp->widgetAt(Qt5Qt6Compat::eventGlobalPos(
event));
357 qDebug() <<
"Widget at pos" << Qt5Qt6Compat::eventGlobalPos(
event) <<
"is" << w
361 if (m_isPickingWidget)
362 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.