示例#1
0
// Send a "Set font" event to the GUI, and wait for the font metrics answer
void qt_sendFont()
{
    qt->out << GESetFont << qt->currentFontName << qt->currentFontSize;

    QPair<QString, int> currentFont(qt->currentFontName, qt->currentFontSize);
    static QPair<QString, int> lastFont("", 0);

    // The font has not changed
    if (currentFont == lastFont)
        return;

    static QMap<QPair<QString, int>, QPair<int, int> > fontMetricCache;
    QPair<int, int> metric;

    // Try to find the font metric in the cache or ask the GUI for the font metrics
    if (fontMetricCache.contains(currentFont))
        metric = fontMetricCache[currentFont];
    else
    {
        qt->out << GEFontMetricRequest;
        qt_flushOutBuffer();
        bool receivedFontProps = false;
        int waitcount = 0;
        while (!receivedFontProps)
        {
            qt->socket.waitForReadyRead(1000);
            if (qt->socket.bytesAvailable() < (int)sizeof(gp_event_t)) {
                fprintf(stderr, (waitcount++ % 10 > 0) ? "  ."
                        : "\nWarning: slow font initialization");
#ifdef Q_OS_MAC
                // OSX can be slow (>30 seconds?!) in determining font metrics
                // Give it more time rather than failing after 1 second
                // Possibly this is only relevant to Qt5
                GP_SLEEP(0.5);
                continue;
#endif
                return;
            }
            while (qt->socket.bytesAvailable() >= (int)sizeof(gp_event_t))
            {
                gp_event_t event;
                qt->socket.read((char*) &event, sizeof(gp_event_t));
                // Here, we discard other events than fontprops.
                if ((event.type == GE_fontprops) && (event.par1 > 0) && (event.par2 > 0))
                {
                    receivedFontProps = true;
                    metric = QPair<int, int>(event.par1, event.par2);
                    fontMetricCache[currentFont] = metric;
                    break;
                }
            }
        }
        if (waitcount > 0)
            fprintf(stderr,"\n");
    }

    term->v_char = qt_oversampling*metric.first;
    term->h_char = qt_oversampling*metric.second;
    lastFont = currentFont;
}
示例#2
0
文件: wnd_main.cpp 项目: noQQ0312/DDD
void MainWindow::onFormatMoreBtnClicked()
{
    QFontDialog cDlgFont(  currentFont(), this );
    if ( QDialog::Accepted == cDlgFont.exec() ) {
        setCurrentFont( cDlgFont.selectedFont() );
    }
}
示例#3
0
文件: wnd_main.cpp 项目: noQQ0312/DDD
void MainWindow::onFontFamilyChanged()
{
    updateFontPointSize( m_pCmbFont->currentText() );

    QFont fnt = currentFont();
    fnt.setFamily( m_pCmbFont->currentText() );
    fnt.setPointSize( m_pCmbFontPointSize->currentText().toInt() );
    setCurrentFont( fnt );
}
示例#4
0
SettingsDialog::SettingsDialog(QWidget *parent):
    QDialog(parent)
{
    QLabel *nameLabel = new QLabel(tr("Имя бога"));
    nameLine = new QLineEdit;
    if (settings.contains("godname"))
        nameLine->setText(settings.value("godname").toString());
    QLabel *serverLabel = new QLabel(tr("Сервер"));
    serverBox = new QComboBox;
    serverBox->setEditable(false);
    serverBox->addItem("godville.net");
    serverBox->addItem("godvillegame.com");
    if (settings.value("server").toString()=="godvillegame.com")
        serverBox->setCurrentIndex(1);
    QLabel *fontLabel = new QLabel(tr("Шрифт"));
    fontBox = new QFontComboBox;
    QFont currentFont(settings.value("fontFamily").toString());
    fontBox->setCurrentFont(currentFont);
    fontSizeBox = new QComboBox;
    fontSizeBox->setEditable(false);
    for (int i=8; i<30; i+=2)
        fontSizeBox->addItem(QString::number(i));
    fontSizeBox->setCurrentIndex((settings.value("fontSize").toInt()-8)/2);
    ok = new QPushButton(tr("Применить"));
    QGridLayout *layout = new QGridLayout;
    layout->addWidget(nameLabel, 0, 0);
    layout->addWidget(nameLine, 0, 1, 1, 2);
    layout->addWidget(serverLabel, 1, 0);
    layout->addWidget(serverBox, 1, 1, 1, 2);
    layout->addWidget(fontLabel, 2, 0);
    layout->addWidget(fontBox, 2, 1);
    layout->addWidget(fontSizeBox, 2, 2);
    QVBoxLayout *formLayout = new QVBoxLayout;
    formLayout->addLayout(layout);
#ifdef Q_WS_MAEMO_5
    formLayout->addWidget(ok);
#else
    cancel = new QPushButton(tr("Отмена"));
    QHBoxLayout *buttonLayout = new QHBoxLayout;
    buttonLayout->addStretch();
    buttonLayout->addWidget(ok);
    buttonLayout->addWidget(cancel);
    formLayout->addLayout(buttonLayout);
    connect(cancel, SIGNAL(clicked()), this, SLOT(close()));
#endif
    setLayout(formLayout);

    connect(ok, SIGNAL(clicked()), this, SLOT(save()));
}
示例#5
0
文件: wnd_main.cpp 项目: noQQ0312/DDD
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    initControls();
    layoutControls();

    connect( ui->txtEdt, SIGNAL(currentCharFormatChanged( QTextCharFormat)), this, SLOT(onTextCharFormatChanged(QTextCharFormat)) );

    QFont fnt = currentFont();
    m_pCmbFont->setCurrentText( fnt.family() );
    m_pCmbFontPointSize->setCurrentText( QString::number( fnt.pointSize() ) );
}
示例#6
0
///// constructor /////////////////////////////////////////////////////////////
StatusText::StatusText(QWidget* parent, const char* name) : QTextEdit(parent, name)
/// The default constructor.
{
  // Basic setup
  setSizePolicy(QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding, false));
  setReadOnly(true);
  setTextFormat(Qt::LogText);
  setMaxLogLines(2000);
  setWordWrap(QTextEdit::NoWrap);

  // A fixed pitch font?
  QFont font = currentFont();
  font.setStyleHint(QFont::TypeWriter); // does nothing on X11 by definition
  font.setFixedPitch(true);
  setFont(font); // can't get a fixed pitch font in this way on Windows
}
示例#7
0
ChatTextEdit::ChatTextEdit(QWidget *parent) :
    QTextEdit(parent)
{
    QFontMetrics metrics(currentFont());
    fontHeight = metrics.height();

    isEmojiWidgetOpen = false;
    isComposing = false;

    connect(&composingTimer,SIGNAL(timeout()),
            this,SLOT(verifyPaused()));

    connect(this,SIGNAL(textChanged()),
            this,SLOT(textChanged()));

    installEventFilter(this);
}
示例#8
0
void ChatTextEdit::textChanged()
{
    int editHeight = size().height();
    double textLines = (editHeight - 39) / fontHeight;

    int docHeight = document()->size().height();

    QFontMetrics metrics(currentFont());

    fontHeight = metrics.height();

    double docLines = (docHeight - 8) / fontHeight;

    if (abs(docLines) < MAX_LINES && abs(docLines) != abs(textLines))
    {
        setFixedHeight((docLines * fontHeight) + 39);
        update();
    }
}
int QFontComboBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QComboBox::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 4)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 4;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QFontDatabase::WritingSystem*>(_v) = writingSystem(); break;
        case 1: *reinterpret_cast<int*>(_v) = QFlag(fontFilters()); break;
        case 2: *reinterpret_cast< QFont*>(_v) = currentFont(); break;
        }
        _id -= 3;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setWritingSystem(*reinterpret_cast< QFontDatabase::WritingSystem*>(_v)); break;
        case 1: setFontFilters(QFlag(*reinterpret_cast<int*>(_v))); break;
        case 2: setCurrentFont(*reinterpret_cast< QFont*>(_v)); break;
        }
        _id -= 3;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 3;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 3;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 3;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 3;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 3;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 3;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
