void SeExprEdColorFrame::mouseReleaseEvent(QMouseEvent* event) { if (event->button() == Qt::RightButton) deleteSwatchMenu(event->pos()); else { #ifdef SEEXPR_USE_QDGUI QColor color = QdColorPickerDialog::chooseColorFromDialog(_color,this); #else QColor color = QColorDialog::getColor(_color); #endif if (color.isValid()) { _value[0] = color.red() / 255.0; _value[1] = color.green() / 255.0; _value[2] = color.blue() / 255.0; update(); _color = color; emit selValChangedSignal(_value); emit swatchChanged(color); } } }
/** * Opens a QColorDialog to set a new color. */ void ColorButton::onChooseColor() { if (!d->allowChange) return; if (d->modal) { QColor c = QColorDialog::getColor(d->col, this); if (c.isValid()) { setColor(c); changed(); } } else { if (d->cd.isNull()) { d->old = d->col; d->cd = new QColorDialog(d->col, this); d->cd->setAttribute(Qt::WA_DeleteOnClose); connect(d->cd, SIGNAL(rejected()), this, SLOT(onRejected())); connect(d->cd, SIGNAL(currentColorChanged(const QColor &)), this, SLOT(onColorChosen(const QColor&))); } d->cd->show(); }
/** * @brief Set theme color. * @param color Color to set. * * Pass an invalid QColor to reset to defaults. */ void Style::setThemeColor(const QColor &color) { if (!color.isValid()) { // Reset to default palette[ThemeDark] = QColor("#1c1c1c"); palette[ThemeMediumDark] = QColor("#2a2a2a"); palette[ThemeMedium] = QColor("#414141"); palette[ThemeLight] = QColor("#4e4e4e"); } else { palette[ThemeDark] = color.darker(155); palette[ThemeMediumDark] = color.darker(135); palette[ThemeMedium] = color.darker(120); palette[ThemeLight] = color.lighter(110); } dict["@themeDark"] = getColor(ThemeDark).name(); dict["@themeMediumDark"] = getColor(ThemeMediumDark).name(); dict["@themeMedium"] = getColor(ThemeMedium).name(); dict["@themeLight"] = getColor(ThemeLight).name(); }
void TagColorEditor::cellDoubleClicked(int row, int col) { QTableWidgetItem *item = table->item(row, col); uchar *colors = Global::tagColors(); int index = row*2 + col; QColor clr = QColor(colors[4*index+0], colors[4*index+1], colors[4*index+2]); clr = DColorDialog::getColor(clr); if (!clr.isValid()) return; colors[4*index+0] = clr.red(); colors[4*index+1] = clr.green(); colors[4*index+2] = clr.blue(); item->setData(Qt::DisplayRole, QString("%1").arg(index)); item->setBackground(clr); emit tagColorChanged(); }
void ColourTable::slotEditEntry(int row, int col) { switch (col) { case 0: { if (row == 0) return ; bool ok = false; QString newName = InputDialog::getText(this, tr("Modify Color Name"), tr("Enter new name"), LineEdit::Normal, item(row, col)->text(), &ok); if ((ok == true) && (!newName.isEmpty())) { emit entryTextChanged(row, newName); return ; } } break; case 1: { QColor temp = m_colours[row]; QColor result = QColorDialog::getColor(temp); if (result.isValid()) { emit entryColourChanged(row, temp); return ; } } break; default: // Should never happen break; } }
bool QmitkDoseColorDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { Q_ASSERT(event); Q_ASSERT(model); // make sure that the item is checkable Qt::ItemFlags flags = model->flags(index); if (!(flags & Qt::ItemIsEditable) || !(flags & Qt::ItemIsEnabled)) { return false; } // make sure that we have the right event type QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event); if (!mouseEvent) { return false; } else { if (mouseEvent->type() != QEvent::MouseButtonRelease || mouseEvent->button() != Qt::LeftButton) { return false; } } QColor oldcolor = index.data(Qt::EditRole).value<QColor>(); QColor newColor = QColorDialog::getColor(oldcolor, NULL); if (newColor.isValid()) { return model->setData(index, QVariant(newColor), Qt::EditRole); } return false; };
void ColorButton::paintEvent( QPaintEvent * ) { QPainter painter(this); //First, we need to draw the bevel. QStyleOptionButton butOpt; initStyleOption(&butOpt); style()->drawControl( QStyle::CE_PushButtonBevel, &butOpt, &painter, this ); //OK, now we can muck around with drawing out pretty little color box //First, sort out where it goes QRect labelRect = style()->subElementRect( QStyle::SE_PushButtonContents, &butOpt, this ); int shift = style()->pixelMetric( QStyle::PM_ButtonMargin ); labelRect.adjust(shift, shift, -shift, -shift); int x, y, w, h; labelRect.getRect(&x, &y, &w, &h); if (isChecked() || isDown()) { x += style()->pixelMetric( QStyle::PM_ButtonShiftHorizontal ); y += style()->pixelMetric( QStyle::PM_ButtonShiftVertical ); } QColor fillCol = isEnabled() ? btnColor : palette().color(backgroundRole()); qDrawShadePanel( &painter, x, y, w, h, palette(), true, 1, NULL); if ( fillCol.isValid() ) painter.fillRect( x+1, y+1, w-2, h-2, fillCol ); if ( hasFocus() ) { QRect focusRect = style()->subElementRect( QStyle::SE_PushButtonFocusRect, &butOpt, this ); QStyleOptionFocusRect focusOpt; focusOpt.init(this); focusOpt.rect = focusRect; focusOpt.backgroundColor = palette().background().color(); style()->drawPrimitive( QStyle::PE_FrameFocusRect, &focusOpt, &painter, this ); } }
bool PreferencesDialog::eventFilter(QObject *obj, QEvent *event) { // Use mouse click and enter press on the frames to pop up a colour dialog if (obj == ui->frameNullBgColour || obj == ui->frameNullFgColour) { if (event->type() == QEvent::KeyPress) { QKeyEvent *key = static_cast<QKeyEvent *>(event); // Not interesting, so send to the parent (might be shortcuts) if((key->key() != Qt::Key_Enter) && (key->key() != Qt::Key_Return)) { return QDialog::eventFilter(obj, event); } } else if (event->type() != QEvent::MouseButtonPress) { // Not a key event neither a mouse event, send to the parent return QDialog::eventFilter(obj, event); } QFrame *frame = qobject_cast<QFrame *>(obj); QColor oldColour = frame->palette().color(frame->backgroundRole()); QColor colour = QColorDialog::getColor(oldColour, frame); if (colour.isValid()) { QPalette palette = frame->palette(); palette.setColor(frame->backgroundRole(), colour); frame->setPalette(palette); } // Consume return true; } // Send any other events to the parent return QDialog::eventFilter(obj, event); }
QColor DomConvenience::getColor(const QDomElement& e) { QColor color; if (e.hasAttribute("name")) color = QColor(e.attribute("name")); // allow specifying of base color by name and then tweaking if (e.hasAttribute("red") || e.hasAttribute("green") || e.hasAttribute("blue")) { int base = getBase(e); bool colorOk = false; // default to black int r = 0, g = 0, b = 0; // if color was specified by name, use it's RGB values as defaults if (color.isValid()) { r = color.red(); g = color.green(); b = color.blue(); } if (e.hasAttribute("red")) r = e.attribute("red").toInt(&colorOk, base); if (e.hasAttribute("green")) g = e.attribute("green").toInt(&colorOk, base); if (e.hasAttribute("blue")) b = e.attribute("blue").toInt(&colorOk, base); color = QColor(r, g, b); } return color; }
xColor xColorFromVariant(const QVariant &object, bool& isValid) { isValid = false; xColor color { 0, 0, 0 }; if (!object.isValid()) { return color; } if (object.canConvert<int>()) { isValid = true; color.red = color.green = color.blue = (uint8_t)object.toInt(); } else if (object.canConvert<QString>()) { QColor qcolor(object.toString()); if (qcolor.isValid()) { isValid = true; color.red = (uint8_t)qcolor.red(); color.blue = (uint8_t)qcolor.blue(); color.green = (uint8_t)qcolor.green(); } } else if (object.canConvert<QColor>()) { QColor qcolor = qvariant_cast<QColor>(object); if (qcolor.isValid()) { isValid = true; color.red = (uint8_t)qcolor.red(); color.blue = (uint8_t)qcolor.blue(); color.green = (uint8_t)qcolor.green(); } } else { QVariantMap map = object.toMap(); color.red = map["red"].toInt(&isValid); if (isValid) { color.green = map["green"].toInt(&isValid); } if (isValid) { color.blue = map["blue"].toInt(&isValid); } } return color; }
bool QgsColorRampShader::shade( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue ) { //Get the shaded value from the cache if it exists already QColor myColor = mColorCache.value( theValue ); if ( myColor.isValid() ) { *theReturnRedValue = myColor.red(); *theReturnGreenValue = myColor.green(); *theReturnBlueValue = myColor.blue(); return true; } //pixel value not in cache so generate new value //Check to be sure mCurrentColorRampItemIndex is within the valid range. if ( mCurrentColorRampItemIndex < 0 ) { mCurrentColorRampItemIndex = 0; } else if ( mCurrentColorRampItemIndex >= mColorRampItemList.size() ) { mCurrentColorRampItemIndex = mColorRampItemList.size() - 1; } if ( QgsColorRampShader::EXACT == mColorRampType ) { return exactColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue ); } else if ( QgsColorRampShader::INTERPOLATED == mColorRampType ) { return interpolatedColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue ); } return discreteColor( theValue, theReturnRedValue, theReturnGreenValue, theReturnBlueValue ); }
void QgsRasterTerrainAnalysisDialog::on_mReliefClassTreeWidget_itemDoubleClicked( QTreeWidgetItem* item, int column ) { if ( !item ) { return; } if ( column == 0 ) { bool ok; double d = QInputDialog::getDouble( 0, tr( "Enter lower elevation class bound" ), tr( "Elevation" ), item->text( 0 ).toDouble(), -2147483647, 2147483647, 2, &ok ); if ( ok ) { item->setText( 0, QString::number( d ) ); } } else if ( column == 1 ) { bool ok; double d = QInputDialog::getDouble( 0, tr( "Enter upper elevation class bound" ), tr( "Elevation" ), item->text( 1 ).toDouble(), -2147483647, 2147483647, 2, &ok ); if ( ok ) { item->setText( 1, QString::number( d ) ); } } else if ( column == 2 ) { QColor c = QColorDialog::getColor( item->background( 2 ).color(), 0, tr( "Select color for relief class" ) ); if ( c.isValid() ) { item->setBackground( 2, QBrush( c ) ); } } }
void QgsPresetColorRampWidget::mButtonAddColor_clicked() { if ( dockMode() ) { mTreeColors->addColor( QgsRecentColorScheme::lastUsedColor(), QgsSymbolLayerUtils::colorToName( QgsRecentColorScheme::lastUsedColor() ), true ); QgsCompoundColorWidget *colorWidget = new QgsCompoundColorWidget( this, QgsRecentColorScheme::lastUsedColor(), QgsCompoundColorWidget::LayoutVertical ); colorWidget->setPanelTitle( tr( "Select Color" ) ); colorWidget->setAllowOpacity( true ); connect( colorWidget, &QgsCompoundColorWidget::currentColorChanged, this, &QgsPresetColorRampWidget::newColorChanged ); openPanel( colorWidget ); } else { QColor newColor = QgsColorDialog::getColor( QColor(), this->parentWidget(), tr( "Select Color" ), true ); if ( !newColor.isValid() ) { return; } activateWindow(); mTreeColors->addColor( newColor, QgsSymbolLayerUtils::colorToName( newColor ) ); } }
/*! \internal */ void QThemeWidgetItem::parseColorGroup(const QMap<QString,QString> &cgatts) { if (!d->proxy || !d->proxy->widget()) return; QPalette pal = d->proxy->palette(); for (int i = 0; colorTable[i].role != QPalette::NColorRoles; ++i) { const QString curColorName = QString(colorTable[i].name).toLower(); QColor colour; for (QMap<QString,QString>::ConstIterator it = cgatts.begin(); it != cgatts.end(); ++it) { if (it.key().toLower() == curColorName) { colour = colorFromString(*it); break; } } if (colour.isValid()) { pal.setColor(QPalette::Active, colorTable[i].role, colour); pal.setColor(QPalette::Inactive, colorTable[i].role, colour); pal.setColor(QPalette::Disabled, colorTable[i].role, colour); } } d->proxy->setPalette(pal); }
/* ======================== selectClearColor brings up a color selection dialog for glClearColor. ======================== */ void CSceneWidget::selectClearColor( bool ) { QPalette pal = m_btnClearColor->palette(); // ask for new color QColor color = pal.color( QPalette::Button ); color = QColorDialog::getColor( color, this ); if( color.isValid() ) { pal.setColor( QPalette::Button, color ); m_btnClearColor->setPalette( pal ); // translate color vec4_t v( float(color.red()) / 255.0f, float(color.green()) / 255.0f, float(color.blue()) / 255.0f, 1.0f ); // update state m_scene->setClearColor( v ); } }
void QgsComposerScaleBarWidget::on_mStrokeColorPushButton_clicked() { if ( !mComposerScaleBar ) { return; } QColor oldColor = mComposerScaleBar->pen().color(); QColor newColor = QColorDialog::getColor( oldColor, 0 ); if ( !newColor.isValid() ) //user canceled the dialog { return; } mComposerScaleBar->beginCommand( tr( "Scalebar stroke color changed" ) ); disconnectUpdateSignal(); QPen newPen = mComposerScaleBar->pen(); newPen.setColor( newColor ); mComposerScaleBar->setPen( newPen ); mComposerScaleBar->update(); connectUpdateSignal(); mComposerScaleBar->endCommand(); }
void Window::setLinhaColor() { if(QApplication::keyboardModifiers() == Qt::ControlModifier) { if(docAtual->linha) { docAtual->linha = false; } else { docAtual->linha = true; } updateLinhaButton(); } else { const QColor color = QColorDialog::getColor(QColor::fromRgbF(docAtual->linhaColorSelecionada[0], docAtual->linhaColorSelecionada[1], docAtual->linhaColorSelecionada[2]), this, "Selecionar cor"); if (color.isValid()) { docAtual->linhaColorSelecionada[0] = color.redF(); docAtual->linhaColorSelecionada[1] = color.greenF(); docAtual->linhaColorSelecionada[2] = color.blueF(); updateLinhaButton(); } } }
void MRichTextEdit::textBgColor() { QColor col = QColorDialog::getColor(f_textedit->textBackgroundColor(), this); QTextCursor cursor = f_textedit->textCursor(); if (!cursor.hasSelection()) { cursor.select(QTextCursor::WordUnderCursor); } QTextCharFormat fmt = cursor.charFormat(); if (col.isValid()) { fmt.setBackground(col); } else { fmt.clearBackground(); } cursor.setCharFormat(fmt); f_textedit->setCurrentCharFormat(fmt); bgColorChanged(col); }
bool QgsColorButton::colorFromMimeData( const QMimeData *mimeData, QColor &resultColor ) { bool hasAlpha = false; QColor mimeColor = QgsSymbolLayerUtils::colorFromMimeData( mimeData, hasAlpha ); if ( mimeColor.isValid() ) { if ( !mAllowOpacity ) { //remove alpha channel mimeColor.setAlpha( 255 ); } else if ( !hasAlpha ) { //mime color has no explicit alpha component, so keep existing alpha mimeColor.setAlpha( mColor.alpha() ); } resultColor = mimeColor; return true; } //could not get color from mime data return false; }
void PreferenceDialog::selectViewerColor() { QColor color; QPalette palette = ui->viewerSample->palette(); if (sender() == ui->viewerClrBg) { color = palette.background().color(); } else if (sender() == ui->viewerClrFg) { color = palette.text().color(); } color = QColorDialog::getColor(color, this, tr("色選択")); if (!color.isValid()) { return; } if (sender() == ui->viewerClrBg) { palette.setColor(QPalette::Base, color); } else if (sender() == ui->viewerClrFg) { palette.setColor(QPalette::Text, color); } ui->viewerSample->setPalette(palette); }
void CurveCollectionImp::setColor(const QColor& clrCurve) { if (clrCurve.isValid() == false) { return; } if (clrCurve != mColor) { mColor = clrCurve; for (vector<Curve*>::iterator iter = mCurves.begin(); iter != mCurves.end(); ++iter) { CurveImp* pCurve = dynamic_cast<CurveImp*>(*iter); if (pCurve != NULL) { pCurve->setColor(mColor); } } emit legendPixmapChanged(); notify(SIGNAL_NAME(Subject, Modified)); } }
SplashObserver(QSplashScreen* splasher=0, const char* name=0) : splash(splasher), alignment(Qt::AlignBottom|Qt::AlignLeft), textColor(Qt::black) { Base::Console().AttachObserver(this); // allow to customize text position and color const std::map<std::string,std::string>& cfg = App::GetApplication().Config(); std::map<std::string,std::string>::const_iterator al = cfg.find("SplashAlignment"); if (al != cfg.end()) { QString alt = QString::fromAscii(al->second.c_str()); int align=0; if (alt.startsWith(QLatin1String("VCenter"))) align = Qt::AlignVCenter; else if (alt.startsWith(QLatin1String("Top"))) align = Qt::AlignTop; else align = Qt::AlignBottom; if (alt.endsWith(QLatin1String("HCenter"))) align += Qt::AlignHCenter; else if (alt.endsWith(QLatin1String("Right"))) align += Qt::AlignRight; else align += Qt::AlignLeft; alignment = align; } // choose text color std::map<std::string,std::string>::const_iterator tc = cfg.find("SplashTextColor"); if (tc != cfg.end()) { QColor col; col.setNamedColor(QString::fromAscii(tc->second.c_str())); if (col.isValid()) textColor = col; } }
void Tractography::set_track_colour_slot() { QColor color; color = QColorDialog::getColor(Qt::red, this, "Select Color", QColorDialog::DontUseNativeDialog); float colour[] = {float(color.redF()), float(color.greenF()), float(color.blueF())}; if (color.isValid()) { QModelIndexList indices = tractogram_list_view->selectionModel()->selectedIndexes(); for (int i = 0; i < indices.size(); ++i) { Tractogram* tractogram = tractogram_list_model->get_tractogram (indices[i]); tractogram->set_color_type (TrackColourType::Manual); tractogram->set_colour (colour); if (tractogram->get_threshold_type() == TrackThresholdType::UseColourFile) tractogram->set_threshold_type (TrackThresholdType::None); } colour_combobox->blockSignals (true); colour_combobox->setCurrentIndex (3); colour_combobox->clearError(); colour_combobox->blockSignals (false); colour_button->setEnabled (true); colour_button->setColor (QColor (colour[0]*255.0f, colour[1]*255.0f, colour[2]*255.0f)); update_scalar_options(); } window().updateGL(); }
void QtPropertyEditorView::drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItemV3 opt = option; bool hasValue = true; if (m_editorPrivate) { QtProperty *property = m_editorPrivate->indexToProperty(index); if (property) hasValue = property->hasValue(); } if (!hasValue && m_editorPrivate->markPropertiesWithoutValue()) { const QColor c = option.palette.color(QPalette::Dark); painter->fillRect(option.rect, c); opt.palette.setColor(QPalette::AlternateBase, c); } else { const QColor c = m_editorPrivate->calculatedBackgroundColor( m_editorPrivate->indexToBrowserItem(index)); if (c.isValid()) { painter->fillRect(option.rect, c); opt.palette.setColor(QPalette::AlternateBase, c.lighter(112)); } } QTreeWidget::drawRow(painter, opt, index); QColor color = static_cast<QRgb>( QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &opt)); painter->save(); painter->setPen(QPen(color)); painter->drawLine(opt.rect.x(), opt.rect.bottom(), opt.rect.right(), opt.rect.bottom()); painter->restore(); }
void KDReports::SpreadsheetReportLayout::paintPageContent(int pageNumber, QPainter &painter) { //qDebug() << "painting with" << m_tableLayout.scaledFont(); QAbstractItemModel* model = m_tableLayout.m_model; const qreal padding = m_tableLayout.scaledCellPadding(); const QRect cellCoords = m_pageRects[pageNumber]; //qDebug() << "painting page" << pageNumber << "cellCoords=" << cellCoords; qreal y = 0 /*m_topMargin*/; // in pixels const qreal rowHeight = m_tableLayout.rowHeight(); if ( m_tableLayout.m_horizontalHeaderVisible ) { qreal x = 0 /*m_leftMargin*/; if ( m_tableLayout.m_verticalHeaderVisible ) { x += m_tableLayout.vHeaderWidth(); } for ( int col = cellCoords.left(); col <= cellCoords.right(); ++col ) { const QRectF cellRect( x, y, m_tableLayout.m_columnWidths[ col ], m_tableLayout.hHeaderHeight() ); paintTableHorizontalHeader( cellRect, painter, col ); x += cellRect.width(); } y += m_tableLayout.hHeaderHeight(); } const int firstRow = cellCoords.top(); const int firstColumn = cellCoords.left(); const int numRows = cellCoords.height(); const int numColumns = cellCoords.width(); // This won't work across page breaks.... QVector<QBitArray> coveredCells; coveredCells.resize( numRows ); for ( int row = firstRow; row <= cellCoords.bottom(); ++row ) coveredCells[row - firstRow].resize( numColumns ); for ( int row = firstRow; row <= cellCoords.bottom(); ++row ) { qreal x = 0 /*m_leftMargin*/; if ( m_tableLayout.m_verticalHeaderVisible ) { x = paintTableVerticalHeader( x, y, painter, row ); } painter.setFont( m_tableLayout.scaledFont() ); for ( int col = cellCoords.left(); col <= cellCoords.right(); ++col ) { if (coveredCells[row - firstRow].testBit(col - firstColumn)) { x += m_tableLayout.m_columnWidths[ col ]; continue; } const QModelIndex index = model->index( row, col ); const QSize span = model->span( index ); if (span.isValid()) { for (int r = row; r < row + span.height() && r < numRows; ++r) { for (int c = col; c < col + span.width() && c < numColumns; ++c) { coveredCells[r - firstRow].setBit(c - firstColumn); } } } const QRectF cellRect( x, y, cellWidth( col, span.width() ), qMax(1, span.height()) * rowHeight ); const QRectF cellContentsRect = cellRect.adjusted( padding, padding, -padding, -padding ); //qDebug() << "cell" << row << col << "rect=" << cellRect; const QString cellText = model->data( index, Qt::DisplayRole ).toString(); const QColor foreground = qvariant_cast<QColor>( model->data( index, Qt::ForegroundRole ) ); const QColor background = qvariant_cast<QColor>( model->data( index, Qt::BackgroundRole ) ); const Qt::Alignment alignment( model->data( index, Qt::TextAlignmentRole ).toInt() ); const QVariant decorationAlignment( model->data( index, KDReports::AutoTableElement::DecorationAlignmentRole ) ); const QVariant cellDecoration( model->data( index, Qt::DecorationRole ) ); if ( background.isValid() ) { painter.fillRect( cellRect, QBrush( background ) ); } else if ( span.isValid() ) { painter.fillRect( cellRect, Qt::white ); } drawBorder(cellRect, painter); // Per-cell font is not supported, on purpose. All rows use the same font, // otherwise the calculations for making things fit into a number of pages // become quite complex and slow. //const QVariant cellFont = model->data( index, Qt::FontRole ); //if ( cellFont.isValid() ) // painter.setFont( qvariant_cast<QFont>( cellFont ) ); //else // painter.setFont( scaledFont ); if ( foreground.isValid() ) painter.setPen( foreground ); paintTextAndIcon( painter, cellContentsRect, cellText, cellDecoration, decorationAlignment, alignment ); if ( foreground.isValid() ) painter.setPen( Qt::black ); x += m_tableLayout.m_columnWidths[ col ]; } y += rowHeight; } }
void Session::setUserTitle( int what, const QString &caption ) { //set to true if anything is actually changed (eg. old _nameTitle != new _nameTitle ) bool modified = false; // (btw: what=0 changes _userTitle and icon, what=1 only icon, what=2 only _nameTitle if (( what == 0 ) || ( what == 2 ) ) { if ( _userTitle != caption ) { _userTitle = caption; modified = true; } } if (( what == 0 ) || ( what == 1 ) ) { if ( _iconText != caption ) { _iconText = caption; modified = true; } } if ( what == 11 ) { QString colorString = caption.section( ';', 0, 0 ); qDebug() << __FILE__ << __LINE__ << ": setting background color to " << colorString; QColor backColor = QColor( colorString ); if ( backColor.isValid() ) // change color via \033]11;Color\007 { if ( backColor != _modifiedBackground ) { _modifiedBackground = backColor; // bail out here until the code to connect the terminal display // to the changeBackgroundColor() signal has been written // and tested - just so we don't forget to do this. Q_ASSERT( 0 ); emit changeBackgroundColorRequest( backColor ); } } } if ( what == 30 ) { if ( _nameTitle != caption ) { setTitle( Session::NameRole, caption ); return; } } if ( what == 31 ) { QString cwd = caption; cwd = cwd.replace( QRegExp( "^~" ), QDir::homePath() ); emit openUrlRequest( cwd ); } // change icon via \033]32;Icon\007 if ( what == 32 ) { if ( _iconName != caption ) { _iconName = caption; modified = true; } } if ( what == 50 ) { emit profileChangeCommandReceived( caption ); return; } if ( modified ) emit titleChanged(); }
bool SessionManager::save() { if (debug) qDebug() << "SessionManager - saving session" << d->m_sessionName; emit m_instance->aboutToSaveSession(); if (!d->m_writer || d->m_writer->fileName() != sessionNameToFileName(d->m_sessionName)) { delete d->m_writer; d->m_writer = new PersistentSettingsWriter(sessionNameToFileName(d->m_sessionName), QLatin1String("QtCreatorSession")); } QVariantMap data; // save the startup project if (d->m_startupProject) data.insert(QLatin1String("StartupProject"), d->m_startupProject->projectFilePath()); QColor c = StyleHelper::requestedBaseColor(); if (c.isValid()) { QString tmp = QString::fromLatin1("#%1%2%3") .arg(c.red(), 2, 16, QLatin1Char('0')) .arg(c.green(), 2, 16, QLatin1Char('0')) .arg(c.blue(), 2, 16, QLatin1Char('0')); data.insert(QLatin1String("Color"), tmp); } QStringList projectFiles; foreach (Project *pro, d->m_projects) projectFiles << pro->projectFilePath(); // Restore infromation on projects that failed to load: // don't readd projects to the list, which the user loaded foreach (const QString &failed, d->m_failedProjects) if (!projectFiles.contains(failed)) projectFiles << failed; data.insert(QLatin1String("ProjectList"), projectFiles); QMap<QString, QVariant> depMap; QMap<QString, QStringList>::const_iterator i = d->m_depMap.constBegin(); while (i != d->m_depMap.constEnd()) { QString key = i.key(); QStringList values; foreach (const QString &value, i.value()) { values << value; } depMap.insert(key, values); ++i; } data.insert(QLatin1String("ProjectDependencies"), QVariant(depMap)); data.insert(QLatin1String("EditorSettings"), EditorManager::saveState().toBase64()); QMap<QString, QVariant>::const_iterator it, end = d->m_values.constEnd(); QStringList keys; for (it = d->m_values.constBegin(); it != end; ++it) { data.insert(QLatin1String("value-") + it.key(), it.value()); keys << it.key(); } data.insert(QLatin1String("valueKeys"), keys); bool result = d->m_writer->save(data, Core::ICore::mainWindow()); if (!result) { QMessageBox::warning(0, tr("Error while saving session"), tr("Could not save session to file %1").arg(d->m_writer->fileName().toUserOutput())); } if (debug) qDebug() << "SessionManager - saving session returned " << result; return result; }
// static function void ContextHelp::addLinkTypeAppearances( QString * html ) { QRegExp rx("<a href=\"([^\"]*)\">([^<]*)</a>"); int pos = 0; while ( (pos = rx.search( *html, pos )) >= 0 ) { QString anchorText = rx.cap( 0 ); // contains e.g.: <a href="http://ktechlab.org/">KTechlab website</a> QString url = rx.cap( 1 ); // contains e.g.: http://ktechlab.org/ QString text = rx.cap( 2 ); // contains e.g.: KTechlab website int length = anchorText.length(); LinkType lt = extractLinkType( url ); QColor color; // default constructor gives an "invalid" color QString imageURL; switch ( lt ) { case HelpLink: break; case NewHelpLink: color = Qt::red; break; case ExampleLink: { //QString iconName = KMimeType::iconNameForURL( examplePathToFullPath( KUrl( url ).path() ) ); QString iconName = KMimeType::iconNameForUrl( examplePathToFullPath( KUrl( url ).path() ) ); imageURL = KIconLoader::global()->iconPath( iconName, - KIconLoader::SizeSmall ); break; } case ExternalLink: { imageURL = KStandardDirs::locate( "appdata", "icons/external_link.png" ); break; } } QString newAnchorText; if ( color.isValid() ) { newAnchorText = QString("<a href=\"%1\" style=\"color: %2;\">%3</a>").arg( url ).arg( color.name() ).arg( text ); } else if ( !imageURL.isEmpty() ) { newAnchorText = anchorText; newAnchorText += QString(" <img src=\"%1\"/>").arg( imageURL ); } if ( !newAnchorText.isEmpty() ) html->replace( pos, length, newAnchorText ); pos++; // avoid the string we just found } }
int BiomeIdentifier::addDefinitions(JSONArray *defs, int pack) { if (pack == -1) { pack = packs.length(); packs.append(QList<BiomeInfo *>()); } int len = defs->length(); for (int i = 0; i < len; i++) { JSONObject *b = dynamic_cast<JSONObject *>(defs->at(i)); int id = b->at("id")->asNumber(); BiomeInfo *biome = new BiomeInfo(); biome->enabled = true; if (b->has("name")) biome->name = b->at("name")->asString(); else biome->name = "Unknown"; // check for "alpha" (0: transparent / 1: saturated) // probably never used if (b->has("alpha")) biome->alpha = b->at("alpha")->asNumber(); else biome->alpha = 1.0; // get color definition QColor biomecolor; if (b->has("color")) { QString colorname = b->at("color")->asString(); if (colorname.length() == 6) { // check if this is an old color definition with missing '#' bool ok; colorname.toInt(&ok,16); if (ok) colorname.push_front('#'); } biomecolor.setNamedColor(colorname); assert(biomecolor.isValid()); } else { // use hashed by name instead quint32 hue = qHash(biome->name); biomecolor.setHsv(hue % 360, 255, 255); } // pre-calculate light spectrum for (int i = 0; i < 16; i++) { // calculate light attenuation similar to Minecraft // except base 90% here, were Minecraft is using 80% per level double light_factor = pow(0.90,15-i); biome->colors[i].setRgb(light_factor*biomecolor.red(), light_factor*biomecolor.green(), light_factor*biomecolor.blue(), 255*biome->alpha ); } biomes[id].append(biome); packs[pack].append(biome); } return pack; }
/*! \reimp */ bool Q3GroupBox::event(QEvent *e) { if (e->type()==QEvent::Paint) { QStyleOptionGroupBox opt; initStyleOption(&opt); opt.lineWidth=d->lineWidth; opt.midLineWidth=d->midLineWidth; QPainter p(this); if (frameShape()==GroupBoxPanel) { style()->drawComplexControl(QStyle::CC_GroupBox, &opt, &p, this); } else { //in case it is a Paint event with a frame shape different from the group box const QRect textRect = style()->subControlRect(QStyle::CC_GroupBox, &opt, QStyle::SC_GroupBoxLabel, this); const QRect checkBoxRect = style()->subControlRect(QStyle::CC_GroupBox, &opt, QStyle::SC_GroupBoxCheckBox, this); // Draw title if ((opt.subControls & QStyle::SC_GroupBoxLabel) && !opt.text.isEmpty()) { QColor textColor = opt.textColor; if (textColor.isValid()) p.setPen(textColor); int alignment = int(opt.textAlignment); if (!style()->styleHint(QStyle::SH_UnderlineShortcut, &opt, this)) alignment |= Qt::TextHideMnemonic; style()->drawItemText(&p, textRect, Qt::TextShowMnemonic | Qt::AlignHCenter | alignment, opt.palette, opt.state & QStyle::State_Enabled, opt.text, textColor.isValid() ? QPalette::NoRole : QPalette::WindowText); if (opt.state & QStyle::State_HasFocus) { QStyleOptionFocusRect fropt; fropt.QStyleOption::operator=(opt); fropt.rect = textRect; style()->drawPrimitive(QStyle::PE_FrameFocusRect, &fropt, &p, this); } } // Draw checkbox if (opt.subControls & QStyle::SC_GroupBoxCheckBox) { QStyleOptionButton box; box.QStyleOption::operator=(opt); box.rect = checkBoxRect; style()->drawPrimitive(QStyle::PE_IndicatorCheckBox, &box, &p, this); } //sets clipping QRegion region(rect()); if (!title().isEmpty()) { bool ltr = layoutDirection() == Qt::LeftToRight; QRect finalRect = checkBoxRect.united(textRect); if (isCheckable()) finalRect.adjust(ltr ? -4 : 0, 0, ltr ? 0 : 4, 0); region -= finalRect; } p.setClipRegion(region); drawFrame(&p); } return false; } return QGroupBox::event(e); }