From 757479f7f2b7ce6f074400ebeb5d85244f792aa1 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Tue, 25 Jul 2017 11:33:33 +0200 Subject: [PATCH] hmi-demo top layout code simplified --- examples/hmi-demo/MainWindow.cpp | 109 +++++++++++++++++-------------- examples/hmi-demo/MainWindow.h | 12 ++-- 2 files changed, 66 insertions(+), 55 deletions(-) diff --git a/examples/hmi-demo/MainWindow.cpp b/examples/hmi-demo/MainWindow.cpp index c7d07a54..75f93860 100644 --- a/examples/hmi-demo/MainWindow.cpp +++ b/examples/hmi-demo/MainWindow.cpp @@ -5,24 +5,42 @@ #include #include #include -#include -#include #include #include -#include +#include 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 ); - buildLabel->setFixedSize( 76, 36 ); - buildLabel->setMargins( QMarginsF( 20, 7, 20, 7 ) ); - buildLabel->setGraphic( QskGraphic::fromImage( buildIcon ) ); - } + setSizePolicy( QskSizePolicy::MinimumExpanding, QskSizePolicy::Fixed ); + } + + 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() @@ -30,69 +48,62 @@ MainWindow::MainWindow() setPreferredSize( QSize( 1024, 576 ) ); setAutoLayoutChildren( true ); - // later: -// QFont font( "Roboto" ); -// font.setPointSize( 20 ); -// setFont( QskSkin::DefaultFont, 20 ); + populate(); +} +void MainWindow::populate() +{ const QImage image( ":/images/background.jpg" ); auto backgroundImage = new QskGraphicLabel( contentItem() ); backgroundImage->setGraphic( QskGraphic::fromImage( image ) ); backgroundImage->setFillMode( QskGraphicLabel::Stretch ); - m_layout = new QskLinearBox( Qt::Vertical, contentItem() ); - m_layout->setAutoAddChildren( true ); + auto header = headerBar(); + auto content = mainContent(); + auto footer = footerBar(); - addHeaderBar(); - addMainContent(); - addBottomBar(); + auto layout = new QskLinearBox( Qt::Vertical, contentItem() ); + + layout->addItem( header ); + layout->addItem( content ); + layout->addItem( footer ); } -void MainWindow::addHeaderBar() +QQuickItem* MainWindow::headerBar() const { - QskLinearBox* header = new QskLinearBox( m_layout ); - header->setOpacity( 0.5 ); - header->setBackgroundColor( Qt::black ); - header->setFixedHeight( 50 ); - header->setMargins( QMarginsF( 20, 0, 20, 0 ) ); + auto* header = new ButtonBar(); + header->addIcon( "ic_pan_tool_white_48dp_2x.png" ); + header->addIcon( "ic_star_rate_white_18dp_2x.png" ); + header->addIcon( "ic_airplanemode_active_white_18dp_2x.png" ); - addIcon( header, ":/images/ic_pan_tool_white_48dp_2x.png" ); - 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 ); + auto dateLabel = new QskTextLabel( QDate::currentDate().toString(), header ); dateLabel->setColor( QskTextLabel::Text, Qt::white ); - addIcon( header, ":/images/ic_face_white_48px.svg" ); - addIcon( header, ":/images/ic_extension_white_48dp_2x.png" ); - addIcon( header, ":/images/ic_build_white_24dp_2x.png" ); + header->addIcon( "ic_face_white_48px.svg" ); + header->addIcon( "ic_extension_white_48dp_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 ); // m_layout->setRetainSizeWhenHidden( radioControl, true ); // 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 ); - bottomBar->setEnabled( false ); - bottomBar->setPosition( QPointF( 0, 0 ) ); - bottomBar->setOpacity( 0.5 ); - bottomBar->setBackgroundColor( Qt::black ); - bottomBar->setFixedHeight( 50 ); - bottomBar->setFlat( true ); + auto* footer = new ButtonBar(); - QskLinearBox* bottomLayout = new QskLinearBox( bottomBar ); - bottomLayout->setMargins( QMarginsF( 20, 0, 20, 0 ) ); + footer->addIcon( "ic_pan_tool_white_48dp_2x.png" ); + 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" ); - addIcon( bottomLayout, ":/images/ic_star_rate_white_18dp_2x.png" ); - addIcon( bottomLayout, ":/images/ic_airplanemode_active_white_18dp_2x.png" ); + return footer; } diff --git a/examples/hmi-demo/MainWindow.h b/examples/hmi-demo/MainWindow.h index 3cfdee53..b73bcf0e 100644 --- a/examples/hmi-demo/MainWindow.h +++ b/examples/hmi-demo/MainWindow.h @@ -3,7 +3,7 @@ #include -class QskLinearBox; +class QQuickItem; class MainWindow : public QskWindow { @@ -11,11 +11,11 @@ public: MainWindow(); private: - void addHeaderBar(); - void addMainContent(); - void addBottomBar(); + void populate(); - QskLinearBox* m_layout; + QQuickItem* headerBar() const; + QQuickItem* mainContent() const; + QQuickItem* footerBar() const; }; -#endif // MAINWINDOW_H +#endif