Wed, 17 Jul 2013 03:06:21 +0300
Added configs for Zandronum binary paths
src/config.cpp | file | annotate | diff | comparison | revisions | |
src/config.h | file | annotate | diff | comparison | revisions | |
src/main.cpp | file | annotate | diff | comparison | revisions | |
src/main.h | file | annotate | diff | comparison | revisions | |
src/ui/configbox.ui | file | annotate | diff | comparison | revisions |
--- a/src/config.cpp Wed Jul 17 01:55:18 2013 +0300 +++ b/src/config.cpp Wed Jul 17 03:06:21 2013 +0300 @@ -1,18 +1,56 @@ +#include <QLabel> #include <QFileDialog> +#include <QFormLayout> #include "config.h" #include "ui_configbox.h" // ============================================================================= // ----------------------------------------------------------------------------- +class FindPathButton : public QPushButton { +public: + explicit FindPathButton( QWidget* parent = null ) : QPushButton( parent ) { + setText( "..." ); + } + + QLineEdit* editWidget() const { return m_editWidget; } + void setEditWidget( QLineEdit* edit ) { m_editWidget = edit; } + +private: + QLineEdit* m_editWidget; +}; + +// ============================================================================= +// ----------------------------------------------------------------------------- ConfigBox::ConfigBox( QWidget* parent, Qt::WindowFlags f ) : QDialog( parent, f ) { ui = new Ui_ConfigBox; ui->setupUi( this ); - setWindowTitle( fmt( APPNAME " %1", versionString())); + QFormLayout* layout = new QFormLayout( ui->zandronumVersions ); + + for( str ver : g_zanVersions ) { + QLabel* lb = new QLabel( ver + ":" ); + QLineEdit* ledit = new QLineEdit; + FindPathButton* btn = new FindPathButton; + btn->setEditWidget( ledit ); + + QWidget* wdg = new QWidget; + QHBoxLayout* leditLayout = new QHBoxLayout( wdg ); + leditLayout->addWidget( ledit ); + leditLayout->addWidget( btn ); + + m_zanBinaries << ledit; + layout->addRow( lb, wdg ); + connect( btn, SIGNAL( clicked() ), this, SLOT( findZanBinary() )); + } + + initFromSettings(); connect( ui->wad_add, SIGNAL( clicked() ), this, SLOT( addPath() )); connect( ui->wad_pathEntry, SIGNAL( returnPressed() ), this, SLOT( addPath() )); connect( ui->wad_findPath, SIGNAL( clicked() ), this, SLOT( findPath() )); connect( ui->wad_del, SIGNAL( clicked() ), this, SLOT( delPath() )); + connect( ui->buttonBox, SIGNAL( accepted() ), this, SLOT( okPressed() )); + connect( ui->buttonBox, SIGNAL( rejected() ), this, SLOT( cancelPressed() )); + setWindowTitle( fmt( APPNAME " %1", versionString())); } // ============================================================================= @@ -24,11 +62,17 @@ // ============================================================================= // ----------------------------------------------------------------------------- void ConfigBox::initFromSettings() { + QSettings cfg; + ui->wad_pathsList->clear(); - list<var> paths = cfg->value( "wads/paths", list<var>() ).toList(); + list<var> paths = cfg.value( "wads/paths", list<var>() ).toList(); for( const var& it : paths ) addPath( it.toString() ); + + int i = 0; + for( str ver : g_zanVersions ) + m_zanBinaries[i++]->setText( cfg.value( binaryConfigName( ver ), "" ).toString() ); } // ============================================================================= @@ -42,6 +86,8 @@ // ----------------------------------------------------------------------------- void ConfigBox::addPath( str path ) { ui->wad_pathsList->addItem( path ); + QListWidgetItem* item = ui->wad_pathsList->item( ui->wad_pathsList->count() - 1 ); + item->setFlags( item->flags() | Qt::ItemIsEditable ); } // ============================================================================= @@ -59,3 +105,55 @@ void ConfigBox::delPath() { delete ui->wad_pathsList->currentItem(); } + +// ============================================================================= +// ----------------------------------------------------------------------------- +void ConfigBox::findZanBinary() { + FindPathButton* btn = dynamic_cast<FindPathButton*>( sender() ); + str path; + + if( !btn ) + return; + + str filter; +#ifdef _WIN32 + filter = "Zandronum Binaries (zandronum.exe)(zandronum.exe);;All files (*.*)(*.*)"; +#else + filter = "Zandronum Binaries (zandronum)(zandronum);;All files (*.*)(*.*)"; +#endif + + if(( path = QFileDialog::getOpenFileName( this, QString(), QString(), filter )).isEmpty() ) + return; + + btn->editWidget()->setText( path ); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void ConfigBox::okPressed() { + QSettings cfg; + list<var> wadPathList; + + for( int i = 0; i < ui->wad_pathsList->count(); ++i ) + wadPathList << ui->wad_pathsList->item( i )->text(); + + cfg.setValue( "wads/paths", wadPathList ); + + int i = 0; + for( str ver : g_zanVersions ) + cfg.setValue( binaryConfigName( ver ), m_zanBinaries[i++]->text() ); + + accept(); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void ConfigBox::cancelPressed() { + reject(); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +str ConfigBox::binaryConfigName( str ver ) const { + return fmt( "binaries/%1", ver ); +} \ No newline at end of file
--- a/src/config.h Wed Jul 17 01:55:18 2013 +0300 +++ b/src/config.h Wed Jul 17 03:06:21 2013 +0300 @@ -5,6 +5,7 @@ #include "main.h" #include "types.h" +class QLineEdit; class Ui_ConfigBox; class ConfigBox : public QDialog { @@ -15,14 +16,19 @@ virtual ~ConfigBox(); void addPath( str path ); void initFromSettings(); + str binaryConfigName( str ver ) const; public slots: void addPath(); void findPath(); void delPath(); + void findZanBinary(); + void okPressed(); + void cancelPressed(); private: Ui_ConfigBox* ui; + list<QLineEdit*> m_zanBinaries; }; #endif // CONFIG_H \ No newline at end of file
--- a/src/main.cpp Wed Jul 17 01:55:18 2013 +0300 +++ b/src/main.cpp Wed Jul 17 03:06:21 2013 +0300 @@ -3,34 +3,35 @@ #include "types.h" #include "config.h" -QSettings* cfg; +const list<str> g_zanVersions ({ + "1.1", +}); // ============================================================================= // ----------------------------------------------------------------------------- int main( int argc, char* argv[] ) { QApplication app( argc, argv ); - app.setApplicationName( APPNAME ); + app.setApplicationName( UNIXNAME ); + app.setOrganizationName( UNIXNAME ); app.setApplicationVersion( versionString() ); - QSettings settings; - cfg = &settings; + print( "Settings path: %1\n", QSettings().fileName() ); for( int i = 1; i < argc; ++i ) { str arg = argv[i]; if( arg == "--config" ) { - ConfigBox* dlg = new ConfigBox; - dlg->show(); + ConfigBox dlg; + return dlg.exec(); } } - print( "Hello world! This is " APPNAME " %1\n", versionString() ); return app.exec(); } // ============================================================================= // ----------------------------------------------------------------------------- -QString versionString() { +str versionString() { str text = fmt( "v%1.%2", VERSION_MAJOR, VERSION_MINOR ); #if VERSION_PATCH != 0 text += fmt( ".%1", VERSION_PATCH );
--- a/src/main.h Wed Jul 17 01:55:18 2013 +0300 +++ b/src/main.h Wed Jul 17 03:06:21 2013 +0300 @@ -19,7 +19,7 @@ static const std::nullptr_t null = nullptr; -extern QSettings* cfg; +extern const QList<QString> g_zanVersions; QString versionString(); #endif // MAIN_H \ No newline at end of file
--- a/src/ui/configbox.ui Wed Jul 17 01:55:18 2013 +0300 +++ b/src/ui/configbox.ui Wed Jul 17 03:06:21 2013 +0300 @@ -32,29 +32,11 @@ <layout class="QVBoxLayout" name="verticalLayout_3"> <item> <layout class="QGridLayout" name="gridLayout"> - <item row="1" column="2"> - <widget class="QPushButton" name="wad_add"> - <property name="text"> - <string>Add</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QLineEdit" name="wad_pathEntry"/> - </item> - <item> - <widget class="QPushButton" name="wad_findPath"> - <property name="text"> - <string>...</string> - </property> - </widget> - </item> - </layout> - </item> <item row="2" column="1"> <widget class="QListWidget" name="wad_pathsList"> + <property name="editTriggers"> + <set>QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set> + </property> <property name="dragEnabled"> <bool>true</bool> </property> @@ -67,6 +49,12 @@ <property name="selectionMode"> <enum>QAbstractItemView::ExtendedSelection</enum> </property> + <property name="layoutMode"> + <enum>QListView::SinglePass</enum> + </property> + <property name="uniformItemSizes"> + <bool>true</bool> + </property> </widget> </item> <item row="2" column="2"> @@ -100,6 +88,27 @@ </item> </layout> </item> + <item row="1" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLineEdit" name="wad_pathEntry"/> + </item> + <item> + <widget class="QPushButton" name="wad_findPath"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="1" column="2"> + <widget class="QPushButton" name="wad_add"> + <property name="text"> + <string>Add</string> + </property> + </widget> + </item> </layout> </item> </layout> @@ -110,7 +119,26 @@ </attribute> <layout class="QVBoxLayout" name="verticalLayout_4"> <item> - <widget class="QWidget" name="zandronumVersions" native="true"/> + <widget class="QScrollArea" name="scrollArea"> + <property name="widgetResizable"> + <bool>true</bool> + </property> + <widget class="QWidget" name="scrollAreaWidgetContents"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>448</width> + <height>232</height> + </rect> + </property> + <layout class="QVBoxLayout" name="verticalLayout_5"> + <item> + <widget class="QWidget" name="zandronumVersions" native="true"/> + </item> + </layout> + </widget> + </widget> </item> </layout> </widget> @@ -131,46 +159,14 @@ <resources/> <connections> <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>ConfigBox</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>254</x> - <y>313</y> - </hint> - <hint type="destinationlabel"> - <x>157</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>ConfigBox</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>322</x> - <y>313</y> - </hint> - <hint type="destinationlabel"> - <x>286</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> <sender>wad_clear</sender> <signal>clicked(bool)</signal> <receiver>wad_pathsList</receiver> <slot>clear()</slot> <hints> <hint type="sourcelabel"> - <x>441</x> - <y>217</y> + <x>463</x> + <y>129</y> </hint> <hint type="destinationlabel"> <x>219</x>