|
1 #include <QLabel> |
1 #include <QFileDialog> |
2 #include <QFileDialog> |
|
3 #include <QFormLayout> |
2 #include "config.h" |
4 #include "config.h" |
3 #include "ui_configbox.h" |
5 #include "ui_configbox.h" |
|
6 |
|
7 // ============================================================================= |
|
8 // ----------------------------------------------------------------------------- |
|
9 class FindPathButton : public QPushButton { |
|
10 public: |
|
11 explicit FindPathButton( QWidget* parent = null ) : QPushButton( parent ) { |
|
12 setText( "..." ); |
|
13 } |
|
14 |
|
15 QLineEdit* editWidget() const { return m_editWidget; } |
|
16 void setEditWidget( QLineEdit* edit ) { m_editWidget = edit; } |
|
17 |
|
18 private: |
|
19 QLineEdit* m_editWidget; |
|
20 }; |
4 |
21 |
5 // ============================================================================= |
22 // ============================================================================= |
6 // ----------------------------------------------------------------------------- |
23 // ----------------------------------------------------------------------------- |
7 ConfigBox::ConfigBox( QWidget* parent, Qt::WindowFlags f ) : QDialog( parent, f ) { |
24 ConfigBox::ConfigBox( QWidget* parent, Qt::WindowFlags f ) : QDialog( parent, f ) { |
8 ui = new Ui_ConfigBox; |
25 ui = new Ui_ConfigBox; |
9 ui->setupUi( this ); |
26 ui->setupUi( this ); |
10 setWindowTitle( fmt( APPNAME " %1", versionString())); |
27 QFormLayout* layout = new QFormLayout( ui->zandronumVersions ); |
|
28 |
|
29 for( str ver : g_zanVersions ) { |
|
30 QLabel* lb = new QLabel( ver + ":" ); |
|
31 QLineEdit* ledit = new QLineEdit; |
|
32 FindPathButton* btn = new FindPathButton; |
|
33 btn->setEditWidget( ledit ); |
|
34 |
|
35 QWidget* wdg = new QWidget; |
|
36 QHBoxLayout* leditLayout = new QHBoxLayout( wdg ); |
|
37 leditLayout->addWidget( ledit ); |
|
38 leditLayout->addWidget( btn ); |
|
39 |
|
40 m_zanBinaries << ledit; |
|
41 layout->addRow( lb, wdg ); |
|
42 connect( btn, SIGNAL( clicked() ), this, SLOT( findZanBinary() )); |
|
43 } |
|
44 |
|
45 initFromSettings(); |
11 |
46 |
12 connect( ui->wad_add, SIGNAL( clicked() ), this, SLOT( addPath() )); |
47 connect( ui->wad_add, SIGNAL( clicked() ), this, SLOT( addPath() )); |
13 connect( ui->wad_pathEntry, SIGNAL( returnPressed() ), this, SLOT( addPath() )); |
48 connect( ui->wad_pathEntry, SIGNAL( returnPressed() ), this, SLOT( addPath() )); |
14 connect( ui->wad_findPath, SIGNAL( clicked() ), this, SLOT( findPath() )); |
49 connect( ui->wad_findPath, SIGNAL( clicked() ), this, SLOT( findPath() )); |
15 connect( ui->wad_del, SIGNAL( clicked() ), this, SLOT( delPath() )); |
50 connect( ui->wad_del, SIGNAL( clicked() ), this, SLOT( delPath() )); |
|
51 connect( ui->buttonBox, SIGNAL( accepted() ), this, SLOT( okPressed() )); |
|
52 connect( ui->buttonBox, SIGNAL( rejected() ), this, SLOT( cancelPressed() )); |
|
53 setWindowTitle( fmt( APPNAME " %1", versionString())); |
16 } |
54 } |
17 |
55 |
18 // ============================================================================= |
56 // ============================================================================= |
19 // ----------------------------------------------------------------------------- |
57 // ----------------------------------------------------------------------------- |
20 ConfigBox::~ConfigBox() { |
58 ConfigBox::~ConfigBox() { |
22 } |
60 } |
23 |
61 |
24 // ============================================================================= |
62 // ============================================================================= |
25 // ----------------------------------------------------------------------------- |
63 // ----------------------------------------------------------------------------- |
26 void ConfigBox::initFromSettings() { |
64 void ConfigBox::initFromSettings() { |
|
65 QSettings cfg; |
|
66 |
27 ui->wad_pathsList->clear(); |
67 ui->wad_pathsList->clear(); |
28 |
68 |
29 list<var> paths = cfg->value( "wads/paths", list<var>() ).toList(); |
69 list<var> paths = cfg.value( "wads/paths", list<var>() ).toList(); |
30 for( const var& it : paths ) |
70 for( const var& it : paths ) |
31 addPath( it.toString() ); |
71 addPath( it.toString() ); |
|
72 |
|
73 int i = 0; |
|
74 for( str ver : g_zanVersions ) |
|
75 m_zanBinaries[i++]->setText( cfg.value( binaryConfigName( ver ), "" ).toString() ); |
32 } |
76 } |
33 |
77 |
34 // ============================================================================= |
78 // ============================================================================= |
35 // ----------------------------------------------------------------------------- |
79 // ----------------------------------------------------------------------------- |
36 void ConfigBox::addPath() { |
80 void ConfigBox::addPath() { |
40 |
84 |
41 // ============================================================================= |
85 // ============================================================================= |
42 // ----------------------------------------------------------------------------- |
86 // ----------------------------------------------------------------------------- |
43 void ConfigBox::addPath( str path ) { |
87 void ConfigBox::addPath( str path ) { |
44 ui->wad_pathsList->addItem( path ); |
88 ui->wad_pathsList->addItem( path ); |
|
89 QListWidgetItem* item = ui->wad_pathsList->item( ui->wad_pathsList->count() - 1 ); |
|
90 item->setFlags( item->flags() | Qt::ItemIsEditable ); |
45 } |
91 } |
46 |
92 |
47 // ============================================================================= |
93 // ============================================================================= |
48 // ----------------------------------------------------------------------------- |
94 // ----------------------------------------------------------------------------- |
49 void ConfigBox::findPath() { |
95 void ConfigBox::findPath() { |
57 // ============================================================================= |
103 // ============================================================================= |
58 // ----------------------------------------------------------------------------- |
104 // ----------------------------------------------------------------------------- |
59 void ConfigBox::delPath() { |
105 void ConfigBox::delPath() { |
60 delete ui->wad_pathsList->currentItem(); |
106 delete ui->wad_pathsList->currentItem(); |
61 } |
107 } |
|
108 |
|
109 // ============================================================================= |
|
110 // ----------------------------------------------------------------------------- |
|
111 void ConfigBox::findZanBinary() { |
|
112 FindPathButton* btn = dynamic_cast<FindPathButton*>( sender() ); |
|
113 str path; |
|
114 |
|
115 if( !btn ) |
|
116 return; |
|
117 |
|
118 str filter; |
|
119 #ifdef _WIN32 |
|
120 filter = "Zandronum Binaries (zandronum.exe)(zandronum.exe);;All files (*.*)(*.*)"; |
|
121 #else |
|
122 filter = "Zandronum Binaries (zandronum)(zandronum);;All files (*.*)(*.*)"; |
|
123 #endif |
|
124 |
|
125 if(( path = QFileDialog::getOpenFileName( this, QString(), QString(), filter )).isEmpty() ) |
|
126 return; |
|
127 |
|
128 btn->editWidget()->setText( path ); |
|
129 } |
|
130 |
|
131 // ============================================================================= |
|
132 // ----------------------------------------------------------------------------- |
|
133 void ConfigBox::okPressed() { |
|
134 QSettings cfg; |
|
135 list<var> wadPathList; |
|
136 |
|
137 for( int i = 0; i < ui->wad_pathsList->count(); ++i ) |
|
138 wadPathList << ui->wad_pathsList->item( i )->text(); |
|
139 |
|
140 cfg.setValue( "wads/paths", wadPathList ); |
|
141 |
|
142 int i = 0; |
|
143 for( str ver : g_zanVersions ) |
|
144 cfg.setValue( binaryConfigName( ver ), m_zanBinaries[i++]->text() ); |
|
145 |
|
146 accept(); |
|
147 } |
|
148 |
|
149 // ============================================================================= |
|
150 // ----------------------------------------------------------------------------- |
|
151 void ConfigBox::cancelPressed() { |
|
152 reject(); |
|
153 } |
|
154 |
|
155 // ============================================================================= |
|
156 // ----------------------------------------------------------------------------- |
|
157 str ConfigBox::binaryConfigName( str ver ) const { |
|
158 return fmt( "binaries/%1", ver ); |
|
159 } |