Ejemplo n.º 1
0
QSize ModuleTreeView::sizeHint() const
{
    return QListView::sizeHint().boundedTo( 
	QSize( fontMetrics().maxWidth()*35, QWIDGETSIZE_MAX) );
}
Ejemplo n.º 2
0
void QCallTip::paintEvent(QPaintEvent *e)
{
        Q_UNUSED(e)
        
        QPainter p(this);
        QFontMetrics fm = fontMetrics();
        
        m_up = m_down = QRect();
        
        bool bPrev = m_index, bNext = (m_index + 1) < m_tips.count();
        int offset = 3, whalf = arrowWidth / 2 - 3; //, hhalf = height() / 2;
        
        QRect bg(0, 0, fm.width(m_tips.at(m_index)) + 6, fm.height());
        
        if ( bPrev )
        {
                bg.setWidth(bg.width() + arrowWidth);
        }
        
        if ( bNext )
        {
                bg.setWidth(bg.width() + arrowWidth);
        }
        
        p.fillRect(bg, QColor(0xca, 0xff, 0x70));
        //p.drawRect(bg);
        
        p.save();
        
        p.setPen(QColor(0x00, 0x00, 0x00));
        p.drawLine(0, height() - 1, bg.width() - 1, height() - 1);
        p.drawLine(bg.width() - 1, height() - 1, bg.width() - 1, 0);
        
        p.setPen(QColor(0xc0, 0xc0, 0xc0));
        p.drawLine(0, height() - 1, 0, 0);
        p.drawLine(0, 0, bg.width() - 1, 0);
        
        p.restore();
        
        int top = height() / 3, bottom = height() - height() / 3;
        
        if ( bPrev )
        {
                int x = offset + arrowWidth / 2 - 1;
                
                QPoint pts[] = {
                        QPoint(x - whalf, bottom),
                        QPoint(x + whalf, bottom),
                        QPoint(x, top)
                };
                
                p.drawPolygon(pts, sizeof(pts) / sizeof(QPoint), Qt::WindingFill);
                
                m_up = QRect(offset, 0, offset + arrowWidth, height());
                offset += arrowWidth;
        }
        
        if ( bNext )
        {
                int x = offset + arrowWidth / 2 - 1;
                
                QPoint pts[] = {
                        QPoint(x - whalf, top),
                        QPoint(x + whalf, top),
                        QPoint(x, bottom)
                };
                
                p.drawPolygon(pts, sizeof(pts) / sizeof(QPoint), Qt::WindingFill);
                
                m_down = QRect(offset, 0, offset + arrowWidth, height());
                offset += arrowWidth;
        }
        
        p.drawText(offset, fm.ascent() + 2, m_tips.at(m_index));
        
        setFixedSize(bg.size() + QSize(1, 1));
}
Ejemplo n.º 3
0
  connect( mView, &QgsLayoutView::itemFocused, this, [ = ]( QgsLayoutItem * item )
  {
    showItemOptions( item, false );
  } );

  // Panel and toolbar submenus
  mToolbarMenu->addAction( mLayoutToolbar->toggleViewAction() );
  mToolbarMenu->addAction( mNavigationToolbar->toggleViewAction() );
  mToolbarMenu->addAction( mToolsToolbar->toggleViewAction() );

  connect( mActionToggleFullScreen, &QAction::toggled, this, &QgsLayoutDesignerDialog::toggleFullScreen );

  mMenuProvider = new QgsLayoutAppMenuProvider( this );
  mView->setMenuProvider( mMenuProvider );

  int minDockWidth( fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ) ) );

  setTabPosition( Qt::AllDockWidgetAreas, QTabWidget::North );
  mGeneralDock = new QgsDockWidget( tr( "Layout" ), this );
  mGeneralDock->setObjectName( QStringLiteral( "LayoutDock" ) );
  mGeneralDock->setMinimumWidth( minDockWidth );
  mGeneralPropertiesStack = new QgsPanelWidgetStack();
  mGeneralDock->setWidget( mGeneralPropertiesStack );
  mPanelsMenu->addAction( mGeneralDock->toggleViewAction() );
  connect( mActionLayoutProperties, &QAction::triggered, this, [ = ]
  {
    mGeneralDock->setUserVisible( true );
  } );

  mItemDock = new QgsDockWidget( tr( "Item properties" ), this );
  mItemDock->setObjectName( QStringLiteral( "ItemDock" ) );
