summaryrefslogtreecommitdiffstats
path: root/kmymoney2/dialogs/keditequityentrydlg.cpp
blob: 3eed5e645c3a29ead01fa028bf788264ca3459f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/***************************************************************************
                          keditequityentrydlg.cpp  -  description
                             -------------------
    begin                : Sat Mar 6 2004
    copyright            : (C) 2000-2004 by Michael Edwardes
    email                : mte@users.sourceforge.net
                           Javier Campos Morales <javi_c@users.sourceforge.net>
                           Felix Rodriguez <frodriguez@users.sourceforge.net>
                           John C <thetacoturtle@users.sourceforge.net>
                           Thomas Baumgart <ipwizard@users.sourceforge.net>
                           Kevin Tambascio <ktambascio@users.sourceforge.net>
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

// ----------------------------------------------------------------------------
// QT Includes
#include <tqtimer.h>

// ----------------------------------------------------------------------------
// KDE Includes

#include <klocale.h>
#include <kglobal.h>
#include <kpushbutton.h>
#include <kiconloader.h>
#include <kcombobox.h>

// ----------------------------------------------------------------------------
// Project Includes

#include "keditequityentrydlg.h"
#include "kupdatestockpricedlg.h"
#include "../widgets/kmymoneypriceview.h"

KEditEquityEntryDlg::KEditEquityEntryDlg(const MyMoneySecurity& selectedSecurity, TQWidget *parent, const char *name)
  : KEditEquityEntryDecl(parent, name, true)
{
  m_selectedSecurity = selectedSecurity;

  connect(btnOK, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotOKClicked()));
  connect(btnCancel, TQT_SIGNAL(clicked()), this, TQT_SLOT(reject()));
  connect(edtEquityName, TQT_SIGNAL(textChanged(const TQString &)), this, TQT_SLOT(slotDataChanged()));
  connect(edtMarketSymbol, TQT_SIGNAL(textChanged(const TQString &)), this, TQT_SLOT(slotDataChanged()));
  connect(edtFraction, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotDataChanged()));
  connect(btnAddEntry, TQT_SIGNAL(clicked()), kpvPriceHistory, TQT_SLOT(slotAddPrice()));
  connect(btnEditEntry, TQT_SIGNAL(clicked()), kpvPriceHistory, TQT_SLOT(slotEditPrice()));
  connect(btnRemoveEntry, TQT_SIGNAL(clicked()), kpvPriceHistory, TQT_SLOT(slotDeletePrice()));
  connect(kpvPriceHistory, TQT_SIGNAL(selectionChanged(TQListViewItem*)), this, TQT_SLOT(slotSelectionChanged(TQListViewItem*)));

  //fill in the fields with what we know.
  edtEquityName->setText(m_selectedSecurity.name());
  edtMarketSymbol->setText(m_selectedSecurity.tradingSymbol());
  edtFraction->setPrecision(0);
  edtFraction->setCalculatorButtonVisible(false);
  edtFraction->loadText(TQString::number(m_selectedSecurity.smallestAccountFraction()));
  cmbInvestmentType->setCurrentItem((int)m_selectedSecurity.securityType());
  // FIXME PRICE
  // kpvPriceHistory->setHistory(m_selectedSecurity.priceHistory());

  // add icons to buttons
  KIconLoader *il = KGlobal::iconLoader();
  btnOK->setGuiItem(KStdGuiItem::ok());
  btnCancel->setGuiItem(KStdGuiItem::cancel());
  btnRemoveEntry->setGuiItem(KStdGuiItem::remove());
  btnAddEntry->setGuiItem(KStdGuiItem::add());

  KGuiItem editButtenItem( i18n( "&Edit" ),
                    TQIconSet(il->loadIcon("edit", KIcon::Small, KIcon::SizeSmall)),
                    i18n("Modify the selected entry"),
                    i18n("Change the price information of the selected entry."));
  btnEditEntry->setGuiItem(editButtenItem);

  slotSelectionChanged(0);      // make sure buttons are disabled in the beginning
  slotDataChanged();
  m_changes = false;

  // force a resize to optimize the tqlayout of all widgets
  resize(width()-1, height()-1);
  TQTimer::singleShot(10, this, TQT_SLOT(slotTimerDone()));
}

KEditEquityEntryDlg::~KEditEquityEntryDlg()
{
}

void KEditEquityEntryDlg::slotTimerDone(void)
{
  // the resize operation does the trick to adjust
  // all widgets in the view to the size they should
  // have and show up correctly. Don't ask me, why
  // this is, but it cured the problem (ipwizard).
  resize(width()+1, height()+1);
}

/** No descriptions */
void KEditEquityEntryDlg::slotOKClicked()
{
  if(m_changes /* || kpvPriceHistory->dirty() */)
  {
    m_selectedSecurity.setName(edtEquityName->text());
    m_selectedSecurity.setTradingSymbol(edtMarketSymbol->text());
    m_selectedSecurity.setSmallestAccountFraction(edtFraction->value().abs());
    // FIXME PRICE
    // m_selectedSecurity.setPriceHistory(kpvPriceHistory->history());
  }

  accept();
}

void KEditEquityEntryDlg::slotSelectionChanged(TQListViewItem* item)
{
  btnEditEntry->setEnabled(item != 0);
  btnRemoveEntry->setEnabled(item != 0);
}

void KEditEquityEntryDlg::slotDataChanged(void)
{
  bool okEnabled = true;

  if(!edtFraction->value().isPositive()
  || edtMarketSymbol->text().isEmpty()
  || edtEquityName->text().isEmpty())
    okEnabled = false;

  btnOK->setEnabled(okEnabled);

  m_changes = true;
}

#include "keditequityentrydlg.moc"