コード例 #1
0
ファイル: qdesigner_widgetitem.cpp プロジェクト: mohdpatah/qt
bool QDesignerWidgetItem::subjectToStretch(const QLayout *layout, QWidget *w)
{
    if (!layout)
        return false;
    // Are we under some stretch factor?
    if (const QBoxLayout *bl = qobject_cast<const QBoxLayout *>(layout)) {
        const int index = bl->indexOf(w);
        Q_ASSERT(index != -1);
        return bl->stretch(index) != 0;
    }
    if (const QGridLayout *cgl = qobject_cast<const QGridLayout *>(layout)) {
        QGridLayout *gl = const_cast<QGridLayout *>(cgl);
        const int index = cgl->indexOf(w);
        Q_ASSERT(index != -1);
        int row, column, rowSpan, columnSpan;
        gl->getItemPosition (index, &row, &column, &rowSpan, &columnSpan);
        const int rend = row + rowSpan;
        const int cend = column + columnSpan;
        for (int r = row; r < rend; r++)
            if (cgl->rowStretch(r) != 0)
                return true;
        for (int c = column; c < cend; c++)
            if (cgl->columnStretch(c) != 0)
                return true;
    }
    return false;
}
コード例 #2
0
ファイル: PhotoDrop.cpp プロジェクト: RedCraig/retroshare
void PhotoDrop::checkMoveButtons()
{
	std::cerr << "PhotoDrop::checkMoveButtons()";
	std::cerr << std::endl;
	/* locate mSelected in the set */
	QLayout *alayout = layout();
	if (!alayout)
	{
		std::cerr << "PhotoDrop::checkMoveButtons() No Layout";
		std::cerr << std::endl;
		return;
	}
	
	int count = alayout->count();
	if ((!mSelected) || (count < 2))
	{
    		buttonStatus(PHOTO_SHIFT_NO_BUTTONS);
		return;
	}

	QGridLayout *glayout = dynamic_cast<QGridLayout *>(alayout);
	if (!glayout)
	{
		std::cerr << "PhotoDrop::checkMoveButtons() not GridLayout... not much we can do!";
		std::cerr << std::endl;
    		buttonStatus(PHOTO_SHIFT_NO_BUTTONS);
		return;
	}

	int index = alayout->indexOf(mSelected);
	int selectedRow;
	int selectedColumn;
	int rowSpan;
	int colSpan;
	glayout->getItemPosition(index, &selectedRow, &selectedColumn, &rowSpan, &colSpan);

	int maxRow = (count - 1) / mColumns;
	int maxCol = (count - 1) % mColumns;
	if ((selectedRow == 0) && (selectedColumn == 0))
	{
    		buttonStatus(PHOTO_SHIFT_RIGHT_ONLY);
	}
	else if ((selectedRow == maxRow) && (selectedColumn == maxCol))
	{
    		buttonStatus(PHOTO_SHIFT_LEFT_ONLY);
	}
	else
	{
    		buttonStatus(PHOTO_SHIFT_BOTH);
	}
}
コード例 #3
0
void QxtConfirmationMessagePrivate::init(const QString& message)
{
    remember = false;
    confirm = new QCheckBox(&qxt_p());
    if (!message.isNull())
        confirm->setText(message);
    else
        confirm->setText(QxtConfirmationMessage::tr("Do not show again."));

    QGridLayout* grid = qobject_cast<QGridLayout*>(qxt_p().layout());
    QDialogButtonBox* buttons = qFindChild<QDialogButtonBox*>(&qxt_p());
    if (grid && buttons)
    {
        const int idx = grid->indexOf(buttons);
        int row, column, rowSpan, columnSpan = 0;
        grid->getItemPosition(idx, &row, &column, &rowSpan, &columnSpan);
        QLayoutItem* buttonsItem = grid->takeAt(idx);
        grid->addWidget(confirm, row, column, rowSpan, columnSpan, Qt::AlignLeft | Qt::AlignTop);
        grid->addItem(buttonsItem, ++row, column, rowSpan, columnSpan);
    }
}
コード例 #4
0
void PlaylistTabBar::Close() {
  if (menu_index_ == -1) return;

  const int playlist_id = tabData(menu_index_).toInt();

  const int active_id = manager_->active_id();

  qLog(Debug) << "Close : active_id = " << active_id << " and playlist_id = " << playlist_id;


  QSettings s;
  s.beginGroup(kSettingsGroup);

  const bool ask_for_delete = s.value("warn_close_playlist", true).toBool();

  bool check_delete = (ask_for_delete && !manager_->IsPlaylistFavorite(playlist_id) &&
        !manager_->playlist(playlist_id)->GetAllSongs().empty());

  bool check_active = (active_id == playlist_id && manager_->app()->player_locked_);

  qLog(Debug) << "Close : check_delete = " << check_delete << " and check_active = " << check_active;

  if (check_delete || check_active) {

    QMessageBox confirmation_box;
    confirmation_box.setWindowIcon(QIcon(":/icon.png"));
    confirmation_box.setWindowTitle(tr("Remove playlist"));
    confirmation_box.setIcon(QMessageBox::Question);
    confirmation_box.setText(
        tr("You are about to remove a playlist which is not part of your "
           "favorite playlists: "
           "the playlist will be deleted (this action cannot be undone). \n"
           "Are you sure you want to continue?"));
    confirmation_box.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);

    QCheckBox dont_prompt_again(tr("Warn me when closing a playlist tab"),
                                &confirmation_box);
    dont_prompt_again.setChecked(ask_for_delete);
    dont_prompt_again.blockSignals(true);
    dont_prompt_again.setToolTip(
        tr("This option can be changed in the \"Behavior\" preferences"));

    QGridLayout* grid = qobject_cast<QGridLayout*>(confirmation_box.layout());
    QDialogButtonBox* buttons = confirmation_box.findChild<QDialogButtonBox*>();
    if (grid && buttons) {
      const int index = grid->indexOf(buttons);
      int row, column, row_span, column_span = 0;
      grid->getItemPosition(index, &row, &column, &row_span, &column_span);
      QLayoutItem* buttonsItem = grid->takeAt(index);
      grid->addWidget(&dont_prompt_again, row, column, row_span, column_span,
                      Qt::AlignLeft | Qt::AlignTop);
      grid->addItem(buttonsItem, ++row, column, row_span, column_span);
    } else {
      confirmation_box.addButton(&dont_prompt_again, QMessageBox::ActionRole);
    }

    if (confirmation_box.exec() != QMessageBox::Yes) {
      return;
    }

    // If user changed the pref, save the new one
    if (dont_prompt_again.isChecked() != ask_for_delete) {
      s.setValue("warn_close_playlist", dont_prompt_again.isChecked());
    }
  }

  // Close the playlist. If the playlist is not a favorite playlist, it will be
  // deleted, as it will not be visible after being closed. Otherwise, the tab
  // is closed but the playlist still exists and can be resurrected from the
  // "Playlists" tab.
  emit Close(playlist_id);

  // Select the nearest tab.
  if (menu_index_ > 1) {
    setCurrentIndex(menu_index_ - 1);
  }

  // Update playlist tab order/visibility
  TabMoved();
}
コード例 #5
0
void QGridLayoutProto::getItemPosition(int index, int *row, int *column, int *rowSpan, int *columnSpan)
{
  QGridLayout *item = qscriptvalue_cast<QGridLayout*>(thisObject());
  if (item)
    item->getItemPosition(index, row, column, rowSpan, columnSpan);
}
コード例 #6
0
ファイル: qt.cpp プロジェクト: HackerSuid/ACE
/*
 * Update the QtSensoryRegion grid display to reflect the current input
 * pattern by changing the brush color of the QtUnits.
 */
