Skip to content

Commit

Permalink
Diagnostic style for layout debugging
Browse files Browse the repository at this point in the history
Less use than I'd hoped it would be.
  • Loading branch information
martinburchell committed Jul 27, 2023
1 parent 691f160 commit eb18f0d
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tablet_qt/camcops.pro
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ SOURCES += \
lib/css.cpp \
lib/datetime.cpp \
lib/debugfunc.cpp \
lib/diagnosticstyle.cpp \
lib/errorfunc.cpp \
lib/filefunc.cpp \
lib/flagguard.cpp \
Expand Down Expand Up @@ -1136,6 +1137,7 @@ HEADERS += \
lib/css.h \
lib/datetime.h \
lib/debugfunc.h \
lib/diagnosticstyle.h \
lib/errorfunc.h \
lib/filefunc.h \
lib/flagguard.h \
Expand Down
42 changes: 42 additions & 0 deletions tablet_qt/lib/diagnosticstyle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
This file is part of CamCOPS.
CamCOPS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CamCOPS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
*/

// https://stackoverflow.com/questions/5909907/drawing-an-overlay-on-top-of-an-applications-window

#include "diagnosticstyle.h"
#include <QBrush>
#include <QPainter>
#include <QWidget>

void DiagnosticStyle::drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const
{
QCommonStyle::drawControl(element, option, painter, widget);
if (widget && painter) {
// draw a border around the widget
painter->setPen(QColor("red"));
painter->drawRect(widget->rect());

// show the classname of the widget
QBrush translucentBrush(QColor(255,246,240, 100));
painter->fillRect(widget->rect(), translucentBrush);
painter->setPen(QColor("darkblue"));
painter->drawText(widget->rect(), Qt::AlignLeft | Qt::AlignVCenter, widget->metaObject()->className());
}
};
31 changes: 31 additions & 0 deletions tablet_qt/lib/diagnosticstyle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
This file is part of CamCOPS.
CamCOPS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CamCOPS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once
#include <QCommonStyle>

class DiagnosticStyle : public QCommonStyle
{
Q_OBJECT

public:
void drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const;
typedef QStyle BaseStyle;
};
10 changes: 10 additions & 0 deletions tablet_qt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#define FULL_LOG_FORMAT // Include time and thread ID.
// #define DISABLE_ANDROID_NATIVE_DIALOGS // For a bug fixed in Qt 5.2.1.
// #define QT_OPENGL_IN_SOFTWARE // Unnecessary once proper OpenGL detection added.
// #define DEBUG_WITH_DIAGNOSTIC_STYLE


#include <QApplication>
#include <QDebug>
Expand All @@ -31,6 +33,7 @@
#include "common/preprocessor_aid.h"
#include "core/camcopsapp.h"
#include "crypto/cryptofunc.h"
#include "lib/diagnosticstyle.h"

#ifdef FULL_LOG_FORMAT
#ifdef QT_DEBUG
Expand Down Expand Up @@ -119,8 +122,15 @@ VISIBLE_SYMBOL int main(int argc, char* argv[])
created. See https://bugreports.qt.io/browse/QTBUG-45517
*/

#ifdef DEBUG_WITH_DIAGNOSTIC_STYLE
// Overlay widgets with bounding box and class name
auto style = new DiagnosticStyle();
#else
QStyle* style = QStyleFactory::create("Fusion");
#endif

// QProxyStyle* proxy_style = new TreeViewProxyStyle(style);

QApplication::setStyle(style);
// ... https://stackoverflow.com/questions/41184723/i-want-qt-app-to-look-like-qt-app-rather-than-android-native

Expand Down

0 comments on commit eb18f0d

Please sign in to comment.