void qtvplugin_geomarker::on_toolButton_QTV_selColorPen_clicked() { QString str = ui->lineEdit_QTV_PenColor->text(); QColor col = QColorDialog::getColor(string2color(str),this,tr("Select Color"),QColorDialog::ShowAlphaChannel|QColorDialog::DontUseNativeDialog); if (col.isValid()) ui->lineEdit_QTV_PenColor->setText(color2string(col)); }
void qtvplugin_geomarker::style_save() { QSettings settings(ini_file(),QSettings::IniFormat); settings.setValue("default_style/spinBox_QTV_point_width",ui->spinBox_QTV_point_width->value()); settings.setValue("default_style/spinBox_QTV_point_height",ui->spinBox_QTV_point_height->value()); int radioButton_QTV_PointRect = 0; if (ui->radioButton_QTV_PointRound->isChecked()==true) radioButton_QTV_PointRect = 1; else radioButton_QTV_PointRect = 0; settings.setValue("default_style/radioButton_QTV_PointRect",radioButton_QTV_PointRect); settings.setValue("default_style/lineEdit_QTV_PenColor",ui->lineEdit_QTV_PenColor->text()); settings.setValue("default_style/lineEdit_QTV_FillColor",ui->lineEdit_QTV_FillColor->text()); settings.setValue("default_style/lineEdit_QTV_TextColor",ui->lineEdit_QTV_TextColor->text()); settings.setValue("default_style/spinBox_QTV_penWidth",ui->spinBox_QTV_penWidth->value()); settings.setValue("default_style/comboBox_QTV_linePad",ui->comboBox_QTV_linePad->currentIndex()); settings.setValue("default_style/comboBox_QTV_fillPad",ui->comboBox_QTV_fillPad->currentIndex()); settings.setValue("default_style/spinBox_QTV_textWeight",ui->spinBox_QTV_textWeight->value()); settings.setValue("default_style/spinBox_QTV_fontSize",ui->spinBox_QTV_fontSize->value()); settings.setValue("default_style/lineEdit_QTV_icon_rotate",ui->lineEdit_QTV_icon_rotate->text()); settings.setValue("default_style/lineEdit_QTV_icon_scale",ui->lineEdit_QTV_icon_scale->text()); settings.setValue("default_style/checkBox_QTV_multiline",ui->checkBox_QTV_multiline->isChecked()?-1:0); settings.setValue("default_style/checkBox_QTV_icon_smooth",ui->checkBox_QTV_icon_smooth->isChecked()?-1:0); settings.setValue("default_style/comboBox_QTV_icons",ui->comboBox_QTV_icons->currentText()); //update current style m_default_style.n_point_width = ui->spinBox_QTV_point_width->value(); m_default_style.n_point_height = ui->spinBox_QTV_point_height->value(); m_default_style.n_point_rect = radioButton_QTV_PointRect; m_default_style.pen.setColor(string2color(ui->lineEdit_QTV_PenColor->text())); m_default_style.pen.setWidth(ui->spinBox_QTV_penWidth->value()); m_default_style.pen.setStyle(static_cast<Qt::PenStyle>(ui->comboBox_QTV_linePad->currentIndex())); m_default_style.brush.setColor(string2color(ui->lineEdit_QTV_FillColor->text())); m_default_style.brush.setStyle(static_cast<Qt::BrushStyle>(ui->comboBox_QTV_fillPad->currentIndex())); m_default_style.text_color = string2color(ui->lineEdit_QTV_TextColor->text()); m_default_style.font.setWeight(ui->spinBox_QTV_textWeight->value()); m_default_style.font.setPointSize(ui->spinBox_QTV_fontSize->value()); m_default_style.scale = ui->lineEdit_QTV_icon_scale->text().toFloat(); m_default_style.rotate = ui->lineEdit_QTV_icon_rotate->text().toFloat(); m_default_style.multiline = ui->checkBox_QTV_multiline->isChecked()?-1:0; m_default_style.smooth = ui->checkBox_QTV_icon_smooth->isChecked()?-1:0; m_default_style.icon_name = ui->comboBox_QTV_icons->currentText(); }
/** Make sure one given option exists witin root. * If not present, fill inn the input defaults. */ ColorPropertyPtr ColorProperty::initialize(const QString& uid, QString name, QString help, QColor value, QDomNode root) { ColorPropertyPtr retval(new ColorProperty()); retval->mUid = uid; retval->mName = name.isEmpty() ? uid : name; retval->mHelp = help; retval->mStore = XmlOptionItem(uid, root.toElement()); retval->mValue = string2color(retval->mStore.readValue(color2string(value))); return retval; }
/* * Return a SDL rectangle with the size of the font */ void ttf_text_size (font **fpp, const char *text_in, double *w, double *h, enum_fmt *fmt, const char **col, double scaling, double advance, uint8_t fixed_width) { uint8_t found_format_string = false; int32_t c; texp tex; double x_start = 0; double x; enum_fmt _fmt; const char *text = text_in; font *f = *fpp; f->glyphs[' '].width = f->glyphs['t'].width; f->glyphs['('].width = f->glyphs['i'].width; f->glyphs[')'].width = f->glyphs['i'].width; x = 0; *w = 0; *h = f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].height * scaling; /* * To account for shadows that are not included in the glyph. */ *h *= 1.1; while ((c = *text++) != '\0') { if (c == '\\') { c = ' '; } if (!found_format_string) { if (c == '%') { found_format_string = true; continue; } } else if (found_format_string) { if (c == '%') { if (!strncmp(text, "fg=", 3)) { text += 3; if (col) { *col = string2colorname(&text); } else { (void) string2color(&text); } found_format_string = false; continue; } else if (!strncmp(text, "fmt=", 4)) { text += 4; _fmt = string2fmt(&text); if (fmt) { *fmt = _fmt; } found_format_string = false; continue; } else if (!strncmp(text, "font=", 5)) { text += 5; *fpp = string2font(&text); f = *fpp; found_format_string = false; continue; } else if (!strncmp(text, "tex=", 4)) { text += 4; tex = string2tex(&text); found_format_string = false; x += tex_get_width(tex) * scaling * advance; continue; } else if (!strncmp(text, "tile=", 5)) { text += 5; (void)string2tile(&text); x += f->glyphs[(int)TTF_FIXED_WIDTH_CHAR].width * scaling * advance * tile_stretch; found_format_string = false; continue; } else if (!strncmp(text, "tp=", 3)) { text += 3; tpp tp = string2tp(&text); tilep tile = tp_first_tile(tp); fpoint tl; fpoint br; double bx = x; double y = 0; tl.x = (x); tl.y = (y); br.x = (x + f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].width * scaling * tile_stretch); br.y = (y + f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].height * (scaling)); tile_get_blit_size(tp, tile, 0, &tl, &br); x = bx; x += br.x - tl.x; y = br.y - tl.y; y *= 1.1; if (y > *h) { *h = y; } found_format_string = false; continue; } } } found_format_string = false; if (c == '\t') { x = ((((x-x_start) / TTF_TABSTOP) + 1.0) * TTF_TABSTOP); x = x + x_start; } else if (c == '~') { x += f->glyphs[(int) TTF_FIXED_WIDTH_CHAR].width * scaling * advance; } else { int fixed = fixed_width; if (fixed) { x += f->glyphs[(int) TTF_FIXED_WIDTH_CHAR].width * scaling * advance; } else { if (c == TTF_CURSOR_CHAR) { x += f->glyphs[(int) TTF_FIXED_WIDTH_CHAR].width * scaling * advance; } else { x += f->glyphs[(int) c].width * scaling * advance; } } } } *w = x; }
/* * Blit the font to the screen */ static void ttf_puts_internal (font *f, const char *text, double x, double y, double scaling, double advance, uint8_t include_formatting, uint8_t draw_cursor, uint8_t fixed_width) { color saved_color = gl_color_current(); uint8_t color_retore_needed = false; uint8_t found_format_string = false; int32_t c; texp tex; tilep tile; tpp tp; color fg; double x_start = x; while ((c = *text++) != '\0') { if (c == '\\') { c = ' '; } if (!found_format_string) { if (c == '%') { found_format_string = true; continue; } } else if (found_format_string) { if (c == '%') { if (!strncmp(text, "fg=", 3)) { text += 3; fg = string2color(&text); fg.a = saved_color.a; if (!color_retore_needed) { color_retore_needed = true; if (include_formatting) { glcolor_save(); } } if (include_formatting) { glcolor(fg); } found_format_string = false; continue; } else if (!strncmp(text, "fmt=", 4)) { text += 4; (void)string2fmt(&text); found_format_string = false; continue; } else if (!strncmp(text, "font=", 5)) { text += 5; f = string2font(&text); found_format_string = false; continue; } else if (!strncmp(text, "tex=", 4)) { text += 4; tex = string2tex(&text); /* * Move forward half the texture size so it is centered. */ x += (tex_get_width(tex) * scaling * advance)/2; point at; at.x = x; at.y = y + (tex_get_height(tex) * scaling * advance)/2; tex_blit(tex, at); /* * Now the other half. */ x += (tex_get_width(tex) * scaling * advance)/2; found_format_string = false; continue; } else if (!strncmp(text, "tile=", 5)) { text += 5; tile = string2tile(&text); fpoint tl; fpoint br; double bx = x; tl.x = (x); tl.y = (y); br.x = (x + f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].width * scaling * tile_stretch); br.y = (y + f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].height * (scaling)); fpoint otl = tl; fpoint obr = br; tile_get_blit_size(0, tile, 0, &otl, &obr); double dy = ((obr.y - otl.y) - (br.y - tl.y)); double dx = ((obr.x - otl.x) - (br.x - tl.x)); tl.y += dy; br.y += dy; tl.x += dx/2; br.x += dx/2; double stretch = (f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].width * scaling * tile_stretch) - (f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].width * scaling); tl.x -= stretch / 2.0; tile_blit_fat(0, tile, 0, &tl, &br); x = bx; x += obr.x - otl.x; found_format_string = false; continue; } else if (!strncmp(text, "tp=", 3)) { text += 3; tp = string2tp(&text); tilep tile = tp_first_tile(tp); fpoint tl; fpoint br; double bx = x; tl.x = (x); tl.y = (y); br.x = (x + f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].width * scaling * tile_stretch); br.y = (y + f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].height * (scaling)); fpoint otl = tl; fpoint obr = br; double oh = br.y - tl.y; tile_get_blit_size(tp, tile, 0, &otl, &obr); double dx = ((obr.x - otl.x) - (br.x - tl.x)); tl.y += oh * tp_get_blit_top_off(tp); br.y += oh * tp_get_blit_top_off(tp); tl.x += dx/2; br.x += dx/2; double stretch = (f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].width * scaling * tile_stretch) - (f->glyphs[(uint32_t)TTF_FIXED_WIDTH_CHAR].width * scaling); tl.x -= stretch / 2.0; tile_blit_fat(tp, tile, 0, &tl, &br); x = bx; x += obr.x - otl.x; found_format_string = false; continue; } } } found_format_string = false; if (c == '\t') { x = ((((x-x_start) / TTF_TABSTOP) + 1) * TTF_TABSTOP); x = x + x_start; } else if (c == '~') { x += f->glyphs[(int) TTF_FIXED_WIDTH_CHAR].width * scaling * advance; } else { double maxc = f->glyphs[(int) TTF_FIXED_WIDTH_CHAR].width; double thisc = f->glyphs[(int) c].width; int fixed = fixed_width; if (fixed) { thisc = maxc; } double pad = ((maxc - thisc) * scaling * advance) / 2.0; if (fixed) { x += pad; } if (c == TTF_CURSOR_CHAR) { if (draw_cursor) { ttf_putc(f, c, x, y, scaling); } } else { ttf_putc(f, c, x, y, scaling); } if (fixed) { x += thisc; x += pad; } else { if (c == TTF_CURSOR_CHAR) { x += f->glyphs[(int) TTF_FIXED_WIDTH_CHAR].width * scaling * advance; } else { x += f->glyphs[c].width * scaling * advance; } } } } if (color_retore_needed) { glcolor(saved_color); } }
void qtvplugin_geomarker::on_pushButton_QTV_update_clicked() { if (m_pVi==0 || !m_pScene) return; QString name = ui->lineEdit_QTV_currentID->text(); ini_save(); //Get pen and brush settings Qt::PenStyle pst [] ={ Qt::NoPen , Qt::SolidLine , Qt::DashLine , Qt::DotLine , Qt::DashDotLine , Qt::DashDotDotLine , Qt::CustomDashLine }; Qt::BrushStyle bst [] = { Qt::NoBrush, Qt::SolidPattern, Qt::Dense1Pattern, Qt::Dense2Pattern, Qt::Dense3Pattern, Qt::Dense4Pattern, Qt::Dense5Pattern, Qt::Dense6Pattern, Qt::Dense7Pattern, Qt::HorPattern, Qt::VerPattern, Qt::CrossPattern, Qt::BDiagPattern, Qt::FDiagPattern, Qt::DiagCrossPattern }; int ptdd = ui->comboBox_QTV_linePad->currentIndex(); if (ptdd < 0 || ptdd >=7) ptdd = 1; QColor penColor = string2color( ui->lineEdit_QTV_PenColor->text()); int penWidth = ui->spinBox_QTV_penWidth->value(); QPen pen;//(QBrush(color),width,pst[ptdd]); pen.setColor(penColor); pen.setWidth(penWidth); pen.setStyle(pst[ptdd]); int btdd = ui->comboBox_QTV_fillPad->currentIndex(); if (btdd < 0 || btdd >=15) btdd = 1; QColor brushColor = string2color( ui->lineEdit_QTV_FillColor->text()); QBrush brush; brush.setColor(brushColor); brush.setStyle(bst[btdd]); QTVP_GEOMARKER::geoItemBase * newitem = 0; if (ui->radioButton_QTV_tool_point->isChecked()) { double lat = ui->lineEdit_QTV_point_lat->text().toDouble(); double lon = ui->lineEdit_QTV_point_lon->text().toDouble(); int tp = ui->radioButton_QTV_PointRect->isChecked()?0:1; int width = ui->spinBox_QTV_point_width->value(); int height = ui->spinBox_QTV_point_height->value(); if (tp==0) newitem = update_point<QTVP_GEOMARKER::geoGraphicsRectItem>(name,lat,lon,width,height,pen,brush); else newitem = update_point<QTVP_GEOMARKER::geoGraphicsEllipseItem>(name,lat,lon,width,height,pen,brush); } else if (ui->radioButton_QTV_tool_line->isChecked()) { double lat1 = ui->lineEdit_QTV_lineLat1->text().toDouble(); double lat2 = ui->lineEdit_QTV_lineLat2->text().toDouble(); double lon1 = ui->lineEdit_QTV_lineLon1->text().toDouble(); double lon2 = ui->lineEdit_QTV_lineLon2->text().toDouble(); newitem = update_line(name,lat1,lon1,lat2,lon2,pen); } else if (ui->radioButton_QTV_tool_polygon->isChecked()) { QPolygonF latlons; QString strPlainTexts = ui->plainTextEdit_QTV_corners->toPlainText(); strPlainTexts.remove(' '); strPlainTexts.remove('\n'); strPlainTexts.remove('\r'); strPlainTexts.remove('\015'); strPlainTexts.remove('\012'); QStringList lst = strPlainTexts.split(QRegExp("[,;]"),QString::SkipEmptyParts); int c = 0; QPointF ll; foreach (QString s,lst) { if (c%2==0) ll.setY(s.toDouble()); else ll.setX(s.toDouble()); if ((++c) % 2==0) latlons.push_back(ll); } if (latlons.size()) newitem = update_polygon(name,latlons,pen,brush,ui->checkBox_QTV_multiline->isChecked()?true:false); }
void qtvplugin_geomarker::style_load() { QSettings settings(ini_file(),QSettings::IniFormat); int spinBox_QTV_point_width = settings.value("default_style/spinBox_QTV_point_width",8).toInt(); ui->spinBox_QTV_point_width->setValue(spinBox_QTV_point_width); int spinBox_QTV_point_height = settings.value("default_style/spinBox_QTV_point_height",8).toInt(); ui->spinBox_QTV_point_height->setValue(spinBox_QTV_point_height); QString lineEdit_QTV_PenColor = settings.value("default_style/lineEdit_QTV_PenColor",color2string(QColor(0,0,0,128))).toString(); ui->lineEdit_QTV_PenColor->setText(lineEdit_QTV_PenColor); QString lineEdit_QTV_FillColor = settings.value("default_style/lineEdit_QTV_FillColor",color2string(QColor(255,255,255,128))).toString(); ui->lineEdit_QTV_FillColor->setText(lineEdit_QTV_FillColor); QString lineEdit_QTV_TextColor = settings.value("default_style/lineEdit_QTV_TextColor",color2string(QColor(0,0,0))).toString(); ui->lineEdit_QTV_TextColor->setText(lineEdit_QTV_TextColor); int radioButton_QTV_PointRect = settings.value("default_style/radioButton_QTV_PointRect",0).toInt(); switch (radioButton_QTV_PointRect) { case 0: ui->radioButton_QTV_PointRect->setChecked(true); break; case 1: ui->radioButton_QTV_PointRound->setChecked(true); break; default: ui->radioButton_QTV_PointRect->setChecked(true); break; } int spinBox_QTV_penWidth = settings.value("default_style/spinBox_QTV_penWidth",3).toInt(); ui->spinBox_QTV_penWidth->setValue(spinBox_QTV_penWidth); int comboBox_QTV_linePad = settings.value("default_style/comboBox_QTV_linePad",1).toInt(); ui->comboBox_QTV_linePad->setCurrentIndex(comboBox_QTV_linePad); int comboBox_QTV_fillPad = settings.value("default_style/comboBox_QTV_fillPad",1).toInt(); ui->comboBox_QTV_fillPad->setCurrentIndex(comboBox_QTV_fillPad); int spinBox_QTV_fontSize = settings.value("default_style/spinBox_QTV_fontSize",9).toInt(); ui->spinBox_QTV_fontSize->setValue(spinBox_QTV_fontSize); int spinBox_QTV_textWeight = settings.value("default_style/spinBox_QTV_textWeight",16).toInt(); ui->spinBox_QTV_textWeight->setValue(spinBox_QTV_textWeight); QString lineEdit_QTV_icon_scale = settings.value("default_style/lineEdit_QTV_icon_scale","1.0").toString(); ui->lineEdit_QTV_icon_scale->setText(lineEdit_QTV_icon_scale); QString lineEdit_QTV_icon_rotate = settings.value("default_style/lineEdit_QTV_icon_rotate","1.0").toString(); ui->lineEdit_QTV_icon_rotate->setText(lineEdit_QTV_icon_rotate); int checkBox_QTV_multiline = settings.value("default_style/checkBox_QTV_multiline",0).toInt(); ui->checkBox_QTV_multiline->setChecked(checkBox_QTV_multiline?true:false); int checkBox_QTV_icon_smooth = settings.value("default_style/checkBox_QTV_icon_smooth",0).toInt(); ui->checkBox_QTV_icon_smooth->setChecked(checkBox_QTV_icon_smooth?true:false); QString comboBox_QTV_icons = settings.value("default_style/comboBox_QTV_icons","default").toString(); if (m_map_icons.contains(comboBox_QTV_icons)) ui->comboBox_QTV_icons->setCurrentText(comboBox_QTV_icons); //update current style m_default_style.n_point_width = ui->spinBox_QTV_point_width->value(); m_default_style.n_point_height = ui->spinBox_QTV_point_height->value(); m_default_style.n_point_rect = radioButton_QTV_PointRect; m_default_style.pen.setColor(string2color(ui->lineEdit_QTV_PenColor->text())); m_default_style.pen.setWidth(ui->spinBox_QTV_penWidth->value()); m_default_style.pen.setStyle(static_cast<Qt::PenStyle>(ui->comboBox_QTV_linePad->currentIndex())); m_default_style.brush.setColor(string2color(ui->lineEdit_QTV_FillColor->text())); m_default_style.brush.setStyle(static_cast<Qt::BrushStyle>(ui->comboBox_QTV_fillPad->currentIndex())); m_default_style.text_color = string2color(ui->lineEdit_QTV_TextColor->text()); m_default_style.font.setWeight(ui->spinBox_QTV_textWeight->value()); m_default_style.font.setPointSize(ui->spinBox_QTV_fontSize->value()); m_default_style.scale = ui->lineEdit_QTV_icon_scale->text().toFloat(); m_default_style.rotate = ui->lineEdit_QTV_icon_rotate->text().toFloat(); m_default_style.multiline = ui->checkBox_QTV_multiline->isChecked()?-1:0; m_default_style.smooth = ui->checkBox_QTV_icon_smooth->isChecked()?-1:0; m_default_style.icon_name = ui->comboBox_QTV_icons->currentText(); }