FreeDebks  1.0.3
 All Classes Files Functions Variables Friends Pages
FdDialogBkgProperties.cpp
Go to the documentation of this file.
1 // --------------------------------------------------------------------
2 // Copyright © 2011-2013 Mathieu Schopfer
3 //
4 // This file is part of FreeDebks.
5 //
6 // FreeDebks is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // FreeDebks is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with FreeDebks. If not, see <http://www.gnu.org/licenses/>.
18 // --------------------------------------------------------------------
19 
20 #include "FdDialogBkgProperties.hpp"
21 
22 #include "FdSubWindow.hpp"
23 #include "../data/FdModelJournal.hpp"
24 
29  QDialog(parent), mSubwindow(NULL), mMainWindow(main)
30 {
31  setupUi(this);
32  init();
33 
34  // Set initialDate to be 1st of Jan and finalDate 31st of Dec, of the current year.
35  int currentYear = QDate::currentDate().year();
36  inInitialDate->setDate(QDate(currentYear,1,1));
37  inFinalDate->setDate(QDate(currentYear,12,31));
38 }
39 
43 FdDialogBkgProperties::FdDialogBkgProperties(QWidget* parent, FdSubWindow* subwindow) : QDialog(parent), mSubwindow(subwindow)
44 {
45  setupUi(this);
46  init();
47  getInputFields();
48 }
49 
51 {
52  buttonBrowse->setIcon(QIcon::fromTheme("document-open"));
53 }
54 
64 {
65  QDate initialDate = inInitialDate->date();
66  QDate finalDate = inFinalDate->date();
67 
68  if(initialDate > finalDate)
69  return false;
70 
71  return true;
72 }
73 
78 {
79  inLabel->setText(mSubwindow->label());
80  inCurrency->setText(mSubwindow->currency());
81  inInitialDate->setDate(mSubwindow->initialDate());
82  inFinalDate->setDate(mSubwindow->finalDate());
83  inCorporation->setText(mSubwindow->corporation());
84  inLogo->setText(mSubwindow->logo());
85  inAccountant->setText(mSubwindow->accountant());
86 
87  if(mSubwindow)
88  {
89  FdModelJournal* journal = mSubwindow->journal();
90  if(journal->rowCount())
91  {
92  inInitialDate->setMaximumDate(journal->getMinDate());
93  inFinalDate->setMinimumDate(journal->getMaxDate());
94  }
95  }
96 }
97 
102 {
103  // Creates a new subwindow is none is set.
104 // try(mSubwindow->setLabel())
105  if(!mSubwindow)
106  mSubwindow = new FdSubWindow(inLabel->text(), QString());
107  else
108  mSubwindow->setLabel(inLabel->text());
109 
110  mSubwindow->setCurrency(inCurrency->text());
111  mSubwindow->setInitialDate(inInitialDate->date());
112  mSubwindow->setFinalDate(inFinalDate->date());
113  mSubwindow->setCorporation(inCorporation->text());
114  mSubwindow->setLogo(inLogo->text());
115  mSubwindow->setAccountant(inAccountant->text());
116  mSubwindow->setWindowModified(true);
117 }
118 
123 {
125  if(inLabel->text().operator ==(""))
126  {
127  inLabel->setStyleSheet("background: red");
128  }
130  else if(!checkDates())
131  {
132  inInitialDate->setStyleSheet("background: red");
133  inFinalDate->setStyleSheet("background: red");
134  }
136  else
137  {
138  setInputFields();
139  emit accepted(mSubwindow);
140  accept();
141  }
142 }
143 
147 void FdDialogBkgProperties::on_buttonBox_clicked(QAbstractButton* button)
148 {
149  QDialogButtonBox::ButtonRole role(buttonBox->buttonRole(button));
150  if(role == QDialogButtonBox::ResetRole)
151  getInputFields();
152 }
153 
155 {
156  QString file = QFileDialog::getOpenFileName(this, QObject::tr("Select a file", "Select a file to be the bookkeeping logo."), QDir::homePath(),
157  QObject::tr("Images (*.png *.jpg)", "File format, so leave (*.png *.jpg) unchanged."));
158  if(!file.isNull())
159  inLogo->setText(file);
160 }