示例#10
0
/*!
  Closes the dialog and sets its result code to \a result. If this dialog
  is shown with exec(), done() causes the local event loop to finish,
  and exec() to return \a result.

  \sa QDialog::done()
*/
void QFontDialog::done(int result)
{
    Q_D(QFontDialog);
    QDialog::done(result);
    if (result == Accepted) {
        // We check if this is the same font we had before, if so we emit currentFontChanged
        QFont selectedFont = currentFont();
        if(selectedFont != d->selectedFont)
            emit(currentFontChanged(selectedFont));
        d->selectedFont = selectedFont;
        emit fontSelected(d->selectedFont);
    } else
        d->selectedFont = QFont();
    if (d->receiverToDisconnectOnClose) {
        disconnect(this, SIGNAL(fontSelected(QFont)),
                   d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
        d->receiverToDisconnectOnClose = 0;
    }
    d->memberToDisconnectOnClose.clear();
}
示例#11
0
int QFontDialog::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QDialog::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 8)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 8;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QFont*>(_v) = currentFont(); break;
        case 1: *reinterpret_cast< FontDialogOptions*>(_v) = options(); break;
        }
        _id -= 2;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setCurrentFont(*reinterpret_cast< QFont*>(_v)); break;
        case 1: setOptions(*reinterpret_cast< FontDialogOptions*>(_v)); break;
        }
        _id -= 2;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 2;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 2;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 2;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 2;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 2;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 2;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
