Пример #1
0
void Editor::setHighlightColor( ColorType type, QColor color )
{
    d->highlightColors[ type ] = color;

    setSelectionAttributes( 1, highlightColor( Editor::MatchedPar ), false );
    setSelectionAttributes( 2, highlightColor( Editor::MatchedPar ), false );

    d->highlighter->rehighlight();
}
Пример #2
0
void StyleHelper::verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect)
{
    QString key;
    key.sprintf("mh_toolbar %d %d %d %d %d", spanRect.width(), spanRect.height(), clipRect.width(),
                                             clipRect.height(), StyleHelper::baseColor().rgb());;
    QPixmap pixmap;
    QPainter *p = painter;
    QRect rect = clipRect;
    if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
        pixmap = QPixmap(clipRect.size());
        p = new QPainter(&pixmap);
        rect = QRect(0, 0, clipRect.width(), clipRect.height());
    }

    QColor base = StyleHelper::baseColor();
    QLinearGradient grad(spanRect.topRight(), spanRect.topLeft());
    grad.setColorAt(0, highlightColor());
    grad.setColorAt(0.301, base);
    grad.setColorAt(1, shadowColor());
    p->fillRect(rect, grad);

    QColor light(255, 255, 255, 80);
    p->setPen(light);
    p->drawLine(rect.topRight() - QPoint(1, 0), rect.bottomRight() - QPoint(1, 0));

    if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
        painter->drawPixmap(clipRect.topLeft(), pixmap);
        p->end();
        delete p;
        QPixmapCache::insert(key, pixmap);
    }

}
Пример #3
0
void IPZoomWidget::paintEvent(QPaintEvent*)
{
    if(!_image)
        return;

    QPainter painter(this);
    QBrush brush(Qt::black);
    QColor highlightColor(Qt::red);

    int cellWidth = width()/(2*_columnOffset+1);

    int rectX = 0;
    int rectY = 0;
    for(int offsetY=-_columnOffset; offsetY <= _columnOffset; offsetY++)
    {
        for(int offsetX=-_columnOffset; offsetX <= _columnOffset; offsetX++)
        {
            uchar r = 0;
            uchar g = 0;
            uchar b = 0;
            if( _image->type() == IPLData::IMAGE_COLOR)
            {
                //uchar test = *_image->rgb32() + (_x+offsetX)*_image->height() + (_y+offsetY);
                r = _image->plane(0)->cp(_x+offsetX, _y+offsetY) * FACTOR_TO_UCHAR;
                g = _image->plane(1)->cp(_x+offsetX, _y+offsetY) * FACTOR_TO_UCHAR;
                b = _image->plane(2)->cp(_x+offsetX, _y+offsetY) * FACTOR_TO_UCHAR;

                highlightColor = QColor(255-r, 255-g, 255-b);
            }
            else if(_image->type() == IPLData::IMAGE_GRAYSCALE || _image->type() == IPLImage::IMAGE_BW)
            {
                r = g = b = _image->plane(0)->cp(_x+offsetX, _y+offsetY) * FACTOR_TO_UCHAR;

                highlightColor = QColor(255, 0, 0);
            }

            else if(_image->type() == IPLData::IMAGE_ORIENTED)
            {
                r = g = b = _image->plane(0)->cp(_x+offsetX, _y+offsetY) * FACTOR_TO_UCHAR;

                highlightColor = QColor(255, 0, 0);
            }

            brush.setColor(QColor(r, g, b));
            painter.fillRect(rectX+1, rectY+1, cellWidth-1, cellWidth-1, brush);

            // center
            if(offsetX == 0 && offsetY == 0)
            {
                painter.setPen(highlightColor);
                painter.drawRect(rectX, rectY, cellWidth, cellWidth);
            }

            rectX += cellWidth;
        }
        rectX = 0;
        rectY += cellWidth;
    }
}
Пример #4
0
void TapHighlightController::drawRect(PageOverlay* pageOverlay, GraphicsContext& context, const IntRect& dirtyRect)
{
    if (m_path.isEmpty())
        return;

    float fractionFadedIn = pageOverlay->fractionFadedIn();

    {
        GraphicsContextStateSaver stateSaver(context);
        context.setFillColor(highlightColor(m_color, fractionFadedIn), ColorSpaceSRGB);
        context.fillPath(m_path);
    }
}
Пример #5
0
void
MenuItem::drawButton( QPainter* p )
{
	QPen origPen = p->pen();
	p->setPen( Qt::NoPen );
	RasterOp origRasterOp = p->rasterOp();
// 	p->setRasterOp( OrROP );
	if( isDown() && m_mouseOver )
	{
 		p->fillRect( m_offset,
 					 m_offset,
					 geometry().width() - 2 * m_offset,
					 geometry().height() - 2 * m_offset,
					 QBrush( highlightColor().light() ) );
	}
	else if( m_mouseOver )
	{
		// if mouse is over the button, paint the highlight area with highlight color
 		p->fillRect( m_offset,
 					 m_offset,
					 geometry().width() - 2 * m_offset,
					 geometry().height() - 2 * m_offset,
					 QBrush( highlightColor() ) );
	}

	// Check if there's a sub menu, if so draw an arrow-like thing
	if( m_sub )
	{
		QPixmap arrow = KGlobal::iconLoader()->loadIcon( m_arrowIcon, KIcon::Toolbar );
		p->drawPixmap( geometry().width() - arrow.width() - m_offset - m_secOffset,
						( geometry().height() - arrow.height() ) / 2,
						arrow );
	}
	// Restore the settings
	p->setPen( origPen );
	p->setRasterOp( origRasterOp );
	// Draw the pixmap AND the labels
	drawLabel( p );
}
Пример #6
0
void StyleHelper::horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect)
{
    QString key;
    key.sprintf("mh_toolbar %d %d %d %d %d", spanRect.width(), spanRect.height(),
                clipRect.width(), clipRect.height(), StyleHelper::baseColor().rgb());
    QPixmap pixmap;
    QPainter *p = painter;
    QRect rect = clipRect;
    if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
        pixmap = QPixmap(clipRect.size());
        p = new QPainter(&pixmap);
        rect = QRect(0, 0, clipRect.width(), clipRect.height());
    }

    QColor base = StyleHelper::baseColor();
    QLinearGradient grad(rect.topLeft(), rect.bottomLeft());

    grad.setColorAt(0, highlightColor().lighter(120));
    grad.setColorAt(0.5, highlightColor());
    grad.setColorAt(0.501, base);
    grad.setColorAt(1, shadowColor());
    p->fillRect(rect, grad);

