void
CQPropertyDelegate::
drawFont(QPainter *painter, const QStyleOptionViewItem &option,
         const QFont &f, const QModelIndex &index) const
{
  QItemDelegate::drawBackground(painter, option, index);

  QRect rect = option.rect;

  rect.setWidth(option.rect.height());

  rect.adjust(0, 1, -3, -2);

  QFont f1 = f;
  QFont f2 = painter->font();

  QFontMetrics fm1(f1);
  QFontMetrics fm2(f2);

  int fw = fm1.width("Abc");
  int fh = fm1.height();

  if (fh > rect.height()) {
    f1.setPixelSize(rect.height());

    fm1 = QFontMetrics(f1);

    fw = fm1.width("Abc");
  }

  int x1 = rect.left();
  int y1 = rect.top() + fm1.ascent();

  painter->save();

  painter->setFont(f1);
  painter->setPen(QColor(0,0,0));

  painter->drawText(x1, y1, "Abc");

  painter->restore();

  int x2 = x1 + fw + 4;
//int y2 = rect.top() + fm2.ascent();

  QRect rect1;

  rect1.setCoords(x2, option.rect.top(), option.rect.right(), option.rect.bottom());

//painter->drawText(x2, y2, f.toString());
  QItemDelegate::drawDisplay(painter, option, rect1, f.toString());
}
/**
 * Update the number of unread messages in the tray icon
 */
void KCheckGmailTray::updateCountImage(QColor color)
{
    kDebug() << k_funcinfo << "Count=" << mMailCount;

    if(mMailCount == 0)
        setPixmapEmpty();
    else {
        // adapted from KMSystemTray::updateCount()

        int oldPixmapWidth = mPixGmail.size().width();

        QString countString = QString::number( mMailCount );
        QFont countFont = KGlobalSettings::generalFont();
        countFont.setBold(true);

        // decrease the size of the font for the number of unread messages if the
        // number doesn't fit into the available space
        float countFontSize = countFont.pointSizeF();
        QFontMetrics qfm( countFont );
        int width = qfm.width( countString );
        if( width > (oldPixmapWidth - 2) )
        {
            countFontSize *= float( oldPixmapWidth - 2 ) / float( width );
            countFont.setPointSizeF( countFontSize );
        }

        // Overlay the light KCheckGmail image with the number image
        QImage iconWithNumberImage = mLightIconImage.copy();
        QPainter p( &iconWithNumberImage );
        p.setFont( countFont );
        KColorScheme scheme( QPalette::Active, KColorScheme::View );

        qfm = QFontMetrics( countFont );
        QRect boundingRect = qfm.tightBoundingRect( countString );
        boundingRect.adjust( 0, 0, 0, 2 );
        boundingRect.setHeight( qMin( boundingRect.height(), oldPixmapWidth ) );
        boundingRect.moveTo( (oldPixmapWidth - boundingRect.width()) / 2,
                             ((oldPixmapWidth - boundingRect.height()) / 2) - 1 );
        p.setOpacity( 0.7 );
        p.setBrush( scheme.background( KColorScheme::LinkBackground ) );
        p.setPen( scheme.background( KColorScheme::LinkBackground ).color() );
        p.drawRoundedRect( boundingRect, 2.0, 2.0 );

        p.setBrush( Qt::NoBrush );
//		p.setPen( scheme.foreground( KColorScheme::LinkText ).color() );
        p.setPen(color);
        p.setOpacity( 1.0 );
        p.drawText( iconWithNumberImage.rect(), Qt::AlignCenter, countString );

        setIcon( QPixmap::fromImage( iconWithNumberImage ) );
    }
}
Example #3
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

#ifdef WIN32
    // Make sure there is a console to get our stdout,stderr information
    AllocConsole();
    HANDLE stdOutHandle=GetStdHandle(STD_OUTPUT_HANDLE);
    int hConHandle=_open_osfhandle((intptr_t)stdOutHandle,_O_TEXT);
    FILE* fp=_fdopen((int)hConHandle,"w");
    *stdout=*fp;
    setvbuf(stdout,NULL,_IONBF,0);
    HANDLE stdErrHandle=GetStdHandle(STD_ERROR_HANDLE);
    int hConHandleErr=_open_osfhandle((intptr_t) stdOutHandle,_O_TEXT);
    FILE* fperr=_fdopen( (int)hConHandleErr,"w");
    *stderr=*fperr;
    setvbuf(stderr,NULL,_IONBF,0);
    std::ios::sync_with_stdio();
    std::cerr<<"BRDF Version "<<BRDF_VERSION<<std::endl;
