21 #include <QPushButton> |
21 #include <QPushButton> |
22 #include <QGroupBox> |
22 #include <QGroupBox> |
23 #include <QComboBox> |
23 #include <QComboBox> |
24 #include <QCheckBox> |
24 #include <QCheckBox> |
25 #include <QLabel> |
25 #include <QLabel> |
|
26 #include <QTableWidget> |
26 #include <QLineEdit> |
27 #include <QLineEdit> |
27 #include <QSpinBox> |
28 #include <QSpinBox> |
28 #include <QTextBrowser> |
29 #include <QTextBrowser> |
29 #include <QTableWidget> |
30 #include <QScrollArea> |
|
31 #include <QHeaderView> |
30 #include <QSlider> |
32 #include <QSlider> |
31 #include <QSignalMapper> |
33 #include <QSignalMapper> |
32 #include <QColorDialog> |
34 #include <QColorDialog> |
33 #include <QStandardItemModel> |
35 #include <QStandardItemModel> |
|
36 #include <QDebug> |
34 |
37 |
35 #include "pageoptions.h" |
38 #include "pageoptions.h" |
36 #include "gameuiconfig.h" |
39 #include "gameuiconfig.h" |
37 #include "hwconsts.h" |
40 #include "hwconsts.h" |
38 #include "fpsedit.h" |
41 #include "fpsedit.h" |
39 #include "igbox.h" |
42 #include "igbox.h" |
40 #include "DataManager.h" |
43 #include "DataManager.h" |
41 #include "LibavInteraction.h" |
44 #include "LibavInteraction.h" |
42 #include "AutoUpdater.h" |
45 #include "AutoUpdater.h" |
|
46 #include "HWApplication.h" |
|
47 #include "keybinder.h" |
43 |
48 |
44 #ifdef __APPLE__ |
49 #ifdef __APPLE__ |
45 #ifdef SPARKLE_ENABLED |
50 #ifdef SPARKLE_ENABLED |
46 #include "SparkleAutoUpdater.h" |
51 #include "SparkleAutoUpdater.h" |
47 #endif |
52 #endif |
54 |
59 |
55 QTabWidget * tabs = new QTabWidget(this); |
60 QTabWidget * tabs = new QTabWidget(this); |
56 pageLayout->addWidget(tabs); |
61 pageLayout->addWidget(tabs); |
57 QWidget * page1 = new QWidget(this); |
62 QWidget * page1 = new QWidget(this); |
58 QWidget * page2 = new QWidget(this); |
63 QWidget * page2 = new QWidget(this); |
|
64 binder = new KeyBinder(this, tr("Select an action to change what key controls it"), tr("Reset to default"), tr("Reset all binds")); |
|
65 connect(binder, SIGNAL(bindUpdate(int)), this, SLOT(bindUpdated(int))); |
|
66 connect(binder, SIGNAL(resetAllBinds()), this, SLOT(resetAllBinds())); |
59 tabs->addTab(page1, tr("General")); |
67 tabs->addTab(page1, tr("General")); |
|
68 binderTab = tabs->addTab(binder, tr("Controls")); |
60 tabs->addTab(page2, tr("Advanced")); |
69 tabs->addTab(page2, tr("Advanced")); |
|
70 |
|
71 connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(tabIndexChanged(int))); |
61 |
72 |
62 #ifdef VIDEOREC |
73 #ifdef VIDEOREC |
63 QWidget * page3 = new QWidget(this); |
74 QWidget * page3 = new QWidget(this); |
64 tabs->addTab(page3, tr("Video Recording")); |
75 tabs->addTab(page3, tr("Video Recording")); |
65 #endif |
76 #endif |
944 if (iACodec != -1) |
955 if (iACodec != -1) |
945 comboAudioCodecs->setCurrentIndex(iACodec); |
956 comboAudioCodecs->setCurrentIndex(iACodec); |
946 |
957 |
947 return true; |
958 return true; |
948 } |
959 } |
|
960 |
|
961 // When the current tab is switched |
|
962 void PageOptions::tabIndexChanged(int index) |
|
963 { |
|
964 if (index == binderTab) // Switched to bind tab |
|
965 { |
|
966 binder->resetInterface(); |
|
967 |
|
968 if (!config) return; |
|
969 |
|
970 QStandardItemModel * binds = DataManager::instance().bindsModel(); |
|
971 for(int i = 0; i < BINDS_NUMBER; i++) |
|
972 { |
|
973 QString value = config->bind(i); |
|
974 QModelIndexList mdl = binds->match(binds->index(0, 0), Qt::UserRole + 1, value, 1, Qt::MatchExactly); |
|
975 if(mdl.size() == 1) binder->setBindIndex(i, mdl[0].row()); |
|
976 } |
|
977 } |
|
978 |
|
979 currentTab = index; |
|
980 } |
|
981 |
|
982 // When a key bind combobox is changed |
|
983 void PageOptions::bindUpdated(int bindID) |
|
984 { |
|
985 int bindIndex = binder->bindIndex(bindID); |
|
986 |
|
987 if (bindIndex == 0) bindIndex = resetBindToDefault(bindID); |
|
988 |
|
989 // Save bind |
|
990 QStandardItemModel * binds = DataManager::instance().bindsModel(); |
|
991 QString strbind = binds->index(binder->bindIndex(bindID), 0).data(Qt::UserRole + 1).toString(); |
|
992 config->setBind(bindID, strbind); |
|
993 } |
|
994 |
|
995 // Changes a key bind (bindID) to its default value. This updates the bind's combo-box in the UI. |
|
996 // Returns: The bind model index of the default. |
|
997 int PageOptions::resetBindToDefault(int bindID) |
|
998 { |
|
999 QStandardItemModel * binds = DataManager::instance().bindsModel(); |
|
1000 QModelIndexList mdl = binds->match(binds->index(0, 0), Qt::UserRole + 1, cbinds[bindID].strbind, 1, Qt::MatchExactly); |
|
1001 if(mdl.size() == 1) binder->setBindIndex(bindID, mdl[0].row()); |
|
1002 return mdl[0].row(); |
|
1003 } |
|
1004 |
|
1005 // Called when "reset all binds" button is pressed |
|
1006 void PageOptions::resetAllBinds() |
|
1007 { |
|
1008 for (int i = 0; i < BINDS_NUMBER; i++) |
|
1009 { |
|
1010 resetBindToDefault(i); |
|
1011 bindUpdated(i); |
|
1012 } |
|
1013 } |