GraphicProvider added
This commit is contained in:
parent
2951e25de6
commit
01b6207fa6
|
@ -45,7 +45,7 @@ BoxWithButtons::BoxWithButtons( const QString& title, const QString& value,
|
||||||
layout->setSpacing( 20 );
|
layout->setSpacing( 20 );
|
||||||
|
|
||||||
auto iconLabel = new RoundedIcon( isBright, layout );
|
auto iconLabel = new RoundedIcon( isBright, layout );
|
||||||
iconLabel->setIcon( title );
|
iconLabel->setSource( title );
|
||||||
iconLabel->setFixedSize( 68, 68 );
|
iconLabel->setFixedSize( 68, 68 );
|
||||||
|
|
||||||
auto titleAndValue = new QskLinearBox( Qt::Vertical, layout );
|
auto titleAndValue = new QskLinearBox( Qt::Vertical, layout );
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Copyright (C) 2021 Edelhirsch Software GmbH
|
||||||
|
* This file may be used under the terms of the 3-clause BSD License
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include "GraphicProvider.h"
|
||||||
|
|
||||||
|
#include <QskGraphic.h>
|
||||||
|
|
||||||
|
#include <QSvgRenderer>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QImage>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
|
const inline QString pathName( const QString& baseName, const QString& suffix )
|
||||||
|
{
|
||||||
|
QString fileName = baseName;
|
||||||
|
if ( !suffix.isEmpty() )
|
||||||
|
fileName += suffix;
|
||||||
|
|
||||||
|
return QFile( fileName ).exists() ? fileName : QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
const QskGraphic* GraphicProvider::loadGraphic( const QString& id ) const
|
||||||
|
{
|
||||||
|
static QString scope = QStringLiteral( ":/images/" );
|
||||||
|
|
||||||
|
QString baseName = scope;
|
||||||
|
baseName += id.toLower().replace( ' ', '-' );
|
||||||
|
|
||||||
|
auto path = pathName( baseName, QString() );
|
||||||
|
|
||||||
|
if ( path.isEmpty() )
|
||||||
|
path = pathName( baseName, ".png" );
|
||||||
|
|
||||||
|
if ( path.isEmpty() )
|
||||||
|
path = pathName( baseName, ".svg" );
|
||||||
|
|
||||||
|
QskGraphic graphic;
|
||||||
|
|
||||||
|
if ( !path.isEmpty() )
|
||||||
|
{
|
||||||
|
if ( path.endsWith( ".png" ) )
|
||||||
|
{
|
||||||
|
graphic = QskGraphic::fromImage( QImage( path ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QSvgRenderer renderer;
|
||||||
|
if ( renderer.load( path ) )
|
||||||
|
{
|
||||||
|
QPainter painter( &graphic );
|
||||||
|
renderer.render( &painter );
|
||||||
|
painter.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return graphic.isNull() ? nullptr : new QskGraphic( graphic );
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Copyright (C) 2021 Edelhirsch Software GmbH
|
||||||
|
* This file may be used under the terms of the 3-clause BSD License
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QskGraphicProvider.h>
|
||||||
|
|
||||||
|
class GraphicProvider final : public QskGraphicProvider
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
const QskGraphic* loadGraphic( const QString& id ) const override;
|
||||||
|
};
|
||||||
|
|
|
@ -5,14 +5,6 @@
|
||||||
|
|
||||||
#include "MenuBar.h"
|
#include "MenuBar.h"
|
||||||
|
|
||||||
#include <QskGraphic.h>
|
|
||||||
#include <QskGraphicLabel.h>
|
|
||||||
#include <QskGraphicIO.h>
|
|
||||||
#include <QskSkin.h>
|
|
||||||
#include <QskTextLabel.h>
|
|
||||||
|
|
||||||
#include <QImage>
|
|
||||||
|
|
||||||
QSK_SUBCONTROL( MenuBarTopLabel, Graphic )
|
QSK_SUBCONTROL( MenuBarTopLabel, Graphic )
|
||||||
QSK_SUBCONTROL( MenuBarGraphicLabel, Graphic )
|
QSK_SUBCONTROL( MenuBarGraphicLabel, Graphic )
|
||||||
QSK_SUBCONTROL( MenuBarLabel, Text )
|
QSK_SUBCONTROL( MenuBarLabel, Text )
|
||||||
|
@ -32,11 +24,7 @@ MenuItem::MenuItem( const QString& name, QQuickItem* parent )
|
||||||
setPanel( true );
|
setPanel( true );
|
||||||
setSubcontrolProxy( QskBox::Panel, MenuItem::Panel );
|
setSubcontrolProxy( QskBox::Panel, MenuItem::Panel );
|
||||||
|
|
||||||
QString fileName = ":/images/" + name.toLower() + ".png";
|
auto graphicLabel = new MenuBarGraphicLabel( name, this );
|
||||||
QImage image( fileName );
|
|
||||||
auto graphic = QskGraphic::fromImage( image );
|
|
||||||
|
|
||||||
auto graphicLabel = new MenuBarGraphicLabel( graphic, this );
|
|
||||||
graphicLabel->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
|
graphicLabel->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
|
||||||
graphicLabel->setFixedWidth( metric( MenuBarGraphicLabel::Graphic | QskAspect::Size ) );
|
graphicLabel->setFixedWidth( metric( MenuBarGraphicLabel::Graphic | QskAspect::Size ) );
|
||||||
|
|
||||||
|
@ -52,9 +40,7 @@ MenuBar::MenuBar( QQuickItem* parent )
|
||||||
initSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Preferred );
|
initSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Preferred );
|
||||||
setSpacing( 8 );
|
setSpacing( 8 );
|
||||||
|
|
||||||
auto graphic = QskGraphic::fromImage( QImage( ":/images/main-icon.png" ) );
|
auto graphicLabel = new MenuBarTopLabel( "main-icon", this );
|
||||||
|
|
||||||
auto graphicLabel = new MenuBarTopLabel( graphic, this );
|
|
||||||
graphicLabel->setMargins( marginHint( MenuBarTopLabel::Graphic ) );
|
graphicLabel->setMargins( marginHint( MenuBarTopLabel::Graphic ) );
|
||||||
graphicLabel->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
|
graphicLabel->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ class MenuBarTopLabel final : public QskGraphicLabel
|
||||||
public:
|
public:
|
||||||
QSK_SUBCONTROLS( Graphic )
|
QSK_SUBCONTROLS( Graphic )
|
||||||
|
|
||||||
MenuBarTopLabel( const QskGraphic& graphic, QQuickItem* parent = nullptr )
|
MenuBarTopLabel( const QString& icon, QQuickItem* parent = nullptr )
|
||||||
: QskGraphicLabel( graphic, parent )
|
: QskGraphicLabel( icon, parent )
|
||||||
{
|
{
|
||||||
setSubcontrolProxy( QskGraphicLabel::Graphic, Graphic );
|
setSubcontrolProxy( QskGraphicLabel::Graphic, Graphic );
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@ class MenuBarGraphicLabel final : public QskGraphicLabel
|
||||||
public:
|
public:
|
||||||
QSK_SUBCONTROLS( Graphic )
|
QSK_SUBCONTROLS( Graphic )
|
||||||
|
|
||||||
MenuBarGraphicLabel( const QskGraphic& graphic, QQuickItem* parent = nullptr )
|
MenuBarGraphicLabel( const QString& icon, QQuickItem* parent = nullptr )
|
||||||
: QskGraphicLabel( graphic, parent )
|
: QskGraphicLabel( icon, parent )
|
||||||
{
|
{
|
||||||
setSubcontrolProxy( QskGraphicLabel::Graphic, Graphic );
|
setSubcontrolProxy( QskGraphicLabel::Graphic, Graphic );
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace
|
||||||
|
|
||||||
auto icon = new RoundedIcon( isBright, this );
|
auto icon = new RoundedIcon( isBright, this );
|
||||||
icon->setPale( true );
|
icon->setPale( true );
|
||||||
icon->setIcon( name );
|
icon->setSource( name );
|
||||||
icon->setFixedSize( 68, 68 );
|
icon->setFixedSize( 68, 68 );
|
||||||
|
|
||||||
auto textLabel = new QskTextLabel( name, this );
|
auto textLabel = new QskTextLabel( name, this );
|
||||||
|
|
|
@ -20,20 +20,15 @@ RoundButton::RoundButton( QskAspect::Placement placement, QQuickItem* parent )
|
||||||
setSubcontrolProxy( QskPushButton::Panel, RoundButton::Panel );
|
setSubcontrolProxy( QskPushButton::Panel, RoundButton::Panel );
|
||||||
setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Expanding );
|
setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Expanding );
|
||||||
|
|
||||||
QskGraphic graphic;
|
|
||||||
QImage image;
|
|
||||||
|
|
||||||
if( placement == QskAspect::Top )
|
if( placement == QskAspect::Top )
|
||||||
{
|
{
|
||||||
setSkinStateFlag( Top );
|
setSkinStateFlag( Top );
|
||||||
image.load( ":/images/up.svg" );
|
setGraphicSource( "up" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
image.load( ":/images/down.svg" );
|
setGraphicSource( "down" );
|
||||||
}
|
}
|
||||||
|
|
||||||
setGraphicSourceSize( image.size() );
|
setGraphicSourceSize( graphic().defaultSize() * 1.2 );
|
||||||
graphic = QskGraphic::fromImage( image );
|
|
||||||
setGraphic( graphic );
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,6 @@
|
||||||
|
|
||||||
#include "RoundedIcon.h"
|
#include "RoundedIcon.h"
|
||||||
|
|
||||||
#include <QskGraphic.h>
|
|
||||||
#include <QImage>
|
|
||||||
|
|
||||||
QSK_SUBCONTROL( RoundedIcon, Panel )
|
QSK_SUBCONTROL( RoundedIcon, Panel )
|
||||||
QSK_SUBCONTROL( RoundedIcon, PalePanel )
|
QSK_SUBCONTROL( RoundedIcon, PalePanel )
|
||||||
|
|
||||||
|
@ -31,16 +28,4 @@ void RoundedIcon::setPale( bool on )
|
||||||
setSubcontrolProxy( QskGraphicLabel::Panel, on ? PalePanel : Panel );
|
setSubcontrolProxy( QskGraphicLabel::Panel, on ? PalePanel : Panel );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoundedIcon::setIcon( const QString& iconName )
|
|
||||||
{
|
|
||||||
// we should use a graphic provider, TODO ...
|
|
||||||
|
|
||||||
QString fileName = ":/images/";
|
|
||||||
fileName += iconName.toLower().replace( ' ', '-' );
|
|
||||||
fileName += ".png";
|
|
||||||
|
|
||||||
const QImage image( fileName );
|
|
||||||
setGraphic( QskGraphic::fromImage( image ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "moc_RoundedIcon.cpp"
|
#include "moc_RoundedIcon.cpp"
|
||||||
|
|
|
@ -19,6 +19,5 @@ class RoundedIcon : public QskGraphicLabel
|
||||||
|
|
||||||
RoundedIcon( bool isBright, QQuickItem* parent = nullptr );
|
RoundedIcon( bool isBright, QQuickItem* parent = nullptr );
|
||||||
|
|
||||||
void setIcon( const QString& );
|
|
||||||
void setPale( bool );
|
void setPale( bool );
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
CONFIG += qskexample
|
CONFIG += qskexample
|
||||||
|
|
||||||
|
QT += svg
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
Box.cpp \
|
Box.cpp \
|
||||||
BoxWithButtons.cpp \
|
BoxWithButtons.cpp \
|
||||||
|
@ -7,6 +9,7 @@ SOURCES += \
|
||||||
CircularProgressBarSkinlet.cpp \
|
CircularProgressBarSkinlet.cpp \
|
||||||
Diagram.cpp \
|
Diagram.cpp \
|
||||||
DiagramSkinlet.cpp \
|
DiagramSkinlet.cpp \
|
||||||
|
GraphicProvider.cpp \
|
||||||
LightIntensity.cpp \
|
LightIntensity.cpp \
|
||||||
MainContent.cpp \
|
MainContent.cpp \
|
||||||
MenuBar.cpp \
|
MenuBar.cpp \
|
||||||
|
@ -34,6 +37,7 @@ HEADERS += \
|
||||||
CircularProgressBarSkinlet.h \
|
CircularProgressBarSkinlet.h \
|
||||||
Diagram.h \
|
Diagram.h \
|
||||||
DiagramSkinlet.h \
|
DiagramSkinlet.h \
|
||||||
|
GraphicProvider.h \
|
||||||
LightIntensity.h \
|
LightIntensity.h \
|
||||||
MainContent.h \
|
MainContent.h \
|
||||||
MainWindow.h \
|
MainWindow.h \
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
#include "GraphicProvider.h"
|
||||||
#include "Skin.h"
|
#include "Skin.h"
|
||||||
|
|
||||||
#include <SkinnyFont.h>
|
#include <SkinnyFont.h>
|
||||||
|
@ -62,6 +63,8 @@ int main( int argc, char* argv[] )
|
||||||
|
|
||||||
SkinnyFont::init( &app );
|
SkinnyFont::init( &app );
|
||||||
|
|
||||||
|
Qsk::addGraphicProvider( QString(), new GraphicProvider() );
|
||||||
|
|
||||||
// disable default skins
|
// disable default skins
|
||||||
qskSkinManager->setPluginPaths( QStringList() ); // no plugins
|
qskSkinManager->setPluginPaths( QStringList() ); // no plugins
|
||||||
qskSkinManager->unregisterFactory( "materialfactory" );
|
qskSkinManager->unregisterFactory( "materialfactory" );
|
||||||
|
|
Loading…
Reference in New Issue