Ejemplo n.º 1
0
// checks user input
void WMain::check() {
	if(mode!=testMode) return;

	if(!answered) {
		if(currentEntry->check(answerEdit->text(), intoforeign, ignoreSynonyms, caseSensitive)) {
			questionLabel->setText(tr("Good!"));
			answerLabel->clear();
			if(hintsize < 2) {
				currentEntry->wordstatus = true;
				countdown--;
				testQueue.dequeue();
			}
			else {
				testQueue.enqueue(currentEntry);
				testQueue.dequeue();
			}
		}
		else {
			questionLabel->setText(tr("Wrong"));
			answerLabel->setText(tr("%1 - %2")
				.arg(processToNice(intoforeign?currentEntry->word:currentEntry->translation, "\n"))
				.arg(processToNice(intoforeign?currentEntry->translation:currentEntry->word, "\n")));
			testQueue.enqueue(currentEntry);
			testQueue.dequeue();
		}
		submitWordButton->setText(tr("Next"));
		answered = true;
		cDocument->filechanged = true;
		updateStatusbar();
	}
	else {
		if(testQueue.empty()) {
			endTest(true, tr("All words learned!"));
			return;
		}
		currentEntry = testQueue.head();
		
		// process question string
		QString question = intoforeign ? currentEntry->word : currentEntry->translation;
		question = processToNice(question, "\n");
		
		// append speech part
		if(currentEntry->sp != spNone) question.append("("+currentEntry->spToString()+")");

		// end
		questionLabel->setText(question);
		answerLabel->clear();
		answered = false;
		hintsize=1;
		submitWordButton->setText(tr("OK"));
		answerEdit->clear();
		answerEdit->setFocus();
		updateStatusbar();
	}
}
Ejemplo n.º 2
0
// starts test
void WMain::test(unsigned howmany, bool intoforeign, bool include, bool ignoreSynonyms) {
	// prepare test variables
	setMode(testMode);
	this->howmany = howmany;
	this->countdown = howmany;
	this->intoforeign = intoforeign;
	this->include = include;
	this->ignoreSynonyms = ignoreSynonyms;
	this->answered = true;
	this->hintsize = 1;
	this->caseSensitive = QSettings("dicto.ini", QSettings::IniFormat).value("testing/case_sensitive").value<bool>();
	
	// reset all words to unpassed
	for(unsigned i=0; i<dictionarySize(); i++) cDocument->dictionary[i].passed = false;
	
	// prepare test queue
	testQueue.clear();
	int i;
	for(i=0; i<howmany; i++) {
		int newWord = pickWord(include);
		if(newWord == -1) {
			setMode(normalMode);
			updateStatusbar();
			break;
		}
		testQueue.enqueue(&cDocument->dictionary[newWord]);
		cDocument->dictionary[newWord].passed = true;
	}
	if(testQueue.empty()) { // not supposed to happen
		endTest(true, tr("No words match your criteria"));
		return;
	}
	check();
}
Ejemplo n.º 3
0
// displays message and ends test 
void WMain::endTest(bool display, QString message) {
	if(display) {
		QMessageBox::information(this, tr("Test ended"), message);
	}
	setMode(normalMode);
	updateStatusbar();
	return;
}
Ejemplo n.º 4
0
// creates new file
void WMain::newfile() {
	if(cDocument->filechanged) {
		int userAnswer = askUser(tr("File has been changed. Save?"));
		if(userAnswer == 2) saveFileAction();
		else if(userAnswer == 1) return;
	}
	
	delete cDocument;
	cDocument = new CDocument;
	updateList();
	updateStatusbar();
}
Ejemplo n.º 5
0
static gint menuImageFramerate_CB(GtkWidget *widget, gpointer data)
{
	GtkWidget *dialog;
	GtkWidget *hbox;
	GtkWidget *stock;

	GtkWidget *label;
	GtkWidget *spinner;
	GtkAdjustment *spinner_adj;
	gint response;

	dialog = gtk_dialog_new_with_buttons ("New Frame Rate",
					GTK_WINDOW (mainWindow),
					GTK_DIALOG_MODAL,
					GTK_STOCK_OK,
					GTK_RESPONSE_OK,
                    GTK_STOCK_CANCEL,
                    GTK_RESPONSE_CANCEL,
					NULL);

	hbox = gtk_hbox_new (FALSE, 8);
	gtk_container_set_border_width (GTK_CONTAINER (hbox), 8);
	stock = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
	gtk_box_pack_start (GTK_BOX (hbox), stock, FALSE, FALSE, 0);
	label = gtk_label_new_with_mnemonic ("Insert new frame rate (in mSec):");
	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
	spinner_adj = (GtkAdjustment *) gtk_adjustment_new (_options.refreshTime, 0.0, 1000.0, 1.0, 5.0, 5.0);
	spinner = gtk_spin_button_new (spinner_adj, 1.0, 0);
	gtk_box_pack_start (GTK_BOX (hbox), spinner, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 0);
	
	gtk_widget_show_all (hbox);
	response = gtk_dialog_run (GTK_DIALOG (dialog));

	if (response == GTK_RESPONSE_OK)
	{
		_options.refreshTime = (int) gtk_spin_button_get_value (GTK_SPIN_BUTTON(spinner));
		gtk_timeout_remove (_options.refreshTime);
		timeout_ID = gtk_timeout_add (_options.refreshTime, timeout_CB, NULL);
		updateStatusbar(GTK_STATUSBAR (statusbar));
	}

	gtk_widget_destroy (dialog);
		
	return (TRUE);
}
Ejemplo n.º 6
0
//-------------------------------------------------
// Main Window 
//-------------------------------------------------
GtkWidget* createMainWindow(void)
{
	GtkRequisition actualSize;
	GtkWidget* window;
	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "YARP GTK Image Viewer");
	gtk_window_set_default_size(GTK_WINDOW (window), _options.windWidth, _options.windHeight); 
	gtk_window_set_resizable (GTK_WINDOW (window), TRUE);
    // When the window is given the "delete_event" signal (this is given
	// by the window manager, usually by the "close" option, or on the
	// titlebar), we ask it to call the delete_event () function
	// as defined above. The data passed to the callback
	// function is NULL and is ignored in the callback function.
    g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (delete_event), NULL);
    // Box for main window
	GtkWidget *box;
	box = gtk_vbox_new (FALSE, 0); // parameters (gboolean homogeneous_space, gint spacing);
    gtk_container_add (GTK_CONTAINER (window), box);
	// MenuBar for main window
	menubar = createMenubar();
	gtk_box_pack_start (GTK_BOX (box), menubar, FALSE, TRUE, 0); // parameters (GtkBox *box, GtkWidget *child, gboolean expand, gboolean fill, guint padding);
	gtk_widget_size_request(menubar, &actualSize);
	// Drawing Area : here the image will be drawed
	da = gtk_drawing_area_new ();
	g_signal_connect (da, "expose_event", G_CALLBACK (expose_CB), NULL);
	if (_options.outputEnabled == 1)
	{
		g_signal_connect (da, "button_press_event", G_CALLBACK (clickDA_CB), NULL);
		// Ask to receive events the drawing area doesn't normally subscribe to
		gtk_widget_set_events (da, gtk_widget_get_events (da) | GDK_BUTTON_PRESS_MASK);
	}
	gtk_box_pack_start(GTK_BOX(box), da, TRUE, TRUE, 0);
	// StatusBar for main window
	statusbar = gtk_statusbar_new ();
	updateStatusbar(GTK_STATUSBAR (statusbar));
	gtk_box_pack_start (GTK_BOX (box), statusbar, FALSE, TRUE, 0);
	gtk_widget_size_request(statusbar, &actualSize);
	_occupiedHeight += 2*(actualSize.height);

	frame = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, _options.windWidth, _options.windHeight);
	// TimeOut used to refresh the screen
	timeout_ID = gtk_timeout_add (_options.refreshTime, timeout_CB, NULL);
	
	return window;
}
Ejemplo n.º 7
0
// sets main window mode
void WMain::setMode(Mode mode) {
	switch(mode) {

		case normalMode :
			searchBar->show();
			listWidget->show();
			questionLabel->hide();
			answerLabel->hide();
			answerEdit->hide();
			submitWordButton->hide();
			cancelTestButton->hide();
			examStatusLabel->hide();
			tableWidget->hide();
			submitExamButton->hide();
			cancelExamButton->hide();

			progressBar->show();

			setActions(true);

			this->mode=normalMode;
			updateStatusbar();
			break;

		case disabledMode :
			this->setEnabled(false);
			this->mode=disabledMode;
			break;

		case enabledMode :
			this->setEnabled(true);
			setMode(normalMode);
			break;

		case testMode :
			searchBar->hide();
			listWidget->hide();
			questionLabel->show();
			answerLabel->show();
			answerEdit->show();
			answerEdit->clear();
			submitWordButton->show();
			cancelTestButton->show();
			examStatusLabel->hide();
			tableWidget->hide();
			submitExamButton->hide();
			cancelExamButton->hide();

			progressBar->show();

			setActions(false);

			this->mode=testMode;
			break;
		case examMode :
			searchBar->hide();
			listWidget->hide();
			questionLabel->hide();
			answerLabel->hide();
			answerEdit->hide();
			submitWordButton->hide();
			cancelTestButton->hide();
			examStatusLabel->show();
			tableWidget->show();
			tableWidget->setColumnWidth(0, (tableWidget->width())/2);
			submitExamButton->show();
			cancelExamButton->show();
			cancelExamButton->setEnabled(true);

			progressBar->hide();

			setActions(false);			

			this->mode=examMode;
			break;
	}
}
Ejemplo n.º 8
0
// WMain constructor
WMain::WMain(QWidget *parent) : QMainWindow(parent) {
	// set window properties
	resize(400, 400);
	setWindowTitle(tr("dicto"));
	setWindowIcon(QIcon(ICON));
	centerWidgetOnScreen(this);
	setAttribute(Qt::WA_DeleteOnClose);
	
	// set random seed
	srand(time(0));
	
	//create widgets
	mainWidget = new QWidget(this);
	setCentralWidget(mainWidget);
	searchBar = new QLineEdit;
	listWidget = new QListWidget;
	questionLabel = new QLabel(tr("Test!"), this);
	answerLabel = new QLabel(tr("Answer"), this);
	answerEdit = new QLineEdit;
	submitWordButton = new QPushButton(tr("OK"), this);
	cancelTestButton = new QPushButton(tr("End test"), this);
	examStatusLabel  =  new QLabel;
	tableWidget = new QTableWidget;
	submitExamButton = new QPushButton(tr("Submit exam"), this);
	cancelExamButton = new QPushButton(tr("Cancel exam"), this);
	progressBar = new QProgressBar;
	createMenus();
	createTrayIcon();

	// initialize widgets
	//QFont font;
	//font.setPointSize(20);
	//font.setBold(true);
	//questionLabel->setFont(font);
	//questionLabel->setTextFormat(Qt::RichText);
	questionLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
	questionLabel->setWordWrap(true);
	QFont questionFont;
	questionFont.setBold(true);
	questionLabel->setFont(questionFont);
	answerLabel->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
	answerLabel->setWordWrap(true);
	tableWidget->setColumnCount(2);
	tableWidget->horizontalHeader()->hide();
	tableWidget->verticalHeader()->hide();
	tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	tableWidget->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
	tableWidget->horizontalHeader()->setStretchLastSection(true);
	progressBar->setMinimum(0);
	
	// initialize members
	cDocument = new CDocument ;
	printer = new QPrinter;
	mode = normalMode;
	parent = 0;
	maxRecentFiles = QSettings("dicto.ini", QSettings::IniFormat).value("general/max_recent_files").value<int>();
	
	// add layout
	QVBoxLayout *mainLayout=new QVBoxLayout(mainWidget);
		QVBoxLayout *normalLayout=new QVBoxLayout();
			normalLayout->addWidget(searchBar);
			normalLayout->addWidget(listWidget);
		mainLayout->addLayout(normalLayout);
		QVBoxLayout *testLayout=new QVBoxLayout();
			testLayout->addWidget(questionLabel);
			testLayout->addWidget(answerLabel);
			testLayout->addWidget(answerEdit);
			testLayout->addWidget(submitWordButton);
			testLayout->addWidget(cancelTestButton);
		mainLayout->addLayout(testLayout);
		QVBoxLayout *examLayout=new QVBoxLayout();
			examLayout->addWidget(examStatusLabel);
			examLayout->addWidget(tableWidget);
			examLayout->addWidget(submitExamButton);
			examLayout->addWidget(cancelExamButton);
		mainLayout->addLayout(examLayout);
	mainWidget->setLayout(mainLayout);
	statusBar()->addPermanentWidget(progressBar);
	
	//update widgets
	updateStatusbar();
	setMode(mode);
	   
	// create shortcuts
	QShortcut *submitShortcut=new QShortcut(Qt::Key_Return, this);
	connect(submitShortcut, SIGNAL(activated()), this, SLOT(check()));
	QShortcut *hintShortcut=new QShortcut(QKeySequence("Ctrl+H"), this);
	connect(hintShortcut, SIGNAL(activated()), this, SLOT(hint()));
	QShortcut *findShortcut=new QShortcut(QKeySequence("Ctrl+f"), this);
	connect(findShortcut, SIGNAL(activated()), this, SLOT(search()));

	// connect signals and slots
	connect(searchBar, SIGNAL(textChanged(QString)), this, SLOT(updateList()));
	connect(listWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(editentry()));
	connect(submitWordButton, SIGNAL(clicked()), this, SLOT(check()));
	connect(cancelTestButton, SIGNAL(clicked()), this, SLOT(canceltest()));
	connect(cancelExamButton, SIGNAL(clicked()), this, SLOT(cancelexam()));
	connect(submitExamButton, SIGNAL(clicked()), this, SLOT(checkexam()));
	connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayactivated(QSystemTrayIcon::ActivationReason)));
	
	statusBar()->showMessage(tr("Dicto version %1").arg(VERSION));
	

}