Ejemplo n.º 4
0
QSize ClockWidget::sizeHint() const 
{
	return QSize(fontMetrics().width(m_Format)+10, 20);
}
double QgsComposerItem::fontHeightCharacterMM( const QFont& font, const QChar& c ) const
{
  QFont metricsFont = scaledFontPixelSize( font );
  QFontMetricsF fontMetrics( metricsFont );
  return ( fontMetrics.boundingRect( c ).height() / FONT_WORKAROUND_SCALE );
}
Ejemplo n.º 6
0
void Font::drawComplexText(GraphicsContext* graphicsContext,
    const TextRunPaintInfo& runInfo,
    const FloatPoint& point) const
{
    UniscribeHelperTextRun state(runInfo.run, *this);

    SkColor color = graphicsContext->effectiveFillColor();
    unsigned char alpha = SkColorGetA(color);
    // Skip 100% transparent text; no need to draw anything.
    if (!alpha && graphicsContext->strokeStyle() == NoStroke)
        return;

    HDC hdc = 0;
    // Uniscribe counts the coordinates from the upper left, while WebKit uses
    // the baseline, so we have to subtract off the ascent.
    state.draw(graphicsContext, primaryFont()->platformData(), hdc, lroundf(point.x()), lroundf(point.y() - fontMetrics().ascent()), runInfo.bounds, runInfo.from, runInfo.to);
}
Ejemplo n.º 7
0
QSize KexiDropDownButton::sizeHint() const
{
    return QSize(fontMetrics().maxWidth() + 2*2, fontMetrics().height()*2 + 2*2);
}
Ejemplo n.º 8
0
AngleDialog::AngleDialog(MyApp *app, QWidget *parent): QDialog(parent)
{
    int width, i;
    mParamsOpen = true;
    mApp = app;
    setWindowTitle(tr("Angle Range & Tile Selection"));
    mDefocusLabel = new QLabel(tr("E&xpected defocus (um): "), this);
    mDefocusEdit = new QLineEdit("6.0", this);

    // Buddy means the accelerator key for the label sets focus to the text box
    // This is meaningless if there is no unique & included in the label!
    mDefocusLabel->setBuddy(mDefocusEdit);
    mDefocusEdit->setFixedWidth(fontMetrics().width("    99.99"));
    mDefocusEdit->setToolTip("Nominal defocus value in microns");

    mLowAngleLabel = new QLabel(tr("Starti&ng tilt angle: "), this);
    mLowAngleEdit = new QLineEdit(tr("-90.0"), this);
    mLowAngleLabel->setBuddy(mLowAngleEdit);
    mLowAngleEdit->setToolTip("Tilt angle at negative end of range to include in fit");

    mHighAngleLabel = new QLabel(tr("Endin&g tilt angle:  "), this);
    mHighAngleEdit = new QLineEdit(tr("90.0"), this);
    mHighAngleLabel->setBuddy(mHighAngleEdit);
    mHighAngleEdit->setToolTip("Tilt angle at positive end of range to include in fit");

    mStepUpButton = new QPushButton( tr("Step &Up"), this);
    mStepUpButton->setToolTip("Increase starting and ending angles by the step");

    mStepDownButton = new QPushButton( tr("Step &Down"), this);
    mStepDownButton->setToolTip("Decrease starting and ending angles by the step");
    width = (int)(1.35 * mStepDownButton->fontMetrics().width("Step Down") + 0.5);
    mStepDownButton->setFixedWidth(width);
    mStepUpButton->setFixedWidth(width);

    mAutofitButton = new QPushButton(mApp->getFitSingleViews() ?
                                     tr("Autofit A&ll Single Views") :
                                     tr("Autofit A&ll Steps"), this);
    mAutofitButton->setEnabled(false);
    mAutofitButton->setToolTip("Fit to all tilt angle ranges that fit within limits below");

    mRangeStepLabel = new QLabel(tr("Ste&p angle range by:  "), this);
    mRangeStepEdit = new QLineEdit(tr("90.0"), this);
    mRangeStepLabel->setBuddy(mRangeStepEdit);
    mRangeStepEdit->setToolTip("Amount to change starting and ending tilt angles with the"
                               " Step buttons");

    mAutoFromLabel = new QLabel(tr("Autof&it: "), this);
    mAutoFromEdit = new QLineEdit(tr("90.0"), this);
    mAutoFromLabel->setBuddy(mAutoFromEdit);
    mAutoFromEdit->setToolTip("Starting angle of range to cover with autofitting to "
                              "stepped ranges");
    width = mAutoFromEdit->fontMetrics().width("   -99.99");
    mAutoFromEdit->setFixedWidth(width);

    mAutoToLabel = new QLabel(tr("t&o"), this);
    mAutoToEdit = new QLineEdit(tr("90.0"), this);
    mAutoToEdit->setFixedWidth(width);
    mAutoToLabel->setBuddy(mAutoToEdit);
    mAutoToEdit->setToolTip("Ending angle of range to cover with autofitting to "
                            "stepped ranges");

    mFitSingleBox = new QCheckBox(tr("Fit each view separately"), this);
    mFitSingleBox->setToolTip("Fit every view in the range separately");
    mFitSingleBox->setChecked(mApp->getFitSingleViews());

    QFrame *line = new QFrame(this);
    line->setFrameShape( QFrame::HLine );
    line->setFrameShadow( QFrame::Sunken );

    QFrame *line2 = new QFrame(this);
    line2->setFrameShape( QFrame::HLine );
    line2->setFrameShadow( QFrame::Sunken );

    QFrame *line3 = new QFrame(this);
    line3->setFrameShape( QFrame::HLine );
    line3->setFrameShadow( QFrame::Sunken );

    mTileParamButton = new QPushButton("+", this);
    width = mTileParamButton->fontMetrics().width(" + ");
    mTileParamButton->setFixedWidth(width);
    mTileParamButton->setFixedHeight(width);
    QLabel *tileParamLabel = new QLabel(tr("Tile parameters"), this);

    mDefTolLabel = new QLabel(tr("Center defocus tol (nm)"), this);
    mDefTolEdit = new QLineEdit(tr("200"), this);
    mDefTolLabel->setBuddy(mDefTolEdit);
    mDefTolEdit->setMinimumWidth(fontMetrics().width(" 9999"));
    mDefTolEdit->setToolTip("Maximum defocus difference for central tiles");

    mLeftTolLabel = new QLabel(tr("Left defocus tol (nm)"), this);
    mLeftTolEdit = new QLineEdit(tr("200"), this);
    mLeftTolLabel->setBuddy(mLeftTolEdit);
    mLeftTolEdit->setToolTip("Maximum defocus difference for non-central tiles on left");

    mRightTolLabel = new QLabel(tr("Right defocus tol (nm)"), this);
    mRightTolEdit = new QLineEdit(tr("200"), this);
    mRightTolLabel->setBuddy(mRightTolEdit);
    mRightTolEdit->setToolTip("Maximum defocus difference for non-central tiles on right");

    mTileSizeLabel = new QLabel(tr("Tile size:           "), this);
    mTileSizeEdit = new QLineEdit(tr("256"),this);
    mTileSizeLabel->setBuddy(mTileSizeEdit);
    mTileSizeEdit->setToolTip("Size of square, overlapping tiles to analyze");

    mAxisAngleLabel = new QLabel(tr("Tilt axis angle:   "), this);
    mAxisAngleEdit = new QLineEdit( tr("0.0"), this);
    mAxisAngleLabel->setBuddy(mAxisAngleEdit);
    mAxisAngleEdit->setToolTip("Angle of tilt axis from vertical");

    mDefocusGroup = new QGroupBox(tr("Which defocus to use"), this);
    QButtonGroup *butGroup = new QButtonGroup(this);
    mExpDefocusRadio = new QRadioButton(tr("Expected defocus"));
    mExpDefocusRadio->setToolTip("Use expected defocus for shifting spectra "
                                 "from off-center tiles");
    mCurrDefocusRadio = new QRadioButton(tr("Current defocus estimate"));
    mCurrDefocusRadio->setToolTip("Use current defocus estimate for shifting "
                                  "spectra from off-center tiles");
    if (mApp->getDefocusOption())
        mCurrDefocusRadio->setChecked(true);
    else
        mExpDefocusRadio->setChecked(true);
    butGroup->addButton(mExpDefocusRadio);
    butGroup->addButton(mCurrDefocusRadio);

    QVBoxLayout *vbox = new QVBoxLayout;
    vbox->addWidget(mExpDefocusRadio);
    vbox->addWidget(mCurrDefocusRadio);
    mDefocusGroup->setLayout(vbox);

    // This is what I usually do for more compact group boxes
    vbox->setSpacing(0);
    vbox->setContentsMargins(5, 2, 5, 5);

    mIfAllGroup = new QGroupBox(tr("Initial tiles to include"), this);
    butGroup = new QButtonGroup(this);
    mOnlyCenterRadio = new QRadioButton(tr("Only central tiles"));
    mAllAtOnceRadio = new QRadioButton(tr("All tiles"));
    mOnlyCenterRadio->setToolTip("Compute curve initially only from central "
                                 "tiles");
    mAllAtOnceRadio->setToolTip("Compute curve using all available tiles");
    if (mApp->getInitTileOption())
        mAllAtOnceRadio->setChecked(true);
    else
        mOnlyCenterRadio->setChecked(true);
    butGroup->addButton(mAllAtOnceRadio);
    butGroup->addButton(mOnlyCenterRadio);

    QVBoxLayout *vbox2 = new QVBoxLayout;
    vbox2->addWidget(mOnlyCenterRadio);
    vbox2->addWidget(mAllAtOnceRadio);
    mIfAllGroup->setLayout(vbox2);
    vbox2->setSpacing(0);
    vbox2->setContentsMargins(5, 2, 5, 5);

    mSaveButton = new QPushButton( tr("&Store Defocus in Table"), this);
    mSaveButton->setEnabled(true);
    mSaveButton->setToolTip("Add current defocus value to table below");

    mApplyButton = new QPushButton( tr("&Apply"), this);
    mApplyButton->setDefault(true);
    mApplyButton->setEnabled(false);
    mApplyButton->setToolTip("Compute power spectra with current settings");

    mCloseButton = new QPushButton( tr("&Close"), this);
    mCloseButton->setFixedWidth(3 * fontMetrics().width("Close"));
    mCloseButton->setToolTip("Close this dialog");

    mTable = new QTableWidget(0, 4, this);
    mTable->setSelectionBehavior(QAbstractItemView::SelectRows);
    mTable->setSelectionMode(QAbstractItemView::SingleSelection);
    mTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
    QStringList headers;
    headers << "Start" << "End" << "Middle" << "Defocus";
    mTable->setHorizontalHeaderLabels(headers);
    width = (int)(1.66 * mTable->fontMetrics().width("Defocus"));
    for (i = 0; i < 4; i++)
        mTable->setColumnWidth(i, width);

    mDeleteButton = new QPushButton( tr("Delete Row"), this);
    mReturnButton = new QPushButton( tr("Set &Tilt Angles"), this);
    mToFileButton = new QPushButton( tr("Sa&ve to File"), this);
    mDeleteButton->setToolTip("Remove this row from the table");
    mReturnButton->setToolTip("Set starting and ending angles from this row and "
                              "recompute spectrum");
    mToFileButton->setToolTip("Save angle and defocus values in table to file");
    mTileParamButton->setFocusPolicy(Qt::NoFocus);
    mStepUpButton->setFocusPolicy(Qt::NoFocus);
    mStepDownButton->setFocusPolicy(Qt::NoFocus);
    mAutofitButton->setFocusPolicy(Qt::NoFocus);
    mFitSingleBox->setFocusPolicy(Qt::NoFocus);
    mDeleteButton->setFocusPolicy(Qt::NoFocus);
    mReturnButton->setFocusPolicy(Qt::NoFocus);
    mToFileButton->setFocusPolicy(Qt::NoFocus);
    mSaveButton->setFocusPolicy(Qt::NoFocus);

    connect(mDefocusEdit, SIGNAL(textChanged(const QString &)), this,
            SLOT(enableApplyButton(const QString &)) );
    connect(mLowAngleEdit, SIGNAL(textChanged(const QString &)), this,
            SLOT(enableApplyButton(const QString &)) );
    connect(mLowAngleEdit, SIGNAL(textChanged(const QString &)), this,
            SLOT(enableApplyButton(const QString &)) );
    connect(mDefTolEdit, SIGNAL(textChanged(const QString &)), this,
            SLOT(enableApplyButton(const QString &)) );
    connect(mTileSizeEdit, SIGNAL(textChanged(const QString &)), this,
            SLOT(enableApplyButton(const QString &)) );
    connect(mAxisAngleEdit, SIGNAL(textChanged(const QString &)), this,
            SLOT(enableApplyButton(const QString &)) );
    connect(mLeftTolEdit, SIGNAL(textChanged(const QString &)), this,
            SLOT(enableApplyButton(const QString &)) );
    connect(mRightTolEdit, SIGNAL(textChanged(const QString &)), this,
            SLOT(enableApplyButton(const QString &)) );

    connect(mExpDefocusRadio, SIGNAL(clicked()), this, SLOT(expDefocusChecked()));
    connect(mCurrDefocusRadio, SIGNAL(clicked()),this, SLOT(currDefocusChecked()));
    connect(mOnlyCenterRadio, SIGNAL(clicked()), this, SLOT(onlyCenterChecked()));
    connect(mAllAtOnceRadio, SIGNAL(clicked()), this, SLOT(allAtOnceChecked()) );

    connect(mTileParamButton, SIGNAL(clicked()), this, SLOT(tileParamsClicked()) );
    connect(mApplyButton, SIGNAL(clicked()), this, SLOT(applyClicked()) );
    connect(mStepUpButton, SIGNAL(clicked()), this, SLOT(stepUpClicked()) );
    connect(mAutofitButton, SIGNAL(clicked()), this, SLOT(autofitClicked()) );
    connect(mStepDownButton, SIGNAL(clicked()), this, SLOT(stepDownClicked()) );
    connect(mFitSingleBox, SIGNAL(toggled(bool)), this, SLOT(fitSingleToggled(bool)));
    connect(mCloseButton, SIGNAL(clicked()), this, SLOT(close()) );
    connect(mSaveButton, SIGNAL(clicked()), mApp, SLOT(saveCurrentDefocus()) );
    connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked()) );
    connect(mReturnButton, SIGNAL(clicked()), this, SLOT(setAnglesClicked()) );
    connect(mToFileButton, SIGNAL(clicked()), mApp, SLOT(writeDefocusFile()) );
    connect(mTable, SIGNAL(cellDoubleClicked(int, int)), this,
            SLOT(rowDoubleClicked(int, int)));

    QHBoxLayout *defHLayout = new QHBoxLayout;
    defHLayout->addWidget(mDefocusLabel);
    defHLayout->addWidget(mDefocusEdit);

    QHBoxLayout *defTolHLayout = new QHBoxLayout;
    defTolHLayout->addWidget(mDefTolLabel);
    defTolHLayout->addWidget(mDefTolEdit);

    QHBoxLayout *leftTolHLayout = new QHBoxLayout;
    leftTolHLayout->addWidget(mLeftTolLabel);
    leftTolHLayout->addWidget(mLeftTolEdit);

    QHBoxLayout *rightTolHLayout = new QHBoxLayout;
    rightTolHLayout->addWidget(mRightTolLabel);
    rightTolHLayout->addWidget(mRightTolEdit);

    QHBoxLayout *lAngleHLayout = new QHBoxLayout;
    lAngleHLayout->addWidget(mLowAngleLabel);
    lAngleHLayout->addWidget(mLowAngleEdit);

    QHBoxLayout *hAngleHLayout = new QHBoxLayout;
    hAngleHLayout->addWidget(mHighAngleLabel);
    hAngleHLayout->addWidget(mHighAngleEdit);

    QHBoxLayout *stepSizeHLayout = new QHBoxLayout;
    stepSizeHLayout->addWidget(mRangeStepLabel);
    stepSizeHLayout->addWidget(mRangeStepEdit);

    QHBoxLayout *stepButHLayout = new QHBoxLayout;
    stepButHLayout->addWidget(mStepUpButton);
    stepButHLayout->addWidget(mStepDownButton);

    QHBoxLayout *autoRangeHLayout = new QHBoxLayout;
    autoRangeHLayout->addWidget(mAutoFromLabel);
    autoRangeHLayout->addWidget(mAutoFromEdit);
    autoRangeHLayout->addWidget(mAutoToLabel);
    autoRangeHLayout->addWidget(mAutoToEdit);

    QHBoxLayout *tileParamHLayout = new QHBoxLayout;
    tileParamHLayout->addWidget(mTileParamButton);
    tileParamHLayout->addWidget(tileParamLabel);

    QHBoxLayout *tileSizeHLayout = new QHBoxLayout;
    tileSizeHLayout->addWidget(mTileSizeLabel);
    tileSizeHLayout->addWidget(mTileSizeEdit);

    QHBoxLayout *axisAngleHLayout = new QHBoxLayout;
    axisAngleHLayout->addWidget(mAxisAngleLabel);
    axisAngleHLayout->addWidget(mAxisAngleEdit);

    QHBoxLayout *bottomHLayout = new QHBoxLayout;
    bottomHLayout->addWidget(mCloseButton);

    QHBoxLayout *tabHLayout = new QHBoxLayout;
    tabHLayout->addWidget(mDeleteButton);
    tabHLayout->addWidget(mReturnButton);
    tabHLayout->addWidget(mToFileButton);

    QVBoxLayout *leftVLayout = new QVBoxLayout;
    leftVLayout->addLayout(lAngleHLayout);
    leftVLayout->addLayout(hAngleHLayout);
    leftVLayout->addWidget(line);
    leftVLayout->addLayout(stepSizeHLayout);
    leftVLayout->addLayout(stepButHLayout);
    leftVLayout->addWidget(line2);
    leftVLayout->addWidget(mAutofitButton);
    leftVLayout->addLayout(autoRangeHLayout);
    leftVLayout->addWidget(mFitSingleBox);
    leftVLayout->addWidget(line3);
    leftVLayout->addLayout(tileParamHLayout);
    leftVLayout->addLayout(defTolHLayout);
    leftVLayout->addLayout(leftTolHLayout);
    leftVLayout->addLayout(rightTolHLayout);

    QVBoxLayout *rightVLayout = new QVBoxLayout;
    rightVLayout->addLayout(defHLayout);
    rightVLayout->addWidget(mDefocusGroup);
    rightVLayout->addWidget(mIfAllGroup);
    rightVLayout->addWidget(mApplyButton);
    rightVLayout->addWidget(mSaveButton);
    rightVLayout->addStretch();
    rightVLayout->addLayout(tileSizeHLayout);
    rightVLayout->addLayout(axisAngleHLayout);

    QHBoxLayout *topHLayout = new QHBoxLayout;
    topHLayout->addLayout(leftVLayout);
    topHLayout->addLayout(rightVLayout);

    QVBoxLayout *mainVLayout = new QVBoxLayout(this);
    mainVLayout->addLayout(topHLayout);
    mainVLayout->addWidget(mTable);
    mainVLayout->setStretchFactor(mTable, 100);
    mainVLayout->addLayout(tabHLayout);
    mainVLayout->addLayout(bottomHLayout);
}
GraphicsPortItem::GraphicsPortItem(GraphicsClientItemsClient *client_, const QString &fullPortName_, int style_, QFont font_, int padding, QGraphicsItem *parent) :
    QGraphicsPathItem(parent),
    client(client_),
    fullPortName(fullPortName_),
    shortPortName(fullPortName.split(":")[1]),
    dataType(client->getPortType(fullPortName)),
    isInput(client->getPortFlags(fullPortName) & JackPortIsInput),
    style(style_),
    font(font_),
    showMenu(false)
{
    bool gradient = false;
    QColor captionColor(0xfc, 0xf9, 0xc2);
    setPen(QPen(QBrush(Qt::black), 2));
    setBrush(QBrush(captionColor));
    setFlags(QGraphicsItem::ItemSendsScenePositionChanges);
    setCursor(Qt::ArrowCursor);
    font.setStyleStrategy(QFont::PreferAntialias);
    QFontMetrics fontMetrics(font);
    int portPadding = padding;

    QGraphicsSimpleTextItem *portTextItem = new QGraphicsSimpleTextItem(shortPortName, this);
    portTextItem->setFont(font);
    portTextItem->setPos(portPadding, 0);
    portRect = portTextItem->boundingRect().adjusted(-portPadding, -portPadding, portPadding, portPadding).translated(portTextItem->pos());

    QPainterPath portPath;
    if (style == 0) {
        portPath = portPath.united(EllipsePath(portRect));
    } else if (style == 1) {
        portPath = portPath.united(SpeechBubblePath(portRect, portRect.height() / 4, portRect.height() / 4, Qt::AbsoluteSize));
    } else if (style == 2) {
        portPath = portPath.united(RoundedRectanglePath(portRect, portPadding + fontMetrics.height() / 2, portPadding + fontMetrics.height() / 2));
    } else if (style == 3) {
        portPath = portPath.united(RectanglePath(portRect));
    }
    setPath(portPath);

    // register the port registration callback at the jack server:
    QObject::connect(client, SIGNAL(portRegistered(QString,QString,int)), this, SLOT(onPortRegistered(QString,QString,int)), Qt::QueuedConnection);
    QObject::connect(client, SIGNAL(portUnregistered(QString,QString,int)), this, SLOT(onPortUnregistered(QString,QString,int)), Qt::QueuedConnection);
    QObject::connect(client, SIGNAL(portConnected(QString,QString)), this, SLOT(onPortConnected(QString,QString)), Qt::QueuedConnection);
    QObject::connect(client, SIGNAL(portDisconnected(QString,QString)), this, SLOT(onPortDisconnected(QString,QString)), Qt::QueuedConnection);

    if (gradient) {
        QLinearGradient gradient(portRect.topLeft(), portRect.bottomRight());
        gradient.setColorAt(0, Qt::white);
        gradient.setColorAt(1, QColor("wheat"));
        setBrush(QBrush(gradient));
    }

    // create the context menu:
    connectMenu = contextMenu.addMenu("Connect");
    disconnectMenu = contextMenu.addMenu("Disconnect");
    // create the entries in connect- and disconnect-menus, as well as graphical representations of existing connections:
    QStringList connectedPorts = client->getConnectedPorts(fullPortName);
    QSet<QString> connectedPortsSet;
    for (int i = 0; i < connectedPorts.size(); i++) {
        // create an entry in the disconnect-menu:
        QAction *action = disconnectMenu->addAction(connectedPorts[i]);
        action->setData(connectedPorts[i]);
        QObject::connect(action, SIGNAL(triggered()), this, SLOT(onDisconnectAction()));
        mapPortNamesToActions[connectedPorts[i]] = action;
        connectedPortsSet.insert(connectedPorts[i]);
        // create a graphical representation of the connection:
        if (isInput) {
            client->getPortConnectionItem(connectedPorts[i], fullPortName)->setPos(fullPortName, getConnectionScenePos());
        } else {
            client->getPortConnectionItem(fullPortName, connectedPorts[i])->setPos(fullPortName, getConnectionScenePos());
        }
    }
    // get all available ports that can be connected to this:
    QStringList connectablePorts = client->getPorts(0, dataType.toAscii().data(), isInput ? JackPortIsOutput : JackPortIsInput);
    for (int i = 0; i < connectablePorts.size(); i++) {
        // skip ports that are already connected:
        if (!connectedPortsSet.contains(connectablePorts[i])) {
            // create an entry in the connect-menu:
            QAction *action = connectMenu->addAction(connectablePorts[i]);
            action->setData(connectablePorts[i]);
            QObject::connect(action, SIGNAL(triggered()), this, SLOT(onConnectAction()));
            mapPortNamesToActions[connectablePorts[i]] = action;
        }
    }
    disconnectMenu->setEnabled(disconnectMenu->actions().size());
    connectMenu->setEnabled(connectMenu->actions().size());
}
Ejemplo n.º 10
0
QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer *layer, const QgsRectangle &extent ): QgsRasterRendererWidget( layer, extent )
{
  setupUi( this );

  mCalculatingProgressBar->hide();
  mCancelButton->hide();

  mContextMenu = new QMenu( tr( "Options" ), this );
  mContextMenu->addAction( tr( "Change Color…" ), this, SLOT( changeColor() ) );
  mContextMenu->addAction( tr( "Change Opacity…" ), this, SLOT( changeOpacity() ) );
  mContextMenu->addAction( tr( "Change Label…" ), this, SLOT( changeLabel() ) );

  mAdvancedMenu = new QMenu( tr( "Advanced Options" ), this );
  QAction *mLoadFromLayerAction = mAdvancedMenu->addAction( tr( "Load Classes from Layer" ) );
  connect( mLoadFromLayerAction, &QAction::triggered, this, &QgsPalettedRendererWidget::loadFromLayer );
  QAction *loadFromFile = mAdvancedMenu->addAction( tr( "Load Color Map from File…" ) );
  connect( loadFromFile, &QAction::triggered, this, &QgsPalettedRendererWidget::loadColorTable );
  QAction *exportToFile = mAdvancedMenu->addAction( tr( "Export Color Map to File…" ) );
  connect( exportToFile, &QAction::triggered, this, &QgsPalettedRendererWidget::saveColorTable );


  mButtonAdvanced->setMenu( mAdvancedMenu );

  mModel = new QgsPalettedRendererModel( this );
  mTreeView->setSortingEnabled( false );
  mTreeView->setModel( mModel );

#ifdef ENABLE_MODELTEST
  new ModelTest( mModel, this );
#endif

  mSwatchDelegate = new QgsColorSwatchDelegate( this );
  mTreeView->setItemDelegateForColumn( QgsPalettedRendererModel::ColorColumn, mSwatchDelegate );
  mTreeView->setColumnWidth( QgsPalettedRendererModel::ColorColumn, Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 6.6 );
  mTreeView->setContextMenuPolicy( Qt::CustomContextMenu );
  mTreeView->setSelectionMode( QAbstractItemView::ExtendedSelection );
  mTreeView->setDragEnabled( true );
  mTreeView->setAcceptDrops( true );
  mTreeView->setDropIndicatorShown( true );
  mTreeView->setDragDropMode( QAbstractItemView::InternalMove );
  mTreeView->setSelectionBehavior( QAbstractItemView::SelectRows );
  mTreeView->setDefaultDropAction( Qt::MoveAction );

  connect( mTreeView, &QTreeView::customContextMenuRequested, this, [ = ]( QPoint ) { mContextMenu->exec( QCursor::pos() ); }
         );

  btnColorRamp->setShowRandomColorRamp( true );

  connect( btnColorRamp, &QgsColorRampButton::colorRampChanged, this, &QgsPalettedRendererWidget::applyColorRamp );

  mBandComboBox->setLayer( mRasterLayer );

  if ( mRasterLayer )
  {
    QgsRasterDataProvider *provider = mRasterLayer->dataProvider();
    if ( !provider )
    {
      return;
    }
    setFromRenderer( mRasterLayer->renderer() );
  }

  connect( mBandComboBox, &QgsRasterBandComboBox::bandChanged, this, &QgsRasterRendererWidget::widgetChanged );
  connect( mModel, &QgsPalettedRendererModel::classesChanged, this, &QgsPalettedRendererWidget::widgetChanged );
  connect( mDeleteEntryButton, &QPushButton::clicked, this, &QgsPalettedRendererWidget::deleteEntry );
  connect( mButtonDeleteAll, &QPushButton::clicked, mModel, &QgsPalettedRendererModel::deleteAll );
  connect( mAddEntryButton, &QPushButton::clicked, this, &QgsPalettedRendererWidget::addEntry );
  connect( mClassifyButton, &QPushButton::clicked, this, &QgsPalettedRendererWidget::classify );

  QgsRasterDataProvider *provider = mRasterLayer->dataProvider();
  if ( provider )
  {
    mLoadFromLayerAction->setEnabled( !provider->colorTable( mBandComboBox->currentBand() ).isEmpty() );
  }
  else
  {
    mLoadFromLayerAction->setEnabled( false );
  }

  connect( QgsProject::instance(), static_cast < void ( QgsProject::* )( QgsMapLayer * ) >( &QgsProject::layerWillBeRemoved ), this, &QgsPalettedRendererWidget::layerWillBeRemoved );
  connect( mBandComboBox, &QgsRasterBandComboBox::bandChanged, this, &QgsPalettedRendererWidget::bandChanged );
}
Ejemplo n.º 11
0
QSize LineColumnLabel::sizeHint() const
{
    return fontMetrics().boundingRect(m_maxText).size();
}
Ejemplo n.º 12
0
/*!
  painting functions
*/
void PYHistogramTip::draw(QPainter *painter)
{
    painter->save();

    QPainterPath BgPath;

    if(m_bLeft)
    {
        QPointF LeftPot(0,PYHT_BG_TOP_SPACE*2);
        QPointF LeftTopPot(PYHT_BG_LEFT_SPACE,PYHT_BG_TOP_SPACE);
        QPointF TopLeftPot(PYHT_BG_LEFT_SPACE,0);
        QPointF RightTopPot(width(),0);
        QPointF RightBottomPot(width(),height());
        QPointF LeftBottomPot(PYHT_BG_LEFT_SPACE,height());
        QPointF LeftBottomTopPot(PYHT_BG_LEFT_SPACE,PYHT_BG_TOP_SPACE*2);

        BgPath.moveTo(LeftPot);
        BgPath.lineTo(LeftTopPot);
        BgPath.lineTo(TopLeftPot);
        BgPath.lineTo(RightTopPot);
        BgPath.lineTo(RightBottomPot);
        BgPath.lineTo(LeftBottomPot);
        BgPath.lineTo(LeftBottomTopPot);
        BgPath.lineTo(LeftPot);

    }else{
        QPointF TopLeftPot(0,0);
        QPointF TopRightPot(width() - PYHT_BG_LEFT_SPACE,0);
        QPointF RightTopPot(width() - PYHT_BG_LEFT_SPACE,PYHT_BG_TOP_SPACE);
        QPointF RightPot(width(),height()/2);
        QPointF RightBottomPot(width() - PYHT_BG_LEFT_SPACE,height()/2);
        QPointF BottomRightPot(width()-PYHT_BG_LEFT_SPACE,height());
        QPointF BottomLeftPot(0,height());

        BgPath.moveTo(TopLeftPot);
        BgPath.lineTo(TopRightPot);
        BgPath.lineTo(RightTopPot);
        BgPath.lineTo(RightPot);
        BgPath.lineTo(RightBottomPot);
        BgPath.lineTo(BottomRightPot);
        BgPath.lineTo(BottomLeftPot);
        BgPath.lineTo(TopLeftPot);

    }

    painter->setPen(Qt::NoPen);

#ifdef PYHT_BG_APPLY_LINEARGRADIENT
    QLinearGradient BgGradient(QPoint(0,0),QPoint(0,height()));
    BgGradient.setColorAt(0.0,PYHT_BG_START_COLOR);
    BgGradient.setColorAt(1.0,PYHT_BG_END_COLOR);
    painter->setBrush(BgGradient);
#else
    painter->setBrush(PYHT_BG_BRUSH_COLOR);
#endif

#ifdef PYHT_SCHEME2
    QLinearGradient Scheme2Gradient(QPoint(0,0),QPoint(0,height()));
    Scheme2Gradient.setColorAt(0.0,PYHT_BG_START_COLOR);
    Scheme2Gradient.setColorAt(1.0,PYHT_BG_END_COLOR);
    painter->setBrush(Scheme2Gradient);
#endif

#ifdef PYHT_SCHEME3
    QLinearGradient Scheme3Gradient(QPoint(0,0),QPoint(0,height()));
    Scheme3Gradient.setColorAt(0.0,PYHT_BG_START_COLOR);
    Scheme3Gradient.setColorAt(1.0,PYHT_BG_END_COLOR);
    painter->setBrush(Scheme3Gradient);
#endif

    painter->drawPath(BgPath);

    QPointF TextPot(PYHT_BG_LEFT_SPACE*2,PYHT_BG_TOP_SPACE*2);


    painter->setPen(PYHT_TEXT_COLOR);

#if 1
    QFont TextFont;
    TextFont.setBold(true);
    painter->setFont(TextFont);
#endif

    painter->drawText(TextPot,m_strTip);


    painter->restore();

    qreal TextLength = fontMetrics().width(m_strTip);
    m_width = PYHT_BG_LEFT_SPACE * 2 + TextLength * 1.5 ;
    m_height = PYHT_BG_TOP_SPACE * 2 + fontMetrics().height();
    setFixedSize(QSize(m_width,m_height));
}
Ejemplo n.º 13
0
void TimelineWidget::draw(QPainter *pPainter, const QRect &update_rect)
{
   scaleDraw()->draw(pPainter, palette());

   if(mpD->animCount > 0)
   {
      const std::vector<Animation*> &animations = mpD->mpController->getAnimations();
      int ypos = mpD->animRect.y();
      for(std::vector<Animation*>::const_iterator animation = animations.begin(); animation != animations.end(); ++animation)
      {
         int xpos = transform((*animation)->getStartValue());
         int xend = transform((*animation)->getStopValue());
         int animWidth = xend - xpos;
         if(mpDragging == *animation)
         {
            int xdiff = mDragPos.x() - mDragStartPos.x();
            switch(mDragType)
            {
            case DRAGGING_MOVE:
               xpos += xdiff;
               break;
            case DRAGGING_LEFT:
               xpos += xdiff;
               animWidth -= xdiff;
               break;
            case DRAGGING_RIGHT:
               animWidth += xdiff;
               break;
            }
         }
         pPainter->setBrush(palette().brush(QPalette::Base));
         pPainter->drawRect(xpos, ypos, animWidth, mpD->animHeight);
         qDrawShadePanel(pPainter, xpos, ypos, animWidth, mpD->animHeight, palette());
         int textXpos = xpos + mpD->borderWidth;
         int textYpos = ypos + (fontMetrics().height() + mpD->animHeight) / 2;
         pPainter->drawText(textXpos, textYpos, QString::fromStdString((*animation)->getName()));
         if(mpDragging != *animation)
         {
            const std::vector<AnimationFrame> &frames = (*animation)->getFrames();
            pPainter->setPen(QPen(QBrush(Qt::lightGray), 1));
            int prevPos = 0;
            for(std::vector<AnimationFrame>::const_iterator frame = frames.begin(); frame != frames.end(); ++frame)
            {
               int framePos = transform((*animation)->getFrameType() == FRAME_ID ? frame->mFrameNumber : frame->mTime);
               while((framePos - prevPos) < 32 && ++frame != frames.end())
               {
                  framePos = transform((*animation)->getFrameType() == FRAME_ID ? frame->mFrameNumber : frame->mTime);
               }
               if(frame == frames.end())
               {
                  break;
               }
#pragma message(__FILE__ "(" STRING(__LINE__) ") : warning : Add code to draw thumbnails if they are available (tclarke)")
               pPainter->drawLine(framePos, ypos, framePos, ypos + mpD->animHeight);
               prevPos = framePos;
            }
         }
         ypos += mpD->animHeight + mpD->animSpacing;
      }
     int lineX = transform(mpD->mpController->getCurrentFrame());
     pPainter->setPen(QPen(QBrush(Qt::darkGreen), 1, Qt::DashLine, Qt::RoundCap));
     pPainter->drawLine(lineX, mpD->borderWidth, lineX, mpD->animRect.bottom());
   }
}
Ejemplo n.º 14
0
LabelTab::LabelTab(PlotItem* plotItem, QWidget *parent)
  : DialogTab(parent), _plotItem(plotItem), _activeLineEdit(0), _fontDirty(false) {

  setupUi(this);

  int h = fontMetrics().lineSpacing();
  _globalLabelBold->setIcon(KstGetIcon("kst_bold"));
  _globalLabelBold->setFixedHeight(h);
  _globalLabelBold->setFixedWidth(h);
  _globalLabelItalic->setIcon(KstGetIcon("kst_italic"));
  _globalLabelItalic->setFixedHeight(h);
  _globalLabelItalic->setFixedWidth(h);
  _globalLabelColor->setFixedHeight(h);
  _globalLabelColor->setFixedWidth(h);

  _topLabelText->setFixedHeight(h*4/3);
  _bottomLabelText->setFixedHeight(h*4/3);
  _leftLabelText->setFixedHeight(h*4/3);
  _rightLabelText->setFixedHeight(h*4/3);

  setTabTitle(tr("Labels"));

  setGlobalFont(_plotItem->globalFont());
  _globalLabelColor->setColor(_plotItem->globalFontColor());
  _globalLabelFontSize->setValue(_plotItem->globalFontScale());

  _topLabelText->setObjectStore(kstApp->mainWindow()->document()->objectStore());
  _bottomLabelText->setObjectStore(kstApp->mainWindow()->document()->objectStore());
  _leftLabelText->setObjectStore(kstApp->mainWindow()->document()->objectStore());
  _rightLabelText->setObjectStore(kstApp->mainWindow()->document()->objectStore());

  connect(_topLabelText, SIGNAL(textChanged()), this, SIGNAL(modified()));
  connect(_leftLabelText, SIGNAL(textChanged()), this, SIGNAL(modified()));
  connect(_bottomLabelText, SIGNAL(textChanged()), this, SIGNAL(modified()));
  connect(_rightLabelText, SIGNAL(textChanged()), this, SIGNAL(modified()));

  connect(_topLabelText, SIGNAL(textChanged()), this, SLOT(_enableLabelLabels()));
  connect(_bottomLabelText, SIGNAL(textChanged()), this, SLOT(_enableLabelLabels()));
  connect(_leftLabelText, SIGNAL(textChanged()), this, SLOT(_enableLabelLabels()));
  connect(_rightLabelText, SIGNAL(textChanged()), this, SLOT(_enableLabelLabels()));

  connect(_autoScaleNumberAxis, SIGNAL(stateChanged(int)), this, SIGNAL(modified()));
  connect(_showLegend, SIGNAL(stateChanged(int)), this, SIGNAL(modified()));

  connect(_editLegendContents, SIGNAL(pressed()), _plotItem->legend(), SLOT(edit()));

  connect(_globalLabelFontSize, SIGNAL(valueChanged(double)), this, SIGNAL(globalFontUpdate()));
  connect(_globalLabelBold, SIGNAL(toggled(bool)), this, SIGNAL(globalFontUpdate()));
  connect(_globalLabelItalic, SIGNAL(toggled(bool)), this, SIGNAL(globalFontUpdate()));
  connect(_globalLabelFontFamily, SIGNAL(currentFontChanged(QFont)), this, SIGNAL(globalFontUpdate()));
  connect(_globalLabelColor, SIGNAL(changed(QColor)), this, SIGNAL(globalFontUpdate()));
  connect(_globalLabelBold, SIGNAL(toggled(bool)), this, SLOT(buttonUpdate()));
  connect(_globalLabelItalic, SIGNAL(toggled(bool)), this, SLOT(buttonUpdate()));

  connect(_topLabelAuto, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
  connect(_leftLabelAuto, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
  connect(_bottomLabelAuto, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
  connect(_rightLabelAuto, SIGNAL(toggled(bool)), this, SIGNAL(modified()));

  connect(_topLabelAuto, SIGNAL(toggled(bool)), this, SLOT(activateFields()));
  connect(_leftLabelAuto, SIGNAL(toggled(bool)), this, SLOT(activateFields()));
  connect(_bottomLabelAuto, SIGNAL(toggled(bool)), this, SLOT(activateFields()));
  connect(_rightLabelAuto, SIGNAL(toggled(bool)), this, SLOT(activateFields()));

}
Ejemplo n.º 15
0
TlinearChart::TlinearChart(Texam* exam, Tchart::Tsettings& settings, QWidget* parent) :
    TmainChart(exam, settings, parent)
{
// Determine y value type and its maximal value to prepare Y axis
  switch (settings.yValue) {
    case TmainLine::e_prepareTime: {
      quint32 prepTime = 0;
      for(int i = 0; i < exam->count(); i++)
        prepTime = qMax(prepTime, exam->question(i)->attempt(0)->prepareTime());
      yAxis->setMaxValue((qreal)prepTime / 10.0);
      yAxis->setUnit(TYaxis::e_prepareTime);
      break;
    }
    case TmainLine::e_attemptsCount: {
      int attemptsNr = 0;
      for(int i = 0; i < exam->count(); i++)
        attemptsNr = qMax(attemptsNr, exam->question(i)->attemptsCount());
      yAxis->setMaxValue(attemptsNr, false);
      yAxis->setUnit(TYaxis::e_attemptsCount);
      break;
    }
    case TmainLine::e_playedCount: {
      int playedNr = 0;
      for(int i = 0; i < exam->count(); i++)
        playedNr = qMax(playedNr, exam->question(i)->totalPlayBacks());
      yAxis->setMaxValue(playedNr, false);
      yAxis->setUnit(TYaxis::e_playedCount);
      break;
    }
    case TmainLine::e_effectiveness: {
      yAxis->setMaxValue(100.0); // 100% looks good for this kind
      yAxis->setUnit(TYaxis::e_effectiveness);
      break;
    }
    default: {
      quint16 maxTime = 0;
      for(int i = 0; i < exam->count(); i++)
        maxTime = qMax(maxTime, exam->question(i)->time);
      yAxis->setMaxValue((qreal)maxTime / 10.0);
      break;
    }
  }
  
	if (settings.order == e_byNumber) {
		xAxis->setAnswersList(currExam->answList(), currExam->level());
		prepareChart(currExam->count());
		m_mainLine = new TmainLine(currExam->answList(), this, settings.yValue);
		if (settings.yValue == TmainLine::e_questionTime) {
			qreal aTime = 0 , prev = 0;
			int firstCorrect = 0, okCount = 0;
			for(int i = 0; i < exam->count(); i++) { // looking for first correct answer
				if (!exam->question(i)->isWrong() || (!exam->question(i)->isWrong() && settings.inclWrongAnsw)) {
					firstCorrect = i;
					prev = exam->question(i)->time;
					okCount++;
					aTime = prev;
					break;
				}
			}
      int prevX = firstCorrect + 1;
      for(int i = firstCorrect + 1; i < exam->count(); i++) {
        if (exam->question(i)->isWrong())
          continue; // skip wrong answers in aver time
        else 
          aTime = (aTime * okCount + (exam->question(i)->time)) / (okCount + 1);
        
        okCount++;
        TgraphicsLine *averProgress = new TgraphicsLine();
        scene->addItem(averProgress);
        averProgress->setPen(QPen(averColor.darker(120), 3, Qt::DotLine));
        averProgress->setLine(xAxis->mapValue(prevX) + xAxis->pos().x(), yAxis->mapValue(prev / 10.0),
                              xAxis->mapValue(i + 1) + xAxis->pos().x(), yAxis->mapValue(aTime / 10.0));
        prevX = i + 1;
        averProgress->setZValue(20);
        prev = aTime;
      }
      
      if (exam->averageReactonTime() > 0) {
          TgraphicsLine *averLine = new TgraphicsLine(0, "<p>" +
              TexTrans::averAnsverTimeTxt() + 
              QString("<br><big><b>%1</b></big></p>").arg(Texam::formatReactTime(exam->averageReactonTime(), true)) );
          scene->addItem(averLine);
          averLine->setZValue(15);
          averLine->setPen(QPen(averColor, 2));
          averLine->setLine(xAxis->mapValue(1) + xAxis->pos().x(), yAxis->mapValue(exam->averageReactonTime() / 10.0),
              xAxis->mapValue(exam->count()) + xAxis->pos().x(), yAxis->mapValue(exam->averageReactonTime() / 10.0));
      }
  // rest of cases are available only for melodies
		}
  }
  
  if (settings.order == e_byNote || settings.order == e_byFret ||
          settings.order == e_byKey || settings.order == e_byAccid || 
          settings.order == e_byQuestAndAnsw || settings.order == e_byMistake) {
      sort();
      xAxis->setAnswersLists(sortedLists, exam->level());
      int ln = 0;
      for (int i = 0; i < sortedLists.size(); i++)
        ln += sortedLists[i].size();
      prepareChart(ln);
      m_mainLine = new TmainLine(sortedLists, this, settings.yValue);
      
      int goodOffset = 0; // 0 when not unrelated question list inside
      if (hasListUnrelated)
        goodOffset = -1; // do not perform a last loop 
      int cnt = 1;
      if (settings.yValue != TmainLine::e_questionTime) {
        QTimer::singleShot(10, this, SLOT(ajustChartHeight()));
        return;
      }
  // paint lines with average time of all the same notes/frets
     for (int i = 0; i < goodSize + goodOffset; i++) { // skip wrong answers if separated
        if (sortedLists[i].size() > 1) {
        TgraphicsLine *averTimeLine = new TgraphicsLine(&sortedLists[i]);

        averTimeLine->setText(sortedLists[i].fullDescription());
        scene->addItem(averTimeLine);
        averTimeLine->setZValue(46);
        averTimeLine->setPen(QPen(averColor, 3)); // sea blue
        averTimeLine->setLine(xAxis->mapValue(cnt - 0.4) + xAxis->pos().x(), yAxis->mapValue(sortedLists[i].averTime() / 10.0),
          xAxis->mapValue(cnt + sortedLists[i].size() -0.6) + xAxis->pos().x(), yAxis->mapValue(sortedLists[i].averTime() / 10.0));
        }
        cnt += sortedLists[i].size();
      }
      cnt = 1;
      // paint highlights under grouped items
      for (int i = 0; i < sortedLists.size(); i++) {
          QGraphicsRectItem *groupBg = new QGraphicsRectItem();
          scene->addItem(groupBg);
          QColor hiCol = palette().highlight().color();
          hiCol.setAlpha(60);
          if (i%2) {
            groupBg->setBrush(QBrush(hiCol));
            groupBg->setPen(Qt::NoPen);
            groupBg->setRect(xAxis->mapValue(cnt), 0, sortedLists[i].size() * xAxis->questWidth(), yAxis->boundingRect().height());
            groupBg->setZValue(-1);
          }
          cnt += sortedLists[i].size();
      }
  // fret number over the chart
    if (settings.order == e_byFret) {
      cnt = 1;
      for (int i = 0; i < goodSize; i++) { 
        QGraphicsTextItem *fretText = getTextItem(30);
        QString hintText = "<b>";
        if (goodOffset && (i == goodSize -1))
          hintText += QApplication::translate("TlinearChart", "questions unrelated<br>with chart type");
        else
          hintText += QString("%1").arg(TfingerPos::romanFret(sortedLists[i].first()->qa.pos.fret()));
        hintText += "</b>";
        fretText->setHtml(hintText);
				TgraphicsTextTip::alignCenter(fretText);
				qreal sc = 1.0;
        if (sortedLists[i].size() * xAxis->questWidth() < fretText->boundingRect().width()) {
            sc = (sortedLists[i].size() * xAxis->questWidth()) / fretText->boundingRect().width();
            fretText->setScale(sc);
        }
        fretText->setPos(xAxis->mapValue(cnt) + 
        (sortedLists[i].size() * xAxis->questWidth() - fretText->boundingRect().width() * sc) / 2,
                         yAxis->mapValue(yAxis->maxValue()));        
        
        cnt += sortedLists[i].size();
      }      
    }
  // key signature names over the chart
    if (settings.order == e_byKey) {
      cnt = 1;
      QColor tc = palette().text().color();
      for (int i = 0; i < goodSize; i++) { 
        QGraphicsTextItem *keyText = getTextItem(16);
        QString hintText = "<b>";
        if (goodOffset && (i == goodSize -1))
          hintText += QApplication::translate("TlinearChart", "questions unrelated<br>with chart type");
        else {
            hintText += QString("%1").arg(sortedLists[i].first()->key.getName());
            hintText += "<br>" + getWasInAnswOrQuest(TQAtype::e_asNote, sortedLists[i].operator[](0).qaPtr);
        }
        hintText += "</b>";
        keyText->setHtml(hintText);
				TgraphicsTextTip::alignCenter(keyText);
        qreal sc = 1.0;
        if (sortedLists[i].size() * xAxis->questWidth() < keyText->boundingRect().width()) {
            sc = (sortedLists[i].size() * xAxis->questWidth()) / keyText->boundingRect().width();
            keyText->setScale(sc);
        }
        keyText->setPos(xAxis->mapValue(cnt) + 
        (sortedLists[i].size() * xAxis->questWidth() - keyText->boundingRect().width() * sc) / 2, 
                         yAxis->mapValue(yAxis->maxValue()));        
        cnt += sortedLists[i].size();
      }
    }
// accidentals over the chart
    if (settings.order == e_byAccid) {
      cnt = 1;
      for (int i = 0; i < goodSize; i++) { 
        QGraphicsTextItem *accidentalText = getTextItem(30);
        QString hintText;
        if (goodOffset && (i == goodSize -1))
          hintText += QApplication::translate("TlinearChart", "questions unrelated<br>with chart type") + "</span>";
        else 
          if (kindOfAccids[i])
            hintText += QString("%1").arg(accidToNotka(kindOfAccids[i], 40));
          else
            hintText += QApplication::translate("TlinearChart", "without accidentals");
        accidentalText->setHtml(hintText);
				TgraphicsTextTip::alignCenter(accidentalText);
        accidentalText->setPos(xAxis->mapValue(cnt) + 
        (sortedLists[i].size() * xAxis->questWidth() - accidentalText->boundingRect().width()) / 2, 
                         yAxis->mapValue(yAxis->maxValue()));        
        cnt += sortedLists[i].size();
      }      
    }
  // question/answer type over the chart
		if (settings.order == e_byQuestAndAnsw) {
			cnt = 1;
			for (int i = 0; i < goodSize; i++) { 
        QGraphicsTextItem *qaText = getTextItem(30);
				int nootFontSize = fontMetrics().boundingRect("A").height() * 2;
        QString hintText;
				if (exam->melodies()) {
					if (sortedLists[i].first()->questionAs == TQAtype::e_asNote)
						hintText = TexTrans::playMelodyTxt();
					else
						hintText = TexTrans::writeMelodyTxt();
				} else
					hintText = TnooFont::span(TquestionAsWdg::qaTypeSymbol(sortedLists[i].first()->questionAs) + "?", nootFontSize) + 
							"<br>" + TnooFont::span(TquestionAsWdg::qaTypeSymbol(sortedLists[i].first()->answerAs) + "!", nootFontSize);
        qaText->setHtml(hintText);
				TgraphicsTextTip::alignCenter(qaText);
				qreal sc = 1.0;
        if (sortedLists[i].size() * xAxis->questWidth() < qaText->boundingRect().width()) {
            sc = (sortedLists[i].size() * xAxis->questWidth()) / qaText->boundingRect().width();
            qaText->setScale(sc);
        }
        qaText->setPos(xAxis->mapValue(cnt) + 
        (sortedLists[i].size() * xAxis->questWidth() - qaText->boundingRect().width() * sc) / 2, 
                         yAxis->mapValue(0) - yAxis->length());        
        cnt += sortedLists[i].size();
      }
		}  
  }
  QTimer::singleShot(10, this, SLOT(ajustChartHeight()));
}
Ejemplo n.º 16
0
LineNumbersWidget::LineNumbersWidget(QWidget *par): QWidget(par), InpDataInterface()
{
    width=fontMetrics().width(QLatin1Char('9'))*7;
}
Ejemplo n.º 17
0
PageSelector::PageSelector( QWidget* parent, int maxPg ) : QWidget( parent, 0 )
{
	PageCountString = "%1" ;
	LastPG = maxPg;
	APage = 1;
	PageSelectorLayout = new QHBoxLayout( this );
	PageSelectorLayout->setMargin(0);
	PageSelectorLayout->setSpacing(1);

#if OPTION_USE_QTOOLBUTTON
	Start = new QToolButton( this );
	Start->setAutoRaise(OPTION_FLAT_BUTTON);
	Back = new QToolButton( this );
	Back->setAutoRaise(OPTION_FLAT_BUTTON);
	Forward = new QToolButton( this );
	Forward->setAutoRaise(OPTION_FLAT_BUTTON);
	Last = new QToolButton( this );
	Last->setAutoRaise(OPTION_FLAT_BUTTON);
#else
	Start = new QPushButton( this );
	Start->setDefault( false );
	Start->setAutoDefault( false );
	Start->setFlat(OPTION_FLAT_BUTTON);
	Back = new QPushButton( this );
	Back->setDefault( false );
	Back->setAutoDefault( false );
	Back->setFlat(OPTION_FLAT_BUTTON);
	Forward = new QPushButton( this );
	Forward->setDefault( false );
	Forward->setAutoDefault( false );
	Forward->setFlat(OPTION_FLAT_BUTTON);
	Last = new QPushButton( this );
	Last->setDefault( false );
	Last->setAutoDefault( false );
	Last->setFlat(OPTION_FLAT_BUTTON);
#endif
	Start->setIcon(QIcon(loadIcon("16/go-first.png")));
	Start->setFocusPolicy(Qt::NoFocus);
	PageSelectorLayout->addWidget( Start );

	Back->setIcon(QIcon(loadIcon("16/go-previous.png")));
	Back->setFocusPolicy(Qt::NoFocus);
	Back->setAutoRepeat(true);
	PageSelectorLayout->addWidget( Back );

// 	v = new PageValidator(1, LastPG, this);
	m_validator = new QIntValidator(1, LastPG, this);
	PageCombo = new ScComboBox( this );
	PageCombo->setEditable(true);
	PageCombo->setDuplicatesEnabled( false );
	PageCombo->lineEdit()->setAlignment(Qt::AlignHCenter);
	for (int a = 0; a < LastPG; ++a)
	{
		PageCombo->addItem(QString::number(a+1));
	}
	PageCombo->setValidator(m_validator);
	PageCombo->setMinimumSize(fontMetrics().width( "999" )+20, 20);
	PageCombo->setFocusPolicy(Qt::ClickFocus);
	PageSelectorLayout->addWidget( PageCombo );
	
	PageCount = new QLabel(PageCountString.arg(LastPG), this);
	PageSelectorLayout->addWidget(PageCount);
			
	Forward->setIcon(QIcon(loadIcon("16/go-next.png")));
	Forward->setFocusPolicy(Qt::NoFocus);
	Forward->setAutoRepeat(true);
	PageSelectorLayout->addWidget( Forward );

	Last->setIcon(QIcon(loadIcon("16/go-last.png")));
	Last->setFocusPolicy(Qt::NoFocus);
	PageSelectorLayout->addWidget( Last );
	Forward->setEnabled(true);
	Last->setEnabled(true);
	Back->setEnabled(false);
	Start->setEnabled(false);
	if (APage == LastPG)
	{
		Forward->setEnabled(false);
		Last->setEnabled(false);
	}

	languageChange();
	// signals and slots connections
	connect( PageCombo, SIGNAL( activated(int) ), this, SLOT( GotoPgE(int) ) );
	connect( Back, SIGNAL( clicked() ), this, SLOT( goBk() ) );
	connect( Start, SIGNAL( clicked() ), this, SLOT( ToStart() ) );
	connect( Forward, SIGNAL( clicked() ), this, SLOT( goFw() ) );
	connect( Last, SIGNAL( clicked() ), this, SLOT( ToEnd() ) );
}
Ejemplo n.º 18
0
int QHexScrollArea::stringWidth(const QString& str) const
{
    QFontMetrics fm = fontMetrics();
    return fm.width(str);
}
Ejemplo n.º 19
0
/*!\reimp
*/
QSize QProgressBar::sizeHint() const
{
    constPolish();
    QFontMetrics fm = fontMetrics();
    return QSize( fm.height()*4, fm.height()+8);
}
/**
 * Sets up the dialog.
 */
void UMLOperationDialog::setupDialog()
{
    QFrame *frame = new QFrame(this);
    setMainWidget(frame);
    int margin = fontMetrics().height();
    QVBoxLayout * topLayout = new QVBoxLayout(frame);

    m_pGenGB = new QGroupBox(i18n("General Properties"), frame);
    QGridLayout * genLayout = new QGridLayout(m_pGenGB);
    genLayout->setColumnStretch(1, 1);
    genLayout->setColumnStretch(3, 1);
    genLayout->addItem(new QSpacerItem(200, 0), 0, 1);
    genLayout->addItem(new QSpacerItem(200, 0), 0, 3);
    genLayout->setMargin(margin);
    genLayout->setSpacing(10);

    Dialog_Utils::makeLabeledEditField(genLayout, 0,
                                    m_pNameL, i18nc("operation name", "&Name:"),
                                    m_pNameLE, m_operation->name());

    m_pRtypeL = new QLabel(i18n("&Type:"), m_pGenGB);
    genLayout->addWidget(m_pRtypeL, 0, 2);

    m_pRtypeCB = new KComboBox(true, m_pGenGB);
    genLayout->addWidget(m_pRtypeCB, 0, 3);
    m_pRtypeL->setBuddy(m_pRtypeCB);

    m_stereotypeWidget = new UMLStereotypeWidget(m_operation);
    m_stereotypeWidget->addToLayout(genLayout, 1);

    m_pAbstractCB = new QCheckBox(i18n("&Abstract operation"), m_pGenGB);
    m_pAbstractCB->setChecked(m_operation->isAbstract());
    genLayout->addWidget(m_pAbstractCB, 2, 0);
    m_pStaticCB = new QCheckBox(i18n("Classifier &scope (\"static\")"), m_pGenGB);
    m_pStaticCB->setChecked(m_operation->isStatic());
    genLayout->addWidget(m_pStaticCB, 2, 1);
    m_pQueryCB = new QCheckBox(i18n("&Query (\"const\")"), m_pGenGB);
    m_pQueryCB->setChecked(m_operation->getConst());
    genLayout->addWidget(m_pQueryCB, 2, 2);

    m_visibilityEnumWidget = new VisibilityEnumWidget(m_operation, this);

    m_docWidget = new DocumentationWidget(m_operation, this);

    m_pParmsGB = new QGroupBox(i18n("Parameters"), frame);
    QVBoxLayout* parmsLayout = new QVBoxLayout(m_pParmsGB);
    parmsLayout->setMargin(margin);
    parmsLayout->setSpacing(10);

    // horizontal box contains the list box and the move up/down buttons
    QHBoxLayout* parmsHBoxLayout = new QHBoxLayout();
    m_pParmsLW = new QListWidget(m_pParmsGB);
    m_pParmsLW->setContextMenuPolicy(Qt::CustomContextMenu);

    // the move up/down buttons (another vertical box)
    QVBoxLayout* buttonLayout = new QVBoxLayout();

    m_pUpButton = new QToolButton(m_pParmsGB);
    m_pUpButton->setArrowType(Qt::UpArrow);
    m_pUpButton->setEnabled(false);
    buttonLayout->addWidget(m_pUpButton);

    m_pDownButton = new QToolButton(m_pParmsGB);
    m_pDownButton->setArrowType(Qt::DownArrow);
    m_pDownButton->setEnabled(false);
    buttonLayout->addWidget(m_pDownButton);

    KDialogButtonBox* buttonBox = new KDialogButtonBox(m_pParmsGB);
    buttonBox->addButton(i18n("Ne&w Parameter..."), KDialogButtonBox::ActionRole,
                          this, SLOT(slotNewParameter()));
    m_pDeleteButton = buttonBox->addButton(i18n("&Delete"), KDialogButtonBox::ActionRole,
                                            this, SLOT(slotDeleteParameter()));
    m_pPropertiesButton = buttonBox->addButton(i18n("&Properties"), KDialogButtonBox::ActionRole,
                          this, SLOT(slotParameterProperties()));

    parmsHBoxLayout->addWidget(m_pParmsLW);
    parmsHBoxLayout->addLayout(buttonLayout);

    parmsLayout->addLayout(parmsHBoxLayout);
    parmsLayout->addWidget(buttonBox);

    topLayout->addWidget(m_pGenGB);
    topLayout->addWidget(m_visibilityEnumWidget);
    topLayout->addWidget(m_docWidget);
    topLayout->addWidget(m_pParmsGB);

    m_pDeleteButton->setEnabled(false);
    m_pPropertiesButton->setEnabled(false);
    m_pUpButton->setEnabled(false);
    m_pDownButton->setEnabled(false);

    m_pRtypeCB->setDuplicatesEnabled(false); // only allow one of each type in box
    m_pRtypeCB->setCompletionMode(KGlobalSettings::CompletionPopup);
    // add the return types
    insertTypesSorted(m_operation->getTypeName());

    // fill in parm list box
    UMLAttributeList list = m_operation->getParmList();
    foreach (UMLAttribute* pAtt, list) {
        m_pParmsLW->addItem(pAtt->toString(Uml::SignatureType::SigNoVis));
    }
Ejemplo n.º 21
0
 QSize sizeHint( ) const
 {
     int w = fontMetrics( ).width( text( ) );
     int h = fontMetrics( ).height( );
     return QSize( w, h );
 }
Ejemplo n.º 22
0
DiffDialog::DiffDialog(KConfig& cfg, QWidget *parent, bool modal)
    : QDialog(parent)
    , partConfig(cfg)
{
    markeditem = -1;
    setModal(modal);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    setLayout(mainLayout);

    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Close);
    connect(buttonBox, &QDialogButtonBox::helpRequested, this, &DiffDialog::slotHelp);

    QPushButton *user1Button = new QPushButton;
    buttonBox->addButton(user1Button, QDialogButtonBox::ActionRole);
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
    KGuiItem::assign(user1Button, KStandardGuiItem::saveAs());

    QGridLayout *pairlayout = new QGridLayout();
    mainLayout->addLayout(pairlayout);
    pairlayout->setRowStretch(0, 0);
    pairlayout->setRowStretch(1, 1);
    pairlayout->setColumnStretch(1, 0);
    pairlayout->addItem(new QSpacerItem(16, 0), 0, 1);
    pairlayout->setColumnStretch(0, 10);
    pairlayout->setColumnStretch(2, 10);

    revlabel1 = new QLabel;
    pairlayout->addWidget(revlabel1, 0, 0);

    revlabel2 = new QLabel;
    pairlayout->addWidget(revlabel2, 0, 2);

    diff1 = new DiffView(cfg, true, false, this);
    diff2 = new DiffView(cfg, true, true, this);
    DiffZoomWidget *zoom = new DiffZoomWidget(this);
    zoom->setDiffView(diff2);

    pairlayout->addWidget(diff1, 1, 0);
    pairlayout->addWidget(zoom,  1, 1);
    pairlayout->addWidget(diff2, 1, 2);

    diff1->setPartner(diff2);
    diff2->setPartner(diff1);

    syncbox = new QCheckBox(i18n("Synchronize scroll bars"));
    syncbox->setChecked(true);
    connect(syncbox, SIGNAL(toggled(bool)), this, SLOT(toggleSynchronize(bool)));

    itemscombo = new KComboBox;
    itemscombo->addItem(QString());
    connect(itemscombo, SIGNAL(activated(int)), this, SLOT(comboActivated(int)));

    nofnlabel = new QLabel;
    // avoids auto resize when the text is changed
    nofnlabel->setMinimumWidth(fontMetrics().width(i18np("%1 difference", "%1 differences", 10000)));

    backbutton = new QPushButton(QLatin1String("&<<"));
    connect(backbutton, SIGNAL(clicked()), SLOT(backClicked()));

    forwbutton = new QPushButton(QLatin1String("&>>"));
    connect(forwbutton, SIGNAL(clicked()), SLOT(forwClicked()));

    connect(user1Button, SIGNAL(clicked()), SLOT(saveAsClicked()));

    QBoxLayout *buttonlayout = new QHBoxLayout();
    mainLayout->addLayout(buttonlayout);
    buttonlayout->addWidget(syncbox, 0);
    buttonlayout->addStretch(4);
    buttonlayout->addWidget(itemscombo);
    buttonlayout->addStretch(1);
    buttonlayout->addWidget(nofnlabel);
    buttonlayout->addStretch(1);
    buttonlayout->addWidget(backbutton);
    buttonlayout->addWidget(forwbutton);

    mainLayout->addWidget(buttonBox);
    buttonBox->button(QDialogButtonBox::Close)->setDefault(true);

    setAttribute(Qt::WA_DeleteOnClose, true);

    KConfigGroup cg(&partConfig, "DiffDialog");
    syncbox->setChecked(cg.readEntry("Sync",false));
    restoreGeometry(cg.readEntry<QByteArray>("geometry", QByteArray()));
}
Ejemplo n.º 23
0
double QgsComposerItem::textWidthMillimeters( const QFont& font, const QString& text ) const
{
  QFont metricsFont = scaledFontPixelSize( font );
  QFontMetrics fontMetrics( metricsFont );
  return ( fontMetrics.width( text ) / FONT_WORKAROUND_SCALE );
}
Ejemplo n.º 24
0
QSize FontRowTable::cellSize() const
{
    QFontMetrics fm = fontMetrics();
    return QSize( fm.maxWidth(), fm.lineSpacing()+1 );
}
Ejemplo n.º 25
0
double QgsComposerItem::fontDescentMillimeters( const QFont& font ) const
{
  QFont metricsFont = scaledFontPixelSize( font );
  QFontMetricsF fontMetrics( metricsFont );
  return ( fontMetrics.descent() / FONT_WORKAROUND_SCALE );
}
Ejemplo n.º 26
0
void FontRowTable::paintEvent( QPaintEvent* e )
{
    QFrame::paintEvent(e);
    QPainter p(this);
    p.setClipRegion(e->region());
    QRect r = e->rect();
    QFontMetrics fm = fontMetrics();
    int ml = frameWidth()+margin() + 1 + QMAX(0,-fm.minLeftBearing());
    int mt = frameWidth()+margin();
    QSize cell((width()-15-ml)/16,(height()-15-mt)/16);

    if ( !cell.width() || !cell.height() )
	return;

    int mini = r.left() / cell.width();
    int maxi = (r.right()+cell.width()-1) / cell.width();
    int minj = r.top() / cell.height();
    int maxj = (r.bottom()+cell.height()-1) / cell.height();

    int h = fm.height();

    QColor body(255,255,192);
    QColor negative(255,192,192);
    QColor positive(192,192,255);
    QColor rnegative(255,128,128);
    QColor rpositive(128,128,255);

    for (int j = minj; j<=maxj; j++) {
	for (int i = mini; i<=maxi; i++) {
	    if ( i < 16 && j < 16 ) {
		int x = i*cell.width();
		int y = j*cell.height();

		QChar ch = QChar(j*16+i,row);

		if ( fm.inFont(ch) ) {
		    int w = fm.width(ch);
		    int l = fm.leftBearing(ch);
		    int r = fm.rightBearing(ch);

		    x += ml;
		    y += mt+h;

		    p.fillRect(x,y,w,-h,body);
		    if ( w ) {
			if ( l ) {
			    p.fillRect(x+(l>0?0:l), y-h/2, abs(l),-h/2,
				       l < 0 ? negative : positive);
			}
			if ( r ) {
			    p.fillRect(x+w-(r>0?r:0),y+2, abs(r),-h/2,
				       r < 0 ? rnegative : rpositive);
			}
		    }
		    QString s;
		    s += ch;
		    p.setPen(QPen(Qt::black));
		    p.drawText(x,y,s);
		}
	    }
	}
    }
}
Ejemplo n.º 27
0
float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const
{
    ComplexTextController controller(this, run, true, fallbackFonts);
    if (glyphOverflow) {
        glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-controller.minGlyphBoundingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().ascent()));
        glyphOverflow->bottom = max<int>(glyphOverflow->bottom, ceilf(controller.maxGlyphBoundingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().descent()));
        glyphOverflow->left = max<int>(0, ceilf(-controller.minGlyphBoundingBoxX()));
        glyphOverflow->right = max<int>(0, ceilf(controller.maxGlyphBoundingBoxX() - controller.totalWidth()));
    }
    return controller.totalWidth();
}
Ejemplo n.º 28
0
osgText::Glyph*
QFontImplementation::getGlyph(const osgText::FontResolution& fontRes, unsigned int charcode)
{
    unsigned int fontSize = fontRes.second;
    _font.setPixelSize(fontSize);

    float coord_scale = 1.0f/float(fontSize);

    QFontMetrics fontMetrics(_font);
    QFontMetricsF fontMetricsF(_font);

    QRect rect = fontMetrics.boundingRect(QChar(charcode));
    QRectF rectF = fontMetricsF.boundingRect(QChar(charcode));

    int margin = 1;

    int imageWidth = rect.width() + 2*margin;
    int imageHeight = rect.height() + 2*margin;

    // Now paint the glyph into the image
    QImage image(imageWidth, imageHeight, QImage::Format_ARGB32);
    image.fill(0);
    QPainter painter(&image);
    painter.setRenderHint(QPainter::TextAntialiasing);

    painter.setFont(_font);

    painter.setBackgroundMode(Qt::TransparentMode);
    painter.setBrush(Qt::white);
    painter.setPen(Qt::white);

    painter.drawText(margin - rect.left(), imageHeight - 1 - (margin + rect.bottom()), QString(QChar(charcode)));
    painter.end();

    // Transfer the rendered image to osg
    osg::ref_ptr<osgText::Glyph> glyph = new osgText::Glyph(_facade, charcode);

    unsigned int dataSize = imageWidth*imageHeight;
    unsigned char* data = new unsigned char[dataSize];

    // copy the qimage into the texture memory
    for (int x = 0; x < imageWidth; ++x)
    {
        for (int y = 0; y < imageHeight; ++y)
        {
           data[x + y*imageWidth] = qAlpha(image.pixel(x, imageHeight - 1 - y));
        }
    }

    // the glyph texture in osg
    glyph->setImage(imageWidth, imageHeight, 1,
                    OSGTEXT_GLYPH_INTERNALFORMAT,
                    OSGTEXT_GLYPH_FORMAT, GL_UNSIGNED_BYTE,
                    data,
                    osg::Image::USE_NEW_DELETE,
                    1);
    glyph->setInternalTextureFormat(OSGTEXT_GLYPH_INTERNALFORMAT);

    glyph->setWidth((float)imageWidth * coord_scale);
    glyph->setHeight((float)imageHeight * coord_scale);

    // Layout parameters
    float leftBearing = fontMetricsF.leftBearing(QChar(charcode));
    float rightBearing = fontMetricsF.rightBearing(QChar(charcode));

    // for horizonal layout
    osg::Vec2 bottomLeft(leftBearing - margin, - rectF.bottom() - margin);
    glyph->setHorizontalBearing(bottomLeft * coord_scale);
    glyph->setHorizontalAdvance(fontMetricsF.width(QChar(charcode)) * coord_scale);

    // for vertical layout
    osg::Vec2 topMiddle(- margin + 0.5*(leftBearing - rect.width() - rightBearing),
                        rectF.top() - margin);
    glyph->setVerticalBearing(topMiddle * coord_scale);
    glyph->setVerticalAdvance((rectF.height() + fontMetricsF.overlinePos() - fontMetricsF.xHeight()) * coord_scale);

    // ... ready
    //addGlyph(fontRes, charcode, glyph.get());

    return glyph.release();
}
Ejemplo n.º 29
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    quitDialog(0), saveChanges(false),
    newJobFileName(""), newJobDestinationDirectory("")
{
    m_has_error_happend = false;
    QMetaObject::invokeMethod(this, "loadSettings", Qt::QueuedConnection);
    setWindowIcon(QIcon(":/ui/icons/motocool.jpg"));

    // Initiallize headers
    QStringList headers;
    headers << tr("Name") << tr("Downloaded/Total") << tr("Progress") << tr("Speed")
            << tr("Status") << tr("Remaining time");

    // Main job list
    jobView = new JobView(this);
    jobView->setHeaderLabels(headers);
    jobView->setSelectionBehavior(QAbstractItemView::SelectRows);
    jobView->setAlternatingRowColors(true);
    jobView->setRootIsDecorated(false);
    setCentralWidget(jobView);

    // Set header resize modes and initial section sizes
    QFontMetrics fm = fontMetrics();
    QHeaderView *header = jobView->header();
    header->resizeSection(0, fm.width("typical-name-length-for-a-download-task"));
    header->resizeSection(1, fm.width(headers.at(1) + "100MB/999MB"));
    header->resizeSection(2, fm.width(headers.at(2) + "100%"));
    header->resizeSection(3, qMax(fm.width(headers.at(3) + "   "), fm.width(" 1023.0 KB/s")));
    header->resizeSection(4, qMax(fm.width(headers.at(4) + "   "), fm.width(tr("Downloading  ") + "   ")));
    header->resizeSection(5, qMax(fm.width(headers.at(5) + "   "), fm.width(tr("--:--") + "   ")));

    // Create common actions
    QAction *newJobAction = new QAction(QIcon(":/ui/icons/bottom.png"), tr("Add &new job"), this);
    pauseJobAction = new QAction(QIcon(":/ui/icons/player_pause.png"), tr("&Pause job"), this);
    removeJobAction = new QAction(QIcon(":/ui/icons/player_stop.png"), tr("&Remove job"), this);
    openDirAction = new QAction(QIcon(":/ui/icons/folder.png"), tr("Open file &directory"), this);

    // File menu
    QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
    fileMenu->addAction(newJobAction);
    fileMenu->addAction(pauseJobAction);
    fileMenu->addAction(removeJobAction);
    fileMenu->addAction(openDirAction);
    fileMenu->addSeparator();
    fileMenu->addAction(QIcon(":/ui/icons/exit.png"), tr("E&xit"), this, SLOT(close()));

    // Help Menu
    QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
    helpMenu->addAction(tr("&About"), this, SLOT(about()));

    // Top toolbar
    QToolBar *topBar = new QToolBar(tr("Tools"));
    addToolBar(Qt::TopToolBarArea, topBar);
    topBar->setMovable(false);
    topBar->addAction(newJobAction);
    topBar->addAction(pauseJobAction);
    topBar->addAction(removeJobAction);
    topBar->addAction(openDirAction);
    pauseJobAction->setEnabled(false);
    removeJobAction->setEnabled(false);
    openDirAction->setEnabled(false);

    // Set up connections
    connect(jobView, SIGNAL(itemSelectionChanged()),
            this, SLOT(setActionsEnabled()));
    connect(newJobAction, SIGNAL(triggered()),
            this, SLOT(addJob()));
    connect(pauseJobAction, SIGNAL(triggered()),
            this, SLOT(pauseJob()));
    connect(removeJobAction, SIGNAL(triggered()),
            this, SLOT(removeJob()));
    connect(openDirAction, SIGNAL(triggered()),
            this, SLOT(openDir()));
}
// Constructor.
LteMacStatisticsDialog::LteMacStatisticsDialog(QWidget &parent, CaptureFile &cf, const char *filter) :
    TapParameterDialog(parent, cf, HELP_STATS_LTE_MAC_TRAFFIC_DIALOG),
    commonStatsCurrent(false)
{
    setWindowSubtitle(tr("LTE Mac Statistics"));

    clearCommonStats();

    // Create common_stats_grid to appear just above the filter area.
    int statstree_layout_idx = verticalLayout()->indexOf(filterLayout()->widget());
    QGridLayout *common_stats_grid = new QGridLayout();
    verticalLayout()->insertLayout(statstree_layout_idx, common_stats_grid);
    int one_em = fontMetrics().height();
    common_stats_grid->setColumnMinimumWidth(2, one_em * 2);
    common_stats_grid->setColumnStretch(2, 1);
    common_stats_grid->setColumnMinimumWidth(5, one_em * 2);
    common_stats_grid->setColumnStretch(5, 1);


    // Create statistics label.
    commonStatsLabel = new QLabel(this);
    commonStatsLabel ->setObjectName(tr("statisticsLabel"));
    commonStatsLabel ->setTextFormat(Qt::RichText);
    commonStatsLabel ->setTextInteractionFlags(Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse);
    common_stats_grid->addWidget(commonStatsLabel);


    // XXX Use recent settings instead
    resize(parent.width() * 1, parent.height() * 3 / 4);

    // Will set whole-UE headings originally.
    updateHeaderLabels();

    statsTreeWidget()->setItemDelegateForColumn(col_ul_padding_percent_, new PercentBarDelegate());
    statsTreeWidget()->setItemDelegateForColumn(col_dl_padding_percent_, new PercentBarDelegate());

    statsTreeWidget()->sortByColumn(col_rnti_, Qt::AscendingOrder);

    // Set up column widths.
    // resizeColumnToContents doesn't work well here, so set sizes manually.
    for (int col = 0; col < statsTreeWidget()->columnCount() - 1; col++) {
        switch (col) {
            case col_rnti_:
                statsTreeWidget()->setColumnWidth(col, one_em * 8);
                break;
            case col_ul_frames_:
                statsTreeWidget()->setColumnWidth(col, one_em * 5);
                break;
            case col_ul_bytes_:
                statsTreeWidget()->setColumnWidth(col, one_em * 5);
                break;
            case col_ul_mb_s_:
                statsTreeWidget()->setColumnWidth(col, one_em * 4);
                break;
            case col_ul_padding_percent_:
                statsTreeWidget()->setColumnWidth(col, one_em * 6);
                break;
            case col_ul_retx_:
                statsTreeWidget()->setColumnWidth(col, one_em * 6);
                break;
            case col_dl_frames_:
                statsTreeWidget()->setColumnWidth(col, one_em * 5);
                break;
            case col_dl_bytes_:
                statsTreeWidget()->setColumnWidth(col, one_em * 5);
                break;
            case col_dl_mb_s_:
                statsTreeWidget()->setColumnWidth(col, one_em * 4);
                break;
            case col_dl_padding_percent_:
                statsTreeWidget()->setColumnWidth(col, one_em * 6);
                break;
            case col_dl_crc_failed_:
                statsTreeWidget()->setColumnWidth(col, one_em * 6);
                break;
            case col_dl_retx_:
                statsTreeWidget()->setColumnWidth(col, one_em * 6);
                break;

            default:
                // The rest are numeric
                statsTreeWidget()->setColumnWidth(col, one_em * 4);
                statsTreeWidget()->headerItem()->setTextAlignment(col, Qt::AlignRight);
                break;
        }
    }

    addFilterActions();

    if (filter) {
        setDisplayFilter(filter);
    }

    // Set handler for when the tree item changes to set the appropriate labels.
    connect(statsTreeWidget(), SIGNAL(itemSelectionChanged()),
            this, SLOT(updateHeaderLabels()));
}