Esempio n. 1
0
bool Bishop::MayIGoHere(Coordinates position, Coordinates prev_position, QPointer<Player> friends, QPointer<Player>& enemies, bool CheckForCheck/* = true*/)
{
    if ((prev_position.y() - prev_position.x() != position.y() - position.x()) &&
            (prev_position.y() + prev_position.x() != position.y() + position.x()))
        return false;

    QPointer<Piece> pieceForDelete;
    for (int x = position.x(), y = position.y(); x != prev_position.x(), y != prev_position.y(); (position.x() < prev_position.x())?++x:--x, (position.y() < prev_position.y())?++y:--y)
    {
        if (!(friends->GetAnotherPiece(Coordinates(x, y), this).isNull()))
            return false;
        QPointer<Piece> piece = enemies->GetPiece(Coordinates(x, y));
        if (!piece.isNull())
        {
            if ((x == position.x()) && (y == position.y()))
                pieceForDelete = piece;
            else
            {
                pieceForDelete.clear();
                return false;
            }
        }
    }
    if (CheckForCheck)
    {
        if (enemies->MaySomebodyGoHere(friends->GetKing(), friends, pieceForDelete))
        {
            pieceForDelete.clear();
            return false;
        }
    }

    if (!pieceForDelete.isNull() && CheckForCheck)
        enemies->RemovePiece(pieceForDelete);

    pieceForDelete.clear();
    return true;
}
Esempio n. 2
0
static void logDialogUnregister(QPointer<DebugLog> dialog) {
    if(activeDialog == dialog) {
        qInstallMessageHandler(0);
        activeDialog.clear();
    }
}
Esempio n. 3
0
	void ensureInitialized()
	{
		if (!onVisibleChanged.isValid()) {
			int index = q_ptr->metaObject()->indexOfMethod("implementationVisibileChanged()");
			Q_ASSERT(index >= 0);
			onVisibleChanged = q_ptr->metaObject()->method(index);
		}

		if (component.isNull()) {
			Config config;
			config.beginGroup(QStringLiteral("qml/themes"));
			QString themeName = config.value(dialogName, QStringLiteral("default"));
			QString themePath = ThemeManager::path(QStringLiteral("qml/") + dialogName, themeName);

			if (themePath.isEmpty()) {
				qWarning() << "Failed to find theme:" << themeName << "for dialog:" << dialogName;
				themePath = ThemeManager::path(QStringLiteral("qml/") + dialogName, QStringLiteral("default"));
				if (themePath.isEmpty()) {
					qCritical() << "Failed to find default theme for dialog:" << dialogName;
					return;
				}
			}

			QString fileName = themePath + QStringLiteral("/main.qml");

			component.reset(new QQmlComponent(DeclarativeView::globalEngine(), fileName));
		}

		if (dialog.isNull()) {
			dialog = component->create();
			visibleProperty = QMetaProperty();

			if (!dialog) {
				qCritical() << "Failed to create object for component:" << component->url() << "errors:";
				for (QQmlError error : component->errors()) {
					qCritical() << error.toString();
				}
				return;
			}

			deathConnection = QObject::connect(dialog.data(), &QObject::destroyed, q_ptr, [this] () {
				dialog.clear();
				visibleProperty = QMetaProperty();
				updateVisible();
			});

			int visibleIndex = dialog->metaObject()->indexOfProperty("visible");
			if (visibleIndex < 0) {
				qCritical() << "Failed to find \"visible\" property for component:" << component->url();
				return;
			}

			visibleProperty = dialog->metaObject()->property(visibleIndex);

			if (!visibleProperty.hasNotifySignal()) {
				qCritical() << "Property \"visible\" has no notify signal for component:" << component->url();
			} else {
				QObject::connect(dialog.data(), visibleProperty.notifySignal(), q_ptr, onVisibleChanged);
			}

			updateVisible();
		}
	}