mirror of https://github.com/cutefishos/calamares
Merge branch '3.1.x-stable'
commit
c582ff0d6b
@ -0,0 +1,97 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2017, Adriaan de Groot <groot@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 PLASMALNF_THEMEINFO_H
|
||||
#define PLASMALNF_THEMEINFO_H
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
class KPluginMetaData;
|
||||
class ThemeWidget;
|
||||
|
||||
/** @brief describes a single plasma LnF theme.
|
||||
*
|
||||
* A theme description has an id, which is really the name of the desktop
|
||||
* file (e.g. org.kde.breeze.desktop), a name which is human-readable and
|
||||
* translated, and an optional image Page, which points to a local screenshot
|
||||
* of that theme.
|
||||
*/
|
||||
struct ThemeInfo
|
||||
{
|
||||
QString id;
|
||||
QString name;
|
||||
QString description;
|
||||
QString imagePath;
|
||||
ThemeWidget* widget;
|
||||
|
||||
ThemeInfo()
|
||||
: widget( nullptr )
|
||||
{}
|
||||
|
||||
explicit ThemeInfo( const QString& _id )
|
||||
: id( _id )
|
||||
, widget( nullptr )
|
||||
{
|
||||
}
|
||||
|
||||
explicit ThemeInfo( const QString& _id, const QString& image )
|
||||
: id( _id )
|
||||
, imagePath( image )
|
||||
, widget( nullptr )
|
||||
{}
|
||||
|
||||
// Defined in PlasmaLnfPage.cpp
|
||||
explicit ThemeInfo( const KPluginMetaData& );
|
||||
|
||||
bool isValid() const { return !id.isEmpty(); }
|
||||
} ;
|
||||
|
||||
class ThemeInfoList : public QList< ThemeInfo >
|
||||
{
|
||||
public:
|
||||
/** @brief Looks for a given @p id in the list of themes, returns nullptr if not found. */
|
||||
ThemeInfo* findById( const QString& id )
|
||||
{
|
||||
for ( ThemeInfo& i : *this )
|
||||
{
|
||||
if ( i.id == id )
|
||||
return &i;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/** @brief Looks for a given @p id in the list of themes, returns nullptr if not found. */
|
||||
const ThemeInfo* findById( const QString& id ) const
|
||||
{
|
||||
for ( const ThemeInfo& i : *this )
|
||||
{
|
||||
if ( i.id == id )
|
||||
return &i;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/** @brief Checks if a given @p id is in the list of themes. */
|
||||
bool contains( const QString& id ) const
|
||||
{
|
||||
return findById( id ) != nullptr;
|
||||
}
|
||||
} ;
|
||||
|
||||
#endif
|
@ -0,0 +1,85 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2017, Adriaan de Groot <groot@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 "ThemeWidget.h"
|
||||
|
||||
#include "ThemeInfo.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QRadioButton>
|
||||
|
||||
ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent)
|
||||
: QWidget( parent )
|
||||
, m_check( new QRadioButton( info.name.isEmpty() ? info.id : info.name, parent ) )
|
||||
, m_description( new QLabel( info.description, parent ) )
|
||||
, m_id( info.id )
|
||||
{
|
||||
QHBoxLayout* layout = new QHBoxLayout( this );
|
||||
this->setLayout( layout );
|
||||
|
||||
layout->addWidget( m_check, 1 );
|
||||
|
||||
constexpr QSize image_size{120, 80};
|
||||
|
||||
QPixmap image( info.imagePath );
|
||||
if ( info.imagePath.isEmpty() )
|
||||
{
|
||||
// Image can't possibly be valid
|
||||
image = QPixmap( ":/view-preview.png" );
|
||||
}
|
||||
else if ( image.isNull() )
|
||||
{
|
||||
// Not found or not specified, so convert the name into some (horrible, likely)
|
||||
// color instead.
|
||||
image = QPixmap( image_size );
|
||||
uint hash_color = qHash( info.imagePath.isEmpty() ? info.id : info.imagePath );
|
||||
cDebug() << "Theme image" << info.imagePath << "not found, hash" << hash_color;
|
||||
image.fill( QColor( QRgb( hash_color ) ) );
|
||||
}
|
||||
else
|
||||
image.scaled( image_size );
|
||||
|
||||
QLabel* image_label = new QLabel( this );
|
||||
image_label->setPixmap( image );
|
||||
layout->addWidget( image_label, 1 );
|
||||
layout->addWidget( m_description, 3 );
|
||||
|
||||
connect( m_check, &QRadioButton::clicked, this, &ThemeWidget::clicked );
|
||||
}
|
||||
|
||||
void
|
||||
ThemeWidget::clicked( bool checked )
|
||||
{
|
||||
if ( checked )
|
||||
emit themeSelected( m_id );
|
||||
}
|
||||
|
||||
QAbstractButton*
|
||||
ThemeWidget::button() const
|
||||
{
|
||||
return m_check;
|
||||
}
|
||||
|
||||
void ThemeWidget::updateThemeName(const ThemeInfo& info)
|
||||
{
|
||||
m_check->setText( info.name );
|
||||
m_description->setText( info.description );
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2017, Adriaan de Groot <groot@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 PLASMALNF_THEMEWIDGET_H
|
||||
#define PLASMALNF_THEMEWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QAbstractButton;
|
||||
class QLabel;
|
||||
class QRadioButton;
|
||||
|
||||
struct ThemeInfo;
|
||||
|
||||
class ThemeWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ThemeWidget( const ThemeInfo& info, QWidget* parent = nullptr );
|
||||
|
||||
QAbstractButton* button() const;
|
||||
|
||||
void updateThemeName( const ThemeInfo& info );
|
||||
|
||||
signals:
|
||||
void themeSelected( const QString& id );
|
||||
|
||||
public slots:
|
||||
void clicked( bool );
|
||||
|
||||
private:
|
||||
QString m_id;
|
||||
QRadioButton* m_check;
|
||||
QLabel* m_description;
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
@ -1 +1,5 @@
|
||||
<RCC/>
|
||||
<RCC>
|
||||
<qresource>
|
||||
<file>view-preview.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 560 B |
@ -0,0 +1,13 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
|
||||
<defs id="defs3051">
|
||||
<style type="text/css" id="current-color-scheme">
|
||||
.ColorScheme-Text {
|
||||
color:#4d4d4d;
|
||||
}
|
||||
</style>
|
||||
</defs>
|
||||
<path style="fill:currentColor;fill-opacity:1;stroke:none"
|
||||
d="m4 4v24h24v-24zm1 1h22v22h-22zm6 2a4 4 0 0 0 -4 4 4 4 0 0 0 4 4 4 4 0 0 0 4 -4 4 4 0 0 0 -4 -4m0 1a3 3 0 0 1 3 3 3 3 0 0 1 -3 3 3 3 0 0 1 -3 -3 3 3 0 0 1 3 -3m9.5 6.793l-5 5-2-2-6.5 6.5.707.707 5.793-5.793 2 2 5-5 3.793 3.793.707-.707z"
|
||||
class="ColorScheme-Text"
|
||||
/>
|
||||
</svg>
|
After Width: | Height: | Size: 570 B |
Loading…
Reference in New Issue