Changeset 4837

Show
Ignore:
Timestamp:
01/27/07 17:56:03 (21 months ago)
Author:
flynd
Message:

Created a spinbox for editing timezones and changed the user info dialog to allow timezone of contacts to be changed.
This implements one part of the feature in #1.
Changing the owners timezone is disabled as licq uses system setting instead.

Location:
trunk/qt-gui/src
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/qt-gui/src/ewidgets.cpp

    r4792 r4837  
    5151#include "licq_history.h" 
    5252#include "licq_events.h" 
     53#include "licq_user.h" 
    5354#include "mainwin.h" 
    5455#include "eventdesc.h" 
     
    651652} 
    652653 
     654// ----------------------------------------------------------------------------- 
     655 
     656CTimeZoneField::CTimeZoneField(QWidget *parent) 
     657    : QSpinBox(-24, 24, 1, parent) 
     658{ 
     659  // The world is round so let timezones wrap 
     660  setWrapping(true); 
     661 
     662  // Plus and minus seems more fitting than up and down 
     663  setButtonSymbols(QSpinBox::PlusMinus); 
     664 
     665  // Force the input to be in format GMT+500, GMT-1030, etc... 
     666  setPrefix("GMT"); 
     667  setValidator(new QRegExpValidator(QRegExp("^[\\+\\-](1[012]|\\d)[03]0$|^Unknown$"), this)); 
     668 
     669  // Allow the value to be undefined as well. This will replace the lowest value (-24) 
     670  setSpecialValueText(tr("Unknown")); 
     671} 
     672 
     673void CTimeZoneField::setData(char data) 
     674{ 
     675  // The spinbox uses the lowest value to mark the undefined state but the constant is some other value so we need to change it 
     676  // For all defined values, the sign is inverted 
     677  setValue(data == TIMEZONE_UNKNOWN ? undefinedValue : static_cast<int>(-data)); 
     678} 
     679 
     680char CTimeZoneField::data() 
     681{ 
     682  int v = value(); 
     683  if (v == undefinedValue) 
     684    return TIMEZONE_UNKNOWN; 
     685  return static_cast<char>(-v); 
     686} 
     687 
     688QString CTimeZoneField::mapValueToText(int v) 
     689{ 
     690  // The internal value in the spinbox is 30min intervals so convert it to something more readable 
     691  return QString("%1%2%3").arg(v < 0 ? "-" : "+").arg(abs(v) / 2).arg(v % 2 ? "30" : "00"); 
     692} 
     693 
     694int CTimeZoneField::mapTextToValue(bool *ok) 
     695{ 
     696  // The user entered something so now we must try and convert it back to the internal int 
     697  QRegExp rx("^(\\+|-)(\\d+)(0|3)0$"); 
     698  if (rx.search(cleanText()) == -1) 
     699  { 
     700    *ok = false; 
     701    return 0; 
     702  } 
     703  int ret = rx.cap(2).toInt() * 2; 
     704  if (rx.cap(3) == "3") 
     705    ret++; 
     706  if (rx.cap(1) == "-") 
     707    ret = -ret; 
     708  *ok = true; 
     709  return ret; 
     710} 
    653711 
    654712// ----------------------------------------------------------------------------- 
     
    658716{ 
    659717  setTextFormat(RichText); 
    660 }; 
     718} 
    661719 
    662720// ----------------------------------------------------------------------------- 
  • trunk/qt-gui/src/ewidgets.h

    r4792 r4837  
    3434#include <qlistview.h> 
    3535#include <qstringlist.h> 
     36#include <qspinbox.h> 
    3637 
    3738#include "mlview.h" 
     
    180181}; 
    181182 
     183/* ----------------------------------------------------------------------------- */ 
     184 
     185/** 
     186 * Input field for timezones. 
     187 */ 
     188class CTimeZoneField : public QSpinBox 
     189{ 
     190public: 
     191  CTimeZoneField(QWidget *parent); 
     192  void setData(char data); 
     193  char data(); 
     194protected: 
     195  QString mapValueToText(int v); 
     196  int mapTextToValue(bool* ok); 
     197 
     198  static const int undefinedValue = -24; 
     199}; 
    182200 
    183201/* ----------------------------------------------------------------------------- */ 
  • trunk/qt-gui/src/userinfodlg.cpp

    r4791 r4837  
    308308  lay->addWidget(nfoStatus, CR, 1); 
    309309  lay->addWidget(new QLabel(tr("Timezone:"), p), CR, 3); 
    310   nfoTime = new CInfoField(p, true); 
    311   lay->addWidget(nfoTime, CR, 4); 
     310  tznZone = new CTimeZoneField(p); 
     311  lay->addWidget(tznZone, CR, 4); 
    312312 
    313313  lay->addWidget(new QLabel(tr("Name:"), p), ++CR, 0); 
     
    414414  } 
    415415  nfoIp->setData(ip); 
    416   if (u->GetTimezone() == TIMEZONE_UNKNOWN) 
    417     nfoTime->setText(tr("Unknown")); 
    418   else 
    419   { 
    420     nfoTime->setText(tr("GMT%1%1%1") 
    421        .arg(u->GetTimezone() > 0 ? "-" : "+") 
    422        .arg(abs(u->GetTimezone() / 2)).arg(u->GetTimezone() % 2 ? "30" : "00") ); 
    423   } 
     416  tznZone->setData(u->GetTimezone()); 
    424417  nfoStatus->setData(u->StatusStr()); 
    425418  if (m_bOwner) 
    426419  { 
     420    // Owner timezone is not editable, it is taken from system timezone instead 
     421    tznZone->setEnabled(false); 
     422 
    427423    const SCountry *c = GetCountryByCode(u->GetCountryCode()); 
    428424    if (c == NULL) 
     
    491487    u->SetCountryCode(GetCountryByIndex(i)->nCode); 
    492488  } 
     489  u->SetTimezone(tznZone->data()); 
    493490 
    494491  u->SetEnableSave(true); 
  • trunk/qt-gui/src/userinfodlg.h

    r4699 r4837  
    104104             *nfoAlias, *nfoIp, *nfoUin, *nfoCity, *nfoState, 
    105105             *nfoZipCode, *nfoAddress, *nfoCountry, *nfoFax, *nfoCellular, 
    106              *nfoPhone, *nfoTime, *nfoStatus; 
     106             *nfoPhone, *nfoStatus; 
    107107  QCheckBox *chkKeepAliasOnUpdate; 
    108108  CEComboBox *cmbCountry; 
    109109  QLabel *lblAuth, *lblICQHomepage; 
     110  CTimeZoneField *tznZone; 
    110111 
    111112  // More info