Guest User

Untitled

a guest
Nov 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. void MainWindow::slotConstructWaterBodies(const QString& mapName, const QString& mapImagePath)
  2. {
  3. ui->mylabel->setPixmap(mapImagePath);
  4. /*Прочий код*/
  5. }
  6.  
  7. void MainWindow::resizeEvent(QResizeEvent *event)
  8. {
  9. adjustWidgetSize();
  10.  
  11. QMainWindow::resizeEvent(event);
  12. }
  13.  
  14. void MainWindow::adjustWidgetSize()
  15. {
  16. int widthCurrentPixMap = 1;
  17. int heightCurrentPixMap = 1;
  18.  
  19. if(pixPtr_) {
  20. widthCurrentPixMap = pixPtr_->width();
  21. heightCurrentPixMap = pixPtr_->height();
  22. }
  23. const QSize pixmapSize(widthCurrentPixMap, heightCurrentPixMap);
  24.  
  25. ui->mylabel->setFixedWidth(
  26. ui->centralWidget->height() * pixmapSize.width() / pixmapSize.height()
  27. );
  28. }
  29.  
  30. void MainWindow::slotConstructWaterBodies(const QString& mapName, const QString& mapImagePath)
  31. {
  32. QPixmap *pixmap = new QPixmap(mapImagePath);
  33. pixPtr_ = pixmap;
  34.  
  35. QGraphicsScene *scene = new QGraphicsScene;
  36. QGraphicsPixmapItem *item = new QGraphicsPixmapItem(*pixPtr_);
  37. item->setTransformationMode(Qt::SmoothTransformation);
  38. scene->addItem(item);
  39. ui->graphicsViewMap->setScene(scene);
  40. ui->graphicsViewMap->fitInView(scene->sceneRect(), Qt::IgnoreAspectRatio);
  41.  
  42. /*Прочий код*/
  43. }
  44.  
  45. void MainWindow::resizeEvent(QResizeEvent *event)
  46. {
  47. adjustWidgetSize();
  48.  
  49. adjustScaledPixmap();
  50.  
  51. QMainWindow::resizeEvent(event);
  52. }
  53.  
  54. void MainWindow::adjustWidgetSize()
  55. {
  56. int widthCurrentPixMap = 1;
  57. int heightCurrentPixMap = 1;
  58.  
  59. if(pixPtr_) {
  60. widthCurrentPixMap = pixPtr_->width();
  61. heightCurrentPixMap = pixPtr_->height();
  62. }
  63. const QSize pixmapSize(widthCurrentPixMap, heightCurrentPixMap);
  64.  
  65. ui->graphicsViewMap->setFixedWidth(
  66. ui->centralWidget->height() * pixmapSize.width() / pixmapSize.height()
  67. );
  68. }
  69.  
  70. void MainWindow::adjustScaledPixmap()
  71. {
  72. QGraphicsScene *scene = new QGraphicsScene;
  73. QGraphicsPixmapItem *item = new QGraphicsPixmapItem(*pixPtr_);
  74. item->setTransformationMode(Qt::SmoothTransformation);
  75. scene->addItem(item);
  76. ui->graphicsViewMap->setScene(scene);
  77. ui->graphicsViewMap->fitInView(scene->sceneRect(), Qt::IgnoreAspectRatio);
  78. }
Add Comment
Please, Sign In to add comment