File indexing completed on 2024-05-19 04:49:41
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Daniel Jones <danielcjones@gmail.com> * 0003 * Copyright (c) 2009 Leo Franchi <lfranchi@kde.org> * 0004 * Copyright (c) 2010, 2011 Ralf Engels <ralf-engels@gmx.de> * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify it under * 0007 * the terms of the GNU General Public License as published by the Free Software * 0008 * Foundation; either version 2 of the License, or (at your option) version 3 or * 0009 * any later version accepted by the membership of KDE e.V. (or its successor approved * 0010 * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of * 0011 * version 3 of the license. * 0012 * * 0013 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0014 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0015 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0016 * * 0017 * You should have received a copy of the GNU General Public License along with * 0018 * this program. If not, see <http://www.gnu.org/licenses/>. * 0019 ****************************************************************************************/ 0020 0021 #ifndef AMAROK_PARTBIAS_H 0022 #define AMAROK_PARTBIAS_H 0023 0024 #include "dynamic/Bias.h" 0025 #include "dynamic/BiasFactory.h" 0026 0027 #include <QList> 0028 #include <QVector> 0029 class QGridLayout; 0030 class QSlider; 0031 class QWidget; 0032 0033 namespace Dynamic 0034 { 0035 class PartBias; 0036 0037 /** The widget for the PartBias */ 0038 class PartBiasWidget : public QWidget 0039 { 0040 Q_OBJECT 0041 0042 public: 0043 explicit PartBiasWidget( Dynamic::PartBias* bias, QWidget* parent = nullptr ); 0044 0045 protected Q_SLOTS: 0046 void biasAppended( Dynamic::BiasPtr bias ); 0047 void biasRemoved( int pos ); 0048 void biasMoved( int from, int to ); 0049 0050 void sliderValueChanged( int val ); 0051 void biasWeightsChanged(); 0052 0053 protected: 0054 /** True if we just handle a signal. Used to protect against recursion */ 0055 bool m_inSignal; 0056 0057 Dynamic::PartBias* m_bias; 0058 0059 QGridLayout* m_layout; 0060 0061 QList<QSlider*> m_sliders; 0062 QList<QWidget*> m_widgets; 0063 }; 0064 0065 /** The part bias will ensure that tracks are fulfilling all the sub-biases according to it's weights. 0066 The bias has an implicit random sub-bias 0067 */ 0068 class PartBias : public AndBias 0069 { 0070 Q_OBJECT 0071 0072 public: 0073 /** Create a new part bias. 0074 */ 0075 PartBias(); 0076 0077 void fromXml( QXmlStreamReader *reader ) override; 0078 void toXml( QXmlStreamWriter *writer ) const override; 0079 0080 static QString sName(); 0081 QString name() const override; 0082 QString toString() const override; 0083 0084 QWidget* widget( QWidget* parent = nullptr ) override; 0085 void paintOperator( QPainter* painter, const QRect &rect, Dynamic::AbstractBias* bias ) override; 0086 0087 TrackSet matchingTracks( const Meta::TrackList& playlist, 0088 int contextCount, int finalCount, 0089 const TrackCollectionPtr &universe ) const override; 0090 0091 bool trackMatches( int position, 0092 const Meta::TrackList& playlist, 0093 int contextCount ) const override; 0094 0095 /** Returns the weights of the bias itself and all the sub-biases. */ 0096 virtual QList<qreal> weights() const; 0097 0098 /** Appends a bias to this bias. 0099 This object will take ownership of the bias and free it when destroyed. 0100 */ 0101 void appendBias( const Dynamic::BiasPtr &bias ) override; 0102 void moveBias( int from, int to ) override; 0103 0104 public Q_SLOTS: 0105 void resultReceived( const Dynamic::TrackSet &tracks ) override; 0106 0107 /** The overall weight has changed */ 0108 void changeBiasWeight( int biasNum, qreal value ); 0109 0110 Q_SIGNALS: 0111 /** The overall weight has changed */ 0112 void weightsChanged(); 0113 0114 protected Q_SLOTS: 0115 void biasReplaced( const Dynamic::BiasPtr &oldBias, const Dynamic::BiasPtr &newBias ) override; 0116 0117 private: 0118 /** Using the data from m_matchingTracks it tries to compute a valid m_tracks */ 0119 void updateResults() const; // only changes mutables 0120 0121 QList<qreal> m_weights; 0122 mutable QVector<Dynamic::TrackSet> m_matchingTracks; 0123 0124 // buffered by matchingTracks 0125 mutable Meta::TrackList m_playlist; 0126 mutable int m_contextCount; 0127 mutable int m_finalCount; 0128 mutable Dynamic::TrackCollectionPtr m_universe; 0129 0130 Q_DISABLE_COPY(PartBias) 0131 }; 0132 0133 0134 class AMAROK_EXPORT PartBiasFactory : public Dynamic::AbstractBiasFactory 0135 { 0136 public: 0137 QString i18nName() const override; 0138 QString name() const override; 0139 QString i18nDescription() const override; 0140 BiasPtr createBias() override; 0141 }; 0142 0143 } 0144 0145 0146 #endif 0147