better size for order windows table
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 16 May 2010 09:14:24 +0000 (09:14 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 16 May 2010 09:14:24 +0000 (09:14 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@457 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/dialogs/orderwin.cpp

index 3721f97..aafa586 100644 (file)
@@ -25,6 +25,8 @@
 #include <QBoxLayout>
 #include <QComboBox>
 #include <QDateTimeEdit>
+#include <QDebug>
+#include <QDesktopWidget>
 #include <QDoubleSpinBox>
 #include <QFileDialog>
 #include <QGridLayout>
 
 #include <math.h>
 
+/**helper class that has a more sensible sizeHint than the original QTableView - it tries to make sure the full table is visible*/
+class MOWTableView:public QTableView
+{
+       public:
+               MOWTableView()
+               {
+                       //set a sensible policy
+                       QSizePolicy sp=sizePolicy();
+                       sp.setVerticalPolicy  (QSizePolicy::Expanding);
+                       sp.setHorizontalPolicy(QSizePolicy::Expanding);
+                       setSizePolicy(sp);
+                       //remember absolute maximum
+                       absmax=QDesktopWidget().availableGeometry(this).size()-QSize(50,50);
+               }
+               QSize sizeHint()const{
+                       QSize psz=QTableView::minimumSizeHint();
+                       QSize vsz=maximumViewportSize()+QSize(50,50);
+                       //get maximum of parents view and viewports view of things
+                       if(psz.width()>vsz.width())vsz.setWidth(psz.width());
+                       if(psz.height()>vsz.height())vsz.setHeight(psz.height());
+                       //constrain to absolute maximum
+                       if(absmax.width()<vsz.width())vsz.setWidth(absmax.width());
+                       if(absmax.height()<vsz.height())vsz.setHeight(absmax.height());
+                       qDebug()<<"ret min"<<vsz;
+                       return vsz;
+               }
+       private:
+               QSize absmax;
+};
+
 MOrderWindow::MOrderWindow(QWidget*par,const MOOrder&o)
        :QMainWindow(par),m_order(o)
 {
@@ -129,20 +161,15 @@ MOrderWindow::MOrderWindow(QWidget*par,const MOOrder&o)
        gl->setColumnStretch(0,0);
        gl->setColumnStretch(1,10);
        
-       QSize sz=size();
        
        vl->addSpacing(10);
-       vl->addWidget(m_table=new QTableView,10);
+       vl->update();
+       QSize sz=size();qDebug()<<"size"<<sz;
+       
+       vl->addWidget(m_table=new MOWTableView,10);
        m_table->setModel(m_model=new QStandardItemModel(this));
        m_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
        updateData();
-       //make sure everything is visible
-       QSize vsz=m_table->maximumViewportSize();
-       vsz.setWidth(vsz.width()+40);
-       if(sz.width()<vsz.width())sz.setWidth(vsz.width());
-       sz.setHeight(sz.height()+vsz.height()+40);
-       //TODO: limit this to the screen size; find a better measure than viewport
-       resize(sz);
 }
 
 static const int ITEM_TICKET=1;