File indexing completed on 2024-05-19 04:49:56

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_PLAYLISTFILESIZE_CONSTRAINT
0018 #define APG_PLAYLISTFILESIZE_CONSTRAINT
0019 
0020 #include "ui_PlaylistFileSizeEditWidget.h"
0021 
0022 #include "playlistgenerator/Constraint.h"
0023 
0024 #include <QString>
0025 
0026 class ConstraintFactoryEntry;
0027 class QWidget;
0028 
0029 namespace ConstraintTypes {
0030 
0031     class PlaylistFileSize : public Constraint {
0032         Q_OBJECT
0033 
0034         enum NumComparison { CompareNumLessThan, CompareNumEquals, CompareNumGreaterThan };
0035 
0036         public:
0037             static Constraint* createFromXml( QDomElement&, ConstraintNode* );
0038             static Constraint* createNew( ConstraintNode* );
0039             static ConstraintFactoryEntry* registerMe();
0040 
0041             QWidget* editWidget() const override;
0042             void toXml( QDomDocument&, QDomElement& ) const override;
0043 
0044             QString getName() const override;
0045 
0046             double satisfaction( const Meta::TrackList& ) const override;
0047             quint32 suggestPlaylistSize() const override;
0048 
0049         private Q_SLOTS:
0050             void setComparison( const int );
0051             void setSize( const int );
0052             void setStrictness( const int );
0053             void setUnit( const int );
0054 
0055         private:
0056             PlaylistFileSize( QDomElement&, ConstraintNode* );
0057             explicit PlaylistFileSize( ConstraintNode* );
0058 
0059             // constraint parameters
0060             int m_size;
0061             int m_unit;
0062             int m_comparison;
0063             double m_strictness;
0064 
0065             // internal mathematical functions
0066             quint64 getWantedSize() const;
0067             double transformFileSize( const quint64 ) const;
0068     };
0069 
0070     class PlaylistFileSizeEditWidget : public QWidget {
0071         Q_OBJECT
0072 
0073         public:
0074             PlaylistFileSizeEditWidget( const int, const int, const int, const int );
0075 
0076         Q_SIGNALS:
0077             void updated();
0078             void sizeChanged( const int );
0079             void unitChanged( const int );
0080             void comparisonChanged( const int );
0081             void strictnessChanged( const int );
0082 
0083         private Q_SLOTS:
0084             void on_spinBox_Size_valueChanged( const int );
0085             void on_comboBox_Unit_currentIndexChanged( const int );
0086             void on_comboBox_Comparison_currentIndexChanged( const int );
0087             void on_slider_Strictness_valueChanged( const int );
0088 
0089         private:
0090             Ui::PlaylistFileSizeEditWidget ui;
0091     };
0092 } // namespace ConstraintTypes
0093 
0094 #endif