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 );
|
||||
|
||||
auto iconLabel = new RoundedIcon( isBright, layout );
|
||||
iconLabel->setIcon( title );
|
||||
iconLabel->setSource( title );
|
||||
iconLabel->setFixedSize( 68, 68 );
|
||||
|
||||
auto titleAndValue = new QskLinearBox( Qt::Vertical, layout );
|
||||
|
60
examples/iotdashboard/GraphicProvider.cpp
Normal file
60
examples/iotdashboard/GraphicProvider.cpp
Normal file
@ -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 );
|
||||
}
|
15
examples/iotdashboard/GraphicProvider.h
Normal file
15
examples/iotdashboard/GraphicProvider.h
Normal file
@ -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 <QskGraphic.h>
|
||||
#include <QskGraphicLabel.h>
|
||||
#include <QskGraphicIO.h>
|
||||
#include <QskSkin.h>
|
||||
#include <QskTextLabel.h>
|
||||
|
||||
#include <QImage>
|
||||
|
||||
QSK_SUBCONTROL( MenuBarTopLabel, Graphic )
|
||||
QSK_SUBCONTROL( MenuBarGraphicLabel, Graphic )
|
||||
QSK_SUBCONTROL( MenuBarLabel, Text )
|
||||
@ -32,11 +24,7 @@ MenuItem::MenuItem( const QString& name, QQuickItem* parent )
|
||||
setPanel( true );
|
||||
setSubcontrolProxy( QskBox::Panel, MenuItem::Panel );
|
||||
|
||||
QString fileName = ":/images/" + name.toLower() + ".png";
|
||||
QImage image( fileName );
|
||||
auto graphic = QskGraphic::fromImage( image );
|
||||
|
||||
auto graphicLabel = new MenuBarGraphicLabel( graphic, this );
|
||||
auto graphicLabel = new MenuBarGraphicLabel( name, this );
|
||||
graphicLabel->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
|
||||
graphicLabel->setFixedWidth( metric( MenuBarGraphicLabel::Graphic | QskAspect::Size ) );
|
||||
|
||||
@ -52,9 +40,7 @@ MenuBar::MenuBar( QQuickItem* parent )
|
||||
initSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Preferred );
|
||||
setSpacing( 8 );
|
||||
|
||||
auto graphic = QskGraphic::fromImage( QImage( ":/images/main-icon.png" ) );
|
||||
|
||||
auto graphicLabel = new MenuBarTopLabel( graphic, this );
|
||||
auto graphicLabel = new MenuBarTopLabel( "main-icon", this );
|
||||
graphicLabel->setMargins( marginHint( MenuBarTopLabel::Graphic ) );
|
||||
graphicLabel->setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Fixed );
|
||||
|
||||
|
@ -16,8 +16,8 @@ class MenuBarTopLabel final : public QskGraphicLabel
|
||||
public:
|
||||
QSK_SUBCONTROLS( Graphic )
|
||||
|
||||
MenuBarTopLabel( const QskGraphic& graphic, QQuickItem* parent = nullptr )
|
||||
: QskGraphicLabel( graphic, parent )
|
||||
MenuBarTopLabel( const QString& icon, QQuickItem* parent = nullptr )
|
||||
: QskGraphicLabel( icon, parent )
|
||||
{
|
||||
setSubcontrolProxy( QskGraphicLabel::Graphic, Graphic );
|
||||
}
|
||||
@ -30,8 +30,8 @@ class MenuBarGraphicLabel final : public QskGraphicLabel
|
||||
public:
|
||||
QSK_SUBCONTROLS( Graphic )
|
||||
|
||||
MenuBarGraphicLabel( const QskGraphic& graphic, QQuickItem* parent = nullptr )
|
||||
: QskGraphicLabel( graphic, parent )
|
||||
MenuBarGraphicLabel( const QString& icon, QQuickItem* parent = nullptr )
|
||||
: QskGraphicLabel( icon, parent )
|
||||
{
|
||||
setSubcontrolProxy( QskGraphicLabel::Graphic, Graphic );
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace
|
||||
|
||||
auto icon = new RoundedIcon( isBright, this );
|
||||
icon->setPale( true );
|
||||
icon->setIcon( name );
|
||||
icon->setSource( name );
|
||||
icon->setFixedSize( 68, 68 );
|
||||
|
||||
auto textLabel = new QskTextLabel( name, this );
|
||||
|
@ -20,20 +20,15 @@ RoundButton::RoundButton( QskAspect::Placement placement, QQuickItem* parent )
|
||||
setSubcontrolProxy( QskPushButton::Panel, RoundButton::Panel );
|
||||
setSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Expanding );
|
||||
|
||||
QskGraphic graphic;
|
||||
QImage image;
|
||||
|
||||
if( placement == QskAspect::Top )
|
||||
{
|
||||
setSkinStateFlag( Top );
|
||||
image.load( ":/images/up.svg" );
|
||||
setGraphicSource( "up" );
|
||||
}
|
||||
else
|
||||
{
|
||||
image.load( ":/images/down.svg" );
|
||||
setGraphicSource( "down" );
|
||||
}
|
||||
|
||||
setGraphicSourceSize( image.size() );
|
||||
graphic = QskGraphic::fromImage( image );
|
||||
setGraphic( graphic );
|
||||
setGraphicSourceSize( graphic().defaultSize() * 1.2 );
|
||||
}
|
||||
|
@ -5,9 +5,6 @@
|
||||
|
||||
#include "RoundedIcon.h"
|
||||
|
||||
#include <QskGraphic.h>
|
||||
#include <QImage>
|
||||
|
||||
QSK_SUBCONTROL( RoundedIcon, Panel )
|
||||
QSK_SUBCONTROL( RoundedIcon, PalePanel )
|
||||
|
||||
@ -31,16 +28,4 @@ void RoundedIcon::setPale( bool on )
|
||||
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"
|
||||
|
@ -19,6 +19,5 @@ class RoundedIcon : public QskGraphicLabel
|
||||
|
||||
RoundedIcon( bool isBright, QQuickItem* parent = nullptr );
|
||||
|
||||
void setIcon( const QString& );
|
||||
void setPale( bool );
|
||||
};
|
||||
|
@ -1,5 +1,7 @@
|
||||
CONFIG += qskexample
|
||||
|
||||
QT += svg
|
||||
|
||||
SOURCES += \
|
||||
Box.cpp \
|
||||
BoxWithButtons.cpp \
|
||||
@ -7,6 +9,7 @@ SOURCES += \
|
||||
CircularProgressBarSkinlet.cpp \
|
||||
Diagram.cpp \
|
||||
DiagramSkinlet.cpp \
|
||||
GraphicProvider.cpp \
|
||||
LightIntensity.cpp \
|
||||
MainContent.cpp \
|
||||
MenuBar.cpp \
|
||||
@ -34,6 +37,7 @@ HEADERS += \
|
||||
CircularProgressBarSkinlet.h \
|
||||
Diagram.h \
|
||||
DiagramSkinlet.h \
|
||||
GraphicProvider.h \
|
||||
LightIntensity.h \
|
||||
MainContent.h \
|
||||
MainWindow.h \
|
||||
|
@ -4,6 +4,7 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include "GraphicProvider.h"
|
||||
#include "Skin.h"
|
||||
|
||||
#include <SkinnyFont.h>
|
||||
@ -62,6 +63,8 @@ int main( int argc, char* argv[] )
|
||||
|
||||
SkinnyFont::init( &app );
|
||||
|
||||
Qsk::addGraphicProvider( QString(), new GraphicProvider() );
|
||||
|
||||
// disable default skins
|
||||
qskSkinManager->setPluginPaths( QStringList() ); // no plugins
|
||||
qskSkinManager->unregisterFactory( "materialfactory" );
|
||||
|
Loading…
x
Reference in New Issue
Block a user