示例#1
0
QVariant ItemModel::data(const QModelIndex &index, int role) const
{
	const int id = index.row();
	switch(role)
	{
		case Qt::DisplayRole: return ToolbarAction(item_enum(id)).text();
		case Qt::DecorationRole: return ToolbarAction(item_enum(id)).icon();
		default: return QVariant();
	}
}
示例#2
0
/*
  Saving toolbar's items
*/
void Settings::setToolbarItems(const QVector<int>& v)
{
	if(v==tb_items) return;
	//removing old settings
	for(int i=0; i<tb_items.size(); ++i) if(tb_items[i]!=itemSeparator)
	{
		config.remove(ToolbarAction(item_enum(tb_items[i])).pref_name()); //dirty hack =(
	}
	tb_items = v;
	//saving settings
	config.setValue("Toolbar/itemCount", tb_items.size());
	for(int i=0; i<tb_items.size(); ++i) if(tb_items[i]!=itemSeparator)
	{
		config.setValue(ToolbarAction(item_enum(tb_items[i])).pref_name(), i);
	}
	emit ToolbarItemsChanged();
}
示例#3
0
void Settings::load()
{
	if(config.allKeys().size()) //if exist - reading settings
	{
		notes_path = config.value("NotesPath").toString();
		last_note = config.value("LastNote").toString();
		hide_start = config.value("HideStart").toBool();
		//
		dialog_geometry = config.value("DialogGeometry").toByteArray();
		dialog_state = config.value("DialogState").toByteArray();
		//
		tab_position = TabPosition(config.value("TabPosition").toInt());
		show_hidden = config.value("ShowHidden").toBool();
		show_extensions = config.value("ShowExtensions").toBool();
		//
		hide_frame = config.value("HideFrame").toBool();
		stay_top = config.value("StayTop").toBool();
		//
		single_instance = config.value("SingleInstance").toBool();
		copy_start_raise = config.value("CopyStartRaise").toBool();
		//
		note_font.fromString(config.value("NoteFont").toString());
		note_links_open = config.value("NoteLinksOpen").toBool();
		note_paste_plaintext = config.value("NotePastePlaintext").toBool();
		//
		int ScriptCount = config.value("ComandCount").toInt();
		for(int i=0; i<ScriptCount; ++i)
		{
			script_model.append(
				config.value(QString("ComandName%1").arg(i)).toString(),
				config.value(QString("ComandFile%1").arg(i)).toString(),
				config.value(QString("ComandIcon%1").arg(i)).toString());
		}
		note_highlight = config.value("NoteHighlight").toBool();

		int HighlightRuleCount = config.beginReadArray("HighlightRules");
		highlight_rules.resize(HighlightRuleCount);
		for(int i=0; i<highlight_rules.size(); ++i)
		{
			config.setArrayIndex(i);
			highlight_rules[i].enabled = config.value("enabled").toBool();
			highlight_rules[i].regexp = config.value("regexp").toString();
			highlight_rules[i].color = QColor(config.value("color").toString());
		}
		config.endArray();

		script_show_output = config.value("ScriptShowOutput").toBool();
		script_copy_output = config.value("ScriptCopyOutput").toBool();
		//
		language_custom = config.value("LanguageCustom").toBool();
		locale_current = QLocale(config.value("LanguageCurrent").toString());
		//
		if(config.contains("Toolbar/itemCount"))
		{
			tb_items.resize(config.value("Toolbar/itemCount").toInt());
			for(int i=itemAdd; i<itemMax; ++i)
			{
				int pos = config.value(ToolbarAction(item_enum(i)).pref_name(), tb_items.size()).toInt();
				if(pos<tb_items.size()) tb_items[pos] = i; //Item's position
			}
		}
	}
	/*
	* If settings don't exist - setup default settings
	*/
	//Setting default path to notes
	if(notes_path.isEmpty())
	{
#ifdef Q_WS_X11
	notes_path = QDir::homePath()+"/.local/share/notes";
#elif defined(Q_WS_WIN)
	QSettings win_settings("Microsoft", "Windows");
	QString mydocuments_path = win_settings.value("CurrentVersion/Explorer/Shell Folders/Personal", "").toString();
	if(!mydocuments_path.isEmpty()) notes_path = mydocuments_path+"/Notes";
	else if(!QDir::homePath().isEmpty()) notes_path = QDir::homePath()+"/Notes";
#else
	if(!QDir::homePath().isEmpty()) notes_path = QDir::homePath()+"\Notes";
#endif
		config.setValue("NotesPath", notes_path);
	}
	//Settings single instance options
	if(!config.contains("SingleInstance"))
	{
		single_instance = true;
		config.setValue("SingleInstance", single_instance);
		copy_start_raise = true;
		config.setValue("CopyStartRaise", copy_start_raise);
	}
	//Setting default note options
	if(!config.contains("NoteLinksOpen"))
	{
		note_links_open = true;
		config.setValue("NoteLinksOpen", note_links_open);
	}
	if(!config.contains("NotePastePlaintext"))
	{
		note_paste_plaintext = false;
		config.setValue("NotePastePlaintext", note_paste_plaintext);
	}
	//Setting default highlight rules
	if(!config.contains("NoteHighlight"))
	{
		if(config.contains("NoteLinksHighlight"))
			note_highlight = config.value("NoteLinksHighlight").toBool();
		else
			note_highlight = true;

		config.setValue("NoteHighlight", note_highlight);
		highlight_rules.append(HighlightRule(true, "(http|https|ftp)://\\S+", QColor(Qt::blue)));
		highlight_rules.append(HighlightRule(false, "(\\d{1,3}\\.){3,3}\\d{1,3}(\\:\\d+)?", QColor("#500000")));
		highlight_rules.append(HighlightRule(false, "(0x|)\\d+", QColor("#147E16")));
		highlight_rules.append(HighlightRule(false, "#[0-9a-fA-F]{6,6}", QColor("#CEC51B")));

		config.beginWriteArray("HighlightRules", highlight_rules.size());
		for(int i=0; i<highlight_rules.size(); ++i)
		{
			config.setArrayIndex(i);
			config.setValue("enabled", highlight_rules.at(i).enabled);
			config.setValue("regexp", highlight_rules.at(i).regexp);
			config.setValue("color", highlight_rules.at(i).color);
		}
		config.endArray();
	}
	//Setting default scripts
	if((script_model.rowCount()==0) && !config.contains("ComandCount"))
	{
	#ifdef unix
		script_model.append("Print note's content", "cat", "");
	#elif defined(Q_WS_WIN)
		//
	#endif
		config.setValue("ComandCount", script_model.rowCount());
		for(int i=0; i<script_model.rowCount(); ++i)
		{
			config.setValue(QString("ComandName%1").arg(i), script_model.getName(i));
			config.setValue(QString("ComandFile%1").arg(i), script_model.getFile(i));
			config.setValue(QString("ComandIcon%1").arg(i), script_model.getIcon(i));
		}
	}
	//Setting default tab position
	if(!config.contains("TabPosition"))
	{
		tab_position = West;
		config.setValue("TabPosition", tab_position);
	}
	//Setting default toolbar items
	if((tb_items.size()==0) && !config.contains("Toolbar/itemCount"))
	{
		tb_items.append(itemAdd);
		tb_items.append(itemRemove);
		tb_items.append(itemRename);
		tb_items.append(itemSeparator);
		tb_items.append(itemPrev);
		tb_items.append(itemNext);
		tb_items.append(itemSeparator);
		tb_items.append(itemCopy);
		tb_items.append(itemSeparator);
		tb_items.append(itemSetup);
		tb_items.append(itemInfo);
		tb_items.append(itemSeparator);
		tb_items.append(itemRun);
		tb_items.append(itemSearch);
		tb_items.append(itemSeparator);
		tb_items.append(itemExit);
		config.setValue("Toolbar/itemCount", tb_items.size());
		for(int i=0; i<tb_items.size(); ++i)
			if(tb_items[i]!=itemSeparator)
				config.setValue(ToolbarAction(item_enum(tb_items[i])).pref_name(), i);
	}

    // Build two dictionaries of translation files for the program:
    // 1) the program translation files;
    // 2) qt library translation files.
    loadLanguages();
	//
#ifdef unix
	//Fixing Qt's problem on unix systems...
	QString system_lang(qgetenv("LANG").constData());
	system_lang.truncate(system_lang.indexOf('.'));
	if(system_lang.size()) locale_system = QLocale(system_lang);
	else locale_system = QLocale::system().language();
#else
	locale_system = QLocale::system().language();
#endif
	locale = (language_custom)?locale_current:locale_system;

    // Define priority locale for user interface.
    // Analyze only the program translation files dictionary.
    QMap<int, QMap<int, QString> >::const_iterator it = translations.find(locale.language());
	if(it!=translations.end()) //if translation list has locale language
	{
		const QMap<int, QString>& country_list = it.value();
		if(!country_list.contains(locale.country()))
		{
			QList<QLocale::Country> language_countries = QLocale::countriesForLanguage(locale.language());
			if(!language_countries.empty() && country_list.contains(language_countries[0]))
			{
				QLocale::Country country = language_countries[0];
				locale = QLocale(locale.language(), country);
			}
			else if(!country_list.empty())
			{
				QLocale::Country country = QLocale::Country(country_list.begin().key());
				locale = QLocale(locale.language(), country);
			}
			else locale = QLocale::c();
		}
	}
	else locale = QLocale::c();

    // Load files from dictionary for defined locale.
    updateLocale();

	qApp->installTranslator(&qtranslator);
	qApp->installTranslator(&translator);
}