[plasmalnf] Give the themes a selected-state
- This kind of runs around the selection model on the view, but we're drawing radio buttons ourselves **anyway** and the list of themes knows which is selected / current independent of the view.
This commit is contained in:
parent
da4f8fffcf
commit
bcff0454a3
@ -98,6 +98,8 @@ Config::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
m_themeModel->showOnlyThemes( listedThemes );
|
m_themeModel->showOnlyThemes( listedThemes );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_themeModel->select( m_preselectThemeId );
|
||||||
}
|
}
|
||||||
|
|
||||||
Calamares::JobList
|
Calamares::JobList
|
||||||
@ -157,5 +159,6 @@ Config::setTheme( const QString& id )
|
|||||||
cDebug() << "Plasma look-and-feel applied" << id;
|
cDebug() << "Plasma look-and-feel applied" << id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_themeModel->select( id );
|
||||||
emit themeChanged( id );
|
emit themeChanged( id );
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,7 @@ ThemeDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, con
|
|||||||
{
|
{
|
||||||
auto label = index.data( ThemesModel::LabelRole ).toString();
|
auto label = index.data( ThemesModel::LabelRole ).toString();
|
||||||
auto description = index.data( ThemesModel::DescriptionRole ).toString();
|
auto description = index.data( ThemesModel::DescriptionRole ).toString();
|
||||||
|
auto selected = index.data( ThemesModel::SelectedRole ).toBool() ? QStyle::State_On : QStyle::State_Off;
|
||||||
auto image_v = index.data( ThemesModel::ImageRole );
|
auto image_v = index.data( ThemesModel::ImageRole );
|
||||||
QPixmap image = image_v.canConvert< QPixmap >() ? qvariant_cast< QPixmap >( image_v ) : QPixmap();
|
QPixmap image = image_v.canConvert< QPixmap >() ? qvariant_cast< QPixmap >( image_v ) : QPixmap();
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ ThemeDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, con
|
|||||||
labelRect.setWidth( labelRect.width() / 3 );
|
labelRect.setWidth( labelRect.width() / 3 );
|
||||||
|
|
||||||
QStyleOptionButton rbOption;
|
QStyleOptionButton rbOption;
|
||||||
rbOption.state |= QStyle::State_Enabled | QStyle::State_On;
|
rbOption.state |= QStyle::State_Enabled | selected;
|
||||||
rbOption.rect = labelRect;
|
rbOption.rect = labelRect;
|
||||||
rbOption.text = label;
|
rbOption.text = label;
|
||||||
option.widget->style()->drawControl( QStyle::CE_RadioButton, &rbOption, painter, option.widget );
|
option.widget->style()->drawControl( QStyle::CE_RadioButton, &rbOption, painter, option.widget );
|
||||||
|
@ -34,6 +34,7 @@ struct ThemeInfo
|
|||||||
QString imagePath;
|
QString imagePath;
|
||||||
mutable QPixmap pixmap;
|
mutable QPixmap pixmap;
|
||||||
bool show = true;
|
bool show = true;
|
||||||
|
bool selected = false;
|
||||||
|
|
||||||
ThemeInfo() {}
|
ThemeInfo() {}
|
||||||
|
|
||||||
@ -138,6 +139,8 @@ ThemesModel::data( const QModelIndex& index, int role ) const
|
|||||||
return item.id;
|
return item.id;
|
||||||
case ShownRole:
|
case ShownRole:
|
||||||
return item.show;
|
return item.show;
|
||||||
|
case SelectedRole:
|
||||||
|
return item.selected;
|
||||||
case DescriptionRole:
|
case DescriptionRole:
|
||||||
return item.description;
|
return item.description;
|
||||||
case ImageRole:
|
case ImageRole:
|
||||||
@ -151,7 +154,11 @@ ThemesModel::data( const QModelIndex& index, int role ) const
|
|||||||
QHash< int, QByteArray >
|
QHash< int, QByteArray >
|
||||||
ThemesModel::roleNames() const
|
ThemesModel::roleNames() const
|
||||||
{
|
{
|
||||||
return { { LabelRole, "label" }, { KeyRole, "key" }, { ShownRole, "show" }, { ImageRole, "image" } };
|
return { { LabelRole, "label" },
|
||||||
|
{ KeyRole, "key" },
|
||||||
|
{ SelectedRole, "selected" },
|
||||||
|
{ ShownRole, "show" },
|
||||||
|
{ ImageRole, "image" } };
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -219,6 +226,26 @@ ThemesModel::imageSize()
|
|||||||
qMax( 8 * CalamaresUtils::defaultFontHeight(), 80 ) };
|
qMax( 8 * CalamaresUtils::defaultFontHeight(), 80 ) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ThemesModel::select( const QString& themeId )
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
for ( auto& t : *m_themes )
|
||||||
|
{
|
||||||
|
if ( t.selected && t.id != themeId )
|
||||||
|
{
|
||||||
|
t.selected = false;
|
||||||
|
emit dataChanged( index( i, 0 ), index( i, 0 ), { SelectedRole } );
|
||||||
|
}
|
||||||
|
if ( !t.selected && t.id == themeId )
|
||||||
|
{
|
||||||
|
t.selected = true;
|
||||||
|
emit dataChanged( index( i, 0 ), index( i, 0 ), { SelectedRole } );
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Massage the given @p path to the most-likely
|
* Massage the given @p path to the most-likely
|
||||||
|
@ -25,7 +25,8 @@ public:
|
|||||||
{
|
{
|
||||||
LabelRole = Qt::DisplayRole,
|
LabelRole = Qt::DisplayRole,
|
||||||
KeyRole = Qt::UserRole,
|
KeyRole = Qt::UserRole,
|
||||||
ShownRole,
|
ShownRole, // Should theme be displayed
|
||||||
|
SelectedRole, // Is theme selected
|
||||||
DescriptionRole,
|
DescriptionRole,
|
||||||
ImageRole
|
ImageRole
|
||||||
};
|
};
|
||||||
@ -49,6 +50,15 @@ public:
|
|||||||
/// @brief Shows the keys in the @p onlyThese map, and hides the rest
|
/// @brief Shows the keys in the @p onlyThese map, and hides the rest
|
||||||
void showOnlyThemes( const QMap< QString, QString >& onlyThese );
|
void showOnlyThemes( const QMap< QString, QString >& onlyThese );
|
||||||
|
|
||||||
|
/** @brief Mark the @p themeId as current / selected
|
||||||
|
*
|
||||||
|
* One theme can be selected at a time; this will emit data
|
||||||
|
* changed signals for any (one) theme already selected, and
|
||||||
|
* the newly-selected theme. If @p themeId does not name any
|
||||||
|
* theme, none are selected.
|
||||||
|
*/
|
||||||
|
void select( const QString& themeId );
|
||||||
|
|
||||||
/** @brief The size of theme Images
|
/** @brief The size of theme Images
|
||||||
*
|
*
|
||||||
* The size is dependent on the font size used by Calamares,
|
* The size is dependent on the font size used by Calamares,
|
||||||
|
Loading…
Reference in New Issue
Block a user