//    std::cerr<<"stdout: BRDF Version "<<BRDF_VERSION<<std::endl;
#endif

    // make sure we can open the data files
    if( !checkTeapot() ) {
        QString errString = "Can't open data files.\n\nPlease run BRDF Explorer from the directory containing the data/, images/, probes/, and shaderTemplates/ subdirectories (probably the src/ directory).";
        QMessageBox::critical( NULL, "BRDF Explorer", errString );
        return 1;
    }

    
    // center the window in the middle of the default screen
    QDesktopWidget desktopWidget;
    QRect rect = desktopWidget.screenGeometry();
    rect.adjust( 60, 60, -60, -60 );

    MainWindow main;
    main.setGeometry(rect);
    main.show();
    
    
    
    // open all BRDFs passed in on the commandline
    if( argc > 1 )
    {
        std::vector<std::string> files;
        for( int i = 1; i < argc; i++ )           
            files.push_back( std::string(argv[i]) );
        main.getParameterWindow()->openBRDFFiles( files );
    }
    
    return app.exec();
}
Example #4
0
// virtual
void AbstractGroupItem::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *)
{
    const double scale = option->matrix.m11();
    QRect clipRect = option->exposedRect.toRect();
    clipRect.adjust(0, 0, 1 / scale + 0.5, 1);
    p->fillRect(option->exposedRect, QColor(100, 100, 200, 100));
    p->setClipRect(clipRect);
    QPen pen = p->pen();
    pen.setColor(QColor(200, 90, 90));
    pen.setStyle(Qt::DashLine);
    p->setPen(pen);
    p->drawRect(boundingRect());
}
    //____________________________________________________________________________________
    void SunkenFrameShadow::updateGeometry()
    {

        QWidget *widget = parentWidget();
        if( !widget ) return;

        QRect cr = widget->contentsRect();
        switch (shadowArea())
        {

            case Top:
            cr.setHeight( SHADOW_SIZE_TOP );
            cr.adjust( -1, -1, 1, 0 );
            break;

            case Left:
            cr.setWidth(SHADOW_SIZE_LEFT);
            cr.adjust(-1, SHADOW_SIZE_TOP, 0, -SHADOW_SIZE_BOTTOM);
            break;


            case Bottom:
            cr.setTop(cr.bottom() - SHADOW_SIZE_BOTTOM + 1);
            cr.adjust( -1, 0, 1, 1 );
            if( hasContrast() ) cr.adjust( 0, 0, 0, 1 );
            break;

            case Right:
            cr.setLeft(cr.right() - SHADOW_SIZE_RIGHT + 1);
            cr.adjust(0, SHADOW_SIZE_TOP, 1, -SHADOW_SIZE_BOTTOM);
            break;

            case Unknown:
            default:
            return;
        }

        setGeometry(cr);
    }
