Exemple #1
0
/*!
    \reimp
*/
QSize Q3ProgressBar::sizeHint() const
{
    ensurePolished();
    QFontMetrics fm = fontMetrics();
    QStyleOptionProgressBar opt = getStyleOption(this);
    int cw = style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &opt, this);
    return style()->sizeFromContents(QStyle::CT_ProgressBar, &opt,
                                    QSize(cw * 7 + fm.width(QLatin1Char('0')) * 4, fm.height() + 8), this);
}
QSize
TagWidget::sizeHint() const
{
    QFontMetrics fm = fontMetrics();
    QSize size = QPushButton::sizeHint();
    size.setWidth( m_left_rest.width() + m_right_rest.width() + fm.width( text() ) + 8 );
    size.setHeight( 19 );
    return size;
}
/*!
    \reimp
*/
QSize QProgressBar::sizeHint() const
{
    constPolish();
    QFontMetrics fm = fontMetrics();
    int cw = style().pixelMetric(QStyle::PM_ProgressBarChunkWidth, this);
    return style().sizeFromContents(QStyle::CT_ProgressBar, this,
				    QSize( cw * 7 + fm.width( '0' ) * 4,
					   fm.height() + 8));
}
Exemple #4
0
static int xPosToCursorPos( char *s, const QFontMetrics &fm,
			    int xPos, int width )
{
    char *tmp;
    int	  dist;

    if ( xPos > width )
	xPos = width;
    if ( xPos <= 0 )
	return 0;
    dist = xPos;
    tmp	 = s;
    while ( *tmp && dist > 0 )
	dist -= fm.width( tmp++, 1 );
    if ( dist < 0 && ( xPos - dist > width || fm.width( tmp - 1, 1)/2 < -dist))
	tmp--;
    return tmp - s;
}
 int OverlayMenuDisplay::drawAreaWidth(
   const jsk_rviz_plugins::OverlayMenu::ConstPtr& msg)
 {
   QFontMetrics fm = fontMetrics();
   int max_width = 0;
   for (size_t i = 0; i < msg->menus.size(); i++) {
     int w = fm.width(getMenuString(msg, i).c_str());
     if (max_width < w) {
       max_width = w;
     }
   }
   int w = fm.width(msg->title.c_str());
   
   if (max_width < w) {
     max_width = w;
   }
   return max_width + menu_padding_x * 2;
 }
Exemple #6
0
void PageWidget::drawPageNumber(int page, QPainter &p, int x, int y)
{
    const QString pagestr(QString::number(page + 1));
    const QFontMetrics mtr(p.fontMetrics());
    const int txtw(mtr.width(pagestr));
    p.setPen(Qt::black);
    p.fillRect(x - txtw - 5, y - 2 - mtr.height(), txtw + 5, mtr.height() + 4, Qt::white);
    p.drawText(x - txtw - 4, y - 4, pagestr);
}
Exemple #7
0
QString elideText(const QString &srcText, const QFontMetrics &fm, int width,
                  const QString &elideSymbol) {
  QString text(srcText);

  for (int i = text.size(); i > 1 && fm.width(text) > width;)
    text = srcText.left(--i).append(elideSymbol);

  return text;
}
Exemple #8
0
qint64 QHexScrollArea::getByteNumberWidth() const
{
    QFontMetrics fm = this->fontMetrics();

    int ssw = fm.width(" ");                                            // width of space symbol
    int zsw = fm.width("0");                                            // width of zero symbol

    return ssw * 2 + zsw * 8;
}
Exemple #9
0
 void toggleColumnWidth(int logicalIndex)
 {
     QHeaderView *h = q->header();
     const int currentSize = h->sectionSize(logicalIndex);
     const int suggestedSize = suggestedColumnSize(logicalIndex);
     int targetSize = suggestedSize;
     // We switch to the size suggested by the contents, except
     // when we have that size already, in that case minimize.
     if (currentSize == suggestedSize) {
         QFontMetrics fm = q->fontMetrics();
         int headerSize = fm.width(q->model()->headerData(logicalIndex, Qt::Horizontal).toString());
         int minSize = 10 * fm.width(QLatin1Char('x'));
         targetSize = qMax(minSize, headerSize);
     }
     h->resizeSection(logicalIndex, targetSize);
     m_userHandled.remove(logicalIndex); // Reset.
     saveState();
 }
