2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2014-07-01 11:48:10 +02:00
|
|
|
*
|
2015-04-02 12:49:40 +02:00
|
|
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
2018-06-15 11:59:11 +02:00
|
|
|
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
|
2014-07-01 11:48:10 +02:00
|
|
|
*
|
|
|
|
* 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 CALAMARESUTILSGUI_H
|
|
|
|
#define CALAMARESUTILSGUI_H
|
|
|
|
|
|
|
|
#include "utils/CalamaresUtils.h"
|
|
|
|
#include "UiDllMacro.h"
|
|
|
|
|
2018-12-14 10:52:55 +01:00
|
|
|
#include <QObject>
|
2014-08-26 15:18:30 +02:00
|
|
|
#include <QPixmap>
|
2014-07-08 13:22:09 +02:00
|
|
|
#include <QSize>
|
|
|
|
|
2014-07-01 11:48:10 +02:00
|
|
|
class QLayout;
|
|
|
|
|
|
|
|
namespace CalamaresUtils
|
|
|
|
{
|
2017-03-01 13:34:48 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The ImageType enum lists all common Calamares icons.
|
|
|
|
* Icons are loaded from SVGs and cached. Each icon has an enum value, through which
|
|
|
|
* it can be accessed.
|
|
|
|
* You can forward-declare this as:
|
|
|
|
* enum ImageType : int;
|
|
|
|
*/
|
2014-12-16 15:22:33 +01:00
|
|
|
enum ImageType : int
|
2014-08-26 15:18:30 +02:00
|
|
|
{
|
|
|
|
Yes,
|
2014-08-26 18:21:16 +02:00
|
|
|
No,
|
|
|
|
Information,
|
2014-09-03 18:00:47 +02:00
|
|
|
Fail,
|
2015-04-02 12:49:40 +02:00
|
|
|
Bugs,
|
|
|
|
Help,
|
2015-04-02 14:03:12 +02:00
|
|
|
Release,
|
2015-04-03 11:57:01 +02:00
|
|
|
PartitionDisk,
|
|
|
|
PartitionPartition,
|
2015-04-02 14:03:12 +02:00
|
|
|
PartitionAlongside,
|
|
|
|
PartitionEraseAuto,
|
|
|
|
PartitionManual,
|
2015-06-16 02:38:07 +02:00
|
|
|
PartitionReplaceOs,
|
2015-11-27 17:25:16 +01:00
|
|
|
PartitionTable,
|
|
|
|
BootEnvironment,
|
2017-11-20 14:45:54 +01:00
|
|
|
Squid,
|
|
|
|
StatusOk, // Icons for the requirements checker
|
|
|
|
StatusWarning,
|
|
|
|
StatusError
|
2014-08-26 15:18:30 +02:00
|
|
|
};
|
|
|
|
|
2017-03-01 13:34:48 +01:00
|
|
|
/**
|
|
|
|
* @brief The ImageMode enum contains different transformations that can be applied.
|
|
|
|
* Most of these are currently unused.
|
|
|
|
*/
|
2014-08-26 15:18:30 +02:00
|
|
|
enum ImageMode
|
|
|
|
{
|
|
|
|
Original,
|
|
|
|
CoverInCase,
|
|
|
|
Grid,
|
|
|
|
DropShadow,
|
|
|
|
RoundedCorners
|
|
|
|
};
|
|
|
|
|
2017-03-01 13:34:48 +01:00
|
|
|
/**
|
|
|
|
* @brief defaultPixmap returns a resized and/or transformed pixmap for a given
|
|
|
|
* ImageType.
|
|
|
|
* @param type the ImageType i.e. the enum value for an SVG.
|
|
|
|
* @param mode the transformation to apply (default: no transformation).
|
|
|
|
* @param size the target pixmap size (default: original SVG size).
|
|
|
|
* @return the new pixmap.
|
|
|
|
*/
|
|
|
|
UIDLLEXPORT QPixmap defaultPixmap( ImageType type,
|
|
|
|
ImageMode mode = CalamaresUtils::Original,
|
|
|
|
const QSize& size = QSize( 0, 0 ) );
|
2014-07-01 11:48:10 +02:00
|
|
|
|
2017-03-01 13:34:48 +01:00
|
|
|
/**
|
|
|
|
* @brief createRoundedImage returns a rounded version of a pixmap.
|
|
|
|
* @param avatar the input pixmap.
|
|
|
|
* @param size the new size.
|
|
|
|
* @param frameWidthPct the frame size, as percentage of width.
|
|
|
|
* @return the transformed pixmap.
|
|
|
|
* This one is currently unused.
|
|
|
|
*/
|
|
|
|
UIDLLEXPORT QPixmap createRoundedImage( const QPixmap& avatar,
|
|
|
|
const QSize& size,
|
2017-06-27 12:08:07 +02:00
|
|
|
float frameWidthPct = 0.20f );
|
2017-03-01 13:34:48 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief unmarginLayout recursively walks the QLayout tree and removes all margins.
|
|
|
|
* @param layout the layout to unmargin.
|
|
|
|
*/
|
2014-07-01 11:48:10 +02:00
|
|
|
UIDLLEXPORT void unmarginLayout( QLayout* layout );
|
2017-03-01 13:34:48 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief clearLayout recursively walks the QLayout tree and deletes all the child
|
|
|
|
* widgets and layouts.
|
|
|
|
* @param layout the layout to clear.
|
|
|
|
*/
|
2015-09-11 18:45:56 +02:00
|
|
|
UIDLLEXPORT void clearLayout( QLayout* layout );
|
2014-07-01 11:48:10 +02:00
|
|
|
|
2014-08-26 15:18:30 +02:00
|
|
|
UIDLLEXPORT void setDefaultFontSize( int points );
|
2017-03-01 13:34:48 +01:00
|
|
|
UIDLLEXPORT int defaultFontSize(); // in points
|
|
|
|
UIDLLEXPORT int defaultFontHeight(); // in pixels, DPI-specific
|
2015-12-02 15:40:55 +01:00
|
|
|
UIDLLEXPORT QFont defaultFont();
|
2018-06-13 19:31:00 +02:00
|
|
|
UIDLLEXPORT QFont largeFont();
|
2014-08-26 15:18:30 +02:00
|
|
|
UIDLLEXPORT QSize defaultIconSize();
|
2014-07-08 13:22:09 +02:00
|
|
|
|
2017-06-21 12:23:05 +02:00
|
|
|
/**
|
|
|
|
* @brief Size constants for the main Calamares window.
|
|
|
|
*/
|
|
|
|
constexpr int windowMinimumWidth = 800;
|
|
|
|
constexpr int windowMinimumHeight = 520;
|
|
|
|
constexpr int windowPreferredWidth = 1024;
|
|
|
|
constexpr int windowPreferredHeight = 520;
|
2018-12-14 10:52:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Consistent locale (language + country) naming.
|
|
|
|
*
|
|
|
|
* Support class to turn locale names (as used by Calamares's
|
|
|
|
* translation system) into QLocales, and also into consistent
|
|
|
|
* human-readable text labels.
|
|
|
|
*/
|
2018-12-14 11:30:05 +01:00
|
|
|
class LocaleLabel
|
2018-12-14 10:52:55 +01:00
|
|
|
{
|
|
|
|
public:
|
2018-12-14 13:20:32 +01:00
|
|
|
/** @brief Formatting option for label -- add (country) to label. */
|
|
|
|
enum class LabelFormat { AlwaysWithCountry, IfNeededWithCountry } ;
|
|
|
|
|
2018-12-14 10:52:55 +01:00
|
|
|
/** @brief Construct from a locale name.
|
|
|
|
*
|
2018-12-14 13:20:32 +01:00
|
|
|
* The @p localeName should be one that Qt recognizes, e.g. en_US or ar_EY.
|
|
|
|
* The @p format determines whether the country name is always present
|
|
|
|
* in the label (human-readable form) or only if needed for disambiguation.
|
2018-12-14 10:52:55 +01:00
|
|
|
*/
|
2018-12-14 13:20:32 +01:00
|
|
|
LocaleLabel( const QString& localeName, LabelFormat format = LabelFormat::IfNeededWithCountry );
|
2018-12-14 10:52:55 +01:00
|
|
|
|
|
|
|
/** @brief Define a sorting order.
|
|
|
|
*
|
|
|
|
* English (@see isEnglish() -- it means en_US) is sorted at the top.
|
|
|
|
*/
|
2018-12-14 11:33:13 +01:00
|
|
|
bool operator <( const LocaleLabel& other ) const
|
2018-12-14 10:52:55 +01:00
|
|
|
{
|
|
|
|
if ( isEnglish() )
|
|
|
|
return !other.isEnglish();
|
|
|
|
if ( other.isEnglish() )
|
|
|
|
return false;
|
|
|
|
return m_sortKey < other.m_sortKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief Is this locale English?
|
|
|
|
*
|
|
|
|
* en_US and en (American English) is defined as English. The Queen's
|
|
|
|
* English -- proper English -- is relegated to non-English status.
|
|
|
|
*/
|
|
|
|
bool isEnglish() const
|
|
|
|
{
|
2018-12-14 11:33:13 +01:00
|
|
|
return m_localeId == QLatin1Literal( "en_US" ) || m_localeId == QLatin1Literal( "en" );
|
2018-12-14 10:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief Get the human-readable name for this locale. */
|
2018-12-14 11:33:13 +01:00
|
|
|
QString label() const
|
|
|
|
{
|
|
|
|
return m_label;
|
|
|
|
}
|
2018-12-14 10:52:55 +01:00
|
|
|
/** @brief Get the Qt locale. */
|
2018-12-14 11:33:13 +01:00
|
|
|
QLocale locale() const
|
|
|
|
{
|
|
|
|
return m_locale;
|
|
|
|
}
|
2018-12-14 10:52:55 +01:00
|
|
|
|
|
|
|
/** @brief Get a Qt locale for the given @p localeName
|
|
|
|
*
|
|
|
|
* This special-cases `sr@latin`, which is used as a translation
|
|
|
|
* name in Calamares, while Qt recognizes `sr@latn`.
|
|
|
|
*/
|
|
|
|
static QLocale getLocale( const QString& localeName );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
QLocale m_locale;
|
|
|
|
QString m_localeId; // the locale identifier, e.g. "en_GB"
|
|
|
|
QString m_sortKey; // the English name of the locale
|
|
|
|
QString m_label; // the native name of the locale
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace CalamaresUtils
|
2014-07-01 11:48:10 +02:00
|
|
|
|
|
|
|
#endif // CALAMARESUTILSGUI_H
|