Example #1
0
LRESULT HubMessageControl::onChangeFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
  if (GetUpdateRect(NULL, FALSE)) {
    Invalidate();
  }
  else {
    dcdebug("call drawFocusRect in onChangeFocus\n");
    CClientDC dc(m_hWnd);
    drawFocusRect(dc);
  }
  return 0;
}
Example #2
0
LRESULT HubMessageControl::onPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
  CPaintDC dc(m_hWnd);
  CRect r;
  GetClientRect(r);
  dc.FillRect(r, GetSysColorBrush(COLOR_INFOBK));
  CIcon helpIcon;
  helpIcon.LoadIcon(IDI_SETTINGS_HELP, ICON_WIDTH, ICON_HEIGHT);
  if (helpIcon) {
    helpIcon.DrawIconEx(dc, (m_leftMargin - ICON_WIDTH) / 2, (r.Height() - ICON_HEIGHT) / 2, ICON_WIDTH, ICON_HEIGHT);
  }
  dc.SetBkColor(GetSysColor(COLOR_INFOBK));
  dc.SetTextColor(GetSysColor(COLOR_INFOTEXT));
  const HFONT oldFont = dc.SelectFont(WinUtil::systemFont);
  r.top += m_topMargin;
  r.left += m_leftMargin;
  r.right -= m_rightMargin;
  r.bottom -= m_bottomMargin;
  const int screenTop = r.top;
  const int screenBottom = r.bottom;
  r.top -= scrollTop;
  for (HubMessageIterator i = messages.begin(); i != messages.end(); ++i) {
    const HubMessage& msg = *i;
    r.bottom = r.top + msg.height;
    //dcdebug("scrollTop=%d r.top=%d r.bottom=%d screenTop=%d screenBottom=%d \n", scrollTop, r.top, r.bottom, screenTop, screenBottom);
    if (r.bottom > screenTop) {
      tstring tmp = msg.time + _T(" ") + msg.text;
      dc.DrawText(tmp.c_str(), tmp.length(), r, DT_WORDBREAK);
    }
    if (r.bottom >= screenBottom) break;
    r.top = r.bottom;
  }
  dc.SelectFont(oldFont);
  if (GetFocus() == m_hWnd) {
    drawFocusRect(dc);
  }
  return 0;
}
Example #3
0
//! Draw a focus rectangle on a widget using its style.
void QwtPainter::drawFocusRect( QPainter *painter, const QWidget *widget )
{
    drawFocusRect( painter, widget, widget->rect() );
}
Example #4
0
void KstViewLine::drawSelectRect(KstPainter& p) {
  p.setPen(QPen(Qt::black, 0));
  p.setBrush(QBrush(Qt::green, Qt::SolidPattern));
  drawFocusRect(p);
}
void IconsetDelegate::paint(QPainter *APainter, const QStyleOptionViewItem &AOption, const QModelIndex &AIndex) const
{
	QString name = AIndex.data(IDR_STORAGE).toString();
	QString subdir = AIndex.data(IDR_SUBSTORAGE).toString();

	IconStorage *storage = FStorages.value(name).value(subdir);
	if (storage==NULL && !name.isEmpty() && !subdir.isEmpty())
	{
		storage = new IconStorage(name,subdir);
		FStorages[name].insert(subdir,storage);
	}

	if (storage != NULL)
	{
		QStyleOptionViewItemV4 indexOption = indexStyleOption(AOption,AIndex);

#if defined(Q_WS_WIN) && !defined(QT_NO_STYLE_WINDOWSVISTA)
		QStyle *style = indexOption.widget ? indexOption.widget->style() : QApplication::style();
		if (qobject_cast<QWindowsVistaStyle *>(style))
		{
			indexOption.palette.setColor(QPalette::All, QPalette::HighlightedText, indexOption.palette.color(QPalette::Active, QPalette::Text));
			indexOption.palette.setColor(QPalette::All, QPalette::Highlight, indexOption.palette.base().color().darker(108));
		}
#endif

		APainter->save();
		APainter->setClipping(true);
		APainter->setClipRect(indexOption.rect);

		drawBackground(APainter,indexOption);

		int space = 2;
		QRect drawRect = indexOption.rect.adjusted(space,space,-space,-space);

		if (!AIndex.data(IDR_HIDE_STORAGE_NAME).toBool())
		{
			QRect ceckRect(drawRect.topLeft(),checkButtonRect(indexOption,drawRect,AIndex.data(Qt::CheckStateRole)).size());
			drawCheckButton(APainter,indexOption,ceckRect,static_cast<Qt::CheckState>(AIndex.data(Qt::CheckStateRole).toInt()));
			drawRect.setLeft(ceckRect.right()+space);

			QString displayText = storage->storageProperty(FILE_STORAGE_NAME,name+"/"+subdir);
			QRect textRect(drawRect.topLeft(),indexOption.fontMetrics.size(Qt::TextSingleLine,displayText));

			QPalette::ColorGroup cg = indexOption.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
			if (cg == QPalette::Normal && !(indexOption.state & QStyle::State_Active))
				cg = QPalette::Inactive;
			if (indexOption.state & QStyle::State_Selected)
				APainter->setPen(indexOption.palette.color(cg, QPalette::HighlightedText));
			else
				APainter->setPen(indexOption.palette.color(cg, QPalette::Text));
			APainter->drawText(textRect,indexOption.displayAlignment,displayText);

			drawRect.setTop(textRect.bottom() + space);
			drawRect.setLeft(indexOption.rect.left() + space);
		}

		int maxRows = AIndex.data(IDR_ICON_ROW_COUNT).isValid() ? AIndex.data(IDR_ICON_ROW_COUNT).toInt() : DEFAULT_ICON_ROW_COUNT;

		int row = 0;
		int column = 0;
		int iconIndex = 0;
		int left = drawRect.left();
		int top = drawRect.top();
		QList<QString> iconKeys = storage->fileFirstKeys();
		while (drawRect.bottom()>top && drawRect.right()>left && iconIndex<iconKeys.count() && row<maxRows)
		{
// *** <<< eyeCU <<< ***
			bool filtered=false;
			for (QStringList::ConstIterator it=FFilter.constBegin(); it!=FFilter.constEnd(); ++it)
				if (iconKeys.at(iconIndex).endsWith(*it))
				{
					filtered=true;
					break;
				}
			if (!filtered)
			{
// *** >>> eyeCU >>> ***
			QIcon icon = storage->getIcon(iconKeys.at(iconIndex));
			if (!icon.isNull())
			{
				QPixmap pixmap = icon.pixmap(indexOption.decorationSize,QIcon::Normal,QIcon::On);
				APainter->drawPixmap(left,top,pixmap);
				left += indexOption.decorationSize.width()+space;
			}
			// *** <<< eyeCU >>> ***
			column++;

			if (left >= drawRect.right()-indexOption.decorationSize.width())
			{
				column = 0;
				left = drawRect.left();
				top += indexOption.decorationSize.height()+space;
			}
// *** <<< eyeCU <<< ***
			}
			iconIndex++;
// *** >>> eyeCU >>> ***
		}

		drawFocusRect(APainter,indexOption,indexOption.rect);

		APainter->restore();
	}
	else
	{
		QStyledItemDelegate::paint(APainter,AOption,AIndex);
	}
}
Example #6
0
 void drawFocusRect(const MVRect& r,int color)
 { drawFocusRect(r.left(),r.top(),r.right(),r.bottom(),color); };
