File indexing completed on 2024-05-19 04:49:57
0001 /**************************************************************************************** 0002 * Copyright (c) 2008-2012 Soren Harward <stharward@gmail.com> * 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 APG_PLAYLISTLENGTH_CONSTRAINT 0018 #define APG_PLAYLISTLENGTH_CONSTRAINT 0019 0020 #include "ui_PlaylistLengthEditWidget.h" 0021 0022 #include "playlistgenerator/Constraint.h" 0023 0024 #include <QString> 0025 0026 class ConstraintFactoryEntry; 0027 class QWidget; 0028 0029 namespace ConstraintTypes { 0030 0031 /* This constraint derives its name from the fact that it specifies the 0032 * length (ie, number of tracks) of the Playlist. */ 0033 0034 class PlaylistLength : public Constraint { 0035 Q_OBJECT 0036 0037 enum NumComparison { CompareNumLessThan, CompareNumEquals, CompareNumGreaterThan }; 0038 0039 public: 0040 static Constraint* createFromXml( QDomElement&, ConstraintNode* ); 0041 static Constraint* createNew( ConstraintNode* ); 0042 static ConstraintFactoryEntry* registerMe(); 0043 0044 QWidget* editWidget() const override; 0045 void toXml( QDomDocument&, QDomElement& ) const override; 0046 0047 QString getName() const override; 0048 0049 double satisfaction( const Meta::TrackList& ) const override; 0050 quint32 suggestPlaylistSize() const override; 0051 0052 private Q_SLOTS: 0053 void setComparison( const int ); 0054 void setLength( const int ); 0055 void setStrictness( const int ); 0056 0057 private: 0058 PlaylistLength( QDomElement&, ConstraintNode* ); 0059 explicit PlaylistLength( ConstraintNode* ); 0060 0061 // constraint parameters 0062 quint32 m_length; 0063 int m_comparison; 0064 double m_strictness; 0065 0066 // internal mathematical functions 0067 double transformLength( const int ) const; 0068 }; 0069 0070 class PlaylistLengthEditWidget : public QWidget { 0071 Q_OBJECT 0072 0073 public: 0074 PlaylistLengthEditWidget( const int, const int, const int ); 0075 0076 Q_SIGNALS: 0077 void updated(); 0078 void lengthChanged( const int ); 0079 void comparisonChanged( const int ); 0080 void strictnessChanged( const int ); 0081 0082 private Q_SLOTS: 0083 void on_spinBox_Length_valueChanged( const int ); 0084 void on_comboBox_Comparison_currentIndexChanged( const int ); 0085 void on_slider_Strictness_valueChanged( const int ); 0086 0087 private: 0088 Ui::PlaylistLengthEditWidget ui; 0089 }; 0090 } // namespace ConstraintTypes 0091 0092 #endif