Ejemplo n.º 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;
}
Ejemplo n.º 2
0
void ImportCategoryDrawer::drawCategory(const QModelIndex& index, int /*sortRole*/,
                                       const QStyleOption& option, QPainter* p) const
{
    if (option.rect.width() != d->rect.width())
    {
        const_cast<ImportCategoryDrawer*>(this)->updateRectsAndPixmaps(option.rect.width());
    }

    p->save();

    p->translate(option.rect.topLeft());

    CamItemSortSettings::CategorizationMode mode =
        (CamItemSortSettings::CategorizationMode)index.data(ImportFilterModel::CategorizationModeRole).toInt();

    p->drawPixmap(0, 0, d->pixmap);

    QFont fontBold(d->font);
    QFont fontNormal(d->font);
    fontBold.setBold(true);
    int fnSize = fontBold.pointSize();

    //    bool usePointSize;
    if (fnSize > 0)
    {
        fontBold.setPointSize(fnSize+2);
        //        usePointSize = true;
    }
    else
    {
        fnSize = fontBold.pixelSize();
        fontBold.setPixelSize(fnSize+2);
        //        usePointSize = false;
    }

    QString header;
    QString subLine;

    switch (mode)
    {
        case CamItemSortSettings::NoCategories:
            break;
        case CamItemSortSettings::CategoryByFolder:
            viewHeaderText(index, &header, &subLine);
            break;
        case CamItemSortSettings::CategoryByFormat:
            textForFormat(index, &header, &subLine);
            break;
    }

    p->setPen(kapp->palette().color(QPalette::HighlightedText));
    p->setFont(fontBold);

    QRect tr;
    p->drawText(5, 5, d->rect.width(), d->rect.height(),
                Qt::AlignLeft | Qt::AlignTop,
                header, &tr);

    int y = tr.height() + 2;

    p->setFont(fontNormal);

    p->drawText(5, y, d->rect.width(), d->rect.height() - y,
                Qt::AlignLeft | Qt::AlignVCenter, subLine);

    p->restore();
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
void
SimpleRichTextEdit::toggleFontBold()
{
	setFontBold(!fontBold());
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
void CBlockUnit::DrawBlock(Graphics *pGraph)
{
  Pen pen(Color(0, 0, 0));
  Font fontBold(L"Tahoma", 10, FontStyleBold);
  Font fontNormal(L"Tahoma", 10, FontStyleRegular);
  SolidBrush brush(Color(0, 0, 0));

  // Check & update block size
  UINT nMinWidth  = GetMinWidth();
  UINT nMinHeight = GetMinHeight();
  if ((INT)m_rRect.Width < (INT)nMinWidth)
  {
    m_rRect.Width = ROUND(nMinWidth);
  }
  if ((INT)m_rRect.Height < (INT)nMinHeight)
  {
    m_rRect.Height = ROUND(nMinHeight);
  }

  // select color according to type
  switch (m_nType)
  {
    case T_FUNCTION:
      {
        brush.SetColor(Color(220, 220, 255));
      }
      break;
    case T_SUBSYSTEM:
      {
        brush.SetColor(Color(255, 220, 220));
      }
      break;
    case T_TEXTBOX:
      {
        brush.SetColor(Color(255, 255, 230));
      }
      break;
    case T_INPUT:
      {
        brush.SetColor(Color(255, 255, 220));
      }
      break;
    case T_OUTPUT:
      {
        brush.SetColor(Color(255, 255, 220));
      }
      break;
    default:
      {
        ASSERT(TRUE);
      }
  }

  // Mark selected
  if (m_bSelected)
  {
    pen.SetWidth(2);
  }

  // Outline error connections
  if (m_bError)
  {
    pen.SetColor(Color(255, 100, 100));
  }
  else
  {
    pen.SetColor(Color(0, 0, 0));
  }

  // Draw rectangle body
  pGraph->FillRectangle(&brush, m_rRect);
  pGraph->DrawRectangle(&pen, m_rRect);

  if ((m_nType != T_INPUT) && (m_nType != T_OUTPUT))
  {
    pen.SetWidth(1);
    brush.SetColor(Color(0, 0, 0));
    RectF rect, rectSize;
    StringFormat format;

    // Write title string
    if (m_nType == T_TEXTBOX)
    {
      rect = RectF(m_rRect.X, m_rRect.Y, m_rRect.Width, m_rRect.Height);
      wstring ws(m_sName.begin(), m_sName.end());
      pGraph->DrawString(ws.c_str(), -1, &fontNormal, rect, &format, &brush);

      // Measure title text width
      rect.Width = 0;
      pGraph->MeasureString(ws.c_str(), -1, &fontNormal, rect, &format,
          &rectSize);
      m_lName = (INT)rectSize.Width;
    }
    else
    {
      // Draw title line
      pGraph->DrawLine(&pen, m_rRect.X, m_rRect.Y+20, m_rRect.GetRight(),
          m_rRect.Y+20);

      format.SetAlignment(StringAlignmentCenter);
      format.SetLineAlignment(StringAlignmentCenter);
      rect = RectF(m_rRect.X, m_rRect.Y, m_rRect.Width, 20);
      wstring ws(m_sName.begin(), m_sName.end());
      pGraph->DrawString(ws.c_str(), -1, &fontBold, rect, &format, &brush);

      // Measure title text width
      rect.Width = 0;
      pGraph->MeasureString(ws.c_str(), -1, &fontBold, rect, &format,
          &rectSize);
      m_lName = (INT)rectSize.Width;
    }
  }

  // Draw input variables
  Point ptInput(m_rRect.X, m_rRect.GetTop() + 10);
  if ((m_nType != T_INPUT) && (m_nType != T_OUTPUT))
  {
    ptInput.Y += 20;
  }
  for (int i=0; i<m_vInput.size(); i++)
  {
    // Skip if input port
    if (m_nType == T_INPUT)
    {
      break;
    }

    // Draw port
    m_vInput[i]->DrawIOPort(pGraph, ptInput.X, ptInput.Y);
    ptInput.Y += 20;

    // Only draw one if I/O ports
    if (m_nType == T_OUTPUT)
    {
      break;
    }
  }

  // Draw output variables
  Point ptOutput(m_rRect.GetRight(), m_rRect.Y + 10);
  if ((m_nType != T_INPUT) && (m_nType != T_OUTPUT))
  {
    ptOutput.Y += 20;
  }
  for (int i=0; i<m_vOutput.size(); i++)
  {
    // Skip if output port
    if (m_nType == T_OUTPUT)
    {
      break;
    }

    // Draw port
    m_vOutput[i]->DrawIOPort(pGraph, ptOutput.X, ptOutput.Y);
    ptOutput.Y += 20;

    // Only draw one if I/O ports
    if (m_nType == T_INPUT)
    {
      break;
    }
  }
}
Ejemplo n.º 7
0
void inputRZImpl::print()
{
    QString fname = EGSdir + EGSfileName;
    QPrinter* printer = new QPrinter;
    printer->setPageSize( QPrinter::Letter );
    const int Margin = 20;
    const int MarginY = 30;
    int pageNo = 1;

    QPrintDialog pdialog(printer,this);

    if ( pdialog.exec()) {

cout << "let's print !!!" << endl;


        QPainter paint( printer );
        //if( !paint.begin( printer ) )              // paint on printer
        //     return;

       static const char *fonts[] = { "Helvetica", "Courier", "Times", 0 };
       static int	 sizes[] = { 10, 12, 18, 24, 36, 0 };
       int yPos = 0;

       QFont fontNormal( fonts[1], sizes[0] );
       QFont fontBold( fonts[0], sizes[0] );
       fontBold.setWeight( QFont::Black);

       paint.setFont( fontBold );
       QFontMetrics fmBold = paint.fontMetrics();
       paint.setFont( fontNormal );
       QFontMetrics fm = paint.fontMetrics();

       //qt3to4 -- BW
       //Q3PaintDeviceMetrics metrics( printer ); // need width/height

       QFile              fi( fname );
       //qt3to4 -- BW
       //Q3TextStream ts( &fi );
       QTextStream ts( &fi );
       QString          t;
       int StepsPerPage =  500;

       int LinesPerPage = (printer->height() - 2* MarginY) / fm.lineSpacing();
       if ( fi.open( QIODevice::ReadOnly ) ) {

            int NumOfPages = 1 + TotalTextLines( fname ) / LinesPerPage;
            int totalSteps = StepsPerPage * NumOfPages;

            QString msg( "Printing (page " );
                         msg += QString::number( pageNo );
                         msg += ")...";
            //qt3to4 -- BW
            //Q3ProgressDialog* dialog = new Q3ProgressDialog(msg, "Cancel",
             //                                                               totalSteps, this, "progress", true);
            QProgressDialog* dialog = new QProgressDialog(msg, "Cancel",0,totalSteps);
            //dialog->setTotalSteps( totalSteps );
            //dialog->setProgress( 0 );
            dialog->setValue(0);
            dialog->setMinimumDuration( 0 );

            int progress_count = 0;

           QString gui = "EGSnrc GUI for RZ Geometries:  " + EGSfileName;
           QDate currDate = QDate::currentDate();
           QString date = currDate.toString ( "dd.MM.yyyy" );
           paint.setFont( fontBold );
           paint.drawText( Margin, 0,  printer->width() - 2*Margin, fmBold.lineSpacing(),
                        Qt::AlignLeft | Qt::RichText, gui );
           paint.drawText( Margin, 0,  printer->width() - 2*Margin, fmBold.lineSpacing(),
                        Qt::AlignRight, date );
           paint.drawLine( Margin, MarginY - 10, printer->width() - Margin, MarginY - 10 );
           paint.drawLine( Margin, printer->height() - MarginY + 10,
                                    printer->width() - Margin, printer->height() - MarginY + 10 );
           paint.drawText( Margin, printer->height() - fmBold.lineSpacing(),
	                       printer->width(), fmBold.lineSpacing(),
                                     Qt::AlignHCenter, QString::number( pageNo ) );
           paint.setFont( fontNormal );

           do {
                progress_count++;
                qApp->processEvents();
                if ( dialog->wasCanceled() )
                     dialog->close();
                t = ts.readLine();

                if ( MarginY + yPos + fm.lineSpacing() > printer->height() - MarginY ) {
                         do{
                                    //dialog->setProgress( ++progress_count );
                                    dialog->setValue(++progress_count );
                         }while ( progress_count < StepsPerPage*pageNo );
	           msg = "Printing (page " + QString::number( ++pageNo ) + ")...";
	           dialog->setLabelText( msg );
                         printer->newPage();             // no more room on this page
                         yPos = 0;                       // back to top of page
                         paint.setFont( fontBold );
                         paint.drawText( Margin, 0,  printer->width() - 2*Margin, fmBold.lineSpacing(),
                                                   Qt::AlignLeft | Qt::RichText, gui );
                         paint.drawText( Margin, 0,  printer->width() - 2*Margin, fmBold.lineSpacing(),
                                                  Qt::AlignRight, date );
                        paint.drawLine( Margin, MarginY - 10, printer->width() - Margin, MarginY - 10 );
	          paint.drawLine( Margin, printer->height() - MarginY + 10,
                                    printer->width() - Margin, printer->height() - MarginY + 10 );
                        paint.drawText( Margin, printer->height() - fmBold.lineSpacing(),
	                       printer->width(), fmBold.lineSpacing(),
                                     Qt::AlignHCenter, QString::number( pageNo ) );
                         paint.setFont( fontNormal );
                }

                paint.drawText( Margin, MarginY + yPos,
                        printer->width(), fm.lineSpacing(),
                        Qt::TextExpandTabs | Qt::TextDontClip, t );

                yPos = yPos + fm.lineSpacing();

               dialog->setValue( progress_count );

           //qt3to4 -- BW
           //} while ( !ts.eof() );
          } while ( !ts.atEnd() );

          do{
               dialog->setValue( ++progress_count );
           }while ( progress_count < totalSteps );

          dialog->setValue( totalSteps );
          zap(dialog);
       }
       else {
               QMessageBox::critical( 0,
                        tr("Error printing "),
	          tr("Couldn't open file %1").arg(fname),
                        tr("Quit") );
       }

       fi.close();

    }
    else {
             QMessageBox::information( this, "Printing status", "Printing aborted");
    }

    delete printer;
}