ItemSettings::ItemSettings(ItemProperties *prop,QWidget *parent):QWidget(parent,Qt::Tool) { setupUi(this); this->prop = prop; this->fontColor = prop->fontColor; this->penColor = prop->itemPen.color(); this->brushColor = prop->itemBrush.color(); QPixmap penColor(45,11); penColor.fill(prop->itemPen.color()); QIcon penIcon(penColor); this->pb_penColor->setIcon(penIcon); this->pb_penColor->setIconSize(QSize(45,11)); this->sd_penWidth->setValue(prop->itemPen.width()); this->cb_penStyle->setCurrentIndex(this->prop->itemPen.style() - 1); QPixmap brushColor(45,11); brushColor.fill(prop->itemBrush.color()); QIcon brushIcon(brushColor); this->pb_brushColor->setIcon(brushIcon); this->pb_brushColor->setIconSize(QSize(45,11)); this->cb_brushStyle->setCurrentIndex(this->prop->itemBrush.style()); QPixmap fontColor(45,11); fontColor.fill(prop->fontColor); QIcon fontIcon(fontColor); this->pb_fontColor->setIcon(fontIcon); this->pb_fontColor->setIconSize(QSize(45,11)); connect(pb_penColor,SIGNAL(released()),this,SLOT(setPenColor())); connect(pb_brushColor,SIGNAL(released()),this,SLOT(setBrushColor())); connect(pb_done,SIGNAL(released()),this,SLOT(saveSettings())); connect(pb_selectFont,SIGNAL(released()),this,SLOT(selectFont())); connect(pb_fontColor,SIGNAL(released()),this,SLOT(setFontColor())); int p_midX = parent->x() + 100; int p_midY = parent->y() + 150; this->move(p_midX , p_midY) ; this->activateWindow(); }
void KateStyleTreeWidget::contextMenuEvent( QContextMenuEvent * event ) { KateStyleTreeWidgetItem *i = dynamic_cast<KateStyleTreeWidgetItem*>(itemAt(event->pos())); if (!i) return; KMenu m( this ); KTextEditor::Attribute::Ptr currentStyle = i->style(); // the title is used, because the menu obscures the context name when // displayed on behalf of spacePressed(). QPainter p; p.setPen(Qt::black); QIcon cl = brushIcon( i->style()->foreground().color() ); QIcon scl = brushIcon( i->style()->selectedForeground().color() ); QIcon bgcl = brushIcon( i->style()->hasProperty(QTextFormat::BackgroundBrush) ? i->style()->background().color() : viewport()->palette().base().color() ); QIcon sbgcl = brushIcon( i->style()->hasProperty(KTextEditor::Attribute::SelectedBackground) ? i->style()->selectedBackground().color() : viewport()->palette().base().color() ); m.addTitle( i->contextName() ); QAction* a = m.addAction( i18n("&Bold"), this, SLOT(changeProperty()) ); a->setCheckable(true); a->setChecked( currentStyle->fontBold() ); a->setData(KateStyleTreeWidgetItem::Bold); a = m.addAction( i18n("&Italic"), this, SLOT(changeProperty()) ); a->setCheckable(true); a->setChecked( currentStyle->fontItalic() ); a->setData(KateStyleTreeWidgetItem::Italic); a = m.addAction( i18n("&Underline"), this, SLOT(changeProperty()) ); a->setCheckable(true); a->setChecked( currentStyle->fontUnderline() ); a->setData(KateStyleTreeWidgetItem::Underline); a = m.addAction( i18n("S&trikeout"), this, SLOT(changeProperty()) ); a->setCheckable(true); a->setChecked( currentStyle->fontStrikeOut() ); a->setData(KateStyleTreeWidgetItem::StrikeOut); m.addSeparator(); a = m.addAction( cl, i18n("Normal &Color..."), this, SLOT(changeProperty()) ); a->setData(KateStyleTreeWidgetItem::Foreground); a = m.addAction( scl, i18n("&Selected Color..."), this, SLOT(changeProperty()) ); a->setData(KateStyleTreeWidgetItem::SelectedForeground); a = m.addAction( bgcl, i18n("&Background Color..."), this, SLOT(changeProperty()) ); a->setData(KateStyleTreeWidgetItem::Background); a = m.addAction( sbgcl, i18n("S&elected Background Color..."), this, SLOT(changeProperty()) ); a->setData(KateStyleTreeWidgetItem::SelectedBackground); // Unset [some] colors. I could show one only if that button was clicked, but that // would disable setting this with the keyboard (how many aren't doing just // that every day? ;) // ANY ideas for doing this in a nicer way will be warmly wellcomed. KTextEditor::Attribute::Ptr style = i->style(); if ( style->hasProperty( QTextFormat::BackgroundBrush) || style->hasProperty( KTextEditor::Attribute::SelectedBackground ) ) { m.addSeparator(); if ( style->hasProperty( QTextFormat::BackgroundBrush) ) { a = m.addAction( i18n("Unset Background Color"), this, SLOT(unsetColor()) ); a->setData(100); } if ( style->hasProperty( KTextEditor::Attribute::SelectedBackground ) ) { a = m.addAction( i18n("Unset Selected Background Color"), this, SLOT(unsetColor()) ); a->setData(101); } } if ( ! i->isDefault() && ! i->defStyle() ) { m.addSeparator(); a = m.addAction( i18n("Use &Default Style"), this, SLOT(changeProperty()) ); a->setCheckable(true); a->setChecked( i->defStyle() ); a->setData(KateStyleTreeWidgetItem::UseDefaultStyle); } m.exec( event->globalPos() ); }