Ejemplo n.º 1
0
void
drawQueryBackground( QPainter* p, const QPalette& palette, const QRect& r, qreal lightnessFactor )
{
    p->setPen( palette.highlight().color().lighter( lightnessFactor * 100 ) );
    p->setBrush( palette.highlight().color().lighter( lightnessFactor * 100 ) );
    p->drawRoundedRect( r, 4.0, 4.0 );
}
Ejemplo n.º 2
0
void TextOutput::loadColorStyleScheme()
{
    bool useColorShceme = m_liteApp->settings()->value(TEXTOUTPUT_USECOLORSCHEME,true).toBool();

    const ColorStyleScheme *colorScheme = m_liteApp->editorManager()->colorStyleScheme();
    const ColorStyle *text = colorScheme->findStyle("Text");
    const ColorStyle *selection = colorScheme->findStyle("Selection");
    const ColorStyle *keyword = colorScheme->findStyle("Keyword");
    const ColorStyle *error = colorScheme->findStyle("Error");

    QPalette p = this->m_defPalette;
    if (useColorShceme && text) {
        if (text->foregound().isValid()) {
            p.setColor(QPalette::Text,text->foregound());
            p.setColor(QPalette::Foreground, text->foregound());
        }
        if (text->background().isValid()) {
            p.setColor(QPalette::Base, text->background());
        }
    }
    if (useColorShceme && selection) {
        if (selection->foregound().isValid()) {
            p.setColor(QPalette::HighlightedText, selection->foregound());
        }
        if (selection->background().isValid()) {
            p.setColor(QPalette::Highlight, selection->background());
        }
        p.setBrush(QPalette::Inactive, QPalette::Highlight, p.highlight());
        p.setBrush(QPalette::Inactive, QPalette::HighlightedText, p.highlightedText());
    }

    QString sheet = QString("QPlainTextEdit{color:%1;background-color:%2;selection-color:%3;selection-background-color:%4;}")
                .arg(p.text().color().name())
                .arg(p.base().color().name())
                .arg(p.highlightedText().color().name())
                .arg(p.highlight().color().name());
    this->setPalette(p);
    this->setStyleSheet(sheet);

    m_clrText = p.text().color();

    m_fmt.setForeground(p.text().color());
    m_fmt.setBackground(p.base().color());

    if (useColorShceme && keyword && keyword->foregound().isValid()) {
        m_clrTag = keyword->foregound();
    } else {
        m_clrTag = Qt::darkBlue;
    }
    if (useColorShceme && error && error->foregound().isValid()) {
        m_clrError = error->foregound();
    } else {
        m_clrError = Qt::red;
    }
    this->updateExistsTextColor();
}
Ejemplo n.º 3
0
void TimeTrackingView::PaintAttributes::initialize( const QPalette& palette ) {
    headerBrush = palette.mid();
    taskBrushEven = palette.light();
    taskBrushOdd = palette.midlight();
    totalsRowBrush = headerBrush;
    totalsRowEvenDayBrush = QBrush( taskBrushEven.color().darker(125) );
    headerEvenDayBrush = totalsRowEvenDayBrush;
    QColor dimHighlight = palette.highlight().color();
    dim = 0.25;
    dimHighlight.setAlphaF( dim * dimHighlight.alphaF() );
    const QBrush halfHighlight( dimHighlight );
    runningTaskColor = palette.highlight().color();
}
Ejemplo n.º 4
0
    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
        if (option.state & QStyle::State_Selected) {
            painter->fillRect(option.rect, option.palette.color(QPalette::Highlight));
            painter->setPen(option.palette.color(QPalette::HighlightedText));
        }

        QString text = index.data(Qt::DisplayRole).toString();
        QRect r = option.rect.adjusted(option.rect.height() + 4, 0, -4 - option.rect.height(), 0);
        painter->drawText(r, Qt::AlignVCenter | Qt::AlignLeft, text, &r);
        QColor swatch_color = index.data(Qt::UserRole).value<QColor>();

        if (!swatch_color.isValid()) {
            // Special cases for colors we want to come from the system
            QPalette defaultPalette;

            if (text == QString(tr("Background"))) {
                swatch_color = defaultPalette.base().color();
            } else if (text == QString(tr("Foreground"))) {
                swatch_color = defaultPalette.windowText().color();
            } else if (text == QString(tr("Selection Background"))) {
                swatch_color = defaultPalette.highlight().color();
            } else if (text == QString(tr("Selection Foreground"))) {
                swatch_color = defaultPalette.highlightedText().color();
            }
        }

        r = option.rect.adjusted(1, 1, option.rect.height() - option.rect.width(), -2);
        painter->setPen(Qt::black);
        painter->setBrush(swatch_color);
        painter->drawRect(r);
    }
void StarRating::paint(QPainter *painter, const QRect &rect,
                       const QPalette &palette, EditMode mode) const {
    painter->save();
    painter->setRenderHint(QPainter::Antialiasing, true);
    painter->setPen(Qt::NoPen);
    QBrush yellowBrush(QColor::fromCmyk(0,128,255,0));
    if (mode == Editable) {
        painter->setBrush(palette.highlight());
    } else {
        painter->setBrush(yellowBrush);

    }

    int yOffset = (rect.height() - PaintingScaleFactor) / 2;
    painter->translate(rect.x(), rect.y() + yOffset);
    painter->scale(PaintingScaleFactor, PaintingScaleFactor);

    for (int i = 0; i < m_maxStars; ++i) {
        if (i < m_stars) {
            painter->drawPolygon(m_starPolygon, Qt::WindingFill);
        } else if (mode == Editable) {
            painter->drawPolygon(m_diamondPolygon, Qt::WindingFill);
        }
        painter->translate(1.0, 0.0);
    }

    painter->restore();
}
Ejemplo n.º 6
0
void KstMatrixTable::paintCell( QPainter* painter, int row, int col, const QRect& cr, bool selected, const QPalette &palette ) {
  KstMatrixPtr matrix = *KST::matrixList.findTag(_strMatrix);
  QString str;
  double value;

  painter->eraseRect( 0, 0, cr.width(), cr.height() );
  if (selected) {
    painter->fillRect( 0, 0, cr.width(), cr.height(), palette.highlight() );
    painter->setPen(palette.highlightedText().color());
  } else {
    painter->fillRect( 0, 0, cr.width(), cr.height(), palette.base() );
    painter->setPen(palette.text().color());
  }

  if (matrix) {
    bool ok;
    value = matrix->valueRaw(col, row, &ok);
    if (ok) {
      str.setNum(value, 'g', 16);
    } else {
      str = "-";
    }
  }

  painter->drawText(0, 0, cr.width(), cr.height(), Qt::AlignLeft, str);
}
Ejemplo n.º 7
0
//! [2]
void StarRating::paint(QPainter *painter, const QRect &rect,
                       const QPalette &palette, EditMode mode) const
{
    painter->save();

    painter->setRenderHint(QPainter::Antialiasing, true);
    painter->setPen(Qt::NoPen);

    if (mode == Editable) {
        painter->setBrush(palette.highlight());
    } else {
        painter->setBrush(palette.foreground());
    }

    int yOffset = (rect.height() - PaintingScaleFactor) / 2;
    painter->translate(rect.x(), rect.y() + yOffset);
    painter->scale(PaintingScaleFactor, PaintingScaleFactor);

    for (int i = 0; i < myMaxStarCount; ++i) {
        if (i < myStarCount) {
            painter->drawPolygon(starPolygon, Qt::WindingFill);
        } else if (mode == Editable) {
            painter->drawPolygon(diamondPolygon, Qt::WindingFill);
        }
        painter->translate(1.0, 0.0);
    }

    painter->restore();
}
Ejemplo n.º 8
0
static void drawRectBox(QPainter *painter, const QRect &rect, bool start, bool end,
                        const QPalette &pal)
{
    painter->save();
    painter->setRenderHint(QPainter::Antialiasing, false);

    QRgb b = pal.base().color().rgb();
    QRgb h = pal.highlight().color().rgb();
    QColor c = StyleHelper::mergedColors(b,h, 50);

    QLinearGradient grad(rect.topLeft(), rect.topRight());
    grad.setColorAt(0, c.lighter(110));
    grad.setColorAt(1, c.lighter(130));
    QColor outline = c;

    painter->fillRect(rect, grad);
    painter->setPen(outline);
    if (start)
        painter->drawLine(rect.topLeft() + QPoint(1, 0), rect.topRight() -  QPoint(1, 0));
    if (end)
        painter->drawLine(rect.bottomLeft() + QPoint(1, 0), rect.bottomRight() -  QPoint(1, 0));

    painter->drawLine(rect.topRight() + QPoint(0, start ? 1 : 0), rect.bottomRight() - QPoint(0, end ? 1 : 0));
    painter->drawLine(rect.topLeft() + QPoint(0, start ? 1 : 0), rect.bottomLeft() - QPoint(0, end ? 1 : 0));

    painter->restore();
}
void KTModuleWidgetBase::enterEvent(QEvent *e)
{
    Q_UNUSED(e);
    QPalette pal = palette();
    pal.setBrush(QPalette::Background, pal.highlight ());
    pal.setBrush(QPalette::Text, pal.base ());
    m_title->setPalette(pal);
}
Ejemplo n.º 10
0
 void highlight(bool value) {
     if (value) {
         QPalette palette;
         QPen p(palette.highlight(), SELECT_FRAME_WIDTH);
         frame_->setPen(p);
     }
     else {
         frame_->setPen(QPen(QBrush(), 0));
     }
 }
