Exemple #1
0
bool SVGPlotter::DrawAxis(FILE *fout) {
  char text[1000], format[1000];
  fprintf(fout, "\n  <rect class=\"axis\" x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" />\n", width, height);

  int xd = (int)(LOG_B((xMax-xMin), 10.0));
  float xTicSpacing = pow(10.0f, xd);
  if((xMax-xMin) / xTicSpacing < 5) { xd--; xTicSpacing /= 2; }
  float x = ceil(xMin/xTicSpacing)*xTicSpacing;
  while(x <= xMax) {
    if(xd >= 0) sprintf(text, "%d", (int)x);
    else { sprintf(format, "%%.%df", -xd); sprintf(text, format, x); }
    fprintf(fout, "  <line class=\"tic\" x1=\"%f\" y1=\"%d\" x2=\"%f\" y2=\"%d\" />", (x-xMin)*sx, height, (x-xMin)*sx, height+ticLength);
    fprintf(fout, "  <text class=\"xTic\" x=\"%f\" y=\"%d\" text-anchor=\"middle\" >%s</text>", (x-xMin)*sx, height+ticLength+1, text);
    x += xTicSpacing;
  }
  fprintf(fout, "\n");

  int yd = (int)(LOG_B((yMax-yMin), 10.0));
  float yTicSpacing = pow(10.0f, yd);
  if((yMax-yMin) / yTicSpacing < 5) { yd--; yTicSpacing /= 2; }
  float y = ceil(yMin/yTicSpacing)*yTicSpacing;
  while(y <= yMax) {
    if(yd >= 0) sprintf(text, "%d", (int)y);
    else { sprintf(format, "%%.%df", -yd); sprintf(text, format, y); }
    fprintf(fout, "  <line class=\"tic\" x1=\"%d\" y1=\"%f\" x2=\"%d\" y2=\"%f\" />", 0, height-(y-yMin)*sy, -ticLength, height-(y-yMin)*sy);
    fprintf(fout, "  <text class=\"yTic\" x=\"%d\" y=\"%f\" text-anchor=\"end\" >%s</text>", -ticLength-1, height-(y-yMin)*sy, text);
    y += yTicSpacing;
  }
  fprintf(fout, "\n");

  if(title) fprintf(fout, "  <text class=\"title\" text-anchor=\"middle\" x=\"%d\" y=\"%d\" >%s</text>\n", width/2, -4, title);
  if(xLabel) fprintf(fout, "  <text class=\"xLabel\" text-anchor=\"middle\" x=\"%d\" y=\"%d\" >%s</text>\n", width/2, height+ticLength+1+axisLabelGap, xLabel);
  if(yLabel) fprintf(fout, "  <text class=\"yLabel\" transform=\"rotate(-90)\" x=\"%d\" y=\"%d\" >%s</text>\n", -height/2, -ticLength-1-axisLabelGap, yLabel);

  return true;
}
int showMessageBox( QWidget* parent, const QString& strMessage, const QString& strTitle,
                    QMessageBox::Icon icon, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defButton )
{
    QString strLog = strMessage;
    strLog.replace( "\r", " " );
    strLog.replace( "\n", " " );
    LOG_I( strLog );

    QString strStyle =
        "QWidget {"
            "background-color: rgb(225, 225, 225);"
        "}"
        "QPushButton {"
            "border: 1px solid #8f8f91;"
            "border-radius: 6px;"
            "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #f6f7fa, stop: 1 #dadbde);"
            "min-width: 80px;"
        "}"

        "QPushButton:pressed {"
            "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #dadbde, stop: 1 #f6f7fa);"
        "}"

        "QPushButton:flat {"
            "border: none;"
        "}"

        "QPushButton:focus {"
            "outline: none;"
        "}"

        "QPushButton:default {"
            "border-color: rgb(90, 129, 129);"
        "}";

    s_bShowMessageBox = true;
    QMessageBox msgBox(icon, strTitle, strMessage, buttons, parent);
    msgBox.setDefaultButton(defButton);
    //msgBox.setStyleSheet(strStyle);
    msgBox.setWindowModality( Qt::WindowModal );
    msgBox.setModal( true );

#define MAIN "MAIN"
    QLangRes& res = QLangManager::getResource();
    msgBox.setButtonText(QMessageBox::Ok, res.getResString("MESSAGEBOX", "BTN_CAPTION_OK"));
    msgBox.setButtonText(QMessageBox::Cancel, res.getResString("MESSAGEBOX", "BTN_CAPTION_CANCEL"));
    msgBox.setButtonText(QMessageBox::Yes, res.getResString("MESSAGEBOX", "BTN_CAPTION_YES"));
    msgBox.setButtonText(QMessageBox::No, res.getResString("MESSAGEBOX", "BTN_CAPTION_NO"));
    QAbstractButton* pBtn = msgBox.button(QMessageBox::Yes);
    if( pBtn )
        pBtn->setShortcut( QKeySequence(Qt::Key_Y) );
    pBtn = msgBox.button(QMessageBox::No);
    if( pBtn )
        pBtn->setShortcut( QKeySequence(Qt::Key_N) );

    QFont fnt(msgBox.font());
    fnt.setPointSize(fnt.pointSize()+1);
    msgBox.setFont(fnt);
    s_pShowedMessageBox = &msgBox;
    int nRet = msgBox.exec();

    s_pShowedMessageBox = NULL;
    s_bShowMessageBox = false;

    switch (nRet)
    {
    case QMessageBox::Yes:
        LOG_B( "Yes" );
        break;
    case QMessageBox::No:
        LOG_B( "No" );
        break;
    case QMessageBox::Ok:
        LOG_B( "OK" );
        break;
    case QMessageBox::Cancel:
        LOG_B( "Cancel" );
        break;
    }
    return nRet;
}