Пример #1
0
/**
 * Add a new sub-window at a given position in the layout.
 * The row and column indices do not have to be within the current shape -
 * it will change accordingly.
 * @param widget :: An MdiSubWindow to add.
 * @param row :: A row index at which to place the new tile.
 * @param col :: A column index at which to place the new tile.
 */
void TiledWindow::addWidget(MdiSubWindow *widget, int row, int col) {
  try {
    Tile *tile = getOrAddTile(row, col);
    // prepare the cell
    m_layout->setColumnMinimumWidth(col, minimumTileWidth);
    m_layout->setRowMinimumHeight(row, minimumTileHeight);
    m_layout->setColumnStretch(col, 1);
    // detach the widget from ApplicationWindow
    widget->detach();
    // widget must have it's parent
    widget->setParent(this);
    // disable mouse events
    widget->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    // attach it to this window
    tile->setWidget(widget);
    connect(widget, SIGNAL(detachFromParent(MdiSubWindow *)), this,
            SLOT(removeWidget(MdiSubWindow *)));
    connect(widget, SIGNAL(closedWindow(MdiSubWindow *)), this,
            SLOT(removeWidget(MdiSubWindow *)));
    // fill possible empty spaces with Tiles
    tileEmptyCells();
  } catch (std::invalid_argument &ex) {
    QMessageBox::critical(this, "MantidPlot- Error",
                          "Cannot add a widget to a TiledWindow:\n\n" +
                              QString::fromStdString(ex.what()));
    sendWidgetTo(widget, Default);
  }
}
Пример #2
0
/**
 * Get a Tile widget at position(row,col). If it doesn't exist create it.
 * @param row :: The row of the cell.
 * @param col :: The column of the cell.
 */
Tile *TiledWindow::getOrAddTile(int row, int col) {
  auto item = m_layout->itemAtPosition(row, col);
  if (item == NULL) {
    m_layout->addWidget(new Tile(this), row, col);
    tileEmptyCells();
    item = m_layout->itemAtPosition(row, col);
    if (item == NULL) {
      throw std::logic_error("TiledWindow cannot be properly initialized.");
    }
  }
  Tile *widget = dynamic_cast<Tile *>(item->widget());
  if (widget != NULL)
    return widget;

  throw std::logic_error("TiledWindow wasn't properly initialized.");
}
Пример #3
0
/**
 * Initialize the inner widgets.
 * @param nrows :: Number of rows to create.
 * @param ncols :: Number of columns to create.
 */
void TiledWindow::init(int nrows, int ncols)
{
  if ( nrows < 1 )
  {
    throw std::invalid_argument("Number of rows in TiledWindow cannot be less then 1.");
  }
  if ( ncols < 1 )
  {
    throw std::invalid_argument("Number of columns in TiledWindow cannot be less then 1.");
  }
  
  if ( m_scrollArea )
  {
    m_scrollArea->close();
    m_scrollArea->deleteLater();
  }

  m_scrollArea = new QScrollArea(this);
  m_scrollArea->setWidgetResizable(true);

  QWidget *innerWidget = new InnerWidget(m_scrollArea);
  m_layout = new QGridLayout(innerWidget);
  m_layout->setMargin(6);
  m_layout->setColumnMinimumWidth(0,minimumTileWidth);
  m_layout->setRowMinimumHeight(0,minimumTileHeight);
  m_layout->addWidget(new Tile(this), nrows - 1, ncols - 1);
  m_layout->setColumnMinimumWidth(0,minimumTileWidth);
  m_layout->setRowMinimumHeight(0,minimumTileHeight);
  for(int col = 0; col < ncols; ++col)
  {
    m_layout->setColStretch( col, 1 );
  }

  m_scrollArea->setWidget(innerWidget);
  this->setWidget( NULL );
  this->setWidget( m_scrollArea );

  tileEmptyCells();
}