Exemplo n.º 1
0
/* List1-5
画像データ上の画素値を変更する
x,y 画素の座標
pix セットする画素値
*/
int setPixel(ImageData *img, int x, int y, Pixel *pix)
{
	int adr;  // 画素の画像上の位置
	int dep, val;
	BYTE *pixels;

	if (img == NULL) return -1;
	if (img->pixels == NULL) return -1;
	// 画像外の座標が指定されたらなにもしない
	if (x<0 || x >= img->width || y<0 || y >= img->height) {
		return 0;
	}
	dep = img->depth;
	adr = x + y*img->width;
	pixels = img->pixels;
	if (dep == 8) {
		pixels[adr] = correctValue(pix->r, PIXELMAX);
	}
	else if (dep == 24) {
		pixels += (adr * 3);
		(*pixels) = correctValue(pix->r, PIXELMAX);
		pixels++;
		(*pixels) = correctValue(pix->g, PIXELMAX);
		pixels++;
		(*pixels) = correctValue(pix->b, PIXELMAX);
	}
	else {
		return -1;
	}
	return 1;
}
Exemplo n.º 2
0
void FlatInput::onTextEdited() {
	QString was(_oldtext);
	correctValue(_kev, was);
	_oldtext = text();
	if (was != _oldtext) emit changed();
	updatePlaceholder();
}
Exemplo n.º 3
0
void CountryCodeInput::codeSelected(const QString &code) {
	QString old(text());
	setText('+' + code);
	_nosignal = true;
	correctValue(0, old);
	_nosignal = false;
	emit changed();
}
Exemplo n.º 4
0
/*
	データのセット

	pgm:PGMファイルポインタ
	x,y:座標
	dat:データ値
*/
int setPixData(PGMFILE *pgm,int x,int y,BYTE dat){

	if(x < 0 || y < 0) return 1;
	if(x > pgm->x || y > pgm->y) return 1;

	pgm->data[x+pgm->x*y] = correctValue(dat,pgm->max);
	return 0;
}
Exemplo n.º 5
0
void PhoneInput::addedToNumber(const QString &added) {
    setFocus();
    QString was(text());
    setText(added + text());
    setCursorPosition(added.length());
    correctValue(0, was);
    updatePlaceholder();
}
Exemplo n.º 6
0
void FlatTextarea::onDocumentContentsChanged() {
	if (_correcting) return;

	QString curText(getText());
	_correcting = true;
	correctValue(_oldtext, curText);
	_correcting = false;
	if (_oldtext != curText) {
		_oldtext = curText;
		emit changed();
		checkContentHeight();
	}
	updatePlaceholder();
	if (App::wnd()) App::wnd()->updateGlobalMenu();
}
Exemplo n.º 7
0
void FlatInput::keyPressEvent(QKeyEvent *e) {
	QString was(text());
	_kev = e;
	if (_customUpDown && (e->key() == Qt::Key_Up || e->key() == Qt::Key_Down)) {
		e->ignore();
	} else {
		QLineEdit::keyPressEvent(e);
	}

	if (was == text()) { // call correct manually
		correctValue(_kev, was);
		_oldtext = text();
		if (was != _oldtext) emit changed();
		updatePlaceholder();
	}
	if (e->key() == Qt::Key_Escape) {
		emit cancelled();
	} else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
		emit accepted();
	}
	_kev = 0;
}
Exemplo n.º 8
0
void PhoneInput::onChooseCode(const QString &code) {
    pattern = phoneNumberParse(code);
    if (!pattern.isEmpty() && pattern.at(0) == code.size()) {
        pattern.pop_front();
    } else {
        pattern.clear();
    }
    if (pattern.isEmpty()) {
        setPlaceholder(lang(lng_phone_ph));
    } else {
        QString ph;
        ph.reserve(20);
        for (int i = 0, l = pattern.size(); i < l; ++i) {
            ph.append(' ');
            ph.append(QString(QChar(0x2212)).repeated(pattern.at(i)));
        }
        setPlaceholder(ph);
    }
    correctValue(0, text());
    setPlaceholderFast(!pattern.isEmpty());
    updatePlaceholder();
}
Exemplo n.º 9
0
PortInput::PortInput(QWidget *parent, const style::flatInput &st, const QString &ph, const QString &val) : FlatInput(parent, st, ph, val) {
    correctValue(0, QString());
}
int main()
{
	std::ofstream outFile("fstreamtest.out", std::ios::out);
	outFile <<  "output data from fstreamtest" ;
	for(unsigned char a = 0; a < 255 ; ++a){
		outFile << a;
	}
	outFile.close();

	std::ifstream inFile;
	inFile.open("fstreamtest.out", std::ios::in | std::ios::binary );
	char a;
	unsigned char b;
	for(int i = 0 ; i < 28; ++i){
		inFile >> a;
	}
	while (!inFile.eof()){
		inFile.get(a);
		std::cout << "Read in character: " << (unsigned int)(unsigned char)a << " " << a << std::endl;
	}


	inFile.close();

	outFile.clear();
	outFile.open("fstreamtest2.out", std::ios::out);
	outFile.write("abcd", 4);
	outFile.put('e');
	outFile.write("fghi", 4);
	outFile.close();

	inFile.clear();
	inFile.open("fstreamtest2.out", std::ios::in | std::ios::binary);

	inFile >> a;
	if (a != 'a'){
		std::cout << "Error reading character a, was instead: " << a << std::endl;
	}
	inFile >> a;
	if (a != 'b'){
		std::cout << "Error reading character b, was instead: " << a << std::endl;
	}
	inFile >> a;
	if (a != 'c'){
		std::cout << "Error reading character c, was instead: " << a << std::endl;
	}
	inFile >> a;
	if (a != 'd'){
		std::cout << "Error reading character d, was instead: " << a << std::endl;
	}
	inFile >> a;
	if (a != 'e'){
		std::cout << "Error reading character e, was instead: " << a << std::endl;
	}
	inFile >> a;
	if (a != 'f'){
		std::cout << "Error reading character f, was instead: " << a << std::endl;
	}
	inFile >> a;
	if (a != 'g'){
		std::cout << "Error reading character g, was instead: " << a << std::endl;
	}
	inFile >> a;
	if (a != 'h'){
		std::cout << "Error reading character h, was instead: " << a << std::endl;
	}
	inFile >> a;
	if (a != 'i'){
		std::cout << "Error reading character i, was instead: " << a << std::endl;
	}
	inFile.close();
	inFile.clear();


	std::cout << "Now reading other input file to see what wonderful goodness we can discover" << std::endl;

	inFile.open("fstreamtest.input", std::ios::in | std::ios::binary );
	inFile.seekg(27);
	inFile.read(&a, 1);
	b = a;
	if(correctValue(27) != b){
		std::cout << "Read in invalid value.  Read in " << (int)b << ", expected " << (int)correctValue(27) << std::endl;
	}else{
		std::cout << "Character 27 read in correctly\n";
	}

	std::cout << "The following two lines should be identical\n";
	std::cout << "Current position: 28\n";
	std::cout << "Current position: " << inFile.tellg() << std::endl;

	inFile.seekg(1, std::ios::cur);
	inFile.read(&a, 1);
	b = a;
	if(correctValue(29) != b){
		std::cout << "Read in invalid value.  Read in " << (int)b << ", expected " << (int)correctValue(29) << std::endl;
	}else{
		std::cout << "Character 29 read in correctly\n";
	}

	std::cout << "The following two lines should be identical\n";
	std::cout << "Current position: 30\n";
	std::cout << "Current position: " << inFile.tellg() << std::endl;


	return 0;
}