diff --git a/apps/launcher/datafilesdialog.cpp b/apps/launcher/datafilesdialog.cpp index a0835f1e96..391eb28fe1 100644 --- a/apps/launcher/datafilesdialog.cpp +++ b/apps/launcher/datafilesdialog.cpp @@ -14,26 +14,26 @@ DataFilesDialog::DataFilesDialog() /* listtest QTableWidget *pluginlist = new QTableWidget(this); - + pluginlist->horizontalHeader()->setStretchLastSection(true); pluginlist->insertColumn(0); - + for (unsigned int i=0; i<6; ++i) { pluginlist->insertRow(i); QTableWidgetItem *item = new QTableWidgetItem(QString("Plugin %0").arg(i)); item->setFlags(item->flags() & ~(Qt::ItemIsDropEnabled)); pluginlist->setItem(i, 0, item); } - + pluginlist->insertRow(6); pluginlist->setSelectionMode(QAbstractItemView::SingleSelection); // single item can be draged or droped pluginlist->setDragEnabled(true); pluginlist->setDragDropMode(QAbstractItemView::InternalMove); pluginlist->viewport()->setAcceptDrops(true); - + pluginlist->setDropIndicatorShown(true); */ - + splitter->setOrientation(Qt::Vertical); splitter->addWidget(tree); splitter->addWidget(mastertable); @@ -43,7 +43,7 @@ DataFilesDialog::DataFilesDialog() QList sizelist; sizelist << 100 << 200 << 400; splitter->setSizes(sizelist); - + QVBoxLayout *dialogLayout = new QVBoxLayout(this); dialogLayout->addWidget(splitter); //dialogLayout->addWidget(plugintable); @@ -57,55 +57,55 @@ DataFilesDialog::DataFilesDialog() QStringList acceptedfiles = (QStringList() << "*.esp"); QStringList files; - + datafilesdir.setNameFilters(acceptedfiles); files = datafilesdir.entryList(); - + //foreach (const QString ¤tfile, datafiles) { for (int i=0; isetFlags(item->flags() & ~(Qt::ItemIsDropEnabled)); - + QList foundmasters = mastersmodel->findItems(currentmaster); - + if (foundmasters.isEmpty()) { // Current master is not found in the master, add it mastersmodel->appendRow(item); } } - + // Add the masters to datafilesmodel QStandardItem *item = new QStandardItem(masters.join(",")); item->setFlags(item->flags() & ~(Qt::ItemIsDropEnabled)); QStandardItem *child = new QStandardItem(currentfile); child->setFlags(child->flags() & ~(Qt::ItemIsDropEnabled)); - + QList masteritems = datafilesmodel->findItems(masters.join(",")); - - + + if (masteritems.isEmpty()) { item->appendRow(child); datafilesmodel->appendRow(item); - } else { + } else { foreach (QStandardItem *currentitem, masteritems) { currentitem->setFlags(currentitem->flags() & ~(Qt::ItemIsDropEnabled)); currentitem->appendRow(child); @@ -132,17 +132,17 @@ DataFilesDialog::DataFilesDialog() pluginsmodel = new QStandardItemModel(0, 1); pluginsmodel->setSupportedDragActions(Qt::MoveAction); pluginsmodel->invisibleRootItem()->setFlags(Qt::ItemIsDropEnabled); - - + + masterselectmodel = new QItemSelectionModel(mastersmodel); pluginselectmodel = new QItemSelectionModel(pluginsmodel); - + tree->setModel(datafilesmodel); tree->header()->hide(); - + mastertable->setModel(mastersmodel); mastertable->setSelectionModel(masterselectmodel); - + mastertable->setSelectionBehavior(QAbstractItemView::SelectRows); mastertable->setSelectionMode(QAbstractItemView::MultiSelection); mastertable->setEditTriggers(QAbstractItemView::NoEditTriggers); @@ -156,13 +156,13 @@ DataFilesDialog::DataFilesDialog() plugintable->setEditTriggers(QAbstractItemView::NoEditTriggers); plugintable->horizontalHeader()->setStretchLastSection(true); plugintable->horizontalHeader()->hide(); - + plugintable->setDragEnabled(true); plugintable->setDragDropMode(QAbstractItemView::InternalMove); plugintable->setDropIndicatorShown(true); plugintable->setDragDropOverwriteMode(false); plugintable->viewport()->setAcceptDrops(true); - + plugintable->setContextMenuPolicy(Qt::CustomContextMenu); @@ -170,7 +170,7 @@ DataFilesDialog::DataFilesDialog() connect(plugintable, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showContextMenu(const QPoint&))); connect(plugintable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setCheckstate(QModelIndex))); connect(pluginsmodel, SIGNAL(rowsAboutToBeMoved(const QModelIndex&, int, int, const QModelIndex&, int)), this, SLOT(test())); - + // Adjust the dialog width setMinimumWidth(500); } @@ -179,13 +179,13 @@ void DataFilesDialog::test() { qDebug() << "Breaky Breaky!"; /*QModelIndexList deselectedindexes = deselected.indexes(); - + if (!deselectedindexes.isEmpty()) { foreach (const QModelIndex ¤tindex, deselectedindexes) { qDebug() << "Data is: " << currentindex.data(); qDebug() << "Row is: "<< currentindex.row(); QList itemlist = pluginsmodel->findItems(QVariant(currentindex.data()).toString()); - + if (!itemlist.isEmpty()) { foreach (const QStandardItem *currentitem, itemlist) { @@ -201,14 +201,14 @@ void DataFilesDialog::appendPlugins(const QModelIndex &masterindex) // Find the plugins in the datafilesmodel and append them to the pluginsmodel if (!masterindex.isValid()) return; - + for (int r=0; rrowCount(masterindex); ++r ) { QModelIndex childindex = masterindex.child(r, 0); - + if (childindex.isValid()) { // Now we see if the pluginsmodel already contains this plugin QList itemlist = pluginsmodel->findItems(QVariant(datafilesmodel->data(childindex)).toString()); - + if (itemlist.isEmpty()) { // Plugin not yet in the pluginsmodel, add it @@ -218,22 +218,22 @@ void DataFilesDialog::appendPlugins(const QModelIndex &masterindex) pluginsmodel->appendRow(item); } } - + } - + } void DataFilesDialog::removePlugins(const QModelIndex &masterindex) { - + if (!masterindex.isValid()) return; - + for (int r=0; rrowCount(masterindex); ++r) { QModelIndex childindex = masterindex.child(r, 0); QList itemlist = pluginsmodel->findItems(QVariant(childindex.data()).toString()); - + if (!itemlist.isEmpty()) { foreach (const QStandardItem *currentitem, itemlist) { qDebug() << "Remove plugin:" << currentitem->data(Qt::DisplayRole).toString(); @@ -241,32 +241,32 @@ void DataFilesDialog::removePlugins(const QModelIndex &masterindex) } } } - + } void DataFilesDialog::masterSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) -{ +{ if (masterselectmodel->hasSelection()) { // Not exactly necessary to check const QModelIndexList selectedindexes = masterselectmodel->selectedIndexes(); - + QStringList masters; QString masterstr; - + // Create a QStringList containing all the masters foreach (const QModelIndex ¤tindex, selectedindexes) { masters.append(currentindex.data().toString()); } - + masters.sort(); masterstr = masters.join(","); // Make a comma-separated QString - + qDebug() << "Masters" << masterstr; - + // Iterate over all masters in the datafilesmodel to see if they are selected for (int r=0; rrowCount(); ++r) { QModelIndex currentindex = datafilesmodel->index(r, 0); QString master = currentindex.data().toString(); - + if (currentindex.isValid()) { // See if the current master is in the string with selected masters if (masterstr.contains(master)) @@ -277,10 +277,10 @@ void DataFilesDialog::masterSelectionChanged(const QItemSelection &selected, con } } } - + // See what plugins to remove QModelIndexList deselectedindexes = deselected.indexes(); - + if (!deselectedindexes.isEmpty()) { foreach (const QModelIndex ¤tindex, deselectedindexes) { @@ -288,15 +288,15 @@ void DataFilesDialog::masterSelectionChanged(const QItemSelection &selected, con master.prepend("*"); master.append("*"); QList itemlist = datafilesmodel->findItems(master, Qt::MatchWildcard); - + if (itemlist.isEmpty()) qDebug() << "Empty as shit"; - + foreach (const QStandardItem *currentitem, itemlist) { - + QModelIndex index = currentitem->index(); qDebug() << "Master to remove plugins of:" << index.data().toString(); - + removePlugins(index); } } @@ -306,29 +306,29 @@ void DataFilesDialog::masterSelectionChanged(const QItemSelection &selected, con void DataFilesDialog::showContextMenu(const QPoint &point) { qDebug() << "Show me the money!"; - - + + QAction *action1 = new QAction(QIcon::fromTheme("arrow-up-double"), tr("Move to Top"), this); QAction *action2 = new QAction(QIcon::fromTheme("arrow-down-double"), tr("Move to Bottom"), this); QAction *action3 = new QAction(QIcon::fromTheme("arrow-up"), tr("Move Up"), this); QAction *action4 = new QAction(QIcon::fromTheme("arrow-down"), tr("Move Down"), this); QAction *action5 = new QAction(this); - + QModelIndex index = plugintable->indexAt(point); - + if (index.isValid()) { // Should be valid! const QStandardItem *item = pluginsmodel->itemFromIndex(index); - + if (item->checkState() == Qt::Checked) { action5->setText("Uncheck Item"); } else if (item->checkState() == Qt::Unchecked) { action5->setText("Check Item"); } } - + connect(action5, SIGNAL(triggered()), this, SLOT(actionCheckstate())); - + QMenu menu(this); menu.addAction(action1); menu.addAction(action2); @@ -337,7 +337,7 @@ void DataFilesDialog::showContextMenu(const QPoint &point) menu.addAction(action4); menu.addSeparator(); menu.addAction(action5); - + menu.exec(plugintable->viewport()->mapToGlobal(point)); } @@ -345,14 +345,14 @@ void DataFilesDialog::showContextMenu(const QPoint &point) void DataFilesDialog::actionCheckstate() { qDebug() << "actionCheckstate"; - + const QModelIndexList selectedindexes = pluginselectmodel->selectedIndexes(); // Should only be one index selected foreach (const QModelIndex ¤tindex, selectedindexes) { setCheckstate(currentindex); } - + } void DataFilesDialog::setCheckstate(QModelIndex index) @@ -376,16 +376,16 @@ void DataFilesDialog::setCheckstate(QModelIndex index) } void DataFilesDialog::readConfig() -{ +{ /* QString filename; QString path = "data/"; // TODO: Should be global - + QFile file("openmw.cfg"); // Specify filepath later if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "error open"; close(); // File cannot be opened or created TODO: throw error } - + QTextStream in(&file); QStringList datafiles; @@ -393,27 +393,27 @@ void DataFilesDialog::readConfig() // Add each data file read from the config file to a QStringList while (!in.atEnd()) { QString line = in.readLine(); - + if (line.contains("master")) { filename = line.remove("master="); filename.prepend(path); - + datafiles << filename << "\n"; - + } else if (line.contains("plugin")) { filename = line.remove("plugin="); filename.prepend(path); - + datafiles << filename << "\n"; } } file.close(); - + // Check if the files are in the model, set to checked if found foreach(const QString ¤tfile, datafiles) { QModelIndex index = dataFilesModel->index(currentfile, 0); - + if (index.isValid()) { // File is found in model, set it to checked dataFilesModel->setData(index, Qt::Checked, Qt::CheckStateRole); @@ -430,14 +430,14 @@ void DataFilesDialog::writeConfig() //QString sectionname = "[Game Files]"; QString filename; QFileInfo datafile; - + // Sort the items so that master files end up on top foreach (const QString ¤titem, checkeditems) { if(currentitem.endsWith(QString(".esm"), Qt::CaseInsensitive)) { checkeditems.move(checkeditems.indexOf(currentitem), 0); } } - + QFile file("openmw.cfg"); // Specify filepath later if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) close(); // File cannot be opened or created TODO: throw error @@ -453,7 +453,7 @@ void DataFilesDialog::writeConfig() QString line = in.readLine(); //if (!line.contains("GameFile") && line != "[Game Files]") { if (!line.contains("master") && !line.contains("plugin")) { - buffer += line += "\n"; + buffer += line += "\n"; } } @@ -465,16 +465,16 @@ void DataFilesDialog::writeConfig() file.write(buffer); QTextStream out(&file); - + // Write the section name to the config file before we write out the data files //out << sectionname << endl; - + // Write the list of game files to the config for (int i = 0; i < checkeditems.size(); ++i) { //filename = dataFilesModel->fileName(checkeditems.at(i)); filename = checkeditems.at(i); datafile = QFileInfo(filename); - + if (datafile.exists()) { if (filename.endsWith(QString(".esm"), Qt::CaseInsensitive)) { out << "master=" << datafile.fileName() << endl; diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index c3aa6b0d30..e6792e2d6d 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -13,87 +13,87 @@ DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent) { mDataFilesModel = new QStandardItemModel(); // Contains all plugins with masters mPluginsModel = new QStandardItemModel(); // Contains selectable plugins - + mPluginsSelectModel = new QItemSelectionModel(mPluginsModel); - + //QPushButton *deselectButton = new QPushButton(tr("Deselect All")); QLabel *filterLabel = new QLabel(tr("Filter:"), this); LineEdit *filterLineEdit = new LineEdit(this); - + QHBoxLayout *topLayout = new QHBoxLayout(); QSpacerItem *hSpacer1 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - + topLayout->addItem(hSpacer1); topLayout->addWidget(filterLabel); topLayout->addWidget(filterLineEdit); - - mMastersWidget = new QTableWidget(this); // Contains the available masters + + mMastersWidget = new QTableWidget(this); // Contains the available masters mPluginsTable = new QTableView(this); - + // Add both tables to a splitter QSplitter *splitter = new QSplitter(this); splitter->setOrientation(Qt::Horizontal); splitter->addWidget(mMastersWidget); - splitter->addWidget(mPluginsTable); - + splitter->addWidget(mPluginsTable); + // Adjust the default widget widths inside the splitter QList sizeList; sizeList << 100 << 300; splitter->setSizes(sizeList); - + // Bottom part with profile options QLabel *profileLabel = new QLabel(tr("Current Profile:"), this); - + // TEST mProfileModel = new QStringListModel(); QStringList profileList; profileList << "Default" << "New" << "Yeah" << "Cool story bro!"; mProfileModel->setStringList(profileList); - + mProfileComboBox = new QComboBox(this); mProfileComboBox->setModel(mProfileModel); mProfileComboBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum)); mProfileComboBox->setInsertPolicy(QComboBox::InsertAtBottom); //mProfileComboBox->addItem(QString("New Profile")); - + QToolButton *NewProfileToolButton = new QToolButton(this); NewProfileToolButton->setIcon(QIcon::fromTheme("document-new")); - + QToolButton *CopyProfileToolButton = new QToolButton(this); CopyProfileToolButton->setIcon(QIcon::fromTheme("edit-copy")); - + QToolButton *DeleteProfileToolButton = new QToolButton(this); DeleteProfileToolButton->setIcon(QIcon::fromTheme("document-close")); - + QHBoxLayout *bottomLayout = new QHBoxLayout(); - + bottomLayout->addWidget(profileLabel); bottomLayout->addWidget(mProfileComboBox); bottomLayout->addWidget(NewProfileToolButton); bottomLayout->addWidget(CopyProfileToolButton); bottomLayout->addWidget(DeleteProfileToolButton); - + QVBoxLayout *pageLayout = new QVBoxLayout(this); // Add some space above and below the page items QSpacerItem *vSpacer1 = new QSpacerItem(5, 5, QSizePolicy::Minimum, QSizePolicy::Minimum); QSpacerItem *vSpacer2 = new QSpacerItem(5, 5, QSizePolicy::Minimum, QSizePolicy::Minimum); QSpacerItem *vSpacer3 = new QSpacerItem(5, 5, QSizePolicy::Minimum, QSizePolicy::Minimum); - + //pageLayout->addItem(vSpacer1); pageLayout->addLayout(topLayout); pageLayout->addItem(vSpacer2); pageLayout->addWidget(splitter); pageLayout->addLayout(bottomLayout); pageLayout->addItem(vSpacer3); - + setupDataFiles(); - + connect(mMastersWidget->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(masterSelectionChanged(const QItemSelection&, const QItemSelection&))); connect(mPluginsTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setCheckstate(QModelIndex))); connect(mPluginsModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(resizeRows())); - + } void DataFilesPage::setupDataFiles() @@ -106,7 +106,7 @@ void DataFilesPage::setupDataFiles() mMastersWidget->horizontalHeader()->hide(); mMastersWidget->verticalHeader()->hide(); mMastersWidget->insertColumn(0); - + mPluginsTable->setModel(mPluginsModel); mPluginsTable->setSelectionModel(mPluginsSelectModel); mPluginsTable->setSelectionBehavior(QAbstractItemView::SelectRows); @@ -115,45 +115,45 @@ void DataFilesPage::setupDataFiles() mPluginsTable->setAlternatingRowColors(true); mPluginsTable->horizontalHeader()->setStretchLastSection(true); mPluginsTable->horizontalHeader()->hide(); - - + + mPluginsTable->setDragEnabled(true); mPluginsTable->setDragDropMode(QAbstractItemView::InternalMove); mPluginsTable->setDropIndicatorShown(true); mPluginsTable->setDragDropOverwriteMode(false); mPluginsTable->viewport()->setAcceptDrops(true); - + mPluginsTable->setContextMenuPolicy(Qt::CustomContextMenu); - + // Some testing TODO TODO TODO - + QDir dataFilesDir("data/"); - + if (!dataFilesDir.exists()) qWarning("Cannot find the plugin directory"); - + dataFilesDir.setNameFilters((QStringList() << "*.esp")); // Only load plugins - + QStringList dataFiles = dataFilesDir.entryList(); - + for (int i=0; i itemList = mMastersWidget->findItems(currentMaster, Qt::MatchExactly); - + if (itemList.isEmpty()) // Master is not yet in the widget { mMastersWidget->insertRow(i); @@ -161,16 +161,16 @@ void DataFilesPage::setupDataFiles() mMastersWidget->setItem(i, 0, item); } } - + availableMasters.sort(); // Sort the masters alphabetically - + // Now we put the currentFile in the mDataFilesModel under its masters QStandardItem *parent = new QStandardItem(availableMasters.join(",")); QStandardItem *child = new QStandardItem(currentFile); - + QList masterList = mDataFilesModel->findItems(availableMasters.join(",")); - - + + if (masterList.isEmpty()) { // Masters node not yet in the mDataFilesModel parent->appendRow(child); mDataFilesModel->appendRow(parent); @@ -187,25 +187,25 @@ void DataFilesPage::masterSelectionChanged(const QItemSelection &selected, const { if (mMastersWidget->selectionModel()->hasSelection()) { const QModelIndexList selectedIndexes = mMastersWidget->selectionModel()->selectedIndexes(); - + QStringList masters; QString masterstr; - + // Create a QStringList containing all the masters foreach (const QModelIndex &index, selectedIndexes) { masters.append(index.data().toString()); } - + masters.sort(); masterstr = masters.join(","); // Make a comma-separated QString - + qDebug() << "Masters" << masterstr; - + // Iterate over all masters in the datafilesmodel to see if they are selected for (int r=0; rrowCount(); ++r) { QModelIndex currentIndex = mDataFilesModel->index(r, 0); QString master = currentIndex.data().toString(); - + if (currentIndex.isValid()) { // See if the current master is in the string with selected masters if (masterstr.contains(master)) @@ -217,10 +217,10 @@ void DataFilesPage::masterSelectionChanged(const QItemSelection &selected, const } } } - + // See what plugins to remove QModelIndexList deselectedIndexes = deselected.indexes(); - + if (!deselectedIndexes.isEmpty()) { foreach (const QModelIndex ¤tIndex, deselectedIndexes) { @@ -228,15 +228,15 @@ void DataFilesPage::masterSelectionChanged(const QItemSelection &selected, const master.prepend("*"); master.append("*"); QList itemList = mDataFilesModel->findItems(master, Qt::MatchWildcard); - + if (itemList.isEmpty()) qDebug() << "Empty as shit"; - + foreach (const QStandardItem *currentItem, itemList) { - + QModelIndex index = currentItem->index(); qDebug() << "Master to remove plugins of:" << index.data().toString(); - + removePlugins(index); } } @@ -248,15 +248,15 @@ void DataFilesPage::addPlugins(const QModelIndex &index) // Find the plugins in the datafilesmodel and append them to the pluginsmodel if (!index.isValid()) return; - + for (int r=0; rrowCount(index); ++r ) { QModelIndex childIndex = index.child(r, 0); const QString childIndexData = QVariant(mDataFilesModel->data(childIndex)).toString(); - + if (childIndex.isValid()) { // Now we see if the pluginsmodel already contains this plugin QList itemList = mPluginsModel->findItems(childIndexData); - + if (itemList.isEmpty()) { // Plugin not yet in the pluginsmodel, add it @@ -267,31 +267,31 @@ void DataFilesPage::addPlugins(const QModelIndex &index) mPluginsModel->appendRow(item); } } - + } - + } void DataFilesPage::removePlugins(const QModelIndex &index) { - + if (!index.isValid()) return; - + for (int r=0; rrowCount(index); ++r) { QModelIndex childIndex = index.child(r, 0); QList itemList = mPluginsModel->findItems(QVariant(childIndex.data()).toString()); - + if (!itemList.isEmpty()) { foreach (const QStandardItem *currentItem, itemList) { qDebug() << "Remove plugin:" << currentItem->data(Qt::DisplayRole).toString(); - + mPluginsModel->removeRow(currentItem->row()); } } } - + } void DataFilesPage::setCheckstate(QModelIndex index) diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index 689c17ef44..2c2764a678 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -30,16 +30,16 @@ public slots: private: QTableWidget *mMastersWidget; QTableView *mPluginsTable; - + QStandardItemModel *mDataFilesModel; QStandardItemModel *mPluginsModel; - + QItemSelectionModel *mPluginsSelectModel; void setupDataFiles(); void addPlugins(const QModelIndex &index); void removePlugins(const QModelIndex &index); -}; +}; -#endif +#endif diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 8d1c8b69c3..8b13789179 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -1 +1 @@ - + diff --git a/apps/launcher/graphicspage.hpp b/apps/launcher/graphicspage.hpp index 8d1c8b69c3..8b13789179 100644 --- a/apps/launcher/graphicspage.hpp +++ b/apps/launcher/graphicspage.hpp @@ -1 +1 @@ - + diff --git a/apps/launcher/maindialog.hpp b/apps/launcher/maindialog.hpp index c1b7a6a81a..b94727bd44 100644 --- a/apps/launcher/maindialog.hpp +++ b/apps/launcher/maindialog.hpp @@ -19,7 +19,7 @@ public: MainDialog(); //QStringListModel *mProfileModel; - + public slots: void changePage(QListWidgetItem *current, QListWidgetItem *previous); @@ -28,7 +28,7 @@ private: QListWidget *mIconWidget; QStackedWidget *mPagesWidget; - + PlayPage *mPlayPage; DataFilesPage *mDataFilesPage; }; diff --git a/apps/launcher/playpage.hpp b/apps/launcher/playpage.hpp index dcf7c48f37..14689d5d50 100644 --- a/apps/launcher/playpage.hpp +++ b/apps/launcher/playpage.hpp @@ -12,9 +12,9 @@ class PlayPage : public QWidget public: PlayPage(QWidget *parent = 0); - + QComboBox *mProfileComboBox; QStringListModel *mProfileModel; -}; +}; #endif \ No newline at end of file diff --git a/apps/launcher/settingsdialog.cpp b/apps/launcher/settingsdialog.cpp index 100254ce65..cce5715a50 100644 --- a/apps/launcher/settingsdialog.cpp +++ b/apps/launcher/settingsdialog.cpp @@ -3,120 +3,120 @@ #include "settingsdialog.h" SettingsDialog::SettingsDialog() -{ +{ QTabWidget *tabWidget = new QTabWidget(this); QWidget *graphicsTab = new QWidget(); - + // Render group QGroupBox *groupRender = new QGroupBox(tr("Renderer"), graphicsTab); groupRender->setMinimumWidth(450); - + QVBoxLayout *groupRenderLayout = new QVBoxLayout(groupRender); QVBoxLayout *dialogLayout = new QVBoxLayout(this); QVBoxLayout *pageLayout = new QVBoxLayout(graphicsTab); - + QGridLayout *renderLayout = new QGridLayout(); - - QLabel *labelRender = new QLabel(tr("Rendering Subsystem:"), groupRender); + + QLabel *labelRender = new QLabel(tr("Rendering Subsystem:"), groupRender); comboRender = new QComboBox(groupRender); - - QLabel *labelRTT = new QLabel(tr("Preferred RTT Mode:"), groupRender); + + QLabel *labelRTT = new QLabel(tr("Preferred RTT Mode:"), groupRender); comboRTT = new QComboBox(groupRender); - + QLabel *labelAA = new QLabel(tr("Antialiasing:"), groupRender); comboAA = new QComboBox(groupRender); - + renderLayout->addWidget(labelRender, 0, 0, 1, 1); renderLayout->addWidget(comboRender, 0, 1, 1, 1); - + QSpacerItem *vSpacer1 = new QSpacerItem(20, 10, QSizePolicy::Minimum, QSizePolicy::Minimum); renderLayout->addItem(vSpacer1, 1, 1, 1, 1); - + renderLayout->addWidget(labelRTT, 2, 0, 1, 1); renderLayout->addWidget(comboRTT, 2, 1, 1, 1); renderLayout->addWidget(labelAA, 3, 0, 1, 1); renderLayout->addWidget(comboAA, 3, 1, 1, 1); - + QSpacerItem *vSpacer2 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); - + groupRenderLayout->addLayout(renderLayout); groupRenderLayout->addItem(vSpacer2); - + pageLayout->addWidget(groupRender); - + // Display group QGroupBox *groupDisplay = new QGroupBox(tr("Display"), graphicsTab); QVBoxLayout *groupDisplayLayout = new QVBoxLayout(groupDisplay); QGridLayout *displayLayout = new QGridLayout(); - + QLabel *labelResolution = new QLabel(tr("Resolution:"), groupDisplay); comboResolution = new QComboBox(groupDisplay); - + QLabel *labelFrequency = new QLabel(tr("Display Frequency:"), groupDisplay); comboFrequency = new QComboBox(groupDisplay); - + checkVSync = new QCheckBox(tr("Vertical Sync"), groupDisplay); checkGamma = new QCheckBox(tr("sRGB Gamma Conversion"), groupDisplay); checkFullScreen = new QCheckBox(tr("Full Screen"), groupDisplay); - + displayLayout->addWidget(labelResolution, 0, 0, 1, 1); - displayLayout->addWidget(comboResolution, 0, 1, 1, 1); + displayLayout->addWidget(comboResolution, 0, 1, 1, 1); displayLayout->addWidget(labelFrequency, 1, 0, 1, 1); displayLayout->addWidget(comboFrequency, 1, 1, 1, 1); - + QSpacerItem *vSpacer3 = new QSpacerItem(20, 10, QSizePolicy::Minimum, QSizePolicy::Minimum); displayLayout->addItem(vSpacer3, 2, 1, 1, 1); - + displayLayout->addWidget(checkVSync, 3, 0, 1, 1); displayLayout->addWidget(checkGamma, 3, 1, 1, 1); displayLayout->addWidget(checkFullScreen, 6, 0, 1, 1); - + QSpacerItem *vSpacer4 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); - + groupDisplayLayout->addLayout(displayLayout); groupDisplayLayout->addItem(vSpacer4); - + pageLayout->addWidget(groupDisplay); - - + + tabWidget->addTab(graphicsTab, QString(tr("Graphics"))); tabWidget->setCurrentIndex(0); - + dialogLayout->addWidget(tabWidget); - + QDialogButtonBox *buttonBox = new QDialogButtonBox(this); buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); dialogLayout->addWidget(buttonBox); - + setWindowTitle(tr("Settings")); setWindowIcon(QIcon::fromTheme("preferences-other")); - + // Ogre Settings // TODO: Find out a way to do this nice and platform-independent QString filepath = QDir::homePath(); filepath.append("/.config/openmw/ogre.cfg"); - + ogreConfig = new QSettings(filepath, QSettings::IniFormat); - + // Signals and slots connect(comboRender, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(rendererChanged(const QString&))); connect(buttonBox, SIGNAL(accepted()), this, SLOT(writeConfig())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(close())); - + // Ogre stuff root = new Ogre::Root("plugins.cfg"); - + // Get the available renderers and put them in the combobox const Ogre::RenderSystemList &renderers = root->getAvailableRenderers(); - + for (Ogre::RenderSystemList::const_iterator r = renderers.begin(); r != renderers.end(); ++r) { - comboRender->addItem((*r)->getName().c_str()); + comboRender->addItem((*r)->getName().c_str()); } - + int index = comboRender->findText(getConfigValue("Render System")); - + if ( index != -1) { comboRender->setCurrentIndex(index); } @@ -126,10 +126,10 @@ SettingsDialog::SettingsDialog() QStringList SettingsDialog::getAvailableOptions(const QString& key) { QStringList result; - + uint row = 0; Ogre::ConfigOptionMap options = mSelectedRenderSystem->getConfigOptions(); - + for (Ogre::ConfigOptionMap::iterator i = options.begin (); i != options.end (); i++, row++) { Ogre::StringVector::iterator opt_it; @@ -137,64 +137,64 @@ QStringList SettingsDialog::getAvailableOptions(const QString& key) for (opt_it = i->second.possibleValues.begin (); opt_it != i->second.possibleValues.end (); opt_it++, idx++) { - + if (strcmp (key.toStdString().c_str(), i->first.c_str()) == 0) result << (*opt_it).c_str(); - } - + } + } - + return result; } void SettingsDialog::rendererChanged(const QString& renderer) -{ +{ // Set the render system to the selected one mSelectedRenderSystem = root->getRenderSystemByName(renderer.toStdString().c_str()); - + comboRTT->addItems(getAvailableOptions("RTT Preferred Mode")); comboAA->addItems(getAvailableOptions("FSAA")); comboResolution->addItems(getAvailableOptions("Video Mode")); comboFrequency->addItems(getAvailableOptions("Display Frequency")); - + // Get the value for the option the config file, find if it's in the combobox. // If it's found, set the current index to that value, otherwise: ignore. - + int index = comboRTT->findText(getConfigValue("RTT Preferred Mode")); if ( index != -1) comboRTT->setCurrentIndex(index); - + index = comboAA->findText(getConfigValue("FSAA")); if ( index != -1) comboAA->setCurrentIndex(index); - + index = comboResolution->findText(getConfigValue("Video Mode")); if ( index != -1) comboResolution->setCurrentIndex(index); - + index = comboFrequency->findText(getConfigValue("Display Frequency")); if ( index != -1) comboFrequency->setCurrentIndex(index); - + // Now we do the same for the checkboxes if (QString::compare(getConfigValue("VSync"), QString("Yes")) == 0) { checkVSync->setCheckState(Qt::Checked); } - + if (QString::compare(getConfigValue("sRGB Gamma Conversion"), QString("Yes")) == 0) { checkGamma->setCheckState(Qt::Checked); } - + if (QString::compare(getConfigValue("Full Screen"), QString("Yes")) == 0) { checkFullScreen->setCheckState(Qt::Checked); } - + } QString SettingsDialog::getConfigValue(const QString& key) { QString result; - + ogreConfig->beginGroup(mSelectedRenderSystem->getName().c_str()); result = ogreConfig->value(key).toString(); ogreConfig->endGroup(); @@ -205,22 +205,22 @@ QString SettingsDialog::getConfigValue(const QString& key) void SettingsDialog::writeConfig() { // Get the values from the GUI elements and write them to the config file - + // Custom write method: We cannot use QSettings because it does not accept spaces QString keyName; QString fileName; QFile file(ogreConfig->fileName()); - + if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) // File could not be opened, TODO error close(); QTextStream out(&file); - + out << "Render System=" << mSelectedRenderSystem->getName().c_str() << endl << endl; - + // add brackets to the renderer's name QString renderer = mSelectedRenderSystem->getName().c_str(); renderer.prepend("["); @@ -229,21 +229,21 @@ void SettingsDialog::writeConfig() out << "Display Frequency=" << comboFrequency->currentText() << endl; out << "FSAA=" << comboAA->currentText() << endl; - + if (checkFullScreen->checkState() == Qt::Checked) { out << "Full Screen=Yes" << endl; } else { out << "Full Screen=No" << endl; } - + out << "RTT Preferred Mode=" << comboRTT->currentText() << endl; - + if (checkVSync->checkState() == Qt::Checked) { out << "VSync=Yes" << endl; } else { out << "VSync=No" << endl; } - + out << "Video Mode=" << comboResolution->currentText() << endl; if (checkGamma->checkState() == Qt::Checked) { @@ -251,9 +251,9 @@ void SettingsDialog::writeConfig() } else { out << "sRGB Gamma Conversion=No" << endl; } - + file.close(); - + close(); // Exit dialog }