예제 #1
0
void ULLineEditor::slotEditGroup ( QGraphicsItem * git )
{
	if ( editing )
		validateLine();
	editing = true;
	reedit = true;
// 	qDebug() << git->data ( 1 ).toString() << ":" << git->data ( 2 ).toUInt() ;
	QGraphicsItemGroup * gr = static_cast<QGraphicsItemGroup*> ( git );
	QList<QGraphicsItem*> lgr =  gr->children();
	double realwidth = 0;
	reeditPos = gr->scenePos();
	reedit_id = gr->data ( 2 ).toUInt();
	
	slotChangeBaseLine ( gr->data ( 3 ).toDouble() );
	slotChangeWidth ( gr->data ( 4 ).toDouble() );
	slotMoveCursor ( gr->data ( 5 ).toDouble() );
	slotLTR(gr->data( 6 ).toInt() == 1 ? Qt::Checked : Qt::Unchecked);
	
	gr->setPos ( 0.0, 0.0 );
	addItem ( gr );
	destroyItemGroup ( gr );
	
	for ( uint i = 0; i < lgr.count(); ++i )
	{
// 		lgr[i]->clearFocus();
		lgr[i]->setSelected ( false );
	}


// 	adjust();
	glyphs.clear();
	glyphs = PageBuffer::getInstance()->take ( reedit_id, false );
}
예제 #2
0
/*
 *Reads level settings file
 */
void readLevelSettingsFile(char *file)	{
	FILE *fp;
    char letter;
	int wordCount = 1;
   	char *currentLine; 
	int currSize = 0;
	if((fp = fopen(file,"r")) != NULL)	{
		while((letter = getc(fp)) != EOF)	{
			if(letter == ' ')	{
				wordCount++;
			}
			currentLine = expandCBuffer(currentLine, currSize);
			if(letter == '\n')	{
				currentLine[currSize] = ENDOFSTRING;
				validateLine(currentLine,wordCount);
				free(currentLine);
				currentLine = NULL;
				wordCount = 1;
				currSize = 0;
			} else {
				currentLine[currSize] = letter;
				currSize++;
			}
		}	
	}	
}
예제 #3
0
int readLinesFromFile(char * filename){
	FILE *file = fopen(filename, "r");
	int success =0;

	if (file != NULL){
		char line [ MAXSIZE ]; /* or other suitable maximum line size */
		while (fgets(line, sizeof line, file) != NULL){
			if (strlen(line) > 1){
				//validate the line before any further processing
				if(validateLine(line)==1)
				{
					//remove the '{' and '}'
					line[0] = ' ';
					line[strlen(line) - 2] = '\0';
					//remove the extra spaces
					char *ch = line;
					char *p1 = ch;
					char *p2 = ch;
					p1 = ch;
					while (*p1 != 0){
						if (isspace(*p1) || (*p1) == '\"'){
							++p1;
						}
						else
							*p2++ = *p1++;
					}
					*p2 = 0;

					//now the string without extra spaces is stored in 'ch'
					//printf("Splitting string \"%s\" into tokens:\n", ch);
					char * keyV[13];

					char *str = line;
					char * pch;
					pch = strtok(str, ",");
					int i = 0;
					while (pch != NULL){
						keyV[i] = pch;
						pch = strtok(NULL, ",");
						i++;
					}

					//now tokenize them further
					//now each of those tokens is a key-value pair
					char *values[26];
					int k, x;
					x = 0;
					for (k = 0; k < i; k++){
						char *str2 = keyV[k];
						char * pch2;
						pch2 = strtok(str2, ":");
						while (pch2 != NULL){
							values[x++] = pch2;
							pch2 = strtok(NULL, ":");
						}
					}
					//call function to insert to db with the cprrect params
					success = storeToDB(values[1], values[3], values[5], values[7], values[9], values[11], values[13], values[15], values[17], values[19], values[21], values[23],values[25]);
					memset(line, 0, sizeof (line));
					if(success==0){//if it fails any where, break here
						break;
					}
				}
				else {
					printf("Not a valid json string\n");
				}
			}
		}
		fclose(file);
	}
	else{
		perror(filename); /* why didn't the file open? */
	}
	return success;
}
예제 #4
0
void ULLineEditor::keyPressEvent ( QKeyEvent * event )
{
	if ( event->key() == Qt::Key_Return )
	{
		validateLine();
		return;
	}
	if ( event->key() == Qt::Key_G && event->modifiers().testFlag ( Qt::ControlModifier ))
	{
		pushLastGlyphAtFirstOfNextLine();
		return;
	}
	if ( event->key() == Qt::Key_P&& event->modifiers().testFlag ( Qt::ControlModifier ) )
	{
		insertAtLastFirstGlyphOfNextLine();
		return;
	}
	if ( event->key() == Qt::Key_G && event->modifiers().testFlag ( Qt::ShiftModifier ))
	{
		insertAtFirstLastGlyphFromPrevLine();
		pushLastGlyphAtFirstOfNextLine();
		return;
	}
	if ( event->key() == Qt::Key_P&& event->modifiers().testFlag ( Qt::ShiftModifier ) )
	{
		pushFirstGlyphAtLastOfPrevLine();
		insertAtLastFirstGlyphOfNextLine();
		return;
	}
	if ( event->key() == Qt::Key_G )
	{
		pushFirstGlyphAtLastOfPrevLine();
		return;
	}
	if ( event->key() == Qt::Key_P )
	{
		insertAtFirstLastGlyphFromPrevLine();
		return;
	}
	

	QList<QGraphicsItem*> it = selectedItems();
	if ( it.isEmpty() && event->modifiers().testFlag ( Qt::ControlModifier )  && event->modifiers().testFlag ( Qt::ShiftModifier ) )
	{
		switch ( event->key() )
		{
			case Qt::Key_Right : slotJustifyItsVeryBadInterletter ( 0.005 );
				break;
			case Qt::Key_Left : slotJustifyItsVeryBadInterletter ( -0.005 );
				break;
			default:break;
		}

	}
	else if ( it.isEmpty() && event->modifiers().testFlag ( Qt::ControlModifier ) )
	{
		switch ( event->key() )
		{
			case Qt::Key_Right : slotJustifyBlanks ( 0.01 );
				break;
			case Qt::Key_Left : slotJustifyBlanks ( -0.01 );
				break;
			default:break;
		}

	}
	else if ( it.isEmpty() )
	{
		QGraphicsView * v = views().first();
		switch ( event->key() )
		{
			case Qt::Key_Up: v->scale ( 1.2,1.2 );
				break;
			case Qt::Key_Down : v->scale ( 1.0/1.2,1.0/1.2 );
				break;
			case Qt::Key_Right : slotJustifyBlanks ( 0.1 );
				break;
			case Qt::Key_Left : slotJustifyBlanks ( -0.1 );
				break;
			default:break;
		}

	}
	else
	{
        if ( (event->key() == Qt::Key_Delete) || (event->key() == Qt::Key_Backslash) )
		{
			for ( uint i = 0; i < it.count();++i )
			{
				removeItem ( it[i] );
				glyphs.removeAll ( static_cast<ULGlyphItem*> ( it[i] ) );
			}
		}
		else if ( event->key() == Qt::Key_E )
		{
			wantEdit ( static_cast<ULGlyphItem*> ( it.first() ) );
		}

		else
		{
			for ( uint i = 0; i < it.count();++i )
				static_cast<ULGlyphItem*> ( it[i] )->keyForeign ( event );

		}
// 		previewLine();
	}
}