void FilesDialog::setSelectedFile(const QString &file)
{
	//ROS_INFO("Selected file: %s", file.toStdString().c_str());

	//I should do something when the path is empty, but, the way the signals are emmitted,
	//that sould not be an problem
	if (!_path.isEmpty()) {
		_file = file;
		if (_file.isEmpty()) {
			_ui.deleteFolderButton->setEnabled(true);
			_ui.createFolderButton->setEnabled(true);
			_ui.deleteFileButton->setEnabled(false);

			_ui.currentFileLabel->setText("No file selected.");

			//And now... for the elipsis
			QFontMetrics metrics = _ui.currentFolderLabel->fontMetrics();
			if (metrics.width(_file) > _ui.currentFolderLabel->width()) {
				_ui.currentFolderLabel->setText(metrics.elidedText(_file, Qt::ElideLeft, _ui.currentFolderLabel->width()));
			} else {
				_ui.currentFolderLabel->setText(_file);
			}
		} else {
			_ui.deleteFolderButton->setEnabled(true);
			_ui.createFolderButton->setEnabled(true);
			_ui.deleteFileButton->setEnabled(true);

			//And now... for the elipsis
			QFontMetrics metrics = _ui.currentFolderLabel->fontMetrics();
			if (metrics.width(_path) > _ui.currentFolderLabel->width()) {
				_ui.currentFolderLabel->setText(metrics.elidedText(_path, Qt::ElideLeft, _ui.currentFolderLabel->width()));
			} else {
				_ui.currentFolderLabel->setText(_path);
			}

			metrics = _ui.currentFileLabel->fontMetrics();
			if (metrics.width(_file) > _ui.currentFileLabel->width()) {
				_ui.currentFileLabel->setText(metrics.elidedText(_file, Qt::ElideLeft, _ui.currentFileLabel->width()));
			} else {
				_ui.currentFileLabel->setText(_file);
			}
		}
	}
}
void
TagDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
    QPen p( Qt::NoPen );
    QBrush b( Qt::NoBrush );
    int alpha = 255;
    float tagRelevance = index.data( PlaydarTagCloudModel::RelevanceRole ).value<float>() * 0.8;
    QColor bc(54,115,213);
    QColor borderColor = bc;

    bc.setAlphaF( tagRelevance * 0.5 );
    borderColor.setAlphaF( tagRelevance );
    b = QBrush( bc );
    p = QPen( borderColor );


    QColor const dark = option.palette.color( QPalette::Highlight ).darker();

    if( option.state & (QStyle::State_Selected | QStyle::State_Active) )
    {
        b = option.state & QStyle::State_Enabled
                ? option.palette.highlight()
                : QColor(0x64, 0x64, 0x64, alpha );
    }
    
    if( option.state & QStyle::State_MouseOver )
        p = option.palette.color( QPalette::Highlight );

    if( option.state & QStyle::State_Active )
        p = dark;


    p.setWidth( 3 );
    painter->setPen( p );
    painter->setBrush( b );
    painter->setRenderHint( QPainter::Antialiasing, true );
    painter->drawRoundedRect( option.rect.adjusted( 2, 2, -2, -2 ), 5.0f, 5.0f );

    const float weight = index.data( PlaydarTagCloudModel::LinearWeightRole ).value<float>();
    painter->setFont( font( option.font, weight ) );

    painter->setRenderHint( QPainter::Antialiasing, false );
    QColor textColor = option.state & (QStyle::State_Selected|QStyle::State_Active)
 					 ? option.palette.color( QPalette::HighlightedText )
					 : option.palette.color( QPalette::Text );
 	textColor.setAlpha( alpha );
    painter->setPen( textColor );

    QString const text = index.data().toString();
    QFontMetrics const metrics = painter->fontMetrics();

    QPoint pt;
    pt.setX( option.rect.x() + (option.rect.width() - metrics.width( text ))/2 );
    pt.setY( option.rect.y() + margins( weight ).height()/2 + metrics.ascent() );
    painter->drawText( pt, text );
}
void FavoritesViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {

    QStyleOptionViewItemV4 options = option;
    initStyleOption(&options, index);

    options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter);
    if (global.countBehavior == Global::CountNone)
        return;
    qint32 lid = index.data(Qt::UserRole).toInt();
    QString test = index.data(Qt::UserRole).toString().toLower();
    if (test == "stack")
        return;

    FavoritesView *tree = NULL;
    FavoritesViewItem *item = NULL;

    if (lid > 0) {
        tree = (FavoritesView*)options.widget;
        item = tree->dataStore[lid];
    } else {
        return;
    }
    if (item->record.type == FavoritesRecord::NotebookStack
            || item->record.type == FavoritesRecord::LinkedStack
            || item->record.type == FavoritesRecord::Search)
        return;

    qint32 total = item->total;
    qint32 subTotal = item->subTotal;
    if (total < 0 || subTotal < 0) {
        return;
    }

    QString countString;
    if (total == subTotal){
        countString = QString("(")+QString::number(total) + QString(")");
    } else {
        countString = QString("(")+QString::number(subTotal) + QString("/") + QString::number(total) + QString(")");
    }
    painter->save();

    // shift text right to make icon visible
    QSize iconSize = options.icon.actualSize(options.rect.size());
    painter->translate(options.rect.left()+iconSize.width(), options.rect.top());
    QRect clip(0, 0, options.rect.width()+iconSize.width(), options.rect.height());

    painter->setClipRect(clip);
    QFontMetrics fm = options.fontMetrics;
    QFont f = options.font;
    f.setBold(false);
    painter->setFont(f);
    painter->setPen(Qt::darkGray);
    painter->drawText(6+fm.width(index.data().toString()+QString("   ")),fm.ascent(),countString);

    painter->restore();
}
static QVector<QString> splitInTwoLines(const QString &text, const QFontMetrics &fontMetrics,
                                        qreal availableWidth)
{
    // split in two lines.
    // this looks if full words can be split off at the end of the string,
    // to put them in the second line. First line is drawn with ellipsis,
    // second line gets ellipsis if it couldn't split off full words.
    QVector<QString> splitLines(2);
    QRegExp rx(QLatin1String("\\s+"));
    int splitPos = -1;
    int nextSplitPos = text.length();
    do {
        nextSplitPos = rx.lastIndexIn(text,
                                      nextSplitPos - text.length() - 1);
        if (nextSplitPos != -1) {
            int splitCandidate = nextSplitPos + rx.matchedLength();
            if (fontMetrics.width(text.mid(splitCandidate)) <= availableWidth) {
                splitPos = splitCandidate;
            } else {
                break;
            }
        }
    } while (nextSplitPos > 0 && fontMetrics.width(text.left(nextSplitPos)) > availableWidth);
    // check if we could split at white space at all
    if (splitPos < 0) {
        splitLines[0] = fontMetrics.elidedText(text, Qt::ElideRight,
                                                       availableWidth);
        QString common = Manhattan::commonPrefix(QStringList()
                                             << splitLines[0] << text);
        splitLines[1] = text.mid(common.length());
        // elide the second line even if it fits, since it is cut off in mid-word
        while (fontMetrics.width(QChar(0x2026) /*'...'*/ + splitLines[1]) > availableWidth
               && splitLines[1].length() > 3
               /*keep at least three original characters (should not happen)*/) {
            splitLines[1].remove(0, 1);
        }
        splitLines[1] = QChar(0x2026) /*'...'*/ + splitLines[1];
    } else {
        splitLines[0] = fontMetrics.elidedText(text.left(splitPos).trimmed(), Qt::ElideRight, availableWidth);
        splitLines[1] = text.mid(splitPos);
    }
    return splitLines;
}
Exemple #14
0
QPainterPath
AnimInterfaceText::shape () const
{
  QPainterPath p;
  QFontMetrics fm (font ());
  QRectF r (0, 0, fm.width (getText ())/AnimatorView::getInstance ()->transform ().m11 (),
           fm.height ()/AnimatorView::getInstance ()->transform ().m11 ());
  p.addRect (r);
  return p;
}
Exemple #15
0
static unsigned itemWidth(QTreeWidgetItem *item, QFontMetrics &fm)
{
    unsigned w = fm.width(item->text(0)) + 64;
	for(int i = 0; i < item->childCount(); i++)
	{
		QTreeWidgetItem *child = item->child(i);
        w = qMax(w, itemWidth(child, fm));
    }
    return w;
}
QSize medWorkspaceShifterMenuPrivate::calculateSizeHint(const QFontMetrics& fm)
{
    int i = 0;
    int fullWidth = 0;
    xCache.resize(actions.size());
    foreach (QAction *action, actions) {
        int width = fm.width(action->text()) + TEXT_HPADDING;
        xCache[i++] = qMakePair(fullWidth, width);
        fullWidth += width;
    }
Exemple #17
0
void
AnimatorScene::setSceneInfoText(QString text, bool show)
{
    m_sceneInfoText->setText (text);
    m_sceneInfoText->setVisible (show);
    QFontMetrics fm (font ());
    QRectF r = sceneRect ();
    QPointF pos = QPointF ((sceneRect ().width () - fm.width (text))/2, r.center ().y ());
    m_sceneInfoText->setPos (pos);
}
static int maxDateColumnWidth( const QFontMetrics &fm )
{
    int width = 0;
    KDateTime date( KDateTime::currentLocalDate(), QTime(23, 59) );
    for (int x=0; x<10; x++, date = date.addDays( -1 ) ) {
        QString txt = ' ' + KGlobal::locale()->formatDateTime(date, KLocale::FancyShortDate ) + ' ';
        width = qMax( width, fm.width( txt ) );
    }
    return width;
}
QString ThreadRunnerDlgImpl::truncateLarge(const QString& s, int nKeepFirst /* = 0*/) // truncates strings that are too wide to display without resizing
{
    QFontMetrics fontMetrics (m_pCurrentL->font());
    const int MARGIN (8); // normally this should be 0 but in other cases Qt missed a few pixels when estimating how much space it needed, so it seems better to lose some pixels // ttt2 2009.04.30 - actually this is probably related to spacing; if this is true, the hard-coded value should be replaced by some query to QApplication::style()->pixelMetric()

    if (fontMetrics.width(s) < m_pCurrentL->width() - MARGIN)
    {
        return s;
    }

    int nSize (s.size() - 1);
    QString res (s);

    switch (m_eTruncatePos)
    {
    case TRUNCATE_BEGIN:
        {
            res.insert (nKeepFirst, "... ");
            nKeepFirst += 4; // size of "... "
            nSize -= nKeepFirst;
            while (nSize > 0 && fontMetrics.width(res) >= m_pCurrentL->width() - MARGIN)
            {
                res.remove(nKeepFirst, 1);
                --nSize;
            }
            return res;
        }

    case TRUNCATE_END:
        {
            while (nSize > 0 && fontMetrics.width(res + " ...") >= m_pCurrentL->width() - MARGIN)
            {
                res.truncate(nSize);
                --nSize;
            }
            return res + " ...";
        }

    default:
        //CB_ASSERT (false); //ttt2 add support for TRUNCATE_MIDDLE
        CB_THROW(CbRuntimeError);
    }
}
Exemple #20
0
QPoint BaseTrackView::getDbValuePosition(const QString &dbValueText,
                                         const QFontMetrics &fontMetrics) const
{
    int textWidth = fontMetrics.width(dbValueText);
    int textX = levelSlider->x() + levelSlider->width()/2 - textWidth - ((!narrowed) ? 14 : 11);
    float sliderPosition = (double)levelSlider->value()/levelSlider->maximum();
    int offset = levelSlider->y() + fontMetrics.height();
    int textY = (1 - sliderPosition) * levelSlider->height() + offset;
    return QPoint(textX, textY);
}
Exemple #21
0
static int showLastPartOffset( char *s, const QFontMetrics &fm, int width )
{
    if ( !s || s[0] == '\0' )
	return 0;
    char *tmp = &s[strlen( s ) - 1];
    do {
	width -= fm.width( tmp--, 1 );
    } while ( tmp >=s && width >=0 );
    return width < 0 ? tmp - s + 2 : 0;
}
int Context2D::textAlignOffset(Context2D::TextAlign value, const QFontMetrics &metrics, const QString &text)
{
    int offset = 0;
    if (value == Context2D::Start)
        value = qApp->layoutDirection() == Qt::LeftToRight ? Context2D::Left : Context2D::Right;
    else if (value == Context2D::End)
        value = qApp->layoutDirection() == Qt::LeftToRight ? Context2D::Right: Context2D::Left;
    switch (value) {
    case Context2D::Center:
        offset = metrics.width(text)/2;
        break;
    case Context2D::Right:
        offset = metrics.width(text);
    case Context2D::Left:
    default:
        break;
    }
    return offset;
}
Exemple #23
0
//int Utils::getClosestPointSize(QString fontName, int targetSize, int& nextSmaller, int& nextLarger, int direction, QString text) {
int Utils::getClosestPointSize(PointSizeParams p) {
    //haha - clumsy c++ syntax :)))
    int closestSize = std::numeric_limits<int>::max();
    int nextSmallerSize = std::numeric_limits<int>::max();
    int nextLargerSize = std::numeric_limits<int>::max();
    int closest = -1;
    *p.nextSmaller = -1;
    *p.nextLarger = -1;
    int pointSize = 1;
    int maxPointSize = 96;
    QRect boundingRect;
    while(pointSize <= maxPointSize) {
        QFontMetrics fontMetrics = QFontMetrics(QFont(p.fontName, pointSize));
        int crtSize = 0;
        switch(p.measure) {
        case PointSizeParams::Measure::width:
            crtSize = fontMetrics.width(p.text);
            break;
        case PointSizeParams::Measure::heightAscent:
            crtSize = fontMetrics.ascent();
            break;
        case PointSizeParams::Measure::height:
            //TODO - this bounding rect seems to be useless; find something else
            //boundingRect = fontMetrics.boundingRect(p.text);
            //crtSize = boundingRect.height();
            crtSize = fontMetrics.height();
            break;
        default:
            Q_ASSERT("this should not happen");
            break;
        }
        //printf("%s - pointSize=%d. Results in height=%d, we need height=%d\n",
        //       __func__, pointSize, crtSize, targetSize);
        if (abs(crtSize - p.targetSize) < abs(crtSize - closestSize)) {
            closest = pointSize;
            closestSize = crtSize;
        }
        if ( (crtSize < p.targetSize) && (abs(crtSize - p.targetSize) < abs(crtSize - nextSmallerSize)) ) {
            *p.nextSmaller = pointSize;
            nextSmallerSize = crtSize;
        }
        if ( (crtSize > p.targetSize) && (abs(crtSize - p.targetSize) < abs(crtSize - nextLargerSize)) ) {
            *p.nextLarger = pointSize;
            nextLargerSize = crtSize;
        }
        if ((closestSize != std::numeric_limits<int>::max()) &&
            (nextSmallerSize != std::numeric_limits<int>::max()) &&
            (nextLargerSize != std::numeric_limits<int>::max()))
            break;
        pointSize += 1;
    }
    //printf("%s, closest:%d:%d, smaller:%d:%d, larger:%d:%d\n", __func__,
    //       closest, closestSize, nextSmaller, nextSmallerSize, nextLarger, nextLargerSize);
    return closest;
}
Exemple #24
0
int TextFactory::stringWidth(const QString &string, const QFontMetrics &metrics) {
  const QStringList lines = string.split(QL1C('\n'));
  int width = 0;

  foreach (const QString &line, lines) {
    int line_width = metrics.width(line);

    if (line_width > width) {
      width = line_width;
    }
  }
Exemple #25
0
void GTLineEdit::checkTextSize(GUITestOpStatus& os, QLineEdit* lineEdit) {

    GT_CHECK(lineEdit != NULL, "lineEdit is NULL");

    QMargins lineEditMargins = lineEdit->textMargins();
    QFontMetrics fontMetrics = lineEdit->fontMetrics();
    int textWidth = lineEditMargins.left() + lineEditMargins.right() + fontMetrics.width(lineEdit->text());
    int rectWidth = lineEdit->rect().width();

    GT_CHECK(textWidth <= rectWidth, "GTLineEdit::checkTextSize: Text is not inside LineEdit's rect");
}
Exemple #26
0
QSize Editor::sizeHint() const
{
    constPolish();
    QFontMetrics fm = fontMetrics();
    int h = QMAX(fm.lineSpacing(), 14);
    int w = fm.width( 'x' ) * 20;
    int m = frameWidth() * 2;
    return( style().sizeFromContents(QStyle::CT_LineEdit, this,
             QSize( w + m, h + m + 4 ).
             expandedTo(QApplication::globalStrut())));
}
Exemple #27
0
int KexiComboBoxTableEdit::widthForValue(const QVariant &val, const QFontMetrics &fm)
{
    KexiDB::TableViewData *relData = column() ? column()->relatedData() : 0;
    if (lookupFieldSchema() || relData) {
        // in 'lookupFieldSchema' or  or 'related table data' model
        // we're assuming val is already the text, not the index
//! @todo ok?
        return qMax(KEXITV_MINIMUM_COLUMN_WIDTH, fm.width(val.toString()));
    }
    //use 'enum hints' model
    QVector<QString> hints = field()->enumHints();
    bool ok;
    int idx = val.toInt(&ok);
    if (!ok || idx < 0 || idx > int(hints.size() - 1))
        return KEXITV_MINIMUM_COLUMN_WIDTH;
    QString txt = hints.value(idx);
    if (txt.isEmpty())
        return KEXITV_MINIMUM_COLUMN_WIDTH;
    return fm.width(txt);
}
//*******************************************************************
// showEvent                                       PRIVATE inherited
//*******************************************************************
void QBtCompareFileDialog::showEvent( QShowEvent* const in_event )
{
   QBtShared::resize_width( this, 40 );
   QDialog::showEvent( in_event );
   
   const qint32       MAXLEN = ifield1_->width();
   const QFontMetrics fm     = ifield1_->fontMetrics();

   QString src_path = fpath1_;
   if( fm.width( src_path ) > MAXLEN ) {
      QBtShared::elide( fm, MAXLEN, src_path );
   }
   ifield1_->setText( src_path );
   
   QString dst_path = fpath2_;
   if( fm.width( dst_path ) > MAXLEN ) {
      QBtShared::elide( fm, MAXLEN, dst_path );
   }
   ifield2_->setText( dst_path );
}
Exemple #29
0
//=========================================================================
//  DebuggerMemView
//=========================================================================
void DebuggerMemView::mousePressEvent(QMouseEvent* event)
{
	const bool leftClick = event->button() == Qt::LeftButton;
	const bool rightClick = event->button() == Qt::RightButton;

	if (leftClick || rightClick)
	{
		QFontMetrics actualFont = fontMetrics();
		const double fontWidth = actualFont.width(QString(100, '_')) / 100.;
		const int fontHeight = MAX(1, actualFont.height());

		debug_view_xy topLeft = view()->visible_position();
		debug_view_xy clickViewPosition;
		clickViewPosition.x = topLeft.x + (event->x() / fontWidth);
		clickViewPosition.y = topLeft.y + (event->y() / fontHeight);
		if (leftClick)
		{
			view()->process_click(DCK_LEFT_CLICK, clickViewPosition);
		}
		else if (rightClick)
		{
			// Display the last known PC to write to this memory location & copy it onto the clipboard
			debug_view_memory* memView = downcast<debug_view_memory*>(view());
			const offs_t address = memView->addressAtCursorPosition(clickViewPosition);
			const debug_view_memory_source* source = downcast<const debug_view_memory_source*>(memView->source());
			address_space* addressSpace = source->space();
			const int nativeDataWidth = addressSpace->data_width() / 8;
			const UINT64 memValue = source->device()->machine().debugger().cpu().read_memory(*addressSpace,
														addressSpace->address_to_byte(address),
														nativeDataWidth,
														true);
			const offs_t pc = source->device()->debug()->track_mem_pc_from_space_address_data(addressSpace->spacenum(),
																								address,
																								memValue);
			if (pc != (offs_t)(-1))
			{
				// TODO: You can specify a box that the tooltip stays alive within - might be good?
				const QString addressAndPc = QString("Address %1 written at PC=%2").arg(address, 2, 16).arg(pc, 2, 16);
				QToolTip::showText(QCursor::pos(), addressAndPc, nullptr);

				// Copy the PC into the clipboard as well
				QClipboard *clipboard = QApplication::clipboard();
				clipboard->setText(QString("%1").arg(pc, 2, 16));
			}
			else
			{
				QToolTip::showText(QCursor::pos(), "UNKNOWN PC", nullptr);
			}
		}

		viewport()->update();
		update();
	}
}
void NNotebookViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
#if QT_VERSION < 0x050000
    QStyleOptionViewItemV4 options = option;
#else
    QStyleOptionViewItem options = option;
#endif
    initStyleOption(&options, index);

    options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter);

    if (global.countBehavior == Global::CountNone)
        return;

    qint32 lid = index.data(Qt::UserRole).toInt();
    QString test = index.data(Qt::UserRole).toString().toLower();
    if (test == "stack")
        return;

    painter->save();

    NNotebookView *tree = nullptr;
    NNotebookViewItem *item = nullptr;

    if (lid > 0) {
        tree = (NNotebookView*)options.widget;
        item = tree->dataStore[lid];
    } else {
        tree = (NNotebookView*)options.widget;
        item = tree->root;
    }
    qint32 total = item->total;
    qint32 subTotal = item->subTotal;
    QString countString;
    if (total == subTotal){
        countString = QString("(")+QString::number(total) + QString(")");
    } else {
        countString = QString("(")+QString::number(subTotal) + QString("/") + QString::number(total) + QString(")");
    }

    // shift text right to make icon visible
    QSize iconSize = options.icon.actualSize(options.rect.size());
    painter->translate(options.rect.left()+iconSize.width(), options.rect.top());
    QRect clip(0, 0, options.rect.width()+iconSize.width(), options.rect.height());

    painter->setClipRect(clip);
    QFontMetrics fm = options.fontMetrics;
    QFont f = options.font;
    f.setBold(false);
    painter->setFont(f);
    painter->setPen(Qt::darkGray);
    painter->drawText(10+fm.width(index.data().toString()+QString(" ")),fm.ascent(),countString);

    painter->restore();
}