Ejemplo n.º 1
0
void AVLTree::LevelOrder()
{
    QSequentialAnimationGroup *group = new QSequentialAnimationGroup;
    QQueue<TreeNode*> q;
    q.push_back(root);
    while (!q.empty())
    {
        TreeNode *node = q.front();
        q.pop_front();
        if (node == NULL) continue;
        group->addAnimation(node->getPopAnim());
        q.push_back(node->Lson);
        q.push_back(node->Rson);
    }
    group->start(QAbstractAnimation::DeleteWhenStopped);
}
Ejemplo n.º 2
0
gpu::FramebufferPointer FramebufferCache::getFramebuffer() {
    if (_cachedFramebuffers.isEmpty()) {
        _cachedFramebuffers.push_back(gpu::FramebufferPointer(gpu::Framebuffer::create(gpu::Element::COLOR_RGBA_32, _frameBufferSize.width(), _frameBufferSize.height())));
    }
    gpu::FramebufferPointer result = _cachedFramebuffers.front();
    _cachedFramebuffers.pop_front();
    return result;
}
Ejemplo n.º 3
0
QQueue<QString> Data::getListList()
{
    tryConnectListList();
    QQueue <QString> q;
    QSqlQuery query;
    query.exec("select * from listlist order by id;");
    while (query.next())
    {
        q.push_back(query.value(0).toString());
        qDebug() << "Get list" << query.value(1).toInt() << ":" << query.value(0).toString()<< endl;
    }
    if (q.size() == 0)
    {
        query.exec("insert into listlist"
                   "(name, id, count) values('默认列表', 0, 0);");
        Data::changeListCount(1);
        q.push_back(QString("默认列表"));
        qDebug() << "Create list:默认列表" << endl;
    }
    return q;
}
Ejemplo n.º 4
0
		void DockWidget::addChildren(QObject *object)
		{
			if (!object->isWidgetType())
			{
				return;
			}
			QQueue<QObject*> install;
			install.push_back(object);
			while (!install.empty())
			{
				object = install.front();
				install.pop_front();
				object->installEventFilter(this);
				for (auto &i : object->children())
				{
					if (i->isWidgetType())
					{
						install.push_back(i);
					}
				}
			}
		}
Ejemplo n.º 5
0
void MusicWindow::addMusics()
{
    QQueue<MusicInfo> musics;
    MusicInfo musicInfo;
    QStringList fileDir = QFileDialog::getOpenFileNames(
                this,
                tr("添加"),
                ".",
                tr("MP3 音频文件(*.mp1 *.mp2 *.mp3);; WMA 音频文件(*.wma)"));
    if (fileDir.isEmpty())
        return;
    QStringList::iterator it;
    musicPage->addMusics(fileDir);
    for (it = fileDir.begin(); it != fileDir.end(); ++it)
    {
        musicInfo.setDir(*it);
        musicInfo.setName(QFileInfo(*it).baseName());
        musicInfo.setArtist("");
        musics.push_back(musicInfo);
    }
    player->addMusics(musicPage->getCurrentList(), musics);
    Data::addMusicsToEnd(musicPage->getCurrentList(), musics);
}
Ejemplo n.º 6
0
QQueue<MusicInfo> Data::getMusicList(QString listName)
{
    tryConnectMusicList();
    listName = listName.replace("'", "''");
    QQueue <MusicInfo> q;
    MusicInfo musicInfo;
    QSqlQuery query;
    query.exec("select * from musiclist where listname = '"+listName+"' order by id;");
    while (query.next())
    {
        musicInfo.setDir(query.value(2).toString());
        musicInfo.setName(query.value(3).toString());
        musicInfo.setArtist(query.value(4).toString());
        q.push_back(musicInfo);
        qDebug() << "Get music:" << query.value(3).toString() << endl;
    }
    int all = q.size();
    query.exec("select * from listlist;");
    QString str =
            QString("update listlist set count = %1 "
                    "where name = '%2';").arg(all).arg(listName);
    query.exec(str);
    return q;
}
Ejemplo n.º 7
0
void FramebufferCache::releaseFramebuffer(const gpu::FramebufferPointer& framebuffer) {
    if (QSize(framebuffer->getSize().x, framebuffer->getSize().y) == _frameBufferSize) {
        _cachedFramebuffers.push_back(framebuffer);
    }
}
Ejemplo n.º 8
0
bool ChessModel::isMovable(char player, QPair<int, int> st, QPair<int, int> ed) const
{
    if (player == 'A') {
        st.first = 14 - st.first;
        st.second = 6 - st.second;
        ed.first = 14 - ed.first;
        ed.second = 6 - ed.second;
    }
    if (st.first < 1 || st.first > 13 || st.second < 1 || st.second > 5 ||
            ed.first < 1 || ed.first > 13 || ed.second < 1 || ed.second > 5) return 0;
    if (getChessId(player, ed) != -1) return 0;
    if (getChessId(player, st) == -1) return 0;
    if (isHouse(ed) && (getChessId('A' + 'B' - player, ed) != -1)) return 0;

    int pt = pieceType[getChessId(player, st)];
    if (pt == 10 || pt == 12) return 0;

    if (ed.first == 7  && (ed.second == 2 || ed.second == 4)) return 0;
    if ((st.first == 1 || st.first == 13) && (st.second == 2 || st.second == 4)) return 0;
    int dis = abs(st.first - ed.first) + abs(st.second - ed.second);

    if (dis == 1) return 1;
    if (dis == 2 && (isHouse(st) || isHouse(ed))) return 1;

    if (isRail(st) && isRail(ed)) {
        if (st.first == ed.first) {
            bool flag = 1;
            for (int i = qMin(st.second, ed.second) + 1; i <= qMax(st.second, ed.second) - 1; i++)
                if (getChessId('A', qMakePair(st.first, i)) != -1 || getChessId('B', qMakePair(st.first, i)) != -1)
                    flag = 0;
            if (flag) return 1;
        }
        if (st.second == ed.second) {
            bool flag = 1;
            for (int i = qMin(st.first, ed.first) + 1; i <= qMax(st.first, ed.first) - 1; i++)
                if (getChessId('A', qMakePair(i, st.second)) != -1 || getChessId('B', qMakePair(i, st.second)) != -1)
                    flag = 0;
            if (flag) return 1;
        }
        if (pt != 9) return 0;
        QQueue< QPair<int, int> > queue;
        QSet< QPair<int, int> > set;
        queue.push_back(st);
        while (!queue.empty()) {
            QPair<int, int> now = queue.front();
            queue.pop_front();
            for (int i = 0; i < 4; i++) {
                QPair<int, int> tmp = now;
                tmp.first += dx[i];
                tmp.second += dy[i];
                if (isRail(tmp) && getChessId('A', tmp) == -1 && getChessId('B', tmp) == -1 && set.find(tmp) == set.end()) {
                    queue.push_back(tmp);
                    set.insert(tmp);
                }
            }
        }
        for (auto itm : set) {
            if (qAbs(itm.first - ed.first) + qAbs(itm.second - ed.second) <= 1)
                return 1;
        }
    }
    return 0;
}