qskinny/playground/drawer/main.cpp

145 lines
3.8 KiB
C++
Raw Normal View History

2023-10-06 10:41:23 +00:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/
#include "SkinnyShortcut.h"
#include <QskRgbValue.h>
#include <QskControl.h>
#include <QskDrawer.h>
#include <QskPushButton.h>
#include <QskFocusIndicator.h>
2023-10-06 10:41:23 +00:00
#include <QskWindow.h>
#include <QskEvent.h>
#include <QskAnimationHint.h>
#include <QGuiApplication>
namespace
{
class Drawer : public QskDrawer
{
public:
Drawer( Qt::Edge edge, QQuickItem* parent )
: QskDrawer( parent )
{
setEdge( edge );
auto content = new QskControl( this );
content->setObjectName( "Content" );
2023-10-26 11:29:16 +00:00
content->setAutoLayoutChildren( true );
content->setMargins( 20 );
2023-10-06 10:41:23 +00:00
auto button = new QskPushButton( "Push Me", content );
button->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
button->setLayoutAlignmentHint( Qt::AlignCenter );
const auto size = content->sizeHint();
2023-10-06 10:41:23 +00:00
switch( edge )
{
case Qt::LeftEdge:
2023-11-03 16:49:26 +00:00
setPanel( QskRgb::Tomato );
2023-10-06 10:41:23 +00:00
break;
case Qt::RightEdge:
2023-11-03 16:49:26 +00:00
setPanel( QskRgb::Orchid );
content->setFixedWidth( 1.5 * size.width() );
2023-10-06 10:41:23 +00:00
break;
case Qt::TopEdge:
2023-11-03 16:49:26 +00:00
setPanel( QskRgb::Chartreuse );
2023-10-06 10:41:23 +00:00
break;
case Qt::BottomEdge:
2023-11-03 16:49:26 +00:00
setPanel( QskRgb::Wheat );
content->setFixedHeight( 2 * size.height() );
2023-10-06 10:41:23 +00:00
break;
}
}
2023-11-03 16:49:26 +00:00
private:
void setPanel( const QColor& color )
{
setGradientHint( Panel, color );
}
2023-10-06 10:41:23 +00:00
};
class DrawerBox : public QskControl
{
public:
DrawerBox( QQuickItem* parent = nullptr )
: QskControl( parent )
{
setBackgroundColor( QskRgb::LightSteelBlue );
setMargins( 10 );
2023-10-06 10:41:23 +00:00
setAutoLayoutChildren( true );
for ( int i = 0; i < 4; i++ )
{
const auto edge = static_cast< Qt::Edge >( 1 << i );
auto dragMargin = 30; // the default setting is pretty small
if ( edge == Qt::TopEdge )
{
// to check if dragging works above the button
dragMargin = 120;
}
2023-10-19 07:51:38 +00:00
auto drawer = new Drawer( edge, this );
drawer->setDragMargin( dragMargin );
connect( drawer, &QskPopup::openChanged,
this, &DrawerBox::setDrawersLocked );
m_drawers[i] = drawer;
2023-10-06 10:41:23 +00:00
}
auto button = new QskPushButton( "Push Me", this );
button->setPreferredHeight( 100 );
2023-10-06 10:41:23 +00:00
}
private:
2023-10-19 07:51:38 +00:00
void setDrawersLocked( bool locked )
{
for ( auto drawer : m_drawers )
{
if ( !drawer->isOpen() )
drawer->setInteractive( !locked );
}
}
2023-10-06 10:41:23 +00:00
Drawer* m_drawers[4];
};
class MainBox : public QskControl
{
public:
MainBox( QQuickItem* parent = nullptr )
: QskControl( parent )
{
setMargins( 40 );
setAutoLayoutChildren( true );
( void ) new DrawerBox( this );
}
};
}
int main( int argc, char* argv[] )
{
QGuiApplication app( argc, argv );
SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts );
QskWindow window;
window.addItem( new QskFocusIndicator() );
2023-10-06 10:41:23 +00:00
window.addItem( new MainBox() );
window.resize( 600, 600 );
window.show();
return app.exec();
}