Source Code (Use browser search to find items of interest.)

Class Index

kab'TabAddresses (./kdeutils/kab/look_edit_tabaddresses.h:40)

class TabAddresses : public TabBasic
{
  Q_OBJECT
public:
  TabAddresses(QWidget *parent=0);
  /** Derived from TabBasic. */
  void storeContents(AddressBook::Entry& entry);
  /** Dito. */
  void setContents(const AddressBook::Entry& entry);
protected:
  /** Used to select the address to edit. */
  QComboBox *selector;
  /** The resize event. */
  // void resizeEvent(QResizeEvent *);
  /** The button to create a new address. */
  QPushButton *newAddress;
  /** The button to delete an address. */
  QPushButton *delAddress;
  /** The label for the street. */
  QLabel *l_street;
  /** The label for the zip code. */
  QLabel *l_zip;
  /** The label for the city. */
  QLabel *l_city;
  /** The label for the state. */
  QLabel *l_state;
  /** The label for the country. */
  QLabel *l_country;
  /** The label for the position. */
  QLabel *l_position;
  /** The input field to edit the street. */
  QLineEdit *street;
  /** The input field for the zip code. */
  QLineEdit *zip;
  /** The input field for the city. */
  QLineEdit *city;
  /** The input field for the state. */
  QLineEdit *state;
  /** The input field for the country. */
  QLineEdit *country;
  /** The line edit for the position. The position is meant to be the
      task/responsibility/assignment of the person according to this
      address. This makes sense for, for example, working addresses in
      different enterprises.
  */
  QLineEdit *position;
  /** The button to enter the organisational data. */
  QPushButton *orgdata;
  /** The layout manager. */
  QGridLayout *layout;
  /** The index of the item currently displayed. Set by highlighted (exclusivly). */
  int currentItem;
  /** The list of addresses. */
  std::list<AddressBook::Entry::Address> addresses;
  /** A method to fill the selector with the address headlines. */
  void fillSelector();
  /** A method to fill all fields with the values of this address. */
  void fillFields();
  /** A method to write all changes back to the current address object. */
  void storeChanges();
  /** Remember user input. */
  bool modified;
  /** An iterator to the currently selected Address object. */
  std::list<AddressBook::Entry::Address>::iterator currentAddress();
protected slots:
  /** Create a new address. */
  void addAddress();
  /** Delete an address. */
  void deleteAddress();
  /** An address has been highlighted by the user. */
  void highlighted(int);
  /** The currently selected address has been changed. */
  void addressChanged();
  /** The same, for line edits. */
  void addressChanged(const QString &);
  /** The headline of the currently selected address has been changed. */
  void headlineChanged(const QString &);
};

kab'TabAddresses::TabAddresses() (./kdeutils/kab/look_edit_tabaddresses.cc:40)

