[libcalamaresui] Apply coding style to utils/

This commit is contained in:
Adriaan de Groot 2019-08-13 21:00:36 +02:00
parent 1b6aed8c40
commit 6f74463a80
6 changed files with 26 additions and 16 deletions

View File

@ -34,11 +34,10 @@
namespace CalamaresUtils namespace CalamaresUtils
{ {
static int s_defaultFontSize = 0; static int s_defaultFontSize = 0;
static int s_defaultFontHeight = 0; static int s_defaultFontHeight = 0;
QPixmap QPixmap
defaultPixmap( ImageType type, ImageMode mode, const QSize& size ) defaultPixmap( ImageType type, ImageMode mode, const QSize& size )
{ {
@ -152,11 +151,15 @@ createRoundedImage( const QPixmap& pixmap, const QSize& size, float frameWidthPc
} }
if ( !height || !width ) if ( !height || !width )
{
return QPixmap(); return QPixmap();
}
QPixmap scaledAvatar = pixmap.scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); QPixmap scaledAvatar = pixmap.scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
if ( frameWidthPct == 0.00f ) if ( frameWidthPct == 0.00f )
{
return scaledAvatar; return scaledAvatar;
}
QPixmap frame( width, height ); QPixmap frame( width, height );
frame.fill( Qt::transparent ); frame.fill( Qt::transparent );
@ -172,7 +175,8 @@ createRoundedImage( const QPixmap& pixmap, const QSize& size, float frameWidthPc
painter.setBrush( brush ); painter.setBrush( brush );
painter.setPen( pen ); painter.setPen( pen );
painter.drawRoundedRect( outerRect, qreal( frameWidthPct ) * 100.0, qreal( frameWidthPct ) * 100.0, Qt::RelativeSize ); painter.drawRoundedRect(
outerRect, qreal( frameWidthPct ) * 100.0, qreal( frameWidthPct ) * 100.0, Qt::RelativeSize );
return frame; return frame;
} }
@ -189,7 +193,9 @@ unmarginLayout( QLayout* layout )
{ {
QLayout* childLayout = layout->itemAt( i )->layout(); QLayout* childLayout = layout->itemAt( i )->layout();
if ( childLayout ) if ( childLayout )
{
unmarginLayout( childLayout ); unmarginLayout( childLayout );
}
} }
} }
@ -255,13 +261,17 @@ clearLayout( QLayout* layout )
while ( QLayoutItem* item = layout->takeAt( 0 ) ) while ( QLayoutItem* item = layout->takeAt( 0 ) )
{ {
if ( QWidget* widget = item->widget() ) if ( QWidget* widget = item->widget() )
{
widget->deleteLater(); widget->deleteLater();
}
if ( QLayout* childLayout = item->layout() ) if ( QLayout* childLayout = item->layout() )
{
clearLayout( childLayout ); clearLayout( childLayout );
}
delete item; delete item;
} }
} }
} // namespace } // namespace CalamaresUtils

View File

@ -56,7 +56,7 @@ enum ImageType : int
PartitionTable, PartitionTable,
BootEnvironment, BootEnvironment,
Squid, Squid,
StatusOk, // Icons for the requirements checker StatusOk, // Icons for the requirements checker
StatusWarning, StatusWarning,
StatusError StatusError
}; };
@ -94,9 +94,7 @@ UIDLLEXPORT QPixmap defaultPixmap( ImageType type,
* @return the transformed pixmap. * @return the transformed pixmap.
* This one is currently unused. * This one is currently unused.
*/ */
UIDLLEXPORT QPixmap createRoundedImage( const QPixmap& avatar, UIDLLEXPORT QPixmap createRoundedImage( const QPixmap& avatar, const QSize& size, float frameWidthPct = 0.20f );
const QSize& size,
float frameWidthPct = 0.20f );
/** /**
* @brief unmarginLayout recursively walks the QLayout tree and removes all margins. * @brief unmarginLayout recursively walks the QLayout tree and removes all margins.
@ -112,8 +110,8 @@ UIDLLEXPORT void unmarginLayout( QLayout* layout );
UIDLLEXPORT void clearLayout( QLayout* layout ); UIDLLEXPORT void clearLayout( QLayout* layout );
UIDLLEXPORT void setDefaultFontSize( int points ); UIDLLEXPORT void setDefaultFontSize( int points );
UIDLLEXPORT int defaultFontSize(); // in points UIDLLEXPORT int defaultFontSize(); // in points
UIDLLEXPORT int defaultFontHeight(); // in pixels, DPI-specific UIDLLEXPORT int defaultFontHeight(); // in pixels, DPI-specific
UIDLLEXPORT QFont defaultFont(); UIDLLEXPORT QFont defaultFont();
UIDLLEXPORT QFont largeFont(); UIDLLEXPORT QFont largeFont();
UIDLLEXPORT QSize defaultIconSize(); UIDLLEXPORT QSize defaultIconSize();
@ -128,4 +126,4 @@ constexpr int windowPreferredHeight = 520;
} // namespace CalamaresUtils } // namespace CalamaresUtils
#endif // CALAMARESUTILSGUI_H #endif // CALAMARESUTILSGUI_H

View File

@ -2,7 +2,7 @@
* *
* SPDX-License-Identifier: GPLv3+ * SPDX-License-Identifier: GPLv3+
* License-Filename: LICENSES/GPLv3+-ImageRegistry * License-Filename: LICENSES/GPLv3+-ImageRegistry
* *
* Copyright 2019, Adriaan de Groot <groot@kde.org> * Copyright 2019, Adriaan de Groot <groot@kde.org>
*/ */

View File

@ -2,7 +2,7 @@
* *
* SPDX-License-Identifier: GPLv3+ * SPDX-License-Identifier: GPLv3+
* License-Filename: LICENSES/GPLv3+-ImageRegistry * License-Filename: LICENSES/GPLv3+-ImageRegistry
* *
* Copyright 2019, Adriaan de Groot <groot@kde.org> * Copyright 2019, Adriaan de Groot <groot@kde.org>
*/ */

View File

@ -34,11 +34,13 @@ lookupAndCall( PyObject* object,
{ {
PythonQtObjectPtr callable = PythonQt::self()->lookupCallable( object, name ); PythonQtObjectPtr callable = PythonQt::self()->lookupCallable( object, name );
if ( callable ) if ( callable )
{
return callable.call( args, kwargs ); return callable.call( args, kwargs );
}
} }
// If we haven't found a callable with the given names, we force an error: // If we haven't found a callable with the given names, we force an error:
return PythonQt::self()->call( object, candidateNames.first(), args, kwargs ); return PythonQt::self()->call( object, candidateNames.first(), args, kwargs );
} }
} } // namespace CalamaresUtils

View File

@ -33,6 +33,6 @@ QVariant lookupAndCall( PyObject* object,
const QVariantList& args = QVariantList(), const QVariantList& args = QVariantList(),
const QVariantMap& kwargs = QVariantMap() ); const QVariantMap& kwargs = QVariantMap() );
} //ns } // namespace CalamaresUtils
#endif // PYTHONQTUTILS_H #endif // PYTHONQTUTILS_H