00001 #include "settingsdialog.h"
00002
00003 SettingsDialog::SettingsDialog(Settings &set, QWidget *parent) : QDialog(parent)
00004 {
00005 setupUi(this);
00006 setAttribute(Qt::WA_DeleteOnClose, true);
00007 createActions();
00008
00009 settings = &set;
00010
00011 restoreSettings();
00012 }
00013
00014 void SettingsDialog::createActions()
00015 {
00016 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ok()));
00017 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(cancel()));
00018
00019 connect(buttonChooseWorkspace, SIGNAL(clicked()), this, SLOT(chooseWorkSpace()));
00020
00021
00022 connect(buttonProductionCosts, SIGNAL(clicked()), this, SLOT(setColorProductionCostCU()));
00023 connect(buttonProfit, SIGNAL(clicked()), this, SLOT(setColorProfitCU()));
00024 connect(buttonCommission, SIGNAL(clicked()), this, SLOT(setColorCommissionCU()));
00025 connect(buttonTradeDiscount, SIGNAL(clicked()), this, SLOT(setColorTradeDiscountCU()));
00026 connect(buttonDiscount, SIGNAL(clicked()), this, SLOT(setColorDiscountCU()));
00027 connect(buttonSalesTax, SIGNAL(clicked()), this, SLOT(setColorSalesTaxCU()));
00028
00029 }
00030
00031 void SettingsDialog::ok()
00032 {
00033 if(saveSettings())
00034 {
00035 done(0);
00036 }
00037 else
00038 {
00039 QMessageBox::warning(this, tr("Fehler"), tr("Es trat ein Fehler auf! Möglicherweise ist eine Ihrer Eingaben falsch!"));
00040 }
00041 }
00042
00043 void SettingsDialog::cancel()
00044 {
00045 done(1);
00046 }
00047
00048 bool SettingsDialog::restoreSettings()
00049 {
00050 qDebug()<<"Loading settings";
00051 textWorkspace->setText(settings->workspace().absolutePath());
00052
00053 checkBoxUpdatesEnabled->setChecked(settings->automaticCheckForUpdates());
00054
00055 productionCostCUcolor = settings->productionCostsCUColor();
00056 profitCUcolor = settings->profitCUColor();
00057 commissionCUcolor = settings->commissionCUColor();
00058 tradeDiscountCUcolor = settings->tradeDiscountCUColor();
00059 discountCUcolor = settings->discountCUColor();
00060 salesTaxCUcolor = settings->salesTaxCUColor();
00061
00062 buttonProductionCosts->setStyleSheet(colorStylesheet(productionCostCUcolor));
00063 buttonProfit->setStyleSheet(colorStylesheet(profitCUcolor));
00064 buttonCommission->setStyleSheet(colorStylesheet(commissionCUcolor));
00065 buttonTradeDiscount->setStyleSheet(colorStylesheet(tradeDiscountCUcolor));
00066 buttonDiscount->setStyleSheet(colorStylesheet(discountCUcolor));
00067 buttonSalesTax->setStyleSheet(colorStylesheet(salesTaxCUcolor));
00068
00069 return true;
00070 }
00071
00072 bool SettingsDialog::saveSettings()
00073 {
00074 qDebug()<<"Saving settings";
00075 QDir workspace(textWorkspace->text());
00076 if(workspace.exists())
00077 {
00078 settings->setWorkspace(workspace);
00079 }
00080 else
00081 {
00082 return false;
00083 }
00084
00085 settings->setAutomaticCheckForUpdates(checkBoxUpdatesEnabled->isChecked());
00086
00087 settings->setProductionCostsCUColor(productionCostCUcolor);
00088 settings->setProfitCUColor(profitCUcolor);
00089 settings->setCommissionCUColor(commissionCUcolor);
00090 settings->setTradeDiscountCUColor(tradeDiscountCUcolor);
00091 settings->setDiscountCUColor(discountCUcolor);
00092 settings->setSalesTaxCUColor(salesTaxCUcolor);
00093
00094 return true;
00095 }
00096
00097 void SettingsDialog::chooseWorkSpace()
00098 {
00099 textWorkspace->setText(settings->chooseWorkspacePath());
00100 }
00101
00102 QRgb SettingsDialog::getColorRGB(int color)
00103 {
00104 QRgb initial;
00105 switch(color)
00106 {
00107 case 1:
00108 initial = productionCostCUcolor;
00109 break;
00110 case 2:
00111 initial = profitCUcolor;
00112 break;
00113 case 3:
00114 initial = commissionCUcolor;
00115 break;
00116 case 4:
00117 initial = tradeDiscountCUcolor;
00118 break;
00119 case 5:
00120 initial = discountCUcolor;
00121 break;
00122 case 6:
00123 initial = salesTaxCUcolor;
00124 break;
00125 default:
00126 initial = QRgb();
00127 }
00128
00129 bool ok;
00130 QRgb c = QColorDialog::getRgba(initial, &ok, this);
00131 if(&ok != NULL)
00132 {
00133 return c;
00134 }
00135 return initial;
00136 }
00137
00138 void SettingsDialog::setColorProductionCostCU()
00139 {
00140 QRgb color = getColorRGB(1);
00141 productionCostCUcolor = color;
00142 buttonProductionCosts->setStyleSheet(colorStylesheet(productionCostCUcolor));
00143 }
00144
00145 void SettingsDialog::setColorProfitCU()
00146 {
00147 QRgb color = getColorRGB(2);
00148 profitCUcolor = color;
00149 buttonProfit->setStyleSheet(colorStylesheet(profitCUcolor));
00150 }
00151
00152 void SettingsDialog::setColorCommissionCU()
00153 {
00154 QRgb color = getColorRGB(3);
00155 commissionCUcolor = color;
00156 buttonCommission->setStyleSheet(colorStylesheet(commissionCUcolor));
00157 }
00158
00159 void SettingsDialog::setColorTradeDiscountCU()
00160 {
00161 QRgb color = getColorRGB(4);
00162 tradeDiscountCUcolor = color;
00163 buttonTradeDiscount->setStyleSheet(colorStylesheet(tradeDiscountCUcolor));
00164 }
00165
00166 void SettingsDialog::setColorDiscountCU()
00167 {
00168 QRgb color = getColorRGB(5);
00169 discountCUcolor = color;
00170 buttonDiscount->setStyleSheet(colorStylesheet(discountCUcolor));
00171 }
00172
00173 void SettingsDialog::setColorSalesTaxCU()
00174 {
00175 QRgb color = getColorRGB(6);
00176 salesTaxCUcolor = color;
00177 buttonSalesTax->setStyleSheet(colorStylesheet(salesTaxCUcolor));
00178 }
00179
00180 QString SettingsDialog::colorStylesheet(QRgb color)
00181 {
00182 QString stylesheet = "border: 4px solid rgb(";
00183 stylesheet += QString::number(qRed(color));
00184 stylesheet += ",";
00185 stylesheet += QString::number(qGreen(color));
00186 stylesheet += ",";
00187 stylesheet += QString::number(qBlue(color));
00188 stylesheet += ");";
00189 stylesheet += "border-radius: 6px;background-color: rgb(";
00190 stylesheet += QString::number(qRed(color));
00191 stylesheet += ",";
00192 stylesheet += QString::number(qGreen(color));
00193 stylesheet += ",";
00194 stylesheet += QString::number(qBlue(color));
00195 stylesheet += ");";
00196
00197 return stylesheet;
00198 }
00199
00200 void SettingsDialog::setActivePage(int page)
00201 {
00202 settingsList->setCurrentRow(page);
00203 }