/*    QLinearGradient shadowGradient(spanRect.topLeft(), spanRect.topRight());
    shadowGradient.setColorAt(0, QColor(0, 0, 0, 30));
    QColor highlight = highlightColor().lighter(130);
    highlight.setAlpha(100);
    shadowGradient.setColorAt(0.7, highlight);
    shadowGradient.setColorAt(1, QColor(0, 0, 0, 40));
    p->fillRect(rect, shadowGradient);*/

    if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
        painter->drawPixmap(clipRect.topLeft(), pixmap);
        p->end();
        delete p;
        QPixmapCache::insert(key, pixmap);
    }
}
Пример #7
0
void Applet::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
	if(m_size.width() < 32)
		return; // Too small to draw a background (don't want to deal with weird corner cases).

	if(!m_interactive)
		return; // Currently, background is only used for highlight on interactive applets.

	painter->setPen(Qt::NoPen);
	qreal radius = (m_size.width()*m_size.width() + m_size.height()*m_size.height()) / (4.0*m_size.height());
	QPointF center(m_size.width()/2.0, m_size.height() + radius - m_size.height()/2.0);
	static const qreal radiusInc = 10.0;
	QRadialGradient gradient(center, radius + radiusInc, center);
	QColor highlightColor(255, 255, 255, static_cast<int>(150*m_highlightIntensity));
	gradient.setColorAt(0.0, highlightColor);
	gradient.setColorAt((radius - m_size.height()/2.0)/(radius + radiusInc), highlightColor);
	gradient.setColorAt(1.0, QColor(255, 255, 255, 0));
	painter->setBrush(QBrush(gradient));
	painter->drawRect(boundingRect());
}
Пример #8
0
void ProgressBarWidget::paintEvent(QPaintEvent *pEvent)
{
    // Draw ourselves and accept the event

    QPainter painter(this);

    if (isEnabled()) {
        int value = int(mValue*width());

        if (value != 0) {
            painter.fillRect(0, 0, value, height(), highlightColor());
        }

        if (value != width()) {
            painter.fillRect(value, 0, width()-value, height(), windowColor());
        }
    } else {
        painter.fillRect(0, 0, width(), height(), windowColor());
    }

    pEvent->accept();
}
Пример #9
0
/*!
  Creates a DOM node that describes this task link.

  \param doc the DOM document to which the node belongs
  \param parentElement the element into which to insert this node
*/
void KDGanttViewTaskLink::createNode( QDomDocument& doc,
                                      QDomElement& parentElement )
{
    QDomElement taskLinkElement = doc.createElement( "TaskLink" );
    parentElement.appendChild( taskLinkElement );

    QDomElement fromItemsElement = doc.createElement( "FromItems" );
    taskLinkElement.appendChild( fromItemsElement );
    QPtrList<KDGanttViewItem> fromList = from();
    KDGanttViewItem* item;
    for( item = fromList.first(); item;
         item = fromList.next() )
        KDGanttXML::createStringNode( doc, fromItemsElement, "Item", item->name() );

    QDomElement toItemsElement = doc.createElement( "ToItems" );
    taskLinkElement.appendChild( toItemsElement );
    QPtrList<KDGanttViewItem> toList = to();
    for( item = toList.first(); item;
         item = toList.next() )
        KDGanttXML::createStringNode( doc, toItemsElement, "Item", item->name() );

    KDGanttXML::createBoolNode( doc, taskLinkElement, "Highlight", highlight() );
    KDGanttXML::createColorNode( doc, taskLinkElement, "Color", color() );
    KDGanttXML::createColorNode( doc, taskLinkElement, "HighlightColor",
                            highlightColor() );
    KDGanttXML::createStringNode( doc, taskLinkElement, "TooltipText",
                             tooltipText() );
    KDGanttXML::createStringNode( doc, taskLinkElement, "WhatsThisText",
                             whatsThisText() );
    if( group() )
        KDGanttXML::createStringNode( doc, taskLinkElement, "Group",
                                 group()->name() );
    KDGanttXML::createBoolNode( doc, taskLinkElement, "Visible",
                           isVisible() );
    KDGanttXML::createStringNode( doc, taskLinkElement, "Linktype",
                             linkTypeToString( myLinkType ) );
}
Пример #10
0
void
HistogramDialog::recalculateHistogramRaw ()
{
    if(! m_visibleOnClient) return;

    ScopedDebug sd( "Recalculating histogram (slow)", 1);

    // drawable area width/height
    int daWidth = m_imageWidth - m_marginLeft - m_marginRight;
    int daHeight = m_imageHeight - m_marginTop - m_marginBottom;

    m_histInfo.min = zMin_;
    m_histInfo.max = zMax_;
    m_histInfo.nNans = 0;
    m_histInfo.maxBin = 0;
    int nBins;
    if( m_smoothGraph)
        nBins = std::max( daWidth , 10);
    else
        nBins = std::max( daWidth / 10, 10);

    m_histInfo.bins.resize ( nBins);
    for( int i = 0 ; i < nBins ; i ++ )
        m_histInfo.bins[i] = 0;

    quint64 trueCount = 0; // number of pixels in the clip range
    quint64 totalPixels = 0; // number of pixels that are not nans
    if( m_cir) {

        FitsParser & p = m_cir-> parser (); // alias

        FitsParser::HeaderInfo header = p.getHeaderInfo ();
//        totalPixels = header.naxis1 * header.naxis2;
        for( int y = 0 ; y < header.naxis2 ; y ++ ) {
            for( int x = 0 ; x < header.naxis1 ; x ++ ) {
                double v = p.src ( x, y, m_frameInfoNumber);
                if( isnan (v)) {
                    m_histInfo.nNans ++;
//                    totalPixels --;
                } else {
                    // TODO: centering in bins...?
                    int i = floor (nBins * (v - m_histInfo.min)/(m_histInfo.max - m_histInfo.min));
                    if( i >= 0 && i < nBins) {
                        m_histInfo.bins[i] ++;
                    }
                    if( v >= min() && v <= max()){
                        trueCount ++;
                    }
                }
            }
        }
        totalPixels = header.naxis1 * header.naxis2 - m_histInfo.nNans;

        // compute the highest count (so that we can scale this when drawing)
        for( int i = 0 ; i < m_histInfo.bins.size () ; i ++ ) {
            m_histInfo.maxBin = std::max( m_histInfo.maxBin, m_histInfo.bins[i]);
        }
    }

    // render the histogram
    QColor barColor( "#0071FD");
//    QColor backgroundColor( "#F3F3DA");
    QColor backgroundColor( "#ffffff");
    QColor highlightColor( "#FF0000");
    m_buffer = QImage( QSize(m_imageWidth, m_imageHeight), m_buffer.format());
    int ih = m_imageHeight;
    QPainter painter( & m_buffer);
    painter.setRenderHint( QPainter::Antialiasing, true);
    painter.setRenderHint( QPainter::HighQualityAntialiasing, true);
    painter.fillRect ( m_buffer.rect (), backgroundColor);

    // over which bin is the cursor?
    int cursorBin = m_cursorX - m_marginLeft;
    if( ! m_smoothGraph)
        cursorBin = floor( (m_cursorX - m_marginLeft) / double(daWidth) * nBins);
    cursorBin = clamp( cursorBin, 0, nBins - 1);

    double maxY = m_histInfo.maxBin;
    if( m_logScale) maxY = log( maxY + 1);
    double dx = double(daWidth) / nBins;
    for( int i = 0 ; i < m_histInfo.bins.size () ; i ++ ) {
        double y = m_histInfo.bins[i];
        if(y == 0) continue;
        if( m_logScale) y = log(y + 1);
        y = (daHeight-2) * y / double( maxY) + 2;
        //        painter.fillRect( QRectF( dx * i, ih, dx, -y ), barColor);
        QPoint p1( round( dx  * i) + m_marginLeft, ih - m_marginBottom);
        QPoint p2( round( dx  * (i+1)) - 1 + m_marginLeft, ih - m_marginBottom - y);

        if( i == cursorBin)
            painter.fillRect( QRect( p1, p2 ), highlightColor);
        else
            painter.fillRect( QRect( p1, p2 ), barColor);
    }

    // draw faint rectangles around bars (only if in bar mode)
    if( ! m_smoothGraph) {
        for( int i = 0 ; i < m_histInfo.bins.size () ; i ++ ) {
            double y = m_histInfo.bins[i];
            if( m_logScale) y = log(y + 1);
            y = daHeight * y / double( maxY);
            //        painter.fillRect( QRectF( dx * i, ih, dx, -y ), barColor);
            QPoint p1( round( dx  * i) + m_marginLeft, ih - m_marginBottom);
            QPoint p2( round( dx  * (i+1)) - 1 + m_marginLeft, ih - m_marginBottom - y);
            painter.setPen( QPen( QColor("black"), 0.1));
            painter.drawRect( QRect( p1, p2 ));
        }
    }

    // draw labels for horizontal
    {
        double yy = m_imageHeight - m_marginBottom + 1;
        Plot2dLabelers::BasicLabeler::SharedPtr horizLabeler = std::make_shared< Plot2dLabelers::BasicLabeler >();

        QFont m_fontHorizontalLabels( "Arial", 8);
        QFontMetrics m_fmHorizontalLabels( m_fontHorizontalLabels);
        int labelFontHeight = m_fmHorizontalLabels.height();
        auto measureTxt = [&m_fmHorizontalLabels]( const QString & str) -> double {
            return m_fmHorizontalLabels.width( str);
        };

        horizLabeler-> setZoom( zMin_, zMax_);
        horizLabeler-> setPixels( daWidth);
        horizLabeler-> setDual( false);
        auto labels = horizLabeler-> compute( measureTxt);

        painter.setFont( m_fontHorizontalLabels);
        painter.setPen( "black");
        QVector<QPointF> ticks;
        ticks.append( QPointF( m_marginLeft - 5, yy));
        ticks.append( QPointF( m_imageWidth - m_marginRight + 5, yy));
        for( auto & label : labels) {
            double xx = label.centerPix + m_marginLeft;
            painter.drawText( QRectF( xx, yy + labelFontHeight / 2.0 + 5, 1, 1),
                              Qt::AlignCenter | Qt::TextDontClip,
                              label.txt1
                              );
            ticks.append( QPointF( xx, m_imageHeight - m_marginBottom + 1));
            ticks.append( QPointF( xx, m_imageHeight - m_marginBottom + 5));
        }
        // tick marks
        painter.setPen( QPen( QBrush("blue"), 1));
        painter.drawLines( ticks);
    }

    // draw the markers
    double x1 = (min() - zMin_) / (zMax_ - zMin_) * daWidth + m_marginLeft;
    double x2 = (max() - zMin_) / (zMax_ - zMin_) * daWidth + m_marginLeft;
    painter.fillRect( QRectF( x1, 5, x2-x1, 5 ), QColor("#008800"));

    // draw the current cursor position
    double binCenter = (cursorBin + 0.5) / nBins * (zMax_ - zMin_) + zMin_;
    double cursorBinVal = m_histInfo.bins[ cursorBin];

    GetStateManager().ViewManager().RenderViewDeferred("HistogramView");

    // tell clients where the markers are
    pwset( "/Histogram/marker1", x1 / m_imageWidth);
    pwset( "/Histogram/marker2", x2 / m_imageWidth);

    // tell clients other stats
//    pwset("/Histogram/LowerClip", m_fvs.formatValue( min_));
//    pwset("/Histogram/UpperClip", m_fvs.formatValue( max_));
    m_vars.lowerClip-> set( min_);
    m_vars.upperClip-> set( max_);
    pwset("/Histogram/GlobalMin", m_fvs.formatValue( frameInfo_.min));
    pwset("/Histogram/GlobalMax", m_fvs.formatValue( frameInfo_.max));
    pwset( "/Histogram/nNaNs", m_histInfo.nNans);
    pwset( "/Histogram/binValue", m_fvs.formatValue( binCenter));
    pwset( "/Histogram/nValuesInBin", cursorBinVal);
    pwset( "/Histogram/trueCount", QString::number( 100 * double(trueCount) / totalPixels, 'g', 6) + "%");
}
Пример #11
0
//
// Whenever you change something here check both settingsdialog.cpp and settingsdialogmac.cpp !
//
SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
    QDialog(parent)
    , _ui(new Ui::SettingsDialog), _gui(gui)

