Exemplo n.º 1
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();
}
Exemplo n.º 2
0
static void qDrawWinArrow(QPainter *p, Qt::ArrowType type, bool down,
                           int x, int y, int w, int h,
                           const QPalette &pal, bool enabled)
{
    QPolygon a;                                // arrow polygon
    switch (type) {
    case Qt::UpArrow:
        a.setPoints(7, -3,1, 3,1, -2,0, 2,0, -1,-1, 1,-1, 0,-2);
        break;
    case Qt::DownArrow:
        a.setPoints(7, -3,-1, 3,-1, -2,0, 2,0, -1,1, 1,1, 0,2);
        break;
    case Qt::LeftArrow:
        a.setPoints(7, 1,-3, 1,3, 0,-2, 0,2, -1,-1, -1,1, -2,0);
        break;
    case Qt::RightArrow:
        a.setPoints(7, -1,-3, -1,3, 0,-2, 0,2, 1,-1, 1,1, 2,0);
        break;
    default:
        break;
    }
    if (a.isEmpty())
        return;

    if (down) {
        x++;
        y++;
    }

    QPen savePen = p->pen();                        // save current pen
    if (down)
        p->setBrushOrigin(p->brushOrigin() + QPoint(1,1));
    p->fillRect(x, y, w, h, pal.brush(QPalette::Button));
    if (down)
        p->setBrushOrigin(p->brushOrigin() - QPoint(1,1));
    if (enabled) {
        a.translate(x+w/2, y+h/2);
        p->setPen(pal.foreground().color());
        p->drawLine(a.at(0), a.at(1));
        p->drawLine(a.at(2), a.at(2));
        p->drawPoint(a[6]);
    } else {
        a.translate(x+w/2+1, y+h/2+1);
        p->setPen(pal.light().color());
        p->drawLine(a.at(0), a.at(1));
        p->drawLine(a.at(2), a.at(2));
        p->drawPoint(a[6]);
        a.translate(-1, -1);
        p->setPen(pal.mid().color());
        p->drawLine(a.at(0), a.at(1));
        p->drawLine(a.at(2), a.at(2));
        p->drawPoint(a[6]);
    }
    p->setPen(savePen);                        // restore pen
}
Exemplo n.º 3
0
QColor FormatDescription::defaultForeground(TextStyle id)
{
    if (id == C_LINE_NUMBER) {
        const QPalette palette = Utils::Theme::initialPalette();
        const QColor bg = palette.background().color();
        if (bg.value() < 128)
            return palette.foreground().color();
        else
            return palette.dark().color();
    } else if (id == C_CURRENT_LINE_NUMBER) {
        const QPalette palette = Utils::Theme::initialPalette();
        const QColor bg = palette.background().color();
        if (bg.value() < 128)
            return palette.foreground().color();
        else
            return QColor();
    } else if (id == C_PARENTHESES) {
        return QColor(Qt::red);
    } else if (id == C_AUTOCOMPLETE) {
        return QColor(Qt::darkBlue);
    }
    return QColor();
}
Exemplo n.º 4
0
void FileView::paint(QPainter* painter, const QRect& rect, const QPalette& palette, DisplayMode displayMode) const {
	painter->save();
	painter->setRenderHint(QPainter::Antialiasing, true);

	painter->translate(rect.x(), rect.y());

	if(displayMode == DM_Selected)
		painter->setBrush(palette.highlightedText());
	else
		painter->setBrush(palette.foreground());

	painter->setPen(QPen(painter->brush(), 1));
	
	int textFlags = Qt::AlignLeft | Qt::AlignVCenter;

	QFont font(painter->font());
	font.setBold(true);
	painter->setFont(font);

	QString nameDisplay = (mode == TM_Send) ? tr("To: ") : tr("From: ");
	nameDisplay.append(userName);
	QRect textRect = QRect(54, 0, rect.width() - 58, 18);
	QString text = painter->fontMetrics().elidedText(nameDisplay, Qt::ElideRight, textRect.width());
	painter->drawText(textRect, textFlags, text);
	
	font.setBold(false);
	painter->setFont(font);
	textRect = QRect(54, 18, rect.width() - 58, 18);
	text = painter->fontMetrics().elidedText(fileDisplay, Qt::ElideMiddle, textRect.width());
	painter->drawText(textRect, textFlags, text);

	bool drawProgress = false;
	QString stateDisplay;
	switch(state) {
	case TS_Send:
		stateDisplay = timeDisplay + " left - " + posDisplay + " of " + sizeDisplay + " (" + speedDisplay + ")";
		drawProgress = true;
		break;
	case TS_Receive:
		stateDisplay = timeDisplay + " left - " + posDisplay + " of " + sizeDisplay + " (" + speedDisplay + ")";
		drawProgress = true;
		break;
	case TS_Complete:
		stateDisplay = tr("Completed");
		break;
	case TS_Cancel:
		stateDisplay = tr("Canceled");
		break;
	case TS_Abort:
		stateDisplay = tr("Interrupted");
		break;
    default:
        break;
	}
	textRect = QRect(54, 36, rect.width() - 58, 18);
	text = painter->fontMetrics().elidedText(stateDisplay, Qt::ElideRight, textRect.width());
	painter->drawText(textRect, textFlags, text);

	if(drawProgress) {
		int spanAngle = ((double)position / (double)fileSize) * 360;

		painter->setBrush(QBrush(QColor(230, 230, 230)));
		painter->setPen(QPen(QColor(230, 230, 230)));
		painter->drawPie(4, 4, 46, 46, (90 - spanAngle) * 16, -(360 - spanAngle) * 16);

		painter->setBrush(QBrush(QColor(150, 225, 110)));
		painter->setPen(QPen(QColor(150, 225, 110)));
		painter->drawPie(4, 4, 46, 46, 90 * 16, -spanAngle * 16);

		painter->setBrush(QBrush(QColor(255, 255, 255)));
		painter->setPen(QPen(QColor(255, 255, 255), 2));
		painter->drawLine(27, 5, 27, 49);
		painter->drawLine(5, 27, 49, 27);
		painter->drawLine(11, 11, 42, 42);
		painter->drawLine(42, 11, 11, 42);
	}

	QRect imageRect(11, 11, 32, 32);
	painter->drawPixmap(imageRect, icon);

	painter->restore();
}
Exemplo n.º 5
0
void qDrawItem(QPainter *p, Qt::GUIStyle gs,
                int x, int y, int w, int h,
                int flags,
                const QPalette &pal, bool enabled,
                const QPixmap *pixmap,
                const QString& text, int len , const QColor* penColor)
{
    p->setPen(penColor?*penColor:pal.foreground().color());
    if (pixmap) {
        QPixmap  pm(*pixmap);
        bool clip = (flags & Qt::TextDontClip) == 0;
        if (clip) {
            if (pm.width() < w && pm.height() < h)
                clip = false;
            else
                p->setClipRect(x, y, w, h);
        }
        if ((flags & Qt::AlignVCenter) == Qt::AlignVCenter)
            y += h/2 - pm.height()/2;
        else if ((flags & Qt::AlignBottom) == Qt::AlignBottom)
            y += h - pm.height();
        if ((flags & Qt::AlignRight) == Qt::AlignRight)
            x += w - pm.width();
        else if ((flags & Qt::AlignHCenter) == Qt::AlignHCenter)
            x += w/2 - pm.width()/2;
        else if (((flags & Qt::AlignLeft) != Qt::AlignLeft) && QApplication::isRightToLeft()) // Qt::AlignAuto && rightToLeft
            x += w - pm.width();

        if (!enabled) {
            if (pm.hasAlphaChannel()) {                        // pixmap with a mask
                pm = pm.mask();
            } else if (pm.depth() == 1) {        // monochrome pixmap, no mask
                ;
#ifndef QT_NO_IMAGE_HEURISTIC_MASK
            } else {                                // color pixmap, no mask
                QString k;
                k.sprintf("$qt-drawitem-%llx", pm.cacheKey());
                if (!QPixmapCache::find(k, pm)) {
                    pm = pm.createHeuristicMask();
                    pm.setMask((QBitmap&)pm);
                    QPixmapCache::insert(k, pm);
                }
#endif
            }
            if (gs == Qt::WindowsStyle) {
                p->setPen(pal.light().color());
                p->drawPixmap(x+1, y+1, pm);
                p->setPen(pal.text().color());
            }
        }
        p->drawPixmap(x, y, pm);
        if (clip)
            p->setClipping(false);
    } else if (!text.isNull()) {
        if (gs == Qt::WindowsStyle && !enabled) {
            p->setPen(pal.light().color());
            p->drawText(x+1, y+1, w, h, flags, text.left(len));
            p->setPen(pal.text().color());
        }
        p->drawText(x, y, w, h, flags, text.left(len));
    }
}
void KTThemeSelector::setupChooseColor()
{
	DVHBox *hbox = new DVHBox(this, Qt::Horizontal);
	DVHBox *box1 = new DVHBox(hbox, Qt::Vertical);
	box1->boxLayout()->setMargin(10);
	m_general = new QGroupBox(tr("General"), box1);
	
	QGridLayout *layout1 = new QGridLayout(m_general);
	
	QStringList labels1 = QStringList() << tr("Text") << tr("Base") << tr("Foreground") << tr("Background") << tr("Button") << tr("Button Text");
	
	QStringList names = QStringList() << "Text" << "Base" << "Foreground" << "Background" << "Button" << "ButtonText";
	
	QPalette colorGroup = QApplication::palette();
	
	
	QList<QColor> colors = QList<QColor>() << colorGroup.text ().color() << colorGroup.base().color() << colorGroup.foreground().color() << colorGroup.background().color() << colorGroup.button().color() << colorGroup.buttonText().color();
	
	for(int i = 0; i < labels1.count(); i++)
	{
		layout1->addWidget(new QLabel(labels1[i], m_general), i, 0 );
		DColorButton *button = new DColorButton(m_general);
		button->setObjectName(names[i]);
		QPalette pal = button->palette();
		pal.setColor(QPalette::Button, colors[i]);
		button->setPalette(pal);
		
		m_generalButtonGroup.addButton(button);
		layout1->addWidget(button, i, 1);
		m_generalSection.insert(names[i], colors[i].name());
	}
	
	m_effects = new QGroupBox(tr("Effects"), box1);
	
	QGridLayout *layout2 = new QGridLayout(m_effects);
	
	QStringList labels2 = QStringList() << tr("Light") << tr("Midlight") << tr("Dark") << tr("Mid");
	QStringList names2 = QStringList() << "Light" << "Midlight" << "Dark" << "Mid";
	
	colors.clear();
	colors << colorGroup.light().color() << colorGroup.midlight().color() << colorGroup.dark().color() << colorGroup.mid().color();
	
	for(int i = 0; i < labels2.count(); i++)
	{
		layout2->addWidget(new QLabel(labels2[i], m_effects), i, 0 );
		DColorButton *button = new DColorButton(m_effects);
		button->setObjectName(names2[i]);
		QPalette pal = button->palette();
		pal.setColor(QPalette::Button, colors[i]);
		button->setPalette(pal);
		m_effectsButtonGroup.addButton(button);
		layout2->addWidget(button, i, 1);
		m_effectsSection.insert(names2[i], colors[i].name());
	}
	////////////
	
	DVHBox *box2 = new DVHBox(hbox, Qt::Vertical);
	box2->boxLayout()->setMargin(10);
	m_selections = new QGroupBox(tr("Selections"), box2);
	
	QGridLayout *layout3 = new QGridLayout(m_selections);
	
	QStringList labels3 = QStringList() << tr("Highlight") << tr("Highlighted Text");
	QStringList names3 = QStringList() << "Highlight" << "HighlightedText";
	colors.clear();
	colors << colorGroup.highlight().color() << colorGroup.highlightedText().color();
	
	for(int i = 0; i < labels3.count(); i++)
	{
		layout3->addWidget(new QLabel(labels3[i], m_selections), i, 0 );
		DColorButton *button = new DColorButton(m_selections);
		button->setObjectName(names3[i]);
		QPalette pal = button->palette();
		pal.setColor(QPalette::Button, colors[i]);
		button->setPalette(pal);
		m_selectionsButtonGroup.addButton(button);
		layout3->addWidget(button, i, 1);
		m_selectionsSection.insert(names3[i], colors[i].name());
	}
	
	m_textEffects = new QGroupBox(tr("Text effects"), box2);
	
	QGridLayout *layout4 = new QGridLayout(m_textEffects);
	QStringList labels4 = QStringList() << tr("Bright Text") << tr("Link") << tr("Link Visited");
	QStringList names4 = QStringList() << "BrightText" << "Link" << "LinkVisited";
	
	colors.clear();
	colors << colorGroup.brightText().color() << colorGroup.link().color() << colorGroup.linkVisited().color();
	
	for(int i = 0; i < labels4.count(); i++)
	{
		layout4->addWidget(new QLabel(labels4[i], m_textEffects), i, 0 );
		DColorButton *button = new DColorButton(m_textEffects);
		button->setObjectName(names4[i]);
		QPalette pal = button->palette();
		pal.setColor(QPalette::Button, colors[i]);
		button->setPalette(pal);
		m_textEffectsButtonGroup.addButton(button);
		layout4->addWidget(button, i, 1);
		m_textEffectsSection.insert(names4[i], colors[i].name());
	}
	
	QGroupBox *schemeWidget = new QGroupBox(tr("Schema"), box2); // FIXME: add vertical layout
	QVBoxLayout *schemaLayout = new QVBoxLayout;
	
	m_allSchemes = new QTreeWidget;
	m_allSchemes->setHeaderLabels ( QStringList() << tr("Schema") << tr( "Owner" ) << tr( "Date" ) );
	m_allSchemes->header()->setResizeMode(QHeaderView::Stretch);
	
	schemaLayout->addWidget(m_allSchemes);
	
	connect(m_allSchemes, SIGNAL(itemDoubleClicked (QTreeWidgetItem *, int )), this, SLOT(loadSchemaFromListView( QTreeWidgetItem *, int )));
	
	QPushButton *saveSchemeButton = new QPushButton(tr("Save schema"));
	connect(saveSchemeButton, SIGNAL(clicked()), SLOT(saveSchema()));
	
	schemaLayout->addWidget(saveSchemeButton);
	
	schemeWidget->setLayout(schemaLayout);
	
	new DSeparator(this);
	new QLabel(tr("Style"), this);
	DStyleComboBox *styleComboBox = new DStyleComboBox(this);
	Q_UNUSED(styleComboBox);
	new DSeparator(this);
	m_useColors = new QCheckBox(tr("Use this colors"), this);
	
	connect(&m_generalButtonGroup, SIGNAL(buttonClicked(QAbstractButton * )), SLOT(chooseGeneralColor(QAbstractButton * )));
	connect(&m_effectsButtonGroup, SIGNAL(buttonClicked(QAbstractButton * )), SLOT(chooseEffectsColor(QAbstractButton * )));
	connect(&m_selectionsButtonGroup, SIGNAL(buttonClicked(QAbstractButton * )), SLOT(chooseSelectionsColor(QAbstractButton * )));
	connect(&m_textEffectsButtonGroup, SIGNAL(buttonClicked(QAbstractButton * )), SLOT(chooseTextEffectsColor(QAbstractButton * )));
}