Changeset 6043

Show
Ignore:
Timestamp:
01/14/08 09:41:27 (10 months ago)
Author:
eugene
Message:
  • Revised the mainwin geometry save/restore logic;
  • Revised the skin handling mechanism;
  • General code cleanup.
Location:
branches/qt-gui_qt4/src/core
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • branches/qt-gui_qt4/src/core/licqgui.cpp

    r6001 r6043  
    240240 
    241241  // QLocale::system() uses LC_ALL, LC_NUMERIC and LANG (in that 
    242   // order) when detmening system locale. We want LC_MESSAGES instead 
     242  // order) when determines system locale. We want LC_MESSAGES instead 
    243243  // of LC_NUMERIC so we have to do it ourselves. 
    244244#ifdef Q_OS_UNIX 
     
    365365  Config::Skin::active()->setFrameStyle(skinFrameStyle); 
    366366  Config::Skin::active()->setFrameTransparent(skinFrameTransparent); 
    367  
    368   // Get saved position and size for mainwin 
    369   licqConf.SetSection("geometry"); 
    370   unsigned short xPos, yPos, hVal, wVal; 
    371   licqConf.ReadNum("x", xPos, 100); 
    372   licqConf.ReadNum("y", yPos, 100); 
    373   licqConf.ReadNum("h", hVal, 400); 
    374   licqConf.ReadNum("w", wVal, 150); 
    375   gLog.Info("%sGeometry configuration (%d, %d) (%d x %d)\n", L_INITxSTR, 
    376             xPos, yPos, wVal, hVal); 
    377   if (yPos > QApplication::desktop()->height() - 16) 
    378     yPos = 0; 
    379   if (xPos > QApplication::desktop()->width() - 16) 
    380     xPos = 0; 
    381   myMainwinRect.setRect(xPos, yPos, wVal, hVal); 
    382367} 
    383368 
     
    415400void LicqGui::saveConfig() 
    416401{ 
    417   // Tell the daemon to save it's options 
     402  // Tell the daemon to save its options 
    418403  myLicqDaemon->SaveConf(); 
    419404 
     
    525510#endif /* defined(USE_SCRNSAVER) */ 
    526511 
    527   myMainWindow = new MainWindow(myStartHidden, myMainwinRect); 
     512  myMainWindow = new MainWindow(myStartHidden); 
    528513 
    529514  loadFloatiesConfig(); 
  • branches/qt-gui_qt4/src/core/licqgui.h

    r5945 r6043  
    3030 
    3131#include <QList> 
    32 #include <QRect> 
    3332#include <QStringList> 
    3433#include <QTimer> 
     
    262261  QString myIcons; 
    263262  QString myExtendedIcons; 
    264   QRect myMainwinRect; 
    265263 
    266264  bool myStartHidden; 
  • branches/qt-gui_qt4/src/core/mainwin.cpp

    r6032 r6043  
    114114MainWindow* LicqQtGui::gMainWindow = NULL; 
    115115 
    116 MainWindow::MainWindow(bool bStartHidden, QRect startRect, QWidget* parent) 
     116MainWindow::MainWindow(bool bStartHidden, QWidget* parent) 
    117117  : QWidget(parent), 
    118     myInMiniMode(false), 
    119     myPositionChanges(0) 
     118    myInMiniMode(false) 
    120119{ 
    121120  Support::setWidgetProps(this, "MainWindow"); 
     
    123122  gMainWindow = this; 
    124123 
    125   connect(qApp, SIGNAL(aboutToQuit()), SLOT(slot_aboutToQuit())); 
    126  
    127   connect(Config::General::instance(), 
    128       SIGNAL(mainwinChanged()), SLOT(updateConfig())); 
     124  Config::General* conf = Config::General::instance(); 
     125 
     126  connect(conf, SIGNAL(mainwinChanged()), SLOT(updateConfig())); 
    129127  connect(Config::ContactList::instance(), 
    130128      SIGNAL(currentListChanged()), SLOT(updateCurrentGroup())); 
    131  
    132   myRealHeight = startRect.height(); 
    133129 
    134130  myCaption = "Licq"; 
     
    180176  shortcut = new QShortcut(Qt::Key_Delete, this); 
    181177  connect(shortcut, SIGNAL(activated()), SLOT(removeUserFromGroup())); 
    182  
    183   updateSkin(true); 
    184   connect(Config::Skin::active(), SIGNAL(changed()), SLOT(updateSkin())); 
    185178 
    186179  CreateUserView(); 
     
    225218      SLOT(slot_protocolPlugin(unsigned long))); 
    226219 
     220  if (conf->mainwinRect().isValid()) 
     221    setGeometry(conf->mainwinRect()); 
     222  else 
     223  { 
     224    myUserView->resize(myUserView->sizeHint()); 
     225    adjustSize(); 
     226  } 
     227  updateSkin(); 
     228  connect(Config::Skin::active(), SIGNAL(changed()), SLOT(updateSkin())); 
     229 
    227230  updateStatus(); 
    228231  updateEvents(); 
    229232  updateGroups(true); 
    230233 
    231   setGeometry(startRect); 
    232   setMiniMode(Config::General::instance()->miniMode()); 
    233   if (!Config::General::instance()->mainwinStartHidden() && !bStartHidden) 
    234     show(); 
     234  setMiniMode(conf->miniMode()); 
     235  setVisible(!conf->mainwinStartHidden() && !bStartHidden); 
    235236 
    236237  // verify we exist 
     
    329330} 
    330331 
    331 void MainWindow::updateSkin(bool initial) 
     332void MainWindow::updateSkin() 
    332333{ 
    333334  Config::Skin* skin = Config::Skin::active(); 
     335 
     336#define CLEAR(elem) \ 
     337  if ((elem) != NULL) \ 
     338  { \ 
     339    delete (elem); \ 
     340    (elem) = NULL; \ 
     341  } 
    334342 
    335343  // Set the background pixmap and mask 
     
    340348    clearMask(); 
    341349 
    342   // Group Combo Box 
    343   myUserGroupsBox->applySkin(skin->cmbGroups); 
    344  
    345350  // System Button 
    346   if (mySystemButton != NULL) 
    347     delete mySystemButton; 
    348   if (myMenuBar != NULL) 
    349     delete myMenuBar; 
    350  
    351   if (!skin->frame.hasMenuBar) 
    352   { 
    353     mySystemButton = new SkinnableButton(skin->btnSys, tr("System"), this); 
    354     mySystemButton->setMenu(mySystemMenu); 
    355       myMenuBar = NULL; 
    356   } 
    357   else 
     351  CLEAR(mySystemButton); 
     352  CLEAR(myMenuBar); 
     353 
     354  if (skin->frame.hasMenuBar || 
     355      skin->btnSys.rect.isNull()) 
    358356  { 
    359357#ifdef USE_KDE 
     
    367365    myMenuBar->setMinimumWidth(mySystemMenu->width()); 
    368366    myMenuBar->show(); 
    369     mySystemButton = NULL; 
    370367    skin->AdjustForMenuBar(myMenuBar->height()); 
     368  } 
     369  else 
     370  { 
     371    mySystemButton = new SkinnableButton(skin->btnSys, tr("System"), this); 
     372    mySystemButton->setMenu(mySystemMenu); 
     373    mySystemButton->show(); 
    371374  } 
    372375 
    373376  unsigned minHeight = skin->frame.border.top + skin->frame.border.bottom; 
    374377  setMinimumHeight(minHeight); 
    375   setMaximumHeight(Config::General::instance()->miniMode() ? minHeight : QWIDGETSIZE_MAX); 
     378  setMaximumHeight(Config::General::instance()->miniMode() ? 
     379      minHeight : QWIDGETSIZE_MAX); 
     380 
     381  // Group Combo Box 
     382  myUserGroupsBox->applySkin(skin->cmbGroups); 
     383  myUserGroupsBox->setVisible(!skin->cmbGroups.rect.isNull()); 
    376384 
    377385  // Message Label 
    378   delete myMessageField; 
    379   myMessageField = new SkinnableLabel(skin->lblMsg, mySystemMenu->getGroupMenu(), this); 
    380   connect(myMessageField, SIGNAL(doubleClicked()), LicqGui::instance(), SLOT(showNextEvent())); 
    381   myMessageField->setToolTip(tr("Right click - User groups\n" 
    382                            "Double click - Show next message")); 
     386  CLEAR(myMessageField); 
     387  if (!skin->lblMsg.rect.isNull()) 
     388  { 
     389    myMessageField = new SkinnableLabel(skin->lblMsg, 
     390        mySystemMenu->getGroupMenu(), this); 
     391    connect(myMessageField, SIGNAL(doubleClicked()), 
     392        LicqGui::instance(), SLOT(showNextEvent())); 
     393    myMessageField->setToolTip(tr("Right click - User groups\n" 
     394          "Double click - Show next message")); 
     395    myMessageField->show(); 
     396  } 
    383397 
    384398  // Status Label 
    385   delete myStatusField; 
    386   myStatusField = new SkinnableLabel(skin->lblStatus, mySystemMenu->getStatusMenu(), this); 
    387   connect(myStatusField, SIGNAL(doubleClicked()), SLOT(showAwayMsgDlg())); 
    388   myStatusField->setToolTip(tr("Right click - Status menu\n" 
    389                               "Double click - Set auto response")); 
    390  
    391   if (!initial) 
    392   { 
    393     resizeEvent(NULL); 
    394  
    395     if (mySystemButton != NULL) 
    396     { 
    397       if (skin->btnSys.rect.isNull()) 
    398         mySystemButton->hide(); 
    399       else 
    400         mySystemButton->show(); 
    401     } 
    402     if (myStatusField != NULL) 
    403     { 
    404       if (skin->lblStatus.rect.isNull()) 
    405         myStatusField->hide(); 
    406       else 
    407         myStatusField->show(); 
    408     } 
    409     if (myMessageField != NULL) 
    410     { 
    411       if (skin->lblMsg.rect.isNull()) 
    412         myMessageField->hide(); 
    413       else 
    414         myMessageField->show(); 
    415     } 
    416     if (myUserGroupsBox != NULL) 
    417     { 
    418       if (skin->cmbGroups.rect.isNull()) 
    419         myUserGroupsBox->hide(); 
    420       else 
    421         myUserGroupsBox->show(); 
    422     } 
    423     if (myMenuBar != NULL) 
    424       myMenuBar->show(); 
    425     updateEvents(); 
    426     updateStatus(); 
    427   } 
     399  CLEAR(myStatusField); 
     400  if (!skin->lblStatus.rect.isNull()) 
     401  { 
     402    myStatusField = new SkinnableLabel(skin->lblStatus, 
     403        mySystemMenu->getStatusMenu(), this); 
     404    connect(myStatusField, SIGNAL(doubleClicked()), SLOT(showAwayMsgDlg())); 
     405    myStatusField->setToolTip(tr("Right click - Status menu\n" 
     406          "Double click - Set auto response")); 
     407    myStatusField->show(); 
     408  } 
     409 
     410#undef CLEAR 
     411 
     412  // update geometry and contents of the elements 
     413  resizeEvent(NULL); 
     414  updateEvents(); 
     415  updateStatus(); 
    428416} 
    429417 
     
    443431                        width() - skin->frameWidth(), height() - skin->frameHeight()); 
    444432 
    445   if (!skin->frame.hasMenuBar) 
    446     mySystemMenu->setGeometry(skin->btnSys.borderToRect(this)); 
    447  
    448   // Do this to save the new geometry 
    449   myPositionChanges++; 
    450  
    451433  // Resize the background pixmap and mask 
    452434  QPixmap pixmap = skin->mainwinPixmap(width(), height()); 
     
    461443    setMask(mask); 
    462444 
    463   /* Set geometry of our widgets 
    464    * Hide the widget if all position values are equal 
    465    * because this would result in a unusable 1-pixel widget */ 
    466   if (myUserGroupsBox != NULL) 
    467   { 
    468     if (skin->cmbGroups.rect.isNull()) 
    469       myUserGroupsBox->hide(); 
    470     else 
    471       myUserGroupsBox->setGeometry(skin->cmbGroups.borderToRect(this)); 
    472   } 
    473   if (myMessageField != NULL) 
    474   { 
    475     if (skin->lblMsg.rect.isNull()) 
    476       myMessageField->hide(); 
    477     else 
    478       myMessageField->setGeometry(skin->lblMsg.borderToRect(this)); 
    479   } 
    480   if (myStatusField != NULL) 
    481   { 
    482     if (skin->lblStatus.rect.isNull()) 
    483       myStatusField->hide(); 
    484     else 
    485       myStatusField->setGeometry(skin->lblStatus.borderToRect(this)); 
    486   } 
    487   if (mySystemButton != NULL) 
    488   { 
    489     if (skin->btnSys.rect.isNull()) 
    490       mySystemButton->hide(); 
    491     else 
    492       mySystemButton->setGeometry(skin->btnSys.borderToRect(this)); 
    493   } 
    494 } 
    495  
    496 void MainWindow::moveEvent(QMoveEvent* e) 
    497 { 
     445#define UPDATE(wid, group) \ 
     446  if ((wid) != NULL) \ 
     447    (wid)->setGeometry(skin->group.borderToRect(this)); 
     448 
     449  // Set geometry of our widgets 
     450  UPDATE(myUserGroupsBox, cmbGroups); 
     451  UPDATE(myMessageField, lblMsg); 
     452  UPDATE(myStatusField, lblStatus); 
     453  UPDATE(mySystemButton, btnSys) 
     454  else 
     455    myMenuBar->resize(contentsRect().width(), myMenuBar->height()); 
     456 
     457#undef UPDATE 
     458 
    498459  if (isVisible()) 
    499     myPositionChanges++; 
    500  
    501   QWidget::moveEvent(e); 
     460    saveGeometry(); 
     461} 
     462 
     463void MainWindow::saveGeometry() 
     464{ 
     465  Config::General* conf = Config::General::instance(); 
     466  QRect geom = geometry(); 
     467 
     468  if (myInMiniMode) 
     469    geom.setHeight(conf->mainwinRect().height()); 
     470 
     471  conf->setMainwinRect(geom); 
     472} 
     473 
     474void MainWindow::moveEvent(QMoveEvent* /* e */) 
     475{ 
     476  saveGeometry(); 
    502477} 
    503478 
    504479void MainWindow::closeEvent(QCloseEvent* e) 
    505480{ 
    506   if (isVisible() && myPositionChanges > 1) 
    507   { 
    508     // save window position and size 
    509     char buf[MAX_FILENAME_LEN]; 
    510     snprintf(buf, MAX_FILENAME_LEN, "%s%s", BASE_DIR, QTGUI_CONFIGFILE); 
    511     buf[MAX_FILENAME_LEN - 1] = '\0'; 
    512     CIniFile licqConf(INI_FxALLOWxCREATE | INI_FxWARN); 
    513     // need some more error checking here... 
    514     licqConf.LoadFile(buf); 
    515  
    516     licqConf.SetSection("geometry"); 
    517     licqConf.WriteNum("x", static_cast<short>(x())); 
    518     licqConf.WriteNum("y", static_cast<short>(y())); 
    519     licqConf.WriteNum("h", Config::General::instance()->miniMode() ? 
    520         static_cast<short>(myRealHeight) : 
    521         static_cast<short>(size().height())); 
    522     licqConf.WriteNum("w", static_cast<short>(size().width())); 
    523  
    524     licqConf.FlushFile(); 
    525     licqConf.CloseFile(); 
    526   } 
    527  
    528481  e->ignore(); 
    529482 
     
    725678  unsigned short nNumUserEvents = ICQUser::getNumUserEvents() - nNumOwnerEvents; 
    726679 
    727   myMessageField->setBold(false); 
     680  if (myMessageField != NULL) 
     681    myMessageField->setBold(false); 
    728682  QString s, l; 
    729683 
     
    732686    s = tr("SysMsg"); 
    733687    l = tr("System Message"); 
    734     if (Config::General::instance()->boldOnMsg()) 
     688    if (Config::General::instance()->boldOnMsg() && 
     689        myMessageField != NULL) 
    735690      myMessageField->setBold(true); 
    736691    szCaption = "* " + myCaption; 
    737 //    myMessageField->setPrependPixmap(IconManager->instance()->iconForEvent(ICQ_MDxSUB_MSG)); 
    738692  } 
    739693  else if (nNumUserEvents > 0) 
     
    741695    s = tr("%1 msg%2").arg(nNumUserEvents).arg(nNumUserEvents == 1 ? tr(" ") : tr("s")); 
    742696    l = tr("%1 message%2").arg(nNumUserEvents).arg(nNumUserEvents == 1 ? tr(" ") : tr("s")); 
    743     if (Config::General::instance()->boldOnMsg()) 
     697    if (Config::General::instance()->boldOnMsg() && 
     698        myMessageField != NULL) 
    744699      myMessageField->setBold(true); 
    745700    szCaption = "* " + myCaption; 
    746 //    myMessagesField->setPrependPixmap(QPixmap()); 
    747701  } 
    748702  else 
     
    760714    } 
    761715    szCaption = myCaption; 
    762 //    myMessageField->setPrependPixmap(QPixmap()); 
    763   } 
    764   if (myMessageField->fontMetrics().width(l) + myMessageField->margin() > myMessageField->width()) 
    765     myMessageField->setText(s); 
    766   else 
    767     myMessageField->setText(l); 
    768   myMessageField->update(); 
     716  } 
     717 
    769718  setWindowTitle(szCaption); 
     719 
     720  if (myMessageField != NULL) 
     721  { 
     722    if (myMessageField->fontMetrics().width(l) + 
     723        myMessageField->margin() > myMessageField->width()) 
     724      myMessageField->setText(s); 
     725    else 
     726      myMessageField->setText(l); 
     727    myMessageField->update(); 
     728  } 
    770729 
    771730  if (LicqGui::instance()->dockIcon() != NULL) 
     
    802761 
    803762  // Update the msg label if necessary 
    804   if (Config::General::instance()->showGroupIfNoMsg() && 
     763  if (myMessageField != NULL && 
     764      Config::General::instance()->showGroupIfNoMsg() && 
    805765      ICQUser::getNumUserEvents() == 0) 
    806766    myMessageField->setText(myUserGroupsBox->currentText()); 
     
    841801void MainWindow::updateStatus(CICQSignal* s) 
    842802{ 
     803  if (LicqGui::instance()->dockIcon() != NULL) 
     804    LicqGui::instance()->dockIcon()->updateIconStatus(); 
     805 
     806  if (myStatusField == NULL) 
     807    return; 
     808 
    843809  Config::Skin* skin = Config::Skin::active(); 
    844810  QColor theColor = skin->offlineColor; 
     
    939905    myStatusField->setPalette(pal); 
    940906  } 
    941  
    942   if (LicqGui::instance()->dockIcon() != NULL) 
    943     LicqGui::instance()->dockIcon()->updateIconStatus(); 
    944907} 
    945908 
     
    963926} 
    964927 
    965 void MainWindow::slot_aboutToQuit() 
    966 { 
    967   // Empty 
    968 } 
    969  
    970928void MainWindow::slot_logon() 
    971929{ 
    972930  updateStatus(); 
    973   //myStatusField->setEnabled(true); 
    974931} 
    975932 
     
    1029986    return; 
    1030987 
     988  myInMiniMode = miniMode; 
     989 
    1031990  if (miniMode) 
    1032   { 
    1033     myRealHeight = height(); 
    1034991    setMaximumHeight(minimumHeight()); 
    1035   } 
    1036992  else 
    1037993  { 
    1038994    setMaximumHeight(QWIDGETSIZE_MAX); 
    1039     resize(width(), myRealHeight); 
    1040   } 
    1041  
    1042   myInMiniMode = miniMode; 
     995    resize(width(), Config::General::instance()->mainwinRect().height()); 
     996  } 
     997 
    1043998  if (myUserView != NULL) 
    1044999    myUserView->setVisible(!miniMode); 
     
    10501005 
    10511006#ifdef USE_KDE 
    1052     kdeIMInterface->removeProtocol(_nPPID); 
     1007  kdeIMInterface->removeProtocol(_nPPID); 
    10531008#endif 
    10541009} 
  • branches/qt-gui_qt4/src/core/mainwin.h

    r5824 r6043  
    7676 
    7777public: 
    78   MainWindow(bool bStartHidden, QRect startRect, QWidget* parent = 0); 
     78  MainWindow(bool bStartHidden, QWidget* parent = 0); 
    7979  virtual ~MainWindow(); 
    8080 
     
    119119  QString myCaption; 
    120120  bool myInMiniMode; 
    121   unsigned int myPositionChanges; 
    122   unsigned short myRealHeight; 
    123121 
    124122  int myMouseX; 
     
    139137  SkinnableComboBox* myUserGroupsBox; 
    140138 
     139  void saveGeometry(); 
     140 
    141141private slots: 
    142142  void updateConfig(); 
    143   void updateSkin(bool initial = false); 
     143  void updateSkin(); 
    144144  void updateEvents(); 
    145145  void updateStatus(CICQSignal* = NULL); 
     
    151151  void slot_doneOwnerFcn(ICQEvent*); 
    152152  void slot_updateContactList(); 
    153   void slot_aboutToQuit(); 
    154153 
    155154  void addUser(QString id, unsigned long ppid);