{
    setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
    _ui->setupUi(this);
    QToolBar *toolBar = new QToolBar;
    toolBar->setIconSize(QSize(32,32));
    QString highlightColor(palette().highlight().color().name());
    QString altBase(palette().alternateBase().color().name());
    QString dark(palette().dark().color().name());
    toolBar->setStyleSheet(QString::fromAscii(TOOLBAR_CSS).arg(dark).arg(highlightColor).arg(altBase));
    toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    layout()->setMenuBar(toolBar);

    // People perceive this as a Window, so also make Ctrl+W work
    QAction *closeWindowAction = new QAction(this);
    closeWindowAction->setShortcut(QKeySequence("Ctrl+W"));
    connect(closeWindowAction, SIGNAL(triggered()), SLOT(accept()));
    addAction(closeWindowAction);

    setObjectName("Settings"); // required as group for saveGeometry call
    setWindowTitle(Theme::instance()->appNameGUI());

    // Add a spacer so config buttonns are right aligned and account buttons will be left aligned
    auto spacer = new QWidget();
    spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    toolBar->addWidget(spacer);

    // Note: all the actions have a '\n' because the account name is in two lines and
    // all buttons must have the same size in order to keep a good layout
    QIcon protocolIcon(QLatin1String(":/client/resources/activity.png"));
    _protocolAction = toolBar->addAction(protocolIcon, tr("Activity") + QLatin1Char('\n'));
    _protocolAction->setCheckable(true);
    ProtocolWidget *protocolWidget = new ProtocolWidget;
    _ui->stack->addWidget(protocolWidget);

    QIcon generalIcon(QLatin1String(":/client/resources/settings.png"));
    QAction *generalAction = toolBar->addAction(generalIcon, tr("General") + QLatin1Char('\n'));
    generalAction->setCheckable(true);
    GeneralSettings *generalSettings = new GeneralSettings;
    _ui->stack->addWidget(generalSettings);

    QIcon networkIcon(QLatin1String(":/client/resources/network.png"));
    QAction *networkAction = toolBar->addAction(networkIcon, tr("Network") + QLatin1Char('\n'));
    networkAction->setCheckable(true);
    NetworkSettings *networkSettings = new NetworkSettings;
    _ui->stack->addWidget(networkSettings);

    _actions.insert(_protocolAction, protocolWidget);
    _actions.insert(generalAction, generalSettings);
    _actions.insert(networkAction, networkSettings);

    QActionGroup *group = new QActionGroup(this);
    group->addAction(_protocolAction);
    group->addAction(generalAction);
    group->addAction(networkAction);
    group->setExclusive(true);
    connect(group, SIGNAL(triggered(QAction*)), SLOT(slotSwitchPage(QAction*)));

    connect(AccountManager::instance(), SIGNAL(accountAdded(AccountState*)),
            this, SLOT(accountAdded(AccountState*)));
    connect(AccountManager::instance(), SIGNAL(accountRemoved(AccountState*)),
            this, SLOT(accountRemoved(AccountState*)));
    foreach (auto ai , AccountManager::instance()->accounts()) {
        accountAdded(ai.data());
    }
Пример #12
0
void
MenuItem::drawLabel( QPainter* p )
{
	RasterOp origRasterOp = p->rasterOp();
	if( m_mouseOver )
	{
// 		p->setRasterOp( OrROP );
	}
	// Prepare the title and desc
	
	// This is the available width that we can print text. This is the place just next to the pixmap
	uint availableWidth = geometry().width() - ( 2 * m_offset ) - pixmap()->width() - ( 4 * m_secOffset );
	
	// If there's a sub menu we'll draw an arrow in this button, so texts area gets smaller
	if( m_sub )
		availableWidth -= KGlobal::iconLoader()->loadIcon( m_arrowIcon, KIcon::Toolbar ).width() - m_secOffset;
	
	// Titles will be printed in one line definetely, so squeze it to fit
	QString s_title = KStringHandler::rPixelSqueeze( title(), p->fontMetrics(), availableWidth );

	// Draw the icon
	p->drawPixmap( m_offset + m_secOffset,
				   m_offset + m_secOffset,
				   *pixmap() );

	if( !description().isNull() )
	{
		// Write the description with smaller font
		QFont smallerFont = p->font();
	
		// Make the font smaller by m_descFontOffset points
		smallerFont.setPointSize( smallerFont.pointSize() - m_descFontOffset );

		////// MOVE LINE SPLICING CODE TO ABOVE
		// Let's see if we can use more than one line, because descriptions
		// are more likely to be longer
		
		// Active area height = total widget height - 2 * primary offset
		int activeAreaHeight = geometry().height() - 2 * m_offset;
		// Available desc height = Active area height - title height
		int availableDescHeight = activeAreaHeight - p->fontMetrics().height();
		// One desc line height
		int descLineHeight = QFontMetrics( smallerFont ).height();
		// Let's see how many desc lines are available
		int lineCount =  availableDescHeight / descLineHeight;

		// Prepare each line of text
		QString desc = description().stripWhiteSpace();
		QString line = desc;
		QStringList lines;

		if( lineCount > 1 )
		{
			for( int j = 0; j < lineCount; j++ )
			{
				uint size = QFontMetrics( smallerFont ).width( desc );
	
				if( ( j + 1 ) != lineCount )
				{
					while( size > availableWidth )
					{
							// Remove the last word untill it fits in one line
						line = line.section( " ", 0, -2 );
						size = QFontMetrics( smallerFont ).width( line );
					}
				}
				else
				{
					// This is the last available line, so squeze the rest
					line = KStringHandler::rPixelSqueeze( desc,
														  p->fontMetrics(),
														  availableWidth
														);
				}
				lines.push_back( line );
				desc = desc.mid( line.length() ).stripWhiteSpace();
				line = desc;
				if( line.isEmpty() ) break;
			}
		}
		else
		{
			lines.push_back( KStringHandler::rPixelSqueeze( desc,
															p->fontMetrics(),
															availableWidth ) );
		}
	
		uint totalTextHeight = p->fontMetrics().height() + 
							   lines.count() * descLineHeight;
		int offset = ( geometry().height() - totalTextHeight ) / 2;
	
		// Write the title of the cell 
		p->drawText( QRect( m_offset + pixmap()->width() + 2 * m_secOffset,
							offset,
							availableWidth,
							p->fontMetrics().height()
					  	),
					 		Qt::AlignLeft, s_title );
	
		// Print each line of the comment
		QFont origFont = p->font();
		QPen origPen = p->pen();
		p->setFont( smallerFont );
		p->setPen( highlightColor().light( 300 ) );
		int i = 0;
		int titleHeight = QFontMetrics( origFont ).height();
		QStringList::Iterator it;
		for( it = lines.begin(); it != lines.end(); ++it, i++ )
		{
			int lineOffset = i * p->fontMetrics().height();
			p->drawText( m_offset + pixmap()->width() + 2 * m_secOffset,
					 	offset + titleHeight + lineOffset,
					 	availableWidth,
					 	p->fontMetrics().height(),
					 	Qt::AlignLeft,
					 	*it );
		}
		
		// Restore to original font and pen
		p->setFont( origFont );
		p->setPen( origPen );
	}
	else
	{
		int offset = ( geometry().height() - p->fontMetrics().height() ) / 2;

		// Write the title of the cell 
		p->drawText( QRect( m_offset + pixmap()->width() + 2 * m_secOffset,
							offset,
							availableWidth,
							p->fontMetrics().height()
						  ),
				 			Qt::AlignLeft, s_title );
	}

	if( m_mouseOver )
	{
		p->setRasterOp( origRasterOp );
	}
}
Пример #13
0
void YaTabBarBase::drawTab(QPainter* painter, int index, const QRect& tabRect)
{
	QStyleOptionTabV2 tab = getStyleOption(index);
	if (!(tab.state & QStyle::State_Enabled)) {
		tab.palette.setCurrentColorGroup(QPalette::Disabled);
	}

	// Don't bother drawing a tab if the entire tab is outside of the visible tab bar.
	if (tabRect.right() < 0 ||
	    tabRect.left() > width() ||
	    tabRect.bottom() < 0 ||
	    tabRect.top() > height() ||
	    tabRect.width() < 3)
	{
		return;
	}

	bool isCurrent = index == currentIndex();
	bool isHovered = tabHovered(index);
	bool isHighlighted = tabData(index).toBool();

	QColor backgroundColor = this->tabBackgroundColor();
	if (isCurrent) {
#ifndef WIDGET_PLUGIN
		backgroundColor = Ya::VisualUtil::editAreaColor();
#else
		backgroundColor = Qt::white;
#endif
	}
	else if (isHovered) {
#ifndef WIDGET_PLUGIN
		backgroundColor = Ya::VisualUtil::tabHighlightColor();
#else
		backgroundColor = Qt::gray;
#endif
	}
	else if (isHighlighted) {
		backgroundColor = highlightColor();
	}

	if (backgroundColor.isValid()) {
		painter->fillRect(tabRect, backgroundColor);
	}

	painter->save();
#ifndef WIDGET_PLUGIN
	painter->setPen(Ya::VisualUtil::rosterTabBorderColor());
#endif

	bool drawLeftLine  = tabRect.left() != rect().left();
	bool drawRightLine = true; // tabRect.right() != rect().right() || rect().width() < maximumWidth();

	switch (shape()) {
	case YaTabBarBase::RoundedSouth:
	case YaTabBarBase::TriangularSouth:
		if (isMultiLine())
			drawRightLine = tabRect.right() + 1 < maximumWidth();

		if (!isCurrent || isMultiLine())
			painter->drawLine(tabRect.topLeft(), tabRect.topRight());

		if (isCurrent) {
			if (drawLeftLine && !isMultiLine())
				painter->drawLine(tabRect.topLeft(), tabRect.bottomLeft());
			if (drawRightLine)
				painter->drawLine(tabRect.topRight(), tabRect.bottomRight());
		}
		else {
			if (isHovered || isMultiLine()) {
				if (currentIndex() != (index - 1) && !isMultiLine())
					if (drawLeftLine)
						painter->drawLine(tabRect.topLeft(), tabRect.bottomLeft());
				if (currentIndex() != (index + 1) || isMultiLine())
					if (drawRightLine)
						painter->drawLine(tabRect.topRight(), tabRect.bottomRight());
			}
		}
		break;
	default:
		Q_ASSERT(false);
		break;
	}

	painter->restore();

	tabIcon(index).paint(painter, tabIconRect(index));

	QRect textRect = tabTextRect(index);
	QString text = tabText(index);

	if (drawTabNumbers_ && index < 10) {
		int numberToDraw = index + 1;
		if (numberToDraw > 9) {
			numberToDraw = 0;
		}

		painter->save();
		painter->setPen(Qt::gray);
		QString numberToDrawText = QString::number(numberToDraw) + " ";
		painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, numberToDrawText);
		textRect.adjust(fontMetrics().width(numberToDrawText), 0, 0, 0);
		painter->restore();
	}

	painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, text);
