#include #include #include #include #include #include #include #include #include #include #include "configurationdialog.h" #include "helper.h" ConfigurationDialog::ConfigurationDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) { //database setup QGridLayout *dbLayout = new QGridLayout; mDbHost = new QLineEdit; dbLayout->addWidget(new QLabel(tr("Hostname")), 0, 0); dbLayout->addWidget(mDbHost, 0, 1); mDbUser = new QLineEdit; dbLayout->addWidget(new QLabel(tr("Username")), 1, 0); dbLayout->addWidget(mDbUser, 1, 1); mDbPass = new QLineEdit; mDbPass->setEchoMode(QLineEdit::Password); dbLayout->addWidget(new QLabel(tr("Password")), 2, 0); dbLayout->addWidget(mDbPass, 2, 1); mDbName = new QLineEdit; dbLayout->addWidget(new QLabel(tr("DB Name")), 3, 0); dbLayout->addWidget(mDbName, 3, 1); dbLayout->setAlignment(Qt::AlignTop); QWidget *dbWidget = new QWidget; dbWidget->setLayout(dbLayout); //buttons QPushButton *acceptB = new QPushButton(tr("Save")); connect(acceptB, &QPushButton::clicked, this, &ConfigurationDialog::accept); QPushButton *cancelB = new QPushButton(tr("Cancel")); connect(cancelB, &QPushButton::clicked, this, &ConfigurationDialog::reject); QHBoxLayout *bLayout = new QHBoxLayout; bLayout->addStretch(); bLayout->addWidget(acceptB); bLayout->addWidget(cancelB); bLayout->addStretch(); //colors QWidget *colorWidget = new QWidget; QGridLayout *colorGrid = new QGridLayout; colorGrid->setColumnStretch(1, 4); colorGrid->addWidget(new QLabel(tr("Base color")), 0, 0); mBaseColorL = new QLabel; mBaseColorL->setFrameStyle(QFrame::Sunken | QFrame::Panel); mBaseColorL->setScaledContents(true); colorGrid->addWidget(mBaseColorL, 0, 1); QPushButton *baseColorB = new QPushButton; baseColorB->setIcon(QIcon(":/fill-color.png")); colorGrid->addWidget(baseColorB, 0, 2); colorGrid->addWidget(new QLabel(tr("Alt. color")), 1, 0); mAltColorL = new QLabel; mAltColorL->setFrameStyle(QFrame::Sunken | QFrame::Panel); mAltColorL->setScaledContents(true); colorGrid->addWidget(mAltColorL, 1, 1); QPushButton *altColorB = new QPushButton; altColorB->setIcon(QIcon(":/fill-color.png")); colorGrid->addWidget(altColorB, 1, 2); QVBoxLayout *colorL = new QVBoxLayout; colorL->addLayout(colorGrid); colorL->addStretch(); colorWidget->setLayout(colorL); mUseAltColors = new QCheckBox(tr("Use alt. row colors")); colorGrid->addWidget(mUseAltColors, 2, 1, 1, 2, Qt::AlignLeft); connect(baseColorB, &QPushButton::clicked, [=] { chooseColor(mBaseColorL); }); connect(altColorB, &QPushButton::clicked, [=] { chooseColor(mAltColorL); }); //scan mode QWidget *scanModeWidget = new QWidget; QGroupBox *scanGB = new QGroupBox(tr("Scan Mode")); mUseBeetRB = new QRadioButton(tr("Use beet ls")); QRadioButton *scanDirRB = new QRadioButton(tr("Scan directory")); scanDirRB->setChecked(true); QHBoxLayout *scanGBL = new QHBoxLayout; scanGBL->addWidget(mUseBeetRB); scanGBL->addWidget(scanDirRB); scanGB->setLayout(scanGBL); QGridLayout *scanDirL = new QGridLayout; mScanDir = new QLineEdit; scanDirL->addWidget(new QLabel(tr("Dir to scan")), 0, 0); scanDirL->addWidget(mScanDir, 1, 0); QVBoxLayout *scanModeL = new QVBoxLayout; scanModeL->addWidget(scanGB); scanModeL->addLayout(scanDirL); scanModeWidget->setLayout(scanModeL); connect(mUseBeetRB, &QRadioButton::toggled, this, &ConfigurationDialog::selectBeet); //dialog layout QVBoxLayout *mainLayout = new QVBoxLayout; QTabWidget *tab = new QTabWidget; tab->addTab(dbWidget, tr("Database")); tab->addTab(colorWidget, tr("Colors")); tab->addTab(scanModeWidget, tr("Scan Mode")); mainLayout->addWidget(tab); mainLayout->addLayout(bLayout); readSettings(); setLayout(mainLayout); setMinimumWidth(400); } void ConfigurationDialog::accept(){ QSettings s; s.setValue("dbhost", mDbHost->text()); s.setValue("dbuser", mDbUser->text()); s.setValue("dbpass", mDbPass->text()); s.setValue("dbname", mDbName->text()); QColor baseColor = Helper::colorFromLabel(mBaseColorL); s.setValue("basecolor", baseColor); QColor altColor = Helper::colorFromLabel(mAltColorL); s.setValue("altcolor", altColor); s.setValue("usealtcolors", mUseAltColors->isChecked()); s.setValue("usebeet", mUseBeetRB->isChecked()); s.setValue("scandir", mScanDir->text()); QDialog::accept(); } void ConfigurationDialog::chooseColor(QWidget *label){ QLabel *curLabel = static_cast(label); QColor startColor = Helper::colorFromLabel(curLabel); if(!startColor.isValid()){ startColor = palette().base().color(); } QColor newColor = QColorDialog::getColor(startColor, this); if(newColor.isValid()){ QPixmap newPm(curLabel->sizeHint()); newPm.fill(newColor); curLabel->setPixmap(newPm); } } void ConfigurationDialog::selectBeet(bool checked){ if(checked){ mScanDir->setEnabled(false); }else{ mScanDir->setEnabled(true); } } void ConfigurationDialog::readSettings(){ QSettings s; mDbHost->setText(s.value("dbhost").toString()); mDbUser->setText(s.value("dbuser").toString()); mDbPass->setText(s.value("dbpass").toString()); mDbName->setText(s.value("dbname").toString()); QVariant baseColorV = s.value("basecolor", palette().base().color()); QColor baseColor = baseColorV.value(); Helper::fillLabel(mBaseColorL, baseColor); QVariant altColorV = s.value("altcolor", palette().alternateBase().color()); QColor altColor = altColorV.value(); Helper::fillLabel(mAltColorL, altColor); bool useAltColors = s.value("usealtcolors", false).toBool(); mUseAltColors->setChecked(useAltColors); bool useBeet = s.value("usebeet", true).toBool(); mUseBeetRB->setChecked(useBeet); QString scanDir = s.value("scandir", tr("")).toString(); mScanDir->setText(scanDir); }