- Timestamp:
- May 31, 2011, 3:59:25 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/bncmap.cpp
r2805 r3288 10 10 bncMap::bncMap(QWidget* parent) : QDialog(parent) 11 11 { 12 _scale = 2.8; // scale the map 13 _LaOff = 25; // shift longitude 12 _LaOff = 25; // shift longitude 14 13 _mapScen = new QGraphicsScene(); 15 14 _mapView = new BncMapView(); 16 15 _mapView->setScene(_mapScen); 17 _mapView-> setMatrix(QMatrix(_scale,0,0,_scale,0,0));16 _mapView->resetScale(); 18 17 slotReadMap(); 19 18 slotCreateMap(); … … 27 26 28 27 /* rescale button */ 29 QPushButton* buttClean = new QPushButton("Clean"); 30 connect(buttClean, SIGNAL(clicked()), this, SLOT(slotCleanMap())); 31 32 /* reset button */ 33 QPushButton* buttReset = new QPushButton("Reset"); 34 connect(buttReset, SIGNAL(clicked()), this, SLOT(slotResetMap())); 28 // QPushButton* buttClean = new QPushButton("Clean"); 29 // connect(buttClean, SIGNAL(clicked()), this, SLOT(slotCleanMap())); 35 30 36 31 /* zoom button */ … … 42 37 connect(buttZoomOut, SIGNAL(clicked()), this, SLOT(slotZoomOut())); 43 38 39 /* reset button */ 40 QPushButton* buttReset = new QPushButton("World"); 41 connect(buttReset, SIGNAL(clicked()), this, SLOT(slotResetMap())); 42 44 43 /* fit button */ 45 QPushButton* buttFit = new QPushButton("Fit ");44 QPushButton* buttFit = new QPushButton("Fit Map"); 46 45 connect(buttFit, SIGNAL(clicked()), this, SLOT(slotFitMap())); 46 47 /* font reset button */ 48 QPushButton* buttFont = new QPushButton("Fit Font"); 49 connect(buttFont, SIGNAL(clicked()), this, SLOT(slotFitFont())); 47 50 48 51 /* layout */ … … 52 55 ButLayout->addWidget(buttZoomIn); 53 56 ButLayout->addWidget(buttZoomOut); 54 ButLayout->addWidget(buttClean);57 // ButLayout->addWidget(buttClean); 55 58 ButLayout->addWidget(buttReset); 56 59 ButLayout->addWidget(buttFit); 60 ButLayout->addWidget(buttFont); 57 61 ButLayout->addWidget(buttClose); 58 62 … … 145 149 slotCreateMap(); 146 150 slotResetMap(); 151 slotFitFont(); 147 152 } 148 153 … … 151 156 void bncMap::slotResetMap() 152 157 { 153 _mapView->setMatrix(QMatrix(_scale,0,0,_scale,0,0)); 154 } 155 156 157 // ------------ 158 void bncMap::slotZoomIn() 159 { 160 _mapView->scale( 1.2, 1.2 ); 161 } 162 163 164 // ------------ 165 void bncMap::slotZoomOut() 166 { 167 _mapView->scale( 1/1.2, 1/1.2 ); 158 _mapView->resetScale(); 168 159 } 169 160 … … 174 165 QRectF reg = _allPoints.boundingRect().adjusted(-10,-10,10,10); 175 166 167 _mapView->resetScale(); 176 168 _mapView->updateSceneRect(reg); 177 169 _mapView->centerOn(reg.center()); 178 170 _mapView->fitInView(reg,Qt::KeepAspectRatio); 179 } 180 181 182 // ------------ 183 void bncMap::slotNewPoint(QPointF point, QString name, QPen pen) 171 172 slotFitFont(); 173 } 174 175 176 // ------------ 177 void bncMap::slotFitFont() 178 { 179 _mapScen->clear(); 180 slotCreateMap(); 181 182 float fontsize = _mapView->scale_rate(); 183 float pointsize = _mapView->scale_rate(); 184 185 QMapIterator<QString, QList<QVariant> > it(_allNames); 186 while( it.hasNext() ){ 187 188 it.next(); 189 QString name = it.key(); 190 QList<QVariant> tmp = it.value(); 191 192 double la = tmp.at(0).toPointF().x(); 193 double fi = tmp.at(0).toPointF().y(); 194 QPen pen = tmp.at(1).value<QPen>(); 195 double basPT = tmp.at(2).toDouble(); 196 double basFT = tmp.at(3).toDouble(); 197 198 float tmpPT = pointsize * basPT; 199 float tmpFT = fontsize * basFT; 200 201 QFont font(QFont("Arial", 2, 1)); 202 font.setPointSizeF( tmpFT ); 203 204 QGraphicsTextItem* nameItem = new QGraphicsTextItem( name ); 205 nameItem->setFont( font ); 206 207 if( floor(fontsize) < 1 ){ 208 nameItem->setPos( la - 4.0 - floor(fontsize), fi - 5.0 - floor(fontsize) ); 209 }else{ 210 nameItem->setPos( la - 1.0 - floor(fontsize), fi - 4.0 - floor(fontsize) ); 211 } 212 213 if( tmpPT < 0.25 ) tmpPT = 0.25; 214 pen.setWidthF(tmpPT); 215 216 _mapScen->addItem( nameItem ); 217 _mapScen->addEllipse( la, fi, tmpPT, tmpPT, pen ); 218 } 219 _mapView->zoom( 1.0 ); 220 } 221 222 223 // ------------ 224 void bncMap::slotZoomIn() 225 { 226 _mapView->zoom( 1.2 ); 227 } 228 229 230 // ------------ 231 void bncMap::slotZoomOut() 232 { 233 _mapView->zoom( 1/1.2 ); 234 } 235 236 237 // ------------ 238 void bncMap::slotNewPoint(QPointF point, QString name, QPen pen, double size) 184 239 { 185 240 float la = point.x() + _LaOff; … … 189 244 while( la >= 360 ){ la -= 360; } 190 245 191 _allPoints << QPointF(la,fi);192 _ mapScen->addEllipse( la, fi, 1.5, 1.5, pen );246 QPointF tmppoint(la,fi); 247 _allPoints << tmppoint; 193 248 194 249 if( ! name.isEmpty() ){ 195 QGraphicsTextItem* nameItem = new QGraphicsTextItem( name ); 196 nameItem->setPos( QPointF(la-1, fi-2)); 197 nameItem->setFont( QFont("Arial", 2, 1) ); 198 199 _mapScen->addItem( nameItem ); 200 } 201 } 250 251 QList<QVariant> tmp; 252 tmp << tmppoint // QPoint 253 << pen // QPen 254 << size << 4.5; // base pointsize, fontsize 255 _allNames.insert( name, tmp ); 256 } 257 }
Note:
See TracChangeset
for help on using the changeset viewer.