colorswitch example removed

This commit is contained in:
Uwe Rathmann 2022-04-06 08:41:32 +02:00
parent 1cb2110f5d
commit 676e0d5e9f
10 changed files with 21 additions and 397 deletions

View File

@ -5,10 +5,17 @@ Qsk.PushButton
{
sizePolicy
{
// long texts, should not have an effect
horizontalPolicy: Qsk.SizePolicy.Ignored
verticalPolicy: Qsk.SizePolicy.Ignored
}
minimumSize
{
width: 80
height: 60
}
shape
{
sizeMode: Qt.RelativeSize

View File

@ -6,12 +6,20 @@ Qsk.Window
{
id: window
visible: true
// visibility: QskWindow.Minimized
width: 600
height: 600
color: "Beige"
Component.onCompleted:
{
// very much standard: we should find a better way
var hint = sizeConstraint();
setMinimumWidth( hint.width )
setMinimumHeight( hint.height )
}
Qsk.Shortcut
{
sequence : "Ctrl+X"

View File

@ -1,117 +0,0 @@
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "Theme.h"
#include <QskAspect.h>
#include <QskBoxBorderColors.h>
#include <QskFocusIndicator.h>
#include <QskListView.h>
#include <QskSetup.h>
#include <QskSkin.h>
#include <QskSkinTransition.h>
#include <QskSkinHintTable.h>
#include <QskSkinHintTableEditor.h>
namespace
{
class SkinTransition final : public QskSkinTransition
{
public:
SkinTransition( const QColor& accent )
: m_accent( accent )
{
}
protected:
void updateSkin( QskSkin*, QskSkin* newSkin ) override
{
newSkin->resetColors( m_accent );
/*
The current implementation of the skins is not that good
and we don't have support for customizing them by a minimal set
of attributes. So we do some manual extra work here
*/
QskSkinHintTableEditor ed( &newSkin->hintTable() );
ed.setColor( QskListView::Cell | QskListView::Selected, m_accent.darker( 130 ) );
ed.setBoxBorderColors( QskFocusIndicator::Panel, m_accent.darker( 150 ) );
}
private:
const QColor m_accent;
};
}
Theme::Theme( QObject* parent )
: QObject( parent )
, m_accent( Qt::blue )
{
connect( qskSetup, &QskSetup::skinChanged,
this, [ this ]( QskSkin* ) { updateColors(); } );
connect( qskSetup, &QskSetup::skinChanged,
this, [ this ]( QskSkin* ) { Q_EMIT skinChanged(); } );
}
void Theme::setAccent( QColor color )
{
if ( m_accent != color )
{
m_accent = color;
updateColors();
Q_EMIT accentChanged();
}
}
QColor Theme::accent() const
{
return m_accent;
}
void Theme::setSkin( const QString& skinName )
{
if ( skinName == qskSetup->skinName() )
return;
auto oldSkin = qskSetup->skin();
if ( oldSkin->parent() == qskSetup )
oldSkin->setParent( nullptr ); // otherwise setSkin deletes it
auto newSkin = qskSetup->setSkin( skinName );
SkinTransition transition( m_accent );
transition.setSourceSkin( oldSkin );
transition.setTargetSkin( newSkin );
transition.setAnimation( 500 );
transition.process();
if ( oldSkin->parent() == nullptr )
delete oldSkin;
}
QString Theme::skin() const
{
return qskSetup->skinName();
}
void Theme::updateColors()
{
SkinTransition transition( m_accent );
transition.setMask( SkinTransition::Color );
transition.setSourceSkin( qskSetup->skin() );
transition.setTargetSkin( qskSetup->skin() );
transition.setAnimation( 500 );
transition.process();
}
#include "moc_Theme.cpp"

View File

@ -1,35 +0,0 @@
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#pragma once
#include <QColor>
#include <QObject>
class Theme : public QObject
{
Q_OBJECT
Q_PROPERTY( QColor accent READ accent WRITE setAccent NOTIFY accentChanged )
Q_PROPERTY( QString skin READ skin WRITE setSkin NOTIFY skinChanged )
public:
Theme( QObject* parent = nullptr );
void setAccent( QColor color );
QColor accent() const;
void setSkin( const QString& );
QString skin() const;
Q_SIGNALS:
void accentChanged();
void skinChanged();
private:
void updateColors();
QColor m_accent;
};

View File

@ -1,11 +0,0 @@
CONFIG += qskexample qskqmlexport
RESOURCES += \
colorswitch.qrc
HEADERS += \
Theme.h
SOURCES += \
Theme.cpp \
main.cpp

View File

@ -1,187 +0,0 @@
import QtQuick 2.5
import Skinny 1.0
import Theme 1.0 // things beyond supersimple are way more convenient with C++
Main
{
id: main
property var accentColors: [ "red", "lightgreen", "#66336699" ]
Theme
{
accent: accentColors[ tabBar.currentIndex < 0 ? 0 : tabBar.currentIndex ]
skin: listBox.entries[ listBox.selectedRow ]
}
Window
{
id: window
visible: true
color: "Gainsboro"
width: 600
height: 600
Component.onCompleted:
{
// very much standard: we should find a better way
var hint = sizeConstraint();
setMinimumWidth( hint.width )
setMinimumHeight( hint.height )
}
LinearBox
{
orientation: Qt.Horizontal
spacing: 20
//margins: 8 // so that we can see the focus frame
margins { left: 8; top: 8; right: 8; bottom: 8 }
SimpleListBox
{
id: listBox
preferredWidthFromColumns: true
sizePolicy.horizontalPolicy: SizePolicy.Fixed
entries: main.skinList
selectedRow: 1
}
LinearBox
{
// margins: 10
margins { left: 10; top: 10; right: 10; bottom: 10 }
orientation: Qt.Vertical
defaultAlignment: Qt.AlignCenter
extraSpacingAt: Qt.BottomEdge
TabBar
{
id: tabBar
currentIndex: 1
Instantiator
{
onObjectAdded: {
tabBar.insertTab( index, object );
}
model: accentColors
delegate: TabButton
{
id: tabButton1
sizePolicy.horizontalPolicy: SizePolicy.MinimumExpanding
text: modelData
}
}
}
LinearBox
{
orientation: Qt.Horizontal
dimension: 3
spacing: 20
//margins: 20
margins { left: 20; top: 20; right: 20; bottom: 20 }
sizePolicy
{
horizontalPolicy: SizePolicy.Fixed
verticalPolicy: SizePolicy.Fixed
}
PushButton
{
text: "normal"
focus: true
}
PushButton
{
text: checked ? "checked" : "unchecked"
checked: true
checkable: true
}
PushButton
{
text: "disabled"
enabled: false
}
PushButton
{
text: "flat"
flat: true
}
PushButton
{
text: ( checked ? "\u2714 " : "" ) + "flat"
flat: true
checkable: true
checked: true
}
PushButton
{
text: "flat"
flat: true
enabled: false
}
}
LinearBox
{
spacing: 5
orientation: Qt.Horizontal
sizePolicy
{
horizontalPolicy: SizePolicy.MinimumExpanding
verticalPolicy: SizePolicy.Fixed
}
Slider
{
id: slider
minimum: 0
maximum: 100
value: 42
snap: true
stepSize: 1
}
TextLabel
{
id: sliderValue
FontMetrics
{
id: fontMetrics
}
property rect textRect: fontMetrics.boundingRect("100")
preferredSize: Qt.size( textRect.width, textRect.height )
sizePolicy: SizePolicy.Fixed
text: slider.value
}
}
}
}
FocusIndicator
{
}
}
}

View File

@ -1,5 +0,0 @@
<RCC>
<qresource prefix="/qml">
<file>colorswitch.qml</file>
</qresource>
</RCC>

View File

@ -1,36 +0,0 @@
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include "Theme.h"
#include <SkinnyShortcut.h>
#include <QskQml.h>
#include <QskObjectCounter.h>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtQml>
int main( int argc, char* argv[] )
{
#ifdef ITEM_STATISTICS
QskObjectCounter counter( true );
#endif
qputenv( "QT_IM_MODULE", "skinny" );
QskQml::registerTypes();
qmlRegisterType< Theme >( "Theme", 1, 0, "Theme" );
QGuiApplication app( argc, argv );
SkinnyShortcut::enable( SkinnyShortcut::Quit |
SkinnyShortcut::ChangeFonts | SkinnyShortcut::DebugShortcuts );
QQmlApplicationEngine engine( QUrl( "qrc:/qml/colorswitch.qml" ) );
return app.exec();
}

View File

@ -32,7 +32,6 @@ qtHaveModule(svg) {
SUBDIRS += \
boxes \
buttons \
colorswitch \
frames \
gbenchmark \
glabels \

View File

@ -489,15 +489,16 @@ QSize QskWindow::sizeConstraint() const
const auto children = contentItem()->childItems();
for ( auto child : children )
{
if ( auto control = qskControlCast( child ) )
if ( !qskIsTransparentForPositioner( child ) )
{
const QSizeF itemConstraint = control->sizeConstraint();
const auto size = qskSizeConstraint( child, Qt::PreferredSize );
qDebug() << child << size;
if ( doWidth )
constraint.setWidth( qMax( constraint.width(), itemConstraint.width() ) );
constraint.setWidth( qMax( constraint.width(), size.width() ) );
if ( doHeight )
constraint.setHeight( qMax( constraint.height(), itemConstraint.height() ) );
constraint.setHeight( qMax( constraint.height(), size.height() ) );
}
}
}