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 |
912 if (iACodec != -1) |
923 if (iACodec != -1) |
913 comboAudioCodecs->setCurrentIndex(iACodec); |
924 comboAudioCodecs->setCurrentIndex(iACodec); |
914 |
925 |
915 return true; |
926 return true; |
916 } |
927 } |
|
928 |
|
929 // When the current tab is switched |
|
930 void PageOptions::tabIndexChanged(int index) |
|
931 { |
|
932 if (index == binderTab) // Switched to bind tab |
|
933 { |
|
934 binder->resetInterface(); |
|
935 |
|
936 if (!config) return; |
|
937 |
|
938 QStandardItemModel * binds = DataManager::instance().bindsModel(); |
|
939 for(int i = 0; i < BINDS_NUMBER; i++) |
|
940 { |
|
941 QString value = config->bind(i); |
|
942 QModelIndexList mdl = binds->match(binds->index(0, 0), Qt::UserRole + 1, value, 1, Qt::MatchExactly); |
|
943 if(mdl.size() == 1) binder->setBindIndex(i, mdl[0].row()); |
|
944 } |
|
945 } |
|
946 |
|
947 currentTab = index; |
|
948 } |
|
949 |
|
950 // When a key bind combobox is changed |
|
951 void PageOptions::bindUpdated(int bindID) |
|
952 { |
|
953 int bindIndex = binder->bindIndex(bindID); |
|
954 |
|
955 if (bindIndex == 0) bindIndex = resetBindToDefault(bindID); |
|
956 |
|
957 // Save bind |
|
958 QStandardItemModel * binds = DataManager::instance().bindsModel(); |
|
959 QString strbind = binds->index(binder->bindIndex(bindID), 0).data(Qt::UserRole + 1).toString(); |
|
960 config->setBind(bindID, strbind); |
|
961 } |
|
962 |
|
963 // Changes a key bind (bindID) to its default value. This updates the bind's combo-box in the UI. |
|
964 // Returns: The bind model index of the default. |
|
965 int PageOptions::resetBindToDefault(int bindID) |
|
966 { |
|
967 QStandardItemModel * binds = DataManager::instance().bindsModel(); |
|
968 QModelIndexList mdl = binds->match(binds->index(0, 0), Qt::UserRole + 1, cbinds[bindID].strbind, 1, Qt::MatchExactly); |
|
969 if(mdl.size() == 1) binder->setBindIndex(bindID, mdl[0].row()); |
|
970 return mdl[0].row(); |
|
971 } |
|
972 |
|
973 // Called when "reset all binds" button is pressed |
|
974 void PageOptions::resetAllBinds() |
|
975 { |
|
976 for (int i = 0; i < BINDS_NUMBER; i++) |
|
977 { |
|
978 resetBindToDefault(i); |
|
979 bindUpdated(i); |
|
980 } |
|
981 } |