int setText(int posX, int posY, char *text, short color){ char* r, k[100]; int y = posY; strcpy(k, text); for( r = strtok(k, "\n"); r != NULL; r = strtok(NULL, "\n")){ setTextLine(posX, y, r, color); y++; } return y - posY; }
void caCalc::setValue(QRect value) { setTextLine("QRect=ok"); // emit signal when requested if(thisEventSignal == onFirstChange) { if(!eventFired) { emit emitSignal(value); } eventFired = true; } else if(thisEventSignal == onAnyChange) { emit emitSignal(value); } thisValue =0; }
void caCalc::setValue(double value) { char asc[MAX_STRING_LENGTH], format[20]; int precision; if((precision = getPrecision()) >= 0) { sprintf(format, "%s.%dlf", "%", precision); } else { sprintf(format, "%s.%dle", "%", -precision); } snprintf(asc, MAX_STRING_LENGTH, format, value); setTextLine(QString(asc)); // emit signal when requested if(thisEventSignal == onFirstChange) { if(!eventFired) { emit emitSignal((int) value); emit emitSignal(value); emit emitSignal((bool) value); } eventFired = true; } else if(thisEventSignal == onAnyChange) { emit emitSignal((int) value); emit emitSignal(value); emit emitSignal((bool) value); } else if(thisEventSignal == TriggerZeroToOne) { if((qRound(thisValue) == 0) && (qRound(value) == 1)) { emit emitSignal((int) value); emit emitSignal(value); emit emitSignal((bool) value); } } else if(thisEventSignal == TriggerOneToZero) { if((qRound(thisValue) == 1) && (qRound(value) == 0)) { emit emitSignal((int) value); emit emitSignal(value); emit emitSignal((bool) value); } } thisValue =value; //printf("%s emit change value %f\n", qasc(objectName()), value); // only in case of a change where no calculation takes places, will we update // the data container with the actual value if(thisCalc.trimmed().size() == 0) emit changeValue(value); }
void caCalc::setValue(double value) { char asc[1024], format[20]; int precision; if((precision = getPrecision()) >= 0) { sprintf(format, "%s.%dlf", "%", precision); } else { sprintf(format, "%s.%dle", "%", -precision); } sprintf(asc, format, value); setTextLine(QString(asc)); // emit signal when requested if(thisEventSignal == onFirstChange) { if(!eventFired) emit emitSignal(); eventFired = true; } else if(thisEventSignal == onAnyChange) { emit emitSignal(); } }
void caCalc::setValue(QString value) { setTextLine(value); }
int main(void) { int length = 0, height = 0, i, k, lowVal = -1000, highVal = -1000; char entred[100] = ""; do{ drawField(COLS/4, ROWS/4, COLS/2, ROWS/2); k = setText(COLS/4 + 2, 3*ROWS/8, "Enter matrix length [1..9]\n& height [1..9]\nparting values with coma:", FIELD_COLOR); getText(COLS/4 + 2, 3*ROWS/8 + k + 1, entred, FIELD_BACKGROUND, FORE_BLACK); getPartiedInts(entred, &length, &height); if((length > 9 || length < 1) || (height > 9 || height< 1)){ setTextLine(COLS/4 + 2, 3*ROWS/8 + k + 4, "Invalid input!", FIELD_BACKGROUND | FOREGROUND_RED); Sleep(1500); } }while((length > 9 || length < 1) || (height > 9 || height< 1)); do{ drawField(COLS/4, ROWS/4, COLS/2, ROWS/2); k = setText(COLS/4 + 2, 3*ROWS/8, "Enter matrix random values diapason\nparting left & right bounds with coma:", FIELD_COLOR); getText(COLS/4 + 2, 3*ROWS/8 + k + 1, entred, FIELD_BACKGROUND, FORE_BLACK); getPartiedInts(entred, &lowVal, &highVal); if((lowVal > highVal) || (highVal > 999) || (lowVal < -999)){ setTextLine(COLS/4 + 2, 3*ROWS/8 + k + 4, "Invalid input!", FIELD_BACKGROUND | FOREGROUND_RED); Sleep(1500); } }while((lowVal > highVal) || (highVal > 999) || (lowVal < -999)); int matr[height][length], mcpy[length][height], isTurned = 0, toSwitch = 0, firstToSwap, secondToSwap; int cX, cY, val, row; fillRand(length, height, matr, lowVal, highVal); int y = 2 + height*2; short color = FIELD_COLOR, toClean = 0, isSwaped = 0, help = 0, toPickOutCols = 0, toYellow = 0, toPickOutRow = 0; char * g, cpy[100]; COORD swaped[2]; clearScr(); drawField(0, 0, COLS - 1, y); while(1){ y = isTurned ? (2 + length*2) : (2 + height*2); if(toClean){ toClean = 0; clean(y); } printMatr(length, height, matr, isTurned, toSwitch, color); color = FIELD_COLOR; if(isSwaped){ pickOut(length, height, matr, isTurned, swaped[0], BACKGROUND_GREEN); pickOut(length, height, matr, isTurned, swaped[1], BACKGROUND_RED); isSwaped = 0; } else if(toYellow){ printEl(length, height, matr, isTurned, cX - 1, cY - 1, FORE_YELLOW | FIELD_BACKGROUND | FOREGROUND_INTENSITY); toYellow = 0; } else if(toPickOutRow){ pickOutRow(length, height, matr, isTurned, row - 1, BACKGROUND_GREEN); toPickOutRow = 0; } else if(toPickOutCols){ pickOutCol(length, height, matr, isTurned, firstToSwap - 1, BACKGROUND_GREEN); pickOutCol(length, height, matr, isTurned, secondToSwap - 1, BACKGROUND_RED); toPickOutCols = 0; } toSwitch = 0; setTextLine(1, y + 2, "Enter your command:", FORE_WHITE); do{ getText(1, y + 3, entred, BACK_BLACK, FOREGROUND_GREEN); }while(entred[0] == '\0'); strcpy(cpy, entred); g = strtok(cpy, " "); if(!g) g = "\n"; for(i = 2; i < COLS; i++){ moveCursor(i, y + 3); putchar(' '); } if(!strcmp(entred, "help")){ helpComm(y + 5); help = 1; }else if(!strcmp(entred, "clear all")){ clearMatr(length, height, matr); color = FIELD_BACKGROUND | FORE_YELLOW | FOREGROUND_INTENSITY; }else if(!strcmp(g, "random")){ lowVal = -1000; highVal = -1000; char cpy1[100]; for(i = 0; cpy[i + 7] != '\0'; i++){ cpy1[i] = cpy[i + 7]; } cpy1[i] = '\0'; getPartiedInts(cpy1, &lowVal, &highVal); if((lowVal > highVal) || (highVal > 999) || (lowVal < -999)){ invalidInput(y); }else{ fillRand(length, height, matr, lowVal, highVal); color = FIELD_BACKGROUND | FORE_YELLOW | FOREGROUND_INTENSITY; } }else if(!strcmp(g, "set")){ cX = -1; cY = -1; val = -1000; char cpy1[100], *l; for(i = 0; cpy[i + 4] != '\0'; i++){ cpy1[i] = cpy[i + 4]; } cpy1[i] = '\0'; getPartiedInts(cpy1, &cX, &cY); l = strtok(cpy1, ":"); l = strtok(NULL, ":"); if(l != NULL){ val = atoi(l); } if(!isTurned){ if(cX > length || cX <= 0 || cY > height || cY <= 0 || val > 999 || val < -999){ invalidInput(y); }else{ matr[cY - 1][cX - 1] = val; toYellow = 1; } }else{ if(cX > height || cX <= 0 || cY > length || cY <= 0 || val > 999 || val < -999){ invalidInput(y); }else{ matr[cX - 1][cY - 1] = val; toYellow = 1; } } }else if(!strcmp(entred, "print upright")){ isTurned = !isTurned; toSwitch = 1; }else if(!strcmp(entred, "middle value")){ double mid = countMiddle(length, height, matr); setTextColor(FORE_WHITE); moveCursor(5, y + 4); printf("middle value: "); setTextColor(FORE_YELLOW); moveCursor(22, y + 4); printf("%f ", mid); help = 1; }else if(!strcmp(g, "sum")){ int sum; row = -1; g = strtok(NULL, " "); if(g != NULL && !strcmp(g, "in")){ g = strtok(NULL, " "); if(g != NULL && !strcmp(g, "row")){ g = strtok(NULL, " "); if(g != NULL) row = atoi(g); } } if(row < 0 || row > (isTurned ? length : height)) invalidInput(y); else{ sum = sumInRow(length, height, matr, isTurned, row -1); toPickOutRow = 1; setTextColor(FORE_WHITE); moveCursor(5, y + 4); printf("sum in %dth row: ", row); setTextColor(FORE_YELLOW); moveCursor(22, y + 4); printf("%d ", sum); help = 1; } }else if(!strcmp(entred, "swap 1")){ swapMinMax(length, height, matr, isTurned, 1, swaped); isSwaped = 1; }else if(!strcmp(entred, "swap 2")){ swapMinMax(length, height, matr, isTurned, 0, swaped); isSwaped = 1; }else if(!strcmp(entred, "swap cols")){ swapCols(length, height, matr, isTurned, &firstToSwap, &secondToSwap); toPickOutCols = 1; }else if(!strcmp(entred, "clean workspace") && help){ toClean = 1; help = 0; }else if(!strcmp(entred, "f**k you")){ clearScr(); setTextLine(0, 0, "GO F**K YOURSELF!", FOREGROUND_RED | FOREGROUND_INTENSITY); setTextColor(FORE_WHITE); return EXIT_FAILURE; }else if(!strcmp(entred, "exit")){ clearScr(); setTextColor(FORE_WHITE); return EXIT_SUCCESS; }else{ invalidInput(y); } } return EXIT_SUCCESS; }
void invalidInput(int y){ setTextLine(5, y + 4, "Invalid input! ", FOREGROUND_RED); Sleep(1500); setTextLine(5, y + 4, " ", 0); }
void helpComm(int y){ short yellow = FORE_YELLOW; short x = 3; setTextLine(x, y, "clear all", yellow); setTextLine(COLS/3, y, "to set all elements to 0", FORE_WHITE); y++; setTextLine(x, y, "random %min%, %max%", yellow); setTextLine(COLS/3, y, "to fill elements with random value from min to max", FORE_WHITE); y++; setTextLine(x, y, "set %x%, %y% : %val%", yellow); setTextLine(COLS/3, y, "to set (x, y) element to val", FORE_WHITE); y++; setTextLine(x, y, "print upright", yellow); setTextLine(COLS/3, y, "to print matrix upright", FORE_WHITE); y++; setTextLine(x, y, "middle value", yellow); setTextLine(COLS/3, y, "to show middle arithmetics value of all elements", FORE_WHITE); y++; setTextLine(x, y, "sum in row %row%", yellow); setTextLine(COLS/3, y, "to show sum value of elements in row %row%", FORE_WHITE); y++; setTextLine(x, y, "swap 1", yellow); setTextLine(COLS/3, y, "to swap first min with last max", FORE_WHITE); y++; setTextLine(x, y, "swap 2", yellow); setTextLine(COLS/3, y, "to swap last min with first max", FORE_WHITE); y++; setTextLine(x, y, "swap cols", yellow); setTextLine(COLS/3, y, "to swap column with max sum with column with min sum", FORE_WHITE); y++; setTextLine(x, y, "clean workspace", yellow); setTextLine(COLS/3, y, "to clean space under the field", FORE_WHITE); y++; setTextLine(x, y, "exit", yellow); setTextLine(COLS/3, y, "to exit the program", FORE_WHITE); }
caLineEdit::caLineEdit(QWidget *parent) : QLineEdit(parent), FontScalingWidget(this) { // we want this font, while nice and monospace QFont font("Lucida Sans Typewriter"); // if this font does not exist then try a next one QFontInfo info(font); //font.setStyleStrategy(QFont::NoAntialias); QString family = info.family(); //printf("got font %s\n", qasc(family)); if(!family.contains("Lucida Sans Typewriter")) { QFont newfont("Monospace"); // not very nice, while a a dot inside the zero to distinguish from o newfont.setStyleHint(QFont::TypeWriter); setFont(newfont); } else { setFont(font); } isShown = false; oldStyle = ""; thisStyle = ""; setColorMode(Default); setAlarmHandling(onForeground); thisFormatC[0] = '\0'; setUnitsEnabled(false); thisBackColor = Qt::gray; thisForeColor = Qt::black; oldBackColor = Qt::black; oldForeColor = Qt::gray; thisFrameColor = Qt::black; oldFrameColor = Qt::gray; thisFramePresent = false; thisFrameLineWidth = 0; oldFrameLineWidth = 0; Alarm = 0; // default colors will be defined in my event handler by taking them from the palette defined by stylesheet definitions //defBackColor = QColor(255, 248, 220, 255); //defForeColor = Qt::black; defSelectColor = Qt::red; // this does not appear in the palette setPrecisionMode(Channel); setLimitsMode(Channel); setPrecision(0); setFormatType(decimal); setFormat(0); setMinValue(0.0); setMaxValue(1.0); setFrame(false); keepText = ""; unitsLast = ""; setTextLine(keepText); setValueType(false); setFontScaleModeL(WidthAndHeight); newFocusPolicy(Qt::NoFocus); d_rescaleFontOnTextChanged = true; installEventFilter(this); }