#ifndef WIDGET_PLUGIN
	if (textWidth(text) > textRect.width() && backgroundColor.isValid()) {
		Ya::VisualUtil::drawTextFadeOut(painter, textRect.adjusted(1, 0, 1, 0), backgroundColor, 15);
	}
#endif

	if (isMultiLine()) {
		QPixmap shadow(tabShadow(isCurrent));
		QRect r(tabRect);
		r.setHeight(shadow.height());
		painter->drawTiledPixmap(r, shadow);
	}
}
Пример #14
0
void
MenuColumn::loadItems()
{
    // Open column's config file
    KDesktopFile cfg( "xkmenu/" + m_name + "/spec.desktop", true ,"data" );

    // Set column specific colors if defined in the file
    setBackgroundColor( cfg.readColorEntry( "BackgroundColor" ) );
    setHighlightColor( cfg.readColorEntry( "HighlightColor" ) );

    // Read directories in the column directory. These are components.
    QStringList compDirs = KGlobal::dirs()->findDirs( "data", "xkmenu/" + m_name  );
    QStringList::ConstIterator it;
    for( it = compDirs.begin(); it != compDirs.end(); ++it )
    {
        QDir d( *it );
        QStringList comps = d.entryList( "*", QDir::Dirs);
        // Now iterate through components
        for( QStringList::ConstIterator comp = comps.begin(); comp != comps.end(); ++comp )
        {
            if( *comp == "." || *comp == ".." ) continue;

            // Read components config file.
            KDesktopFile compCfg( *it + "/" + *comp + "/spec.desktop" );
            QString type = compCfg.readType();

            if( type.lower() == "static" )
            {
                addComponent( new GenericComponent( *it + "/" + *comp,
                                                    this,
                                                    backgroundColor(),
                                                    highlightColor()  )
                            );
            }
            else if( type.lower() == "built-in" || type.lower() == "builtin" )
            {
                QString factory = compCfg.readEntry( "Factory" );
                if( factory.lower() == "all programs" )
                {
                    addComponent( new AllProgramsComponent( this, backgroundColor(), highlightColor() ) );
                }
                else if( factory.lower() == "recent programs" )
                {
                    addComponent( new RecentApplicationsComponent( this, backgroundColor(), highlightColor() ) );
                }
                else if( factory.lower() == "menu extensions" )
                {
                    addComponent( new MenuExtensionsComponent( this, backgroundColor(), highlightColor() ) );
                }
                else if( factory.lower() == "separator" )
                {
                    //! FIXME: make separator read it's own config file
                    addComponent( new SeparatorComponent( this, backgroundColor(),
                                                          compCfg.readColorEntry( "HighlightColor" ) ) );
                }
            }
            else if( type.lower() == "plugin" || type.lower() == "plug-in" )
            {
                //! TODO: implement dynamic loading... later
            }
        }
        addSpacer();
    }
}