void QtFront::UpdateInputDisplay(SensoryRegion *newPattern)
{
    QGridLayout *currSensoryGrid =
        (QGridLayout *)sensoryGroup->layout();
    QGridLayout *newSensoryGrid =
        CurrentInput->SensoryUnitGrid();
    int w = newPattern->GetWidth();
    int h = newPattern->GetHeight();

    SensoryRegion *mp = newPattern->GetMotorPattern();
    //QGridLayout *currMotorGrid =
    //    (QGridLayout *)motorGroup->layout();
    //QGridLayout *newMotorGrid =
    //    CurrentInput->MotorUnitGrid();

    SensoryRegion *lp = newPattern->GetLocationPattern();
    QGridLayout *currLocGrid =
        (QGridLayout *)locGroup->layout();
    QGridLayout *newLocGrid =
        CurrentInput->LocationUnitGrid();

    int r, g, b;
    QColor rgb;
    QtUnit *oldqtunit = NULL, *newqtunit = NULL;

/*
 The old way of updating the sensory input unit grid. This had very,
 very poor performance, so I am leaving the code here as a reminder.

    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            // getting the qlayout item with itemAtPosition has very
            // poor performance.
            qtunit = (QtUnit *)newSensoryGrid->itemAtPosition(i, j)->widget();
            rgb = qtunit->getBrushColor();
            rgb.getRgb(&r, &g, &b);
            qtunit = (QtUnit *)currSensoryGrid->itemAtPosition(i, j)->widget();
            qtunit->setBrushColor(QColor(r, g, b));
        }
    }
*/

    /* sensory input display grid */
    for (int i=0; i<newSensoryGrid->count(); i++) {
        int row, col, rs, cs;
        newSensoryGrid->getItemPosition(i, &row, &col, &rs, &cs);
        newqtunit = (QtUnit *)newSensoryGrid->itemAt(i)->widget();
        rgb = newqtunit->getBrushColor();
        rgb.getRgb(&r, &g, &b);
        oldqtunit = (QtUnit *)currSensoryGrid->itemAt(i)->widget();
        oldqtunit->setBrushColor(QColor(r, g, b));
    }
    /* motor input display grid */
    /*
    for (int i=0; i<newMotorGrid->count(); i++) {
        int row, col, rs, cs;
        newMotorGrid->getItemPosition(i, &row, &col, &rs, &cs);
        newqtunit = (QtUnit *)newMotorGrid->itemAt(i)->widget();
        rgb = newqtunit->getBrushColor();
        rgb.getRgb(&r, &g, &b);
        oldqtunit = (QtUnit *)currMotorGrid->itemAt(i)->widget();
        oldqtunit->setBrushColor(QColor(r, g, b));
        oldqtunit->SetActive(newqtunit->IsActive());
    }
    */

    /* location input display grid */
    for (unsigned int i=0; i<newLocGrid->count(); i++) {
        int row, col, rs, cs;
        newLocGrid->getItemPosition(i, &row, &col, &rs, &cs);
        newqtunit = (QtUnit *)newLocGrid->itemAt(i)->widget();
        rgb = newqtunit->getBrushColor();
        rgb.getRgb(&r, &g, &b);
        oldqtunit = (QtUnit *)currLocGrid->itemAt(i)->widget();
        oldqtunit->setBrushColor(QColor(r, g, b));
        oldqtunit->SetActive(newqtunit->IsActive());
    }
}
コード例 #7
0
ファイル: PhotoDrop.cpp プロジェクト: RedCraig/retroshare
void PhotoDrop::moveRight()
{
	std::cerr << "PhotoDrop::moveRight()";
	std::cerr << std::endl;

	QLayout *alayout = layout();
	if (!alayout)
	{
		std::cerr << "PhotoDrop::moveRight() No Layout";
		std::cerr << std::endl;
		return;
	}

	QGridLayout *glayout = dynamic_cast<QGridLayout *>(alayout);
	if (!glayout)
	{
		std::cerr << "PhotoDrop::moveRight() not GridLayout... not much we can do!";
		std::cerr << std::endl;
		return;
	}
	
	int count = alayout->count();
	if ((!mSelected) || (count < 2))
	{
		std::cerr << "PhotoDrop::moveRight() Not enough items";
		std::cerr << std::endl;
		return;
	}

	int index = alayout->indexOf(mSelected);
	int selectedRow;
	int selectedColumn;
	int rowSpan;
	int colSpan;
	glayout->getItemPosition(index, &selectedRow, &selectedColumn, &rowSpan, &colSpan);

	int maxRow = (count - 1) / mColumns;
	int maxCol = (count - 1) % mColumns;
	if ((selectedRow == maxRow) && (selectedColumn == maxCol))
	{
		std::cerr << "PhotoDrop::moveRight() Selected is last item";
		std::cerr << std::endl;
		return;
	}

	int swapRow = selectedRow;
	int swapColumn = selectedColumn + 1;

	if (swapColumn == mColumns)
	{
		swapRow++;
		swapColumn = 0;
	}

	std::cerr << "PhotoDrop::moveRight() Trying to swap (" << selectedRow << ",";
	std::cerr << selectedColumn << ") <-> (" << swapRow;
	std::cerr << "," << swapColumn << ")";
	std::cerr << std::endl;

	QLayoutItem *litem = glayout->itemAtPosition(swapRow, swapColumn);
	if (!litem)
	{
		std::cerr << "PhotoDrop::moveRight() No layout item to the right";
		std::cerr << std::endl;
		return;
	}

	QWidget *widget = litem->widget();

	if (!widget)
	{
		std::cerr << "PhotoDrop::moveRight() No item to the right";
		std::cerr << std::endl;
		return;
	}

	/* grab both items, and switch */
	std::cerr << "PhotoDrop::moveRight() could move index: " << index;
	std::cerr << std::endl;

	glayout->removeWidget(widget);
	glayout->removeWidget(mSelected);

	glayout->addWidget(widget, selectedRow, selectedColumn, Qt::AlignCenter);
	glayout->addWidget(mSelected, swapRow, swapColumn, Qt::AlignCenter);

	checkMoveButtons();
}
コード例 #8
0
ファイル: PhotoDrop.cpp プロジェクト: RedCraig/retroshare
void PhotoDrop::reorderPhotos()
{
	std::cerr << "PhotoDrop::reorderPhotos()";
	std::cerr << std::endl;

	/* now move the qwidgets around */
	QLayout *alayout = layout();
	QGridLayout *glayout = dynamic_cast<QGridLayout *>(alayout);
	if (!glayout)
	{
		std::cerr << "PhotoDrop::reorderPhotos() not GridLayout... not much we can do!";
		std::cerr << std::endl;
		return;
	}

	/* grab the first PhotoItem - and get it size */
	std::map<gridIndex, PhotoItem *> photoItems;
	std::map<gridIndex, PhotoItem *>::iterator pit;

	int count = glayout->count();
	int i = 0;
	for(i = 0; i < count; i++)
	{
		QLayoutItem *litem = glayout->itemAt(i);
		if (!litem)
		{
			std::cerr << "PhotoDrop::reorderPhotos() missing litem";
			std::cerr << std::endl;
			continue;
		}

		PhotoItem *item = dynamic_cast<PhotoItem *>(litem->widget());
		if (item)
		{
			
			int selectedRow;
			int selectedColumn;
			int rowSpan;
			int colSpan;
			glayout->getItemPosition(i, &selectedRow, &selectedColumn, &rowSpan, &colSpan);

			std::cerr << "PhotoDrop::reorderPhotos() item: " << item;
			std::cerr << " layoutIdx: " << i;
			std::cerr << " item pos(" << selectedRow << ", " << selectedColumn;
			std::cerr << ")" << std::endl;
			
			gridIndex idx(selectedRow, selectedColumn);
			photoItems[idx] = item;
	
		}
		else
		{
			std::cerr << "PhotoDrop::reorderPhotos() Found Child, which is not a PhotoItem???";
			std::cerr << std::endl;
		}
	}

	pit = photoItems.begin(); 
	if (pit == photoItems.end())
	{
		std::cerr << "PhotoDrop::reorderPhotos() No PhotoItems.";
		std::cerr << std::endl;

		mColumns = 1;

		// no PhotoItems here.
		return;
	}

	int minWidth = (pit->second)->minimumWidth();

#define EXPECTED_WIDTH 	(200)
	if (minWidth < EXPECTED_WIDTH)
	{
		minWidth = EXPECTED_WIDTH;
	}
	int space = width();
	mColumns = space / minWidth;
	// incase its too thin!
	if (mColumns < 1)
	{
		mColumns = 1;
	}

	std::cerr << "PhotoDrop::reorderPhotos() minWidth: " << minWidth << " space: " << space;
	std::cerr << " columns: " << mColumns;
	std::cerr << std::endl;

	std::cerr << "PhotoDrop::reorderPhotos() Getting ordered Items from Layout";
	std::cerr << std::endl;


	for(pit = photoItems.begin(); pit != photoItems.end(); pit++)
	{
		glayout->removeWidget(pit->second);
	}
	
	for(pit = photoItems.begin(), i = 0; pit != photoItems.end(); pit++, i++)
	{
		int row = i / mColumns;
		int column = i % mColumns;

		std::cerr << "Inserting item: " << pit->second << " at (" << row << "," << column << ")";
		std::cerr << std::endl;
		glayout->addWidget(pit->second, row, column, Qt::AlignCenter);
	}
}