50 #include "FileOptionsDialog.hh"
52 FileOptionsDialog::FileOptionsDialog(std::vector<fileTypes>& _supportedTypes, QStringList _extensions,
bool _loadMode, QWidget *parent)
55 supportedTypes_(_supportedTypes),
57 defaultPluginBox_(NULL)
60 ext_.removeDuplicates();
62 QGridLayout* grid =
new QGridLayout;
64 QVector< int > usefulPlugins;
67 for (
int i=0; i < ext_.size(); i++){
71 for (
unsigned int t=0; t < supportedTypes_.size(); t++){
76 filters = supportedTypes_[t].loadFilters;
78 filters = supportedTypes_[t].saveFilters;
81 filters = filters.section(
"(",1).section(
")",0,0);
84 QStringList separateFilters = filters.split(
" ");
86 for (
int filterId = 0 ; filterId < separateFilters.size(); ++filterId ) {
87 separateFilters[filterId] = separateFilters[filterId].trimmed();
89 if (separateFilters[filterId].endsWith(
"." + ext_[i],Qt::CaseInsensitive)){
91 names.push_back( supportedTypes_[t].name );
92 usefulPlugins.push_back( t );
102 QLabel* label =
new QLabel( tr(
"For *.%1 use plugin ").arg(ext_[i]) );
103 QComboBox* box =
new QComboBox();
105 defaultPluginBox_ =
new QCheckBox(tr(
"Make this plugin the default"));
107 box->addItems(names);
108 box->setAccessibleName(ext_[i]);
110 currentName_ = box->currentText();
111 currentExtension_ = ext_[i];
113 grid->addWidget(label, grid->rowCount(), 0);
114 grid->addWidget(box, grid->rowCount()-1, 1);
115 grid->addWidget(defaultPluginBox_, grid->rowCount()+1, 0);
117 connect(box, SIGNAL(currentIndexChanged(QString)),
this, SLOT(slotPluginChanged(QString)) );
118 connect(defaultPluginBox_, SIGNAL(stateChanged(
int)),
this, SLOT(slotPluginDefault(
int)) );
119 boxes_.push_back(box);
124 for (
int i=0; i < boxes_.count(); i++){
126 for (
int t=0; t < (boxes_[i])->count(); t++)
127 if ( (boxes_[i])->itemText(t).contains(
"TriangleMesh") ){
128 (boxes_[i])->setCurrentIndex(t);
133 QGroupBox* group =
new QGroupBox(tr(
"Extensions with multiple plugins"));
134 group->setLayout(grid);
136 if (boxes_.count() == 0)
137 group->setVisible(
false);
141 for (
unsigned int t=0; t < supportedTypes_.size(); t++){
143 if ( !usefulPlugins.contains(t) )
149 widget = supportedTypes_[t].plugin->loadOptionsWidget(
"");
151 widget = supportedTypes_[t].plugin->saveOptionsWidget(
"");
154 tabs_.addTab(widget, supportedTypes_[t].name);
158 QPushButton* cancel =
new QPushButton(tr(
"&Cancel"));
159 QPushButton* ok =
new QPushButton(tr(
"&Ok"));
161 QHBoxLayout* buttonLayout =
new QHBoxLayout;
163 buttonLayout->addWidget(cancel);
164 buttonLayout->addStretch();
165 buttonLayout->addWidget(ok);
167 QVBoxLayout* layout =
new QVBoxLayout;
168 layout->addWidget(group);
169 layout->addWidget(&tabs_);
170 layout->addLayout(buttonLayout);
174 connect( cancel, SIGNAL(clicked()),
this, SLOT(reject()) );
175 connect( ok, SIGNAL(clicked()),
this, SLOT(accept()) );
179 FileOptionsDialog::~FileOptionsDialog()
182 for (
int i=tabs_.count()-1; i >= 0; i--)
186 for (
unsigned int t=0; t < supportedTypes_.size(); t++){
191 widget = supportedTypes_[t].plugin->loadOptionsWidget(
"");
193 widget = supportedTypes_[t].plugin->saveOptionsWidget(
"");
196 widget->setParent(0);
200 int FileOptionsDialog::exec(){
202 if ( tabs_.count() == 0 && boxes_.count() == 0 )
203 return QDialog::Accepted;
205 return QDialog::exec();
209 bool FileOptionsDialog::makePluginDefault() {
210 if (!defaultPluginBox_)
213 return defaultPluginBox_->isChecked();
216 void FileOptionsDialog::slotPluginChanged(QString _name){
218 QComboBox* box =
dynamic_cast<QComboBox*
>(QObject::sender());
220 for (
unsigned int t=0; t < supportedTypes_.size(); t++)
221 if ( supportedTypes_[t].name == _name ){
223 currentName_ = _name;
224 currentExtension_ = box->accessibleName();
226 if (makePluginDefault()) {
230 emit setPluginForExtension(box->accessibleName(), t );
235 void FileOptionsDialog::slotPluginDefault(
int _state) {
237 if (_state == Qt::Checked) {
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...