44 #include "FileOptionsDialog.hh" 46 FileOptionsDialog::FileOptionsDialog(std::vector<fileTypes>& _supportedTypes, QStringList _extensions,
bool _loadMode, QWidget *parent)
49 supportedTypes_(_supportedTypes),
51 defaultPluginBox_(NULL)
54 ext_.removeDuplicates();
56 QGridLayout* grid =
new QGridLayout;
58 QVector< int > usefulPlugins;
61 for (
int i=0; i < ext_.size(); i++){
65 for (
unsigned int t=0; t < supportedTypes_.size(); t++){
70 filters = supportedTypes_[t].loadFilters;
72 filters = supportedTypes_[t].saveFilters;
75 filters = filters.section(
"(",1).section(
")",0,0);
78 QStringList separateFilters = filters.split(
" ");
80 for (
int filterId = 0 ; filterId < separateFilters.size(); ++filterId ) {
81 separateFilters[filterId] = separateFilters[filterId].trimmed();
83 if (separateFilters[filterId].endsWith(
"." + ext_[i],Qt::CaseInsensitive)){
85 names.push_back( supportedTypes_[t].name );
86 usefulPlugins.push_back( t );
96 QLabel* label =
new QLabel( tr(
"For *.%1 use plugin ").arg(ext_[i]) );
97 QComboBox* box =
new QComboBox();
99 defaultPluginBox_ =
new QCheckBox(tr(
"Make this plugin the default"));
101 box->addItems(names);
102 box->setAccessibleName(ext_[i]);
104 currentName_ = box->currentText();
105 currentExtension_ = ext_[i];
107 grid->addWidget(label, grid->rowCount(), 0);
108 grid->addWidget(box, grid->rowCount()-1, 1);
109 grid->addWidget(defaultPluginBox_, grid->rowCount()+1, 0);
111 connect(box, SIGNAL(currentIndexChanged(QString)),
this, SLOT(slotPluginChanged(QString)) );
112 connect(defaultPluginBox_, SIGNAL(stateChanged(
int)),
this, SLOT(slotPluginDefault(
int)) );
113 boxes_.push_back(box);
118 for (
int i=0; i < boxes_.count(); i++){
120 for (
int t=0; t < (boxes_[i])->count(); t++)
121 if ( (boxes_[i])->itemText(t).contains(
"TriangleMesh") ){
122 (boxes_[i])->setCurrentIndex(t);
127 QGroupBox* group =
new QGroupBox(tr(
"Extensions with multiple plugins"));
128 group->setLayout(grid);
130 if (boxes_.count() == 0)
131 group->setVisible(
false);
135 for (
unsigned int t=0; t < supportedTypes_.size(); t++){
137 if ( !usefulPlugins.contains(t) )
143 widget = supportedTypes_[t].plugin->loadOptionsWidget(
"");
145 widget = supportedTypes_[t].plugin->saveOptionsWidget(
"");
148 tabs_.addTab(widget, supportedTypes_[t].name);
152 QPushButton* cancel =
new QPushButton(tr(
"&Cancel"));
153 QPushButton* ok =
new QPushButton(tr(
"&Ok"));
155 QHBoxLayout* buttonLayout =
new QHBoxLayout;
157 buttonLayout->addWidget(cancel);
158 buttonLayout->addStretch();
159 buttonLayout->addWidget(ok);
161 QVBoxLayout* layout =
new QVBoxLayout;
162 layout->addWidget(group);
163 layout->addWidget(&tabs_);
164 layout->addLayout(buttonLayout);
168 connect( cancel, SIGNAL(clicked()),
this, SLOT(reject()) );
169 connect( ok, SIGNAL(clicked()),
this, SLOT(accept()) );
173 FileOptionsDialog::~FileOptionsDialog()
176 for (
int i=tabs_.count()-1; i >= 0; i--)
180 for (
unsigned int t=0; t < supportedTypes_.size(); t++){
185 widget = supportedTypes_[t].plugin->loadOptionsWidget(
"");
187 widget = supportedTypes_[t].plugin->saveOptionsWidget(
"");
190 widget->setParent(0);
194 int FileOptionsDialog::exec(){
196 if ( tabs_.count() == 0 && boxes_.count() == 0 )
197 return QDialog::Accepted;
199 return QDialog::exec();
203 bool FileOptionsDialog::makePluginDefault() {
204 if (!defaultPluginBox_)
207 return defaultPluginBox_->isChecked();
210 void FileOptionsDialog::slotPluginChanged(QString _name){
212 QComboBox* box =
dynamic_cast<QComboBox*
>(QObject::sender());
214 for (
unsigned int t=0; t < supportedTypes_.size(); t++)
215 if ( supportedTypes_[t].name == _name ){
217 currentName_ = _name;
218 currentExtension_ = box->accessibleName();
220 if (makePluginDefault()) {
224 emit setPluginForExtension(box->accessibleName(), t );
229 void FileOptionsDialog::slotPluginDefault(
int _state) {
231 if (_state == Qt::Checked) {
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.