예제 #1
0
/*!
 * Returns a QFont object based on font data contained in the format.
 */
QFont Format::font() const
{
   QFont font;
   font.setFamily(fontName());
   if (fontSize() > 0)
       font.setPointSize(fontSize());
   font.setBold(fontBold());
   font.setItalic(fontItalic());
   font.setUnderline(fontUnderline()!=FontUnderlineNone);
   font.setStrikeOut(fontStrikeOut());
   return font;
}
QMenu *
SimpleRichTextEdit::createContextMenu(const QPoint &mouseGlobalPos)
{
	Qt::TextInteractionFlags interactionFlags = this->textInteractionFlags();
	QTextDocument *document = this->document();
	QTextCursor cursor = textCursor();

	const bool showTextSelectionActions = (Qt::TextEditable | Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse) & interactionFlags;

	QMenu *menu = new QMenu(this);

	if(interactionFlags & Qt::TextEditable) {
		m_actions[Undo]->setEnabled(document->isUndoAvailable());
		menu->addAction(m_actions[Undo]);

		m_actions[Redo]->setEnabled(document->isRedoAvailable());
		menu->addAction(m_actions[Redo]);

		menu->addSeparator();

		m_actions[Cut]->setEnabled(cursor.hasSelection());
		menu->addAction(m_actions[Cut]);
	}

	if(showTextSelectionActions) {
		m_actions[Copy]->setEnabled(cursor.hasSelection());
		menu->addAction(m_actions[Copy]);
	}

	if(interactionFlags & Qt::TextEditable) {
#if !defined(QT_NO_CLIPBOARD)
		m_actions[Paste]->setEnabled(canPaste());
		menu->addAction(m_actions[Paste]);
#endif
		m_actions[Delete]->setEnabled(cursor.hasSelection());
		menu->addAction(m_actions[Delete]);

		m_actions[Clear]->setEnabled(!document->isEmpty());
		menu->addAction(m_actions[Clear]);

		if(m_insertUnicodeControlCharMenu && interactionFlags & Qt::TextEditable) {
			menu->addSeparator();
			menu->addMenu(m_insertUnicodeControlCharMenu);
		}
	}

	if(showTextSelectionActions) {
		menu->addSeparator();

		m_actions[SelectAll]->setEnabled(!document->isEmpty());
		menu->addAction(m_actions[SelectAll]);
	}

	if(interactionFlags & Qt::TextEditable) {
		menu->addSeparator();

		m_actions[ToggleBold]->setCheckable(true);
		m_actions[ToggleBold]->setChecked(fontBold());
		menu->addAction(m_actions[ToggleBold]);

		m_actions[ToggleItalic]->setCheckable(true);
		m_actions[ToggleItalic]->setChecked(fontItalic());
		menu->addAction(m_actions[ToggleItalic]);

		m_actions[ToggleUnderline]->setCheckable(true);
		m_actions[ToggleUnderline]->setChecked(fontUnderline());
		menu->addAction(m_actions[ToggleUnderline]);

		m_actions[ToggleStrikeOut]->setCheckable(true);
		m_actions[ToggleStrikeOut]->setChecked(fontStrikeOut());
		menu->addAction(m_actions[ToggleStrikeOut]);

		menu->addAction(m_actions[ChangeTextColor]);

		menu->addSeparator();

		m_actions[CheckSpelling]->setEnabled(!document->isEmpty());
		menu->addAction(m_actions[CheckSpelling]);

		m_actions[ToggleAutoSpellChecking]->setChecked(checkSpellingEnabled());
		menu->addAction(m_actions[ToggleAutoSpellChecking]);

		if(checkSpellingEnabled()) {
			setupWordUnderPositionCursor(mouseGlobalPos);

			QString selectedWord = m_selectedWordCursor.selectedText();
			if(!selectedWord.isEmpty() && highlighter() && highlighter()->isWordMisspelled(selectedWord)) {
				QMenu *suggestionsMenu = menu->addMenu(i18n("Suggestions"));
				suggestionsMenu->addAction(i18n("Ignore"), this, SLOT(addToIgnoreList()));
				suggestionsMenu->addAction(i18n("Add to Dictionary"), this, SLOT(addToDictionary()));
				suggestionsMenu->addSeparator();
				QStringList suggestions = highlighter()->suggestionsForWord(m_selectedWordCursor.selectedText());
				if(suggestions.empty())
					suggestionsMenu->addAction(i18n("No suggestions"))->setEnabled(false);
				else {
					for(QStringList::ConstIterator it = suggestions.begin(), end = suggestions.end(); it != end; ++it)
						suggestionsMenu->addAction(*it, this, SLOT(replaceWithSuggestion()));
				}
			}
		}

		menu->addSeparator();

		m_actions[AllowTabulations]->setCheckable(true);
		m_actions[AllowTabulations]->setChecked(!tabChangesFocus());
		menu->addAction(m_actions[AllowTabulations]);
	}

	return menu;
}
void
SimpleRichTextEdit::toggleFontUnderline()
{
	setFontUnderline(!fontUnderline());
}
예제 #4
0
파일: 6.c 프로젝트: 18616378431/myCode
int main()
{	
	union view font = {{1,12,RIGHT,OFF,OFF,OFF}};//初始化联合的第一个成员,结构体
	FONT * pf = &font.st_view;
	char ch;
	//init
	/*font.st_view.font_id = 1;
	font.st_view.font_size = 12;
	font.st_view.alignment = LEFT;
	font.st_view.font_bold = OFF;
	font.st_view.font_italic = OFF;
	font.st_view.font_underline = OFF;*/
	showSetting(pf);
	while((ch = menu()) != 'q')
	{
		puts("Enter your mode:");
		puts("f)bit field mode\tb)bit mode");
		switch(ch)
		{
		case 'f':
			ch = getchar();
			delMore();
			switch(ch)
			{
			case 'f':fontId(pf);break;
			case 'b':bitId(&font.ui_view);break;
			} 
			break;
		case 's':
			ch = getchar();
			delMore();
			switch(ch)
			{
			case 'f':fontSize(pf);break;
			case 'b':bitSize(&font.ui_view);break;
			} 
			break;
		case 'a':
			ch = getchar();
			delMore();
			switch(ch)
			{
			case 'f':fontAlignment(pf);break;
			case 'b':bitAlign(&font.ui_view);break;
			}  
			break;
		case 'b':
			ch = getchar();
			delMore();
			switch(ch)
			{
			case 'f':fontBold(pf);break;
			case 'b':bitBold(&font.ui_view);break;
			} 
			break;
		case 'i':
			ch = getchar();
			delMore();
			switch(ch)
			{
			case 'f':fontItalic(pf);break;
			case 'b':bitItalic(&font.ui_view);break;
			} 
			break;
		case 'u':
			ch = getchar();
			delMore();
			switch(ch)
			{
			case 'f':fontUnderline(pf);break;
			case 'b':bitUnderline(&font.ui_view);break;
			}  
			break;
		default:
			puts("Error input,Please type in an character such as f s a b i u or q:");
			break;
		}
		showSetting(pf);
	}
	itobs(font.ui_view);
	return 0;
}