Exemplo n.º 1
0
void CAppPalette::initColors()
{
   for (int colorIndex = 0;colorIndex < NumAppColors - 1;colorIndex++)
   {
      setPaletteEntry(colorIndex,getDefaultColor(colorIndex),PC_RESERVED);
   }

   setPaletteEntry(m_editIndex,colorWhite,PC_RESERVED);
}
Exemplo n.º 2
0
namespace helper {

    Console::ColorsStatus Console::s_colorsStatus = Console::ColorsAuto;

    void Console::init()
    {
        // Change s_colorsStatus based on the SOFA_COLOR_TERMINAL environnement variable.
        const char *sofa_color_terminal = getenv("SOFA_COLOR_TERMINAL");
        if (sofa_color_terminal != NULL)
        {
            const std::string colors(sofa_color_terminal);
            if (colors == "yes" || colors == "on" || colors == "always")
                s_colorsStatus = Console::ColorsEnabled;
            else if (colors == "no" || colors == "off" || colors == "never")
                s_colorsStatus = Console::ColorsDisabled;
            else if (colors == "auto")
                s_colorsStatus = Console::ColorsAuto;
            else
                msg_warning("Console::init()") << "Bad value for environnement variable SOFA_COLOR_TERMINAL (" << colors << ")";
        }
    }

#ifdef WIN32

    static HANDLE getOutputHandle()
    {
        static bool first = true;
        static HANDLE s_console = NULL;
        if (first)
        {
            s_console = GetStdHandle(STD_OUTPUT_HANDLE);
            if (s_console == INVALID_HANDLE_VALUE)
            {
                std::cerr << "Console::getOutputHandle(): " << Utils::GetLastError() << std::endl;
            }
            if (s_console == NULL)
            {
                std::cerr << "Console::getOutputHandle(): no stdout handle!" << std::endl;
            }
            first = false;
        }
        return s_console;
    }

    static Console::ColorType getDefaultColor()
    {
        CONSOLE_SCREEN_BUFFER_INFO currentInfo;
        GetConsoleScreenBufferInfo(getOutputHandle(), &currentInfo);
        return currentInfo.wAttributes;
    }
    static Console::CodeType getDefaultCode()
    {
        CONSOLE_SCREEN_BUFFER_INFO currentInfo;
        GetConsoleScreenBufferInfo(getOutputHandle(), &currentInfo);
        return currentInfo.wAttributes;
    }



    const Console::ColorType Console::BLACK         = Console::ColorType(0);
    const Console::ColorType Console::BLUE          = Console::ColorType(1);
    const Console::ColorType Console::GREEN         = Console::ColorType(2);
    const Console::ColorType Console::CYAN          = Console::ColorType(3);
    const Console::ColorType Console::RED           = Console::ColorType(4);
    const Console::ColorType Console::PURPLE        = Console::ColorType(5);
    const Console::ColorType Console::YELLOW        = Console::ColorType(6);
    const Console::ColorType Console::WHITE         = Console::ColorType(7);
    const Console::ColorType Console::BRIGHT_BLACK  = Console::ColorType(8);
    const Console::ColorType Console::BRIGHT_BLUE   = Console::ColorType(9);
    const Console::ColorType Console::BRIGHT_GREEN  = Console::ColorType(10);
    const Console::ColorType Console::BRIGHT_CYAN   = Console::ColorType(11);
    const Console::ColorType Console::BRIGHT_RED    = Console::ColorType(12);
    const Console::ColorType Console::BRIGHT_PURPLE = Console::ColorType(13);
    const Console::ColorType Console::BRIGHT_YELLOW = Console::ColorType(14);
    const Console::ColorType Console::BRIGHT_WHITE  = Console::ColorType(15);
    const Console::ColorType Console::DEFAULT_COLOR = getDefaultColor();

    //TODO(dmarchal): Implement the rich text on windows...
    const Console::CodeType Console::ITALIC = getDefaultCode();
    const Console::CodeType Console::UNDERLINE = getDefaultCode();
    const Console::CodeType Console::DEFAULT_CODE = getDefaultCode();

    void Console::setColorsStatus(ColorsStatus status)
    {
        s_colorsStatus = status;
    }

    bool Console::shouldUseColors(std::ostream& stream)
    {
        // On Windows, colors are not handled with control characters, so we can
        // probably always use them unless explicitely disabled.
        return getColorsStatus() != ColorsDisabled;
    }

    SOFA_HELPER_API std::ostream& operator<<( std::ostream& stream, Console::ColorType color )
    {
        if (Console::shouldUseColors(stream))
            SetConsoleTextAttribute(getOutputHandle(), color.value);
        return stream;
    }

