aboutsummaryrefslogblamecommitdiff
path: root/qmidiplayer-desktop/qmpsettingswindow.hpp
blob: c1ae4107b0d43e85e82daef0ac67e2a3e91fd44f (plain) (tree)
1
2
3
4
5
6
7
8
9


                           
                 
              
                 

                      
                     
                    
                       
                    
                   
                      
                        
                                 
                               




                                






                                      










                                  
                                                



                                               

                                 
                
































                                                                        

                              




                                      
                                                                    

                                                    
                                                  
                                    
                                                              
                                                                                                                        
                                                  









                                                                                                                                        
                                                                                                                               

                                                                      


                                                                                                                                             
                                


                                     
                      
                                             

                                             









                                                                       



                                                 

                                                

                                            
                
                                          
                                      
                                                                    

                                                                  
                                       
                                      
                                                  
                                           

                                                                     


                             
#ifndef QMPSETTINGSWINDOW_H
#define QMPSETTINGSWINDOW_H

#include <string>
#include <map>
#include <vector>
#include <QDialog>
#include <QCloseEvent>
#include <QHideEvent>
#include <QSettings>
#include <QTableWidget>
#include <QComboBox>
#include <QSpinBox>
#include <QFormLayout>
#include "qmpplugin.hpp"
#include "qmpcustomizewindow.hpp"
#include "qmpdevpropdialog.hpp"

namespace Ui {
	class qmpSettingsWindow;
}

struct qmpCustomOption
{
	QWidget* widget;
	std::string desc;int type;
	QVariant defaultval,minv,maxv;
};

class QLineEdit;
class QToolButton;
class QFileEdit:public QWidget
{
	Q_OBJECT
	private:
		QLineEdit *le;
		QToolButton *tb;
	private slots:
		void chooseFile();
	public:
		QFileEdit(QWidget* par=nullptr);
		QString text();
		void setText(const QString& s);
};

class QHexSpinBox:public QSpinBox
{
	Q_OBJECT
	public:
		QHexSpinBox(QWidget *parent=0):QSpinBox(parent)
		{
			setPrefix("0x");
			setDisplayIntegerBase(16);
			setRange(-0x80000000,0x7FFFFFFF);
		}
	protected:
		QString textFromValue(int value)const
		{
			return QString::number(u(value),16).toUpper();
		}
		int valueFromText(const QString &text)const
		{
			return i(text.toUInt(0,16));
		}
		QValidator::State validate(QString &input,int &pos)const
		{
			QString t=input;
			if(t.startsWith("0x"))t.remove(0,2);
			pos-=t.size()-t.trimmed().size();t=t.trimmed();
			if(t.isEmpty())return QValidator::Intermediate;
			input=QString("0x")+t.toUpper();
			bool okay;t.toUInt(&okay,16);
			if(!okay)return QValidator::Invalid;
			return QValidator::Acceptable;
		}
		inline unsigned int u(int i)const
		{return *reinterpret_cast<unsigned int*>(&i);}
		inline int i(unsigned int u)const
		{return *reinterpret_cast<int*>(&u);}
};

class qmpDevicePriorityDialog;

class qmpSettingsWindow:public QDialog
{
	Q_OBJECT

	public:
		explicit qmpSettingsWindow(QWidget *parent=nullptr);
		~qmpSettingsWindow();
		void closeEvent(QCloseEvent *event);
		void hideEvent(QHideEvent *event);
		void settingsInit();
		void updatePluginList(qmpPluginManager *pmgr);
		void registerOptionInt(std::string tab,std::string desc,std::string key,int min,int max,int defaultval);
		int getOptionInt(std::string key);
		void setOptionInt(std::string key,int val);
		void registerOptionUint(std::string tab,std::string desc,std::string key,unsigned min,unsigned max,unsigned defaultval);
		unsigned getOptionUint(std::string key);
		void setOptionUint(std::string key,unsigned val);
		void registerOptionBool(std::string tab,std::string desc,std::string key,bool defaultval);
		bool getOptionBool(std::string key);
		void setOptionBool(std::string key,bool val);
		void registerOptionDouble(std::string tab,std::string desc,std::string key,double min,double max,double defaultval);
		double getOptionDouble(std::string key);
		void setOptionDouble(std::string key,double val);
		void registerOptionString(std::string tab,std::string desc,std::string key,std::string defaultval,bool ispath);
		std::string getOptionString(std::string key);
		void setOptionString(std::string key,std::string val);
		void registerOptionEnumInt(std::string tab,std::string desc,std::string key,std::vector<std::string> options,int defaultval);
		int getOptionEnumInt(std::string key);
		void setOptionEnumInt(std::string key,int val);
		void postInit();
	signals:
		void dialogClosing();

	private slots:
		void on_buttonBox_accepted();
		void on_buttonBox_rejected();

		void on_cbBufSize_currentTextChanged(const QString &s);
		void on_cbBufCnt_currentTextChanged(const QString &s);

		void on_pbAdd_clicked();
		void on_pbRemove_clicked();
		void on_pbUp_clicked();
		void on_pbDown_clicked();

		void on_cbAutoBS_stateChanged();

		void on_pbCustomizeTb_clicked();

		void on_pbCustomizeAct_clicked();

		void on_pbExtDevSetup_clicked();

		void on_pbDevPrio_clicked();

	private:
		Ui::qmpSettingsWindow *ui;
		void settingsUpdate();
		std::map<std::string,qmpCustomOption> customOptions;
		std::map<std::string,QGridLayout*> customOptPages;
		void updateCustomOptions();
		qmpCustomizeWindow *cw;
		qmpDevPropDialog *dps;
		qmpDevicePriorityDialog *devpriod;
		static QSettings *settings;
	public:
		static QSettings* getSettingsIntf(){return settings;}
};

#endif // QMPSETTINGSWINDOW_H