Merge branch 'wip/install-step2'

This commit is contained in:
Aurélien Gâteau 2014-07-08 16:09:08 +02:00
commit bb796ecdb0
13 changed files with 197 additions and 55 deletions

View File

@ -11,11 +11,11 @@ set( calamaresSources
CalamaresApplication.cpp CalamaresApplication.cpp
CalamaresWindow.cpp CalamaresWindow.cpp
progresstree/CategoryItem.cpp
progresstree/ProgressTreeDelegate.cpp progresstree/ProgressTreeDelegate.cpp
progresstree/ProgressTreeItem.cpp progresstree/ProgressTreeItem.cpp
progresstree/ProgressTreeModel.cpp progresstree/ProgressTreeModel.cpp
progresstree/ProgressTreeView.cpp progresstree/ProgressTreeView.cpp
progresstree/TextTreeItem.cpp
progresstree/ViewStepItem.cpp progresstree/ViewStepItem.cpp
) )

View File

@ -44,19 +44,18 @@ QSize
ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option, ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option,
const QModelIndex& index ) const const QModelIndex& index ) const
{ {
ProgressTreeModel::RowType type = if ( !index.isValid() )
static_cast< ProgressTreeModel::RowType >(
index.data( ProgressTreeModel::ProgressTreeItemTypeRole ).toInt() );
if ( type == ProgressTreeModel::Invalid )
return option.rect.size(); return option.rect.size();
bool isFirstLevel = !index.parent().isValid();
QFont font = qApp->font(); QFont font = qApp->font();
if ( type == ProgressTreeModel::Category ) if ( isFirstLevel )
{ {
font.setPointSize( CAT_FONTSIZE ); font.setPointSize( CAT_FONTSIZE );
} }
else if ( type == ProgressTreeModel::ViewStep ) else
{ {
font.setPointSize( VS_FONTSIZE ); font.setPointSize( VS_FONTSIZE );
} }
@ -74,25 +73,21 @@ ProgressTreeDelegate::paint( QPainter* painter,
const QStyleOptionViewItem& option, const QStyleOptionViewItem& option,
const QModelIndex& index) const const QModelIndex& index) const
{ {
bool isFirstLevel = !index.parent().isValid();
QStyleOptionViewItemV4 opt = option; QStyleOptionViewItemV4 opt = option;
painter->save(); painter->save();
ProgressTreeModel::RowType type =
static_cast< ProgressTreeModel::RowType >(
index.data( ProgressTreeModel::ProgressTreeItemTypeRole ).toInt() );
if ( type == ProgressTreeModel::Invalid )
return;
initStyleOption( &opt, index ); initStyleOption( &opt, index );
opt.text.clear(); opt.text.clear();
painter->setBrush( CalamaresStyle::SIDEBAR_BACKGROUND ); painter->setBrush( CalamaresStyle::SIDEBAR_BACKGROUND );
painter->setPen( CalamaresStyle::SIDEBAR_TEXT ); painter->setPen( CalamaresStyle::SIDEBAR_TEXT );
if ( type == ProgressTreeModel::Category ) if ( isFirstLevel )
paintCategory( painter, opt, index ); paintCategory( painter, opt, index );
else if ( type == ProgressTreeModel::ViewStep ) else
paintViewStep( painter, opt, index ); paintViewStep( painter, opt, index );
painter->restore(); painter->restore();
@ -109,9 +104,12 @@ ProgressTreeDelegate::paintCategory( QPainter* painter,
ITEM_MARGIN, ITEM_MARGIN,
ITEM_MARGIN ); ITEM_MARGIN );
bool isCurrent = index.data( ProgressTreeModel::ProgressTreeItemCurrentRole ).toBool();
QFont font = qApp->font(); QFont font = qApp->font();
font.setPointSize( CAT_FONTSIZE ); font.setPointSize( CAT_FONTSIZE );
font.setBold( false ); font.setBold( false );
font.setUnderline( isCurrent ); // FIXME: Figure out a nicer way to highlight the current category step
painter->setFont( font ); painter->setFont( font );
painter->drawText( textRect, index.data().toString() ); painter->drawText( textRect, index.data().toString() );

View File

@ -86,8 +86,6 @@ ProgressTreeRoot::ProgressTreeRoot()
QVariant QVariant
ProgressTreeRoot::data( int role ) const ProgressTreeRoot::data( int role ) const
{ {
if ( role == ProgressTreeModel::ProgressTreeItemTypeRole )
return ProgressTreeModel::Invalid;
if ( role == ProgressTreeModel::ProgressTreeItemRole ) if ( role == ProgressTreeModel::ProgressTreeItemRole )
return this; return this;
return QVariant(); return QVariant();

View File

@ -18,7 +18,7 @@
#include "ProgressTreeModel.h" #include "ProgressTreeModel.h"
#include "progresstree/CategoryItem.h" #include "progresstree/TextTreeItem.h"
#include "progresstree/ViewStepItem.h" #include "progresstree/ViewStepItem.h"
#include "ViewManager.h" #include "ViewManager.h"
@ -133,16 +133,16 @@ ProgressTreeModel::setupModelData()
m_rootItem = new ProgressTreeRoot(); m_rootItem = new ProgressTreeRoot();
const Calamares::ViewManager* vm = Calamares::ViewManager::instance(); const Calamares::ViewManager* vm = Calamares::ViewManager::instance();
CategoryItem* prepare = new CategoryItem( tr( "Prepare" ), m_rootItem ); TextTreeItem* prepare = new TextTreeItem( tr( "Prepare" ), m_rootItem );
m_rootItem->appendChild( prepare ); m_rootItem->appendChild( prepare );
foreach ( const Calamares::ViewStep* step, vm->steps() ) foreach ( const Calamares::ViewStep* step, vm->prepareSteps() )
{ {
prepare->appendChild( new ViewStepItem( step, prepare ) ); prepare->appendChild( new ViewStepItem( step, prepare ) );
} }
m_rootItem->appendChild( new CategoryItem( tr( "Install" ), m_rootItem ) ); m_rootItem->appendChild( new ViewStepItem( vm->installationStep(), m_rootItem ) );
m_rootItem->appendChild( new CategoryItem( tr( "Finish" ), m_rootItem ) ); m_rootItem->appendChild( new TextTreeItem( tr( "Finish" ), m_rootItem ) );
} }

View File

@ -28,18 +28,10 @@ class ProgressTreeModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
public: public:
enum RowType
{
Invalid = -1,
Category = 0,
ViewStep = 1
};
enum Role enum Role
{ {
ProgressTreeItemRole = Qt::UserRole + 10, ProgressTreeItemRole = Qt::UserRole + 10,
ProgressTreeItemTypeRole = Qt::UserRole + 11, ProgressTreeItemCurrentRole = Qt::UserRole + 11
ProgressTreeItemCurrentRole = Qt::UserRole + 12
}; };
explicit ProgressTreeModel( QObject* parent = nullptr ); explicit ProgressTreeModel( QObject* parent = nullptr );

View File

@ -16,21 +16,19 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "CategoryItem.h" #include "TextTreeItem.h"
#include "ProgressTreeModel.h" #include "ProgressTreeModel.h"
CategoryItem::CategoryItem( const QString& text, ProgressTreeItem* parent ) TextTreeItem::TextTreeItem( const QString& text, ProgressTreeItem* parent )
: ProgressTreeItem( parent ) : ProgressTreeItem( parent )
, m_text( text ) , m_text( text )
{} {}
QVariant QVariant
CategoryItem::data( int role ) const TextTreeItem::data( int role ) const
{ {
if ( role == ProgressTreeModel::ProgressTreeItemTypeRole )
return ProgressTreeModel::Category;
if ( role == ProgressTreeModel::ProgressTreeItemRole ) if ( role == ProgressTreeModel::ProgressTreeItemRole )
return this; return this;
if ( role == Qt::DisplayRole ) if ( role == Qt::DisplayRole )

View File

@ -16,16 +16,16 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CATEGORYITEM_H #ifndef TEXTTREEITEM_H
#define CATEGORYITEM_H #define TEXTTREEITEM_H
#include "ProgressTreeItem.h" #include "ProgressTreeItem.h"
class CategoryItem : public ProgressTreeItem class TextTreeItem : public ProgressTreeItem
{ {
public: public:
explicit CategoryItem( const QString& text, ProgressTreeItem* parent = nullptr ); explicit TextTreeItem( const QString& text, ProgressTreeItem* parent = nullptr );
virtual QVariant data( int role ) const override; virtual QVariant data( int role ) const override;
@ -33,4 +33,4 @@ private:
QString m_text; QString m_text;
}; };
#endif // CATEGORYITEM_H #endif // TEXTTREEITEM_H

View File

@ -40,8 +40,6 @@ ViewStepItem::appendChild( ProgressTreeItem* item )
QVariant QVariant
ViewStepItem::data( int role ) const ViewStepItem::data( int role ) const
{ {
if ( role == ProgressTreeModel::ProgressTreeItemTypeRole )
return ProgressTreeModel::ViewStep;
if ( role == ProgressTreeModel::ProgressTreeItemRole ) if ( role == ProgressTreeModel::ProgressTreeItemRole )
return this; return this;
if ( role == Qt::DisplayRole ) if ( role == Qt::DisplayRole )

View File

@ -11,6 +11,7 @@ list( APPEND ${CALAMARESUI_LIBRARY_TARGET}_SOURCES
viewpages/AbstractPage.cpp viewpages/AbstractPage.cpp
viewpages/ViewStep.cpp viewpages/ViewStep.cpp
InstallationViewStep.cpp
Settings.cpp Settings.cpp
ViewManager.cpp ViewManager.cpp
) )

View File

@ -0,0 +1,79 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include <InstallationViewStep.h>
#include <QLabel>
namespace Calamares
{
InstallationViewStep::InstallationViewStep( QObject* parent )
: ViewStep( parent )
, m_widget( new QLabel( "[Installation Progress]" ) )
{
}
QString
InstallationViewStep::prettyName() const
{
return tr( "Install" );
}
QWidget*
InstallationViewStep::widget()
{
return m_widget;
}
void
InstallationViewStep::next()
{
}
void
InstallationViewStep::back()
{
}
bool
InstallationViewStep::isNextEnabled() const
{
return false;
}
bool
InstallationViewStep::isAtBeginning() const
{
return false;
}
bool
InstallationViewStep::isAtEnd() const
{
return false;
}
QList< Calamares::job_ptr >
InstallationViewStep::jobs() const
{
return QList< Calamares::job_ptr >();
}
} // namespace

View File

@ -0,0 +1,52 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INSTALLATIONVIEWSTEP_H
#define INSTALLATIONVIEWSTEP_H
#include <viewpages/ViewStep.h>
namespace Calamares
{
class InstallationViewStep : public ViewStep
{
public:
explicit InstallationViewStep( QObject* parent = nullptr );
QString prettyName() const override;
QWidget* widget() override;
void next() override;
void back() override;
bool isNextEnabled() const override;
bool isAtBeginning() const override;
bool isAtEnd() const override;
QList< Calamares::job_ptr > jobs() const override;
private:
QWidget* m_widget;
};
}
#endif /* INSTALLATIONVIEWSTEP_H */

View File

@ -19,6 +19,7 @@
#include "ViewManager.h" #include "ViewManager.h"
#include "viewpages/ViewStep.h" #include "viewpages/ViewStep.h"
#include "InstallationViewStep.h"
#include <QApplication> #include <QApplication>
#include <QLabel> #include <QLabel>
@ -64,6 +65,9 @@ ViewManager::ViewManager( QObject* parent )
connect( m_next, &QPushButton::clicked, this, &ViewManager::next ); connect( m_next, &QPushButton::clicked, this, &ViewManager::next );
connect( m_back, &QPushButton::clicked, this, &ViewManager::back ); connect( m_back, &QPushButton::clicked, this, &ViewManager::back );
m_back->setEnabled( false ); m_back->setEnabled( false );
m_installationViewStep = new InstallationViewStep( this );
insertViewStep( 0, m_installationViewStep );
} }
@ -83,26 +87,41 @@ ViewManager::centralWidget()
void void
ViewManager::addViewStep( ViewStep* step ) ViewManager::addViewStep( ViewStep* step )
{ {
step->setParent( this ); m_prepareSteps.append( step );
m_steps.append( step );
insertViewStep( m_steps.size() - 1, step );
}
void
ViewManager::insertViewStep( int before, ViewStep* step)
{
m_steps.insert( before, step );
QLayout* layout = step->widget()->layout(); QLayout* layout = step->widget()->layout();
if ( layout ) if ( layout )
{ {
layout->setContentsMargins( 0, 0, 0, 0 ); layout->setContentsMargins( 0, 0, 0, 0 );
} }
m_stack->addWidget( step->widget() ); m_stack->insertWidget( before, step->widget() );
connect( step, &ViewStep::nextStatusChanged, connect( step, &ViewStep::nextStatusChanged,
m_next, &QPushButton::setEnabled ); m_next, &QPushButton::setEnabled );
emit currentStepChanged(); m_stack->setCurrentIndex( 0 );
} }
QList< ViewStep* > QList< ViewStep* >
ViewManager::steps() const ViewManager::prepareSteps() const
{ {
return m_steps; return m_prepareSteps;
}
ViewStep*
ViewManager::installationStep() const
{
return m_installationViewStep;
} }
@ -124,20 +143,21 @@ void
ViewManager::next() ViewManager::next()
{ {
ViewStep* step = m_steps.at( m_currentStep ); ViewStep* step = m_steps.at( m_currentStep );
if ( step->isAtEnd() && m_currentStep < m_steps.length() -1 ) bool installing = false;
if ( step->isAtEnd() )
{ {
m_currentStep++; m_currentStep++;
m_stack->setCurrentIndex( m_currentStep ); m_stack->setCurrentIndex( m_currentStep );
installing = m_steps.at( m_currentStep ) == m_installationViewStep;
emit currentStepChanged(); emit currentStepChanged();
} }
else if ( !step->isAtEnd() ) else
{ {
step->next(); step->next();
} }
else return;
m_next->setEnabled( m_steps.at( m_currentStep )->isNextEnabled() ); m_next->setEnabled( !installing && m_steps.at( m_currentStep )->isNextEnabled() );
m_back->setEnabled( true ); m_back->setEnabled( !installing );
} }

View File

@ -30,6 +30,7 @@ namespace Calamares
{ {
class ViewStep; class ViewStep;
class InstallationViewStep;
class UIDLLEXPORT ViewManager : public QObject class UIDLLEXPORT ViewManager : public QObject
{ {
@ -44,7 +45,8 @@ public:
void addViewStep( ViewStep* step ); void addViewStep( ViewStep* step );
QList< ViewStep* > steps() const; QList< ViewStep* > prepareSteps() const;
ViewStep* installationStep() const;
ViewStep* currentStep() const; ViewStep* currentStep() const;
int currentStepIndex() const; int currentStepIndex() const;
@ -59,6 +61,8 @@ private:
static ViewManager* s_instance; static ViewManager* s_instance;
QList< ViewStep* > m_steps; QList< ViewStep* > m_steps;
QList< ViewStep* > m_prepareSteps;
InstallationViewStep* m_installationViewStep;
int m_currentStep; int m_currentStep;
QWidget* m_widget; QWidget* m_widget;
@ -66,6 +70,8 @@ private:
QPushButton* m_back; QPushButton* m_back;
QPushButton* m_next; QPushButton* m_next;
QPushButton* m_quit; QPushButton* m_quit;
void insertViewStep( int before, ViewStep* step );
}; };
} }