Ejemplo n.º 11
0
// Simple color frame for swatch
SeExprEdColorFrame::SeExprEdColorFrame(SeVec3d value, QWidget* parent) :
    QFrame(parent), _value(value)
{
    setValue(_value);
    setFrameStyle(QFrame::Box | QFrame::Plain);
    QPalette pal = palette();
    pal.setColor(backgroundRole(), pal.highlight().color());
    setPalette(pal);
    setAutoFillBackground(true);
}
Ejemplo n.º 12
0
/** Redefined. */
void PlaylistHeaderView::paintEvent(QPaintEvent *)
{
	QStylePainter p(this->viewport());

	QLinearGradient vLinearGradient(rect().topLeft(), QPoint(rect().left(), rect().top() + rect().height()));
	/// XXX
	QPalette palette = QApplication::palette();
	if (SettingsPrivate::instance()->isCustomColors()) {
		vLinearGradient.setColorAt(0, palette.base().color().lighter(110));
		vLinearGradient.setColorAt(1, palette.base().color());
	} else {
		vLinearGradient.setColorAt(0, palette.base().color());
		vLinearGradient.setColorAt(1, palette.window().color());
	}

	QStyleOptionHeader opt;
	opt.initFrom(this->viewport());
	p.fillRect(rect(), QBrush(vLinearGradient));
	p.setPen(opt.palette.windowText().color());
	QRect r;
	p.save();
	if (QGuiApplication::isLeftToRight()) {
		p.translate(-offset(), 0);
	} else {
		p.translate(offset(), 0);
	}
	for (int i = 0; i < count(); i++) {
		QRect r2(sectionPosition(i), viewport()->rect().y(), sectionSize(i), viewport()->rect().height());
		p.drawText(r2, Qt::AlignCenter, model()->headerData(i, Qt::Horizontal).toString());
		if (r2.contains(mapFromGlobal(QCursor::pos()))) {
			r = r2;
		}
	}
	p.restore();
	if (!r.isNull()) {
		p.save();
		p.setPen(palette.highlight().color());
		p.drawLine(r.x(), r.y() + r.height() / 4,
				   r.x(), r.y() + 3 * r.height() / 4);
		p.drawLine(r.x() + r.width() - 1, r.y() + r.height() / 4,
				   r.x() + r.width() - 1, r.y() + 3 * r.height() / 4);
		p.restore();
	}

	// Bottom frame
	p.setPen(QApplication::palette().mid().color());
	p.drawLine(rect().bottomLeft(),  QPoint(rect().left() + rect().width(), rect().top() + rect().height()));

	// Vertical frame
	if (QGuiApplication::isLeftToRight()) {
		p.drawLine(rect().topLeft(), QPoint(rect().left(), rect().top() + rect().height()));
	} else {
		p.drawLine(rect().topRight(), QPoint(rect().right(), rect().top() + rect().height()));
	}
}
Ejemplo n.º 13
0
void CountdownFrame::paintEvent( QPaintEvent *e )
{
    QFrame::paintEvent( e );

    QPalette p = palette();
    p.setCurrentColorGroup( QPalette::Active );

    QPainter( this ).fillRect( 2, m_filled * height() , width() - 4, height()
                               - ( m_filled * height() ) , p.highlight()
                             );
}
void highlight_dial(QDial *d)
{
	QPalette pe = d->palette();
	pe.setBrush(QPalette::Button, pe.highlight());
	d->setPalette(pe);

	d->setRange(0, 360 * MY_ANGLE_TICK);
	d->setSingleStep(1 * MY_ANGLE_TICK);
	d->setPageStep(10 * MY_ANGLE_TICK);
	d->setWrapping(true);
	d->setNotchesVisible(true);
}
Ejemplo n.º 15
0
void FormStyle::GlobalColorButtonCliked()
{
	QColor initialColor;
	if ( focusWidget()->objectName() == "bC1_1" )
		initialColor = applicationPalette.button().color().rgba();
	else if ( focusWidget()->objectName() == "bC1_2" )
		initialColor = applicationPalette.window().color().rgba();
	else if ( focusWidget()->objectName() == "bC1_3" )
		initialColor = applicationPalette.shadow().color().rgba();
	else if ( focusWidget()->objectName() == "bC1_4" )
		initialColor = applicationPalette.highlight().color().rgba();
	else if ( focusWidget()->objectName() == "bC1_5" )
		initialColor = applicationPalette.base().color().rgba();
	else if ( focusWidget()->objectName() == "bC1_6" )
		initialColor = applicationPalette.text().color().rgba();
	else if ( focusWidget()->objectName() == "bC1_7" )
		initialColor = applicationPalette.highlightedText().color().rgba();
	else if ( focusWidget()->objectName() == "bC1_8" )
		initialColor = sliderButtonColor.rgb();
	else
		initialColor = Qt::white;

	QColor color = QColorDialog::getColor( initialColor, this, Texts[ 119 ] /*Wybierz kolor*/, QColorDialog::DontUseNativeDialog );

	if ( !color.isValid() )
		return;

	if ( focusWidget()->objectName() == "bC1_1" )
		applicationPalette.setBrush( QPalette::Button, color );
	else if ( focusWidget()->objectName() == "bC1_2" )
		applicationPalette.setBrush( QPalette::Window, color );
	else if ( focusWidget()->objectName() == "bC1_3" )
	{
		applicationPalette.setBrush( QPalette::Shadow, color );
		applicationPalette.setBrush( QPalette::Light, color );
		applicationPalette.setBrush( QPalette::Dark, color );
	} else if ( focusWidget()->objectName() == "bC1_4" )
		applicationPalette.setBrush( QPalette::Highlight, color );
	else if ( focusWidget()->objectName() == "bC1_5" )
		applicationPalette.setBrush( QPalette::Base, color );
	else if ( focusWidget()->objectName() == "bC1_6" )
	{
		applicationPalette.setBrush( QPalette::Text, color );
		applicationPalette.setBrush( QPalette::WindowText, color );
		applicationPalette.setBrush( QPalette::ButtonText, color );
	} else if ( focusWidget()->objectName() == "bC1_7" )
		applicationPalette.setBrush( QPalette::HighlightedText, color );
	else if ( focusWidget()->objectName() == "bC1_8" )
		sliderButtonColor = color;

	setButtonsColor();
}
Ejemplo n.º 16
0
void MiamStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
    switch (element) {
    case CE_MenuBarItem: {
        const QStyleOptionMenuItem *somi = static_cast<const QStyleOptionMenuItem*>(option);
        const bool act = somi->state & (State_Sunken | State_Selected);
        QPalette palette = QApplication::palette();
        QBrush brush;
        //bool dirtyHackMnemonic = widget->property("dirtyHackMnemonic").toBool();
        if (act/* || dirtyHackMnemonic && option->rect.x() == 0*/) {
            painter->setPen(palette.highlight().color());
            brush = palette.highlight().color().light();
            painter->setBrush(brush);
            painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
        } else {
            brush = palette.window();
            painter->fillRect(option->rect, palette.window());
        }

        uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
        if (/*dirtyHackMnemonic == false &&*/ !styleHint(SH_UnderlineShortcut, somi, widget)) {
            alignment |= Qt::TextHideMnemonic;
        }
        if (qAbs(palette.text().color().value() - brush.color().value()) < 128) {
            painter->setPen(palette.highlightedText().color());
        } else {
            painter->setPen(palette.text().color());
        }
        painter->drawText(option->rect, alignment, somi->text);
        break;
    }
    case CE_MenuBarEmptyArea: {
        painter->fillRect(option->rect, QApplication::palette().window());
        break;
    }
    default:
        QProxyStyle::drawControl(element, option, painter, widget);
    }
}
Ejemplo n.º 17
0
void SlopeEditor::paintEvent(QPaintEvent* event) {
	QPainter painter(this);
	QPalette pal = QApplication::palette();
	if(isEnabled()) {
		pal.setCurrentColorGroup(QPalette::Normal);
	} else {
		pal.setCurrentColorGroup(QPalette::Disabled);
	}
	float scale = event->rect().height() / 16;
	QPoint start(0,0), end(event->rect().right(),0);
	start.setY(_left * scale);
	end.setY(_right * scale);
	//qDebug() << (_slope != 0 ? event->rect().height()/_slope : 0);
	QPolygon p;
	painter.setRenderHint(QPainter::Antialiasing);
	painter.fillRect(0, 0, width(), height(), pal.color(QPalette::Base));
	QPen slopePen;
	slopePen.setColor(pal.color(QPalette::Text));
	slopePen.setStyle(Qt::SolidLine);
	slopePen.setWidth(1);
	QBrush brush = pal.highlight();
	painter.setBrush(brush);
	painter.setPen(slopePen);
	if(!_slopeOnBottom) {
		p.setPoints(4, start.x(), start.y(), end.x() + 1, end.y(), event->rect().right() + 1, event->rect().bottom() + 1, event->rect().left(), event->rect().bottom() + 1);
		painter.drawPolygon(p);
	} else {
		p.setPoints(4, start.x(), start.y(), end.x() + 1, end.y(), event->rect().right() + 1, event->rect().top(), event->rect().left(), event->rect().top());
		painter.drawPolygon(p);
	}
	//handles
	painter.setBrush(Qt::NoBrush);
	start.rx() += width()/16;
	end.rx() -= width()/16;
	if(start.y() == height()) {
		start.ry() -= width()/16;
	}
	if(start.y() == 0) {
		start.ry() += width()/16;
	}
	if(end.y() == height()) {
		end.ry() -= width()/16;
	}
	if(end.y() == 0) {
		end.ry() += width()/16;
	}
	painter.drawEllipse(start, width()/16, width()/16);
	painter.drawEllipse(end, width()/16, width()/16);
}
Ejemplo n.º 18
0
/*! \~russian
 * \brief Метод инициализирует элементы настройки цвета в соответствии с переданной палитрой.
 * \param palette - палитра для инициализации
 */