    SOFA_HELPER_API std::ostream& operator<<( std::ostream& stream, Console::CodeType code )
    {
        if (Console::shouldUseColors(stream))
            SetConsoleTextAttribute(getOutputHandle(), code.value);
        return stream;
    }

#else

    const Console::ColorType Console::BLACK         = Console::ColorType("\033[0;30m");
    const Console::ColorType Console::RED           = Console::ColorType("\033[0;31m");
    const Console::ColorType Console::GREEN         = Console::ColorType("\033[0;32m");
    const Console::ColorType Console::YELLOW        = Console::ColorType("\033[0;33m");
    const Console::ColorType Console::BLUE          = Console::ColorType("\033[0;34m");
    const Console::ColorType Console::PURPLE        = Console::ColorType("\033[0;35m");
    const Console::ColorType Console::CYAN          = Console::ColorType("\033[0;36m");
    const Console::ColorType Console::WHITE         = Console::ColorType("\033[0;37m");
    const Console::ColorType Console::BRIGHT_BLACK  = Console::ColorType("\033[1;30m");
    const Console::ColorType Console::BRIGHT_RED    = Console::ColorType("\033[1;31m");
    const Console::ColorType Console::BRIGHT_GREEN  = Console::ColorType("\033[1;32m");
    const Console::ColorType Console::BRIGHT_YELLOW = Console::ColorType("\033[1;33m");
    const Console::ColorType Console::BRIGHT_BLUE   = Console::ColorType("\033[1;34m");
    const Console::ColorType Console::BRIGHT_PURPLE = Console::ColorType("\033[1;35m");
    const Console::ColorType Console::BRIGHT_CYAN   = Console::ColorType("\033[1;36m");
    const Console::ColorType Console::BRIGHT_WHITE  = Console::ColorType("\033[1;37m");
    const Console::ColorType Console::DEFAULT_COLOR = Console::ColorType("\033[0m");

    const Console::CodeType Console::UNDERLINE = Console::CodeType("\033[4m");
    const Console::CodeType Console::ITALIC = Console::CodeType("\033[3m");
    const Console::CodeType Console::DEFAULT_CODE = Console::CodeType("\033[0m");


    static bool s_stdoutIsRedirected = false;
    static bool s_stderrIsRedirected = false;

    void Console::setColorsStatus(ColorsStatus status)
    {
        s_colorsStatus = status;
        // Check for redirections and save the result.  (This assumes that
        // stdout and stderr won't be redirected in the middle of the execution
        // of the program, which seems reasonable to me.)
        s_stdoutIsRedirected = isatty(STDOUT_FILENO) == 0;
        s_stderrIsRedirected = isatty(STDERR_FILENO) == 0;
    }

    bool Console::shouldUseColors(std::ostream& stream)
    {
        if (s_colorsStatus == Console::ColorsAuto)
            return (&stream == &std::cout && !s_stdoutIsRedirected)
                || (&stream == &std::cerr && !s_stderrIsRedirected);
        else
            return s_colorsStatus == Console::ColorsEnabled;
    }

    std::ostream& operator<<( std::ostream& stream, Console::ColorType color )
    {
        if (Console::shouldUseColors(stream))
            return stream << color.value;
        else
            return stream;
    }

    std::ostream& operator<<( std::ostream& stream, Console::CodeType code )
    {
        if (Console::shouldUseColors(stream))
            return stream << code.value;
        else
            return stream;
    }


#endif

    size_t Console::getColumnCount(){
#ifdef __linux__
        struct winsize w;
        ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
        return w.ws_col;
#else
        //TODO(dmarchal): implement macOS and Windows or a portable version of this function.
        return 80;
#endif
    }