bool
SimpleRichTextEdit::fontStrikeOut()
{
	return currentFont().strikeOut();
}
void MAutocompleteWidget::addText(const QString &text) {
    insertHtml(text);
    QFontMetrics fontMetric(currentFont());
    int height = fontMetric.height()*(toPlainText().count("\n")+3);
    setMaximumHeight(height);
}
示例#14
0
文件: wnd_main.cpp 项目: noQQ0312/DDD
void MainWindow::onFontPointSizeChanged()
{
    QFont fnt = currentFont();
    fnt.setPointSize( m_pCmbFontPointSize->currentText().toInt() );
    setCurrentFont( fnt );
}
/*------------------------------------------------------------------------------
| DrawingArea::button1Up                                                       |
|                                                                              |
| Handle button 1 up events.  This indicates a data points final location.     |
------------------------------------------------------------------------------*/
DrawingArea& DrawingArea::button1Up( const IPoint& point )
{
  if ( drawState() == drawing )
  {
    switch (currentObj)
    {
      case move:
      break;
      case eraser:
      break;
      case stylecan:
      break;
      case line:
        ((IGLine*)iGraphic)->setEndingPoint( point );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      break;
      case freehand:
        ((IGPolygon*)iGraphic)->addPoint( point );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      break;
      case rectangle:
      {
        IRectangle rc(((IGRectangle*)iGraphic)->enclosingRect());
        rc.sizeTo( rc.size() + point - previousPt );
        ((IGRectangle*)iGraphic)->setEnclosingRect( rc );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      }
      break;
      case ellipse:
      {
        IRectangle rc(((IGEllipse*)iGraphic)->enclosingRect());
        rc.sizeTo( rc.size() + point - previousPt );
        ((IGEllipse*)iGraphic)->setEnclosingRect( rc );

        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
      }
      break;
      case polyline:
      case polygon:
        previousPt = point;
        ((IGPolyline*)iGraphic)->setPoint(
                         ((IGPolyline*)iGraphic)->numberOfPoints()-1, point );
        setDrawState( waitingForInput );
      break;
      case arc:
      if ( pointCount == 2 )
      {
        ((IG3PointArc*)iGraphic)->setIntermediatePoint( point );
        gc.setMixMode( IGraphicBundle::xor ).setPenColor( IColor::white );
        IGLine tempLine( ((IG3PointArc*)iGraphic)->startingPoint(), previousPt );
        tempLine.drawOn( gc );
        tempLine.setEndingPoint( point );
        tempLine.drawOn( gc );
        setDrawState( waitingForInput );
      }
      else if ( pointCount == 3 )
      {
        gc.setMixMode( IGraphicBundle::xor ).setPenColor( IColor::white );
        iGraphic->drawOn( gc );
        ((IG3PointArc*)iGraphic)->setEndingPoint( point );
        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
        pointCount = 0;
      }
      break;
      case pie:
      case chord:
      if ( pointCount == 2 )
      {
        gc.setMixMode( IGraphicBundle::xor ).setPenColor( IColor::white );
        setDrawState( waitingForInput );
        IPoint centerPt(((IGPie*)iGraphic)->enclosingRect().center());

        ((IGPie*)iGraphic)->setStartAngle( angleFromPoints( centerPt, point ));

        unsigned a(abs(centerPt.x()) - abs(point.x()));
        unsigned b(abs(centerPt.y()) - abs(point.y()));

        unsigned long radius((unsigned long)sqrtl(a*a + b*b));

        ((IGPie*)iGraphic)->setEnclosingRect(
           ((IGPie*)iGraphic)->enclosingRect().expandBy(radius));
      }
      else if ( pointCount == 3 )
      {
        gc.setMixMode( IGraphicBundle::xor ).setPenColor( IColor::white );
        iGraphic->drawOn( gc );

        double sweep(angleFromPoints(
                              ((IGPie*)iGraphic)->enclosingRect().center(), point ));

        if ( sweep < ((IGPie*)iGraphic)->startAngle() )
          ((IGPie*)iGraphic)->setSweepAngle( 360.0 -
                                ( ((IGPie*)iGraphic)->startAngle() - sweep ));
        else
          ((IGPie*)iGraphic)->setSweepAngle( sweep -
                                            ((IGPie*)iGraphic)->startAngle());

        iGraphic->setGraphicBundle( currentBundle );
        iGraphic->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *iGraphic );
        pointCount = 0;
      }
      break;
      case text:
      {
        IString input;

        IDynamicLinkLibrary reslib("CPPWV53R");

        if (point.x() % 2)
          input = reslib.loadString( STRING_SAMPLE1 );
        else if ((point.y() % 5)==1)
          input = reslib.loadString( STRING_SAMPLE3 );
        else if ((point.y() % 5)==3)
          input = reslib.loadString( STRING_SAMPLE4 );
        else
          input = reslib.loadString( STRING_SAMPLE2 );

        IGString* text = new IGString( input.x2c(), point, currentFont());
//      IGString* text = new IGString( "Doodle", point, currentFont());
        text->rotateBy( 10.0, point );
        text->setGraphicBundle( currentBundle );
        text->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *text );
      }
      break;
      case bitmap:
      {
        IGBitmap *bmp;
//      if (bitmapFileName().length() > 0)
//      {
//        bmp = new IGBitmap(bitmapFileName());
//      }

        // Select a bitmap to load
        IDynamicLinkLibrary reslib("CPPWV53R");

        if (point.x() % 2)
          bmp = new IGBitmap(reslib.loadBitmap( BITMAP_SAMPLE1 ));
        else if ((point.y() % 5)==1)
          bmp = new IGBitmap(reslib.loadBitmap( BITMAP_SAMPLE3 ));
        else if ((point.y() % 5)==3)
          bmp = new IGBitmap(reslib.loadBitmap( BITMAP_SAMPLE4 ));
        else
          bmp = new IGBitmap(reslib.loadBitmap( BITMAP_SAMPLE2 ));

        bmp->moveTo( point );
        bmp->drawOn( gc );
        setDrawState( notDrawing );
        graphicList()->addAsLast( *bmp );
      }
      break;
    } /* endswitch */
  } /* endif */
  else  // not drawing
  {
    switch (currentObj)
    {
      case move:
        if (moveGraphic && capturePointer)
        {
          moveRect.translateBy( point - previousPt );
          moveRect.drawOn( gc );
          moveRect.resetTransformMatrix();
          this->refresh( moveRect.boundingRect(gc).expandBy(2) );
          moveGraphic->translateBy( point - startingPt );
          moveGraphic->drawOn( gc );
          moveGraphic = 0;
          capturePointer(false);
        }
      break;
    }
  }
  return *this;
}