File indexing completed on 2024-05-05 16:54:13

0001 /****************************************************************************************
0002  * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016  
0017 #ifndef PALETTEHANDLER_H
0018 #define PALETTEHANDLER_H
0019 
0020 #include "amarok_export.h"
0021 
0022 #include <QObject>
0023 #include <QPalette>
0024 
0025 class QAbstractItemView;
0026 class PaletteHandler;
0027 
0028 namespace The {
0029     AMAROK_EXPORT PaletteHandler* paletteHandler();
0030 }
0031 
0032 /**
0033 A small singleton class to handle propagating palette change notifications and hold some utility functions for updating certain widgets
0034 
0035     @author Nikolaj Hald Nielsen <nhn@kde.org>
0036 */
0037 class AMAROK_EXPORT PaletteHandler : public QObject
0038 {
0039     Q_OBJECT
0040 
0041 friend PaletteHandler* The::paletteHandler();
0042 
0043 public:
0044     ~PaletteHandler() override;
0045 
0046     QPalette palette() const;
0047 
0048     void setPalette( const QPalette & palette );
0049 
0050     /** Gives the item view a special darker palette and transparent background.
0051         You need to connect to the newPalette signal afterwards because this
0052         darker palette does not automatically update.
0053         @param view the item view.
0054     */
0055     void updateItemView( QAbstractItemView * view );
0056 
0057     /**
0058     * Returns the foreground color for the painter by checking the painting QWidget::foregroundRole() and falling back to
0059     * QPalette::WindowText (or QPalette::HighlightedText if @p selected)
0060     * Uses the widgets palette or the application palette as fallback
0061     * @param p the painter.
0062     * @param selected the mode switcher.
0063     */    
0064     QColor foregroundColor( const QPainter *p, bool selected = false );
0065 
0066     /**
0067      * Returns the highlight color which should be used instead of the color from KDE.
0068      * @param percentSaturation Decimal percentage to saturate the highlight color. Will
0069      *        reduce (or magnify) the saturation in HSV representation of the color.
0070      *        Defaults to 50%
0071      * @param percentValue Decimal percentage to multiply the value of the HSV color with.
0072      *        Defaults to 100%.
0073      * @return Highlight color, which is the KDE highlight color, with reduced saturation
0074      *         (less contrast).
0075      */
0076     static QColor highlightColor( qreal percentSaturation = 0.5, qreal percentValue = 1.0 );
0077 
0078     /**
0079      * Returns the background color used in context applets.
0080      */
0081     static QColor backgroundColor();
0082 
0083     /**
0084      * Returns the alternate background color used in context applets.
0085      */
0086     static QColor alternateBackgroundColor();
0087 
0088 Q_SIGNALS:
0089     void newPalette( const QPalette & palette );
0090 
0091 private:
0092     PaletteHandler( QObject* parent = nullptr );
0093 
0094     QPalette m_palette;
0095 };
0096 
0097 #endif