TabAddresses::TabAddresses(QWidget *parent)
  : TabBasic(parent),
    currentItem(0),
    modified(false)
{
  int style; // currently unused
  int row=0;
  QHBoxLayout *hboxbuttons;
  QHBoxLayout *hboxposition;
  // -----
  layout=new QGridLayout(this, 100, 3, 3, 2);
  if(layout==0)
    {
      KMessageBox::sorry
	(this, i18n("Out of memory."),
	 i18n("General failure."));
      ::exit(-1);
    }
  // ----- create and add the buttons:
  hboxbuttons=new QHBoxLayout(layout);
  hboxbuttons->setDirection(QBoxLayout::LeftToRight);
  newAddress=new QPushButton(this);
  newAddress->setPixmap(BarIcon("filenew"));
  QToolTip::add(newAddress, i18n("Add another address"));
  hboxbuttons->addWidget(newAddress, row, 1);
  delAddress=new QPushButton(this);
  delAddress->setPixmap(BarIcon("delete"));
  QToolTip::add(delAddress, i18n("Delete this address"));
  hboxbuttons->addWidget(delAddress, row, 2);
  hboxbuttons->addStretch();
  layout->addMultiCell(hboxbuttons, row, row, 0, 2);
  ++row; // new row
  // ----- create and add the selector:
  selector=new QComboBox(/* true, */ this);
  connect(selector, SIGNAL(selected(int)), SLOT(highlighted(int)));
  layout->addMultiCellWidget(selector, row, row, 0, 2);
  ++row; // new row
  // ----- create and place the input fields according to country style selected:
  //       place the position fields:
  hboxposition=new QHBoxLayout(layout);
  l_position=new QLabel(i18n("Assignment:"), this);
  hboxposition->addWidget(l_position, 0, 0); // added to the layout directly
  position=new QLineEdit(this);
  connect(position, SIGNAL(textChanged(const QString&)),
	  SLOT(addressChanged(const QString &)));
  hboxposition->addWidget(position, 0, 1); // added to the hboxlayout
  orgdata=new QPushButton(this);
  orgdata->setPixmap(BarIcon("down"));
  hboxposition->addWidget(orgdata, 0, 2);
  QToolTip::add(orgdata, i18n("Edit organisational attributes"));
  /*
    hboxposition->setStretchFactor(orgdata, 1);
    hboxposition->setStretchFactor(l_position, 1);
    hboxposition->setStretchFactor(position, 10000);
  */
  layout->addMultiCell(hboxposition, row, row, 0, 2);
  ++row; // new row
  // ----- the address fields:
  switch(style)
    {
    default: // american style, city state zipcode
      l_street=new QLabel(i18n("Street:"), this);
      layout->addWidget(l_street, row, 0);
      street=new QLineEdit(this);
      layout->addMultiCellWidget(street, row, row, 1, 2);
      connect(street, SIGNAL(textChanged(const QString&)),
	      SLOT(addressChanged(const QString &)));
      ++row; // new row
      l_city=new QLabel(i18n("City"), this);
      layout->addWidget(l_city, row, 0, AlignBottom);
      l_state=new QLabel(i18n("State"), this);
      layout->addWidget(l_state, row, 1, AlignBottom);
      l_zip=new QLabel(i18n("Zipcode"), this);
      layout->addWidget(l_zip, row, 2, AlignBottom);
      city=new QLineEdit(this);
      ++row; // new row
      layout->addWidget(city, row, 0);
      connect(city, SIGNAL(textChanged(const QString&)),
	      SLOT(addressChanged(const QString &)));
      state=new QLineEdit(this);
      layout->addWidget(state, row, 1);
      connect(state, SIGNAL(textChanged(const QString&)),
	      SLOT(addressChanged(const QString &)));
      zip=new QLineEdit(this);
      layout->addWidget(zip, row, 2);
      connect(zip, SIGNAL(textChanged(const QString&)),
	      SLOT(addressChanged(const QString &)));
      ++row; // new row
      l_country=new QLabel(i18n("Country:"), this);
      layout->addWidget(l_country, row, 0);
      country=new QLineEdit(this);
      layout->addMultiCellWidget(country, row, row, 1, 2);
      connect(country, SIGNAL(textChanged(const QString&)),
	      SLOT(addressChanged(const QString &)));
    }
  connect(newAddress, SIGNAL(clicked()), SLOT(addAddress()));
  connect(delAddress, SIGNAL(clicked()), SLOT(deleteAddress()));
  connect(selector, SIGNAL(textChanged(const QString&)),
	  SLOT(headlineChanged(const QString&)));
}


kab'TabAddresses::storeContents() (./kdeutils/kab/look_edit_tabaddresses.cc:141)

void TabAddresses::storeContents(AddressBook::Entry& entry)
{
  if(modified) storeChanges();
  entry.addresses=addresses;
}


kab'TabAddresses::setContents() (./kdeutils/kab/look_edit_tabaddresses.cc:147)

void TabAddresses::setContents(const AddressBook::Entry& entry)
{
  currentItem=0;
  addresses=entry.addresses;
  fillSelector();
  fillFields();
}


kab'TabAddresses::fillSelector() (./kdeutils/kab/look_edit_tabaddresses.cc:155)

void TabAddresses::fillSelector()
{
  std::list<AddressBook::Entry::Address>::iterator pos;
  // -----
  selector->clear();
  for(pos=addresses.begin(); pos!=addresses.end(); ++pos)
    {
      selector->insertItem((*pos).headline);
    }
}

std::list<AddressBook::Entry::Address>::iterator TabAddresses::currentAddress()
{
  std::list<AddressBook::Entry::Address>::iterator pos;
  int index=currentItem;
  // ----- find the current address:
  if(addresses.size()==0)
    {
      return addresses.end();
    } else {
      index=selector->currentItem();
      pos=addresses.begin();
      advance(pos, index);
      return pos;
    }
}


kab'TabAddresses::fillFields() (./kdeutils/kab/look_edit_tabaddresses.cc:182)

