Wed, 17 Jul 2013 01:53:57 +0300
Implemented wad path list
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/types.h | file | annotate | diff | comparison | revisions | |
src/ui/configbox.ui | file | annotate | diff | comparison | revisions |
--- a/src/config.cpp Wed Jul 17 00:31:04 2013 +0300 +++ b/src/config.cpp Wed Jul 17 01:53:57 2013 +0300 @@ -1,11 +1,47 @@ +#include <QFileDialog> #include "config.h" #include "ui_configbox.h" ConfigBox::ConfigBox( QWidget* parent, Qt::WindowFlags f ) : QDialog( parent, f ) { ui = new Ui_ConfigBox; ui->setupUi( this ); + setWindowTitle( fmt( APPNAME " %1", versionString())); + + 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() )); } ConfigBox::~ConfigBox() { delete ui; -} \ No newline at end of file +} + +void ConfigBox::initFromSettings() { + ui->wad_pathsList->clear(); + + list<var> paths = cfg->value( "wads/paths", list<var>() ).toList(); + for( const var& it : paths ) + addPath( it.toString() ); +} + +void ConfigBox::addPath() { + addPath( ui->wad_pathEntry->text() ); + ui->wad_pathEntry->clear(); +} + +void ConfigBox::addPath( str path ) { + ui->wad_pathsList->addItem( path ); +} + +void ConfigBox::findPath() { + str path = QFileDialog::getExistingDirectory( this ); + if( path.isEmpty() ) + return; + + ui->wad_pathEntry->setText( path ); +} + +void ConfigBox::delPath() { + delete ui->wad_pathsList->currentItem(); +}
--- a/src/config.h Wed Jul 17 00:31:04 2013 +0300 +++ b/src/config.h Wed Jul 17 01:53:57 2013 +0300 @@ -2,13 +2,24 @@ #define CONFIG_H #include <QDialog> +#include "main.h" +#include "types.h" class Ui_ConfigBox; class ConfigBox : public QDialog { + Q_OBJECT + public: - explicit ConfigBox( QWidget* parent = 0, Qt::WindowFlags f = 0 ); + explicit ConfigBox( QWidget* parent = null, Qt::WindowFlags f = 0 ); virtual ~ConfigBox(); + void addPath( str path ); + void initFromSettings(); + +public slots: + void addPath(); + void findPath(); + void delPath(); private: Ui_ConfigBox* ui;
--- a/src/main.cpp Wed Jul 17 00:31:04 2013 +0300 +++ b/src/main.cpp Wed Jul 17 01:53:57 2013 +0300 @@ -1,11 +1,19 @@ #include <QApplication> +#include <QSettings> #include "types.h" #include "config.h" +QSettings* cfg; + // ============================================================================= // ----------------------------------------------------------------------------- int main( int argc, char* argv[] ) { QApplication app( argc, argv ); + app.setApplicationName( APPNAME ); + app.setApplicationVersion( versionString() ); + + QSettings settings; + cfg = &settings; for( int i = 1; i < argc; ++i ) { str arg = argv[i];
--- a/src/main.h Wed Jul 17 00:31:04 2013 +0300 +++ b/src/main.h Wed Jul 17 01:53:57 2013 +0300 @@ -15,7 +15,11 @@ #define BUILD_RC 3 #define BUILD_RELEASE 4 -class QString; +#include <QSettings> + +static const std::nullptr_t null = nullptr; + +extern QSettings* cfg; QString versionString(); #endif // MAIN_H \ No newline at end of file
--- a/src/types.h Wed Jul 17 00:31:04 2013 +0300 +++ b/src/types.h Wed Jul 17 01:53:57 2013 +0300 @@ -4,9 +4,11 @@ #include "main.h" #include <QString> #include <QList> +#include <QVariant> typedef QString str; typedef QChar qchar; +typedef QVariant var; template<class T> using list = QList<T>; typedef unsigned int uint; typedef unsigned short ushort;
--- a/src/ui/configbox.ui Wed Jul 17 00:31:04 2013 +0300 +++ b/src/ui/configbox.ui Wed Jul 17 01:53:57 2013 +0300 @@ -33,7 +33,7 @@ <item> <layout class="QGridLayout" name="gridLayout"> <item row="1" column="2"> - <widget class="QPushButton" name="pushButton_6"> + <widget class="QPushButton" name="wad_add"> <property name="text"> <string>Add</string> </property> @@ -42,10 +42,10 @@ <item row="1" column="1"> <layout class="QHBoxLayout" name="horizontalLayout"> <item> - <widget class="QLineEdit" name="lineEdit"/> + <widget class="QLineEdit" name="wad_pathEntry"/> </item> <item> - <widget class="QPushButton" name="pushButton"> + <widget class="QPushButton" name="wad_findPath"> <property name="text"> <string>...</string> </property> @@ -54,46 +54,32 @@ </layout> </item> <item row="2" column="1"> - <widget class="QListWidget" name="listWidget"/> + <widget class="QListWidget" name="wad_pathsList"> + <property name="dragEnabled"> + <bool>true</bool> + </property> + <property name="dragDropMode"> + <enum>QAbstractItemView::DragDrop</enum> + </property> + <property name="defaultDropAction"> + <enum>Qt::MoveAction</enum> + </property> + <property name="selectionMode"> + <enum>QAbstractItemView::ExtendedSelection</enum> + </property> + </widget> </item> <item row="2" column="2"> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> - <widget class="QPushButton" name="pushButton_5"> - <property name="text"> - <string>Move Up</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pushButton_4"> - <property name="text"> - <string>Move Down</string> - </property> - </widget> - </item> - <item> - <spacer name="verticalSpacer_2"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QPushButton" name="pushButton_2"> + <widget class="QPushButton" name="wad_del"> <property name="text"> <string>Delete</string> </property> </widget> </item> <item> - <widget class="QPushButton" name="pushButton_3"> + <widget class="QPushButton" name="wad_clear"> <property name="text"> <string>Clear</string> </property> @@ -151,8 +137,8 @@ <slot>accept()</slot> <hints> <hint type="sourcelabel"> - <x>248</x> - <y>254</y> + <x>254</x> + <y>313</y> </hint> <hint type="destinationlabel"> <x>157</x> @@ -167,8 +153,8 @@ <slot>reject()</slot> <hints> <hint type="sourcelabel"> - <x>316</x> - <y>260</y> + <x>322</x> + <y>313</y> </hint> <hint type="destinationlabel"> <x>286</x> @@ -176,5 +162,21 @@ </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> + </hint> + <hint type="destinationlabel"> + <x>219</x> + <y>189</y> + </hint> + </hints> + </connection> </connections> </ui>