ResInsight/Fwk/AppFwk/cafUserInterface/cafQStyledProgressBar.cpp

80 lines
3.6 KiB
C++
Raw Permalink Normal View History

2019-04-05 12:10:46 -05:00
//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2019- Ceetron Solutions AS
//
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// GNU General Public License Usage
// This library 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.
//
// This library 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 at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cafQStyledProgressBar.h"
2019-04-07 11:04:11 -05:00
#include "cafStyleSheetTools.h"
2019-04-05 12:10:46 -05:00
2019-04-07 11:04:11 -05:00
using namespace caf;
2019-04-05 12:10:46 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2020-06-19 00:53:59 -05:00
QStyledProgressBar::QStyledProgressBar( QString objectName, QWidget* parent /*= nullptr*/ )
: QProgressBar( parent )
2019-04-05 12:10:46 -05:00
{
2020-06-19 00:53:59 -05:00
setObjectName( objectName );
2019-04-05 12:10:46 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2020-06-19 00:53:59 -05:00
void QStyledProgressBar::setTextBackgroundAndProgressColor( QColor textColor,
QColor backgroundColor,
QColor backgroundFrameColor,
QColor progressColor )
2019-04-05 12:10:46 -05:00
{
2020-06-19 00:53:59 -05:00
QString styleSheetTemplate = "QProgressBar#%1::chunk"
"{"
"background-color: %2;"
"}";
QString progressColString = colorStringWithAlpha( progressColor );
2019-04-05 12:10:46 -05:00
2019-04-07 11:04:11 -05:00
QString fullStyleSheet =
2020-06-19 00:53:59 -05:00
StyleSheetTools::createFrameStyleSheet( "QProgressBar", objectName(), textColor, backgroundColor, backgroundFrameColor );
fullStyleSheet += styleSheetTemplate.arg( objectName() ).arg( progressColString );
2019-04-07 11:04:11 -05:00
2020-06-19 00:53:59 -05:00
setStyleSheet( fullStyleSheet );
setAttribute( Qt::WA_TranslucentBackground );
2019-04-05 12:10:46 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2020-06-19 00:53:59 -05:00
QString QStyledProgressBar::colorStringWithAlpha( QColor color )
2019-04-05 12:10:46 -05:00
{
2020-06-19 00:53:59 -05:00
return QString( "rgba(%1, %2, %3, %4)" ).arg( color.red() ).arg( color.green() ).arg( color.blue() ).arg( color.alpha() );
2019-04-05 12:10:46 -05:00
}