Example #7
0
/*!\reimp
 */
void QWindowsStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, int sliderStart, uint controls, uint activeControl )
{
#ifndef QT_NO_SCROLLBAR
#define ADD_LINE_ACTIVE ( activeControl == AddLine )
#define SUB_LINE_ACTIVE ( activeControl == SubLine )
    QColorGroup g  = sb->colorGroup();

    int sliderMin, sliderMax, sliderLength, buttonDim;
    scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );

    if (sliderStart > sliderMax) { // sanity check
	sliderStart = sliderMax;
    }

    int b = 0;
    int dimB = buttonDim;
    QRect addB;
    QRect subB;
    QRect addPageR;
    QRect subPageR;
    QRect sliderR;
    int addX, addY, subX, subY;
    int length = HORIZONTAL ? sb->width()  : sb->height();
    int extent = HORIZONTAL ? sb->height() : sb->width();

    if ( HORIZONTAL ) {
	subY = addY = ( extent - dimB ) / 2;
	subX = b;
	addX = length - dimB - b;
    } else {
	subX = addX = ( extent - dimB ) / 2;
	subY = b;
	addY = length - dimB - b;
    }

    subB.setRect( subX,subY,dimB,dimB );
    addB.setRect( addX,addY,dimB,dimB );

    int sliderEnd = sliderStart + sliderLength;
    int sliderW = extent - b*2;
    if ( HORIZONTAL ) {
	subPageR.setRect( subB.right() + 1, b,
			  sliderStart - subB.right() - 1 , sliderW );
	addPageR.setRect( sliderEnd, b, addX - sliderEnd, sliderW );
	sliderR .setRect( sliderStart, b, sliderLength, sliderW );
    } else {
	subPageR.setRect( b, subB.bottom() + 1, sliderW,
			  sliderStart - subB.bottom() - 1 );
	addPageR.setRect( b, sliderEnd, sliderW, addY - sliderEnd );
	sliderR .setRect( b, sliderStart, sliderW, sliderLength );
    }

    bool maxedOut = (sb->maxValue() == sb->minValue());
    if ( controls & AddLine ) {
	qDrawWinPanel( p, addB.x(), addB.y(),
		       addB.width(), addB.height(), g,
		       ADD_LINE_ACTIVE, &g.brush( QColorGroup::Button ) );
	drawArrow( p, VERTICAL ? DownArrow : RightArrow,
		   ADD_LINE_ACTIVE, addB.x()+2, addB.y()+2,
		   addB.width()-4, addB.height()-4, g, !maxedOut );
    }
    if ( controls & SubLine ) {
	qDrawWinPanel( p, subB.x(), subB.y(),
		       subB.width(), subB.height(), g,
		       SUB_LINE_ACTIVE, &g.brush( QColorGroup::Button )  );
	drawArrow( p, VERTICAL ? UpArrow : LeftArrow,
		   SUB_LINE_ACTIVE, subB.x()+2, subB.y()+2,
		   subB.width()-4, subB.height()-4, g, !maxedOut );
    }
    QBrush br =
	g.brush( QColorGroup::Light ).pixmap() ?
		 g.brush( QColorGroup::Light )     :
		 QBrush(g.light(), Dense4Pattern);
    p->setBrush( br );
    p->setPen( NoPen );
    p->setBackgroundMode( OpaqueMode );
    if ( maxedOut ) {
	p->drawRect( sliderR );
    } else {
	if ( (controls & SubPage && SubPage == activeControl) ||
	     (controls  & AddPage && AddPage == activeControl) ) {
	    QBrush b = p->brush();
	    QColor c = p->backgroundColor();
// 	    p->fillRect( AddPage == activeControl? addPageR : subPageR, g.fillDark() );
	    p->setBackgroundColor( g.dark() );
	    p->setBrush( QBrush(g.shadow(), Dense4Pattern) );
	    p->drawRect( AddPage == activeControl? addPageR : subPageR );
	    p->setBackgroundColor( c );
	    p->setBrush( b );
	}
	if ( controls & SubPage && SubPage != activeControl)
	    p->drawRect( subPageR );
	if ( controls & AddPage && AddPage != activeControl)
	    p->drawRect( addPageR );
	if ( controls & Slider ) {
	    if ( !maxedOut ) {
		QPoint bo = p->brushOrigin();
		if ( !sb->testWState(WState_GlobalBrushOrigin) )
		    p->setBrushOrigin(sliderR.topLeft());
		qDrawWinPanel( p, sliderR.x(), sliderR.y(),
				 sliderR.width(), sliderR.height(), g,
				 FALSE, &g.brush( QColorGroup::Button ) );
		p->setBrushOrigin(bo);
	    }
	}
    }
    // ### perhaps this should not be able to accept focus if maxedOut?
    if ( sb->hasFocus() && (controls & Slider) )
	drawFocusRect(p, QRect(sliderR.x()+2, sliderR.y()+2,
			       sliderR.width()-5, sliderR.height()-5), g,
		      &sb->backgroundColor());
