bool QLinuxFbScreen::initialize() { QRegularExpression ttyRx(QLatin1String("tty=(.*)")); QRegularExpression fbRx(QLatin1String("fb=(.*)")); QRegularExpression mmSizeRx(QLatin1String("mmsize=(\\d+)x(\\d+)")); QRegularExpression sizeRx(QLatin1String("size=(\\d+)x(\\d+)")); QRegularExpression offsetRx(QLatin1String("offset=(\\d+)x(\\d+)")); QString fbDevice, ttyDevice; QSize userMmSize; QRect userGeometry; bool doSwitchToGraphicsMode = true; // Parse arguments foreach (const QString &arg, mArgs) { QRegularExpressionMatch match; if (arg == QLatin1String("nographicsmodeswitch")) doSwitchToGraphicsMode = false; else if (arg.contains(mmSizeRx, &match)) userMmSize = QSize(match.captured(1).toInt(), match.captured(2).toInt()); else if (arg.contains(sizeRx, &match)) userGeometry.setSize(QSize(match.captured(1).toInt(), match.captured(2).toInt())); else if (arg.contains(offsetRx, &match)) userGeometry.setTopLeft(QPoint(match.captured(1).toInt(), match.captured(2).toInt())); else if (arg.contains(ttyRx, &match)) ttyDevice = match.captured(1); else if (arg.contains(fbRx, &match)) fbDevice = match.captured(1); }
//解析歌词,支持单行多时段 void Lyric::parseLyricLine(const QString& line) { //常规歌词 QRegExp rx("\\[(\\d+):(\\d+).(\\d+)\\](.*)"); int pos=rx.indexIn(line); //有些歌词只有到秒 QRegExp specialRx("\\[(\\d+):(\\d+)\\](.*)"); int specialPos=specialRx.indexIn(line); //歌词偏置正则表达式 如[offset:500] QRegExp offsetRx("\\[offset(\\d+)\\]"); int offsetIndex=offsetRx.indexIn(line); if(pos>-1) { int min=rx.cap(1).toInt(); int sec=rx.cap(2).toInt(); int mse=rx.cap(3).toInt();//实际为1%秒 qint64 appearTime=(min*60+sec)*1000+mse*10; times.push(appearTime); //递归解析 QString lyricStr=rx.cap(4); qDebug()<<"parse lyric:"<<lyricStr; parseLyricLine(lyricStr); } else if(specialPos>-1) { int min=specialRx.cap(1).toInt(); int sec=specialRx.cap(2).toInt(); qDebug()<<"specialRx int"<<min<<":"<<sec; qint64 appearTime=(min*60+sec)*1000; times.push(appearTime); //递归解析 QString lyricStr=specialRx.cap(3); parseLyricLine(lyricStr); } else if(offsetIndex>-1) { offset=offsetRx.cap(1).toInt(); qDebug()<<"offset:"<<offset; } while(!times.isEmpty()) { LyricLine* lyricLine=new LyricLine; lyricLine->time=times.pop(); lyricLine->lyric=line; qDebug()<<lyricLine->time<<line; lyricList.append(lyricLine); } }
bool QIntegrityFbScreen::initialize() { Error err; QRegularExpression fbRx(QLatin1String("fb=(.*)")); QRegularExpression sizeRx(QLatin1String("size=(\\d+)x(\\d+)")); QRegularExpression offsetRx(QLatin1String("offset=(\\d+)x(\\d+)")); QString fbDevice; QRect userGeometry; // Parse arguments foreach (const QString &arg, mArgs) { QRegularExpressionMatch match; if (arg.contains(sizeRx, &match)) userGeometry.setSize(QSize(match.captured(1).toInt(), match.captured(2).toInt())); else if (arg.contains(offsetRx, &match)) userGeometry.setTopLeft(QPoint(match.captured(1).toInt(), match.captured(2).toInt())); else if (arg.contains(fbRx, &match)) fbDevice = match.captured(1); }