126 lines
3.3 KiB
C++
Raw Normal View History

2017-07-21 18:21:34 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include <SkinnyFont.h>
#include <SkinnyShortcut.h>
#include <QskAspect.h>
2018-08-03 08:15:28 +02:00
#include <QskBoxBorderColors.h>
#include <QskFocusIndicator.h>
#include <QskLinearBox.h>
2017-07-21 18:21:34 +02:00
#include <QskObjectCounter.h>
#include <QskPushButton.h>
#include <QskSkin.h>
2018-08-03 08:15:28 +02:00
#include <QskTabButton.h>
2020-03-13 14:50:09 +01:00
#include <QskTabBar.h>
2018-08-03 08:15:28 +02:00
#include <QskTabView.h>
#include <QskTextLabel.h>
#include <QskWindow.h>
2019-02-13 10:25:38 +01:00
#include <QskShortcutMap.h>
2017-07-21 18:21:34 +02:00
#include <QGuiApplication>
class Label : public QskTextLabel
{
2018-08-03 08:15:28 +02:00
public:
Label( const QString& text, QQuickItem* parent = nullptr )
: QskTextLabel( text, parent )
2017-07-21 18:21:34 +02:00
{
setTextColor( Qt::darkRed );
setFontRole( QskSkin::LargeFont );
2017-07-21 18:21:34 +02:00
setAlignment( Qt::AlignCenter );
}
};
class TabView : public QskTabView
{
2018-08-03 08:15:28 +02:00
public:
TabView( QQuickItem* parent = nullptr )
: QskTabView( parent )
2017-07-21 18:21:34 +02:00
{
2020-03-13 07:39:31 +01:00
for ( int i = 0; i < 10; i++ )
2017-07-21 18:21:34 +02:00
{
QString text;
if ( i == 4 )
text = QString( "Another Tab" );
else
text = QString( "Tab %1" ).arg( i + 1 );
addTab( text, new Label( text ) );
}
buttonAt( 2 )->setEnabled( false );
}
void rotate()
2017-07-21 18:21:34 +02:00
{
const Qsk::Position pos[] = { Qsk::Top, Qsk::Right, Qsk::Bottom, Qsk::Left };
for ( int i = 0; i < 4; i++ )
{
if ( tabPosition() == pos[i] )
{
setTabPosition( pos[ ( i + 1 ) % 4 ] );
break;
}
}
2017-07-21 18:21:34 +02:00
}
};
int main( int argc, char* argv[] )
{
#ifdef ITEM_STATISTICS
QskObjectCounter counter( true );
#endif
QGuiApplication app( argc, argv );
SkinnyFont::init( &app );
SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts );
auto tabView = new TabView();
auto rotateButton = new QskPushButton( "Rotate" );
rotateButton->setFocus( true );
2020-03-13 14:50:09 +01:00
QObject::connect( rotateButton, &QskPushButton::clicked,
tabView, &TabView::rotate );
auto autoFitButton = new QskPushButton( "Fit Tabs" );
autoFitButton->setCheckable( true );
QObject::connect( autoFitButton, &QskPushButton::toggled,
tabView, &QskTabView::setAutoFitTabs );
auto buttonBox = new QskLinearBox( Qt::Horizontal );
buttonBox->addItem( rotateButton );
buttonBox->addItem( autoFitButton );
buttonBox->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
2017-07-21 18:21:34 +02:00
auto layoutBox = new QskLinearBox( Qt::Vertical );
layoutBox->setDefaultAlignment( Qt::AlignLeft );
layoutBox->setMargins( 20 );
2017-07-21 18:21:34 +02:00
layoutBox->setSpacing( 10 );
2020-03-13 14:50:09 +01:00
layoutBox->addItem( buttonBox );
2017-07-21 18:21:34 +02:00
layoutBox->addItem( tabView );
auto focusIndicator = new QskFocusIndicator();
focusIndicator->setObjectName( "FocusIndicator" );
2017-10-18 20:00:06 +02:00
focusIndicator->setBoxBorderColorsHint( QskFocusIndicator::Panel, Qt::red );
2017-07-21 18:21:34 +02:00
QskWindow window;
2020-03-13 14:50:09 +01:00
window.resize( 800, 600 );
2017-07-21 18:21:34 +02:00
window.addItem( layoutBox );
window.addItem( focusIndicator );
window.show();
2019-02-13 10:25:38 +01:00
for ( int i = 0; i < 10; i++ )
{
QskShortcutMap::addShortcut( Qt::Key_F1 + i, false,
[tabView, i] { tabView->removeTab( i ); } );
}
2017-07-21 18:21:34 +02:00
return app.exec();
}