#endif
}
Example #8
0
void ListViewDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
	QStyleOptionViewItemV4 opt = option;
	initStyleOption ( &opt, index );
	painter->save();
	painter->setClipRect ( opt.rect );

	opt.features |= QStyleOptionViewItem::WrapText;
	opt.text = index.data().toString();
	opt.textElideMode = Qt::ElideRight;
	opt.displayAlignment = Qt::AlignTop | Qt::AlignHCenter;

	QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();

	//const int iconSize =  style->pixelMetric(QStyle::PM_IconViewIconSize);
	const int iconSize = 48;
	QRect iconbox = opt.rect;
	const int textMargin = style->pixelMetric ( QStyle::PM_FocusFrameHMargin, 0, opt.widget ) + 1;
	QRect textRect = opt.rect;
	QRect textHighlightRect = textRect;
	// clip the decoration on top, remove width padding
	textRect.adjust ( textMargin,iconSize + textMargin + 5,-textMargin,0 );
	
	textHighlightRect.adjust ( 0,iconSize + 5,0,0 );

	// draw background
	{
		QSize textSize = viewItemTextSize ( &opt );
		QPalette::ColorGroup cg;
		QStyleOptionViewItemV4 opt2(opt);
		
		if((opt.widget && opt.widget->isEnabled()) || (opt.state & QStyle::State_Enabled))
		{
			if(! ( opt.state & QStyle::State_Active ))
				cg = QPalette::Inactive;
			else
				cg = QPalette::Normal;
		}
		else
		{
			cg = QPalette::Disabled;
		}
		opt2.palette.setCurrentColorGroup(cg);
		
		// fill in background, if any
		if ( opt.backgroundBrush.style() != Qt::NoBrush )
		{
			QPointF oldBO = painter->brushOrigin();
			painter->setBrushOrigin ( opt.rect.topLeft() );
			painter->fillRect ( opt.rect, opt.backgroundBrush );
			painter->setBrushOrigin ( oldBO );
		}
		
		if ( opt.showDecorationSelected )
		{
			drawSelectionRect(painter,opt2, opt.rect);
			drawFocusRect(painter,opt2, opt.rect);
			//painter->fillRect ( opt.rect, opt.palette.brush ( cg, QPalette::Highlight ) );
		}
		else
		{
			
			//if ( opt.state & QStyle::State_Selected )
			{
				//QRect textRect = subElementRect ( QStyle::SE_ItemViewItemText,  opt, opt.widget );
				//painter->fillRect ( textHighlightRect, opt.palette.brush ( cg, QPalette::Highlight ) );
				drawSelectionRect(painter,opt2, textHighlightRect);
				drawFocusRect(painter,opt2, textHighlightRect);
			}
		}
	}

	// draw the icon
	{
		QIcon::Mode mode = QIcon::Normal;
		if ( ! ( opt.state & QStyle::State_Enabled ) )
			mode = QIcon::Disabled;
		else if ( opt.state & QStyle::State_Selected )
			mode = QIcon::Selected;
		QIcon::State state = opt.state & QStyle::State_Open ? QIcon::On : QIcon::Off;

		iconbox.setHeight ( iconSize );
		opt.icon.paint ( painter, iconbox, Qt::AlignCenter, mode, state );
	}
	// set the text colors
	QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
	if ( cg == QPalette::Normal && ! ( opt.state & QStyle::State_Active ) )
		cg = QPalette::Inactive;
	if ( opt.state & QStyle::State_Selected )
	{
		painter->setPen ( opt.palette.color ( cg, QPalette::HighlightedText ) );
	}
	else
	{
		painter->setPen ( opt.palette.color ( cg, QPalette::Text ) );
	}

	// draw the text
	QTextOption textOption;
	textOption.setWrapMode ( QTextOption::WrapAtWordBoundaryOrAnywhere );
	textOption.setTextDirection ( opt.direction );
	textOption.setAlignment ( QStyle::visualAlignment ( opt.direction, opt.displayAlignment ) );
	QTextLayout textLayout;
	textLayout.setTextOption ( textOption );
	textLayout.setFont ( opt.font );
	textLayout.setText ( opt.text );

	qreal width, height;
	viewItemTextLayout ( textLayout, iconbox.width(), height, width );

	const int lineCount = textLayout.lineCount();

	const QRect layoutRect = QStyle::alignedRect ( opt.direction, opt.displayAlignment, QSize ( iconbox.width(), int ( height ) ), textRect );
	const QPointF position = layoutRect.topLeft();
	for ( int i = 0; i < lineCount; ++i )
	{
		const QTextLine line = textLayout.lineAt ( i );
		line.draw ( painter, position );
	}

	painter->restore();
}