Beispiel #1
0
void WeatherPlugin::updateButton()
{
    if ((getTime() == 0) || (m_bar == NULL))
        return;
    const char **xpm = NULL;
    QString conditions(getConditions());
    if (conditions == "Overcast"){
        xpm = overcast;
    }else if (conditions == "Fog"){
        xpm = fog;
    }else if (conditions == "Storm"){
        xpm = storm;
    }else if (conditions == "Rain"){
        xpm = rain;
    }else if (conditions == "Snow"){
        xpm = snow;
    }else if (conditions == "Cloudy"){
        xpm = snow;
    }else if (conditions == "Clear"){
        xpm = isDay() ? day : night;
    }else if (conditions == "Partial cloudy"){
        xpm = isDay() ? day_cloudy : night_cloudy;
    }
    if (xpm){
        IconDef icon;
        icon.name = "weather";
        icon.xpm  = xpm;
        Event eIcon(EventAddIcon, &icon);
        eIcon.process();
    }
    QString text = unquoteText(getButtonText());
    QString tip = getTipText();
    text = replace(text);
    tip  = replace(tip);
    Command cmd;
    cmd->id		= CmdWeather;
    cmd->param	= m_bar;
    Event e(EventCommandWidget, cmd);
    CToolButton *btn = (CToolButton*)e.process();
    if (btn == NULL)
        return;
    btn->setTextLabel(text);
    btn->repaint();
    QToolTip::add(btn, tip);
}
Beispiel #2
0
QString CronToken::toString() const {
    if (isNumber())
        return QVariant(number).toString();
    if (isOperator())
        return QVariant(op).toString();
    if (isDay())
        return QDate::shortDayName(number).toLower();
    return command;
}
void FCamera::updateTimeOfDay()
{
    log(Trace, this, "updating time of day");
    bool currentDay = isDay(timeInfo);
    if(currentDay != day)
    {
        stateChange = true;
        log(Trace, this, "state change");
    }
    else
        stateChange = false;

    day = currentDay;
}
int WindscreenLocator::locateLeftRight()
{
    CvRect roiRect = cvRect(0, imgGradH->height / 3, imgGradH->width, imgGradH->height * 0.9 - imgGradH->height/3);

    thresholdGrad = max(averageGrad, 1.0 ) * 2.5;

    cvSetImageROI(imgGradV, roiRect);
    histoStat(imgGradV, vertical2X, NULL, thresholdGrad, 0);
    cvResetImageROI(imgGradV);

    cvSetImageROI(imgGradH, roiRect);
    histoStat(imgGradH, horizon2X, NULL, thresholdGrad, 0);
    cvResetImageROI(imgGradH);


    int margin = 0.04 * imgGrad->width;
    memset(vertical2X, 0, sizeof(double) * margin);
    memset(vertical2X + imgGrad->width - margin, 0, sizeof(double) * margin);
    histoSmooth(vertical2X, imgGrad->width, 5);
    histoSmooth(vertical2X, imgGrad->width, 10);
    histoSmooth(vertical2X, imgGrad->width, 20);

    histoSmooth(horizon2X, imgGrad->width, 5);
    histoSmooth(horizon2X, imgGrad->width, 10);
    histoSmooth(horizon2X, imgGrad->width, 40);

    // 计算车辆左右边界
    int topList[10];
    int topNr = 3;
    histoCrest(vertical2X, imgGrad->width, topList, topNr);

    if(!plate->isValid()){
        if(topNr >= 2){
            int a = min(topList[0], topList[1]);
            int b = max(topList[0], topList[1]);
            pdebug("horizon=%f\n", horizon2X[(b+a) / 2]);
            pdebug("bike Width = %d, lpWIdth=%f\n", b - a, plate->defaultWidth *2);
            double f = isDay(imgGray) ? 0.09 : 0.07;
            if(horizon2X[(b+a) / 2] > imgRGB->height * (0.9 - 1.0 / 3) * f){

            }else if((double)(b - a) < plate->defaultWidth * 2){
                if(b - a < plate->defaultWidth * 1.5){
                    int ext = -(b - a - plate->defaultWidth * 1.5) / 2;
                    a = max((a - ext), 0);
                    b = min((b + ext), (imgGrad->width - 1));
                }
                if(existCrest(horizon2X, imgGrad->width, a, b, 0.9) != 0){
                    return -1;
                }
            }else if((double)(b - a) < plate->defaultWidth * 3.2 && b < imgRGB->width * 0.7){
                if(existCrest(horizon2X, imgGrad->width, a, b, 0.8) != 0){
                    CvRect rect;
                    double shrunkRatio = imgRGB->width / double(imgOrigin->width);
                    rect.x = a;
                    rect.width = b - a;
                    rect.y = imgRGB->height * 0.25;
                    rect.height = imgRGB->height * (0.3 - 0.25);
                    rect = rectScale(rect, 1 / shrunkRatio, cvSize(imgOrigin->width, imgOrigin->height));
                    vector<FaceInfo> faceVec;
                    faceDetector->detectTriWheelMotor(imgOrigin, rect, plate->defaultWidth, faceVec);
                    if(faceVec.size() < 1){
                        return -1;
                    }
                    bool isTriWheel = true;
                    for(size_t i = 0; i < faceVec.size(); i++){
                        int mid = faceVec[i].getMiddlePoint().x;
                        if(mid < rect.x + 0.4 * rect.width || mid > rect.x + 0.6 * rect.width){
                            isTriWheel = false;
                            pdebug("face pos=%d %d\n", faceVec[i].getMiddlePoint().x, faceVec[i].getMiddlePoint().y);
                            break;
                        }
                    }
                    if(isTriWheel)
                        return -1;
                }
            }
        }
    }

    int intervalA;
    int intervalB;

    histoSegment(horizon2X, imgGrad->width, histoSegmentRatio(averageGrad), intervalA, intervalB);
    judgeVerticalBorder(imgGrad->width, topList, topNr, intervalA, intervalB, winLeft, winRight);
    return 0;
}
void SchedulerCellDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
    QStyleOptionViewItemV4 viewOption = option;

    painter->save();

    QBrush brush = viewOption.backgroundBrush;
    QColor textColor = Qt::black;
    QRect rect = viewOption.rect;

    QString textCell = index.model()->data(index, SchedulerTableModel::WishDayRole).toString();

    if (textCell == "RR") {
        brush = QBrush(Qt::lightGray);

    } else if (textCell == "XX") {
        textColor = Qt::white;
        brush = QBrush(Qt::black);

// TODO: градиент как скрине
//        QLinearGradient gradient(rect.topLeft(), rect.bottomRight());
//        gradient.setSpread(QGradient::RepeatSpread);
//        gradient.setColorAt(0, Qt::black);
//        gradient.setColorAt(1, Qt::white);
//        brush = QBrush(gradient);

    } else if (textCell == "DD") {
        brush = QBrush(Qt::yellow);
        rect.setWidth(rect.width() / 2);

    } else if (textCell == "NN") {
        brush = QBrush(Qt::yellow);
        rect.setX(rect.x() + rect.width() / 2);
    }

    painter->fillRect(rect, brush);

    DayKind day = index.model()->data(index, SchedulerTableModel::DayKindRole).value<DayKind>();
    if (day != DayKind::NONE) {
        QImage dayImage = index.model()->data(index, SchedulerTableModel::DayImageKindRole).value<QImage>();
        QRect rect = option.rect;

        // Отступ иконки в ячейке
        auto indent = 4;
        auto size = qMin(rect.size().width(), rect.size().height()) - indent * 2;

        if (!dayImage.isNull()) {
            dayImage = dayImage.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
        }

        if (isDay(day)) {
            painter->drawImage(rect.x() + indent, rect.y() + indent, dayImage);

        } else if (isNight(day)) {
            painter->drawImage(rect.x() + size + indent + indent * 2, rect.y() + indent, dayImage);
        }
    }

    // Если ячейка входит в LongRests ячейки, подрисуем снизу линию, подчеркивая ячейку
    const auto schedulerTableModel = dynamic_cast <const SchedulerTableModel*> (index.model());
    if (schedulerTableModel && schedulerTableModel->columnInLongRests(index)) {
        painter->setPen(Qt::NoPen);
        painter->setBrush(QColor(255, 128, 0));

        const auto heightLine = 4;
        auto rect = viewOption.rect;
        rect.setY(rect.y() + rect.height() - heightLine);
        rect.setHeight(heightLine);
        painter->drawRect(rect);
    }

    painter->restore();

    // Цвет выделения полупрозрачный, чтобы были видно что в ячейке
    QStyleOptionViewItem itemOption(option);
    initStyleOption(&itemOption, index);

    if (itemOption.state & QStyle::State_Selected) {
        auto color = itemOption.palette.color(QPalette::Highlight);
        color.setAlpha(180);
        itemOption.palette.setColor(QPalette::Highlight, color);
    }

    // Здесь дорисовываются стандартные вещи вроде текста, которые берутся из модели
    QStyledItemDelegate::paint(painter, itemOption, index);
}