Esempio n. 1
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void SGApplication::checkWindowPosition(StatsGeneratorUI* win)
{
  QRect geometry = win->geometry();

  QPoint windowTopLeft = geometry.topLeft();
  QRect mwRect(windowTopLeft, win->size());

  QDesktopWidget desktop;
  QRect desktopRect = desktop.availableGeometry(desktop.primaryScreen());
  // try moving it to keep size
  if (!desktopRect.contains(mwRect))
  {
    mwRect = QRect(desktopRect.topLeft(), win->size());
  }
  // still doesn't fit, resize it
  if (!desktopRect.contains(mwRect))
  {
    mwRect = QRect(desktopRect.topLeft(), win->size());
    win->resize(desktopRect.size());
  }
  win->move(mwRect.topLeft());
}
Esempio n. 2
0
//-----------------------------------------------------------------------------
void ctkSettings::restoreState(const QString& key, QMainWindow& window)
{
  this->beginGroup(key);
  
  if(this->contains("Size"))
    {
    window.resize(this->value("Size").toSize());
    }
    
  if(this->contains("Position"))
    {
    QPoint windowTopLeft = this->value("Position").toPoint();
    QRect mwRect(windowTopLeft, window.size());
    
    QDesktopWidget desktop;
    QRect desktopRect = desktop.availableGeometry( desktop.primaryScreen() );
    // try moving it to keep size
    if(!desktopRect.contains(mwRect))
      {
      mwRect = QRect(desktopRect.topLeft(), window.size());
      }
    // still doesn't fit, resize it
    if(!desktopRect.contains(mwRect))
      {
      mwRect = QRect(desktopRect.topLeft(), window.size());
      window.resize(desktopRect.size());
      }
    window.move(mwRect.topLeft());
    }

  if(this->contains("Layout"))
    {
    window.restoreState(this->value("Layout").toByteArray());
    }
  
  this->endGroup();
}