void Settings::initColorPickers(QPalette palette)
{
    ui->Frame_Style_Window->setColor( palette.window().color() );
    ui->Frame_Style_WindowText->setColor( palette.windowText().color() );
    ui->Frame_Style_Base->setColor( palette.base().color() );
    ui->Frame_Style_AlternateBase->setColor( palette.alternateBase().color() );
    ui->Frame_Style_ToolTipBase->setColor( palette.toolTipBase().color() );
    ui->Frame_Style_ToolTipText->setColor( palette.toolTipText().color() );
    ui->Frame_Style_Text->setColor( palette.text().color() );
    ui->Frame_Style_Button->setColor( palette.button().color() );
    ui->Frame_Style_ButtonText->setColor( palette.buttonText().color() );
    ui->Frame_Style_BrightText->setColor( palette.brightText().color() );
    ui->Frame_Style_Link->setColor( palette.link().color() );
    ui->Frame_Style_Highlight->setColor( palette.highlight().color() );
    ui->Frame_Style_HighlightedText->setColor( palette.highlightedText().color() );
}
Ejemplo n.º 19
0
void FormStyle::setButtonsColor()
{
	if ( ui.ccB->isChecked() )
	{
		QPalette tmpPalette;

		tmpPalette.setBrush( QPalette::Button, applicationPalette.button() );
		ui.bC1_1->setPalette( tmpPalette );
		tmpPalette.setBrush( QPalette::Button, applicationPalette.window() );
		ui.bC1_2->setPalette( tmpPalette );
		tmpPalette.setBrush( QPalette::Button, applicationPalette.shadow() );
		ui.bC1_3->setPalette( tmpPalette );
		tmpPalette.setBrush( QPalette::Button, applicationPalette.highlight() );
		ui.bC1_4->setPalette( tmpPalette );
		tmpPalette.setBrush( QPalette::Button, applicationPalette.base() );
		ui.bC1_5->setPalette( tmpPalette );
		tmpPalette.setBrush( QPalette::Button, applicationPalette.text() );
		ui.bC1_6->setPalette( tmpPalette );
		tmpPalette.setBrush( QPalette::Button, applicationPalette.highlightedText() );
		ui.bC1_7->setPalette( tmpPalette );
		tmpPalette.setBrush( QPalette::Button, sliderButtonColor );
		ui.bC1_8->setPalette( tmpPalette );

		if ( !mainWindowPixmap.isNull() )
		{
			QBrush brushW( mainWindowPixmap.scaled( ui.bP2_2->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
			tmpPalette.setBrush( QPalette::Button, brushW );
			ui.bP2_2->setPalette( tmpPalette );
		}
		else
			ui.bP2_2->setPalette( qApp->palette() );
	}
	else
	{
		ui.bC1_1->setPalette( qApp->palette() );
		ui.bC1_2->setPalette( qApp->palette() );
		ui.bC1_3->setPalette( qApp->palette() );
		ui.bC1_4->setPalette( qApp->palette() );
		ui.bC1_5->setPalette( qApp->palette() );
		ui.bC1_6->setPalette( qApp->palette() );
		ui.bC1_7->setPalette( qApp->palette() );
		ui.bC1_8->setPalette( qApp->palette() );

		ui.bP2_2->setPalette( qApp->palette() );
	}
}
Ejemplo n.º 20
0
void
DynamicWidget::paintRoundedFilledRect( QPainter& p, QPalette& pal, QRect& r, qreal opacity )
{   
    p.setBackgroundMode( Qt::TransparentMode );
    p.setRenderHint( QPainter::Antialiasing );
    p.setOpacity( opacity );
    
    QPen pen( pal.dark().color(), .5 );
    p.setPen( pen );
    p.setBrush( pal.highlight() );
    
    p.drawRoundedRect( r, 10, 10 );
    
    p.setOpacity( opacity + .2 );
    p.setBrush( QBrush() );
    p.setPen( pen );
    p.drawRoundedRect( r, 10, 10 );
}
Ejemplo n.º 21
0
QString Charm::reportStylesheet( const QPalette& palette )
{
    QString style;
    QFile stylesheet( ":/Charm/report_stylesheet.sty" );
    if ( stylesheet.open( QIODevice::ReadOnly | QIODevice::Text ) ) {
        style = stylesheet.readAll();
        style.replace(QLatin1String("@header_row_background_color@"), palette.highlight().color().name());
        style.replace(QLatin1String("@header_row_foreground_color@"), palette.highlightedText().color().name());
        style.replace(QLatin1String("@alternate_row_background_color@"), palette.alternateBase().color().name());
        style.replace(QLatin1String("@event_attributes_row_background_color@"), palette.midlight().color().name());
        if ( style.isEmpty() ) {
            qWarning() << "reportStylesheet: default style sheet is empty, too bad";
        }
    } else {
        qCritical() << "reportStylesheet: cannot load report style sheet:" << stylesheet.errorString();
    }
    return style;
}
Ejemplo n.º 22
0
QVariantMap Bridge::get_palette()
{
    QVariantMap colors;
    QPalette palette = qApp->palette();
    colors.insert("window", palette.window().color().name());
    colors.insert("window_text", palette.windowText().color().name());
    colors.insert("base", palette.base().color().name());
    colors.insert("alternate_base", palette.alternateBase().color().name());
    colors.insert("text", palette.text().color().name());
    colors.insert("button", palette.buttonText().color().name());
    colors.insert("bright_text", palette.brightText().color().name());
    colors.insert("light", palette.light().color().name());
    colors.insert("midlight", palette.midlight().color().name());
    colors.insert("dark", palette.dark().color().name());
    colors.insert("mid", palette.mid().color().name());
    colors.insert("shadow", palette.shadow().color().name());
    colors.insert("highlight", palette.highlight().color().name());
    colors.insert("highlight_text", palette.highlightedText().color().name());
    colors.insert("link", palette.link().color().name());
    colors.insert("link_visited", palette.linkVisited().color().name());
    return colors;
}
Ejemplo n.º 23
0
QVariant FileBrowserModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

    FileBrowserItem *item = static_cast<FileBrowserItem*>(index.internalPointer());
    QString path = "";//virtual path
    QStringList dirs = createRemotePath(item).split("\\");

    if (dirs.size() >= 2){
        dirs.removeFirst();

        path = "/" + dirs.join("/");
    }
    else
        path = "";

    switch(role) {
        case Qt::DecorationRole:
        {
            if (item->dir && index.column() == COLUMN_FILEBROWSER_NAME)
                return WICON(WulforUtil::eiFOLDER_BLUE).scaled(16, 16);
            else if (index.column() == COLUMN_FILEBROWSER_NAME)
                return WulforUtil::getInstance()->getPixmapForFile(item->data(COLUMN_FILEBROWSER_NAME).toString()).scaled(16, 16);
        }
        case Qt::DisplayRole:
        {
            if (restrict_map.contains(path) && index.column() == COLUMN_FILEBROWSER_NAME){
                QString ret = tr("%1 [%2 Gb]").arg(item->data(index.column()).toString()).arg(restrict_map[path]);

                return ret;
            }

            return item->data(index.column());
        }
        case Qt::TextAlignmentRole:
        {
            bool align_right = (index.column() == COLUMN_FILEBROWSER_ESIZE) || (index.column() == COLUMN_FILEBROWSER_SIZE);

            if (align_right)
                return Qt::AlignRight;
            else
                return Qt::AlignLeft;
        }
        case Qt::ForegroundRole:
        {
            if (item->dir || ownList)
                break;

            TTHValue t(_tq(item->data(COLUMN_FILEBROWSER_TTH).toString()));

            if (ShareManager::getInstance()->isTTHShared(t)){
                static QColor c;

                c.setNamedColor(WSGET(WS_APP_SHARED_FILES_COLOR));
                c.setAlpha(WIGET(WI_APP_SHARED_FILES_ALPHA));

                return c;
            }

            break;
        }
        case Qt::BackgroundColorRole:
        {
            if (item->isDuplicate){
                QPalette pal = qApp->palette();

                return pal.highlight().color();
            }
        }
        case Qt::ToolTipRole:
        {
            if (item->isDuplicate && item->file){
                const QString &tth = item->data(COLUMN_FILEBROWSER_TTH).toString();
                auto it = hash.find(tth);

                if (it == hash.end())
                    break;

                dcpp::DirectoryListing::File *file = const_cast<dcpp::DirectoryListing::File*>(it.value());
                dcpp::DirectoryListing::Directory *parentDir = file->getParent();

                if (!parentDir)
                    break;

                QString path = "";

                do {
                    path = _q(parentDir->getName()) + "/" + path;
                    parentDir = parentDir->getParent();
                } while (parentDir->getParent());

                return tr("File marked as a duplicate of another file: %1").arg(path+_q(file->getName()));
            }
            
            QString tooltip = "";
            
            if (item->dir){
                tooltip = item->data(COLUMN_FILEBROWSER_NAME).toString();
            }
            
            if (item->file){
                DirectoryListing::File *f = item->file;
                
                if (!f->mediaInfo.video_info.empty() || !f->mediaInfo.audio_info.empty()){
                    MediaInfo &mi = f->mediaInfo;

                    tooltip = tr("<b>Media Info:</b><br/>");
                    if (!f->mediaInfo.video_info.empty())
                        tooltip += tr("&nbsp;&nbsp;<b>Video:</b> %1<br/>").arg(_q(mi.video_info));
                    if (!f->mediaInfo.audio_info.empty())
                        tooltip += tr("&nbsp;&nbsp;<b>Audio:</b> %1<br/>").arg(_q(mi.audio_info));
                    if (f->mediaInfo.bitrate > 0)
                        tooltip += tr("&nbsp;&nbsp;<b>Bitrate:</b> %1<br/>").arg(mi.bitrate);
                    if (!f->mediaInfo.resolution.empty())
                        tooltip += tr("&nbsp;&nbsp;<b>Resolution:</b> %1<br/><br/>").arg(_q(mi.resolution));
                }
            }

            TTHValue t(_tq(item->data(COLUMN_FILEBROWSER_TTH).toString()));
            ShareManager *SM = ShareManager::getInstance();

            if (!ownList){
                try{
                    QString toolTip = _q(SM->toReal(SM->toVirtual(t)));

                    return tooltip + tr("File already exists: %1").arg(toolTip);
                }catch( ... ){};
            }

            if (!tooltip.isEmpty())
                return tooltip;
            
            break;
        }
        case Qt::FontRole:
        {
            if (restrict_map.contains(path) && index.column() == COLUMN_FILEBROWSER_NAME){
                QFont f;
                f.setBold(true);

                return f;
            }

            break;
        }
        default:
            break;
    }

    return QVariant();
}
Ejemplo n.º 24
0
void QgisAppStyleSheet::buildStyleSheet( const QMap<QString, QVariant>& opts )
{
  QString ss = QString( "" );


  // QgisApp-wide font
  QString fontSize = opts.value( "fontPointSize" ).toString();
  QgsDebugMsg( QString( "fontPointSize: %1" ).arg( fontSize ) );
  if ( fontSize.isEmpty() ) { return; }

  QString fontFamily = opts.value( "fontFamily" ).toString();
  QgsDebugMsg( QString( "fontFamily: %1" ).arg( fontFamily ) );
  if ( fontFamily.isEmpty() ) { return; }

  ss += QString( "* { font: %1pt \"%2\"} " ).arg( fontSize ).arg( fontFamily );

  // QGroupBox and QgsCollapsibleGroupBox, mostly for Ubuntu and Mac
  bool gbxCustom = opts.value( "groupBoxCustom" ).toBool();
  QgsDebugMsg( QString( "groupBoxCustom: %1" ).arg( gbxCustom ) );
  bool gbxBoldTitle = opts.value( "groupBoxBoldTitle" ).toBool();
  QgsDebugMsg( QString( "groupBoxBoldTitle: %1" ).arg( gbxBoldTitle ) );
  bool sidebar = opts.value( "sidebarStyle" ).toBool();
  if ( gbxCustom || gbxBoldTitle )
  {
    ss += "QGroupBox{";
    if ( gbxBoldTitle )
    {
      // doesn't work for QGroupBox::title
      ss += QString( "color: rgb(%1,%1,%1);" ).arg( mMacStyle ? 25 : 60 );
      ss += "font-weight: bold;";
    }
    if ( gbxCustom )
    {
      ss += QString( "background-color: rgba(0,0,0,%1%);" )
            .arg( mWinOS && mStyle.startsWith( "windows" ) ? 0 : 3 );
      ss += "border: 1px solid rgba(0,0,0,20%);";
      ss += "border-radius: 5px;";
      ss += "margin-top: 2.5ex;";
      ss += QString( "margin-bottom: %1ex;" ).arg( mMacStyle ? 1.5 : 1 );
    }
    ss += "} ";
    if ( gbxCustom )
    {
      ss += "QGroupBox:flat{";
      ss += "background-color: rgba(0,0,0,0);";
      ss += "border: rgba(0,0,0,0);";
      ss += "} ";

      ss += "QGroupBox::title{";
      ss += "subcontrol-origin: margin;";
      ss += "subcontrol-position: top left;";
      ss += "margin-left: 6px;";
      if ( !( mWinOS && mStyle.startsWith( "windows" ) ) && !mOxyStyle )
      {
        ss += "background-color: rgba(0,0,0,0);";
      }
      ss += "} ";
    }
  }

  if ( sidebar )
  {
    QString style = "QListWidget#mOptionsListWidget {"
                    "    background-color: rgb(69, 69, 69, 220);"
                    "    outline: 0;"
                    "}"
                    "QListWidget#mOptionsListWidget::item {"
                    "    color: white;"
                    "    padding: 3px;"
                    "}"
                    "QListWidget#mOptionsListWidget::item::selected {"
                    "    color: black;"
                    "    background-color:palette(Window);"
                    "    padding-right: 0px;"
                    "}";
    ss += style;
  }

  //fix background issue for gnome desktop
  if ( mLinuxOS && mGtkStyle && !sidebar )
  {
    ss += "QListWidget#mOptionsListWidget{";
    ss += "background-color: white;";
    ss += "} ";
  }

  // Fix selection color on loosing focus (Windows)
  const QPalette palette = qApp->palette();

  ss += QString( "QTableView {"
                 "selection-background-color: %1;"
                 "selection-color: %2;"
                 "}" )
        .arg( palette.highlight().color().name() )
        .arg( palette.highlightedText().color().name() );

  QgsDebugMsg( QString( "Stylesheet built: %1" ).arg( ss ) );

  emit appStyleSheetChanged( ss );
}
Ejemplo n.º 25
0
wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
{
    QPalette pal = qApp->palette();
    QColor color;
    switch (index)
    {
        case wxSYS_COLOUR_SCROLLBAR:
        case wxSYS_COLOUR_BACKGROUND:
        //case wxSYS_COLOUR_DESKTOP:
        case wxSYS_COLOUR_INACTIVECAPTION:
        case wxSYS_COLOUR_MENU:
        case wxSYS_COLOUR_WINDOWFRAME:
        case wxSYS_COLOUR_ACTIVEBORDER:
        case wxSYS_COLOUR_INACTIVEBORDER:
            color = pal.color(QPalette::Window);
            break;

        //case wxSYS_COLOUR_3DFACE:
        case wxSYS_COLOUR_3DLIGHT:
            color = pal.color(QPalette::Light);
            break;

        case wxSYS_COLOUR_BTNFACE:
            color = pal.color(QPalette::Button);
            break;

        case wxSYS_COLOUR_WINDOW:
            color = pal.color(QPalette::Base);
            break;

        case wxSYS_COLOUR_MENUBAR:
            color = pal.window().color();
            break;

        case wxSYS_COLOUR_3DDKSHADOW:
            color = pal.color(QPalette::Shadow);
            break;

        case wxSYS_COLOUR_BTNSHADOW:
            color = pal.color(QPalette::Dark);
            break;

        case wxSYS_COLOUR_GRAYTEXT:
        //case wxSYS_COLOUR_3DSHADOW:
            color = pal.color(QPalette::Disabled, QPalette::Text);
            break;

        case wxSYS_COLOUR_BTNHIGHLIGHT:
        //case wxSYS_COLOUR_BTNHILIGHT:
        //case wxSYS_COLOUR_3DHIGHLIGHT:
        //case wxSYS_COLOUR_3DHILIGHT:
            color = pal.color(QPalette::Light);
            break;

        case wxSYS_COLOUR_HIGHLIGHT:
            color = pal.highlight().color();
            break;

        case wxSYS_COLOUR_LISTBOX:
            color = pal.base().color();
            break;

        case wxSYS_COLOUR_LISTBOXTEXT:
            color = pal.color(QPalette::WindowText);
            break;

        case wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT:
            // This is for the text in a list control (or tree) when the
            // item is selected, but not focused
            color = pal.color(QPalette::HighlightedText);
            break;

        case wxSYS_COLOUR_WINDOWTEXT:
            color = pal.color(QPalette::Text);
            break;

        case wxSYS_COLOUR_MENUTEXT:
        case wxSYS_COLOUR_CAPTIONTEXT:
        case wxSYS_COLOUR_INACTIVECAPTIONTEXT:
        case wxSYS_COLOUR_BTNTEXT:
            color = pal.color(QPalette::ButtonText);
            break;

        case wxSYS_COLOUR_INFOBK:
            color = pal.color(QPalette::ToolTipBase);
            break;

        case wxSYS_COLOUR_INFOTEXT:
            color = pal.color(QPalette::ToolTipText);
            break;

        case wxSYS_COLOUR_HIGHLIGHTTEXT:
            color = pal.color(QPalette::BrightText);
            break;

        case wxSYS_COLOUR_APPWORKSPACE:
            color = QColor(Qt::white);    // ?
            break;

        case wxSYS_COLOUR_ACTIVECAPTION:
        case wxSYS_COLOUR_MENUHILIGHT:
            color = pal.color(QPalette::Highlight);
            break;

        case wxSYS_COLOUR_HOTLIGHT:
        case wxSYS_COLOUR_GRADIENTACTIVECAPTION:
        case wxSYS_COLOUR_GRADIENTINACTIVECAPTION:
            // TODO
            color = QColor(Qt::black);
            break;

        case wxSYS_COLOUR_MAX:
        default:
            wxFAIL_MSG( wxT("unknown system colour index") );
            color = QColor(Qt::white);
            break;
    }

    return wxColor( color.red(), color.green(), color.blue(), color.alpha() );
}
Ejemplo n.º 26
0
/** Redefined. */
void AddressBarButton::paintEvent(QPaintEvent *)
{
	QStylePainter p(this);
	QRect r = rect().adjusted(0, 1, -1, -(1 + extra));
	static const int arrowWidth = r.height();

	QPalette palette = QApplication::palette();
	QLinearGradient g(rect().topLeft(), rect().bottomLeft());
	g.setColorAt(0, palette.base().color());
	g.setColorAt(1, palette.window().color());
	p.fillRect(r, g);

	// Compute size of rectangles to display text and right arrow
	if (_atLeastOneSubDir) {
		if (isLeftToRight()) {
			_arrowRect = QRect(r.width() - arrowWidth, r.y(), arrowWidth, r.height());
			_textRect = QRect(r.x(), r.y(), r.width() - arrowWidth, r.height());
		} else {
			_arrowRect = QRect(r.x(), r.y(), arrowWidth, r.height());
			_textRect = QRect(r.x() + arrowWidth, r.y(), r.width() - arrowWidth, r.height());
		}
	} else {
		_textRect = r.adjusted(0, 0, -5, 0);
	}

	// Highlight button if mouse is over
	QPoint pos = mapFromGlobal(QCursor::pos());
	p.save();
	QBrush brush;
	if (_addressBar->isDown()) {
		brush = palette.highlight().color().lighter();
	} else {
		brush = palette.highlight().color().lighter(lighterValue);
	}

	if (_highlighted) {
		p.setPen(palette.highlight().color());
		p.setBrush(brush);
		p.drawRect(_textRect);
		if (_atLeastOneSubDir) {
			p.drawRect(_arrowRect);
		}
	} else {
		if (_atLeastOneSubDir) {
			if (_textRect.contains(pos) || _arrowRect.contains(pos)) {
				p.setPen(palette.highlight().color());
				p.setBrush(brush);
				p.drawRect(_textRect);
				p.drawRect(_arrowRect);
			} else {
				p.setPen(Qt::NoPen);
				p.setBrush(Qt::NoBrush);
				p.drawRect(_textRect);
				p.drawRect(_arrowRect);
			}
		} else {
			if (_textRect.contains(pos)) {
				p.setPen(palette.highlight().color());
				p.setBrush(brush);
				p.drawRect(_textRect);
			}
		}
	}
	p.restore();

	// Draw folder's name
	QColor lighterBG = palette.highlight().color().lighter();
	QColor highlightedText = palette.highlightedText().color();

	if (rect().contains(pos) && SettingsPrivate::instance()->isCustomTextColorOverriden()) {
		p.setPen(palette.highlightedText().color());
	} else if (qAbs(lighterBG.value() - highlightedText.value()) > 128 && _highlighted) {
		p.setPen(highlightedText);
	} else {
		p.setPen(palette.text().color());
	}

	// Special case for root and drives
	bool root = false;
	if (_path.isRoot()) {
		QPixmap pixmap = QFileIconProvider().icon(QFileIconProvider::Computer).pixmap(20, 20);
		QString drive;
		if (_isAbsoluteRoot) {
			pixmap = QFileIconProvider().icon(QFileIconProvider::Computer).pixmap(20, 20);
			if (isLeftToRight()) {
				p.drawPixmap(2, 3, 20, 20, pixmap);
			} else {
				p.drawPixmap(18, 3, 20, 20, pixmap);
			}
		} else {
			drive = AddressBar::getVolumeInfo(_path.absolutePath());
			if (!_isAbsoluteRoot && !drive.isEmpty()) {
				// Add a small offset to simulate a pressed button
				if (_highlighted) {
					p.translate(1, 1);
				}
				p.drawText(_textRect.adjusted(5, 0, 0, 0), Qt::AlignCenter, drive);
			}
			pixmap = QFileIconProvider().icon(QFileIconProvider::Drive).pixmap(20, 20);
		}
	} else {
		if (!_path.dirName().isEmpty()) {
			// Add a small offset to simulate a pressed button
			if (_highlighted) {
				p.translate(1, 1);
			}
			p.drawText(_textRect.adjusted(0, 0, 0, 0), Qt::AlignCenter, _path.dirName());
		}
	}

	if (_atLeastOneSubDir) {
		QStyleOptionButton o;
		o.initFrom(this);
		p.save();
		p.setPen(Qt::NoPen);
		p.setBrush(o.palette.mid());
		if (root && _addressBar->hasHiddenFolders()) {
			/// Right To Left
			QPoint p1(o.rect.x() + 32, o.rect.y() + 11),
					p2(o.rect.x() + 29, o.rect.y() + 14),
					p2b(o.rect.x() + 29, o.rect.y() + 13),
					p3(o.rect.x() + 32, o.rect.y() + 16);
			p.save();
			p.setPen(Qt::black);
			p.setRenderHint(QPainter::Antialiasing);
			p.drawLine(p1, p2);
			p.drawLine(p2b, p3);
			p.translate(4, 0);
			p.drawLine(p1, p2);
			p.drawLine(p2b, p3);
			p.restore();
		} else {
			int w = _arrowRect.width() / 3;
			int h = this->rect().height() / 3;
			QRect indicatorArrow(_arrowRect.x() + w + 1, _arrowRect.y() + h, w, h);

			o.rect = indicatorArrow;
			p.setRenderHint(QPainter::Antialiasing);

			p.save();
			QPen pen(palette.mid().color());
			pen.setWidthF(1.5);
			pen.setJoinStyle(Qt::MiterJoin);
			p.setPen(pen);
			QPolygon pol;
			QPoint p1, p2, p3;
			if (_highlighted) {
				p.translate(0, -1);
				p1 = QPoint(o.rect.x(), o.rect.y() + o.rect.height() / 2);
				p2 = QPoint(o.rect.x() + o.rect.width(), o.rect.y() + o.rect.height() / 2);
				p3 = QPoint(o.rect.x() + o.rect.width() / 2, o.rect.y() + o.rect.height());
			} else if (isLeftToRight()) {
				p1 = QPoint(o.rect.x(), o.rect.y());
				p2 = QPoint(o.rect.x(), o.rect.y() + o.rect.height());
				p3 = QPoint(o.rect.x() + o.rect.width(), o.rect.y() + o.rect.height() / 2);
			} else {
				p1 = QPoint(o.rect.x() + o.rect.width(), o.rect.y());
				p2 = QPoint(o.rect.x() + o.rect.width(), o.rect.y() + o.rect.height());
				p3 = QPoint(o.rect.x(), o.rect.y() + o.rect.height() / 2);
			}
			pol.append(p1);
			pol.append(p2);
			pol.append(p3);
			p.drawPolygon(pol);
			p.restore();
			p.setRenderHint(QPainter::Antialiasing, false);
		}
		p.restore();
	}
}
Ejemplo n.º 27
0
/** Redefined to be able to display items with the current theme. */
void AddressBarMenu::paintEvent(QPaintEvent *)
{
	QStylePainter p(this->viewport());
	// Vertical frame between icons and text
	p.save();
	QPalette palette = QApplication::palette();
	p.setPen(palette.midlight().color());
	p.drawLine(33, 0, 33, rect().height());
	p.restore();

	int offsetSB = 0;
	if (verticalScrollBar()->isVisible()) {
		offsetSB = verticalScrollBar()->width() - 1;
	}

	// Subdirectories in the popup menu
	for (int i = 0; i < count(); i ++) {
		QListWidgetItem *it = item(i);
		QRect r = this->visualItemRect(it);
		/// FIXME
		//QSize s = it->sizeHint();
		//QRect r(0, i * s.height(), );
		//qDebug() << "r" << r;
		r.setWidth(r.width() - offsetSB);

		if (it->data(Qt::UserRole + 1).toBool()) {
			p.save();
			p.setPen(palette.midlight().color());
			p.drawLine(r.x(), r.y() + (it->sizeHint().height()) / 2, r.width(), r.y() + (it->sizeHint().height()) / 2);
			p.restore();
			continue;
		}

		r.adjust(1, 1, -4, -1);
		bool isHighlighted = r.contains(mapFromGlobal(QCursor::pos()));
		// Draw: Highlight, Icon, Text
		if (r.isValid()) {
			QRect iconRect(r.x() + 6, r.y() + 2, 19, 19);
			bool itemIsEnabled = true;
			if (it->flags().testFlag(Qt::NoItemFlags)) {
				p.drawPixmap(iconRect, it->icon().pixmap(QSize(19, 19), QIcon::Disabled));
				itemIsEnabled = false;
			} else {
				p.save();
				if (isHighlighted) {
					p.setPen(palette.highlight().color());
					p.setBrush(palette.highlight().color().lighter());
					p.drawRect(r);
					p.setPen(QColor(192, 192, 192, 128));
					p.drawLine(33, r.top() + 1, 33, r.bottom());
				}
				p.restore();
				p.drawPixmap(iconRect, it->icon().pixmap(QSize(19, 19)));
			}

			QRect textRect = r.adjusted(37, 0, 0, 0);
			QString text = fontMetrics().elidedText(it->text(), Qt::ElideRight, textRect.width());
			p.save();

			p.setFont(it->font());
			QColor lighterBG = palette.highlight().color().lighter();
			QColor highlightedText = palette.highlightedText().color();
			if (itemIsEnabled && isHighlighted && qAbs(lighterBG.saturation() - highlightedText.saturation()) > 128) {
				p.setPen(highlightedText);
			} else {
				if (itemIsEnabled) {
					p.setPen(palette.text().color());
				} else {
					p.setPen(palette.color(QPalette::Disabled, QPalette::WindowText));
				}
			}

			p.drawText(textRect, text, Qt::AlignLeft | Qt::AlignVCenter);
			p.restore();
		}
	}
}
Ejemplo n.º 28
0
void QgisAppStyleSheet::buildStyleSheet( const QMap<QString, QVariant> &opts )
{
  QString ss;

  // QgisApp-wide font
  QString fontSize = opts.value( QStringLiteral( "fontPointSize" ) ).toString();
  QgsDebugMsg( QStringLiteral( "fontPointSize: %1" ).arg( fontSize ) );
  if ( fontSize.isEmpty() ) { return; }

  QString fontFamily = opts.value( QStringLiteral( "fontFamily" ) ).toString();
  QgsDebugMsg( QStringLiteral( "fontFamily: %1" ).arg( fontFamily ) );
  if ( fontFamily.isEmpty() ) { return; }

  const QString defaultSize = QString::number( mDefaultFont.pointSize() );
  const QString defaultFamily = mDefaultFont.family();
  if ( fontSize != defaultSize || fontFamily != defaultFamily )
    ss += QStringLiteral( "* { font: %1pt \"%2\"} " ).arg( fontSize, fontFamily );

  // Fix for macOS Qt 5.9+, where close boxes do not show on document mode tab bar tabs
  // See: https://bugreports.qt.io/browse/QTBUG-61092
  //      https://bugreports.qt.io/browse/QTBUG-61742
  // Setting any stylesheet makes the default close button disappear.
  // Specifically setting a custom close button temporarily works around issue.
  // TODO: Remove when regression is fixed (Qt 5.9.3 or 5.10?); though hard to tell,
  //       since we are overriding the default close button image now.
  if ( mMacStyle )
  {
    ss += QLatin1String( "QTabBar::close-button{ image: url(:/images/themes/default/mIconCloseTab.svg); }" );
    ss += QLatin1String( "QTabBar::close-button:hover{ image: url(:/images/themes/default/mIconCloseTabHover.svg); }" );
  }

  // QGroupBox and QgsCollapsibleGroupBox, mostly for Ubuntu and Mac
  bool gbxCustom = opts.value( QStringLiteral( "groupBoxCustom" ) ).toBool();
  QgsDebugMsg( QStringLiteral( "groupBoxCustom: %1" ).arg( gbxCustom ) );

  ss += QLatin1String( "QGroupBox{" );
  // doesn't work for QGroupBox::title
  ss += QStringLiteral( "color: rgb(%1,%1,%1);" ).arg( mMacStyle ? 25 : 60 );
  ss += QLatin1String( "font-weight: bold;" );

  if ( gbxCustom )
  {
    ss += QStringLiteral( "background-color: rgba(0,0,0,%1%);" )
          .arg( mWinOS && mStyle.startsWith( QLatin1String( "windows" ) ) ? 0 : 3 );
    ss += QLatin1String( "border: 1px solid rgba(0,0,0,20%);" );
    ss += QLatin1String( "border-radius: 5px;" );
    ss += QLatin1String( "margin-top: 2.5ex;" );
    ss += QStringLiteral( "margin-bottom: %1ex;" ).arg( mMacStyle ? 1.5 : 1 );
  }
  ss += QLatin1String( "} " );
  if ( gbxCustom )
  {
    ss += QLatin1String( "QGroupBox:flat{" );
    ss += QLatin1String( "background-color: rgba(0,0,0,0);" );
    ss += QLatin1String( "border: rgba(0,0,0,0);" );
    ss += QLatin1String( "} " );

    ss += QLatin1String( "QGroupBox::title{" );
    ss += QLatin1String( "subcontrol-origin: margin;" );
    ss += QLatin1String( "subcontrol-position: top left;" );
    ss += QLatin1String( "margin-left: 6px;" );
    if ( !( mWinOS && mStyle.startsWith( QLatin1String( "windows" ) ) ) && !mOxyStyle )
    {
      ss += QLatin1String( "background-color: rgba(0,0,0,0);" );
    }
    ss += QLatin1String( "} " );
  }

  //sidebar style
  QString style = "QListWidget#mOptionsListWidget {"
                  "    background-color: rgb(69, 69, 69, 0);"
                  "    outline: 0;"
                  "}"
                  "QFrame#mOptionsListFrame {"
                  "    background-color: rgb(69, 69, 69, 220);"
                  "}"
                  "QListWidget#mOptionsListWidget::item {"
                  "    color: white;"
                  "    padding: 3px;"
                  "}"
                  "QListWidget#mOptionsListWidget::item::selected {"
                  "    color: black;"
                  "    background-color:palette(Window);"
                  "    padding-right: 0px;"
                  "}";
  ss += style;

  // Fix selection color on losing focus (Windows)
  const QPalette palette = qApp->palette();

  ss += QString( "QTableView {"
                 "selection-background-color: %1;"
                 "selection-color: %2;"
                 "}" )
        .arg( palette.highlight().color().name(),
              palette.highlightedText().color().name() );

  QString toolbarSpacing = opts.value( QStringLiteral( "toolbarSpacing" ), QString() ).toString();
  if ( !toolbarSpacing.isEmpty() )
  {
    bool ok = false;
    int toolbarSpacingInt = toolbarSpacing.toInt( &ok );
    if ( ok )
    {
      ss += QStringLiteral( "QToolBar > QToolButton { padding: %1px; } " ).arg( toolbarSpacingInt );
    }
  }

  QgsDebugMsg( QStringLiteral( "Stylesheet built: %1" ).arg( ss ) );

  emit appStyleSheetChanged( ss );
}
Ejemplo n.º 29
0
// FIXME: we need to figure out a way to derive from Fm::FolderItemDelegate to avoid code duplication.
void DesktopItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
  Q_ASSERT(index.isValid());
  QStyleOptionViewItemV4 opt = option;
  initStyleOption(&opt, index);

  painter->save();
  painter->setClipRect(option.rect);

  opt.decorationAlignment = Qt::AlignHCenter | Qt::AlignTop;
  opt.displayAlignment = Qt::AlignTop | Qt::AlignHCenter;

  // draw the icon
  QIcon::Mode iconMode;
  if(opt.state & QStyle::State_Enabled) {
    if(opt.state & QStyle::State_Selected)
      iconMode = QIcon::Selected;
    else {
      iconMode = QIcon::Normal;
    }
  }
  else
    iconMode = QIcon::Disabled;
  QPoint iconPos(opt.rect.x() + (opt.rect.width() - opt.decorationSize.width()) / 2, opt.rect.y());
  QPixmap pixmap = opt.icon.pixmap(opt.decorationSize, iconMode);
  painter->drawPixmap(iconPos, pixmap);

  // draw some emblems for the item if needed
  // we only support symlink emblem at the moment
  FmFileInfo* file = static_cast<FmFileInfo*>(index.data(Fm::FolderModel::FileInfoRole).value<void*>());
  if(file) {
    if(fm_file_info_is_symlink(file)) {
      painter->drawPixmap(iconPos, symlinkIcon_.pixmap(opt.decorationSize / 2, iconMode));
    }
  }

  // draw text
  QRectF textRect(opt.rect.x(), opt.rect.y() + opt.decorationSize.height(), opt.rect.width(), opt.rect.height() - opt.decorationSize.height());
  QTextLayout layout(opt.text, opt.font);

  QTextOption textOption;
  textOption.setAlignment(opt.displayAlignment);
  textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
  textOption.setTextDirection(opt.direction);
  layout.setTextOption(textOption);
  qreal height = 0;
  qreal width = 0;
  int visibleLines = 0;
  layout.beginLayout();
  QString elidedText;

  for(;;) {
    QTextLine line = layout.createLine();
    if(!line.isValid())
      break;
    line.setLineWidth(textRect.width());
    height += opt.fontMetrics.leading();
    line.setPosition(QPointF(0, height));
    if((height + line.height() + textRect.y()) > textRect.bottom()) {
      // if part of this line falls outside the textRect, ignore it and quit.
      QTextLine lastLine = layout.lineAt(visibleLines - 1);
      elidedText = opt.text.mid(lastLine.textStart());
      elidedText = opt.fontMetrics.elidedText(elidedText, opt.textElideMode, textRect.width());
      break;
    }
    height += line.height();
    width = qMax(width, line.naturalTextWidth());
    ++ visibleLines;
  }
  layout.endLayout();
  QRectF boundRect = layout.boundingRect();
  boundRect.setWidth(width);
  boundRect.moveTo(textRect.x() + (textRect.width() - width)/2, textRect.y());
  if((opt.state & QStyle::State_Selected) && opt.widget) {
    QPalette palette = opt.widget->palette();
    // qDebug("w: %f, h:%f, m:%f", boundRect.width(), boundRect.height(), layout.minimumWidth());
    painter->fillRect(boundRect, palette.highlight());
  }
  else { // only draw shadow for non-selected items
    // draw shadow, FIXME: is it possible to use QGraphicsDropShadowEffect here?
    QPen prevPen = painter->pen();
    painter->setPen(QPen(shadowColor_));
    for(int i = 0; i < visibleLines; ++i) {
      QTextLine line = layout.lineAt(i);
      if(i == (visibleLines - 1) && !elidedText.isEmpty()) { // the last line, draw elided text
        QPointF pos(textRect.x() + line.position().x() + 1, textRect.y() + line.y() + line.ascent() + 1);
        painter->drawText(pos, elidedText);
      }
      else {
        line.draw(painter, textRect.topLeft() + QPointF(1, 1));
      }
    }
    painter->setPen(prevPen);
  }

  // draw text
  for(int i = 0; i < visibleLines; ++i) {
    QTextLine line = layout.lineAt(i);
    if(i == (visibleLines - 1) && !elidedText.isEmpty()) { // the last line, draw elided text
      QPointF pos(textRect.x() + line.position().x(), textRect.y() + line.y() + line.ascent());
      painter->drawText(pos, elidedText);
    }
    else {
      line.draw(painter, textRect.topLeft());
    }
  }

  if(opt.state & QStyle::State_HasFocus) {
    // FIXME: draw focus rect
  }
  painter->restore();
}
Ejemplo n.º 30
0
void
ClassicStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const
{
    if (cc != QStyle::CC_Dial) {
        QCommonStyle::drawComplexControl(cc, opt, p, widget);
        return;
    }

    const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(opt);
    if (dial == NULL)
        return;

    float angle = DIAL_MIN + (DIAL_RANGE * (float(dial->sliderValue - dial->minimum) /
                   (float(dial->maximum - dial->minimum))));
    int degrees = int(angle * 180.0 / M_PI);
    int ns = dial->tickInterval;
    int numTicks = 1 + (dial->maximum + ns - dial->minimum) / ns;
    int size = dial->rect.width() < dial->rect.height() ? dial->rect.width() : dial->rect.height();
    int scale = 1;
    int width = size * scale;
    int indent = (int)(width * 0.15 + 1);

    QPalette pal = opt->palette;
    QColor knobColor = pal.mid().color(); //pal.background().color();
    QColor meterColor = (dial->state & State_Enabled) ? pal.highlight().color() : pal.mid().color();
    QPen pen;
    QColor c;

    p->save();
    p->setRenderHint(QPainter::Antialiasing, true);
    p->translate(1+(dial->rect.width()-size)/2, 1+(dial->rect.height()-size)/2);

    // Knob body and face...

    pen.setColor(knobColor);
    pen.setWidth(scale * 2);
    pen.setCapStyle(Qt::FlatCap);
    p->setPen(pen);

    QRadialGradient gradient(size/2, size/2, size-indent, size/2-indent, size/2-indent);
    gradient.setColorAt(0, knobColor.light());
    gradient.setColorAt(1, knobColor.dark());
    p->setBrush(gradient);
    p->drawEllipse(indent, indent, width-2*indent, width-2*indent);

    // The bright metering bit...

    c = meterColor;
    pen.setColor(c);
    pen.setWidth(indent);
    p->setPen(pen);

    int arcLen = -(degrees - 45) * 16;
    if (arcLen == 0) arcLen = -16;
    p->drawArc(indent/2, indent/2, width-indent, width-indent, (180 + 45) * 16, arcLen);
    p->setBrush(Qt::NoBrush);

    // Tick notches...

    if (dial->subControls & QStyle::SC_DialTickmarks) {
    	//	std::cerr << "Notches visible" << std::endl;
    	pen.setColor(pal.dark().color());
    	pen.setWidth(scale);
    	p->setPen(pen);
    	for (int i = 0; i < numTicks; ++i) {
            int div = numTicks;
            if (div > 1) --div;
            drawTick(p, DIAL_MIN + (DIAL_MAX - DIAL_MIN) * i / div, width, true);
    	}
    }

    // Shadowing...

    pen.setWidth(scale);
    p->setPen(pen);

    // Knob shadow...

    int shadowAngle = -720;
    c = knobColor.dark();
    for (int arc = 120; arc < 2880; arc += 240)
    {
        pen.setColor(c);
        p->setPen(pen);
        p->drawArc(indent, indent, width-2*indent, width-2*indent, shadowAngle
                        + arc, 240);
        p->drawArc(indent, indent, width-2*indent, width-2*indent, shadowAngle
                        - arc, 240);
        c = c.light(110);
    }

    // Scale shadow...

    shadowAngle = 2160;
    c = pal.dark().color();
    for (int arc = 120; arc < 2880; arc += 240) {
    	pen.setColor(c);
    	p->setPen(pen);
    	p->drawArc(scale/2, scale/2,
    			width-scale, width-scale, shadowAngle + arc, 240);
    	p->drawArc(scale/2, scale/2,
    			width-scale, width-scale, shadowAngle - arc, 240);
    	c = c.light(108);
    }

    // Undraw the bottom part...

    pen.setColor(pal.background().color());
    pen.setWidth(scale * 4);
    p->setPen(pen);
    p->drawArc(scale/2, scale/2,
		  width-scale, width-scale, -45 * 16, -90 * 16);

    // Pointer notch...

    float hyp = float(width) / 2.0;
    float len = hyp - indent;
    --len;

    float x0 = hyp;
    float y0 = hyp;

    float x = hyp - len * qSin(angle);
    float y = hyp + len * qCos(angle);

    c = pal.dark().color();
    pen.setColor((dial->state & State_Enabled) ? c.dark(130) : c);
    pen.setWidth(scale * 2);
    p->setPen(pen);
    p->drawLine(int(x0), int(y0), int(x), int(y));

    // done
    p->restore();
}