void TabAddresses::fillFields()
{
  std::list<AddressBook::Entry::Address>::iterator pos;
  QLineEdit **lineedits[]= { &street, &zip, &city, &state, &country, &position };
  int Size=sizeof(lineedits)/sizeof(lineedits[0]);
  int count;
  // ----- find the current address:
  pos=currentAddress();
  // ----- fill the fields:
  if(pos==addresses.end())
    {
      for(count=0; count<Size; ++count)
	{
	  (*lineedits[count])->setEnabled(false);
	  (*lineedits[count])->setText("");
	}
    } else {
      QString *strings[]=
      {
	  &(*pos).address, &(*pos).zip, &(*pos).town,
	  &(*pos).state, &(*pos).country, &(*pos).position
      };
      for(count=0; count<Size; ++count)
	{
	  (*lineedits[count])->setEnabled(true);
	  (*lineedits[count])->setText(*strings[count]);
	}
    }
}


kab'TabAddresses::storeChanges() (./kdeutils/kab/look_edit_tabaddresses.cc:212)

void TabAddresses::storeChanges()
{
  std::list<AddressBook::Entry::Address>::iterator pos;
  QLineEdit **lineedits[]= { &street, &zip, &city, &state, &country, &position };
  int Size=sizeof(lineedits)/sizeof(lineedits[0]);
  int count;
  // ----- find the current address:
  pos=currentAddress();
  // ----- store the fields:
  if(pos!=addresses.end())
    {
      QString *strings[]=
      {
	  &(*pos).address, &(*pos).zip, &(*pos).town,
	  &(*pos).state, &(*pos).country, &(*pos).position
      };
      for(count=0; count<Size; ++count)
	{
	  *strings[count]=(*lineedits[count])->text();
	}
    }
}


kab'TabAddresses::addAddress() (./kdeutils/kab/look_edit_tabaddresses.cc:235)

void TabAddresses::addAddress()
{
  if(modified) storeChanges();
  // WORK_TO_DO: provide menu of defined address types
  addresses.push_back(AddressBook::Entry::Address());
  fillSelector();
  selector->setCurrentItem(selector->count()-1);
  currentItem=selector->currentItem();
  fillFields();
  addressChanged();
}


kab'TabAddresses::deleteAddress() (./kdeutils/kab/look_edit_tabaddresses.cc:247)

void TabAddresses::deleteAddress()
{
  int index;
  std::list<AddressBook::Entry::Address>::iterator pos;  
  // -----
  if(addresses.size()==0)
    {
      kapp->beep();
      return;
    }
  if(KMessageBox::questionYesNo
     (this, i18n("Really delete this address?"),
      i18n("Question"))==KMessageBox::Yes)
    {
      index=selector->currentItem();
      if(index<0)
	{
	  kapp->beep();
	  return;
	}
      selector->removeItem(index);
      pos=addresses.begin();
      advance(pos, index);
      addresses.erase(pos);
      fillSelector();
      if(selector->count()>0)
	{
	  selector->setCurrentItem(QMAX(selector->count()-1, index));
	}
      fillFields();
    } else {
      kapp->beep();
    }
}


kab'TabAddresses::highlighted() (./kdeutils/kab/look_edit_tabaddresses.cc:282)

void TabAddresses::highlighted(int index)
{
  debug("TabAddresses::highlighted: %i (was %i).", index,
	currentItem);
  if(modified)
    {
      storeChanges();
      modified=false;
    }
  currentItem=selector->currentItem();
  fillFields();
}


kab'TabAddresses::addressChanged() (./kdeutils/kab/look_edit_tabaddresses.cc:295)

void TabAddresses::addressChanged()
{
  modified=true;
  emit(changed());
  debug("TabAddresses::addressChanged: address changed.");
}


kab'TabAddresses::addressChanged() (./kdeutils/kab/look_edit_tabaddresses.cc:302)

void TabAddresses::addressChanged(const QString &)
{
  addressChanged();
}


kab'TabAddresses::headlineChanged() (./kdeutils/kab/look_edit_tabaddresses.cc:307)

void TabAddresses::headlineChanged(const QString & string)
{
  int index=selector->currentItem();
  std::list<AddressBook::Entry::Address>::iterator pos;
  // -----
  if(index>=0)
    {
      pos=addresses.begin();
      advance(pos, index);
      (*pos).headline=string;
      // selector->changeItem(string, index);
    } else {
      kapp->beep();
    }
}

  

/*
  void TabAddresses::resizeEvent(QResizeEvent* e)
  {
  const int Grid=3;
  int tempx, tempy, x, y, w=width(), h=height();
  // -----
  tempx=newAddress->sizeHint().width();
  tempy=QMAX(newAddress->sizeHint().height(),
  selector->sizeHint().height());
  x=w-Grid-tempx;
  newAddress->setGeometry(x, Grid, tempx, tempy);
  selector->setGeometry(Grid, Grid, x-tempx-Grid, tempy);
  }
*/