Show
Ignore:
Timestamp:
01/27/07 17:56:03 (23 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.

Files:
1 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// -----------------------------------------------------------------------------