hmi-demo top layout code simplified
This commit is contained in:
parent
d3be6aaa27
commit
757479f7f2
@ -5,24 +5,42 @@
|
|||||||
#include <QskGraphic.h>
|
#include <QskGraphic.h>
|
||||||
#include <QskGraphicLabel.h>
|
#include <QskGraphicLabel.h>
|
||||||
#include <QskLinearBox.h>
|
#include <QskLinearBox.h>
|
||||||
#include <QskPushButton.h>
|
|
||||||
#include <QskSkin.h>
|
|
||||||
#include <QskTextLabel.h>
|
#include <QskTextLabel.h>
|
||||||
|
|
||||||
#include <QDate>
|
#include <QDate>
|
||||||
#include <QTimer>
|
#include <QImage>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
void addIcon( QskLayout* layout, const QString& fileName )
|
class ButtonBar : public QskLinearBox
|
||||||
{
|
{
|
||||||
const QImage buildIcon( fileName );
|
public:
|
||||||
|
ButtonBar( QQuickItem* parentItem = nullptr ):
|
||||||
|
QskLinearBox( parentItem )
|
||||||
|
{
|
||||||
|
setOpacity( 0.5 );
|
||||||
|
setBackgroundColor( Qt::black );
|
||||||
|
setMargins( QMarginsF( 20, 0, 20, 0 ) );
|
||||||
|
|
||||||
QskGraphicLabel* buildLabel = new QskGraphicLabel( layout );
|
setSizePolicy( QskSizePolicy::MinimumExpanding, QskSizePolicy::Fixed );
|
||||||
buildLabel->setFixedSize( 76, 36 );
|
}
|
||||||
buildLabel->setMargins( QMarginsF( 20, 7, 20, 7 ) );
|
|
||||||
buildLabel->setGraphic( QskGraphic::fromImage( buildIcon ) );
|
void addIcon( const char* name )
|
||||||
}
|
{
|
||||||
|
const QString fileName = QString( ":/images/%1" ).arg( name );
|
||||||
|
|
||||||
|
auto* label = new QskGraphicLabel( this );
|
||||||
|
label->setFixedSize( 76, 36 );
|
||||||
|
label->setMargins( QMarginsF( 20, 7, 20, 7 ) );
|
||||||
|
label->setGraphic( QskGraphic::fromImage( QImage( fileName ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual QSizeF contentsSizeHint() const override final
|
||||||
|
{
|
||||||
|
return QSizeF( -1, 50 );
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::MainWindow()
|
MainWindow::MainWindow()
|
||||||
@ -30,69 +48,62 @@ MainWindow::MainWindow()
|
|||||||
setPreferredSize( QSize( 1024, 576 ) );
|
setPreferredSize( QSize( 1024, 576 ) );
|
||||||
setAutoLayoutChildren( true );
|
setAutoLayoutChildren( true );
|
||||||
|
|
||||||
// later:
|
populate();
|
||||||
// QFont font( "Roboto" );
|
}
|
||||||
// font.setPointSize( 20 );
|
|
||||||
// setFont( QskSkin::DefaultFont, 20 );
|
|
||||||
|
|
||||||
|
void MainWindow::populate()
|
||||||
|
{
|
||||||
const QImage image( ":/images/background.jpg" );
|
const QImage image( ":/images/background.jpg" );
|
||||||
|
|
||||||
auto backgroundImage = new QskGraphicLabel( contentItem() );
|
auto backgroundImage = new QskGraphicLabel( contentItem() );
|
||||||
backgroundImage->setGraphic( QskGraphic::fromImage( image ) );
|
backgroundImage->setGraphic( QskGraphic::fromImage( image ) );
|
||||||
backgroundImage->setFillMode( QskGraphicLabel::Stretch );
|
backgroundImage->setFillMode( QskGraphicLabel::Stretch );
|
||||||
|
|
||||||
m_layout = new QskLinearBox( Qt::Vertical, contentItem() );
|
auto header = headerBar();
|
||||||
m_layout->setAutoAddChildren( true );
|
auto content = mainContent();
|
||||||
|
auto footer = footerBar();
|
||||||
|
|
||||||
addHeaderBar();
|
auto layout = new QskLinearBox( Qt::Vertical, contentItem() );
|
||||||
addMainContent();
|
|
||||||
addBottomBar();
|
layout->addItem( header );
|
||||||
|
layout->addItem( content );
|
||||||
|
layout->addItem( footer );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::addHeaderBar()
|
QQuickItem* MainWindow::headerBar() const
|
||||||
{
|
{
|
||||||
QskLinearBox* header = new QskLinearBox( m_layout );
|
auto* header = new ButtonBar();
|
||||||
header->setOpacity( 0.5 );
|
header->addIcon( "ic_pan_tool_white_48dp_2x.png" );
|
||||||
header->setBackgroundColor( Qt::black );
|
header->addIcon( "ic_star_rate_white_18dp_2x.png" );
|
||||||
header->setFixedHeight( 50 );
|
header->addIcon( "ic_airplanemode_active_white_18dp_2x.png" );
|
||||||
header->setMargins( QMarginsF( 20, 0, 20, 0 ) );
|
|
||||||
|
|
||||||
addIcon( header, ":/images/ic_pan_tool_white_48dp_2x.png" );
|
auto dateLabel = new QskTextLabel( QDate::currentDate().toString(), header );
|
||||||
addIcon( header, ":/images/ic_star_rate_white_18dp_2x.png" );
|
|
||||||
addIcon( header, ":/images/ic_airplanemode_active_white_18dp_2x.png" );
|
|
||||||
|
|
||||||
QDate currentDate = QDate::currentDate();
|
|
||||||
QskTextLabel* dateLabel = new QskTextLabel( currentDate.toString(), header );
|
|
||||||
dateLabel->setColor( QskTextLabel::Text, Qt::white );
|
dateLabel->setColor( QskTextLabel::Text, Qt::white );
|
||||||
|
|
||||||
addIcon( header, ":/images/ic_face_white_48px.svg" );
|
header->addIcon( "ic_face_white_48px.svg" );
|
||||||
addIcon( header, ":/images/ic_extension_white_48dp_2x.png" );
|
header->addIcon( "ic_extension_white_48dp_2x.png" );
|
||||||
addIcon( header, ":/images/ic_build_white_24dp_2x.png" );
|
header->addIcon( "ic_build_white_24dp_2x.png" );
|
||||||
|
|
||||||
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::addMainContent()
|
QQuickItem* MainWindow::mainContent() const
|
||||||
{
|
{
|
||||||
// RadioControl* radioControl = new RadioControl( m_layout );
|
// RadioControl* radioControl = new RadioControl( m_layout );
|
||||||
// m_layout->setRetainSizeWhenHidden( radioControl, true );
|
// m_layout->setRetainSizeWhenHidden( radioControl, true );
|
||||||
// radioControl->setVisible( false );
|
// radioControl->setVisible( false );
|
||||||
|
|
||||||
SoundControl* soundControl = new SoundControl( m_layout );
|
return new SoundControl();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::addBottomBar()
|
QQuickItem* MainWindow::footerBar() const
|
||||||
{
|
{
|
||||||
QskPushButton* bottomBar = new QskPushButton( m_layout );
|
auto* footer = new ButtonBar();
|
||||||
bottomBar->setEnabled( false );
|
|
||||||
bottomBar->setPosition( QPointF( 0, 0 ) );
|
|
||||||
bottomBar->setOpacity( 0.5 );
|
|
||||||
bottomBar->setBackgroundColor( Qt::black );
|
|
||||||
bottomBar->setFixedHeight( 50 );
|
|
||||||
bottomBar->setFlat( true );
|
|
||||||
|
|
||||||
QskLinearBox* bottomLayout = new QskLinearBox( bottomBar );
|
footer->addIcon( "ic_pan_tool_white_48dp_2x.png" );
|
||||||
bottomLayout->setMargins( QMarginsF( 20, 0, 20, 0 ) );
|
footer->addIcon( "ic_star_rate_white_18dp_2x.png" );
|
||||||
|
footer->addIcon( "ic_airplanemode_active_white_18dp_2x.png" );
|
||||||
|
footer->addStretch( 10 );
|
||||||
|
|
||||||
addIcon( bottomLayout, ":/images/ic_pan_tool_white_48dp_2x.png" );
|
return footer;
|
||||||
addIcon( bottomLayout, ":/images/ic_star_rate_white_18dp_2x.png" );
|
|
||||||
addIcon( bottomLayout, ":/images/ic_airplanemode_active_white_18dp_2x.png" );
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <QskWindow.h>
|
#include <QskWindow.h>
|
||||||
|
|
||||||
class QskLinearBox;
|
class QQuickItem;
|
||||||
|
|
||||||
class MainWindow : public QskWindow
|
class MainWindow : public QskWindow
|
||||||
{
|
{
|
||||||
@ -11,11 +11,11 @@ public:
|
|||||||
MainWindow();
|
MainWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addHeaderBar();
|
void populate();
|
||||||
void addMainContent();
|
|
||||||
void addBottomBar();
|
|
||||||
|
|
||||||
QskLinearBox* m_layout;
|
QQuickItem* headerBar() const;
|
||||||
|
QQuickItem* mainContent() const;
|
||||||
|
QQuickItem* footerBar() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user