2024-01-17 14:31:45 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) The authors
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
#include "SkinnyShortcut.h"
|
2022-04-01 13:56:16 +02:00
|
|
|
#include "SkinnyNamespace.h"
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2017-12-06 17:01:10 +01:00
|
|
|
#include <QskShortcutMap.h>
|
2017-07-21 18:21:34 +02:00
|
|
|
#include <QskSetup.h>
|
|
|
|
#include <QskWindow.h>
|
|
|
|
#include <QskControl.h>
|
2018-05-01 12:41:20 +02:00
|
|
|
#include <QskQuick.h>
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
#include <QQuickItem>
|
|
|
|
#include <QKeySequence>
|
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QSGNode>
|
|
|
|
#include <QDebug>
|
|
|
|
|
2017-07-24 09:38:16 +02:00
|
|
|
#include <iostream>
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
SkinnyShortcut::SkinnyShortcut( QObject* parent ):
|
|
|
|
QObject( parent )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkinnyShortcut::enable( Types types )
|
|
|
|
{
|
2017-07-24 09:38:16 +02:00
|
|
|
using namespace std;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2017-07-24 09:38:16 +02:00
|
|
|
static SkinnyShortcut s_shortcut;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
if ( types & RotateSkin )
|
|
|
|
{
|
2020-10-23 12:45:46 +02:00
|
|
|
QskShortcutMap::addShortcut( QKeySequence( Qt::CTRL | Qt::Key_S ),
|
2022-04-01 13:56:16 +02:00
|
|
|
false, &s_shortcut, [] { Skinny::changeSkin(); } );
|
2017-07-24 09:38:16 +02:00
|
|
|
cout << "CTRL-S to change the skin." << endl;
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2018-01-04 13:59:51 +01:00
|
|
|
if ( types & ChangeFonts )
|
|
|
|
{
|
2020-10-23 12:45:46 +02:00
|
|
|
QskShortcutMap::addShortcut( QKeySequence( Qt::CTRL | Qt::Key_F ),
|
2022-04-01 13:56:16 +02:00
|
|
|
false, &s_shortcut, [] { Skinny::changeFonts( +1 ); } );
|
2018-01-04 13:59:51 +01:00
|
|
|
|
2020-10-23 12:45:46 +02:00
|
|
|
QskShortcutMap::addShortcut( QKeySequence( Qt::CTRL | Qt::Key_G ),
|
2022-04-01 13:56:16 +02:00
|
|
|
false, &s_shortcut, [] { Skinny::changeFonts( -1 ); } );
|
2018-01-04 13:59:51 +01:00
|
|
|
|
|
|
|
cout << "CTRL-F to increase the font size." << endl;
|
|
|
|
cout << "CTRL-G to decrease the font size." << endl;
|
|
|
|
}
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
if ( types & DebugBackground )
|
|
|
|
{
|
2020-10-23 12:45:46 +02:00
|
|
|
QskShortcutMap::addShortcut( QKeySequence( Qt::CTRL | Qt::Key_B ),
|
2017-12-05 13:10:50 +01:00
|
|
|
false, &s_shortcut, &SkinnyShortcut::showBackground );
|
2017-07-24 09:38:16 +02:00
|
|
|
cout << "CTRL-B to enable visual debugging modes." << endl;
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( types & DebugStatistics )
|
|
|
|
{
|
2020-10-23 12:45:46 +02:00
|
|
|
QskShortcutMap::addShortcut( QKeySequence( Qt::CTRL | Qt::Key_K ),
|
2017-12-05 13:10:50 +01:00
|
|
|
false, &s_shortcut, &SkinnyShortcut::debugStatistics );
|
2017-07-24 09:38:16 +02:00
|
|
|
cout << "CTRL-K to dump statistics about the items/nodes being currently used." << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( types & Quit )
|
|
|
|
{
|
|
|
|
// QKeySequence::Quit crashes the application
|
|
|
|
// when not being implemented by the platform !!
|
|
|
|
|
2020-10-23 12:45:46 +02:00
|
|
|
QskShortcutMap::addShortcut( QKeySequence( Qt::CTRL | Qt::Key_Q ),
|
2017-12-05 13:10:50 +01:00
|
|
|
false, QGuiApplication::instance(), &QGuiApplication::quit );
|
2017-07-24 09:38:16 +02:00
|
|
|
cout << "CTRL-Q to terminate the application." << endl;
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkinnyShortcut::showBackground()
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
const QVector< QByteArray > sgDebugModes =
|
|
|
|
{ "clip", "overdraw", "changes", "batches" };
|
|
|
|
#else
|
|
|
|
const QVector< QByteArray > sgDebugModes = { "overdraw" };
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int id = 0;
|
|
|
|
|
|
|
|
id = ( id + 1 ) % ( sgDebugModes.count() + 2 );
|
|
|
|
|
|
|
|
bool forceBackground = false;
|
|
|
|
QByteArray scengraphDebugMode;
|
|
|
|
|
|
|
|
if ( id == 0 )
|
|
|
|
{
|
|
|
|
// nothing
|
|
|
|
}
|
|
|
|
else if ( id == 1 )
|
|
|
|
{
|
|
|
|
forceBackground = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scengraphDebugMode = sgDebugModes[ id - 2 ];
|
|
|
|
}
|
|
|
|
|
2021-02-09 08:13:20 +01:00
|
|
|
qskSetup->setItemUpdateFlag( QskQuickItem::DebugForceBackground, forceBackground );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2017-10-30 12:06:19 +01:00
|
|
|
const auto windows = QGuiApplication::topLevelWindows();
|
|
|
|
for ( auto window : windows )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
if ( QskWindow* w = qobject_cast< QskWindow* >( window ) )
|
|
|
|
{
|
|
|
|
if ( w->customRenderMode() != scengraphDebugMode )
|
|
|
|
{
|
|
|
|
w->setCustomRenderMode( scengraphDebugMode );
|
|
|
|
w->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void countNodes( const QSGNode* node, int& counter )
|
|
|
|
{
|
|
|
|
if ( node )
|
|
|
|
{
|
|
|
|
counter++;
|
|
|
|
|
|
|
|
for ( auto child = node->firstChild();
|
|
|
|
child != nullptr; child = child->nextSibling() )
|
|
|
|
{
|
|
|
|
countNodes( child, counter );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void countNodes( const QQuickItem* item, int& counter )
|
|
|
|
{
|
2018-01-19 10:07:05 +01:00
|
|
|
const auto itemNode = qskItemNode( item );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
if ( itemNode )
|
|
|
|
{
|
2018-01-19 10:07:05 +01:00
|
|
|
auto node = qskPaintNode( item );
|
2017-07-21 18:21:34 +02:00
|
|
|
if ( node )
|
|
|
|
{
|
|
|
|
countNodes( node, counter );
|
|
|
|
while ( node != itemNode )
|
|
|
|
{
|
|
|
|
counter++;
|
|
|
|
node = node->parent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
counter++;
|
|
|
|
// clipNode/opacityNode ???
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void countItems( const QQuickItem* item, int counter[4] )
|
|
|
|
{
|
|
|
|
if ( item )
|
|
|
|
{
|
|
|
|
counter[0]++;
|
|
|
|
|
|
|
|
int nodeCounter = 0;
|
|
|
|
countNodes( item, nodeCounter );
|
|
|
|
|
|
|
|
counter[2] += nodeCounter;
|
|
|
|
|
|
|
|
if ( item->isVisible() )
|
|
|
|
{
|
|
|
|
counter[1]++;
|
|
|
|
counter[3] += nodeCounter;
|
|
|
|
}
|
|
|
|
|
2017-10-30 12:06:19 +01:00
|
|
|
const auto children = item->childItems();
|
|
|
|
for ( const auto* child : children )
|
2017-07-21 18:21:34 +02:00
|
|
|
countItems( child, counter );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkinnyShortcut::debugStatistics()
|
|
|
|
{
|
2017-10-30 12:06:19 +01:00
|
|
|
const auto windows = QGuiApplication::topLevelWindows();
|
|
|
|
for ( auto window : windows )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
const auto w = qobject_cast< const QQuickWindow* >( window );
|
|
|
|
if ( w == nullptr )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int counter[4] = {};
|
|
|
|
countItems( w->contentItem(), counter );
|
|
|
|
|
2017-07-26 13:21:10 +02:00
|
|
|
qDebug() << w << "\n\titems:" << counter[0] << "visible" << counter[1]
|
2021-08-04 09:31:16 +02:00
|
|
|
<< "\n\tnodes:" << counter[2] << "visible" << counter[3];
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_SkinnyShortcut.cpp"
|