    Console::ColorsStatus Console::getColorsStatus()
    {
        return s_colorsStatus;
    }

}
Exemplo n.º 3
0
bool PSV_ChartItem::adjusetMargin()
{
//    qreal m_margin = getData(PSV::margin).toDouble();
//    PSV_Public::printMes(m_margin,"margin");
    int m_margin = getData(PSV::margin,3).toInt();
    qreal margin_up = m_margin_up+m_margin;
    qreal margin_down = m_margin_down+m_margin;
    qreal margin_left = m_margin_left+m_margin;
    qreal margin_right = m_margin_right+m_margin;

    if(m_axisParam_left.m_isShow)
    {
        createLeftAxisi(m_axisParam_left);
        margin_left += m_leftAxisItem->validRect().width();
    }
    if(m_axisParam_right.m_isShow)
    {
        createRightAxisi(m_axisParam_right);
        margin_right += m_rightAxisItem->validRect().width();
    }
    if(m_axisParam_up.m_isShow)
    {
        createUpAxisi(m_axisParam_up);
        margin_up += m_upAxisItem->validRect().height();
    }

    if(m_axisParam_down.m_isShow)
    {
        createDownAxisi(m_axisParam_down);
        margin_down += m_downAxisItem->validRect().height();
    }
    QString m_titleText = getData(PSV::titleText,"").toString();
    if(!m_titleText.isEmpty())
    {
        createTitle(m_titleText);
        margin_up += m_titleItem->boundingRect().height();
    }
    if(!isStaHidden() && m_curveDataMap.count() > 0)
    {
        qreal height_max = 0;
        qreal width_max = 0;
        QGraphicsTextItem *textItem = new QGraphicsTextItem(this);
        textItem->setDefaultTextColor(getDefaultColor());
        textItem->setFont(staFont());
        QMapIterator<QString,PSV_CurveInfo> iter(m_curveDataMap);
        while(iter.hasNext())
        {
            iter.next();
            PSV_CurveInfo curveInfo = iter.value();
            textItem->setHtml(curveInfo.m_staHtmText);
            qreal tempWidth = textItem->boundingRect().width();
            qreal tempHeight = textItem->boundingRect().height();
            if(width_max < tempWidth)
            {
                width_max = tempWidth;
            }
            if(height_max < tempHeight)
            {
                height_max = tempHeight;
            }
        }
        width_max += height_max;
        height_max +=  getData(PSV::margin,3).toInt();
        qreal width = getBoundingRect().width() - margin_left - margin_right;
        if(width_max >= width)
        {
            margin_down += m_curveDataMap.count() * height_max;
        }
        else
        {
            int count_row = (int)(width / width_max);
            int dataCount = m_curveDataMap.count();
            if(dataCount % count_row != 0)
            {
                dataCount += count_row;
            }
            int count = dataCount / count_row;
            margin_down += count * height_max;
        }
        m_staMaxWidth = width_max;
    }
    m_margin_total_up = margin_up;
    m_margin_total_down = margin_down;
    m_margin_total_left = margin_left;
    m_margin_total_right = margin_right;
    updateChartRect();
    return clearAll();
}
Exemplo n.º 4
0
void PSV_ChartItem::updateForDouble()
{
    QMapIterator<QString,PSV_CurveInfo> iter(m_curveDataMap);
    qreal posY = m_staStartPoint.y();
    qreal posX = m_staStartPoint.x();
    while(iter.hasNext())
    {
        iter.next();
        PSV_CurveInfo curveInfo = iter.value();
        updateAxisRange(curveInfo.m_axisType);
        addCurveItem(curveInfo);
        addEllipseItem(curveInfo);
        if(!isStaHidden())
        {
            QGraphicsTextItem *textItem = new QGraphicsTextItem(this);
            textItem->setData(E_ITEM_TYPE,PSV::staLabelItem);
            textItem->setData(E_CURVE_NAME,curveInfo.m_curveName);
            textItem->setFlags(QGraphicsItem::ItemIsSelectable);
            textItem->installSceneEventFilter(this);

            textItem->setDefaultTextColor(getDefaultColor());
            textItem->setFont(staFont());
            textItem->setHtml(curveInfo.m_staHtmText);
            double textHeight = textItem->boundingRect().height();
            int staMaxHeight = (int)textHeight* 6 / 10;
            textItem->setPos(posX + textItem->boundingRect().height(),posY);

            QPixmap pixmap(staMaxHeight,staMaxHeight);
            pixmap.fill();
            QPen pen(curveInfo.m_lineColor);
            pen.setWidth(3);
            QPainter painter(&pixmap);
            painter.setPen(pen);
            if(!curveInfo.m_isHidden)
            {
                QBrush brush(curveInfo.m_lineColor);
                painter.setBrush(brush);
            }
            painter.drawRect(0, 0, pixmap.height(), pixmap.height());
            QGraphicsPixmapItem* pixmapItem = new QGraphicsPixmapItem(pixmap,this);
            pixmapItem->setPixmap(pixmap);
            pixmapItem->setPos(posX,posY + textHeight * 2 / 10);
            pixmapItem->setData(E_ITEM_TYPE,PSV::staLabelItem);
            pixmapItem->setData(E_CURVE_NAME,curveInfo.m_curveName);
            pixmapItem->setFlags(QGraphicsItem::ItemIsSelectable);
            pixmapItem->installSceneEventFilter(this);
            if(posX + 2 * m_staMaxWidth > m_chartRect.right())
            {
                posX = m_staStartPoint.x();
                posY += textItem->boundingRect().height() + getData(PSV::margin,3).toInt();
            }
            else
            {
                posX += m_staMaxWidth;
            }
        }
    }
    //TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
    //    QGraphicsRectItem *item = new QGraphicsRectItem(m_rect,this);//TTTTTTTTTTTTTTT
    //    item->setPen(QPen(QColor(Qt::red)));//TTTTTTTTTTTTTTT
    //TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
}