void
drawBackgroundAndNumbers( QPainter* painter, const QString& text, const QRect& figRectIn )
{
    painter->save();

    QRect figRect = figRectIn;
    if ( text.length() == 1 )
        figRect.adjust( -painter->fontMetrics().averageCharWidth(), 0, 0, 0 );

    QPen origpen = painter->pen();
    QPen pen = origpen;
    pen.setWidth( 1.0 );
    painter->setPen( pen );
    painter->drawRect( figRect );

    // circles look bad. make it an oval. (thanks, apple)
    const int bulgeWidth = 8;
    const int offset = 0; // number of pixels to begin, counting inwards from figRect.x() and figRect.width(). 0 means start at each end, negative means start inside the rect.

    QPainterPath ppath;
    ppath.moveTo( QPoint( figRect.x() + offset, figRect.y() + figRect.height() / 2 ) );
    QRect leftArcRect( figRect.x() + offset - bulgeWidth, figRect.y(), 2*bulgeWidth, figRect.height() );
    ppath.arcTo( leftArcRect, 90, 180 );
    painter->drawPath( ppath );

    ppath = QPainterPath();
    ppath.moveTo( figRect.x() + figRect.width() - offset, figRect.y() + figRect.height() / 2 );
    leftArcRect = QRect( figRect.x() + figRect.width() - offset - bulgeWidth, figRect.y(), 2*bulgeWidth, figRect.height() );
    ppath.arcTo( leftArcRect, 270, 180 );
    painter->drawPath( ppath );

    figRect.adjust( -1, 0, 0, 0 );

    painter->setPen( origpen );
    painter->setPen( Qt::white );
    painter->drawText( figRect.adjusted( -5, 0, 6, 0 ), text, QTextOption( Qt::AlignCenter ) );

    painter->restore();
}
void ParticlesExtraInfoColumn::paintEvent(QPaintEvent *)
{
	if (!this->timeLineWidget)
	{
		return;
	}
	
	QPainter painter(this);
	painter.setPen(Qt::black);
	
	QRect ourRect = rect();
	ourRect.adjust(0, 0, -1, -1);
	painter.drawRect(ourRect);
	
	// Draw the header.
	painter.setFont(timeLineWidget->nameFont);
	painter.setPen(Qt::black);
	QRect textRect(0, 0, rect().width(), TOP_INDENT);
	painter.drawRect(textRect);
	painter.drawText(textRect, Qt::AlignHCenter | Qt::AlignVCenter, GetExtraInfoHeader());
	
	// Draw the per-layer particles count.
	OnBeforeGetExtraInfoLoop();
	
	QFontMetrics fontMetrics(timeLineWidget->nameFont);
	painter.setFont(timeLineWidget->nameFont);
	
	int32 i = 0;
	for (ParticleTimeLineWidget::LINE_MAP::const_iterator iter = timeLineWidget->lines.begin();
		 iter != timeLineWidget->lines.end(); ++iter, ++i)
	{
		const ParticleTimeLineWidget::LINE& line = iter->second;
		
		painter.setPen(QPen(line.color, LINE_WIDTH));
		int startY = i * LINE_STEP + LINE_STEP / 2;
		QRect textRect (EXTRA_INFO_LEFT_PADDING, TOP_INDENT + startY,
						rect().width() - EXTRA_INFO_LEFT_PADDING, LINE_STEP);
		painter.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter,
						 GetExtraInfoForLayerLine(line));
	}
	
	OnAfterGetExtraInfoLoop();
	
	// Draw the "Total" box.
	QPoint totalPoint(EXTRA_INFO_LEFT_PADDING, rect().bottom() - 3);
	QFont totalFont = timeLineWidget->nameFont;
	totalFont.setBold(true);
	
	painter.setPen(QPen(Qt::black, LINE_WIDTH));
	painter.drawText(totalPoint, GetExtraInfoFooter());
}
void QxtScheduleHeaderWidget::paintSection(QPainter * painter, const QRect & rect, int logicalIndex) const
{
    if (model())
    {
        switch (orientation())
        {
        case Qt::Horizontal:
        {
            QHeaderView::paintSection(painter, rect, logicalIndex);
        }
        break;
        case Qt::Vertical:
        {
            QTime time = model()->headerData(logicalIndex, Qt::Vertical, Qt::DisplayRole).toTime();
            if (time.isValid())
            {
                QRect temp = rect;
                temp.adjust(1, 1, -1, -1);

                painter->fillRect(rect, this->palette().background());

                switch (time.minute())
                {
                    case 00:
                        painter->drawLine(temp.topLeft() + QPoint(temp.width() / 3, 0), temp.topRight());
                        painter->drawText(temp, Qt::AlignTop | Qt::AlignRight, time.toString("hh:mm"));
                        break;

                    case 30:
                        painter->drawLine(temp.topLeft() + QPoint(temp.width() / 2, 0), temp.topRight());
                        break;

                    case 45:
                    case 15:
                        painter->drawLine(temp.topLeft() + QPoint(temp.width() / 1.5, 0), temp.topRight());
                        break;
                }

//                if (time.minute() == 0)
//                {
//                    painter->drawLine(temp.topLeft() + QPoint(temp.width() / 3, 0), temp.topRight());
//                    painter->drawText(temp, Qt::AlignTop | Qt::AlignRight, time.toString("hh:mm"));
//                }
            }
        }
        break;
        default:
            Q_ASSERT(false); //this will never happen... normally
        }
    }
}
Example #9
0
void TPanel::paintEvent(QPaintEvent *e) {
  QPainter painter(this);

  if (widget()) {
    QRect dockRect = widget()->geometry();

    dockRect.adjust(0, 0, -1, -1);
    painter.fillRect(dockRect, m_bgcolor);
    painter.setPen(Qt::black);
    painter.drawRect(dockRect);
  }

  painter.end();
}
Example #10
0
// --------------------------------------------------
QRect ctkSearchBoxPrivate::searchRect()const
{
  Q_Q(const ctkSearchBox);
  QRect sRect = q->contentsRect();
  // If the QLineEdit has a frame, the icon must be shifted from
  // the frame line width
  if (q->hasFrame())
    {
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
    QStyleOptionFrameV2 opt;
#else
    QStyleOptionFrame opt;
#endif
    q->initStyleOption(&opt);
    sRect.adjust(opt.lineWidth, opt.lineWidth, -opt.lineWidth, -opt.lineWidth);
    }
  // Hardcoded: shrink by 1 pixel because some styles have a focus frame inside
  // the line edit frame.
  sRect.adjust(1, 1, -1, -1);
  // Square size
  sRect.setWidth(sRect.height());
  return sRect;
}
Example #11
0
void SysTrayIcon::updateUnreadCount( int changeOfUnreadPosts )
{
    kDebug();
    unread += changeOfUnreadPosts;

    if ( unread <= 0 ) {
        setIconByName(currentIconName());
        unread = 0;
    } else {
        // adapted from KMSystemTray::updateCount()
        int oldWidth = 22;

        QString countStr = QString::number( unread );
        QFont f = KGlobalSettings::generalFont();
        f.setBold( true );

        float pointSize = f.pointSizeF();
        QFontMetrics fm( f );
        int w = fm.width( countStr );
        if ( w > ( oldWidth - 2 ) ) {
            pointSize *= float( oldWidth - 2 ) / float( w );
            f.setPointSizeF( pointSize );
        }

        // overlay
        QPixmap overlayImg = KIcon(currentIconName()).pixmap(22,22);
        QPainter p( &overlayImg );
        p.setFont( f );
        KColorScheme scheme( QPalette::Active, KColorScheme::View );

        fm = QFontMetrics( f );
        QRect boundingRect = fm.tightBoundingRect( countStr );
        boundingRect.adjust( 0, 0, 0, 2 );
        boundingRect.setHeight( qMin( boundingRect.height(), oldWidth ) );
        boundingRect.moveTo(( oldWidth - boundingRect.width() ) / 2,
                            (( oldWidth - boundingRect.height() ) / 2 ) - 1 );
        p.setOpacity( 0.7 );
        QBrush br(QColor(255, 255, 255), Qt::SolidPattern);
        p.setBrush( br );
        p.setPen( QColor(255, 255, 255) );
        p.drawRoundedRect( boundingRect, 2.0, 2.0 );

        p.setBrush( Qt::NoBrush );
        p.setPen( QColor( 0, 0, 0 ) );
        p.setOpacity( 1.0 );
        p.drawText( overlayImg.rect(), Qt::AlignCenter, countStr );
        setIconByPixmap( overlayImg );
    }
    this->setToolTip( "choqok", i18n("Choqok"), i18np( "1 unread post", "%1 unread posts", unread ) );
}
Example #12
0
void DesktopWindow::loadItemPositions() {
    // load custom item positions
    customItemPos_.clear();
    Settings& settings = static_cast<Application*>(qApp)->settings();
    QString configFile = QString("%1/desktop-items-%2.conf").arg(settings.profileDir(settings.profileName())).arg(screenNum_);
    QSettings file(configFile, QSettings::IniFormat);

    auto delegate = static_cast<Fm::FolderItemDelegate*>(listView_->itemDelegateForColumn(0));
    auto grid = delegate->itemSize();
    QRect workArea = qApp->desktop()->availableGeometry(screenNum_);
    workArea.adjust(12, 12, -12, -12);
    char* dektopPath = Fm::Path::getDesktop().toStr();
    QString desktopDir = QString(dektopPath) + QString("/");
    g_free(dektopPath);

    std::vector<QPoint> usedPos;
    for(auto& item: customItemPos_) {
        usedPos.push_back(item.second);
    }

    // FIXME: this is inefficient
    Q_FOREACH(const QString& name, file.childGroups()) {
        if(!QFile::exists(desktopDir + name.toUtf8())) {
            // the file may have been removed from outside LXQT
            continue;
        }
        file.beginGroup(name);
        QVariant var = file.value("pos");
        if(var.isValid()) {
            QPoint customPos = var.toPoint();
            if(customPos.x() >= workArea.x() && customPos.y() >= workArea.y()
                    && customPos.x() + grid.width() <= workArea.right() + 1
                    && customPos.y() + grid.height() <= workArea.bottom() + 1) {
                // correct positions that are't aligned to the grid
                alignToGrid(customPos, workArea.topLeft(), grid, listView_->spacing());
                // FIXME: this is very inefficient
                while(std::find(usedPos.cbegin(), usedPos.cend(), customPos) != usedPos.cend()) {
                    customPos.setY(customPos.y() + grid.height() + listView_->spacing());
                    if(customPos.y() + grid.height() > workArea.bottom() + 1) {
                        customPos.setX(customPos.x() + grid.width() + listView_->spacing());
                        customPos.setY(workArea.top());
                    }
                }
                customItemPos_[name.toStdString()] = customPos;
                usedPos.push_back(customPos);
            }
        }
        file.endGroup();
    }
}
Example #13
0
void KateTabButton::moveEvent(QMoveEvent *event)
{
    // tell the tabbar to redraw its separators. Since the separators overlap
    // the tab buttons geometry, we need to adjust the width by the separator's
    // width to avoid artifacts
    if (parentWidget()) {
        const int w = style()->pixelMetric(QStyle::PM_ToolBarSeparatorExtent, 0, this);
        QRect rect = geometry();
        rect.moveLeft(event->oldPos().x());
        rect.adjust(-w, 0, w, 0);
        parentWidget()->update(rect);
    }
    QAbstractButton::moveEvent(event);
}
Example #14
0
void QxtSpanSliderPrivate::drawSpan(QStylePainter* painter, const QRect& rect) const
{
    QStyleOptionSlider opt;
    initStyleOption(&opt);
    const QSlider* p = &qxt_p();

    // area
    QRect groove = p->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, p);
    if (opt.orientation == Qt::Horizontal)
        groove.adjust(0, 0, -1, 0);
    else
        groove.adjust(0, 0, 0, -1);

    // pen & brush
    painter->setPen(QPen(p->palette().color(QPalette::Dark).light(110), 0));
    if (opt.orientation == Qt::Horizontal)
        setupPainter(painter, opt.orientation, groove.center().x(), groove.top(), groove.center().x(), groove.bottom());
    else
        setupPainter(painter, opt.orientation, groove.left(), groove.center().y(), groove.right(), groove.center().y());

    // draw groove
    painter->drawRect(rect.intersected(groove));
}
Example #15
0
void QtPropertyItemDelegate::updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
	QStyledItemDelegate::updateEditorGeometry(editor, option, index);

	// tune widget border and geometry
	if(NULL != editor)
	{
		editor->setObjectName("customPropertyEditor");
		editor->setStyleSheet("#customPropertyEditor{ border: 1px solid gray; }");
		QRect r = option.rect;
		r.adjust(2, -1, 0, 1);
		editor->setGeometry(r);
	}
}
void ConnectionPOIDelegate::paint(QPainter *iPainter, const QStyleOptionViewItem &iOption, const QModelIndex &iIndex) const
{
    //
    // Fetch data
    //

    QStyledItemDelegate::paint(iPainter, iOption, iIndex);

    if (! iIndex.data(ConnectionPOIRole).type() != QVariant::Invalid)
        return;

    Connection::POI tConnectionPOI = iIndex.data(ConnectionPOIRole).value<Connection::POI>();


    //
    // Configure layout
    //

    // Main drawing rectangle
    QRect rect = iOption.rect;
    rect.adjust(20, 8, -20, -8);

    // Main font
    QFont font = iOption.font;


    //
    // Draw text
    //

    iPainter->save();

    // Station
    QString tStation = stationName(mStations, tConnectionPOI.station);
    iPainter->drawText(rect, Qt::AlignTop | Qt::AlignLeft, tStation);

    // Platform (TODO: might not be available for stops between endpoints)
    QString tPlatform = tr("Platform") % " " % QString::number(tConnectionPOI.platform);
    iPainter->drawText(rect, Qt::AlignTop | Qt::AlignRight, tPlatform);

    // Time
    QString tTime = tConnectionPOI.datetime.toLocalTime().time().toString(Qt::DefaultLocaleShortDate);
    iPainter->setPen(iOption.palette.mid().color());
    font.setPointSizeF(font.pointSizeF() * 0.70);
    iPainter->setFont(font);
    iPainter->drawText(rect, Qt::AlignBottom | Qt::AlignLeft, tTime);

    iPainter->restore();
}
Example #17
0
void GroupWidget::paintEvent(QPaintEvent* e)
{
	Q_UNUSED(e);
	
	QPainterPath path;
	QRect rc;
	QColor clr;
	
	QPainter p(this);

	p.setRenderHint(QPainter::Antialiasing, true);
	
	// Fill shadow
	rc = rect();
	path = roundedRect(rc, 10);
	clr = m_clr.dark(300);
	p.fillPath(path, clr);

	// Path for background
	int nShadow = 5;
	rc.adjust(nShadow, nShadow, -nShadow, -nShadow);
	path = roundedRect(rc, 5);

	// Fill background
	clr = m_clr;
	p.fillPath(path, clr);
	// Border around background
	clr = clr.dark(115);
	p.setPen(clr);
	p.drawPath(path);

	// Title rectangle
	rc = QRect(rc.left() + 2, rc.top() + 2, rc.width() - 4, 20);
	path = roundedRect(rc, 3);
	p.fillPath(path, clr);

	//p.setRenderHint(QPainter::Antialiasing, false);

	// Title text
	QFont fontOrig = p.font();
	QFont fontTitle = fontOrig;
	fontTitle.setBold(true);
	fontTitle.setPixelSize(16);
	rc.translate(0, -1);
	p.setPen(Qt::black);
	p.setFont(fontTitle);
	p.drawText(rc, Qt::AlignCenter, m_sTitle);
	p.setFont(fontOrig);
}
Example #18
0
void TClickLineEdit::paintEvent(QPaintEvent *event)
{
    QLineEdit::paintEvent(event);

    QPainter p(this);
    if (k->drawClickMsg == true && !hasFocus()) {
        QPen tmp = p.pen();
        p.setPen(palette().color(QPalette::Disabled, QPalette::Text));
        QRect cr = contentsRect();

        cr.adjust(3, 0, 0 ,0);
        p.drawText(cr, Qt::AlignVCenter, k->clickMessage);
        p.setPen(tmp);
    }
}
Example #19
0
void ProfileMatchView::DrawButton(const QRect& ButtonRect, const QBrush& pBrush) 
{
	QRect DrawRect = ButtonRect;
	
	DrawRect.adjust(-1,-1,1,1); //draw a inflated rectangle

	QPainter paint(this);

	paint.begin(this); //start painting
	paint.setBrush(pBrush);

	paint.drawRect(DrawRect);
	paint.end(); //release paint device resource

}
Example #20
0
void LayerHeaderPanel::drawIcon(QPainter &p, PredefinedRect rect,
                                optional<QColor> fill,
                                const QPixmap &pixmap) const {
  QRect iconRect =
      Orientations::leftToRight()->rect(rect).adjusted(-2, 0, -2, 0);

  if (rect == PredefinedRect::LOCK) {
    p.setPen(Qt::gray);
    p.setBrush(QColor(255, 255, 255, 128));
    p.drawRect(iconRect);
    iconRect.adjust(1, 1, -1, -1);
  } else if (fill)
    p.fillRect(iconRect, *fill);
  p.drawPixmap(iconRect, pixmap);
}
void MpdClientDialog::paintEvent(QPaintEvent*)
{
    QPainter p(this);
    QPen pen(Qt::SolidLine);
    pen.setColor(Qt::black);
    p.setPen(pen);
    p.drawRect(QRect(QPoint(0, 0), size()).adjusted(0, 0, -1, -1));

    QRect size1 = title_layout_.contentsRect();
    QRect size2 = album_layout_.contentsRect();

    QRect border = size1.united(size2);
    border.adjust(0, 0, 0, 0);
    p.drawRoundedRect(border, 3, 3);
}
Example #22
0
void HistoryField::paintEvent(QPaintEvent *evt)
{
	QPainter p(this);

	QRect clipRect = evt->rect();

	int i0 = y2index(clipRect.top());
	int i1 = y2index(clipRect.bottom());

	int currentHistoryIndex = TUndoManager::manager()->getCurrentHistoryIndex();
	int currentHistoryCount = TUndoManager::manager()->getHistoryCount();

	QRect undoChipRect(0, 0, width(), HISTORY_ITEM_HEIGHT);
	QRect undoIconRect(7, 2, 17, 17);

	for (int i = i0; i <= i1; i++) {

		if (0 <= i && i <= currentHistoryCount) {
			QRect tmpRect = undoChipRect.translated(0, HISTORY_ITEM_HEIGHT * (i - 1));

			bool isCurrent = (i == currentHistoryIndex);
			bool isFuture = (i > currentHistoryIndex);

			p.setPen(QColor(64, 64, 64));
			p.setBrush((isFuture) ? QColor(150, 150, 150) : QColor(192, 192, 192));
			if (isCurrent)
				p.setBrush(QColor(0, 0, 128));
			p.drawRect(tmpRect);

			//draw text
			QFont fon = p.font();
			fon.setItalic(isFuture);
			p.setFont(fon);

			p.setPen((isFuture) ? QColor(64, 64, 64) : Qt::black);
			if (isCurrent)
				p.setPen(Qt::white);

			tmpRect.adjust(30, 0, 0, 0);

			TUndo *tmpUndo = TUndoManager::manager()->getUndoItem(i);
			p.drawText(tmpRect, Qt::AlignLeft | Qt::AlignVCenter, tmpUndo->getHistoryString());

			QRect tmpIconRect = undoIconRect.translated(0, 20 * (i - 1));
			p.drawPixmap(tmpIconRect, HistoryPixmapManager::instance()->getHistoryPm(tmpUndo->getHistoryType()));
		}
	}
}
Example #23
0
void QDockWidgetPrivate::unplug(const QRect &rect)
{
    Q_Q(QDockWidget);
    QRect r;
    if (!undockedGeometry.isNull()) {
        r = undockedGeometry;
    } else {
        r = rect;
        r.moveTopLeft(q->mapToGlobal(QPoint(0, 0)));
        QDockWidgetLayout *dwLayout = qobject_cast<QDockWidgetLayout*>(layout);
        if (dwLayout->nativeWindowDeco(true))
            r.adjust(0, dwLayout->titleHeight(), 0, 0);
    }

    setWindowState(true, true, r);
}
Example #24
0
QRect QToolBarAreaLayout::rectHint(const QRect &r) const
{
    int coef = visible ? 1 : -1;

    QRect result = r;

    QSize left_hint = docks[QInternal::LeftDock].sizeHint();
    QSize right_hint = docks[QInternal::RightDock].sizeHint();
    QSize top_hint = docks[QInternal::TopDock].sizeHint();
    QSize bottom_hint = docks[QInternal::BottomDock].sizeHint();

    result.adjust(-left_hint.width()*coef, -top_hint.height()*coef,
                    right_hint.width()*coef, bottom_hint.height()*coef);

    return result;
}
Example #25
0
void WidgetManager::alignWindow(QWidget *AWindow, Qt::Alignment AAlign)
{
#ifndef Q_WS_X11
	if (AAlign > 0)
	{
		QRect frameRect = AWindow->frameGeometry();
		QRect windowRect = AWindow->geometry();
		QRect rect = alignGeometry(frameRect.size(),AWindow,AAlign);
		rect.adjust(windowRect.left()-frameRect.left(),windowRect.top()-frameRect.top(),windowRect.right()-frameRect.right(),windowRect.bottom()-frameRect.bottom());
		AWindow->setGeometry(rect);
	}
#else
	Q_UNUSED(AWindow);
	Q_UNUSED(AAlign);
#endif
}
bool CWizCategoryViewItemBase::extraButtonClickTest()
{
    QPixmap pixmap;
    if(!getExtraButtonIcon(pixmap) || pixmap.isNull())
        return false;

    CWizCategoryBaseView* view = dynamic_cast<CWizCategoryBaseView*>(treeWidget());
    Q_ASSERT(view);

    QRect rcIemBorder = view->visualItemRect(this);
    QRect btnRect = getExtraButtonRect(rcIemBorder);
    int nClickDist = 2;
    btnRect.adjust(-nClickDist, -nClickDist, nClickDist, nClickDist);

    return btnRect.contains(view->hitPoint());
}
Example #27
0
void PdfImageGenerator::startGeneration(void) {
    int page;
    QRectF highlight;
    QImage img;
    QPair<int,QRectF> demand;

    while (!this->requestedPages.isEmpty()) {
        demand    = requestedPages.takeLast();
        page      = demand.first;
        highlight = demand.second;
        img       = generateImage(page);

        if (!img.isNull()) {
            /* image size estimation */
            if (this->passes < this->minpasses) {
                ++passes;
                avgw += img.width();
                avgh += img.height();
            }

            /* search result highlight
             * cuts out the highlighted word and darkens the rest of the page */
            if (highlight.isValid()) {
                QRect highlightRect = scaleHighlightRect(highlight);
                highlightRect.adjust(-2, -2, 2, 2);
                QImage hImage = img.copy(highlightRect);
                QPainter painter;

                painter.begin(&img);
                painter.fillRect(img.rect(), QColor(0, 0, 0, 32));
                painter.drawImage(highlightRect, hImage);
                painter.end();
            }

            emit imageFinished(img, page);
        }
    }

    if (this->passes == minpasses) {
        pageSize.setWidth((int)(avgw/passes));
        pageSize.setHeight((int)(avgh/passes));
        ++passes;
        emit newPageSize(pageSize);
    }

    emit generationFinished();
}
Example #28
0
//! [2]
QRect BasicToolsPlugin::mouseMove(const QString &brush, QPainter &painter,
                                  const QPoint &oldPos, const QPoint &newPos)
{
    painter.save();

    int rad = painter.pen().width() / 2;
    QRect boundingRect = QRect(oldPos, newPos).normalized()
                         .adjusted(-rad, -rad, +rad, +rad);
    QColor color = painter.pen().color();
    int thickness = painter.pen().width();
    QColor transparentColor(color.red(), color.green(), color.blue(), 0);
//! [2] //! [3]

    if (brush == tr("Pencil")) {
        painter.drawLine(oldPos, newPos);
    } else if (brush == tr("Air Brush")) {
        int numSteps = 2 + (newPos - oldPos).manhattanLength() / 2;

        painter.setBrush(QBrush(color, Qt::Dense6Pattern));
        painter.setPen(Qt::NoPen);

        for (int i = 0; i < numSteps; ++i) {
            int x = oldPos.x() + i * (newPos.x() - oldPos.x()) / (numSteps - 1);
            int y = oldPos.y() + i * (newPos.y() - oldPos.y()) / (numSteps - 1);

            painter.drawEllipse(x - (thickness / 2), y - (thickness / 2),
                                thickness, thickness);
        }
    } else if (brush == tr("Random Letters")) {
        QChar ch('A' + (qrand() % 26));

        QFont biggerFont = painter.font();
        biggerFont.setBold(true);
        biggerFont.setPointSize(biggerFont.pointSize() + thickness);
        painter.setFont(biggerFont);

        painter.drawText(newPos, QString(ch));

        QFontMetrics metrics(painter.font());
        boundingRect = metrics.boundingRect(ch);
        boundingRect.translate(newPos);
        boundingRect.adjust(-10, -10, +10, +10);
    }
    painter.restore();
    return boundingRect;
}
Example #29
0
// Assumes horizontal and vertical center alignment
QRect ImageWindow::drawingRect()
{
	QRect dr = rect();

	const QPixmap *pm = pixmap();

	if (pm) {
		QRect pmRect = pm->rect();

		int x = (dr.width() - pmRect.width()) / 2;
		int y = (dr.height() - pmRect.height()) / 2;

		dr.adjust(x, y, -x, -y);
	}

	return dr;
}
Example #30
0
void Text::updateRenderedString() const
{
	GlErrorTool::getErrors("Text::updateRenderedString:1", name());
	// Get bounding box size
	Vec2f d = dimensions_*pixelScale;
	QFontMetrics fm(font_);
	QRect bb = fm.boundingRect(0, 0, d.w-textMargin*2, d.h-textMargin*2,
							   Qt::TextWordWrap, QString::fromStdString(text_));
	bb.adjust(-textMargin, -textMargin, textMargin, textMargin); // Add margin
	QSize bbs = bb.size();
	renderedDimensions_ = Vec2f(bbs.width(), bbs.height());
	// Dispose old FBO and create a new one
	if (renderedString_)
		delete renderedString_;
	renderedString_ = new QGLFramebufferObject(bbs, QGLFramebufferObject::CombinedDepthStencil);
	// Prepare for drawing
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	// Draw into the FBO
	renderedString_->bind();
	glClearColor(0, 0, 0, 1);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	QPainter p(renderedString_); // p.begin() implicit
	p.setFont(font_);
	p.setPen(QColor(Qt::white));
	// TODO: Transparency support
	p.setBackground(QColor(0,0,0,1));
	p.drawText(textMargin, textMargin, bbs.width()-textMargin, bbs.height()-textMargin,
			   Qt::TextWordWrap, QString::fromStdString(text_));
	p.end();
	renderedString_->release();
	// Cleanup from drawing
	glPopAttrib();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
	// We're done
	renderedStringValid_ = true;
	GlErrorTool::getErrors("Text::updateRenderedString:2", name());
}