Advertisement
Guest User

MainWindow.cpp

a guest
Mar 13th, 2013
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.43 KB | None | 0 0
  1.  
  2. #include <QRect>
  3.  
  4. #include "Results.h"
  5.  
  6. #include "MainWindow.h"
  7. #include "ui_MainWindow.h"
  8.  
  9. MainWindow::MainWindow(QWidget *parent) :
  10.     QMainWindow(parent),
  11.     m_ui(new Ui::MainWindow),
  12.     m_results(0)
  13. {
  14.     m_ui->setupUi(this);
  15.    
  16.     connect(m_ui->in_resultsInSeparateWin, SIGNAL(clicked()),
  17.             this, SLOT(refreshResultsWindow()));
  18.    
  19.     refreshResultsWindow();
  20. }
  21.  
  22. MainWindow::~MainWindow()
  23. {
  24.     delete m_ui;
  25.     delete m_results;
  26. }
  27.  
  28. void MainWindow::refreshResultsWindow()
  29. {
  30.     if(m_ui->in_resultsInSeparateWin->isChecked())
  31.     {
  32.         const int rWidth = m_results ? m_results->width() : 0;
  33.         delete m_results;
  34.        
  35.         m_results = new Results();
  36.         m_results->show();
  37.        
  38.         QWidget *widget = centralWidget();
  39.         const int oldMaxWidth = maximumWidth();
  40.         const int oldMaxWidgetWidth = widget->width();
  41.        
  42.         // This is configuration how resizing should be done:
  43.         const int variant = 0;
  44.         const bool useAlsoCentralWidget = true;
  45.        
  46.         // HERE! THIS IS THE PROBLEM AND WHAT IS NOT WORKING:
  47.         switch(variant)
  48.         {
  49.         case 0:
  50.             {
  51.                 // This doesn't work at all
  52.                 if(useAlsoCentralWidget)
  53.                 {
  54.                     widget->resize(widget->width() - rWidth, widget->height());
  55.                 }
  56.                
  57.                 resize(width() - rWidth, height());
  58.             }
  59.             break;
  60.         case 1:
  61.             {
  62.                 if(useAlsoCentralWidget)
  63.                 {
  64.                     widget->setMaximumWidth(widget->width() - rWidth);
  65.                 }
  66.                
  67.                 // This works only after when user moves main window
  68.                 setMaximumWidth(width() - rWidth);
  69.                
  70.                 // (Note that later I want to reset maximum width to it's
  71.                 // original value, this is just only mean to force window to
  72.                 // resize.)
  73.                 // (Note that if central widget is resized too, it's needed to
  74.                 // reset maximum width later!)
  75.             }
  76.             break;
  77.         case 2:
  78.             {
  79.                 // This doesn't work at all
  80.                
  81.                 if(useAlsoCentralWidget)
  82.                 {
  83.                    QRect g = widget->geometry();
  84.                    g.setWidth(g.width() - rWidth);
  85.                    widget->setGeometry(g);
  86.                 }
  87.                
  88.                 QRect g = geometry();
  89.                 g.setX(g.x() - 10);             // <-- this works
  90.                 g.setWidth(g.width() - rWidth); // <-- but this doesn't
  91.                 setGeometry(g);
  92.             }
  93.             break;
  94.         case 3:
  95.             {
  96.                 // This works well, but... it's SO ugly!
  97.                 setMaximumWidth(width() - rWidth);
  98.                 showMaximized();
  99.                 showNormal();
  100.                 setMaximumWidth(oldMaxWidth);
  101.             }
  102.             break;
  103.            
  104.         default:
  105.             break;
  106.         }
  107.     }
  108.     else
  109.     {
  110.         delete m_results;
  111.         m_results = new Results();
  112.        
  113.         m_ui->layout_results->addWidget(m_results);
  114.     }
  115.    
  116.     // NOTE: this is hardcoded because it's just example; in my real application
  117.     // size changes depending on results!
  118.     m_results->setMinimumSize(128, 128);
  119.     m_results->setMaximumSize(128, 128);
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement